Changeset 5944 for trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java
- Timestamp:
- 2003-11-24T14:26:35+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/AbstractDocument.java
r5800 r5944 3 3 import java.util.List; 4 4 import java.util.ArrayList; 5 import java.util.Iterator; 5 6 import java.util.HashMap; 6 7 import java.util.Map; 8 9 import java.sql.SQLException; 10 import java.sql.ResultSet; 11 7 12 import java.net.URL; 8 13 … … 19 24 20 25 import org.greenstone.gsdl3.gs3build.util.MultiMap; 26 import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection; 21 27 22 28 /** … … 32 38 METSHeader header; 33 39 DocumentID id; 40 boolean isModified; 41 42 /** 43 * <p>Create a very vanilla document with a given document identifier.</p> 44 * <p>Most commonly used in dealing with loading files using DocumentFactory 45 * or similar.</p> 46 * 47 * @param <code>DocumentID</code> the document identifier 48 */ 49 public AbstractDocument(DocumentID id) 50 { this.fileSet = new METSFileSet(); 51 this.metadata = new METSDescriptiveSet(); 52 this.header = new METSHeader(); 53 this.structureSet = new METSStructureSet(); 54 this.id = id; 55 } 34 56 57 /** 58 * Create a basic document from a given <code>URL</code. This is usually the form 59 * called through the recognisers. 60 * 61 * @param <code>URL</code> the URL of the first file in the document package 62 */ 35 63 public AbstractDocument(URL url) 36 64 { this.fileSet = new METSFileSet(); … … 39 67 this.header = new METSHeader(); 40 68 this.structureSet = new METSStructureSet(); 69 this.id = null; 41 70 42 71 METSStructure structure = new METSStructure("All", "All", "Whole Document"); … … 131 160 namespace = GSDL3Namespace.GSDL3_NAMESPACE_ID; 132 161 } 162 163 // no need to set isModified, as the following call will do it anyway! 133 164 this.addDocumentMetadata(namespace, name, value); 134 165 } … … 139 170 public void addDocumentMetadata(String namespace, String label, String value) 140 171 { this.metadata.addMetadata("default", namespace, label, value); 141 } 142 143 /** 144 * @see DocumentInterace:setDocumentMetadata 172 this.isModified = true; 173 } 174 175 /** 176 * Post metadata to a file in this document - the appropriate changes 177 * should be made... 178 */ 179 public void postFileMetadata(URL fileLocation, String namespace, String label, String value) 180 { 181 // First get the list of file groups, etc. that this file is associated with... 182 List fileGroups = this.fileSet.findGroups(fileLocation); 183 184 // Next, get the METS divisions associated with each file group... 185 List divisions = this.structureSet.findDivisionsForFiles(fileGroups); 186 187 // Finally, post the metadata to the metadata group associated with each structure 188 Iterator divisionIter = divisions.iterator(); 189 while (divisionIter.hasNext()) 190 { METSDivision division = (METSDivision) divisionIter.next(); 191 192 // get the open namespace for this division 193 METSNamespace namespaceMetadata = division.findNamespace(namespace, true, this.metadata); 194 195 // then post the metadata to it... 196 namespaceMetadata.addMetadata(label, value); 197 } 198 } 199 200 /** 201 * @see DocumentInterface:setDocumentMetadata 145 202 */ 146 203 public void setDocumentMetadata(String namespace, String label, String value) 147 204 { this.metadata.setMetadata("default", namespace, label, value); 205 this.isModified = true; 148 206 } 149 207 … … 158 216 159 217 /** 218 * Set the metadata structure for this document 219 * 220 * @param <code>METSDescriptive</code> the new metadata holder for the document. 221 */ 222 public void setDocumentMetadata(METSDescriptiveSet metadata) 223 { this.metadata = metadata; 224 this.isModified = true; 225 } 226 227 /** 160 228 * Get the metadata structure of the document 161 229 * … … 164 232 public METSStructureSet getDocumentStructure() 165 233 { return this.structureSet; 234 } 235 236 public void setDocumentStructure(METSStructureSet structureSet) 237 { this.structureSet = structureSet; 166 238 } 167 239 … … 207 279 { return this.fileSet; 208 280 } 281 282 public void setDocumentFiles(METSFileSet fileSet) 283 { this.fileSet = fileSet; 284 } 209 285 210 286 /** … … 231 307 { return new DocumentSQLWriter(); 232 308 } 233 309 310 /** 311 * Obtain a document from the SQL database 312 */ 313 public static AbstractDocument readSQL(GS3SQLConnection connection, ResultSet sqlResult) 314 { try { 315 DocumentID id = new DocumentID(sqlResult.getString("DocID")); 316 String type = sqlResult.getString("docType"); 317 318 // Use a factory method to create the correct subtype... 319 AbstractDocument document = DocumentFactory.createDocument(type, id); 320 321 // Get the individual components of the document 322 METSFileSet fileSet = METSFileSet.readSQL(document, connection); 323 document.setDocumentFiles(fileSet); 324 METSDescriptiveSet descriptiveSet = METSDescriptiveSet.readSQL(document, connection); 325 document.setDocumentMetadata(descriptiveSet); 326 METSStructureSet structureSet = METSStructureSet.readSQL(document, connection); 327 document.setDocumentStructure(structureSet); 328 329 // indicate that the document is not currently modified 330 document.setModified(false); 331 return document; 332 } 333 catch (SQLException sqlEx) { 334 } 335 return null; 336 } 337 338 /** 339 * 340 */ 341 public boolean isModified() 342 { return this.isModified; 343 } 344 345 public void setModified(boolean isModified) 346 { this.isModified = isModified; 347 } 234 348 }
Note:
See TracChangeset
for help on using the changeset viewer.