# HG changeset patch # User Ingo Weinzierl # Date 1299764429 0 # Node ID bf84bcd4e11bb5d865049d852bd27a8fd8035449 # Parent e29658e2623a29aa759cd6f38027e7f46dba8d82 Parse static data from DESCRIBE. flys-client/trunk@1454 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e29658e2623a -r bf84bcd4e11b flys-client/ChangeLog --- a/flys-client/ChangeLog Thu Mar 10 13:38:46 2011 +0000 +++ b/flys-client/ChangeLog Thu Mar 10 13:40:29 2011 +0000 @@ -1,3 +1,9 @@ +2011-03-10 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java: + Parse the static data from DESCRIBE document and put it into the + ArtifactDescription. + 2011-03-10 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/event/HasParameterChangeHandler.java, diff -r e29658e2623a -r bf84bcd4e11b flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java --- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java Thu Mar 10 13:38:46 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java Thu Mar 10 13:40:29 2011 +0000 @@ -37,6 +37,10 @@ public static final String XPATH_REACHABLE_STATE = "art:state"; + public static final String XPATH_STATIC_DATA_NODE = "art:data"; + + public static final String XPATH_STATIC_ITEM_NODE = "art:item"; + /** * This method creates the {@link ArtifactDescription} of the DESCRIBE * document doc. @@ -60,11 +64,11 @@ ArtifactNamespaceContext.INSTANCE); System.out.println("Current state name: " + state); - Data currentData = extractCurrentData(dynamicNode); - String[] states = extractReachableStates(reachable); + Data currentData = extractCurrentData(dynamicNode); + Data[] old = extractOldData(staticNode); + String[] states = extractReachableStates(reachable); - // TODO parse the static ui part - return new DefaultArtifactDescription(null, currentData, state, states); + return new DefaultArtifactDescription(old, currentData, state, states); } @@ -125,6 +129,87 @@ /** + * This method extracts the data objects from the data node of the static ui + * part of the DESCRIBE document. + * + * @param staticNode The static ui node of the DESCRIBE. + * + * @return the Data objects. + */ + protected static Data[] extractOldData(Node staticNode) { + System.out.println("ArtifactDescriptionFactory - extractOldData()"); + + NodeList dataNodes = (NodeList) XMLUtils.xpath( + staticNode, + XPATH_STATIC_DATA_NODE, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (dataNodes == null || dataNodes.getLength() == 0) { + System.out.println("No old items found."); + return null; + } + + int count = dataNodes.getLength(); + + Data[] data = new Data[count]; + + for (int i = 0; i < count; i++) { + Node tmp = dataNodes.item(i); + + String name = XMLUtils.xpathString( + tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); + String type = XMLUtils.xpathString( + tmp, "@art:type", ArtifactNamespaceContext.INSTANCE); + + DataItem[] items = extractOldDataItems(tmp); + + data[i] = new DefaultData(name, name, type, items, null); + } + + return data; + } + + + /** + * This method extracts the data items from the data nodes that are placed + * in the static ui part of the DESCRIBE document. + * + * @param dataNode A data node that contains items. + * + * @return a list of DataItems. + */ + protected static DataItem[] extractOldDataItems(Node dataNode) { + NodeList itemList = (NodeList) XMLUtils.xpath( + dataNode, + XPATH_STATIC_ITEM_NODE, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (itemList == null || itemList.getLength() == 0) { + System.out.println("No old data items found."); + return null; + } + + int count = itemList.getLength(); + + DataItem[] items = new DataItem[count]; + + for (int i = 0; i < count; i++) { + Node tmp = itemList.item(i); + + String value = XMLUtils.xpathString( + tmp, "@art:value", ArtifactNamespaceContext.INSTANCE); + + // TODO extract the human readable value (description) from node + items[i] = new DefaultDataItem(value, value, value); + } + + return items; + } + + + /** * This method extracts the UIProvider specified by the data node. * * @param data The data node.