Changeset 30585

Show
Ignore:
Timestamp:
20.06.2016 12:40:19 (4 years ago)
Author:
kjdon
Message:

added method findExtraMetadataNames. This looks through xsl to find gsf:metadata, gsf:image etc and creates a list of metadata names that should be retrieved. Will replace methods in action and transforming receptionist, which both are doing this but doing it differently.

Files:
1 modified

Legend:

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

    r27716 r30585  
    2222import java.util.ArrayList; 
    2323import java.util.HashMap; 
     24import java.util.HashSet; 
    2425import java.util.Vector; 
    2526 
     
    404405    } 
    405406 
     407 
     408  public static void findExtraMetadataNames(Element xsl_elem, HashSet<String> meta_names) { 
     409 
     410    // gsf:metadata and gsf:foreach-metadata 
     411    NodeList metadata_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "metadata");  
     412    NodeList foreach_metadata_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "foreach-metadata"); 
     413    int num_meta_nodes = metadata_nodes.getLength(); 
     414    int total_nodes = num_meta_nodes +foreach_metadata_nodes.getLength(); 
     415    for (int i = 0; i < total_nodes; i++) { 
     416      Element current; 
     417      if (i<num_meta_nodes) { 
     418    current = (Element) metadata_nodes.item(i); 
     419      } else { 
     420    current = (Element) foreach_metadata_nodes.item(i-num_meta_nodes); 
     421      } 
     422      String full_name = current.getAttribute("name"); 
     423      String select = current.getAttribute("select"); 
     424       
     425      String [] names = full_name.split(","); 
     426      for(int j=0; j<names.length; j++) { 
     427     
     428    String name = names[j]; 
     429    if (!name.equals("")) { 
     430      if (!select.equals("")) { 
     431        name = select + GSConstants.META_RELATION_SEP + name; 
     432      } 
     433      meta_names.add(name); 
     434    } 
     435      } 
     436    } 
     437     
     438    // gsf:link 
     439    boolean getEquivLinkMeta = false; 
     440    NodeList link_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "link"); 
     441    for (int i = 0; i < link_nodes.getLength(); i++) { 
     442       
     443      Element elem = (Element) link_nodes.item(i); 
     444      String type = elem.getAttribute("type"); 
     445      if (type.equals("source")) 
     446    { 
     447      meta_names.add("assocfilepath"); 
     448      meta_names.add("srclinkFile"); 
     449    } 
     450      else if (type.equals("web")) 
     451    { 
     452      meta_names.add("weblink"); 
     453      meta_names.add("webicon"); 
     454      meta_names.add("/weblink"); 
     455    } 
     456      else if (type.equals("equivdoc")) 
     457    { 
     458      getEquivLinkMeta = true; // equivalent to gsf:equivlinkgs3 
     459    } 
     460    } 
     461    // gsf:equivlinkgs3 
     462    link_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "equivlinkgs3"); 
     463    if (getEquivLinkMeta || link_nodes.getLength() > 0) { 
     464       
     465      String[] equivlink_metanames = { "equivDocIcon", "equivDocLink", "/equivDocLink" }; 
     466 
     467      for (int i = 0; i < equivlink_metanames.length; i++) 
     468    { 
     469      StringBuffer metadata = new StringBuffer(); 
     470      metadata.append("all"); // this means the attr multiple = true; 
     471      metadata.append(GSConstants.META_RELATION_SEP); 
     472       
     473      metadata.append(GSConstants.META_SEPARATOR_SEP); 
     474      metadata.append(','); // attr separator = "," 
     475      metadata.append(GSConstants.META_SEPARATOR_SEP); 
     476      metadata.append(GSConstants.META_RELATION_SEP); 
     477       
     478      // the name of the metadata we're retrieving 
     479      metadata.append(equivlink_metanames[i]); 
     480      meta_names.add(metadata.toString()); 
     481    } 
     482    } 
     483     
     484    // gsf:icon 
     485    NodeList icon_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "icon"); 
     486    for (int i = 0; i < icon_nodes.getLength(); i++) { 
     487      Element current = (Element) icon_nodes.item(i); 
     488      String type = current.getAttribute(GSXML.TYPE_ATT); 
     489      if (type == null || type.length() == 0) { 
     490    continue; 
     491      } 
     492      if (type.equals("web")) { 
     493    meta_names.add("webicon"); 
     494    break; // this is the only one we are looking for at the moment 
     495      } 
     496    } 
     497     
     498    // gsf:image 
     499    NodeList image_nodes = xsl_elem.getElementsByTagNameNS(GSXML.GSF_NAMESPACE, "image"); 
     500    for (int i = 0; i < image_nodes.getLength(); i++) { 
     501      Element current = (Element) image_nodes.item(i); 
     502      String type = current.getAttribute(GSXML.TYPE_ATT); 
     503      if (type == null || type.length() == 0) { 
     504    continue; 
     505      } 
     506       
     507      if (type.equals("source")) { 
     508     
     509    String[] standardSourceMeta = new String[] { "SourceFile", "ImageHeight", "ImageWidth", "ImageType", "srcicon" }; 
     510    for (String meta : standardSourceMeta) { 
     511      meta_names.add(meta); 
     512    } 
     513     
     514      } 
     515      else if (type.equals("screen")) { 
     516     
     517    String[] standardScreenMeta = new String[] { "Screen", "ScreenHeight", "ScreenWidth", "ScreenType", "screenicon" }; 
     518    for (String meta : standardScreenMeta) { 
     519      meta_names.add(meta); 
     520    } 
     521      } 
     522      else if (type.equals("thumb")) { 
     523    String[] standardThumbMeta = new String[] { "Thumb", "ThumbHeight", "ThumbWidth", "ThumbType", "thumbicon" }; 
     524    for (String meta : standardThumbMeta) { 
     525      meta_names.add(meta); 
     526    } 
     527      } 
     528      else if (type.equals("cover")) { 
     529    meta_names.add("hascover"); 
     530    logger.error("adding hascover"); 
     531      } 
     532    }   
     533  } 
     534   
    406535    /** 
    407536     * looks through a stylesheet for <xxx:template match='template_name'>