Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java @ 2793:6310b1582f2d
merged flys-artifacts/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:30 +0200 |
parents | 0251393f037c |
children | 02254d763bc0 |
comparison
equal
deleted
inserted
replaced
2548:ada02bbd3b7f | 2793:6310b1582f2d |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.Collection; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.w3c.dom.Document; | |
9 import org.w3c.dom.Element; | |
10 | |
11 import de.intevation.artifacts.ArtifactNamespaceContext; | |
12 import de.intevation.artifacts.CallContext; | |
13 | |
14 import de.intevation.artifactdatabase.data.StateData; | |
15 import de.intevation.artifactdatabase.ProtocolUtils; | |
16 import de.intevation.artifactdatabase.state.Facet; | |
17 import de.intevation.artifactdatabase.state.Output; | |
18 import de.intevation.artifactdatabase.state.State; | |
19 | |
20 import de.intevation.artifacts.common.utils.XMLUtils; | |
21 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
22 | |
23 /** | |
24 * A basic FLYSArtifact. | |
25 */ | |
26 public abstract class StaticFLYSArtifact extends FLYSArtifact { | |
27 | |
28 private static final Logger logger = | |
29 Logger.getLogger(StaticFLYSArtifact.class); | |
30 | |
31 /** Path to 'ids' (data) in doc that comes from datacage. */ | |
32 public static final String XPATH_IDS = "/art:action/art:ids/@value"; | |
33 | |
34 /** | |
35 * Create description document which includes outputmodes. | |
36 * @param data ignored. | |
37 */ | |
38 @Override | |
39 public Document describe(Document data, CallContext cc) { | |
40 logger.debug("Describe artifact: " + identifier()); | |
41 | |
42 Document desc = XMLUtils.newDocument(); | |
43 | |
44 ElementCreator creator = new ElementCreator( | |
45 desc, | |
46 ArtifactNamespaceContext.NAMESPACE_URI, | |
47 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
48 | |
49 Element root = ProtocolUtils.createRootNode(creator); | |
50 desc.appendChild(root); | |
51 | |
52 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); | |
53 root.appendChild(createOutputModes(cc, desc, creator)); | |
54 | |
55 // Add the data to an anonymous state. | |
56 Collection<StateData> datas = this.data.values(); | |
57 if (datas.size() > 0) { | |
58 Element ui = creator.create("ui"); | |
59 Element staticE = creator.create("static"); | |
60 Element state = creator.create("state"); | |
61 ui.appendChild(staticE); | |
62 staticE.appendChild(state); | |
63 root.appendChild(ui); | |
64 | |
65 for (StateData dataItem : datas) { | |
66 Element itemelent = creator.create("data"); | |
67 creator.addAttr(itemelent, "name", dataItem.getName(), true); | |
68 creator.addAttr(itemelent, "type", dataItem.getType(), true); | |
69 state.appendChild(itemelent); | |
70 Element valuement = creator.create("item"); | |
71 creator.addAttr(valuement, "label", dataItem.getDescription(), true); | |
72 creator.addAttr(valuement, "value", dataItem.getValue().toString(), true); | |
73 itemelent.appendChild(valuement); | |
74 } | |
75 } | |
76 | |
77 return desc; | |
78 } | |
79 | |
80 | |
81 /** | |
82 * Return the value of id element in Datacage data document. | |
83 * @param data Document as passed by datacage. | |
84 * @return the id element value of data document. | |
85 */ | |
86 public static String getDatacageIDValue(Document data) { | |
87 return XMLUtils.xpathString(data, XPATH_IDS, | |
88 ArtifactNamespaceContext.INSTANCE); | |
89 } | |
90 | |
91 | |
92 protected Element createOutputModes( | |
93 CallContext cc, | |
94 Document doc, | |
95 ElementCreator creator) | |
96 { | |
97 Element outs = ProtocolUtils.createArtNode( | |
98 creator, "outputmodes", null, null); | |
99 | |
100 State state = getCurrentState(cc); | |
101 List<Output> list = state.getOutputs(); | |
102 | |
103 if (list != null && list.size() > 0) { | |
104 List<Facet> fs = facets.get(state.getID()); | |
105 if (fs != null && fs.size() > 0) { | |
106 List<Output> generated = generateOutputs(list, fs); | |
107 | |
108 logger.debug("Found " + fs.size() + " current facets."); | |
109 if (!generated.isEmpty()) { | |
110 ProtocolUtils.appendOutputModes( | |
111 doc, outs, generated); | |
112 } | |
113 } | |
114 else { | |
115 logger.debug("No facets found for the current state."); | |
116 } | |
117 } | |
118 | |
119 return outs; | |
120 } | |
121 } | |
122 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |