Changeset 23627

Show
Ignore:
Timestamp:
24.01.2011 13:17:24 (9 years ago)
Author:
kjdon
Message:

changed the mergeMetadataLists method so that it actually copied all metadata (was iterating through a changing list). Added a new method mergeMetadataFromList where you pass in the from metatadataList not the parent - needed if the parent hase more than one metadata list

Files:
1 modified

Legend:

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

    r23489 r23627  
    414414  } 
    415415   
    416   /** copies the metadata out of teh metadataList of 'from' into 
     416  /** copies the metadata out of the metadataList of 'from' into 
    417417   * the metadataList of 'to' */ 
    418418  public static boolean mergeMetadataLists(Node to, Node from) { 
    419     Node to_meta = getChildByTagName(to, METADATA_ELEM+LIST_MODIFIER); 
    420419    Node from_meta = getChildByTagName(from, METADATA_ELEM+LIST_MODIFIER); 
    421      
    422420    if  (from_meta == null) { // nothing to copy 
    423421      return true; 
    424422    } 
     423    return mergeMetadataFromList(to, from_meta); 
     424  } 
     425   
     426 
     427  /** copies the metadata out of the meta_list metadataList  into 
     428   * the metadataList of 'to' */ 
     429  public static boolean mergeMetadataFromList(Node to, Node meta_list) { 
     430    if (meta_list == null) return false; 
     431    Node to_meta = getChildByTagName(to, METADATA_ELEM+LIST_MODIFIER); 
    425432    Document to_owner = to.getOwnerDocument(); 
    426     Node new_from = to_owner.importNode(from_meta, true); 
    427      
    428     if (to_meta == null) { // just copy the whole list 
    429       to.appendChild(new_from); 
     433    if (to_meta == null) { 
     434      to.appendChild(to_owner.importNode(meta_list, true)); 
    430435      return true; 
    431436    } 
    432      
    433     // copy individual elements 
    434     Node child = new_from.getFirstChild(); 
    435     while ( child != null) { 
    436       to_meta.appendChild(child); 
    437       child = child.getNextSibling(); 
     437    // copy individual metadata elements 
     438    NodeList meta_items = ((Element)meta_list).getElementsByTagName(METADATA_ELEM); 
     439    for (int i=0; i<meta_items.getLength(); i++) { 
     440      to_meta.appendChild(to_owner.importNode(meta_items.item(i),true)); 
    438441    } 
    439442    return true;