Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/StaticD4EArtifact.java @ 5867:59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 28 Apr 2013 15:23:01 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/StaticFLYSArtifact.java@4897a58c8746 |
children | 95b9e40bbad0 |
comparison
equal
deleted
inserted
replaced
5866:9a6741ccf6d4 | 5867:59ff03ff48f1 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts; | |
10 | |
11 import java.util.Collection; | |
12 import java.util.List; | |
13 | |
14 import org.apache.log4j.Logger; | |
15 | |
16 import org.w3c.dom.Document; | |
17 import org.w3c.dom.Element; | |
18 | |
19 import org.dive4elements.artifacts.ArtifactNamespaceContext; | |
20 import org.dive4elements.artifacts.CallContext; | |
21 | |
22 import org.dive4elements.artifactdatabase.data.StateData; | |
23 import org.dive4elements.artifactdatabase.ProtocolUtils; | |
24 import org.dive4elements.artifactdatabase.state.Facet; | |
25 import org.dive4elements.artifactdatabase.state.Output; | |
26 import org.dive4elements.artifactdatabase.state.State; | |
27 | |
28 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
29 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
30 | |
31 /** | |
32 * A basic D4EArtifact. | |
33 */ | |
34 public abstract class StaticD4EArtifact extends D4EArtifact { | |
35 | |
36 /** Private logger. */ | |
37 private static final Logger logger = | |
38 Logger.getLogger(StaticD4EArtifact.class); | |
39 | |
40 /** Path to 'ids' (data) in doc that comes from datacage. */ | |
41 public static final String XPATH_IDS = "/art:action/art:ids/@value"; | |
42 | |
43 /** | |
44 * Create description document which includes outputmodes. | |
45 * @param data ignored. | |
46 */ | |
47 @Override | |
48 public Document describe(Document data, CallContext cc) { | |
49 logger.debug("Describe artifact: " + identifier()); | |
50 | |
51 Document desc = XMLUtils.newDocument(); | |
52 | |
53 ElementCreator creator = new ElementCreator( | |
54 desc, | |
55 ArtifactNamespaceContext.NAMESPACE_URI, | |
56 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
57 | |
58 Element root = ProtocolUtils.createRootNode(creator); | |
59 desc.appendChild(root); | |
60 | |
61 Element name = ProtocolUtils.createArtNode( | |
62 creator, "name", | |
63 new String[] { "value" }, | |
64 new String[] { getName() }); | |
65 | |
66 root.appendChild(name); | |
67 | |
68 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); | |
69 root.appendChild(createOutputModes(cc, desc, creator)); | |
70 | |
71 // Add the data to an anonymous state. | |
72 Collection<StateData> datas = getAllData(); | |
73 if (datas.size() > 0) { | |
74 Element ui = creator.create("ui"); | |
75 Element staticE = creator.create("static"); | |
76 Element state = creator.create("state"); | |
77 ui.appendChild(staticE); | |
78 staticE.appendChild(state); | |
79 root.appendChild(ui); | |
80 | |
81 for (StateData dataItem : datas) { | |
82 Element itemelent = creator.create("data"); | |
83 creator.addAttr(itemelent, "name", dataItem.getName(), true); | |
84 creator.addAttr(itemelent, "type", dataItem.getType(), true); | |
85 state.appendChild(itemelent); | |
86 Element valuement = creator.create("item"); | |
87 creator.addAttr(valuement, "label", dataItem.getDescription(), true); | |
88 creator.addAttr(valuement, "value", dataItem.getValue().toString(), true); | |
89 itemelent.appendChild(valuement); | |
90 } | |
91 } | |
92 | |
93 return desc; | |
94 } | |
95 | |
96 | |
97 /** | |
98 * Return the value of id element in Datacage data document. | |
99 * @param data Document as passed by datacage. | |
100 * @return the id element value of data document. | |
101 */ | |
102 public static String getDatacageIDValue(Document data) { | |
103 return XMLUtils.xpathString(data, XPATH_IDS, | |
104 ArtifactNamespaceContext.INSTANCE); | |
105 } | |
106 | |
107 | |
108 protected Element createOutputModes( | |
109 CallContext cc, | |
110 Document doc, | |
111 ElementCreator creator) | |
112 { | |
113 logger.debug("createOutputModes"); | |
114 | |
115 Element outs = ProtocolUtils.createArtNode( | |
116 creator, "outputmodes", null, null); | |
117 | |
118 State state = getCurrentState(cc); | |
119 | |
120 logger.debug("Current state is " + state.getID()); | |
121 | |
122 List<Output> list = state.getOutputs(); | |
123 | |
124 if (list != null && list.size() > 0) { | |
125 List<Facet> fs = getFacets(state.getID()); | |
126 if (fs != null && fs.size() > 0) { | |
127 List<Output> generated = generateOutputs(list, fs); | |
128 | |
129 logger.debug("Found " + fs.size() + " current facets."); | |
130 if (!generated.isEmpty()) { | |
131 ProtocolUtils.appendOutputModes( | |
132 doc, outs, generated); | |
133 } | |
134 } | |
135 else { | |
136 logger.debug("No facets found for the current state."); | |
137 } | |
138 } | |
139 | |
140 return outs; | |
141 } | |
142 } | |
143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |