1 | package org.greenstone.gsdl3.gs3build.metadata;
|
---|
2 |
|
---|
3 | /**
|
---|
4 | * A class to hold all the alternative file structures
|
---|
5 | * for a particular METS Document
|
---|
6 | */
|
---|
7 |
|
---|
8 | import java.util.Map;
|
---|
9 | import java.util.HashMap;
|
---|
10 | import java.util.Iterator;
|
---|
11 |
|
---|
12 | import java.io.File;
|
---|
13 | import java.io.PrintWriter;
|
---|
14 | import java.net.URL;
|
---|
15 |
|
---|
16 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
|
---|
17 |
|
---|
18 | import org.greenstone.gsdl3.gs3build.database.*;
|
---|
19 | import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
|
---|
20 |
|
---|
21 | public class METSFileSet
|
---|
22 | { Map fileGroups;
|
---|
23 |
|
---|
24 | public METSFileSet()
|
---|
25 | { this.fileGroups = new HashMap();
|
---|
26 | this.fileGroups.put("default", new METSFileGroup("default"));
|
---|
27 | }
|
---|
28 |
|
---|
29 | public METSFileGroup getGroup(String name)
|
---|
30 | { if (!this.fileGroups.containsKey(name))
|
---|
31 | { return null;
|
---|
32 | }
|
---|
33 | return (METSFileGroup) this.fileGroups.get(name);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public METSFile getFile(int index)
|
---|
37 | { METSFileGroup group = this.getGroup("default");
|
---|
38 |
|
---|
39 | if (group == null)
|
---|
40 | { return null;
|
---|
41 | }
|
---|
42 | return group.getFile(0);
|
---|
43 | }
|
---|
44 |
|
---|
45 | public void addFile(METSFile file)
|
---|
46 | { METSFileGroup defaultGroup = (METSFileGroup) this.fileGroups.get("default");
|
---|
47 | defaultGroup.addFile(file);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public METSFile addFile(URL url)
|
---|
51 | { METSFile file = METSFile.makeMETSFile(url);
|
---|
52 | this.addFile(file);
|
---|
53 | return file;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public void addFile(METSFile file, String toGroup)
|
---|
57 | { METSFileGroup destGroup = (METSFileGroup) this.fileGroups.get(toGroup);
|
---|
58 |
|
---|
59 | if (destGroup == null)
|
---|
60 | { destGroup = new METSFileGroup(toGroup);
|
---|
61 | this.fileGroups.put(destGroup.getName(), destGroup);
|
---|
62 | }
|
---|
63 |
|
---|
64 | destGroup.addFile(file);
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void addFile(URL url, String toGroup)
|
---|
68 | { METSFile file = METSFile.makeMETSFile(url);
|
---|
69 | this.addFile(file, toGroup);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void addGroup(METSFileGroup group)
|
---|
73 | { this.fileGroups.put(group.getName(), group);
|
---|
74 | }
|
---|
75 |
|
---|
76 | public void write(PrintWriter writer)
|
---|
77 | { Iterator groups = this.fileGroups.values().iterator();
|
---|
78 |
|
---|
79 | writer.println("<mets:fileSec>");
|
---|
80 | while (groups.hasNext())
|
---|
81 | { METSFileGroup group = (METSFileGroup) groups.next();
|
---|
82 |
|
---|
83 | group.write(writer);
|
---|
84 | }
|
---|
85 | writer.println("</mets:fileSec>");
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void writeSQL(DocumentInterface document, GS3SQLConnection connection)
|
---|
89 | { Iterator groups = this.fileGroups.values().iterator();
|
---|
90 |
|
---|
91 | GS3SQLInsert insert = new GS3SQLInsert("filesection");
|
---|
92 | insert.addValue("DocID", document.getID().toString());
|
---|
93 | insert.addValue("FileSecID", "test"); // TODO: remove magic string
|
---|
94 |
|
---|
95 | connection.execute(insert.toString());
|
---|
96 |
|
---|
97 | while (groups.hasNext())
|
---|
98 | { METSFileGroup group = (METSFileGroup) groups.next();
|
---|
99 |
|
---|
100 | group.writeSQL(document, connection);
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|