Changeset 30831


Ignore:
Timestamp:
09/22/16 11:56:41 (4 years ago)
Author:
kjdon
Message:

added more generalised versions of mergeMetadataLists and mergeMetadataFromList, so we can use them for merging displayItemLists too

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r30666 r30831  
    571571     * metadataList of 'to'
    572572     */
    573     public static boolean mergeMetadataLists(Node to, Node from)
    574     {
    575         Node from_meta = getChildByTagName(from, METADATA_ELEM + LIST_MODIFIER);
    576         if (from_meta == null)
    577         { // nothing to copy
    578             return true;
    579         }
    580         return mergeMetadataFromList(to, from_meta);
    581     }
    582 
    583     /**
    584      * copies the metadata out of the meta_list metadataList into the
    585      * metadataList of 'to'
    586      */
    587     public static boolean mergeMetadataFromList(Node to, Node meta_list)
    588     {
    589         if (meta_list == null)
    590             return false;
    591         Node to_meta = getChildByTagName(to, METADATA_ELEM + LIST_MODIFIER);
    592         Document to_owner = to.getOwnerDocument();
    593         if (to_meta == null)
    594         {
    595             to.appendChild(to_owner.importNode(meta_list, true));
    596             return true;
    597         }
    598         // copy individual metadata elements
    599         NodeList meta_items = ((Element) meta_list).getElementsByTagName(METADATA_ELEM);
    600         for (int i = 0; i < meta_items.getLength(); i++)
    601         {
    602             to_meta.appendChild(to_owner.importNode(meta_items.item(i), true));
    603         }
    604         return true;
    605     }
    606 
    607     /** copies all the children from from to to */
    608     public static boolean mergeElements(Element to, Element from)
     573  public static boolean mergeMetadataLists(Node to, Node from) {
     574    return mergeSpecifiedLists(to, from, METADATA_ELEM);
     575  }
     576
     577  /** copies metadata from meta_list into the metadataList of to **/
     578  public static boolean mergeMetadataFromList(Node to, Node meta_list) {
     579    return mergeSpecifiedFromList(to, meta_list, METADATA_ELEM);
     580  }
     581
     582
     583  public static boolean mergeSpecifiedLists(Node to, Node from, String element_name) {
     584    // find the list in the from element
     585    Node from_list = getChildByTagName(from, element_name+LIST_MODIFIER);
     586    if (from_list == null) {
     587      // nothing to copy
     588      return false;
     589    }
     590   
     591    return mergeSpecifiedFromList(to, from_list, element_name);
     592  }
     593    public static boolean mergeSpecifiedFromList(Node to, Node from_list, String element_name) {
     594      if (from_list == null) {
     595    return false;
     596      }
     597      Document to_owner = to.getOwnerDocument();
     598      Node to_list = getChildByTagName(to, element_name+LIST_MODIFIER);
     599      if (to_list == null) {
     600    // just copy over the whole list
     601    to.appendChild(to_owner.importNode(from_list, true));
     602    return true;
     603      }
     604      // otherwise we copy all the elements
     605      NodeList from_items = ((Element) from_list).getElementsByTagName(element_name);
     606
     607      for (int i = 0; i < from_items.getLength(); i++)
     608    {
     609      to_list.appendChild(to_owner.importNode(from_items.item(i), true));
     610    }
     611      return true;
     612     
     613    }
     614 
     615  /** copies all the children from from to to */
     616  public static boolean mergeElements(Element to, Element from)
    609617    {
    610618
Note: See TracChangeset for help on using the changeset viewer.