Changeset 6568 for trunk/gli/src/org/greenstone/gatherer/msm
- Timestamp:
- 2004-01-21T11:21:20+13:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/msm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/msm/MSMUtils.java
r6549 r6568 446 446 String language_code_str = Gatherer.config.getLanguage(); 447 447 StringBuffer description = new StringBuffer(StaticStrings.EMPTY_STR); 448 description.append(getElementAttribute(element, StaticStrings.DEFINITION_VALUE, language_code_str , false));448 description.append(getElementAttribute(element, StaticStrings.DEFINITION_VALUE, language_code_str)); 449 449 if(description.length() > 0) { 450 450 description.append(StaticStrings.SPACE_CHARACTER); 451 451 } 452 description.append(getElementAttribute(element, StaticStrings.COMMENT_VALUE, language_code_str , false));452 description.append(getElementAttribute(element, StaticStrings.COMMENT_VALUE, language_code_str)); 453 453 language_code_str = null; 454 454 return description.toString(); … … 459 459 * @param attribute_name_str the name of the desired attribute as a String 460 460 * @param language_code_str the two letter code String indicating the desired language 461 * @param first_match true to allow the first match to be the default value in the absence of a closer match, false for the empty string instead. This argument only has an effect when dealing with legacy metadata sets462 461 * @see org.greenstone.gatherer.msm.MSMUtils#getValue 463 462 * @see org.greenstone.gatherer.msm.MSMUtils#isAttributeLanguageDependant … … 469 468 * @see org.greenstone.gatherer.util.StaticStrings#NAME_ATTRIBUTE 470 469 */ 471 static public String getElementAttribute(Element element_element, String attribute_name_str, String language_code_str , boolean first_match) {470 static public String getElementAttribute(Element element_element, String attribute_name_str, String language_code_str) { 472 471 boolean found = false; 473 472 String result = StaticStrings.EMPTY_STR; 473 Document document = element_element.getOwnerDocument(); 474 474 // Determine if the attribute is language specific 475 if(isAttributeLanguageDependant( element_element.getOwnerDocument(), attribute_name_str)) {475 if(isAttributeLanguageDependant(document, attribute_name_str)) { 476 476 NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT); 477 477 for(int i = 0; !found && i < language_elements.getLength(); i++) { … … 494 494 } 495 495 else { 496 boolean first_match = false; 496 497 NodeList attribute_elements = element_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT); 497 498 for(int k = 0; !found && k < attribute_elements.getLength(); k++) { … … 499 500 // We don't want to consider those attributes found inside language elements 500 501 if(attribute_element.getParentNode() == element_element) { 502 ///ystem.err.println("First level"); 501 503 String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 502 504 String target_language_str = attribute_element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE); 505 ///ystem.err.println("Does " + target_name_str + " equal " + attribute_name_str + "?"); 503 506 if(attribute_name_str.equals(target_name_str)) { 507 ///ystem.err.println("Does " + target_language_str + " equal " + language_code_str + "?"); 504 508 if(language_code_str.equals(target_language_str)) { 509 ///ystem.err.println("Perfect match!"); 505 510 found = true; 506 511 result = MSMUtils.getValue(attribute_element); 507 512 } 508 else if(first_match) { 509 first_match = false; 510 result = MSMUtils.getValue(attribute_element); 513 else if((result == StaticStrings.EMPTY_STR || first_match) && isLegacyMDS(document)) { 514 ///ystem.err.println("Legacy MDS"); 515 // Special case for old style documents, where the english match is good enough 516 if(target_language_str.equals(StaticStrings.ENGLISH_LANGUAGE_STR)) { 517 ///ystem.err.println("English plate."); 518 result = MSMUtils.getValue(attribute_element); 519 } 520 // Super special case where the first match is better than nothing 521 else if(result == StaticStrings.EMPTY_STR && !first_match) { 522 ///ystem.err.println("First match."); 523 first_match = true; 524 result = MSMUtils.getValue(attribute_element); 525 } 511 526 } 512 527 } … … 514 529 target_name_str = null; 515 530 } 531 //else { 532 ///ystem.err.println("Second level"); 533 //} 516 534 attribute_element = null; 517 535 } … … 519 537 520 538 } 539 document = null; 521 540 return result; 522 541 } … … 578 597 */ 579 598 static final public String getIdentifier(Element element) { 580 String identifier = getElementAttribute(element, StaticStrings.IDENTIFIER_VALUE, Gatherer.config.getLanguage() , false);599 String identifier = getElementAttribute(element, StaticStrings.IDENTIFIER_VALUE, Gatherer.config.getLanguage()); 581 600 // Failing the above we return the nodes name instead. 582 601 if(identifier == null || identifier.length() == 0) { … … 745 764 String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase(); 746 765 return language_specific_attributes.indexOf(attribute_name_str) != -1; 766 } 767 768 /** Determine if the given document is a legacy MDS or a new multilingual one. The easiest way to tell is whether there is a language_dependant attribute in the document element. 769 * @param document the Document to test 770 * @return true if this is an old mds, false otherwise 771 * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGEDEPENDANT_ATTRIBUTE 772 * @see org.greenstone.gatherer.util.StaticStrings#EMPTY_STR 773 */ 774 static public boolean isLegacyMDS(Document document) { 775 ///ystem.err.println("isLegacyMDS(): l_d = " + document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE)); 776 return (document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE)).equals(StaticStrings.EMPTY_STR); 747 777 } 748 778 -
trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java
r6549 r6568 325 325 return description; 326 326 } 327 327 328 /** Method to retrieve the <strong>Document</strong> associated with this metadata set. 328 329 * @return The <strong>Document</strong> representing this metadata set. … … 557 558 private String getAttribute(String element_name, String default_string) { 558 559 String result = null; 560 559 561 // Determine the language code. 560 562 current_language_code = Gatherer.config.getLanguage(); 563 564 ///ystem.err.println("Searching for the " + element_name + " in " + current_language_code); 561 565 562 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. … … 565 569 Element set_language_element = (Element) set_language_elements.item(b); 566 570 String code = set_language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).toLowerCase(); 567 if(code.equals(current_language_code) || name == null) {571 if(code.equals(current_language_code)) { 568 572 NodeList specific_elements = set_language_element.getElementsByTagName(element_name); 569 573 if(specific_elements.getLength() > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.