Changeset 5930


Ignore:
Timestamp:
2003-11-21T10:57:52+13:00 (20 years ago)
Author:
jmt12
Message:

Metadata is now only written to collect.cfg if assigned. It used to instead return an empty string if no value was set - which of course meant that any two different collection meta which just happened to have no strings set were taken as the same object by the equals method in the DOMProxyListModel

Location:
trunk/gli/src/org/greenstone/gatherer/cdm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java

    r5907 r5930  
    737737    boolean special = false;
    738738    // If there is no value attribute, then we don't write anything
     739    StringBuffer text = new StringBuffer("");
     740    String name_str = command_element.getAttribute(NAME_ATTRIBUTE);
     741    // If the name is one of the special four, we don't write the collectionmeta first. Note the maintainer collectionmeta is singled out for 'prittying' reasons.
     742    if(name_str.equals(COLLECTIONMETADATA_MAINTAINER_STR)) {
     743        text.append(name_str);
     744        text.append(TAB_CHARACTER);
     745        special = true;
     746    }
     747    else if(name_str.equals(COLLECTIONMETADATA_BETA_STR) || name_str.equals(COLLECTIONMETADATA_CREATOR_STR) || name_str.equals(COLLECTIONMETADATA_PUBLIC_STR)) {
     748        text.append(name_str);
     749        text.append(TAB_CHARACTER);
     750        text.append(TAB_CHARACTER);
     751        special = true;
     752    }
     753    else {
     754        text.append(COLLECTIONMETADATA_STR);
     755        text.append(TAB_CHARACTER);
     756        text.append(name_str);
     757        text.append(SPACE_CHARACTER);
     758        String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
     759        // If this is element is in english, and it is the first one found, we don't need to write the language argument.
     760        //if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
     761        // changed so that we always write the language string
     762        text.append(LBRACKET_CHARACTER);
     763        text.append(LANGUAGE_ARGUMENT);
     764        text.append(language_str);
     765        text.append(RBRACKET_CHARACTER);
     766        text.append(SPACE_CHARACTER);
     767        //}
     768        if(known_metadata != null) {
     769        known_metadata.add(name_str);
     770        }
     771        language_str = null;
     772    }
     773    name_str = null;
     774   
    739775    String value_str = MSMUtils.getValue(command_element);
    740     if(value_str == null || value_str.length() == 0) {
    741         return "";
     776    // The value string we retrieved will be encoded for xml, so we now decode it - to text if text_value set. This parameter was originally show_extracted_namespace, but sincethis is only true for 'toString()' commands from within the CDM, its good enough to determine if this toString() will be used to display on screen, or write to collect.cfg
     777    if(text_value == CollectionMeta.TEXT) {
     778        value_str = Codec.transform(value_str, Codec.DOM_TO_TEXT);
    742779    }
    743780    else {
    744         StringBuffer text = new StringBuffer("");
    745         String name_str = command_element.getAttribute(NAME_ATTRIBUTE);
    746         // If the name is one of the special four, we don't write the collectionmeta first. Note the maintainer collectionmeta is singled out for 'prittying' reasons.
    747         if(name_str.equals(COLLECTIONMETADATA_MAINTAINER_STR)) {
    748         text.append(name_str);
    749         text.append(TAB_CHARACTER);
    750         special = true;
    751         }
    752         else if(name_str.equals(COLLECTIONMETADATA_BETA_STR) || name_str.equals(COLLECTIONMETADATA_CREATOR_STR) || name_str.equals(COLLECTIONMETADATA_PUBLIC_STR)) {
    753         text.append(name_str);
    754         text.append(TAB_CHARACTER);
    755         text.append(TAB_CHARACTER);
    756         special = true;
    757         }
    758         else {
    759         text.append(COLLECTIONMETADATA_STR);
    760         text.append(TAB_CHARACTER);
    761         text.append(name_str);
    762         text.append(SPACE_CHARACTER);
    763         String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
    764         // If this is element is in english, and it is the first one found, we don't need to write the language argument.
    765         //if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
    766         // changed so that we always write the language string
    767         text.append(LBRACKET_CHARACTER);
    768         text.append(LANGUAGE_ARGUMENT);
    769         text.append(language_str);
    770         text.append(RBRACKET_CHARACTER);
    771         text.append(SPACE_CHARACTER);
    772         //}
    773         if(known_metadata != null) {
    774             known_metadata.add(name_str);
    775         }
    776         language_str = null;
    777         }
    778         name_str = null;
    779 
    780         // The value string we retrieved will be encoded for xml, so we now decode it - to text if text_value set. This parameter was originally show_extracted_namespace, but sincethis is only true for 'toString()' commands from within the CDM, its good enough to determine if this toString() will be used to display on screen, or write to collect.cfg
    781         if(text_value == CollectionMeta.TEXT) {
    782         value_str = Codec.transform(value_str, Codec.DOM_TO_TEXT);
    783         }
    784         else {
    785             value_str = Codec.transform(value_str, Codec.DOM_TO_GREENSTONE);
    786         }
    787 
    788         // We don't wrap the email addresses in quotes, nor any string without spaces
    789         if(special) {
    790         text.append(value_str);
    791         }
    792         else {
    793         text.append(SPEECH_CHARACTER);
    794         text.append(value_str);
    795         text.append(SPEECH_CHARACTER);
    796         }
    797         value_str = null;
    798         return text.toString();
    799     }
     781        value_str = Codec.transform(value_str, Codec.DOM_TO_GREENSTONE);
     782    }
     783   
     784    // We don't wrap the email addresses in quotes, nor the other special metadata
     785    if(special) {
     786        text.append(value_str);
     787    }
     788    else {
     789        text.append(SPEECH_CHARACTER);
     790        text.append(value_str);
     791        text.append(SPEECH_CHARACTER);
     792    }
     793    value_str = null;
     794    return text.toString();
    800795    }
    801796
     
    12541249            command_element.setAttribute(NAME_ATTRIBUTE, name_str);
    12551250            command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str);
     1251            command_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
    12561252            MSMUtils.setValue(command_element, value_str);
    12571253        }
     
    12931289            command_element.setAttribute(LANGUAGE_ATTRIBUTE, ENGLISH_LANGUAGE_STR);
    12941290            command_element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
     1291            command_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
    12951292            if(value_str.startsWith(SPEECH_CHARACTER) && value_str.endsWith(SPEECH_CHARACTER)) {
    12961293            value_str = value_str.substring(1, value_str.length() - 1);
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java

    r5899 r5930  
    5353
    5454    private boolean dummy = false;
    55     private Element element;
    56     private String text;
     55    private Element element = null;
     56    private String text = null;
    5757
    5858    /** Constructor.
     
    6868    element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
    6969    element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, Gatherer.config.interface_language);
     70    element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
    7071    }
    7172
     
    7576    element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
    7677    element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language);
     78    element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
    7779    }
    7880
     
    170172    MSMUtils.setValue(element, Codec.transform(raw_value, Codec.TEXT_TO_DOM));
    171173    text = null; // Reset text
     174    // And determine if this makes the metadata assigned
     175    setAssigned(raw_value != null && raw_value.length() > 0);
    172176    }
    173177
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java

    r5900 r5930  
    6161        // Locate where we should insert this new subcollection.
    6262        Node target_node = CollectionConfiguration.findInsertionPoint(element);
    63         // Failing that we insert immediately after a language string
    6463        add(root, metadata, target_node);
    6564        Gatherer.c_man.configurationChanged();
     
    126125        CollectionMeta metadatum = (CollectionMeta) getElementAt(i);
    127126        if(metadatum.getName().equals(name) && metadatum.getLanguage().equals(Gatherer.config.interface_language)) {
    128         //Gatherer.println("Found '" + metadatum + "'");
     127        Gatherer.println("Found '" + metadatum + "'");
    129128        return metadatum;
    130129        }
     
    137136        CollectionMeta result = new CollectionMeta(name);
    138137        addMetadatum(result);
    139         //Gatherer.println("Added new metadata.");
     138        Gatherer.println("Added new metadata: " + name);
    140139        return result;
    141140    }
Note: See TracChangeset for help on using the changeset viewer.