1 | package org.greenstone.gsdl3.gs3build.doctypes;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.HashMap;
|
---|
6 | import java.util.Map;
|
---|
7 | import java.net.URL;
|
---|
8 |
|
---|
9 | import org.greenstone.gsdl3.gs3build.metadata.NamespaceFactory;
|
---|
10 | import org.greenstone.gsdl3.gs3build.metadata.GSDL3Namespace;
|
---|
11 | import org.greenstone.gsdl3.gs3build.metadata.METSDescriptiveSet;
|
---|
12 | import org.greenstone.gsdl3.gs3build.metadata.METSFile;
|
---|
13 | import org.greenstone.gsdl3.gs3build.metadata.METSFileSet;
|
---|
14 | import org.greenstone.gsdl3.gs3build.metadata.METSHeader;
|
---|
15 | import org.greenstone.gsdl3.gs3build.metadata.METSStructure;
|
---|
16 | import org.greenstone.gsdl3.gs3build.metadata.METSStructureSet;
|
---|
17 | import org.greenstone.gsdl3.gs3build.metadata.METSDivision;
|
---|
18 | import org.greenstone.gsdl3.gs3build.metadata.METSNamespace;
|
---|
19 |
|
---|
20 | import org.greenstone.gsdl3.gs3build.util.MultiMap;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Provide a base-line functionality for the <code>DocumentInterface</code>
|
---|
24 | * class.
|
---|
25 | */
|
---|
26 |
|
---|
27 | public abstract class AbstractDocument implements DocumentInterface
|
---|
28 | {
|
---|
29 | METSFileSet fileSet;
|
---|
30 | METSDescriptiveSet metadata;
|
---|
31 | METSStructureSet structureSet;
|
---|
32 | METSHeader header;
|
---|
33 | DocumentID id;
|
---|
34 |
|
---|
35 | public AbstractDocument(URL url)
|
---|
36 | { this.fileSet = new METSFileSet();
|
---|
37 | METSFile metsFile = this.fileSet.addFile(url);
|
---|
38 | this.metadata = new METSDescriptiveSet();
|
---|
39 | this.header = new METSHeader();
|
---|
40 | this.structureSet = new METSStructureSet();
|
---|
41 |
|
---|
42 | METSStructure structure = new METSStructure("All", "All", "Whole Document");
|
---|
43 | METSDivision documentBody = new METSDivision("All", "All", "All", "Whole Document", "Document");
|
---|
44 | structure.addDivision(documentBody);
|
---|
45 | this.structureSet.addStructure(structure);
|
---|
46 | documentBody.addFileReference(metsFile.getID());
|
---|
47 | documentBody.addMetadataReference("DM1");
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Set the identified for the document. Every document should have
|
---|
52 | * a document number set on its accession, either through metadata
|
---|
53 | * placed upon it internally or externally, or by assignment through
|
---|
54 | * a <code>DocumentIDFactory</code>. Each identifier should be
|
---|
55 | * unique.
|
---|
56 | *
|
---|
57 | * @param <code>DocumentID</code> the document identifier - in XML
|
---|
58 | * terms, the gsdl3:id element.
|
---|
59 | */
|
---|
60 | public void setID(DocumentID id)
|
---|
61 | { this.id = id;
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Get the document identifier - this should be unique to the document,
|
---|
66 | * but care must be taken in the configuration of the collection to
|
---|
67 | * ensure that this is the case.
|
---|
68 | *
|
---|
69 | * @return <code>DocumentID</code> the identifer
|
---|
70 | */
|
---|
71 | public DocumentID getID()
|
---|
72 | { return this.id;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Indicate whether this document is indexed.
|
---|
77 | *
|
---|
78 | * @see: DocumentInterface.isIndexed
|
---|
79 | */
|
---|
80 | public boolean isIndexed()
|
---|
81 | {
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Obtain the METS header of this document
|
---|
87 | *
|
---|
88 | * @return <code>METSHeader</code> the header
|
---|
89 | */
|
---|
90 | public METSHeader getHeader()
|
---|
91 | { return this.header;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Set the METS header for this document.
|
---|
96 | *
|
---|
97 | * @param <code>METSHeader</code> the header
|
---|
98 | */
|
---|
99 | public void setHeader(METSHeader header)
|
---|
100 | { this.header = header;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * A simple implementation of the isDocumentType function that does <b>not</b> consider
|
---|
105 | * inheritance - it <code>must</code> be extended as required.
|
---|
106 | */
|
---|
107 | public boolean isDocumentType(String type)
|
---|
108 | { return type.equals(this.getDocumentType());
|
---|
109 | }
|
---|
110 |
|
---|
111 | public abstract String getDocumentType();
|
---|
112 |
|
---|
113 | public abstract String getDocumentText();
|
---|
114 |
|
---|
115 | public String getMETSType()
|
---|
116 | { return "document";
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * @see DocumentInterface:addDocumentMetadata
|
---|
121 | */
|
---|
122 | public void addDocumentMetadata(String name, String value)
|
---|
123 | { int colonAt = name.indexOf(":");
|
---|
124 | String namespace;
|
---|
125 |
|
---|
126 | if (colonAt > 0) {
|
---|
127 | namespace = name.substring(0, colonAt);
|
---|
128 | name = name.substring(colonAt+1);
|
---|
129 | }
|
---|
130 | else {
|
---|
131 | namespace = GSDL3Namespace.GSDL3_NAMESPACE_ID;
|
---|
132 | }
|
---|
133 | this.addDocumentMetadata(namespace, name, value);
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * @see DocumentInterface:addDocumentMetadata
|
---|
138 | */
|
---|
139 | public void addDocumentMetadata(String namespace, String label, String value)
|
---|
140 | { this.metadata.addMetadata("default", namespace, label, value);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * @see DocumentInterace:setDocumentMetadata
|
---|
145 | */
|
---|
146 | public void setDocumentMetadata(String namespace, String label, String value)
|
---|
147 | { this.metadata.setMetadata("default", namespace, label, value);
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Get the metadata structure of the document
|
---|
152 | *
|
---|
153 | * @return <code>METSDescriptive</code> the metadata holder for the document.
|
---|
154 | */
|
---|
155 | public METSDescriptiveSet getDocumentMetadata()
|
---|
156 | { return this.metadata;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Get the metadata structure of the document
|
---|
161 | *
|
---|
162 | * @return <code>METSStructureSet</code> the metadata holder for the document.
|
---|
163 | */
|
---|
164 | public METSStructureSet getDocumentStructure()
|
---|
165 | { return this.structureSet;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Get the values associated with a particular metadata value.
|
---|
170 | *
|
---|
171 | * @param <code>String</code> the namespace to find the values in.
|
---|
172 | * @param <code>String</code> the label to match to find the values.
|
---|
173 | *
|
---|
174 | * @return <code>List</code> the values.
|
---|
175 | */
|
---|
176 | public List getDocumentMetadataItem(String namespace, String label)
|
---|
177 | { return this.metadata.getMetadata("default", namespace, label);
|
---|
178 | }
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Get the values associated with a particular metadata value.
|
---|
182 | *
|
---|
183 | * @param <code>String</code> the namespace and label separated by a
|
---|
184 | * colon.
|
---|
185 | *
|
---|
186 | * @return <code>List</code> the values.
|
---|
187 | */
|
---|
188 | public List getDocumentMetadataItem(String namespaceLabel)
|
---|
189 | { String namespace, label;
|
---|
190 |
|
---|
191 | int colonAt = namespaceLabel.indexOf(':');
|
---|
192 | if (colonAt < 0)
|
---|
193 | { namespace = GSDL3Namespace.GSDL3_NAMESPACE_ID;
|
---|
194 | label = namespaceLabel;
|
---|
195 | }
|
---|
196 | else
|
---|
197 | { namespace = namespaceLabel.substring(0, colonAt);
|
---|
198 | label = namespaceLabel.substring(colonAt+1);
|
---|
199 | }
|
---|
200 | return this.metadata.getMetadata("default", namespace, label);
|
---|
201 | }
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * @see DocumentInterface:getDocumentFiles
|
---|
205 | */
|
---|
206 | public METSFileSet getDocumentFiles()
|
---|
207 | { return this.fileSet;
|
---|
208 | }
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * @see DocumentInterface:isMETSCompatible
|
---|
212 | */
|
---|
213 | public boolean isMETSCompatible()
|
---|
214 | { return true;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Use a default document writer - this may be overridden for subclasses...
|
---|
219 | *
|
---|
220 | * @see DocumentInterface:writeMETSObject
|
---|
221 | */
|
---|
222 | public DocumentWriter getMETSWriter()
|
---|
223 | { return new DocumentWriter();
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Use a default SQL document writer - this may be overridden for subclasses...
|
---|
228 | *
|
---|
229 | */
|
---|
230 | public DocumentSQLWriter getSQLWriter()
|
---|
231 | { return new DocumentSQLWriter();
|
---|
232 | }
|
---|
233 |
|
---|
234 | }
|
---|