# HG changeset patch # User Ingo Weinzierl # Date 1263059745 0 # Node ID 70df44021a9f5443f21a2048ba85ac6e3d252ece # Parent 07672838fa5fa1d37165b350a5d99879a86aaa68 Next step of changing the concept how to use the user interface. Adapted namespaces and replaced FISArtifact with a ProxyArtifact. gnv-artifacts/trunk@525 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/ChangeLog Sat Jan 09 17:55:45 2010 +0000 @@ -1,3 +1,32 @@ +2010-01-09 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/artifacts/fis/FISSelectArtifact.java: + Artifact used for the initial steps when no product is chosen. + + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java: Factory + to create artifacts. It is used to put a new FISSelectArtifact into the + ProxyArtifact for the initial steps when no product is chosen. + + * doc/conf/conf.xml: Use the ProxyArtifact instead of FISArtifact and + GNVArtifactFactory to create it. + + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java: + - Defined XPath expressions at the top of the class instead of directly in + code. + - Use XMLUtils.ElementCreator to create new namespace aware nodes and + attributes. + - Defined 'describe' method to create user interface for initial steps. + + * src/main/java/de/intevation/gnv/profile/horizontalcrosssection/HorizontalCrossSectionMeshArtifact.java, + src/main/java/de/intevation/gnv/profile/verticalcrosssection/VerticalCrossSectionMeshArtifact.java, + src/main/java/de/intevation/gnv/profile/horizontal/HorizontalProfileArtifact.java, + src/main/java/de/intevation/gnv/profile/vertical/VerticalProfileArtifact.java, + src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java: + Moved 'describe' methods which had no special code to super class. + + * src/main/java/de/intevation/gnv/state/StateBase.java: Use + XMLUtils.ElementCreator to create new elements in xml documents. + 2010-01-09 Sascha L. Teichmann * doc/conf/conf.xml: Added configuration for vertical cross diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/doc/conf/conf.xml --- a/gnv-artifacts/doc/conf/conf.xml Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/doc/conf/conf.xml Sat Jan 09 17:55:45 2010 +0000 @@ -3,37 +3,37 @@ de.intevation.gnv.artifacts.context.GNVArtifactContextFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="3600000" artifact="de.intevation.artifactdatabase.ProxyArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -45,7 +45,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -53,7 +53,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -66,7 +66,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -79,7 +79,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -92,7 +92,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -105,7 +105,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -113,7 +113,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -126,7 +126,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -134,7 +134,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -147,7 +147,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -155,7 +155,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -163,7 +163,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -171,7 +171,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileMeshCrossArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -179,7 +179,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.verticalcrosssection.VerticalCrossSectionMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -187,7 +187,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontalcrosssection.HorizontalCrossSectionMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -200,7 +200,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -208,7 +208,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -216,7 +216,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontalcrosssection.HorizontalCrossSectionMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -229,7 +229,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -242,7 +242,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -253,7 +253,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -264,7 +264,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontalcrosssection.HorizontalCrossSectionMeshArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -280,7 +280,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -294,7 +294,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -308,7 +308,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.horizontal.HorizontalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -322,7 +322,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.timeseries.TimeSeriesArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -330,7 +330,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -343,7 +343,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory @@ -356,7 +356,7 @@ de.intevation.artifactdatabase.DefaultArtifactFactory + ttl="300000" artifact="de.intevation.gnv.profile.vertical.VerticalProfileInstantaneousPointArtifact">de.intevation.gnv.artifacts.GNVArtifactFactory diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Sat Jan 09 17:55:45 2010 +0000 @@ -27,6 +27,8 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.artifacts.fis.product.Product; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.state.DefaultInputData; import de.intevation.gnv.state.InputData; import de.intevation.gnv.state.InputValue; @@ -41,6 +43,7 @@ /** * @author Tim Englich + * @author Ingo Weinzierl * */ public abstract class GNVArtifactBase extends DefaultArtifact { @@ -65,6 +68,18 @@ + XPATH_IDENTIFIER_REPLACE + "']"; + public static final String XPATH_STATIC_NODE = "/art:result/art:ui/art:static"; + + public static final String XPATH_INPUT_DATA = "/art:action/art:data/art:input"; + + public static final String XPATH_INCLUDE_UI = "/art:action/art:include-ui"; + + public static final String XPATH_TARGET_NAME = "/art:action/art:target/@name"; + + public static final String XPATH_OUTPUT_NAME = "/art:action/art:out/@name"; + + public static final String XPATH_OUTPUT_PARAMS = "/art:action/art:out/art:params/art:input"; + /** * The current State */ @@ -80,6 +95,12 @@ */ protected Collection transitions = null; + + /** + * The current product + */ + protected Product product; + /** * The Name of the Artifact */ @@ -183,8 +204,8 @@ } protected String readStateName(Document document) { - String returnValue = Config.getStringXPath(document, - "action/target/@name"); + String returnValue = XMLUtils.xpathString( + document, XPATH_TARGET_NAME, ArtifactNamespaceContext.INSTANCE); return returnValue; } @@ -215,8 +236,10 @@ Document result = XMLUtils.newDocument(); try { if (this.current != null) { - Collection inputData = this.parseInputData(target, - "/action/data/input"); + Collection inputData = this.parseInputData( + target, + XPATH_INPUT_DATA); + if (!inputData.isEmpty()){ this.current.putInputData(inputData, super.identifier); result = new ArtifactXMLUtilities().createSuccessReport( @@ -241,6 +264,42 @@ return result; } + + /** + * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) + */ + @Override + public Document describe(Document data, CallContext context) { + log.debug("GNVArtifactBase.describe"); + + Document document = createDescibeOutput( + context.getMeta(), + identifier, + getIncludeUIFromDocument(data) + ); + + // insert node for rendering product field + Element staticNode = (Element) XMLUtils.xpath( + document, + XPATH_STATIC_NODE, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE + ); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + XMLUtils.XFORM_URL, + XMLUtils.XFORM_PREFIX + ); + + if (staticNode != null) { + Element staticUI = createSelectBox(creator, document, context); + staticNode.insertBefore(staticUI, staticNode.getFirstChild()); + } + + return document; + } + /** * @see de.intevation.artifactdatabase.DefaultArtifact#setup(java.lang.String, * java.lang.Object) @@ -290,29 +349,38 @@ } } - protected Document createDescibeOutput(CallMeta callMeta, String uuid, boolean incudeUI) { log.debug("GNVArtifactBase.createDescibeOutput"); Document document = XMLUtils.newDocument(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); Element rootNode = this.createRootNode(document); - this.createHeader(rootNode, document, "describe"); - this.createOutputs(rootNode, document); - this.createCurrentState(rootNode, document); - this.createReachableStates(rootNode, document); - this.createModel(rootNode, document); + this.createHeader(creator, rootNode, document, "describe"); + this.createOutputs(creator, rootNode, document); + this.createCurrentState(creator, rootNode, document); + this.createReachableStates(creator, rootNode, document); + this.createModel(creator, rootNode, document); if (incudeUI){ - this.createUserInterface(rootNode, document, callMeta, uuid); + this.createUserInterface(creator, rootNode, document, callMeta, uuid); } + return document; } protected boolean getIncludeUIFromDocument(Document document){ - String value = Config.getStringXPath(document, "action/include-ui"); + String value = XMLUtils.xpathString( + document, XPATH_INCLUDE_UI, ArtifactNamespaceContext.INSTANCE); + boolean includeUI = false; if (value != null){ includeUI = Boolean.parseBoolean(value); } + log.debug("INCLUDE UI? " + includeUI); return includeUI; } @@ -323,37 +391,86 @@ return rootNode; } - protected void createHeader(Element parent, Document document, - String documentType) { - Element typeNode = xmlUtilities.createArtifactElement(document, "type"); - typeNode.setAttribute("name", documentType); + protected void createHeader( + XMLUtils.ElementCreator creator, + Element parent, + Document document, + String documentType + ) { + Element typeNode = creator.create("type"); + creator.addAttr(typeNode, "name", documentType); parent.appendChild(typeNode); - Element uuidNode = xmlUtilities.createArtifactElement(document, "uuid"); - uuidNode.setAttribute("value", super.identifier); + Element uuidNode = creator.create("uuid"); + creator.addAttr(uuidNode, "value", super.identifier); parent.appendChild(uuidNode); - Element hashNode = xmlUtilities.createArtifactElement(document, "hash"); - hashNode.setAttribute("value", this.hash()); + Element hashNode = creator.create("hash"); + creator.addAttr(hashNode, "value", this.hash()); parent.appendChild(hashNode); } - protected void createReachableStates(Element parent, Document document) { - Element stateNode = xmlUtilities.createArtifactElement(document, - "reachable-states"); + protected Element createSelectBox( + XMLUtils.ElementCreator creator, + Document document, + CallContext context + ) { + RessourceFactory resource = RessourceFactory.getInstance(); + CallMeta callMeta = (CallMeta) context.getMeta(); + String productName = product.getName(); + + Element selectNode = creator.create("select1"); + creator.addAttr(selectNode, "ref", "product"); + + Element labelNode = creator.create("label"); + labelNode.setTextContent( + resource.getRessource(callMeta.getLanguages(), "product", "product") + ); + + Element choicesNode = creator.create("choices"); + + Element itemNode = creator.create("item"); + creator.addAttr(itemNode, "selected", "true"); + + Element choiceLabel = creator.create("label"); + choiceLabel.setTextContent(resource.getRessource( + callMeta.getLanguages(), + productName, + productName + )); + + Element choiceValue = creator.create("value"); + choiceValue.setTextContent(productName); + + itemNode.appendChild(choiceLabel); + itemNode.appendChild(choiceValue); + choicesNode.appendChild(itemNode); + + selectNode.appendChild(labelNode); + selectNode.appendChild(choicesNode); + + return selectNode; + } + + protected void createReachableStates( + XMLUtils.ElementCreator creator, + Element parent, + Document document + ) { + Element stateNode = creator.create("reachable-states"); if (this.current != null) { Iterator transitions = this.transitions.iterator(); while (transitions.hasNext()) { Transition tmpTransition = transitions.next(); if (tmpTransition.getFrom().equals(current.getID()) && tmpTransition.isValid(this.current)){ - Element currentNode = xmlUtilities.createArtifactElement( - document, "state"); - currentNode.setAttribute("name", tmpTransition.getTo()); + Element currentNode = creator.create("state"); + creator.addAttr(currentNode, "name", tmpTransition.getTo()); log.debug("Reachable State: " + tmpTransition.getTo()); - currentNode.setAttribute("description", - this.states.get(tmpTransition.getTo()) - .getDescription()); + creator.addAttr( + currentNode, + "description", + this.states.get(tmpTransition.getTo()).getDescription()); stateNode.appendChild(currentNode); } } @@ -361,17 +478,23 @@ parent.appendChild(stateNode); } - protected void createCurrentState(Element parent, Document document) { - Element stateNode = xmlUtilities.createArtifactElement(document, - "state"); - stateNode.setAttribute("name", this.current.getID()); - stateNode.setAttribute("description", this.current.getDescription()); + protected void createCurrentState( + XMLUtils.ElementCreator creator, + Element parent, + Document document + ) { + Element stateNode = creator.create("state"); + creator.addAttr(stateNode, "name", this.current.getID()); + creator.addAttr(stateNode, "description", this.current.getDescription()); parent.appendChild(stateNode); } - protected void createModel(Element parent, Document document) { - Element modelNode = xmlUtilities.createArtifactElement(document, - "model"); + protected void createModel( + XMLUtils.ElementCreator creator, + Element parent, + Document document + ) { + Element modelNode = creator.create("model"); if (this.current != null) { Collection inputValues = this.current .getRequiredInputValues(); @@ -379,10 +502,9 @@ Iterator it = inputValues.iterator(); while (it.hasNext()) { InputValue inputValue = it.next(); - Element inputNode = xmlUtilities.createArtifactElement( - document, "input"); - inputNode.setAttribute("name", inputValue.getName()); - inputNode.setAttribute("type", inputValue.getType()); + Element inputNode = creator.create("input"); + creator.addAttr(inputNode, "name", inputValue.getName()); + creator.addAttr(inputNode, "type", inputValue.getType()); modelNode.appendChild(inputNode); } } @@ -390,9 +512,14 @@ parent.appendChild(modelNode); } - protected void createUserInterface(Element parent, Document document, - CallMeta callMeta, String uuid) { - Element uiNode = xmlUtilities.createArtifactElement(document, "ui"); + protected void createUserInterface( + XMLUtils.ElementCreator creator, + Element parent, + Document document, + CallMeta callMeta, + String uuid + ) { + Element uiNode = creator.create("ui"); if (this.current != null) { this.current.describe(document, uiNode, callMeta, uuid); @@ -401,10 +528,13 @@ parent.appendChild(uiNode); } - protected void createOutputs(Element parent, Document document) { + protected void createOutputs( + XMLUtils.ElementCreator creator, + Element parent, + Document document + ) { log.debug("GNVArtifactBase.createOutputs"); - Element outputsNode = xmlUtilities.createArtifactElement(document, - "outputs"); + Element outputsNode = creator.create("outputs"); if (this.current instanceof OutputState) { Collection outputModes = ((OutputState) this.current) .getOutputModes(); @@ -413,34 +543,32 @@ while (it.hasNext()) { OutputMode outputMode = it.next(); log.debug("Write Outputnode for " + outputMode.toString()); - Element outputModeNode = xmlUtilities - .createArtifactElement(document, "output"); - outputModeNode.setAttribute("name", outputMode.getName()); - outputModeNode.setAttribute("description", outputMode - .getDescription()); - outputModeNode.setAttribute("mime-type", outputMode - .getMimeType()); + Element outputModeNode = creator.create("output"); + creator.addAttr( + outputModeNode, "name", outputMode.getName()); + creator.addAttr( + outputModeNode, "description", outputMode.getDescription()); + creator.addAttr( + outputModeNode, "mime-type", outputMode.getMimeType()); outputsNode.appendChild(outputModeNode); Collection inputParameters = outputMode .getInputParameters(); if (inputParameters != null) { - Element inputParametersNode = xmlUtilities - .createArtifactElement(document, "parameter"); + Element inputParametersNode = creator.create("parameter"); outputModeNode.appendChild(inputParametersNode); Iterator it2 = inputParameters.iterator(); while (it2.hasNext()) { InputValue inputValue = it2.next(); - Element inputParameterNode = xmlUtilities - .createArtifactElement(document, - "parameter"); + Element inputParameterNode = + creator.create("parameter"); + creator.addAttr( + inputParameterNode, "name", inputValue.getName()); + creator.addAttr( + inputParameterNode, "type", inputValue.getType()); + creator.addAttr( + inputParameterNode, "value", inputValue.getDefaultValue()); inputParametersNode.appendChild(inputParameterNode); - inputParameterNode.setAttribute("name", inputValue - .getName()); - inputParameterNode.setAttribute("type", inputValue - .getType()); - inputParameterNode.setAttribute("value", inputValue - .getDefaultValue()); } } } @@ -453,17 +581,13 @@ protected Collection parseInputData(Document document, String xPath) { - log.debug("GNVArtifactBase.parseInputData"); HashMap returnValue = null; - log.debug(new ArtifactXMLUtilities().writeDocument2String(document)); - NodeList inputElemets = (NodeList) XMLUtils.xpath(document, xPath, - XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE);// Config.getNodeSetXPath(document, - // ""); + XPathConstants.NODESET, ArtifactNamespaceContext.INSTANCE); if (inputElemets != null) { - returnValue = new HashMap(inputElemets - .getLength()); + returnValue = new HashMap(); + for (int i = 0; i < inputElemets.getLength(); i++) { Element inputDataNode = (Element)inputElemets.item(i); String name = inputDataNode.getAttribute("name"); @@ -497,7 +621,7 @@ if (current != null && current instanceof OutputState) { ((OutputState) current) .out(format, this.parseInputData( - format, "/action/out/params/input"), + format, XPATH_OUTPUT_PARAMS), outputStream, super.identifier, context); } } catch (StateException e) { @@ -507,7 +631,14 @@ } protected String readOutputType(Document document) { - String value = Config.getStringXPath(document, "action/out/@name"); + String value = XMLUtils.xpathString( + document, XPATH_OUTPUT_NAME, ArtifactNamespaceContext.INSTANCE); return value; } + + + public void setProduct(Product product) { + this.product = product; + } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactFactory.java Sat Jan 09 17:55:45 2010 +0000 @@ -0,0 +1,34 @@ +package de.intevation.gnv.artifacts; + +import de.intevation.artifactdatabase.DefaultArtifactFactory; +import de.intevation.artifactdatabase.ProxyArtifact; +import de.intevation.artifacts.Artifact; +import de.intevation.gnv.artifacts.fis.FISSelectArtifact; + +import org.apache.log4j.Logger; + +/** + * @author Ingo Weinzierl + */ +public class GNVArtifactFactory extends DefaultArtifactFactory { + + private static Logger logger = Logger.getLogger(GNVArtifactFactory.class); + + public GNVArtifactFactory() { + } + + @Override + public Artifact createArtifact(String identifier, Object context) { + Artifact artifact = super.createArtifact(identifier, context); + + if (artifact instanceof ProxyArtifact) { + FISSelectArtifact select = new FISSelectArtifact(); + select.setup(identifier, this, context); + + ((ProxyArtifact) artifact).setProxied(select); + } + + return artifact; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISSelectArtifact.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/FISSelectArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -0,0 +1,440 @@ +package de.intevation.gnv.artifacts.fis; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import de.intevation.artifactdatabase.DefaultArtifact; +import de.intevation.artifactdatabase.ProxyArtifact; +import de.intevation.artifactdatabase.XMLUtils; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; +import de.intevation.gnv.artifacts.GNVArtifactBase; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.artifacts.fis.product.DefaultProduct; +import de.intevation.gnv.artifacts.fis.product.Product; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; +import de.intevation.gnv.state.DefaultInputData; +import de.intevation.gnv.state.InputData; +import de.intevation.gnv.utils.ArtifactFactoryUtilities; + + +/** + * @author Ingo Weinzierl + */ +public class FISSelectArtifact extends DefaultArtifact { + + public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; + + public static final String XPATH_ARTIFACT_CONFIGURATION = + "/artifact-database/artifacts/artifact[@name='" + + XPATH_IDENTIFIER_REPLACE + "']"; + + public static final String XPATH_UUID = "art:action/art:uuid/@value"; + + public static final String XPATH_HASH = "art:action/art:hash/@value"; + + public static final String XPATH_INPUT_DATA_VALUE = + "art:action/art:data/art:input[@name='product']/@value"; + + /** + * this xpath is related to the config.xml document which doesn't have any + * prefixes yet + */ + public static final String XPATH_PRODUCTS = "products/product"; + + /** + * this xpath is related to the config.xml document which doesn't have any + * prefixes yet + */ + public static final String XPATH_PRODUCT_PARAMETER = "parameters/parameter"; + + public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; + public static final String XFORM_PREFIX = "xform"; + + private static Logger log = Logger.getLogger(FISSelectArtifact.class); + + private HashMap products; + private Product current; + private Artifact artifact; + private String name; + + public FISSelectArtifact() { + super(); + } + + + @Override + public void setup( + String identifier, + ArtifactFactory factory, + Object context + ) { + log.debug("setup()"); + super.setup(identifier, factory, context); + this.name = factory.getName(); + + if (context instanceof GNVArtifactContext) { + GNVArtifactContext gnvContext = (GNVArtifactContext) context; + Document doc = gnvContext.getConfig(); + Node artifactNode = getConfigurationFragment(doc); + + NodeList products = (NodeList) XMLUtils.xpath( + artifactNode, XPATH_PRODUCTS, XPathConstants.NODESET); + + if (products != null) { + this.products = new HashMap(products.getLength()); + + for (int i = 0; i < products.getLength(); i++) { + Element productNode = (Element)products.item(i); + String productName = productNode.getAttribute("name"); + NodeList parameterNodes = (NodeList) XMLUtils.xpath( + productNode, + XPATH_PRODUCT_PARAMETER, + XPathConstants.NODESET + ); + + Collection parameter = null; + if (parameterNodes != null) { + parameter = new ArrayList(parameterNodes.getLength()); + + for (int j = 0; j < parameterNodes.getLength(); j++) { + Element parameterNode = (Element)parameterNodes.item(j); + String name = parameterNode.getAttribute("name"); + String value = parameterNode.getAttribute("value"); + parameter.add(new DefaultInputData(name, value)); + } + } + Node artifactFactoryNode = (Node) XMLUtils.xpath( + productNode, "artifact-factory", XPathConstants.NODE + ); + + ArtifactFactory artifactFactory = + new ArtifactFactoryUtilities().createArtitfactFactor( + doc, artifactFactoryNode + ); + + this.products.put(productName, new DefaultProduct( + productName, parameter, artifactFactory) + ); + } + } + } + } + + + @Override + public Document feed(Document target, CallContext context) { + log.debug("FISSelectArtifact.feed()"); + + if (artifact == null) { + Document document = XMLUtils.newDocument(); + String productName = XMLUtils.xpathString( + target, + XPATH_INPUT_DATA_VALUE, + ArtifactNamespaceContext.INSTANCE + ); + + current = (Product) products.get(productName); + + String reportNode = null; + String resultNode = null; + String msg = null; + + if (current != null) { + reportNode = "result"; + resultNode = "success"; + msg = "Feed was successfully. New Artifact created."; + } + else { + reportNode = "exceptionreport"; + resultNode = "exception"; + msg = "Product does not exist."; + } + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element report = creator.create(reportNode); + Element success = creator.create(resultNode); + success.setTextContent(msg); + report.appendChild(success); + document.appendChild(report); + + return document; + } + else { + return artifact.feed(target, context); + } + } + + + @Override + public Document advance(Document target, CallContext context) { + log.debug("FISSelectArtifact.advance()"); + + if (artifact != null) { + Document result = artifact.advance(target, context); + context.putContextValue(ProxyArtifact.REPLACE_PROXY, artifact); + return result; + } + + Document result = XMLUtils.newDocument(); + if (current == null) { + // artifact needs to be feeded first + String msg = "Artifact is not configured properly. Call 'feed' fist."; + log.error(msg); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + result, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element report = creator.create("exceptionreport"); + Element exception = creator.create("exception"); + exception.setTextContent(msg); + report.appendChild(exception); + result.appendChild(report); + + return result; + } + + String uuid = XMLUtils.xpathString( + target, XPATH_UUID, ArtifactNamespaceContext.INSTANCE + ); + + String hash = XMLUtils.xpathString( + target, XPATH_HASH, ArtifactNamespaceContext.INSTANCE + ); + + artifact = current.getArtifactFactory().createArtifact( + uuid, context + ); + + Document feedDocument = feedDocument(uuid, hash); + artifact.feed(feedDocument(uuid, hash), context); + + result = ((GNVArtifactBase) artifact).initialize(context); + if (artifact instanceof GNVArtifactBase) { + ((GNVArtifactBase) artifact).setProduct(current); + } + context.putContextValue(ProxyArtifact.REPLACE_PROXY, artifact); + return result; + } + + + @Override + public Document describe(Document data, CallContext context) { + log.debug("FISSelectArtifact.describe()"); + + // create root node + Document document = XMLUtils.newDocument(); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + Element rootNode = creator.create("result"); + Element typeNode = creator.create("type"); + creator.addAttr(typeNode, "name", "describe"); + rootNode.appendChild(typeNode); + + Element uuidNode = creator.create("uuid"); + creator.addAttr(uuidNode, "value", super.identifier); + rootNode.appendChild(uuidNode); + + Element hashNode = creator.create("hash"); + creator.addAttr(hashNode, "value", hash()); + rootNode.appendChild(hashNode); + + // create output node + Element out = creator.create("outputs"); + rootNode.appendChild(out); + + // create current state + Element state = creator.create("state"); + creator.addAttr(state, "name", "choose-product"); + creator.addAttr(state, "description", "Auswahl des Produktes."); + rootNode.appendChild(state); + + // create reachable states + Element rStates = creator.create("reachable-states"); + appendProducts(document, rStates, context); + rootNode.appendChild(rStates); + + // create model + Element model = creator.create("model"); + Element input = creator.create("input"); + creator.addAttr(input, "name", "product"); + creator.addAttr(input, "type", "String"); + model.appendChild(input); + rootNode.appendChild(model); + + // create ui + Element ui = creator.create("ui"); + Element dynamic = creator.create("dynamic"); + appendSelectProducts(document, dynamic, context.getMeta()); + ui.appendChild(dynamic); + rootNode.appendChild(ui); + + document.appendChild(rootNode); + return document; + } + + + @Override + public void out(Document document, OutputStream out, CallContext context) + throws IOException + { + log.debug("FISSelectArtifact.out()"); + if (artifact != null) { + artifact.out(document, out, context); + } + } + + + protected void appendProducts( + Document document, + Node parent, + Object context + ) { + Iterator iter = products.values().iterator(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + while(iter.hasNext()) { + Product prod = (Product) iter.next(); + String name = prod.getName(); + + Element current = creator.create("state"); + creator.addAttr(current, "name", name); + creator.addAttr(current, "description", name); + parent.appendChild(current); + } + } + + + protected void appendSelectProducts( + Document document, + Node node, + CallMeta callMeta + ) { + RessourceFactory ressource = RessourceFactory.getInstance(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + XFORM_URL, + XFORM_PREFIX + ); + + String selectboxName = "product"; + Element selectNode = creator.create("select1"); + creator.addAttr(selectNode, "ref", selectboxName); + + Element lableNode = creator.create("label"); + lableNode.setTextContent(ressource.getRessource(callMeta.getLanguages(), + selectboxName, + selectboxName + ) + ); + + Element choiceNode = creator.create("choices"); + selectNode.appendChild(lableNode); + selectNode.appendChild(choiceNode); + + Iterator it = products.values().iterator(); + while (it.hasNext()) { + Product p = (Product) it.next(); + Element itemNode = creator.create("item"); + Element choiceLableNode = creator.create("label"); + choiceLableNode.setTextContent(ressource.getRessource( + callMeta.getLanguages(), + p.getName(), + p.getName() + )); + itemNode.appendChild(choiceLableNode); + + Element choiceValueNode = creator.create("value"); + choiceValueNode.setTextContent(p.getName()); + itemNode.appendChild(choiceValueNode); + choiceNode.appendChild(itemNode); + } + + node.appendChild(selectNode); + } + + + protected Node getConfigurationFragment(Document document) { + String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( + XPATH_IDENTIFIER_REPLACE, name + ); + + return (Node) XMLUtils.xpath(document, xpathQuery, XPathConstants.NODE); + } + + + protected Document feedDocument(String uuid, String hash) { + Document document = XMLUtils.newDocument(); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + Element rootNode = creator.create("action"); + + Element typeNode = creator.create("type"); + creator.addAttr(typeNode, "name", "feed"); + rootNode.appendChild(typeNode); + + Element uuidNode = creator.create("uuid"); + creator.addAttr(uuidNode, "value", uuid); + rootNode.appendChild(uuidNode); + + Element hashNode = creator.create("hash"); + creator.addAttr(hashNode, "value", hash); + rootNode.appendChild(hashNode); + + Element dataNode = creator.create("data"); + rootNode.appendChild(dataNode); + + Collection parameter = this.current.getParameter(); + if (parameter != null) { + Iterator parameterIt = parameter.iterator(); + + while (parameterIt.hasNext()) { + InputData inputData = parameterIt.next(); + + Element inputNode = creator.create("input"); + creator.addAttr(inputNode, "name", inputData.getName()); + creator.addAttr(inputNode, "value", inputData.getValue()); + dataNode.appendChild(inputNode); + } + } + document.appendChild(rootNode); + return document; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontal/HorizontalProfileArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontal/HorizontalProfileArtifact.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontal/HorizontalProfileArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -4,10 +4,8 @@ package de.intevation.gnv.profile.horizontal; import org.apache.log4j.Logger; -import org.w3c.dom.Document; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.GNVArtifactBase; /** @@ -35,16 +33,6 @@ this.name = "horizontalProfile"; } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) - */ - @Override - public Document describe(Document data, CallContext context) { - log.debug("HorizontalProfileArtifact.describe"); - return super.createDescibeOutput(context.getMeta(), - super.identifier, - this.getIncludeUIFromDocument(data)); - } /** * @see de.intevation.gnv.artifacts.GNVArtifactBase#setup(java.lang.String, diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontalcrosssection/HorizontalCrossSectionMeshArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontalcrosssection/HorizontalCrossSectionMeshArtifact.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/profile/horizontalcrosssection/HorizontalCrossSectionMeshArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -4,10 +4,8 @@ package de.intevation.gnv.profile.horizontalcrosssection; import org.apache.log4j.Logger; -import org.w3c.dom.Document; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.GNVArtifactBase; /** @@ -35,16 +33,6 @@ this.name = "horizontalCrossSectionMesh"; } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) - */ - @Override - public Document describe(Document data, CallContext context) { - log.debug("HorizontalCrossSectionMeshArtifact.describe"); - return super.createDescibeOutput(context.getMeta(), - super.identifier, - this.getIncludeUIFromDocument(data)); - } /** * @see de.intevation.gnv.artifacts.GNVArtifactBase#setup(java.lang.String, diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/profile/vertical/VerticalProfileArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/profile/vertical/VerticalProfileArtifact.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/profile/vertical/VerticalProfileArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -4,10 +4,8 @@ package de.intevation.gnv.profile.vertical; import org.apache.log4j.Logger; -import org.w3c.dom.Document; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.GNVArtifactBase; /** @@ -34,16 +32,6 @@ this.name = "verticalProfile"; } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) - */ - @Override - public Document describe(Document data, CallContext context) { - log.debug("VerticalProfileArtifact.describe"); - return super.createDescibeOutput(context.getMeta(), - super.identifier, - this.getIncludeUIFromDocument(data)); - } /** * @see de.intevation.gnv.artifacts.GNVArtifactBase#setup(java.lang.String, diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/profile/verticalcrosssection/VerticalCrossSectionMeshArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/profile/verticalcrosssection/VerticalCrossSectionMeshArtifact.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/profile/verticalcrosssection/VerticalCrossSectionMeshArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -4,10 +4,8 @@ package de.intevation.gnv.profile.verticalcrosssection; import org.apache.log4j.Logger; -import org.w3c.dom.Document; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.GNVArtifactBase; /** @@ -35,16 +33,6 @@ this.name = "verticalCrossSectionMesh"; } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) - */ - @Override - public Document describe(Document data, CallContext context) { - log.debug("VerticalCrossSectionMeshArtifact.describe"); - return super.createDescibeOutput(context.getMeta(), - super.identifier, - this.getIncludeUIFromDocument(data)); - } /** * @see de.intevation.gnv.artifacts.GNVArtifactBase#setup(java.lang.String, diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Sat Jan 09 17:55:45 2010 +0000 @@ -21,6 +21,8 @@ import org.w3c.dom.NodeList; import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.XMLUtils; +import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.GNVArtifactBase; import de.intevation.gnv.artifacts.cache.CacheFactory; @@ -37,7 +39,6 @@ import de.intevation.gnv.state.describedata.NamedCollection; import de.intevation.gnv.state.describedata.SingleValueDescribeData; import de.intevation.gnv.state.exception.StateException; -import de.intevation.gnv.utils.ArtifactXMLUtilities; import de.intevation.gnv.utils.InputValidator; /** @@ -519,21 +520,34 @@ log.debug("StateBase.describe"); Collection descibeData = this.getDescibeData(uuid); if (descibeData != null) { - ArtifactXMLUtilities xmlutilities = new ArtifactXMLUtilities(); Iterator it = descibeData.iterator(); - Node staticNode = xmlutilities.createArtifactElement(document, - "static"); - Node dynamic = xmlutilities.createArtifactElement(document, - "dynamic"); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + Node staticNode = creator.create("static"); + Node dynamic = creator.create("dynamic"); + rootNode.appendChild(staticNode); rootNode.appendChild(dynamic); + + XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator( + document, + XMLUtils.XFORM_URL, + XMLUtils.XFORM_PREFIX + ); + while (it.hasNext()) { Object o = it.next(); if ((!it.hasNext() && dataName != null)) { - appendToDynamicNode(document, dynamic, callMeta, o); + appendToDynamicNode( + xCreator, document, dynamic, callMeta, o); } else { - appendToStaticNode(document, staticNode, callMeta, o); + appendToStaticNode( + xCreator, document, staticNode, callMeta, o); } } } @@ -541,10 +555,11 @@ protected void appendToStaticNode( - Document document, - Node staticNode, - CallMeta callMeta, - Object o + XMLUtils.ElementCreator creator, + Document document, + Node staticNode, + CallMeta callMeta, + Object o ) { if (o instanceof Collection) { String name = null; @@ -558,17 +573,13 @@ name = names[names.length - 1].toString(); } - log.debug("Name of attribute: " + name); - Element selectNode = ArtifactXMLUtilities.createXFormElement( - document, multiselect ? "select" : "select1"); - selectNode.setAttribute("ref", name); + Element selectNode = creator.create(multiselect?"select":"select1"); + creator.addAttr(selectNode, "ref", name); - Element lableNode = ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element lableNode = creator.create("label"); lableNode.setTextContent(RessourceFactory.getInstance() .getRessource(callMeta.getLanguages(), name, name)); - Element choiceNode = ArtifactXMLUtilities.createXFormElement( - document, "choices"); + Element choiceNode = creator.create("choices"); Collection values = (Collection) o; Iterator resultIt = values.iterator(); @@ -576,22 +587,17 @@ KeyValueDescibeData result = resultIt.next(); if (result.isSelected()) { - Element itemNode = ArtifactXMLUtilities.createXFormElement( - document, "item"); + Element itemNode = creator.create("item"); - itemNode.setAttribute("selected", "true"); + creator.addAttr(itemNode, "selected", "true"); - Element choiceLableNode = - ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element choiceLableNode = creator.create("label"); choiceLableNode.setTextContent(result.getValue()); itemNode.appendChild(choiceLableNode); - Element choicValueNode = - ArtifactXMLUtilities.createXFormElement( - document, "value"); - choicValueNode.setTextContent("" + result.getKey()); - itemNode.appendChild(choicValueNode); + Element choiceValueNode = creator.create("value"); + choiceValueNode.setTextContent("" + result.getKey()); + itemNode.appendChild(choiceValueNode); choiceNode.appendChild(itemNode); } } @@ -602,6 +608,7 @@ } else if (o instanceof MinMaxDescribeData) { appendMinMaxDescribeData( + creator, document, staticNode, callMeta, @@ -609,6 +616,7 @@ } else if (o instanceof SingleValueDescribeData) { appendSingleValueDescribeData( + creator, document, staticNode, callMeta, @@ -618,10 +626,11 @@ protected void appendToDynamicNode( - Document document, - Node dynamicNode, - CallMeta callMeta, - Object o + XMLUtils.ElementCreator creator, + Document document, + Node dynamicNode, + CallMeta callMeta, + Object o ) { if (o instanceof Collection) { String name = null; @@ -633,37 +642,31 @@ } else { Object[] names = this.inputValueNames.toArray(); name = names[names.length - 1].toString(); - } + } - Element selectNode = ArtifactXMLUtilities.createXFormElement( - document, multiselect ? "select" : "select1"); - selectNode.setAttribute("ref", name); + Element selectNode = creator.create(multiselect?"select":"select1"); + creator.addAttr(selectNode, "ref", name); - Element lableNode = ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element lableNode = creator.create("label"); lableNode.setTextContent(RessourceFactory.getInstance() .getRessource(callMeta.getLanguages(), name, name)); - Element choiceNode = ArtifactXMLUtilities.createXFormElement( - document, "choices"); + Element choiceNode = creator.create("choices"); Collection values = (Collection) o; Iterator resultIt = values.iterator(); while (resultIt.hasNext()) { KeyValueDescibeData result = resultIt.next(); - Element itemNode = ArtifactXMLUtilities.createXFormElement( - document, "item"); + Element itemNode = creator.create("item"); if (result.isSelected()) { itemNode.setAttribute("selected", "true"); } - Element choiceLableNode = - ArtifactXMLUtilities.createXFormElement(document, "label"); + Element choiceLableNode = creator.create("label"); choiceLableNode.setTextContent(result.getValue()); itemNode.appendChild(choiceLableNode); - Element choicValueNode = ArtifactXMLUtilities.createXFormElement( - document, "value"); + Element choicValueNode = creator.create("value"); choicValueNode.setTextContent("" + result.getKey()); itemNode.appendChild(choicValueNode); choiceNode.appendChild(itemNode); @@ -675,6 +678,7 @@ } else if (o instanceof MinMaxDescribeData) { appendMinMaxDescribeData( + creator, document, dynamicNode, callMeta, @@ -682,6 +686,7 @@ } else if (o instanceof SingleValueDescribeData) { appendSingleValueDescribeData( + creator, document, dynamicNode, callMeta, @@ -691,10 +696,11 @@ protected void appendMinMaxDescribeData( - Document document, - Node node, - CallMeta callMeta, - Object o + XMLUtils.ElementCreator creator, + Document document, + Node node, + CallMeta callMeta, + Object o ) { MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; Object min = minMaxDescibeData.getMinValue(); @@ -709,11 +715,9 @@ max = DateUtils.getPatternedDateAmer(d); } - Element groupNode = ArtifactXMLUtilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", minMaxDescibeData.getName()); - Element groupNodeLableNode = - ArtifactXMLUtilities.createXFormElement(document, "label"); + Element groupNode = creator.create("group"); + creator.addAttr(groupNode, "ref", minMaxDescibeData.getName()); + Element groupNodeLableNode = creator.create("label"); groupNodeLableNode.setTextContent(RessourceFactory .getInstance().getRessource( callMeta.getLanguages(), @@ -721,35 +725,29 @@ minMaxDescibeData.getName())); groupNode.appendChild(groupNodeLableNode); - Element inputMinNode = ArtifactXMLUtilities.createXFormElement( - document, "input"); - inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); - Element inputMinLableNode = ArtifactXMLUtilities - .createXFormElement(document, "label"); + Element inputMinNode = creator.create("input"); + creator.addAttr(inputMinNode, "ref", MINVALUEFIELDNAME); + Element inputMinLableNode = creator.create("label"); inputMinLableNode.setTextContent(RessourceFactory .getInstance().getRessource( callMeta.getLanguages(), MINVALUEFIELDNAME, MINVALUEFIELDNAME)); inputMinNode.appendChild(inputMinLableNode); - Element inputMinValueNode = ArtifactXMLUtilities.createXFormElement( - document, "value"); + Element inputMinValueNode = creator.create("value"); inputMinValueNode.setTextContent(min.toString()); inputMinNode.appendChild(inputMinValueNode); - Element inputMaxNode = ArtifactXMLUtilities.createXFormElement( - document, "input"); - inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); - Element inputMaxLableNode = ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element inputMaxNode = creator.create("input"); + creator.addAttr(inputMaxNode, "ref", MAXVALUEFIELDNAME); + Element inputMaxLableNode = creator.create("label"); inputMaxLableNode.setTextContent(RessourceFactory .getInstance().getRessource( callMeta.getLanguages(), MAXVALUEFIELDNAME, MAXVALUEFIELDNAME)); inputMaxNode.appendChild(inputMaxLableNode); - Element inputMaxValueNode = ArtifactXMLUtilities.createXFormElement( - document, "value"); + Element inputMaxValueNode = creator.create("value"); inputMaxValueNode.setTextContent(max.toString()); inputMaxNode.appendChild(inputMaxValueNode); @@ -762,18 +760,18 @@ protected void appendSingleValueDescribeData( - Document document, - Node node, - CallMeta callMeta, - Object o + XMLUtils.ElementCreator creator, + Document document, + Node node, + CallMeta callMeta, + Object o ) { SingleValueDescribeData svdb = (SingleValueDescribeData) o; - Element groupNode = ArtifactXMLUtilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", svdb.getName()); - Element groupNodeLableNode = ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element groupNode = creator.create("group"); + creator.addAttr(groupNode, "ref", svdb.getName()); + + Element groupNodeLableNode = creator.create("label"); groupNodeLableNode.setTextContent(RessourceFactory .getInstance().getRessource( callMeta.getLanguages(), @@ -781,17 +779,14 @@ svdb.getName())); groupNode.appendChild(groupNodeLableNode); - Element inputNode = ArtifactXMLUtilities.createXFormElement( - document, "input"); - inputNode.setAttribute("ref", svdb.getName()); + Element inputNode = creator.create("input"); + creator.addAttr(inputNode, "ref", svdb.getName()); - Element inputLableNode = ArtifactXMLUtilities.createXFormElement( - document, "label"); + Element inputLableNode = creator.create("label"); inputLableNode.setTextContent(""); inputNode.appendChild(inputLableNode); - Element inputValueNode = ArtifactXMLUtilities.createXFormElement( - document, "value"); + Element inputValueNode = creator.create("value"); inputValueNode.setTextContent(svdb.getValue()); inputNode.appendChild(inputValueNode); @@ -834,3 +829,4 @@ return this.inputData != null ? this.inputData.values() : null; } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: diff -r 07672838fa5f -r 70df44021a9f gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java Sat Jan 09 16:58:53 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/timeseries/TimeSeriesArtifact.java Sat Jan 09 17:55:45 2010 +0000 @@ -4,17 +4,17 @@ package de.intevation.gnv.timeseries; import org.apache.log4j.Logger; -import org.w3c.dom.Document; import de.intevation.artifacts.ArtifactFactory; -import de.intevation.artifacts.CallContext; import de.intevation.gnv.artifacts.GNVArtifactBase; /** * @author Tim Englich - * + * @author Ingo Weinzierl + * */ public class TimeSeriesArtifact extends GNVArtifactBase { + /** * the logger, used to log exceptions and additonaly information */ @@ -34,16 +34,6 @@ this.name = "timeSeries"; } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#describe(org.w3c.dom.Document, de.intevation.artifacts.CallContext) - */ - @Override - public Document describe(Document data, CallContext context) { - log.debug("TimeSeriesArtifact.describe"); - return super.createDescibeOutput(context.getMeta(), - super.identifier, - this.getIncludeUIFromDocument(data)); - } /** * @see de.intevation.gnv.artifacts.GNVArtifactBase#setup(java.lang.String, @@ -55,3 +45,4 @@ super.setup(identifier, factory, context); } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: