comparison artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java @ 64:8b72676698b5

Create a namespace aware document out of the request. We consider namespaces now. Adapted xpath to find action. artifacts/trunk@523 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sat, 09 Jan 2010 16:59:00 +0000
parents 76abf0c64d3b
children ed03cc0e5800
comparison
equal deleted inserted replaced
63:824dd614e647 64:8b72676698b5
26 /** 26 /**
27 * @author Sascha L. Teichmann 27 * @author Sascha L. Teichmann
28 */ 28 */
29 public final class XMLUtils 29 public final class XMLUtils
30 { 30 {
31 public static final String XFORM_URL = "http://www.w3.org/2002/xforms";
32 public static final String XFORM_PREFIX = "xform";
33
31 private static Logger logger = Logger.getLogger(XMLUtils.class); 34 private static Logger logger = Logger.getLogger(XMLUtils.class);
32 35
33 private XMLUtils() { 36 private XMLUtils() {
34 } 37 }
35 38
50 element.setPrefix(prefix); 53 element.setPrefix(prefix);
51 return element; 54 return element;
52 } 55 }
53 56
54 public void addAttr(Element element, String name, String value) { 57 public void addAttr(Element element, String name, String value) {
58 addAttr(element, name, value, false);
59 }
60
61 public void addAttr(
62 Element element,
63 String name,
64 String value,
65 boolean addPrefix
66 ) {
55 Attr attr = document.createAttributeNS(ns, name); 67 Attr attr = document.createAttributeNS(ns, name);
56 attr.setValue(value); 68 attr.setValue(value);
57 attr.setPrefix(prefix); 69
70 if (addPrefix)
71 attr.setPrefix(prefix);
72
58 element.setAttributeNode(attr); 73 element.setAttributeNode(attr);
59 } 74 }
60 } // class ElementCreator 75 } // class ElementCreator
61 76
62 public static final Document newDocument() { 77 public static final Document newDocument() {
78 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
79 factory.setNamespaceAware(true);
80
63 try { 81 try {
64 return DocumentBuilderFactory 82 return factory.newDocumentBuilder().newDocument();
65 .newInstance()
66 .newDocumentBuilder()
67 .newDocument();
68 } 83 }
69 catch (ParserConfigurationException pce) { 84 catch (ParserConfigurationException pce) {
70 logger.error(pce.getLocalizedMessage(), pce); 85 logger.error(pce.getLocalizedMessage(), pce);
71 } 86 }
72 return null; 87 return null;
73 } 88 }
74 89
75 public static final Document parseDocument(File file) { 90 public static final Document parseDocument(File file) {
91 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
92 factory.setNamespaceAware(true);
93
76 try { 94 try {
77 return DocumentBuilderFactory 95 return factory.newDocumentBuilder().parse(file);
78 .newInstance()
79 .newDocumentBuilder()
80 .parse(file);
81 } 96 }
82 catch (ParserConfigurationException pce) { 97 catch (ParserConfigurationException pce) {
83 logger.error(pce.getLocalizedMessage(), pce); 98 logger.error(pce.getLocalizedMessage(), pce);
84 } 99 }
85 catch (SAXException se) { 100 catch (SAXException se) {

http://dive4elements.wald.intevation.org