Changeset 6029


Ignore:
Timestamp:
2003-11-28T17:40:46+13:00 (20 years ago)
Author:
jmt12
Message:

Removed the hvalue attribute from metadata.xml files as it is now obsolete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMDocument.java

    r5998 r6029  
    5656    static final private String FILESET_ELEMENT = "FileSet";
    5757    static final private String HVALUE_ATTRIBUTE = "hvalue";
    58     static final private String METADATA_ELEMENT = "Metadata";
    5958    static final private String MODE_ATTRIBUTE = "mode";
    60     static final private String NAME_ATTRIBUTE = "name";
    6159    static final private String OVERWRITE = "overwrite";
    6260
     
    147145        }
    148146        // Now, finally, we can add the metadata.
    149         Element metadata_element = base_document.createElement(METADATA_ELEMENT);
     147        Element metadata_element = base_document.createElement(StaticStrings.METADATA_ELEMENT);
    150148        String name = metadata.getElement().getName();
    151149        if(name.startsWith(Utility.EXTRACTED_METADATA_NAMESPACE)) {
    152150        name = name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length() + 1);
    153151        }
    154         metadata_element.setAttribute(NAME_ATTRIBUTE, name);
     152        metadata_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
    155153
    156154        // To determine if this metadata entry should overwrite or accumulate we check if there are other entries with the same element in this fileset.
     
    159157        for(int k = 0; !will_accumulate && k < sibling_description_elements.getLength(); k++) {
    160158        Element sibling_description_element = (Element) sibling_description_elements.item(k);
    161         NodeList sibling_metadata_elements = sibling_description_element.getElementsByTagName(METADATA_ELEMENT);
     159        NodeList sibling_metadata_elements = sibling_description_element.getElementsByTagName(StaticStrings.METADATA_ELEMENT);
    162160        for(int l = 0; !will_accumulate && l < sibling_metadata_elements.getLength(); l++) {
    163161            Element sibling_metadata_element = (Element) sibling_metadata_elements.item(l);
    164162            // It appears that its possible that we can be asked to add the same metadata twice (especially after a copy action is cancelled then repeated). So we check if we have been asked to add exactly the same value twice.
    165             if(sibling_metadata_element.getAttribute(NAME_ATTRIBUTE).equals(metadata_element.getAttribute(NAME_ATTRIBUTE))) {
     163            if(sibling_metadata_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equals(metadata_element.getAttribute(StaticStrings.NAME_ATTRIBUTE))) {
    166164                // Check the values and return if they are the same.
    167165               if(metadata.getAbsoluteValue().equals(MSMUtils.getValue(sibling_metadata_element))) {
     
    179177        metadata_element.setAttribute(MODE_ATTRIBUTE, ACCUMULATE);
    180178        }
    181         // As we can't possibly store all the metadata in memory, nor can we ensure that the indexes written to file remain the same until the new time we look at this file, and to avoid having to open a rewrite every collection document whenever any value tree changes, I'm adding a new attribute called hvalue which indicates the hierarchy value path as a '|' separated string.
     179        // As we can't possibly store all the metadata in memory, nor can we ensure that the indexes written to file remain the same until the new time we look at this file, and to avoid having to open a rewrite every collection document whenever any value tree changes, I'm writing the value out as a full path string
    182180        GValueModel model = Gatherer.c_man.getCollection().msm.getValueTree(metadata.getElement());
    183181        String node_value = null;
    184182        if(model != null && model.isHierarchy()) {
    185183            node_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
    186             ///ystem.err.println("Saving H Info: " + node_value);
    187             metadata_element.setAttribute(HVALUE_ATTRIBUTE, node_value);
    188184        }
    189185        else {
    190186            node_value = metadata.getAbsoluteValue();
    191             ///ystem.err.println("Not H Info: " + node_value);
    192187        }
    193188        ///ystem.err.println("Creating node in GDMDocument: '" + node_value + "'");
     
    221216        for(int k = 0; k < description_elements.getLength(); k++) {
    222217            Element description_element = (Element) description_elements.item(k);
    223             NodeList metadata_elements = description_element.getElementsByTagName(METADATA_ELEMENT);
     218            NodeList metadata_elements = description_element.getElementsByTagName(StaticStrings.METADATA_ELEMENT);
    224219            count = count + metadata_elements.getLength();
    225220            metadata_elements = null;
     
    248243    /** Retrieve the metadata associated with the given filename. Keep track of what metadata should be overwritten and what should be accumulated. Also make note of the source file, and remove the metadata if required. Finally if purge is set retrieve every piece of metadata in this file. */
    249244    public ArrayList getMetadata(String filename, boolean remove, ArrayList metadatum_so_far, File file, boolean append_folder_level, boolean purge) {
    250     ///ystem.err.println("Get metadata for " + filename);
     245    Gatherer.println("Get metadata for " + filename);
    251246    ArrayList metadatum = null;
    252247    if(metadatum_so_far == null) {
     
    267262            Element filename_element = (Element) filename_elements.item(j);
    268263            String filename_text = MSMUtils.getValue(filename_element);
    269             if((filename != null && filename.matches(filename_text)) || ((filename == null || append_folder_level) && filename_text.equals(DIRECTORY_FILENAME)) || purge) {
     264            if((filename != null && (filename.matches(filename_text) || (append_folder_level && filename.indexOf(File.separator) != -1 && filename_text.equals(filename.substring(0, filename.indexOf(File.separator)))))) || ((filename == null || append_folder_level) && filename_text.equals(DIRECTORY_FILENAME)) || purge) {
    270265            // If they match add all of the metadata found in the Description child element, remembering to abide by desired mode (accumulate vs. overwrite).
    271266            NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
    272267            for(int k = 0; k < description_elements.getLength(); k++) {
    273268                Element description_element = (Element) description_elements.item(k);
    274                 NodeList metadata_elements = description_element.getElementsByTagName(METADATA_ELEMENT);
     269                NodeList metadata_elements = description_element.getElementsByTagName(StaticStrings.METADATA_ELEMENT);
    275270                for(int l = 0; l < metadata_elements.getLength(); l++) {
    276271                Element metadata_element = (Element) metadata_elements.item(l);
    277                 String raw_element = metadata_element.getAttribute(NAME_ATTRIBUTE);
     272                String raw_element = metadata_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    278273                //String language = metadata_element.getAttribute("language");
    279274                String mode = metadata_element.getAttribute(MODE_ATTRIBUTE);
    280                 String raw_value = metadata_element.getAttribute(HVALUE_ATTRIBUTE);
    281                 if(raw_value == null || raw_value.length() == 0) {
    282                    raw_value = MSMUtils.getValue(metadata_element);
    283                    // Raw value is in GREENSTONE form, convert to DOM
    284                    raw_value = Codec.transform(raw_value, Codec.GREENSTONE_TO_DOM);
    285                 }
     275                String raw_value = MSMUtils.getValue(metadata_element);
     276                // Raw value is in GREENSTONE form, convert to DOM
     277                raw_value = Codec.transform(raw_value, Codec.GREENSTONE_TO_DOM);
    286278                // ***** LEGACY SUPPORT *****
    287279                // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\'
     
    290282                    raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.PIPE_STR);
    291283                    Gatherer.println("Updated Path To: " + raw_value);
    292                     metadata_element.setAttribute(HVALUE_ATTRIBUTE, raw_value);
     284                    MSMUtils.setValue(metadata_element, raw_value);
    293285                }
    294286                // **************************
     
    451443            for(int k = 0; !found && k < description_elements.getLength(); k++) {
    452444                Element description_element = (Element) description_elements.item(k);
    453                 NodeList metadata_elements = description_element.getElementsByTagName("Metadata");
     445                NodeList metadata_elements = description_element.getElementsByTagName(StaticStrings.METADATA_ELEMENT);
    454446                for(int l = 0; (!found || !make_next_metadata_element_overwrite) && l < metadata_elements.getLength(); l++) {
    455447                Element metadata_element = (Element) metadata_elements.item(l);
     
    484476                metadata_element = null;
    485477                }
    486                 metadata_elements = description_element.getElementsByTagName("Metadata");
     478                metadata_elements = description_element.getElementsByTagName(StaticStrings.METADATA_ELEMENT);
    487479                // If we found it, removed it, and now the description tag has no children, mark the fileset for removal
    488480                if(metadata_elements.getLength() == 0) {
Note: See TracChangeset for help on using the changeset viewer.