Changeset 8461
- Timestamp:
- 2004-11-05T10:10:44+13:00 (20 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptive.java
r6738 r8461 179 179 } 180 180 181 protected void parse_xmlData(METSNamespace namespace, Element element) 182 { 183 if (namespace==null) { 184 System.err.println("namespace is null!!!!"); 185 } 186 NodeList children = element.getChildNodes(); 187 188 for (int c = 0; c < children.getLength(); c++) { 189 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) { 190 continue; 191 } 192 193 Element child = (Element) children.item(c); 194 String childName = child.getNodeName(); 195 196 // if (childName.equals("gsdl2:Metadata")) { 197 if (childName.equals("gsdl3:Metadata")) { 198 String metaName = child.getAttribute("name"); 199 Text text = (Text) child.getFirstChild(); 200 String metaValue = text.getData(); 201 202 addMetadata(namespace.getName(),metaName, metaValue); 203 } 204 } 205 } 206 207 public void parse_mdWrap(Element element) 208 { 209 // deal with mets:mdWrap 210 211 METSNamespace namespace = NamespaceFactory.parseXML(element); 212 213 NodeList children = element.getChildNodes(); 214 215 for (int c = 0; c < children.getLength(); c ++) { 216 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) { 217 continue; 218 } 219 220 Element child = (Element) children.item(c); 221 String childName = child.getNodeName(); 222 223 if (childName.equals("mets:xmlData")) { 224 parse_xmlData(namespace, child); 225 } else { 226 System.err.println("Warning: unrecognised tag " + childName 227 + "in mets:mdWrap"); 228 } 229 } 230 } 231 232 /** 233 * Parse an XML Element as a METS Descriptive Metadata section 234 * 235 * @param <code>Element</code> the XML element which represents the dmdSec itself 236 */ 237 238 //public static METSDescriptive parseXML(Element element, METSDescriptive thisDescriptive) 239 public static METSDescriptive parseXML(Element element) 240 { 241 // Note: no parsing of attributes required, we just move onto 242 // the metadata namespaces/sections themselves 243 244 // deal with mets:dmdSec 245 String ID = element.getAttribute("ID"); 246 String label = element.getAttribute("GROUPID"); 247 248 METSDescriptive thisDescriptive = new METSDescriptive(ID, label); 249 250 //thisDescriptive = new METSDescriptive(ID, label); 251 252 NodeList children = element.getChildNodes(); 253 254 for (int c = 0; c < children.getLength(); c ++) { 255 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) { 256 continue; 257 } 258 259 Element child = (Element) children.item(c); 260 String childName = child.getNodeName(); 261 262 if (childName.equals("mets:mdRef")) { 263 //for External Descriptive Metadata 264 METSNamespace namespace = NamespaceFactory.parseXML(element); 265 System.err.println("*** mets::mdRef does not appear to be implemented yet"); 266 } else if (childName.equals("mets:mdWrap")) { 267 thisDescriptive.parse_mdWrap(child); 268 } else { 269 // TODO: raise an error! 270 System.out.println("Error: METSDescriiptive: unrecognised tag "+childName); 271 } 272 } 273 return thisDescriptive; 274 } 275 276 181 277 /** 182 278 * Parse an XML Element as a METS Descriptive Metadata section … … 184 280 * @param <code>Element</code> the XML element which represents the dmdSec itself 185 281 */ 186 public static METSDescriptive parseXML(Element element)282 /* public static METSDescriptive parseXML(Element element) 187 283 { // Note: no parsing of attributes required, we just move onto the metadata 188 284 // namespaces/sections themselves … … 211 307 return thisDescriptive; 212 308 } 213 309 */ 214 310 215 311 /** … … 250 346 output.println(tag); 251 347 } 348 349 public void copy_metadata(METSDescriptive dst) 350 { 351 Iterator keys = this.map.keySet().iterator(); 352 353 // get the keys one by one 354 while (keys.hasNext()) { 355 Object nextKey = keys.next(); 356 if (nextKey == null) { 357 continue; 358 } 359 String key = nextKey.toString(); 360 361 System.err.println("*** Namespace = " + key); 362 363 // get every copy of the current namespace name - namespaces may 364 // occur more than once, so this is a List 365 Iterator namespaces = this.map.getAll(key).iterator(); 366 367 while (namespaces.hasNext()) { 368 METSNamespace namespace = (METSNamespace) namespaces.next(); 369 370 // for each metadata name 371 372 Iterator mdnIter = namespace.getMetadataNames(); 373 while (mdnIter.hasNext()) { 374 375 String md_name = mdnIter.next().toString(); 376 377 List values = getMetadata(key, md_name); 378 379 if (values != null) { 380 Iterator valueIter = values.iterator(); 381 while (valueIter.hasNext()) { 382 String value = valueIter.next().toString(); 383 dst.addMetadata("gsdl3",md_name,value); 384 } 385 } 386 } 387 } 388 } 389 } 390 252 391 253 392 public boolean writeSQL(DocumentInterface document, GS3SQLConnection connection) -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java
r6738 r8461 70 70 71 71 // when a descriptive block is added, check that it hasn't been used before... 72 this.identifierFactory.noteIdentifier(metadata.getID()); 73 } 74 75 /** 76 * Get a descriptive item by its name 72 //this.identifierFactory.noteIdentifier(metadata.getID()); 73 this.identifierFactory.noteIdentifier(metadata.getName()); 74 } 75 76 /** 77 * Get a descriptive item by its name(GROUPID in METS file) 77 78 */ 78 79 public METSDescriptive getDescriptive(String name) … … 177 178 return true; 178 179 } 179 180 /* 180 181 public static METSDescriptiveSet parseXML(NodeList fileSecs) 181 182 { … … 189 190 return set; 190 191 } 192 */ 193 194 /* public static METSDescriptiveSet parseXML(NodeList dmdSecs) 195 { 196 METSDescriptiveSet set = new METSDescriptiveSet(); 197 METSDescriptive thisDescriptive = null; 198 199 for (int g = 0; g < dmdSecs.getLength(); g ++) { 200 Element dmdNode = (Element) dmdSecs.item(g); 201 String ID = dmdNode.getAttribute("ID"); 202 String label = dmdNode.getAttribute("GROUPID"); 203 System.err.println("###Label="+label); 204 205 if (label.equals("1")) { 206 thisDescriptive = set.getDescriptive("default"); 207 System.err.println("####thisDescriptiveDefault=" + thisDescriptive); 208 } else { 209 thisDescriptive = new METSDescriptive(ID, label); 210 System.err.println("####thisDescriptive=" + thisDescriptive); 211 } 212 213 METSDescriptive metadata = METSDescriptive.parseXML((Element) dmdSecs.item(g), thisDescriptive); 214 215 set.addDescriptive(metadata); 216 } 217 return set; 218 }*/ 219 public static METSDescriptiveSet parseXML(NodeList dmdSecs) 220 { 221 METSDescriptiveSet set = new METSDescriptiveSet(); 222 223 for (int g = 0; g < dmdSecs.getLength(); g ++) { 224 METSDescriptive metadata = METSDescriptive.parseXML((Element) dmdSecs.item(g)); 225 226 set.addDescriptive(metadata); 227 } 228 229 230 System.err.println("******** Away to do transfer!!!!!!"); 231 232 METSDescriptive top_level_metadata = set.getDescriptive("1"); 233 METSDescriptive tl2_metadata = set.getDescriptive("1"); 234 METSDescriptive opo_metadata = set.getDescriptive("1.1"); 235 METSDescriptive default_metadata = set.getDescriptive("default"); 236 237 if (top_level_metadata != null) { 238 if (default_metadata != null) { 239 top_level_metadata.copy_metadata(default_metadata); 240 } 241 else { 242 System.err.println("Warning: Could not find default metadata"); 243 } 244 } 245 else { 246 System.err.println("Warning: Could not find top level metadata for groupID=1"); 247 } 248 return set; 249 } 191 250 192 251 public static METSDescriptiveSet readSQL(DocumentInterface document, GS3SQLConnection connection) -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDivision.java
r7187 r8461 11 11 import java.sql.SQLException; 12 12 import java.sql.ResultSet; 13 14 import org.w3c.dom.Element; 15 import org.w3c.dom.NodeList; 13 16 14 17 import org.greenstone.gsdl3.gs3build.doctypes.DocumentID; … … 289 292 } 290 293 } 294 295 /* Parse an XML Element as a METSDivision section 296 * 297 * @param <code>Element</code> the XML element which represents 298 * the mets:div itself 299 */ 300 301 public static METSDivision parseXML(Element element) 302 { 303 METSDivision thisDivision = null; 304 305 String divId = element.getAttribute("ID"); 306 String divType = element.getAttribute("TYPE"); 307 String divOrder = element.getAttribute("ORDER"); 308 String divOrderLabel = element.getAttribute("ORDERLABEL"); 309 String divUserLabel = element.getAttribute("LABEL"); 310 String divMetaRef = element.getAttribute("DMDID"); 311 312 thisDivision = new METSDivision(divId, divOrder,divOrderLabel, divUserLabel, divType); 313 314 thisDivision.addMetadataReference(divMetaRef); 315 316 NodeList children = element.getChildNodes(); 317 318 for (int c = 0; c < children.getLength(); c++){ 319 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE){ 320 continue; 321 } 322 Element child = (Element) children.item(c); 323 String childName = child.getNodeName(); 324 325 if (childName.equals("mets:fptr")) { 326 327 METSDivision.fptr_parseXML(thisDivision, child); 328 } else if (childName.equals("mets:div")) { 329 METSDivision division = METSDivision.parseXML(child); 330 thisDivision.addDivision(division); 331 } else { 332 System.err.println("Error: mets:div expected mets:div or mets:fptr, but got " + childName); 333 } 334 } 335 return thisDivision; 336 } 337 338 339 340 /** 341 * Parse an XML element as a METSFptr Section 342 * @param <code>Element</code> the XML element which represents the mets:fptr itself 343 */ 344 private static void fptr_parseXML(METSDivision thisDivision, Element element) 345 { 346 String fileRef = element.getAttribute("FILEID"); 347 thisDivision.addFileReference(fileRef); 348 } 349 350 /** 351 291 352 292 353 /** -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFile.java
r8408 r8461 248 248 * Parse an XML Element as a METS File 249 249 */ 250 /* 250 251 public static METSFile parseXML(Element element, METSFileGroup parentGroup) 251 252 { METSFile file = null; … … 287 288 return file; 288 289 } 290 */ 291 292 293 public static METSFile parse_file(Element element, METSFileGroup group, String parseFilePath) 294 { 295 NodeList children = element.getChildNodes(); 296 297 METSFile thisFile = null; 298 299 for (int c = 0; c < children.getLength(); c++){ 300 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE){ 301 continue; 302 } 303 Element child = (Element) children.item(c); 304 String childName = child.getNodeName(); 305 306 if (childName.equals("mets:file")){ 307 METSFile.parse_file(child, group, parseFilePath); 308 } else if (childName.equals("mets:FLocat")) { 309 String mimeType = element.getAttribute("MIMETYPE"); 310 String fileId = element.getAttribute("ID"); 311 312 METSFilePos thisFilePos = METSFile.parse_flocateXML(child, parseFilePath); 313 thisFile = new METSFile(new METSFileID(fileId), thisFilePos, mimeType); 314 group.addFile(thisFile); 315 } else { 316 System.err.println("Warning: unrecognised tag " +childName); 317 } 318 } 319 return thisFile; 320 } 321 322 public static METSFilePos parse_flocateXML(Element element, String parseFilePath) 323 { 324 METSFilePos thisFilePos = null; 325 326 // get most of the information from the child FLocat node 327 String locationType = element.getAttribute("LOCTYPE"); 328 String href = element.getAttribute("xlink:href"); 329 String fileId = element.getAttribute("ID"); 330 331 try { 332 thisFilePos = new METSFilePos(locationType, href); 333 334 if (fileId.startsWith("default.")) { 335 //retrieve the string after ..import/ 336 int importPosition = href.indexOf("import/")+7; 337 href.substring(importPosition); 338 if (fileId.equals("default.1")) { 339 href = "file:" + parseFilePath+ "doctxt.xml"; 340 } else { 341 href = "file:" + parseFilePath + href.substring(importPosition); 342 } 343 } 344 thisFilePos = new METSFilePos(locationType, href); 345 } catch (java.net.MalformedURLException ex) { 346 // TODO: raise error 347 System.err.println(ex); 348 } 349 return thisFilePos; 350 // file = new METSFile(new METSFileID(id), filePos, mimeType); 351 // } 352 // else if (childElement.getNodeName().equals("mets:FContent")) 353 // { 354 // } 355 // else 356 // { // TODO: raise an error! 357 // } 358 // } 359 // return file; 360 // } 361 362 } 363 289 364 290 365 /** -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileGroup.java
r7465 r8461 9 9 import java.sql.SQLException; 10 10 import java.sql.ResultSet; 11 12 import org.w3c.dom.Element; 13 import org.w3c.dom.NodeList; 14 11 15 12 16 import java.io.PrintWriter; … … 203 207 { return this.id; 204 208 } 209 210 public static METSFileGroup parse_groupXML(Element element, METSFileSet set, String parseFilePath, METSFileGroup group) 211 { 212 //deal with mets:fileGrp 213 NodeList children = element.getChildNodes(); 214 215 for (int c = 0; c < children.getLength(); c++) { 216 if (children.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE){ 217 continue; 218 } 219 Element child = (Element) children.item(c); 220 String childName = child.getNodeName(); 221 222 if (childName.equals("mets:fileGrp")) { 223 String groupId = child.getAttribute("ID"); 224 METSFileGroup childGroup = new METSFileGroup(groupId); 225 226 if (group != null){ 227 group.addGroup(childGroup); 228 } else { 229 set.addGroup(childGroup); 230 } 231 METSFile file = METSFile.parse_file(child, childGroup, parseFilePath); 232 } 233 } 234 return group; 235 } 205 236 206 237 /** -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSFileSet.java
r7465 r8461 17 17 import java.sql.SQLException; 18 18 import java.sql.ResultSet; 19 20 import org.w3c.dom.Element; 21 import org.w3c.dom.NodeList; 22 19 23 20 24 import java.net.URL; … … 172 176 return resultList; 173 177 } 178 179 /* 180 * 181 * 182 */ 183 public static METSFileSet parseXML(NodeList fileSecs, METSFileSet fileSet, String parseFilePath) { 184 185 //METSFileSet set = new METSFileSet();> 186 // this is in effect a group without a sense of 'self'... 187 for (int c = 0; c < fileSecs.getLength(); c++) { 188 if (fileSecs.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE){ 189 continue; 190 } 191 192 METSFileGroup groups = METSFileGroup.parse_groupXML((Element)fileSecs.item(c), fileSet, parseFilePath, null); 193 } 194 return fileSet; 195 } 196 174 197 175 198 public void write(PrintWriter writer) -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java
r7306 r8461 4 4 5 5 import java.util.List; 6 6 import java.util.Iterator; 7 7 import java.sql.SQLException; 8 8 import java.sql.ResultSet; … … 100 100 public abstract boolean removeMetadata(String label, String value); 101 101 public abstract List getMetadata(String label); 102 public abstract Iterator getMetadataNames(); 102 103 public abstract boolean write(PrintWriter writer); 103 104 // public abstract boolean writeSQL(GS3SQLConnection connection); -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructure.java
r6348 r8461 12 12 import java.sql.ResultSet; 13 13 14 import org.w3c.dom.Element; 15 import org.w3c.dom.NodeList; 16 14 17 import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface; 15 18 … … 22 25 String label; 23 26 String type; 27 METSDivision divGroup; 24 28 25 29 public static final String STRUCTURE_TYPE = "Structure"; … … 30 34 this.label = label; 31 35 this.type = type; 36 this.divGroup = null; 32 37 } 33 38 … … 108 113 } 109 114 115 116 /* 117 * 118 * parse an XML Element as a METSStructure Section 119 * 120 * @param <code>Element</code> the XML element which represents 121 * the mets:structMap itself 122 */ 123 124 public static METSStructure parseXML(Element element) 125 { 126 String structId = element.getAttribute("ID"); 127 String structType = element.getAttribute("TYPE"); 128 String structLabel = element.getAttribute("LABEL"); 129 130 METSStructure thisStruct = new METSStructure (structId, structType, structLabel); 131 132 NodeList divSecs = element.getChildNodes(); 133 if (divSecs != null) { 134 for (int c = 0; c < divSecs.getLength(); c++) { 135 if (divSecs.item(c).getNodeType() != org.w3c.dom.Node.ELEMENT_NODE){ 136 continue; 137 } 138 Element divElement = (Element) divSecs.item(c); 139 String divName = divElement.getNodeName(); 140 if (divName.equals("mets:div")) { 141 METSDivision division = METSDivision.parseXML(divElement); 142 thisStruct.addDivision(division); 143 } else { 144 System.err.println("Error: mets:structMap was expecting mets:div but got "+divName); 145 } 146 } 147 } 148 return thisStruct; 149 } 150 110 151 /** 111 152 * Write this structure in XML(METS) format to a <code>PrintWriter</code> -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java
r6287 r8461 11 11 import java.sql.SQLException; 12 12 import java.sql.ResultSet; 13 14 import org.w3c.dom.Element; 15 import org.w3c.dom.NodeList; 16 17 13 18 14 19 import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface; … … 100 105 return null; 101 106 } 107 public static METSStructureSet parseXML(NodeList structMapSecs) 108 { 109 METSStructureSet set = new METSStructureSet(); 110 111 for (int c = 0; c < structMapSecs.getLength(); c++) { 112 METSStructure structure = METSStructure.parseXML((Element) structMapSecs.item(c)); 113 set.addStructure(structure); 114 } 115 return set; 116 } 117 102 118 103 119 public void write(PrintWriter writer) -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/NamespaceFactory.java
r5800 r8461 32 32 */ 33 33 public static METSNamespace initNamespace(String name, Element element) 34 { return null; 34 { //return null; 35 return new SimpleNamespace(name); 35 36 } 36 37 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/OrderedNamespace.java
r5945 r8461 167 167 return -1; 168 168 } 169 170 public Iterator getMetadataNames() 171 { 172 return this.metadataList.iterator(); 173 } 174 169 175 170 176 /** … … 212 218 protected boolean writeItem(PrintWriter writer, NamespaceItem item) 213 219 { // Do some default sillinesses 220 //writer.write(" "); 214 221 writer.write(XMLTools.getOpenTag(this.name, item.getLabel())); 215 222 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/SimpleNamespace.java
r7306 r8461 164 164 } 165 165 166 public Iterator getMetadataNames() 167 { 168 return this.metadataMap.keySet().iterator(); 169 } 170 166 171 /** 167 172 * Write out the metadata to an XML file through a <code>PrintWriter</code>. … … 221 226 while (values.hasNext()) 222 227 { String value = values.next().toString(); 223 224 writer.write(XMLTools.getOpenTag(this.name, label)); 225 228 String metaTagName = "Metadata name=" +'"'+ label +'"'; 229 //writer.write(XMLTools.getOpenTag(this.name, label)); 230 writer.write(" "); 231 writer.write(XMLTools.getOpenTag(this.name, metaTagName)); 226 232 writer.write(value); 227 233 228 writer.println(XMLTools.getCloseTag(this.name, label)); 234 //writer.println(XMLTools.getCloseTag(this.name, label)); 235 writer.println(XMLTools.getCloseTag(this.name, "Metadata")); 229 236 } 230 237 }
Note:
See TracChangeset
for help on using the changeset viewer.