# HG changeset patch # User Ingo Weinzierl # Date 1265725675 0 # Node ID e8ebdbc7f1e316f6efe7d71bb209494597159c27 # Parent 938ce81a6bd029095783406e80e05448627dd97c First step of removing the cache blob. The static part of the describe document will be created by using the input data stored at each state. Some TODOs left (see ChangeLog). gnv-artifacts/trunk@671 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 938ce81a6bd0 -r e8ebdbc7f1e3 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Tue Feb 09 13:01:20 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue Feb 09 14:27:55 2010 +0000 @@ -1,3 +1,15 @@ +2010-02-09 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/state/StateBase.java: Do not query the + cache / database for rendering the static part of the describe document - + just take the input data stored at each state. + + TODOs: + - Store 'description' of each chosen value. At the moment we are able to + render an id of value, only. + - Take care of input elements with multi selection. + - The subarea node disappears if we don't select any. + 2010-02-09 Tim Englich * doc/conf/conf.xml: diff -r 938ce81a6bd0 -r e8ebdbc7f1e3 gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Feb 09 13:01:20 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Tue Feb 09 14:27:55 2010 +0000 @@ -1,6 +1,3 @@ -/** - * - */ package de.intevation.gnv.state; import java.util.ArrayList; @@ -61,27 +58,30 @@ * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(GNVArtifactBase.class); - + private final static String MINVALUEFIELDNAME = "minvalue"; private final static String MAXVALUEFIELDNAME = "maxvalue"; - + private final static String NODATASELECTIONKEY = "n/n"; - + public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA"; public final static String XPATH_STATIC_UI = "art:static"; public final static String XPATH_DYNAMIC_UI = "art:dynamic"; + /** input value names which should not be rendered from State itself */ + public final static String[] BLACKLIST = {"sourceid", "fisname"}; + private String id = null; private String description = null; protected String dataName = null; - + protected String preSettingsName = null; protected boolean dataMultiSelect = false; - + protected boolean dataNoSelect = false; protected String queryID = null; @@ -93,7 +93,7 @@ private State parent = null; protected Map inputData = null; - + private Map preSettings = null; /** @@ -564,11 +564,55 @@ return keyValueDescibeData; } + + public String findNewValue() { + Iterator iter = inputValueNames.iterator(); + + while (iter.hasNext()) { + String key = (String) iter.next(); + boolean old = false; + + StateBase parent = (StateBase) getParent(); + if (parent == null) { + // first state should always render a dynamic part + old = true; + } + + while (parent != null) { + if (parent.inputValueNames.contains(key) || inBlackList(key)) { + old = true; + break; + } + + parent = (StateBase) parent.getParent(); + } + + if (!old) { + return key; + } + } + + return null; + } + + + public static boolean inBlackList(String key) { + int length = BLACKLIST.length; + for (int i = 0; i < length; i++) { + if (BLACKLIST[i].equals(key)) { + return true; + } + } + + return false; + } + /** * @see de.intevation.gnv.state.State#describe(org.w3c.dom.Document, * org.w3c.dom.Node, de.intevation.artifacts.CallMeta, * java.lang.String) */ + /* public void describe( Document document, Node rootNode, @@ -621,6 +665,98 @@ } } } + */ + + + public void describe( + Document document, + Node rootNode, + CallContext context, + String uuid) + { + log.debug("StateBase.describe"); + + XMLUtils.ElementCreator xCreator = new XMLUtils.ElementCreator( + document, + XMLUtils.XFORM_URL, + XMLUtils.XFORM_PREFIX + ); + + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX + ); + + // append dynamic node + Node dynamic = (Node) XMLUtils.xpath( + rootNode, + XPATH_DYNAMIC_UI, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE + ); + + describeDynamic( + creator, xCreator, document, dynamic, context, uuid); + + // append static nodes + Node staticNode = (Node) XMLUtils.xpath( + rootNode, + XPATH_STATIC_UI, + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE + ); + + describeStatic( + creator,xCreator, document, staticNode, context,uuid); + } + + + protected void describeDynamic( + XMLUtils.ElementCreator artCreator, + XMLUtils.ElementCreator creator, + Document document, + Node dynamic, + CallContext context, + String uuid) + { + log.debug("StateBase.describeDynamic"); + CallMeta callMeta = context.getMeta(); + + List descibeData = getDescibeData(uuid); + if (descibeData != null) { + Iterator it = descibeData.iterator(); + + while (it.hasNext()) { + Object o = it.next(); + if ((!it.hasNext() && dataName != null)) { + appendToDynamicNode( + artCreator, creator, document, dynamic, callMeta, o); + } + } + } + } + + + protected void describeStatic( + XMLUtils.ElementCreator artCreator, + XMLUtils.ElementCreator creator, + Document document, + Node staticNode, + CallContext context, + String uuid) + { + State parent = getParent(); + if (parent != null && parent instanceof StateBase) { + ((StateBase) parent).describeStatic( + artCreator, creator, document, staticNode, context, uuid); + } + + CallMeta callMeta = context.getMeta(); + String inputKey = findNewValue(); + appendToStaticNode( + artCreator, creator, document, staticNode, callMeta, inputKey); + } protected void appendToStaticNode( @@ -629,75 +765,55 @@ Document document, Node staticNode, CallMeta callMeta, - Object o + String inputKey ) { - if (o instanceof Collection) { - String name = null; - boolean multiselect = false; - if (o instanceof NamedCollection) { - NamedCollection nc = ((NamedCollection) o); - name = nc.getName(); - multiselect = nc.isMultiSelect(); - } else { - Object[] names = this.inputValueNames.toArray(); - name = names[names.length - 1].toString(); - } - - Element selectNode = creator.create(multiselect?"select":"select1"); - creator.addAttr(selectNode, "ref", name); - - Element lableNode = creator.create("label"); - lableNode.setTextContent(RessourceFactory.getInstance() - .getRessource(callMeta.getLanguages(), name, name)); - Element choiceNode = creator.create("choices"); - - Collection values = (Collection) o; - Iterator resultIt = values.iterator(); - while (resultIt.hasNext()) { - KeyValueDescibeData result = resultIt.next(); - - if (result.isSelected()) { - artCreator.addAttr( - selectNode, "state", result.getState(), true - ); - - Element itemNode = creator.create("item"); + InputValue meta = inputValues.get(inputKey); + InputData data = inputData.get(inputKey); - creator.addAttr(itemNode, "selected", "true"); - - Element choiceLableNode = creator.create("label"); - choiceLableNode.setTextContent(result.getValue()); - itemNode.appendChild(choiceLableNode); - - Element choiceValueNode = creator.create("value"); - choiceValueNode.setTextContent("" + result.getKey()); - itemNode.appendChild(choiceValueNode); - choiceNode.appendChild(itemNode); - } - } - selectNode.appendChild(lableNode); - selectNode.appendChild(choiceNode); - - staticNode.appendChild(selectNode); + if (meta == null || data == null) { + return; } - else if (o instanceof MinMaxDescribeData) { - appendMinMaxDescribeData( - artCreator, - creator, - document, - staticNode, - callMeta, - o); + + boolean multiselect = meta.isMultiselect(); + + Element selectNode = creator.create(multiselect?"select":"select1"); + creator.addAttr(selectNode, "ref", inputKey); + + Element lableNode = creator.create("label"); + lableNode.setTextContent(RessourceFactory.getInstance() + .getRessource(callMeta.getLanguages(), inputKey, inputKey)); + Element choiceNode = creator.create("choices"); + + /* TODO InputData can have more than 1 value if multiselect, implement a + * loop over these values + + while (resultIt.hasNext()) { + KeyValueDescibeData result = resultIt.next(); + */ + + artCreator.addAttr( + selectNode, "state", getID(), true + ); + + Element itemNode = creator.create("item"); + + creator.addAttr(itemNode, "selected", "true"); + + Element choiceLableNode = creator.create("label"); + choiceLableNode.setTextContent(data.getValue()); + itemNode.appendChild(choiceLableNode); + + Element choiceValueNode = creator.create("value"); + choiceValueNode.setTextContent(inputKey); + itemNode.appendChild(choiceValueNode); + choiceNode.appendChild(itemNode); + /* } - else if (o instanceof SingleValueDescribeData) { - appendSingleValueDescribeData( - artCreator, - creator, - document, - staticNode, - callMeta, - o); - } + */ + selectNode.appendChild(lableNode); + selectNode.appendChild(choiceNode); + + staticNode.appendChild(selectNode); } @@ -892,7 +1008,7 @@ } return null; } - + /** * @see de.intevation.gnv.state.State#getDescibeData() */