Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/StaticFLYSArtifact.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticFLYSArtifact.java@04f144c42da5 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.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 org.dive4elements.artifacts.ArtifactNamespaceContext; | |
12 import org.dive4elements.artifacts.CallContext; | |
13 | |
14 import org.dive4elements.artifactdatabase.data.StateData; | |
15 import org.dive4elements.artifactdatabase.ProtocolUtils; | |
16 import org.dive4elements.artifactdatabase.state.Facet; | |
17 import org.dive4elements.artifactdatabase.state.Output; | |
18 import org.dive4elements.artifactdatabase.state.State; | |
19 | |
20 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
21 import org.dive4elements.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 Element name = ProtocolUtils.createArtNode( | |
54 creator, "name", | |
55 new String[] { "value" }, | |
56 new String[] { getName() }); | |
57 | |
58 root.appendChild(name); | |
59 | |
60 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); | |
61 root.appendChild(createOutputModes(cc, desc, creator)); | |
62 | |
63 // Add the data to an anonymous state. | |
64 Collection<StateData> datas = getAllData(); | |
65 if (datas.size() > 0) { | |
66 Element ui = creator.create("ui"); | |
67 Element staticE = creator.create("static"); | |
68 Element state = creator.create("state"); | |
69 ui.appendChild(staticE); | |
70 staticE.appendChild(state); | |
71 root.appendChild(ui); | |
72 | |
73 for (StateData dataItem : datas) { | |
74 Element itemelent = creator.create("data"); | |
75 creator.addAttr(itemelent, "name", dataItem.getName(), true); | |
76 creator.addAttr(itemelent, "type", dataItem.getType(), true); | |
77 state.appendChild(itemelent); | |
78 Element valuement = creator.create("item"); | |
79 creator.addAttr(valuement, "label", dataItem.getDescription(), true); | |
80 creator.addAttr(valuement, "value", dataItem.getValue().toString(), true); | |
81 itemelent.appendChild(valuement); | |
82 } | |
83 } | |
84 | |
85 return desc; | |
86 } | |
87 | |
88 | |
89 /** | |
90 * Return the value of id element in Datacage data document. | |
91 * @param data Document as passed by datacage. | |
92 * @return the id element value of data document. | |
93 */ | |
94 public static String getDatacageIDValue(Document data) { | |
95 return XMLUtils.xpathString(data, XPATH_IDS, | |
96 ArtifactNamespaceContext.INSTANCE); | |
97 } | |
98 | |
99 | |
100 protected Element createOutputModes( | |
101 CallContext cc, | |
102 Document doc, | |
103 ElementCreator creator) | |
104 { | |
105 logger.debug("createOutputModes"); | |
106 | |
107 Element outs = ProtocolUtils.createArtNode( | |
108 creator, "outputmodes", null, null); | |
109 | |
110 State state = getCurrentState(cc); | |
111 | |
112 logger.debug("Current state is " + state.getID()); | |
113 | |
114 List<Output> list = state.getOutputs(); | |
115 | |
116 if (list != null && list.size() > 0) { | |
117 List<Facet> fs = getFacets(state.getID()); | |
118 if (fs != null && fs.size() > 0) { | |
119 List<Output> generated = generateOutputs(list, fs); | |
120 | |
121 logger.debug("Found " + fs.size() + " current facets."); | |
122 if (!generated.isEmpty()) { | |
123 ProtocolUtils.appendOutputModes( | |
124 doc, outs, generated); | |
125 } | |
126 } | |
127 else { | |
128 logger.debug("No facets found for the current state."); | |
129 } | |
130 } | |
131 | |
132 return outs; | |
133 } | |
134 } | |
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |