Changeset 3600


Ignore:
Timestamp:
2002-12-02T09:51:44+13:00 (21 years ago)
Author:
kjdon
Message:

added some new methods for xml-safeing, and handling multiparams

File:
1 edited

Legend:

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

    r3573 r3600  
    3232    public static final String CONFIGURE_ELEM = "configure";
    3333    public static final String STATUS_ELEM = "status";
    34 
     34    public static final String DEFAULT_ELEM = "default";
    3535    // elems for the pages to be processed by xslt
    3636    public final static String PAGE_ELEM = "page";
     
    5959    public static final String ADDRESS_ATT = "address";
    6060    public static final String PARAM_SHORTNAME_ATT = "shortname";
     61    public static final String PARAM_IGNORE_POS_ATT = "ignore";
    6162
    6263    // parameter types
     
    6768    public static final String PARAM_TYPE_ENUM_MULTI = "enum_multi";
    6869    public static final String PARAM_TYPE_STRING = "string";
    69    
     70    public static final String PARAM_TYPE_MULTI = "multi";
    7071   
    7172    // stuff for text strings
     
    165166    return param_map;
    166167    }
     168    /** takes a paramList element, and gets a HashMap of name-value pairs */
     169    public static HashMap extractAllParams(Element xml) {
     170
     171    if (!xml.getNodeName().equals(PARAM_ELEM+LIST_MODIFIER)) {
     172        System.err.println("GSXML:paramList element should have been passed to extractParams, instead it was "+xml.getNodeName());
     173        return null;
     174    }
     175    NodeList params = xml.getElementsByTagName(PARAM_ELEM);
     176    HashMap param_map = new HashMap();
     177    for (int i=0; i<params.getLength(); i++) {
     178        Element param = (Element)params.item(i);
     179        String name=param.getAttribute(NAME_ATT);
     180        String value=param.getAttribute(VALUE_ATT);
     181        if (value.equals("")) { // the value is in the content of the param
     182        value=getNodeText(param);
     183        }
     184        param_map.put(name, value);
     185       
     186    }
     187    return param_map;
     188    }
    167189
    168190    public static String getValue(Element e) {
     
    414436    return null;
    415437    }
     438
     439    // replaces < > " ' & in the original with their entities
     440    public static String xmlSafe(String original) {
     441
     442    StringBuffer filtered = new StringBuffer(original.length());
     443    char c;
     444    for (int i=0; i<original.length(); i++) {
     445        c = original.charAt(i);
     446        if (c == '>') {
     447        filtered.append("&gt;");
     448        } else if (c == '<') {
     449        filtered.append("&lt;");
     450        } else if (c == '"') {
     451        filtered.append("&quot;");
     452        } else if (c == '&') {
     453        filtered.append("&amp;");
     454        } else if (c == '\'') {
     455        filtered.append("&apos;");
     456        } else {
     457        filtered.append(c);
     458        }
     459    }
     460    return filtered.toString();
     461    }
    416462}
Note: See TracChangeset for help on using the changeset viewer.