Changeset 4331


Ignore:
Timestamp:
2003-05-26T16:00:57+12:00 (21 years ago)
Author:
jmt12
Message:

Method to compare two metadata elements for their ordering within the DOM model - John

File:
1 edited

Legend:

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

    r4293 r4331  
    7373     public MetadataSet(String metadata_template) {
    7474          URL url = ClassLoader.getSystemResource(metadata_template);
    75           init(new File(URLDecoder.decode(url.getFile())));
     75          try {
     76                init(new File(URLDecoder.decode(url.getFile(), "UTF-8")));
     77          }
     78          catch(UnsupportedEncodingException exception) {
     79                Gatherer.printStackTrace(exception);
     80          }
    7681     }
    7782
     
    233238          value_trees.put(element, model);
    234239     }
     240
     241     public int compare(Element e1, Element e2) {
     242          int result = 0;
     243          // Check that they're not the same element.
     244          if(e1 != e2) {
     245                int index_e1 = -1;
     246                int index_e2 = -1;
     247                // Locate the indexes for each element.
     248                for(int i = 0; i < elements.getLength(); i++) {
     249                     Node element = elements.item(i);
     250                     if(element == e1) {
     251                          index_e1 = i;
     252                     }
     253                     if(elements == e2) {
     254                          index_e2 = i;
     255                     }
     256                }
     257                if(index_e1 < index_e2) {
     258                     result = -1;
     259                }
     260                else {
     261                     result = 1;
     262                }
     263          }
     264          return result;
     265     }
     266
    235267     /** A method to determine if this metadata set contains an element with a certain name.
    236268      * @param name A <strong>String</strong> which is the name of the element whose presence we are checking.
Note: See TracChangeset for help on using the changeset viewer.