- Timestamp:
- 2014-04-10T14:29:44+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
r28958 r28963 59 59 public static final String PARAM_ELEM = "param"; 60 60 public static final String PARAM_OPTION_ELEM = "option"; 61 public static final String LIBRARY_PARAM_ELEM = "libraryParam"; 61 62 public static final String CONTENT_ELEM = "content"; 62 63 public static final String RESOURCE_ELEM = "resource"; … … 460 461 461 462 /** add text to a document/subsection element */ 462 public static boolean addDocText( Document owner,Element doc, String text)463 { 464 465 Element content = owner.createElement(NODE_CONTENT_ELEM);466 Text t = owner.createTextNode(text);463 public static boolean addDocText(Element doc, String text) 464 { 465 466 Element content = doc.getOwnerDocument().createElement(NODE_CONTENT_ELEM); 467 Text t = doc.getOwnerDocument().createTextNode(text); 467 468 content.appendChild(t); 468 469 doc.appendChild(content); … … 471 472 472 473 /** add an error message, unknown error type */ 473 public static boolean addError(Document owner,Element doc, String text)474 { 475 return addError( owner,doc, text, ERROR_TYPE_OTHER);474 public static boolean addError(Element doc, String text) 475 { 476 return addError(doc, text, ERROR_TYPE_OTHER); 476 477 } 477 478 478 479 /** add an error message */ 479 public static boolean addError( Document owner,Element doc, String text, String error_type)480 { 481 482 Element content = owner.createElement(ERROR_ELEM);480 public static boolean addError(Element doc, String text, String error_type) 481 { 482 483 Element content = doc.getOwnerDocument().createElement(ERROR_ELEM); 483 484 content.setAttribute(ERROR_TYPE_ATT, error_type); 484 Text t = owner.createTextNode(text);485 Text t = doc.getOwnerDocument().createTextNode(text); 485 486 content.appendChild(t); 486 487 doc.appendChild(content); … … 489 490 490 491 /** add an error message */ 491 public static boolean addError( Document owner,Element doc, Throwable error)492 { 493 return addError( owner,doc, error, ERROR_TYPE_OTHER);492 public static boolean addError(Element doc, Throwable error) 493 { 494 return addError(doc, error, ERROR_TYPE_OTHER); 494 495 } 495 496 496 497 /** add an error message */ 497 public static boolean addError( Document owner,Element doc, Throwable error, String error_type)498 public static boolean addError(Element doc, Throwable error, String error_type) 498 499 { 499 500 error.printStackTrace(); 500 return addError( owner,doc, error.toString(), error_type);501 return addError(doc, error.toString(), error_type); 501 502 } 502 503 … … 518 519 519 520 /** adds a metadata elem to a list */ 520 public static boolean addMetadata( Document owner,Element list, String meta_name, String meta_value)521 public static boolean addMetadata(Element list, String meta_name, String meta_value) 521 522 { 522 523 if (meta_value == null || meta_value.equals("")) … … 524 525 return false; 525 526 } 527 Document owner = list.getOwnerDocument(); 526 528 Element data = owner.createElement(METADATA_ELEM); 527 529 data.setAttribute(NAME_ATT, meta_name); … … 818 820 } 819 821 } 822 823 /** 824 * Given a Node representing an Element or Document, will return the 825 * Element/docroot Element. Returns null if the Node was not an element. 826 */ 827 public static Element nodeToElement(Node node) 828 { 829 if (node == null) 830 { 831 return null; 832 } 833 short nodeType = node.getNodeType(); 834 835 if (nodeType == Node.DOCUMENT_NODE) 836 { 837 Document docNode = (Document) node; 838 return docNode.getDocumentElement(); 839 } 840 else if (nodeType == Node.ELEMENT_NODE) 841 { 842 return (Element) node; 843 } 844 else 845 { 846 String message = "Expecting Document or Element node type but got " + node.getNodeName() + "\nReturning null"; 847 System.err.println(message); 848 logger.warn(message); 849 return null; 850 } 851 } 852 820 853 821 854 /** returns a basic request message */ … … 907 940 } 908 941 909 public static void addParametersToList( Document owner,Element param_list, HashMap params)942 public static void addParametersToList(Element param_list, HashMap params) 910 943 { 911 944 if (params == null) … … 916 949 Set items = params.entrySet(); 917 950 Iterator i = items.iterator(); 951 Document owner = param_list.getOwnerDocument(); 918 952 while (i.hasNext()) 919 953 {
Note:
See TracChangeset
for help on using the changeset viewer.