Changeset 8460
- Timestamp:
- 2004-11-05T10:08:31+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/METSDocument.java
r8448 r8460 18 18 19 19 import org.greenstone.gsdl3.gs3build.metadata.*; 20 import org.greenstone.gsdl3.gs3build.util.HTMLDoc; 21 import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface; 22 import org.greenstone.gsdl3.gs3build.xpointer.XPointer; 20 23 21 24 public class METSDocument extends AbstractDocument { 22 25 23 26 public static final String METS_DOCUMENT_TYPE = "METS"; 27 Document domDocument; 28 public METSDocument(DocumentID id) { 29 super(id); 30 //domDocument = null; 31 } 24 32 25 33 public METSDocument(URL url) { … … 28 36 if (url.getProtocol().equals("file")) { 29 37 this._parseFile(new File(url.getPath())); 30 } 38 } else { 39 System.err.println("Error: METSDocument must currently be a file"); 40 System.err.println(" URL = " + url.getPath()); 41 } 31 42 } 32 43 33 44 private void _parseFile(File file) { 34 45 46 String parseFilePath; 35 47 try { 36 48 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 37 49 DocumentBuilder builder = factory.newDocumentBuilder(); 38 Document document = builder.parse(file); 39 50 domDocument = builder.parse(file); 51 52 int filePosition = file.getPath().indexOf("import/")+7; 53 parseFilePath = file.getPath().substring(0, filePosition); 40 54 // TODO: get all the types in the tree 41 55 … … 46 60 System.out.println("Read"); 47 61 48 NodeList fileSecs = document.getElementsByTagName("mets:fileSec"); 49 50 for (int g = 0; g < fileSecs.getLength(); g ++) { 62 // Get METSDmdSec metadata sections 63 NodeList dmdSecs = domDocument.getElementsByTagName("mets:dmdSec"); 64 65 this.metadata = METSDescriptiveSet.parseXML(dmdSecs); 66 67 // Get METSFileSec sections 68 NodeList fileSecs = domDocument.getElementsByTagName("mets:fileSec"); 69 this.fileSet = METSFileSet.parseXML(fileSecs, fileSet, parseFilePath); 70 // Get METSStructureMap Sections 71 NodeList structMapSecs = domDocument.getElementsByTagName("mets:structMap"); 72 this.structureSet = METSStructureSet.parseXML(structMapSecs); 73 74 //for (int g = 0; g < fileSecs.getLength(); g ++) { 51 75 //Schema schema = new Schema(schemas.item(s)); 52 this._parseFileSec(fileSecs.item(g));53 }76 //this._parseFileSec(fileSecs.item(g)); 77 //} 54 78 55 79 // Get document metadata sections 56 NodeList dmdSecs = document.getElementsByTagName("mets:dmdSec");80 //NodeList dmdSecs = document.getElementsByTagName("mets:dmdSec"); 57 81 58 82 //Schema schema = new Schema(schemas.item(s)); 59 this.metadata = METSDescriptiveSet.parseXML(fileSecs); 60 } 61 catch (FactoryConfigurationError e) { 83 //this.metadata = METSDescriptiveSet.parseXML(fileSecs); 84 } catch (FactoryConfigurationError e) { 62 85 System.out.println(e); 63 } 64 catch (ParserConfigurationException ex) { 86 } catch (ParserConfigurationException ex) { 65 87 System.out.println(ex); 66 } 67 catch (SAXException ex) { 88 } catch (SAXException ex) { 68 89 System.out.println(ex); 69 } 70 catch (IOException ex) { 90 } catch (IOException ex) { 71 91 System.out.println(ex); 72 92 } 73 93 } 74 94 /* 75 95 private void _parseFileSec(Node fileSec) { 76 96 // this is in effect a group without a sense of 'self'... … … 108 128 } 109 129 } 110 } 130 }*/ 111 131 112 132 public String getDocumentType() { … … 116 136 public String getDocumentText() { 117 137 // TODO: make this more than a dummy function! 118 return null; 119 } 120 121 public String getSectionText(String sectionId) { 122 return null; 123 } 124 138 HTMLDoc metsDoc; 139 URL url = (URL) this.fileSet.getFile(0).getLocation(); 140 141 this.getSectionText("1"); 142 143 if (url.getProtocol().equals("file")) { 144 metsDoc = new HTMLDoc(url,url.getPath()); 145 } else { 146 metsDoc = new HTMLDoc(url); 147 } 148 return metsDoc.getContent(); 149 } 150 public Document getDOMDocument() 151 { 152 if (domDocument == null) { 153 URL url = (URL) this.fileSet.getFile(0).getLocation(); 154 try { 155 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 156 DocumentBuilder builder = factory.newDocumentBuilder(); 157 domDocument = builder.parse(new File(url.getPath())); 158 } catch (FactoryConfigurationError e) { 159 System.out.println(e); 160 } catch (ParserConfigurationException ex) { 161 System.out.println(ex); 162 } catch (SAXException ex) { 163 System.out.println(ex); 164 } catch (IOException ex) { 165 System.out.println(ex); 166 } 167 } 168 return domDocument; 169 } 170 171 private XPointer getXPointer(METSDivision division) 172 { 173 String fileId = division.getDefaultFileReference(); 174 175 if (fileId == null) { 176 System.err.println("Unable to obtain file reference for section " + division.getLabel()); 177 return null; 178 } 179 180 METSFileGroup fileGroup = this.getDocumentFiles().getGroup(fileId); 181 if (fileGroup == null) { 182 System.err.println("Unable to obtain file reference for filegroup " + fileId); 183 return null; 184 } 185 METSFile file = fileGroup.getFile(0); 186 if (file == null) { 187 System.err.println("Unable to obtain any files within filegroup " + fileId); 188 return null; 189 } 190 URL url = file.getLocation(); 191 XPointer xpointer = XPointer.processXPointer(domDocument, url); 192 193 return xpointer; 194 } 195 196 private XPointer getXPointer(String sectionId) 197 { 198 if (domDocument == null) { 199 URL url = (URL) this.fileSet.getFile(0).getLocation(); 200 try { 201 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 202 DocumentBuilder builder = factory.newDocumentBuilder(); 203 domDocument = builder.parse(new File(url.getPath())); 204 } catch (FactoryConfigurationError e) { 205 System.out.println(e); 206 } catch (ParserConfigurationException ex) { 207 System.out.println(ex); 208 } catch (SAXException ex) { 209 System.out.println(ex); 210 } catch (IOException ex) { 211 System.out.println(ex); 212 } 213 } 214 215 METSDivision division = 216 this.getDocumentStructure().getDivision(METSStructureSet.GSDL3_SECTION_STRUCTURE, sectionId); 217 218 if(division == null) { 219 return null; 220 } 221 return this.getXPointer(division); 222 } 223 224 public Node getSectionStartNode(METSDivision division) 225 { 226 XPointer xpointer = this.getXPointer(division); 227 return xpointer.getStartNode(); 228 } 229 230 public Node getSectionStartNode(String sectionId) 231 { 232 XPointer xpointer = this.getXPointer(sectionId); 233 return xpointer.getStartNode(); 234 } 235 236 public String getSectionText(String sectionId) 237 { 238 XPointer xpointer = this.getXPointer(sectionId); 239 240 if (xpointer == null) { 241 return ""; 242 } 243 244 //get the XML content of the xpointer 245 return xpointer.toString(); 246 } 125 247 } 248 249
Note:
See TracChangeset
for help on using the changeset viewer.