Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 71:e4ecf3188bdf
Integrated FIS-Artifact
gnv-artifacts/trunk@62 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Thu, 10 Sep 2009 13:11:24 +0000 |
parents | 0035862b0295 |
children | 504570de21fd |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Thu Sep 10 09:40:49 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Thu Sep 10 13:11:24 2009 +0000 @@ -9,6 +9,9 @@ import java.util.Iterator; import java.util.Map; +import javax.xml.XMLConstants; +import javax.xml.xpath.XPathConstants; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -17,6 +20,7 @@ import de.intevation.artifactdatabase.Config; import de.intevation.artifactdatabase.DefaultArtifact; +import de.intevation.artifactdatabase.XMLUtils; import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.gnv.artifacts.context.GNVArtifactContext; @@ -28,6 +32,7 @@ import de.intevation.gnv.transition.Transition; import de.intevation.gnv.transition.TransitionFactory; import de.intevation.gnv.transition.exception.TransitionException; +import de.intevation.gnv.utils.ArtifactXMLUtilities; /** * @author Tim Englich <tim.englich@intevation.de> @@ -69,6 +74,8 @@ */ protected String name = null; + private ArtifactXMLUtilities xmlUtilities = new ArtifactXMLUtilities(); + /** * Constructor */ @@ -81,7 +88,7 @@ */ @Override public Document advance(Document target, Object context) { - Document result = super.newDocument(); + Document result = XMLUtils.newDocument(); if (this.current != null){ String transitionName = this.readTransitionName(target); if (this.current.isTransitionReachable(transitionName)){ @@ -136,7 +143,7 @@ */ @Override public Document feed(Document target, Object context) { - Document result = super.newDocument(); + Document result = XMLUtils.newDocument(); try { if (this.current != null){ this.current.putInputData(this.parseInputData(target)); @@ -178,7 +185,7 @@ protected Document createDescibeOutput(){ log.debug("GNVArtifactBase.createDescibeOutput"); - Document document = super.newDocument(); + Document document = XMLUtils.newDocument(); Element rootNode = this.createRootNode(document); this.createHeader(rootNode, document, "describe"); this.createOutputs(rootNode, document); @@ -191,33 +198,33 @@ } protected Element createRootNode(Document document){ - Element rootNode = createElement(document,"result"); + Element rootNode = xmlUtilities.createArtifactElement(document,"result"); document.appendChild(rootNode); return rootNode; } protected void createHeader(Element parent, Document document, String documentType){ - Element typeNode = createElement(document,"type"); + Element typeNode = xmlUtilities.createArtifactElement(document,"type"); typeNode.setAttribute("name", documentType); parent.appendChild(typeNode); - Element uuidNode = createElement(document,"uuid"); + Element uuidNode = xmlUtilities.createArtifactElement(document,"uuid"); uuidNode.setAttribute("value", super.identifier); parent.appendChild(uuidNode); - Element hashNode = createElement(document,"hash"); + Element hashNode = xmlUtilities.createArtifactElement(document,"hash"); hashNode.setAttribute("value", this.hash()); parent.appendChild(hashNode); } protected void createReachableStates(Element parent,Document document){ - Element stateNode = createElement(document,"reachable-states"); + Element stateNode = xmlUtilities.createArtifactElement(document,"reachable-states"); if (this.current != null){ Iterator<String> states = this.current.reachableTransitions().iterator(); while(states.hasNext()){ String value = states.next(); - Element currentNode = createElement(document,"state"); + Element currentNode = xmlUtilities.createArtifactElement(document,"state"); currentNode.setAttribute("name", value); currentNode.setAttribute("description", transitions.get(value).getDescription()); stateNode.appendChild(currentNode); @@ -227,7 +234,7 @@ } protected void createCurrentState(Element parent, Document document){ - Element stateNode = createElement(document,"state"); + Element stateNode = xmlUtilities.createArtifactElement(document,"state"); stateNode.setAttribute("name", this.current.getID()); stateNode.setAttribute("description", this.current.getDescription()); parent.appendChild(stateNode); @@ -235,14 +242,14 @@ protected void createModel(Element parent, Document document){ - Element modelNode = createElement(document,"model"); + Element modelNode = xmlUtilities.createArtifactElement(document,"model"); if (this.current != null){ Collection<InputValue> inputValues = this.current.getRequiredInputValues(); if (inputValues != null){ Iterator<InputValue> it = inputValues.iterator(); while(it.hasNext()){ InputValue inputValue = it.next(); - Element inputNode = createElement(document,"input"); + Element inputNode = xmlUtilities.createArtifactElement(document,"input"); inputNode.setAttribute("name", inputValue.getName()); inputNode.setAttribute("type", inputValue.getType()); modelNode.appendChild(inputNode); @@ -253,7 +260,7 @@ } protected void createUserInterface(Element parent, Document document){ - Element uiNode = createElement(document,"ui"); + Element uiNode = xmlUtilities.createArtifactElement(document,"ui"); if (this.current != null){ this.current.describe(document, uiNode); @@ -264,7 +271,7 @@ protected void createOutputs(Element parent, Document document){ log.debug("GNVArtifactBase.createOutputs"); - Element outputsNode = createElement(document,"outputs"); + Element outputsNode = xmlUtilities.createArtifactElement(document,"outputs"); if (this.current instanceof OutputTransition){ Collection<OutputMode> outputModes = ((OutputTransition)this.current).getOutputModes(); if (outputModes != null){ @@ -272,7 +279,7 @@ while(it.hasNext()){ OutputMode outputMode = it.next(); log.debug("Write Outputnode for "+ outputMode.toString()); - Element outputModeNode = createElement(document,"output"); + Element outputModeNode = xmlUtilities.createArtifactElement(document,"output"); outputModeNode.setAttribute("name", outputMode.getName()); outputModeNode.setAttribute("description", outputMode.getDescription()); outputModeNode.setAttribute("mime-type", outputMode.getMimeType()); @@ -285,21 +292,14 @@ parent.appendChild(outputsNode); } - /** - * @param document - * @return - */ - private Element createElement(Document document, String name) { - Element node = document.createElementNS(ArtifactNamespaceContext.NAMESPACE_URI, name); - node.setPrefix(ArtifactNamespaceContext.NAMESPACE_PREFIX); - return node; - } protected Collection<InputData> parseInputData(Document document){ log.debug("GNVArtifactBase.parseInputData"); Collection<InputData> returnValue = null; - NodeList inputElemets = Config.getNodeSetXPath(document, "action/data/input"); + log.debug(new ArtifactXMLUtilities().writeDocument2String(document)); + + NodeList inputElemets = (NodeList)XMLUtils.xpath(document, "/action/data/input",XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);//Config.getNodeSetXPath(document, ""); if(inputElemets != null){ returnValue = new ArrayList<InputData>(inputElemets.getLength()); for (int i = 0; i < inputElemets.getLength(); i++){