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