# HG changeset patch # User Ingo Weinzierl # Date 1262769225 0 # Node ID 416ff31f6273dadb35b7fac2a22e285bef55e09a # Parent 6e16dc0057046d52271732ceba9ad10a223f65d1 Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents. gnv/trunk@511 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6e16dc005704 -r 416ff31f6273 gnv/ChangeLog --- a/gnv/ChangeLog Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/ChangeLog Wed Jan 06 09:13:45 2010 +0000 @@ -1,3 +1,20 @@ +2010-01-05 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/util/ArtifactNamespaceContext.java: + NamespaceContext class used by gnv artifacts. + + * src/main/java/de/intevation/gnv/util/XMLUtils.java: Added + ArtifactNamespaceContext as default namespace context while creating + XPath objects. + + * src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl: Removed + local-name() methods. + + * src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java, + src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java, + src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java: Adjust + xpathes regarding namespace changes. + 2010-01-05 Ingo Weinzierl * src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl: Removed diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java --- a/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java Wed Jan 06 09:13:45 2010 +0000 @@ -89,14 +89,14 @@ Node currentUI = artifactDescription.getCurrentUI(); XSLTransformer transformer = new XSLTransformer(); String ui = transformer.transform(new XMLUtils().getNodeXPath( - currentUI, "dynamic"), "UTF-8", request + currentUI, "art:dynamic"), "UTF-8", request .getRealPath("WEB-INF/config/templates/describe-ui.xsl")); request.setAttribute("ui", ui); String staticUI = transformer .transform( - new XMLUtils().getNodeXPath(currentUI, "static"), + new XMLUtils().getNodeXPath(currentUI, "art:static"), "UTF-8", request .getRealPath("WEB-INF/config/templates/describe-ui-static.xsl")); diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java --- a/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java Wed Jan 06 09:13:45 2010 +0000 @@ -106,7 +106,7 @@ Node currentUI = artifactDescription.getCurrentUI(); if (currentUI != null){ XSLTransformer transformer = new XSLTransformer(); - Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"dynamic"); + Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"art:dynamic"); if (dynamicUINode != null){ String ui = transformer .transform( @@ -118,7 +118,7 @@ request.setAttribute("ui", ui); } - Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static"); + Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "art:static"); if (staticUINode != null){ String staticUI = transformer .transform( @@ -161,7 +161,7 @@ Node currentUI = artifactDescription.getCurrentUI(); if (currentUI != null){ XSLTransformer transformer = new XSLTransformer(); - Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"dynamic"); + Node dynamicUINode = new XMLUtils().getNodeXPath(currentUI,"art:dynamic"); if (dynamicUINode != null){ String ui = transformer .transform( @@ -173,7 +173,7 @@ request.setAttribute("ui", ui); } - Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static"); + Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "art:static"); if (staticUINode != null){ String staticUI = transformer .transform( diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java --- a/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java Wed Jan 06 09:13:45 2010 +0000 @@ -128,21 +128,22 @@ String server) { XMLUtils xmlUtils = new XMLUtils(); NodeList artifactFactories = xmlUtils.getNodeSetXPath(document, - "/result/factories/factory"); + "/art:result/art:factories/art:factory"); Collection resultValues = new ArrayList( artifactFactories.getLength()); if (artifactFactories != null) { for (int i = 0; i < artifactFactories.getLength(); i++) { Node artifactFactoryNode = artifactFactories.item(i); String name = xmlUtils.getStringXPath(artifactFactoryNode, - "@name"); + "@art:name"); String description = xmlUtils.getStringXPath( - artifactFactoryNode, "@description"); + artifactFactoryNode, "@art:description"); ArtifactFactory artifactFactory = new ArtifactFactory(name, description, server); resultValues.add(artifactFactory); } } + log.debug("Artifact Factories: " + resultValues.size()); return resultValues; } @@ -265,8 +266,8 @@ private ArtifactObject getArtifact(Document document) { XMLUtils xmlUtils = new XMLUtils(); - String uuid = xmlUtils.getStringXPath(document, "/result/uuid/@value"); - String hash = xmlUtils.getStringXPath(document, "/result/hash/@value"); + String uuid = xmlUtils.getStringXPath(document, "/art:result/art:uuid/@value"); + String hash = xmlUtils.getStringXPath(document, "/art:result/art:hash/@value"); log.info("NEW Artifact: " + uuid + " / " + hash); return new Artifact(uuid, hash); } @@ -387,14 +388,14 @@ XMLUtils xmlUtils = new XMLUtils(); if (artifact instanceof ArtifactDescription) { ArtifactDescription ad = (ArtifactDescription) artifact; - Node uiNode = xmlUtils.getNodeXPath(document, "/result/ui"); + Node uiNode = xmlUtils.getNodeXPath(document, "/art:result/art:ui"); Node outputNode = xmlUtils - .getNodeXPath(document, "/result/outputs"); + .getNodeXPath(document, "/art:result/art:outputs"); Map outputModes = null; if (outputNode != null) { NodeList outputModesNodes = xmlUtils.getNodeSetXPath( - outputNode, "output"); + outputNode, "art:output"); if (outputModesNodes != null) { outputModes = new HashMap( outputModesNodes.getLength()); @@ -406,7 +407,7 @@ outputModeNode, "@mime-type"); NodeList parameterNodes = xmlUtils.getNodeSetXPath( - outputModeNode, "parameter/parameter"); + outputModeNode, "art:parameter/art:parameter"); Collection parameter = null; if (parameterNodes != null) { parameter = new ArrayList( @@ -433,9 +434,9 @@ } String currentState = xmlUtils.getStringXPath(document, - "/result/state/@name"); + "/art:result/art:state/@name"); NodeList statesList = xmlUtils.getNodeSetXPath(document, - "/result/reachable-states/state/@name"); + "/art:result/art:reachable-states/art:state/@name"); Collection reachableStates = new ArrayList( statesList.getLength()); for (int i = 0; i < statesList.getLength(); i++) { @@ -443,7 +444,7 @@ } NodeList inputNodes = xmlUtils.getNodeSetXPath(document, - "/result/model/input"); + "/art:result/art:model/art:input"); if (inputNodes != null) { Collection inputParameter = new ArrayList( inputNodes.getLength()); @@ -707,7 +708,7 @@ if (resultDocument != null) { NodeList statisticSetNodes = xmlUtils.getNodeSetXPath(resultDocument, - "/statistics/statistic"); + "/art:statistics/art:statistic"); resultValues = new ArrayList (statisticSetNodes.getLength()); for (int i = 0; i < statisticSetNodes.getLength(); i++) { @@ -716,7 +717,7 @@ ArtifactStatisticsSet set = new DefaultArtifactStatisticsSet(name); NodeList resultNodes = xmlUtils.getNodeSetXPath(statisticSetNode, - "statistic-value"); + "art:statistic-value"); if (resultNodes != null) { for (int j = 0; j < resultNodes.getLength(); j++) { Element statisticNode = (Element)resultNodes.item(j); diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/java/de/intevation/gnv/util/ArtifactNamespaceContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/util/ArtifactNamespaceContext.java Wed Jan 06 09:13:45 2010 +0000 @@ -0,0 +1,56 @@ +package de.intevation.gnv.util; + +import javax.xml.XMLConstants; + +import javax.xml.namespace.NamespaceContext; + +import java.util.Iterator; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation) + */ +public class ArtifactNamespaceContext +implements NamespaceContext +{ + /** + * The URI of the namespace of the artifacts. + */ + public final static String NAMESPACE_URI = "http://www.intevation.de/2009/artifacts"; + + /** + * The XML prefix for the artifacts namespace. + */ + public final static String NAMESPACE_PREFIX = "art"; + + public static final ArtifactNamespaceContext INSTANCE = + new ArtifactNamespaceContext(); + + public ArtifactNamespaceContext() { + } + + public String getNamespaceURI(String prefix) { + + if (prefix == null) { + throw new NullPointerException("Null prefix"); + } + + if (NAMESPACE_PREFIX.equals(prefix)) { + return NAMESPACE_URI; + } + + if ("xml".equals(prefix)) { + return XMLConstants.XML_NS_URI; + } + + return XMLConstants.NULL_NS_URI; + } + + public String getPrefix(String uri) { + throw new UnsupportedOperationException(); + } + + public Iterator getPrefixes(String uri) { + throw new UnsupportedOperationException(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java --- a/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java Wed Jan 06 09:13:45 2010 +0000 @@ -117,7 +117,13 @@ } public Object getXPath(Object root, String query, QName returnType) { - return xpath(root, query, returnType); + return getXPath(root,query,returnType,ArtifactNamespaceContext.INSTANCE); + } + + public Object getXPath( + Object root, String query, QName returnType, NamespaceContext context + ) { + return xpath(root, query, returnType, context); } public String getStringXPath(String xpath) { @@ -146,6 +152,7 @@ try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory .newInstance(); + docBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); returnValue = docBuilder.parse(inputStream); } catch (ParserConfigurationException e) { diff -r 6e16dc005704 -r 416ff31f6273 gnv/src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl --- a/gnv/src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl Tue Jan 05 08:52:49 2010 +0000 +++ b/gnv/src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl Wed Jan 06 09:13:45 2010 +0000 @@ -6,15 +6,15 @@ xmlns:art="http://www.intevation.de/2009/artifacts"> - +
- + @@ -23,37 +23,37 @@ - + - + - +
:: - +
- - + +
::
- - + +
- + @@ -62,10 +62,10 @@ - +
:: - +
-   +