Changeset 4079


Ignore:
Timestamp:
2003-04-02T15:58:48+12:00 (21 years ago)
Author:
kjdon
Message:

added a method for working out what metadata is needed for a particular node type from an xslt

File:
1 edited

Legend:

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

    r3450 r4079  
    88
    99import java.util.HashMap;
     10import java.util.Vector;
    1011
    1112/** various functions for manipulating Greenstone xslt  */
     
    4344   
    4445    }
     46
     47    /**
     48     * looks through a stylesheet for <xxx:template match='template_name'>
     49     * inside this template it looks for any <xxx:value-of select='metadataList/metadata[@name=yyy]> elements, and extracts the metadata names into a Vector
     50     */
     51    public static Vector extractWantedMetadata(Document stylesheet, String template_name) {
     52   
     53    Vector metadata = new Vector();
     54    Element base_node = stylesheet.getDocumentElement();
     55    NodeList templates = base_node.getElementsByTagNameNS("*","template");
     56    for (int i=0; i<templates.getLength(); i++) {
     57        Element template = (Element)templates.item(i);
     58        String match_name = template.getAttribute("match");
     59        if (!match_name.equals(template_name)) {
     60        continue; // we're only looking for specific templates
     61        }
     62        String mode = template.getAttribute("mode");
     63        if (!mode.equals("")) {   
     64        continue; // we only want ones without modes - these are processing ones, not display ones
     65        }
     66        // we have one that we want to look through
     67        NodeList values = template.getElementsByTagNameNS("*", "value-of");
     68        for (int v=0; v<values.getLength(); v++) {
     69        String select = ((Element)values.item(v)).getAttribute("select");
     70        if (select.startsWith("metadataList/metadata[@name=")) {
     71            String []bits = select.split("'|\"");
     72            // there should be two quotes in teh string, therefore 3 items, and the second one is teh one we want
     73            String name = bits[1];
     74            metadata.add(name);
     75        }
     76        }
     77    }
     78    return metadata;   
     79    }
     80
     81   
     82
    4583}
     84
Note: See TracChangeset for help on using the changeset viewer.