Ignore:
Timestamp:
2004-01-21T11:21:20+13:00 (20 years ago)
Author:
jmt12
Message:

Fixed bug where legacy metadata sets were not locating the english string if one in the requested language was not found

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  
    446446    String language_code_str = Gatherer.config.getLanguage();
    447447    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));
    449449    if(description.length() > 0) {
    450450        description.append(StaticStrings.SPACE_CHARACTER);
    451451    }
    452     description.append(getElementAttribute(element, StaticStrings.COMMENT_VALUE, language_code_str, false));
     452    description.append(getElementAttribute(element, StaticStrings.COMMENT_VALUE, language_code_str));
    453453    language_code_str = null;
    454454    return description.toString();
     
    459459     * @param attribute_name_str the name of the desired attribute as a String
    460460     * @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 sets
    462461     * @see org.greenstone.gatherer.msm.MSMUtils#getValue
    463462     * @see org.greenstone.gatherer.msm.MSMUtils#isAttributeLanguageDependant
     
    469468     * @see org.greenstone.gatherer.util.StaticStrings#NAME_ATTRIBUTE
    470469     */
    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) {
    472471    boolean found = false;
    473472    String result = StaticStrings.EMPTY_STR;
     473    Document document = element_element.getOwnerDocument();
    474474    // Determine if the attribute is language specific
    475     if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str)) {
     475    if(isAttributeLanguageDependant(document, attribute_name_str)) {
    476476        NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
    477477        for(int i = 0; !found && i < language_elements.getLength(); i++) {
     
    494494    }
    495495    else {
     496        boolean first_match = false;
    496497        NodeList attribute_elements = element_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
    497498        for(int k = 0; !found && k < attribute_elements.getLength(); k++) {
     
    499500        // We don't want to consider those attributes found inside language elements
    500501        if(attribute_element.getParentNode() == element_element) {
     502            ///ystem.err.println("First level");
    501503            String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    502504            String target_language_str = attribute_element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE);
     505            ///ystem.err.println("Does " + target_name_str + " equal " + attribute_name_str + "?");
    503506            if(attribute_name_str.equals(target_name_str)) {
     507            ///ystem.err.println("Does " + target_language_str + " equal " + language_code_str + "?");
    504508            if(language_code_str.equals(target_language_str)) {
     509                ///ystem.err.println("Perfect match!");
    505510                found = true;
    506511                result = MSMUtils.getValue(attribute_element);
    507512            }
    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                }
    511526            }
    512527            }
     
    514529            target_name_str = null;
    515530        }
     531        //else {
     532        ///ystem.err.println("Second level");
     533        //}
    516534        attribute_element = null;
    517535        }
     
    519537
    520538    }
     539    document = null;
    521540    return result;
    522541    }
     
    578597     */
    579598    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());
    581600    // Failing the above we return the nodes name instead.
    582601    if(identifier == null || identifier.length() == 0) {
     
    745764    String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase();
    746765    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);
    747777    }
    748778
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java

    r6549 r6568  
    325325    return description;
    326326    }
     327
    327328    /** Method to retrieve the <strong>Document</strong> associated with this metadata set.
    328329     * @return The <strong>Document</strong> representing this metadata set.
     
    557558    private String getAttribute(String element_name, String default_string) {
    558559    String result = null;
     560
    559561    // Determine the language code.
    560562    current_language_code = Gatherer.config.getLanguage();
     563
     564    ///ystem.err.println("Searching for the " + element_name + " in " + current_language_code);
    561565
    562566    // 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.
     
    565569        Element set_language_element = (Element) set_language_elements.item(b);
    566570        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)) {
    568572        NodeList specific_elements = set_language_element.getElementsByTagName(element_name);
    569573        if(specific_elements.getLength() > 0) {
Note: See TracChangeset for help on using the changeset viewer.