1 | package org.greenstone.gsdl3.gs3build.metadata;
|
---|
2 |
|
---|
3 | import java.io.PrintWriter;
|
---|
4 |
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 | import java.util.Iterator;
|
---|
9 |
|
---|
10 | import org.w3c.dom.Document;
|
---|
11 | import org.w3c.dom.Element;
|
---|
12 | import org.w3c.dom.NamedNodeMap;
|
---|
13 | import org.w3c.dom.Node;
|
---|
14 | import org.w3c.dom.NodeList;
|
---|
15 | import org.w3c.dom.Text;
|
---|
16 |
|
---|
17 | import org.xml.sax.SAXException;
|
---|
18 | import org.xml.sax.SAXParseException;
|
---|
19 |
|
---|
20 |
|
---|
21 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
|
---|
22 |
|
---|
23 | import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
|
---|
24 |
|
---|
25 | public class METSDescriptiveSet
|
---|
26 | { Map children;
|
---|
27 |
|
---|
28 | public METSDescriptiveSet()
|
---|
29 | { this.children = new HashMap();
|
---|
30 |
|
---|
31 | METSDescriptive descriptive = new METSDescriptive("DM1", "default");
|
---|
32 | this.addDescriptive(descriptive);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void addDescriptive(METSDescriptive metadata)
|
---|
36 | { this.children.put(metadata.getName(), metadata);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public METSDescriptive getDescriptive(String name)
|
---|
40 | { return (METSDescriptive) this.children.get(name);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void addNamespace(String descriptiveName, METSNamespace namespace)
|
---|
44 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
45 | if (descriptive != null)
|
---|
46 | { descriptive.addNamespace(namespace);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public METSNamespace getNamespace(String descriptiveName, String namespace)
|
---|
51 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
52 | if (descriptive != null)
|
---|
53 | { return descriptive.getNamespace(namespace);
|
---|
54 | }
|
---|
55 | return null;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public METSNamespace getOpenNamespace(String descriptiveName, String namespace)
|
---|
59 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
60 |
|
---|
61 | if (descriptive != null)
|
---|
62 | { return descriptive.getOpenNamespace(namespace);
|
---|
63 | }
|
---|
64 | return null;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void addMetadata(String descriptiveName, String namespace, String label, String value)
|
---|
68 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
69 |
|
---|
70 | if (descriptive != null)
|
---|
71 | { descriptive.addMetadata(namespace, label, value);
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | public void setMetadata(String descriptiveName, String namespace, String label, String value)
|
---|
76 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
77 |
|
---|
78 | if (descriptive != null)
|
---|
79 | { descriptive.setMetadata(namespace, label, value);
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public List getMetadata(String descriptiveName, String namespace, String label)
|
---|
84 | { METSDescriptive descriptive = this.getDescriptive(descriptiveName);
|
---|
85 |
|
---|
86 | if (descriptive != null)
|
---|
87 | { return descriptive.getMetadata(namespace, label);
|
---|
88 | }
|
---|
89 | return null;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public void write(PrintWriter writer)
|
---|
93 | { Iterator groups = this.children.values().iterator();
|
---|
94 |
|
---|
95 | while (groups.hasNext())
|
---|
96 | { METSDescriptive group = (METSDescriptive) groups.next();
|
---|
97 |
|
---|
98 | group.write(writer);
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | public void writeSQL(DocumentInterface document, GS3SQLConnection connection)
|
---|
104 | { Iterator groups = this.children.values().iterator();
|
---|
105 |
|
---|
106 | while (groups.hasNext())
|
---|
107 | { METSDescriptive group = (METSDescriptive) groups.next();
|
---|
108 |
|
---|
109 | group.writeSQL(document, connection);
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | public static METSDescriptiveSet parseXML(NodeList fileSecs)
|
---|
114 | {
|
---|
115 | METSDescriptiveSet set = new METSDescriptiveSet();
|
---|
116 |
|
---|
117 | for (int g = 0; g < fileSecs.getLength(); g ++) {
|
---|
118 | // Schema schema = new Schema(schemas.item(s));
|
---|
119 | METSDescriptive metadata = METSDescriptive.parseXML((Element) fileSecs.item(g));
|
---|
120 | set.addDescriptive(metadata);
|
---|
121 | }
|
---|
122 | return set;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|