Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/fis/SelectProductArtifact.java @ 478:0e0c64c821dc
Added support to step back to the point for choosing a product.
gnv-artifacts/trunk@547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 15 Jan 2010 18:21:49 +0000 |
parents | c0504976e606 |
children | d47b478e662b |
comparison
equal
deleted
inserted
replaced
477:40a058047854 | 478:0e0c64c821dc |
---|---|
4 import java.io.OutputStream; | 4 import java.io.OutputStream; |
5 import java.util.ArrayList; | 5 import java.util.ArrayList; |
6 import java.util.Collection; | 6 import java.util.Collection; |
7 import java.util.HashMap; | 7 import java.util.HashMap; |
8 import java.util.Iterator; | 8 import java.util.Iterator; |
9 import java.util.Map; | |
9 import javax.xml.xpath.XPathConstants; | 10 import javax.xml.xpath.XPathConstants; |
10 | 11 |
11 import org.apache.log4j.Logger; | 12 import org.apache.log4j.Logger; |
12 import org.w3c.dom.Document; | 13 import org.w3c.dom.Document; |
13 import org.w3c.dom.Element; | 14 import org.w3c.dom.Element; |
21 import de.intevation.artifacts.ArtifactFactory; | 22 import de.intevation.artifacts.ArtifactFactory; |
22 import de.intevation.artifacts.ArtifactNamespaceContext; | 23 import de.intevation.artifacts.ArtifactNamespaceContext; |
23 import de.intevation.artifacts.CallContext; | 24 import de.intevation.artifacts.CallContext; |
24 import de.intevation.artifacts.CallMeta; | 25 import de.intevation.artifacts.CallMeta; |
25 import de.intevation.gnv.artifacts.GNVArtifactBase; | 26 import de.intevation.gnv.artifacts.GNVArtifactBase; |
27 import de.intevation.gnv.artifacts.GNVProductArtifactFactory; | |
26 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | 28 import de.intevation.gnv.artifacts.context.GNVArtifactContext; |
27 import de.intevation.gnv.artifacts.fis.product.DefaultProduct; | 29 import de.intevation.gnv.artifacts.fis.product.DefaultProduct; |
28 import de.intevation.gnv.artifacts.fis.product.Product; | 30 import de.intevation.gnv.artifacts.fis.product.Product; |
29 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | 31 import de.intevation.gnv.artifacts.ressource.RessourceFactory; |
30 import de.intevation.gnv.state.DefaultInputData; | |
31 import de.intevation.gnv.state.InputData; | 32 import de.intevation.gnv.state.InputData; |
32 import de.intevation.gnv.utils.ArtifactFactoryUtilities; | 33 import de.intevation.gnv.utils.ArtifactFactoryUtilities; |
33 | 34 |
34 | 35 |
35 /** | 36 /** |
36 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> | 37 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de> |
37 */ | 38 */ |
38 public class SelectProductArtifact extends DefaultArtifact { | 39 public class SelectProductArtifact extends DefaultArtifact { |
39 | 40 |
40 public static final String XPATH_IDENTIFIER_REPLACE = "IDENTIFIER"; | |
41 | |
42 public static final String XPATH_ARTIFACT_CONFIGURATION = | |
43 "/artifact-database/artifacts/artifact[@name='" | |
44 + XPATH_IDENTIFIER_REPLACE + "']"; | |
45 | |
46 public static final String XPATH_UUID = "art:action/art:uuid/@value"; | 41 public static final String XPATH_UUID = "art:action/art:uuid/@value"; |
47 | 42 |
48 public static final String XPATH_HASH = "art:action/art:hash/@value"; | 43 public static final String XPATH_HASH = "art:action/art:hash/@value"; |
49 | 44 |
50 public static final String XPATH_INPUT_DATA_VALUE = | 45 public static final String XPATH_INPUT_DATA_VALUE = |
51 "art:action/art:data/art:input[@name='product']/@value"; | 46 "art:action/art:data/art:input[@name='product']/@value"; |
52 | 47 |
53 /** | |
54 * this xpath is related to the config.xml document which doesn't have any | |
55 * prefixes yet | |
56 */ | |
57 public static final String XPATH_PRODUCTS = "products/product"; | |
58 | |
59 /** | |
60 * this xpath is related to the config.xml document which doesn't have any | |
61 * prefixes yet | |
62 */ | |
63 public static final String XPATH_PRODUCT_PARAMETER = "parameters/parameter"; | |
64 | |
65 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; | 48 public static final String XFORM_URL = "http://www.w3.org/2002/xforms"; |
66 public static final String XFORM_PREFIX = "xform"; | 49 public static final String XFORM_PREFIX = "xform"; |
67 | 50 |
68 private static Logger log = Logger.getLogger(SelectProductArtifact.class); | 51 private static Logger log = Logger.getLogger(SelectProductArtifact.class); |
69 | 52 |
70 private HashMap products; | 53 private Map products; |
71 private Product current; | 54 private Product current; |
72 private Artifact artifact; | 55 private Artifact artifact; |
73 private String name; | 56 private String name; |
74 | 57 |
75 public SelectProductArtifact() { | 58 public SelectProductArtifact() { |
84 Object context | 67 Object context |
85 ) { | 68 ) { |
86 log.debug("setup()"); | 69 log.debug("setup()"); |
87 super.setup(identifier, factory, context); | 70 super.setup(identifier, factory, context); |
88 this.name = factory.getName(); | 71 this.name = factory.getName(); |
89 | 72 } |
90 if (context instanceof GNVArtifactContext) { | 73 |
91 GNVArtifactContext gnvContext = (GNVArtifactContext) context; | 74 |
92 Document doc = gnvContext.getConfig(); | 75 public void setProducts(Map products) { |
93 Node artifactNode = getConfigurationFragment(doc); | 76 this.products = products; |
94 | |
95 NodeList products = (NodeList) XMLUtils.xpath( | |
96 artifactNode, XPATH_PRODUCTS, XPathConstants.NODESET); | |
97 | |
98 if (products != null) { | |
99 this.products = new HashMap(products.getLength()); | |
100 | |
101 for (int i = 0; i < products.getLength(); i++) { | |
102 Element productNode = (Element)products.item(i); | |
103 String productName = productNode.getAttribute("name"); | |
104 NodeList parameterNodes = (NodeList) XMLUtils.xpath( | |
105 productNode, | |
106 XPATH_PRODUCT_PARAMETER, | |
107 XPathConstants.NODESET | |
108 ); | |
109 | |
110 Collection<InputData> parameter = null; | |
111 if (parameterNodes != null) { | |
112 parameter = new ArrayList(parameterNodes.getLength()); | |
113 | |
114 for (int j = 0; j < parameterNodes.getLength(); j++) { | |
115 Element parameterNode = (Element)parameterNodes.item(j); | |
116 String name = parameterNode.getAttribute("name"); | |
117 String value = parameterNode.getAttribute("value"); | |
118 parameter.add(new DefaultInputData(name, value)); | |
119 } | |
120 } | |
121 Node artifactFactoryNode = (Node) XMLUtils.xpath( | |
122 productNode, "artifact-factory", XPathConstants.NODE | |
123 ); | |
124 | |
125 ArtifactFactory artifactFactory = | |
126 new ArtifactFactoryUtilities().createArtitfactFactor( | |
127 doc, artifactFactoryNode | |
128 ); | |
129 | |
130 this.products.put(productName, new DefaultProduct( | |
131 productName, parameter, artifactFactory) | |
132 ); | |
133 } | |
134 } | |
135 } | |
136 } | 77 } |
137 | 78 |
138 | 79 |
139 @Override | 80 @Override |
140 public Document feed(Document target, CallContext context) { | 81 public Document feed(Document target, CallContext context) { |
222 | 163 |
223 String hash = XMLUtils.xpathString( | 164 String hash = XMLUtils.xpathString( |
224 target, XPATH_HASH, ArtifactNamespaceContext.INSTANCE | 165 target, XPATH_HASH, ArtifactNamespaceContext.INSTANCE |
225 ); | 166 ); |
226 | 167 |
227 artifact = current.getArtifactFactory().createArtifact( | 168 // fetch ArtifactFactory from context and create a new Artifact |
228 uuid, context | 169 ArtifactFactory factory = context.getDatabase() |
229 ); | 170 .getInternalArtifactFactory(this.name); |
171 factory = ((GNVProductArtifactFactory)factory) | |
172 .getArtifactFactoryByName(current.getName()); | |
173 artifact = factory.createArtifact(uuid, context); | |
230 | 174 |
231 Document feedDocument = feedDocument(uuid, hash); | 175 Document feedDocument = feedDocument(uuid, hash); |
232 artifact.feed(feedDocument(uuid, hash), context); | 176 artifact.feed(feedDocument(uuid, hash), context); |
233 | 177 |
234 result = ((GNVArtifactBase) artifact).initialize(context); | 178 result = ((GNVArtifactBase) artifact).initialize(context); |
384 | 328 |
385 node.appendChild(selectNode); | 329 node.appendChild(selectNode); |
386 } | 330 } |
387 | 331 |
388 | 332 |
389 protected Node getConfigurationFragment(Document document) { | |
390 String xpathQuery = XPATH_ARTIFACT_CONFIGURATION.replaceAll( | |
391 XPATH_IDENTIFIER_REPLACE, name | |
392 ); | |
393 | |
394 return (Node) XMLUtils.xpath(document, xpathQuery, XPathConstants.NODE); | |
395 } | |
396 | |
397 | |
398 protected Document feedDocument(String uuid, String hash) { | 333 protected Document feedDocument(String uuid, String hash) { |
399 Document document = XMLUtils.newDocument(); | 334 Document document = XMLUtils.newDocument(); |
400 | 335 |
401 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 336 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
402 document, | 337 document, |