Mercurial > dive4elements > framework
changeset 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 | 824dd614e647 |
children | 82f62ef25a8f |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java |
diffstat | 3 files changed, 36 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Dec 17 14:06:52 2009 +0000 +++ b/ChangeLog Sat Jan 09 16:59:00 2010 +0000 @@ -1,3 +1,13 @@ +2010-01-09 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java: + Added convenient method to add attributes to nodes. Attributes have no + prefix as default. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java: + Adapted xpath (added prefix) to find action and made the document which is + created by this resource namespace aware. + 2009-12-17 Sascha L. Teichmann <sascha.teichmann@intevation.de> RELEASE 0.3
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java Thu Dec 17 14:06:52 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/XMLUtils.java Sat Jan 09 16:59:00 2010 +0000 @@ -28,6 +28,9 @@ */ public final class XMLUtils { + public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; + public static final String XFORM_PREFIX = "xform"; + private static Logger logger = Logger.getLogger(XMLUtils.class); private XMLUtils() { @@ -52,19 +55,31 @@ } public void addAttr(Element element, String name, String value) { + addAttr(element, name, value, false); + } + + public void addAttr( + Element element, + String name, + String value, + boolean addPrefix + ) { Attr attr = document.createAttributeNS(ns, name); attr.setValue(value); - attr.setPrefix(prefix); + + if (addPrefix) + attr.setPrefix(prefix); + element.setAttributeNode(attr); } } // class ElementCreator public static final Document newDocument() { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { - return DocumentBuilderFactory - .newInstance() - .newDocumentBuilder() - .newDocument(); + return factory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException pce) { logger.error(pce.getLocalizedMessage(), pce); @@ -73,11 +88,11 @@ } public static final Document parseDocument(File file) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { - return DocumentBuilderFactory - .newInstance() - .newDocumentBuilder() - .parse(file); + return factory.newDocumentBuilder().parse(file); } catch (ParserConfigurationException pce) { logger.error(pce.getLocalizedMessage(), pce);
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java Thu Dec 17 14:06:52 2009 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ArtifactResource.java Sat Jan 09 16:59:00 2010 +0000 @@ -33,7 +33,7 @@ { private static Logger logger = Logger.getLogger(ArtifactResource.class); - public static final String XPATH_ACTION = "/action/type/@name"; + public static final String XPATH_ACTION = "/art:action/art:type/@name"; public static final String PATH = "/artifact/{uuid}"; @@ -112,6 +112,7 @@ Document inputDocument = null; try { DomRepresentation input = new DomRepresentation(requestRepr); + input.setNamespaceAware(true); inputDocument = input.getDocument(); } catch (IOException ioe) {