Changeset 9812


Ignore:
Timestamp:
2005-05-04T16:09:14+12:00 (19 years ago)
Author:
kjdon
Message:

added a new method getChildrenByTagName, and added some new addError methods that take an error code, static string codes also added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r9504 r9812  
    9999    public static final String PARAM_IGNORE_POS_ATT = "ignore";
    100100    public static final String CLASSIFIER_CONTENT_ATT = "content";
    101    
     101    public static final String ERROR_TYPE_ATT = "type";
     102
    102103    // document stuff
    103104    public static final String DOC_TYPE_ATT = "docType";
     
    173174    public static final String COMM_TYPE_SOAP_JAVA = "soap";
    174175   
     176    // error types
     177    public static final String ERROR_TYPE_SYNTAX = "syntax";
     178    public static final String ERROR_TYPE_SYSTEM = "system";
     179    public static final String ERROR_TYPE_INVALID_ID = "invalid_id";
     180    public static final String ERROR_TYPE_OTHER = "other";
     181
    175182    // some system wide param names
    176183    public static final String SUBSET_PARAM = "subset";
     
    279286    }
    280287 
     288    /** add an error message, unknown error type */
     289    public static boolean addError(Document owner, Element doc, String text) {
     290    return addError(owner, doc, text, ERROR_TYPE_OTHER);
     291    }
    281292    /** add an error message */
    282     public static boolean addError(Document owner, Element doc, String text) {
     293    public static boolean addError(Document owner, Element doc, String text,
     294                   String error_type) {
    283295
    284296    Element content = owner.createElement(ERROR_ELEM);
     297    content.setAttribute(ERROR_TYPE_ATT, error_type);
    285298    Text t = owner.createTextNode(text);
    286299    content.appendChild(t);
     
    291304    /** add an error message */
    292305    public static boolean addError(Document owner, Element doc, Throwable error) {
    293       error.printStackTrace();
    294       return addError(owner, doc, error.toString());
     306      return addError(owner, doc, error, ERROR_TYPE_OTHER);
     307    }
     308   
     309    /** add an error message */
     310    public static boolean addError(Document owner, Element doc,
     311                   Throwable error, String error_type) {
     312    error.printStackTrace();
     313    return addError(owner, doc, error.toString(), error_type);
    295314    }
    296315
     
    402421    }
    403422       
     423    public static NodeList getChildrenByTagName(Node n, String name) {
     424    MyNodeList node_list = new MyNodeList();
     425    Node child = n.getFirstChild();
     426    while (child!=null) {
     427        if (child.getNodeName().equals(name)) {
     428        node_list.addNode(child);
     429        }
     430        child = child.getNextSibling();
     431    }
     432    return node_list;
     433    }
     434   
    404435
    405436    /** Duplicates an element, but gives it a new name */
Note: See TracChangeset for help on using the changeset viewer.