Changeset 5721


Ignore:
Timestamp:
2003-10-23T11:15:10+13:00 (21 years ago)
Author:
jmt12
Message:

Added a new attribute - base collection. Thus when importing files from a base collection - given we for sure have the same metadatasets - we can assume any non-namespaced metadata is extracted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r5581 r5721  
    5050import org.greenstone.gatherer.msm.MetadataSetManager;
    5151import org.greenstone.gatherer.msm.MSMUtils;
     52import org.greenstone.gatherer.util.StaticStrings;
    5253import org.greenstone.gatherer.util.Utility;
    5354import org.w3c.dom.*;
     
    7475    /** The file the collection is in (the file may not actually exist, such in the case of a legacy collection)! */
    7576    private File file;
    76     /** The name of the argument element. */
    77     static final private String ARGUMENT = "Argument";
     77   /** The name of the argument element. */
     78   static final private String ARGUMENT = "Argument";
     79   static final private String BASE_COLLECTION = "base_collection";
    7880    /** The name of the build element. */
    7981    static final private String BUILD = "Build";
     
    161163    }
    162164
     165   /** Determine the path to the base collection.
     166    * @return the path as a String
     167    */
     168   public String getBaseCollection() {
     169      return getString(BASE_COLLECTION);
     170   }
     171   
    163172    /** Determine the number of documents and folders in this collection. */
    164173    public int getCount() {
     
    304313    }
    305314
     315   public void setBaseCollection(String base_collection) {
     316      set(BASE_COLLECTION, base_collection);
     317   }
     318   
    306319    /** Set the value of imported to the given value.
    307320     * @param value The new value for imported, <i>true</i> if the collection has been imported successfully, <i>false</i> otherwise.
     
    359372    }
    360373
     374    /** Get the value of a collection argument. */
     375    private String getString(String name) {
     376    String result = "";
     377    try {
     378        Element document_element = document.getDocumentElement();
     379        NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
     380        boolean found = false;
     381        for(int i = 0; !found && i < arguments.getLength(); i++) {
     382        Element argument_element = (Element) arguments.item(i);
     383        if(argument_element.getParentNode() == document_element) {
     384            if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
     385            result = MSMUtils.getValue(argument_element);
     386            found = true;
     387            }
     388        }
     389        argument_element = null;
     390        }
     391        arguments = null;
     392        document_element = null;
     393    }
     394    catch (Exception error) {
     395        Gatherer.printStackTrace(error);
     396    }
     397    return result;
     398    }   
     399
    361400    /** Method to retrieve the current build options associated with this Collection. */
    362401    private Element getBuildValues() {
     
    407446    }
    408447
    409     /** Set the value of a collection argument. */
    410     private void set(String name, boolean value) {
    411     try {
    412         Element document_element = document.getDocumentElement();
    413         NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
    414         boolean found = false;
    415         for(int i = 0; !found && i < arguments.getLength(); i++) {
    416         Element argument_element = (Element) arguments.item(i);
    417         if(argument_element.getParentNode() == document_element) {
    418             if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
    419             // Strip any current value nodes.
    420             while(argument_element.hasChildNodes()) {
    421                 argument_element.removeChild(argument_element.getFirstChild());
    422             }
    423             // Append new value
    424             argument_element.appendChild(document.createTextNode(value ? "true" : "false"));
    425             }
    426         }
    427         argument_element = null;
    428         }
    429         arguments = null;
    430         document_element = null;
    431     }
    432     catch (Exception error) {
    433         Gatherer.printStackTrace(error);
    434     }
    435     }
     448   /** Set the value of a collection argument. */
     449   private void set(String name, boolean value) {
     450      set(name, (value ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
     451   }
     452   
     453   private void set(String name, String value) {
     454      try {
     455     Element document_element = document.getDocumentElement();
     456     NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
     457     boolean found = false;
     458     for(int i = 0; !found && i < arguments.getLength(); i++) {
     459        Element argument_element = (Element) arguments.item(i);
     460        if(argument_element.getParentNode() == document_element) {
     461           if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
     462          // Strip any current value nodes.
     463          while(argument_element.hasChildNodes()) {
     464             argument_element.removeChild(argument_element.getFirstChild());
     465          }
     466          // Append new value
     467          argument_element.appendChild(document.createTextNode(value));
     468          found = true;
     469           }
     470        }
     471        argument_element = null;
     472     }
     473     // Append it
     474     if(!found) {
     475        Element argument_element = document.createElement(ARGUMENT);
     476        argument_element.setAttribute(NAME, name);
     477        argument_element.appendChild(document.createTextNode(value));
     478        document_element.appendChild(argument_element);
     479        argument_element = null;
     480     }
     481     arguments = null;
     482     document_element = null;
     483      }
     484      catch (Exception error) {
     485     Gatherer.printStackTrace(error);
     486      }
     487   }
    436488}
Note: See TracChangeset for help on using the changeset viewer.