Mercurial > dive4elements > gnv-client
changeset 389:416ff31f6273
Removed local-name() method from xsl stylesheet and adjusted xpathes while reading xml documents.
gnv/trunk@511 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 06 Jan 2010 09:13:45 +0000 |
parents | 6e16dc005704 |
children | f2e2053ecf23 |
files | gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/ChangeOptionsAction.java gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java gnv/src/main/java/de/intevation/gnv/artifactdatabase/client/DefaultArtifactDatabaseClient.java gnv/src/main/java/de/intevation/gnv/util/ArtifactNamespaceContext.java gnv/src/main/java/de/intevation/gnv/util/XMLUtils.java gnv/src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl |
diffstat | 7 files changed, 116 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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 <ingo.weinzierl@intevation.de> + + * 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 <ingo.weinzierl@intevation.de> * src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl: Removed
--- 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"));
--- 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(
--- 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<ArtifactObject> resultValues = new ArrayList<ArtifactObject>( 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<String, OutputMode> outputModes = null; if (outputNode != null) { NodeList outputModesNodes = xmlUtils.getNodeSetXPath( - outputNode, "output"); + outputNode, "art:output"); if (outputModesNodes != null) { outputModes = new HashMap<String, OutputMode>( outputModesNodes.getLength()); @@ -406,7 +407,7 @@ outputModeNode, "@mime-type"); NodeList parameterNodes = xmlUtils.getNodeSetXPath( - outputModeNode, "parameter/parameter"); + outputModeNode, "art:parameter/art:parameter"); Collection<OutputParameter> parameter = null; if (parameterNodes != null) { parameter = new ArrayList<OutputParameter>( @@ -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<String> reachableStates = new ArrayList<String>( 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<String> inputParameter = new ArrayList<String>( inputNodes.getLength()); @@ -707,7 +708,7 @@ if (resultDocument != null) { NodeList statisticSetNodes = xmlUtils.getNodeSetXPath(resultDocument, - "/statistics/statistic"); + "/art:statistics/art:statistic"); resultValues = new ArrayList<ArtifactStatisticsSet> (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);
--- /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:
--- 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) {
--- 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"> <xsl:output method="html" version="1.0" encoding="UTF-8" omit-xml-declaration="no"/> - <xsl:template match="*[local-name() = 'select']"> + <xsl:template match="xform:select"> <xsl:variable name="selectName" select="@ref"/> <div id="timeseriesfilter"> <table> <tr> - <th class="parameter"><xsl:value-of select="*[local-name() = 'label']"/>:</th> + <th class="parameter"><xsl:value-of select="xform:label"/>:</th> <td> <table> - <xsl:apply-templates select="choices/item" mode="table"/> + <xsl:apply-templates select="xform:choices/xform:item" mode="table"/> </table> </td> </tr> @@ -23,37 +23,37 @@ </xsl:template> - <xsl:template match="*[local-name() = 'item']" mode="table"> + <xsl:template match="xform:item" mode="table"> <xsl:if test="@selected = 'true'"> <tr> - <td class="value"><xsl:value-of select="./label"/></td> + <td class="value"><xsl:value-of select="./xform:label"/></td> </tr> </xsl:if> </xsl:template> - <xsl:template match="*[local-name() = 'select1']"> + <xsl:template match="xform:select1"> <xsl:variable name="selectName" select="@ref"/> <div id="timeseriesfilter"> <table> <tr> - <th class="parameter"><xsl:value-of select="*[local-name() = 'label']"/>:</th> - <td><xsl:value-of select="./choices/item/label" /></td> + <th class="parameter"><xsl:value-of select="xform:label"/>:</th> + <td><xsl:value-of select="./xform:choices/xform:item/xform:label" /></td> </tr> </table> </div> </xsl:template> - <xsl:template match="*[local-name() = 'group']"> - <xsl:variable name="inputName" select="*[local-name() = 'label']"/> + <xsl:template match="xform:group"> + <xsl:variable name="inputName" select="xform:label"/> <div id="timeseriesfilter"> <table> <tr> - <th class="parameter"><xsl:value-of select="*[local-name() = 'label']"/>:</th> + <th class="parameter"><xsl:value-of select="xform:label"/>:</th> <td> <table> - <xsl:apply-templates select="input" mode="table"/> + <xsl:apply-templates select="xform:input" mode="table"/> </table> </td> </tr> @@ -62,10 +62,10 @@ </xsl:template> - <xsl:template match="*[local-name() = 'input']" mode="table"> + <xsl:template match="xform:input" mode="table"> <tr> <td class="value"> - <xsl:value-of select="./label"/> <xsl:value-of select="./value"/> + <xsl:value-of select="./xform:label"/> <xsl:value-of select="./xform:value"/> </td> </tr> </xsl:template>