source: trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java@ 7116

Last change on this file since 7116 was 6890, checked in by kjdon, 20 years ago

fixed a typo in a comment

  • Property svn:keywords set to Author Date Id Revision
File size: 26.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.msm;
38
39import java.io.*;
40import java.net.*;
41import java.util.*;
42import org.apache.xerces.dom.*;
43import org.greenstone.gatherer.Dictionary;
44import org.greenstone.gatherer.Gatherer;
45import org.greenstone.gatherer.valuetree.GValueModel;
46import org.greenstone.gatherer.valuetree.GValueNode;
47import org.greenstone.gatherer.util.StaticStrings;
48import org.greenstone.gatherer.util.Utility;
49import org.w3c.dom.*;
50/** An semi-data class to hold details about a loaded metadata set, it also provides some methods to manipulating the data within.
51 * @author John Thompson, Greenstone Digital Library, University of Waikato
52 * @version 2.3b
53 */
54public class MetadataSet {
55 /** The <Strong>Document</strong> of the DOM model. */
56 private Document document = null;
57 /** The document <strong>Element</strong> of the DOM model. */
58 private Element root = null;
59 /** The <strong>File</strong> this metadata set was loaded from. */
60 private File file = null;
61 /** A mapping from metadata elements to the root element of the value trees for that element. */
62 private Hashtable value_trees = null;
63 /** The list of metadata elements which are, of course, children of the root node. */
64 private NodeList elements = null;
65
66 private String current_language_code;
67 /** The description of this metadata set. Cached as it takes more computation time. */
68 private String description = null;
69 /** The name of this metadata set. Cached as it takes more computation time. */
70 private String name = null;
71 /** An element of the tree pruning filter enumeration, that indicates all nodes in the tree should be retained. */
72 static final int ALL_VALUES = 1;
73 /** An element of the tree pruning filter enumeration, that indicates only metadata Subject nodes or higher should remain after pruning. */
74 static final int SUBJECTS_ONLY = 2;
75 /** An element of the tree pruning filter enumeration, that indicates no value nodes i.e. the entire AssignedValues subtree, should remain after pruning. */
76 static final int NO_VALUES = 3;
77
78 public MetadataSet(String metadata_template) {
79 URL url = ClassLoader.getSystemResource(metadata_template);
80 try {
81 init(new File(URLDecoder.decode(url.getFile(), "UTF-8")));
82 }
83 catch(UnsupportedEncodingException exception) {
84 Gatherer.printStackTrace(exception);
85 }
86 }
87
88 /** Constructor.
89 * @param file The file the metadata set should be loaded from.
90 */
91 public MetadataSet(File file) {
92 init(file);
93 }
94
95 /** Metadata Set already parsed constructor.
96 * @param file The file the metadata was loaded from.
97 * @param document The DOM model <strong>Document</strong> containing the metadata set.
98 */
99 public MetadataSet(File file, Document document) {
100 this.document = document;
101 this.elements = document.getElementsByTagName("Element");
102 this.file = file;
103 this.root = document.getDocumentElement();
104 this.value_trees = new Hashtable();
105 // Now for each element read in its value tree if present.
106 for(int i = elements.getLength() - 1; i >= 0; i--) {
107 ElementWrapper value_element = new ElementWrapper((Element)elements.item(i));
108 File value_file = new File(file.getParentFile(), value_element.getName() + ".mdv");
109 ///ystem.err.println("Searching for " + value_file.getAbsolutePath());
110 if(value_file.exists()) {
111 Document value_document = Utility.parse(value_file, false);
112 if(value_document != null) {
113 value_trees.put(value_element, new GValueModel(value_element, value_document));
114 }
115 //else {
116 //atherer.println("Error! Missing mdv file: " + value_file.getAbsolutePath());
117 //}
118 }
119 }
120 }
121 /** Copy constructor.
122 * @param original The original metadata set to copy from.
123 */
124 public MetadataSet(MetadataSet original) {
125 this.value_trees = new Hashtable();
126 // We have to create a new document.
127 document = new DocumentImpl(original.getDocument().getDoctype());
128 root = (Element) document.importNode(original.getDocument().getDocumentElement(), true);
129 document.appendChild(root);
130 elements = root.getElementsByTagName("Element");
131 file = original.getFile();
132 // Now for each element read in its value tree if present.
133 for(int i = elements.getLength() - 1; i >= 0; i--) {
134 ElementWrapper value_element_wrapper = new ElementWrapper((Element)elements.item(i));
135 GValueModel value_tree = original.getValueTree(value_element_wrapper);
136 Document value_document = value_tree.getDocument();
137 Document value_document_copy = new DocumentImpl(value_document.getDoctype());
138 Element value_element = value_document.getDocumentElement();
139 Element value_element_copy = (Element) value_document_copy.importNode(value_element, true);
140 value_document_copy.appendChild(value_element_copy);
141 GValueModel value_tree_copy = new GValueModel(value_element_wrapper, value_document_copy);
142 value_trees.put(value_element_wrapper, value_tree_copy);
143 }
144 }
145 /** Conditional copy constructor.
146 * @param original The original metadata set to copy from.
147 * @param condition An <i>int</i> which matches one of the tree pruning filter types.
148 */
149 public MetadataSet(MetadataSet original, int condition) {
150 this(original);
151 // Now based on condition, we may have to remove some nodes from
152 // this model.
153 switch(condition) {
154 case ALL_VALUES:
155 // Do nothing.
156 break;
157 case SUBJECTS_ONLY:
158 // For each element retrieve its AssignedValues element.
159 for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
160 ElementWrapper value_element = (ElementWrapper)keys.nextElement();
161 GValueModel value_tree = (GValueModel)value_trees.get(value_element);
162 Document value_tree_document = value_tree.getDocument();
163 Element value_tree_root_element = value_tree_document.getDocumentElement();
164 // Traverse tree and remove leaf nodes.
165 MSMUtils.traverseTree(value_tree_root_element, MSMUtils.NONE, true);
166 }
167 break;
168 case NO_VALUES:
169 // Remove assigned values trees.
170 value_trees.clear();
171 break;
172 }
173 }
174
175 /** Add a mds level attribute.
176 * @param name The name of the attribute to add as a <Strong>String</strong>.
177 * @param value The value as a <strong>String</strong>.
178 */
179 public void addAttribute(String name, String value) {
180 root.setAttribute(name, value);
181 }
182
183 /** Add a new default metadata element with the given name to this metadata set.
184 * @param name The name of this element as a <strong>String</strong>.
185 * @return An <strong>ElementWrapper</strong> around the newly created element or null if the element was not created.
186 */
187 public ElementWrapper addElement(String name, String language)
188 {
189 Text text = document.createTextNode(name);
190 Element identifier = document.createElementNS("","Attribute");
191 identifier.setAttribute("name","identifier");
192 identifier.setAttribute("language", language);
193 identifier.appendChild(text);
194 Element element = document.createElementNS("","Element");
195 element.setAttribute("name",name);
196 element.appendChild(identifier);
197 root.appendChild(element);
198 return new ElementWrapper(element);
199 }
200
201 /** Method to add a new metadata element to this metadata set, if and only if the element is not already present.
202 * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
203 * @param model A <strong>GValueModel</strong> value tree
204 * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
205 */
206 public String addElement(Element others_element, GValueModel model) {
207 if(!containsElement(others_element.getAttribute("name"))) {
208 // First get ownership of the new element, then add it.
209 Element our_element = (Element)document.importNode(others_element, true);
210 // add the value tree
211 root.appendChild(our_element);
212 if (model != null) {
213 addValueTree(new ElementWrapper(our_element), model);
214 }
215 return null;
216 }
217 else {
218 return "MSMPrompt.Name_Exists";
219 }
220 }
221
222 /** Method to add a new metadata element with the specified new name to this metadata set, if and only if the name is not already in use.
223 * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
224 * @param new_name The new name to be given this element, as a <strong>String</strong>.
225 * @param model A <strong>GValueModel</strong> value tree
226 * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
227 */
228 public String addElement(Element others_element, String new_name, GValueModel model) {
229 if(!containsElement(new_name)) {
230 // First get ownership of the new element, then add it.
231 Element our_element =
232 (Element) document.importNode(others_element, true);
233 // Change name
234 our_element.setAttribute("name", new_name);
235 // we also want to change the english identifier of this element
236 MSMUtils.setIdentifier(our_element, new_name);
237 // Add it to teh set
238 root.appendChild(our_element);
239 // add the value tree
240 if (model != null) {
241 addValueTree(new ElementWrapper(our_element), model);
242 }
243 return null;
244 }
245 else {
246 return "MSMPrompt.Name_Exists";
247 }
248 }
249 /** Add a value tree to a given metadata element.
250 * @param element The <strong>ElementWrapper</strong> containing the element you wish to add a value tree for.
251 * @param model A <strong>GValueModel</strong> value tree
252 */
253 public void addValueTree(ElementWrapper element, GValueModel model) {
254 ///ystem.err.println("Adding value tree for " + element.toString());
255 value_trees.put(element, model);
256 }
257
258 public int compare(Element e1, Element e2) {
259 int result = 0;
260 // Check that they're not the same element.
261 if(e1 != e2) {
262 int index_e1 = -1;
263 int index_e2 = -1;
264 // Locate the indexes for each element.
265 for(int i = 0; i < elements.getLength(); i++) {
266 Node element = elements.item(i);
267 if(element == e1) {
268 index_e1 = i;
269 }
270 if(element == e2) {
271 index_e2 = i;
272 }
273 }
274 if(index_e1 < index_e2) {
275 result = -1;
276 }
277 else {
278 result = 1;
279 }
280 }
281 return result;
282 }
283
284 /** A method to determine if this metadata set contains an element with a certain name (case sensitive).
285 * @param name A <strong>String</strong> which is the name of the element whose presence we are checking.
286 * @return A <i>boolean</i> which is <i>true</i> if the named element exists, <i>false</i> otherwise.
287 */
288 public boolean containsElement(String name) {
289 for(int i = 0; i < elements.getLength(); i++) {
290 Element sibling = (Element) elements.item(i);
291 String sibling_name = sibling.getAttribute("name");
292 if(sibling_name.equals(name)) {
293 return true;
294 }
295 }
296 return false;
297 }
298
299 public NamedNodeMap getAttributes() {
300 return root.getAttributes();
301 }
302
303 /** Method to retrieve the contact address of the metadata set creator.
304 * @return A <strong>String</strong> containing the address.
305 */
306 /* private String getContact() {
307 return root.getAttribute("contact");
308 } */
309 /** Method to retrieve the name of the creator of this metadata set.
310 * @return A <strong>String</strong> containing the name.
311 */
312 public String getCreator() {
313 return root.getAttribute("creator");
314 }
315 /** Method to retrieve the description of this metadata set. Note that this is language specific, so we determine the desired language from the Dictionary. If no such entry exists, first try returning the english version and failing that the first description found.
316 * @return The description as a <strong>String</strong>.
317 */
318 public String getDescription() {
319 if(current_language_code != null && !Gatherer.config.getLanguage().equals(current_language_code)) {
320 description = null;
321 }
322 if(description == null) {
323 description = getAttribute(StaticStrings.DESCRIPTION_ELEMENT, Dictionary.get("MSM.No_Description"));
324 }
325 return description;
326 }
327
328 /** Method to retrieve the <strong>Document</strong> associated with this metadata set.
329 * @return The <strong>Document</strong> representing this metadata set.
330 */
331 public Document getDocument() {
332 return document;
333 }
334 /** Method to retrieve the metadata element indicated by an index.
335 * @param index An <i>int</i> specifying the required element.
336 * @return The <strong>Element</strong> at the index.
337 */
338 public Element getElement(int index) {
339 return (Element)elements.item(index);
340 }
341 /** This method is used to acquire a reference to the element which matches the given metadata. Note that this is not the same as <i>metadata.getElement()</i> as the reference returned by it may now be obsolete.
342 * @param metadata A <strong>Metadata</strong> object representing an element and value assignment.
343 * @return A 'live' reference to an <strong>Element</strong> which is the same as that referenced by the given metadata, or <i>null</i> if there is no such element.
344 */
345 public Element getElement(Metadata metadata) {
346 return metadata.getElement().getElement();
347 }
348 /** This method is used to acquire a reference to the element which has the name specified. Note that this is not the same as <i>metadata.getElement()</i> as the reference returned by it may now be obsolete.
349 * @param name A <strong>String</strong> stating the desired objects name.
350 * @return A 'live' reference to an <strong>Element</strong> which is the same as that referenced by the given metadata, or <i>null</i> if there is no such element.
351 */
352 public Element getElement(String name) {
353 // Strip any namespace.
354 while(name.indexOf(".") != -1 && !name.equals(".")) {
355 name = name.substring(name.indexOf(".") + 1);
356 }
357 ///ystem.err.println("Get element named " + name);
358 for(int i = 0; i < elements.getLength(); i++) {
359 Element element = (Element) elements.item(i);
360 ///ystem.err.println("Compare to: " + element.getAttribute("name"));
361 if(element.getAttribute("name").equals(name)) {
362 return element;
363 }
364 }
365 return null;
366 }
367
368 public Element getElement(Element parent_element, String name) {
369 Gatherer.println("Get element named " + name + " from " + parent_element.getAttribute("name"));
370 NodeList elements = parent_element.getElementsByTagName("Element");
371 for(int i = 0; i < elements.getLength(); i++) {
372 Element element = (Element) elements.item(i);
373 if(element.getAttribute("name").equals(name) && element.getParentNode() == parent_element) {
374 elements = null;
375 return element;
376 }
377 }
378 elements = null;
379 return null;
380 }
381 /** Method to acquire a list of all the elements in this metadata set.
382 * @return A <strong>NodeList</strong> containing all of this sets elements.
383 */
384 public NodeList getElements() {
385 return elements;
386 }
387
388 /** Method to retrieve a list of all the elements in this metadata set, sorted.
389 * @return A <strong>Vector</strong> containing all of the elements of this sets, sorted.
390 */
391 public Vector getElementsSorted() {
392 Vector elements_list = new Vector();
393 for (int i = 0; i < elements.getLength(); i++) {
394 elements_list.add(new ElementWrapper((Element) elements.item(i)));
395 }
396 Collections.sort(elements_list, MSMUtils.METADATA_COMPARATOR);
397 return elements_list;
398 }
399
400 /** Method to retrieve the original file this metadata set was created from.
401 * @return A <strong>File</strong>.
402 */
403 public File getFile() {
404 return file;
405 }
406 /** Get the last changed attribute.
407 * @return Last changed as a <strong>String</strong>.
408 */
409 public String getLastChanged() {
410 return root.getAttribute("lastchanged");
411 }
412 /** Method to get this metadata sets name. Note that this is language specific, so we determine the desired language from the Dictionary. If no such entry exists, first try returning the english version and failing that the first name found.
413 * @return A <strong>String</strong> which contains its name.
414 */
415 public String getName() {
416 if(current_language_code != null && !Gatherer.config.getLanguage().equals(current_language_code)) {
417 name = null;
418 }
419 if(name == null) {
420 name = getAttribute(StaticStrings.NAME_ELEMENT, Dictionary.get("MSM.No_Name"));
421 }
422 return name;
423 }
424 /** Method to retrieve this metadata sets namespace.
425 * @return The namespace as a <strong>String</strong>.
426 */
427 public String getNamespace() {
428 return root.getAttribute("namespace");
429 }
430 /** Method to retrieve the root element, i.e. the Document Element, of the DOM model behind this metadata set.
431 * @return An <strong>Element</strong> which is at the root of the modal.
432 */
433 public Element getRoot() {
434 return root;
435 }
436 /** Retrieve the value tree from this set that matches the given element.
437 * @param element The target <strong>ElementWrapper</strong>.
438 * @return A <strong>GValueModel</strong> value tree, or <i>null</i> if no such element or value tree.
439 */
440 public GValueModel getValueTree(ElementWrapper element) {
441 GValueModel value_tree = null;
442 // Stinking hashtable get doesn't use the overridden equals. So I'll do a loop, which should be pretty small ie O(n) for n metadata elements.
443 for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
444 ElementWrapper sibling = (ElementWrapper) keys.nextElement();
445 if(sibling.equals(element)) {
446 value_tree = (GValueModel) value_trees.get(sibling);
447 break;
448 }
449 }
450 // If we've found no value tree, create a new one.
451 if(value_tree == null) {
452 value_tree = new GValueModel(element);
453 value_trees.put(element, value_tree);
454 }
455 return value_tree;
456 }
457 /** Remove a mds level attribute.
458 * @param name The name of the attribute to remove.
459 */
460 public void removeAttribute(String name) {
461 root.removeAttribute(name);
462 }
463 /** Method to remove the given element from this metadata set.
464 * @param element The <strong>Element</strong> to be removed.
465 */
466 public void removeElement(Element element) {
467 // we need to remove the value tree too!!
468 removeValueTree(new ElementWrapper(element));
469 root.removeChild(element);
470 }
471 /** Used to remove the value tree for a specific element.
472 * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove.
473 * @return The <strong>GValueModel</strong> we just removed
474 */
475 public GValueModel removeValueTree(ElementWrapper element) {
476 for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
477 ElementWrapper sibling = (ElementWrapper) keys.nextElement();
478 if(sibling.equals(element)) {
479 GValueModel value_tree = (GValueModel) value_trees.get(sibling);
480 value_trees.remove(sibling);
481 return value_tree;
482 }
483 }
484 return null;
485 }
486 /** Set one of the mds level attributes.
487 * @param name The attribute to change.
488 * @param value its new value.
489 */
490 public void setAttribute(String name, String value) {
491 root.setAttribute(name, value);
492 }
493 /** Once the metadata set has been saved to a different location, this is used to update the file parameter.
494 * @param file The new location of this metadata set <strong>File</strong>.
495 */
496 public void setFile(File file) {
497 this.file = file;
498 }
499
500 public void setName(String name) {
501 // Retrieve the name element. We look for the first english one.
502 Element name_element = null;
503 Element metadataset_element = document.getDocumentElement();
504 NodeList name_elements = metadataset_element.getElementsByTagName(Utility.NAME_ELEMENT);
505 for(int i = 0; i < name_elements.getLength(); i++) {
506 Element possible_name_element = (Element) name_elements.item(i);
507 if(possible_name_element.getAttribute(Utility.LANGUAGE_ATTRIBUTE).equals(Utility.ENGLISH_VALUE)) {
508 // Found it.
509 name_element = possible_name_element;
510 }
511 }
512 // If there is none add one. Note that we can only add english metadata sets. Although others can edit them to add further names as necessary.
513 if(name_element == null) {
514 name_element = document.createElement(Utility.NAME_ELEMENT);
515 name_element.setAttribute(Utility.LANGUAGE_ATTRIBUTE, Utility.ENGLISH_VALUE);
516 metadataset_element.insertBefore(name_element, metadataset_element.getFirstChild());
517 }
518 // Replace the text node
519 while(name_element.hasChildNodes()) {
520 name_element.removeChild(name_element.getFirstChild());
521 }
522 name_element.appendChild(document.createTextNode(name));
523 }
524
525 /** Method to determine the number of elements in this set.
526 * @return An <i>int</i> specifying the element count.
527 */
528 public int size() {
529 return elements.getLength();
530 }
531 /** Method to translate this class into a meaningful string, which in this case is the metadata sets name.
532 * @return The metadata sets name as a <strong>String</strong>.
533 */
534 public String toString() {
535 String name = getName();
536 // If there is no given name, then use the namespace as there is garaunteed to be one of them.
537 if(name == null || name.length() == 0) {
538 name = root.getAttribute("namespace");
539 }
540 // Append namespace
541 String namespace = root.getAttribute("namespace");
542 if(namespace == null || namespace.equals("")) {
543 namespace = Utility.EXTRACTED_METADATA_NAMESPACE;
544 }
545 name = name + " (" + namespace + ")";
546 return name;
547 }
548
549 /** This method retrieves the required attribute from the Metadata Set, typically it's name or it's description. Note that this method is language dependant, and moreover supports both legacy metadata sets and the new sets optimized for multiple languages.
550 * @param element_name the name of the type of element the required information is in as a String
551 * @param default_string the value to return if no such element is found also as a String
552 * @see org.greenstone.gatherer.Configuration#getLanguage()
553 * @see org.greenstone.gatherer.Gatherer#config
554 * @see org.greenstone.gatherer.msm.MSMUtils#getValue(Node)
555 * @see org.greenstone.gatherer.util.StaticStrings#CODE_ATTRIBUTE
556 * @see org.greenstone.gatherer.util.StaticStrings#SETLANGUAGE_ELEMENT
557 */
558 private String getAttribute(String element_name, String default_string) {
559 String result = null;
560
561 // Determine the language code.
562 current_language_code = Gatherer.config.getLanguage();
563
564 ///ystem.err.println("Searching for the " + element_name + " in " + current_language_code);
565
566 // New Metadata Set Format makes use of deferred-node-expansion to save memory - rather than create nodes for a name and description in each language, nodes which have potentially huge strings, we instead create simplier SETLANGUAGE nodes, and then only expand the one in the desired language. Of course if a user happens to change to every available language slightly more memory will be used than in the old method. For instance consider the DLS with 25 languages, each with a name node of 50 bytes and an descriptions of 500. Thus old style > 13750 bytes while new style < 600.
567 NodeList set_language_elements = document.getElementsByTagName(StaticStrings.SETLANGUAGE_ELEMENT);
568 for(int b = 0; b < set_language_elements.getLength(); b++) {
569 Element set_language_element = (Element) set_language_elements.item(b);
570 String code = set_language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).toLowerCase();
571 if(code.equals(current_language_code)) {
572 NodeList specific_elements = set_language_element.getElementsByTagName(element_name);
573 if(specific_elements.getLength() > 0) {
574 Element specific_element = (Element) specific_elements.item(0);
575 result = MSMUtils.getValue(specific_element);
576 specific_element = null;
577 }
578 specific_elements = null;
579 }
580 code = null;
581 set_language_element = null;
582 }
583 set_language_elements = null;
584 // And we may be all done
585 if(result != null) {
586 return result;
587 }
588
589 // Failing that we move on to an older style search - start by recovering all Name elements
590 NodeList possible_elements = document.getElementsByTagName(element_name);
591 // Iterate through the available names looking for the appropriate one. Also make note of the first name, then overwrite it with any english one.
592 boolean found = false;
593 for(int i = 0; !found && i < possible_elements.getLength(); i++) {
594 Element possible_element = (Element) possible_elements.item(i);
595 String possible_element_code = possible_element.getAttribute("language").toLowerCase();
596 if(possible_element_code.equals(current_language_code) || name == null) {
597 result = MSMUtils.getValue(possible_element);
598 found = true;
599 }
600 possible_element_code = null;
601 possible_element = null;
602 }
603 possible_elements = null;
604 // Failing all that set an error message
605 if(result == null) {
606 result = default_string;
607 }
608 return result;
609 }
610
611 private void init(File file) {
612 this.file = file;
613 this.value_trees = new Hashtable();
614 this.document = Utility.parse(file, false);
615 if(document != null) {
616 this.elements = document.getElementsByTagName("Element");
617 this.root = document.getDocumentElement();
618 // Now for each element read in its value tree if present.
619 for(int i = elements.getLength() - 1; i >= 0; i--) {
620 ElementWrapper value_element = new ElementWrapper((Element)elements.item(i));
621 File value_file = new File(file.getParentFile(), value_element.getName() + ".mdv");
622 ///ystem.err.println("Searching for " + value_file.getAbsolutePath());
623 if(value_file.exists()) {
624 Document value_document = Utility.parse(value_file, false);
625 if(value_document != null) {
626 value_trees.put(value_element, new GValueModel(value_element, value_document));
627 }
628 else {
629 Gatherer.println("Error! Missing mdv file: " + value_file.getAbsolutePath());
630 }
631 }
632 }
633 }
634 else {
635 Gatherer.println("Error! Missing mds file: " + file.getAbsolutePath());
636 }
637 }
638}
Note: See TracBrowser for help on using the repository browser.