8951
|
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.sinfo.common; |
|
10 |
|
11 import java.util.List; |
|
12 |
|
13 import org.apache.log4j.Logger; |
|
14 import org.dive4elements.artifactdatabase.ProtocolUtils; |
|
15 import org.dive4elements.artifactdatabase.state.Facet; |
|
16 import org.dive4elements.artifacts.Artifact; |
|
17 import org.dive4elements.artifacts.CallContext; |
|
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
|
19 import org.dive4elements.river.artifacts.D4EArtifact; |
|
20 import org.dive4elements.river.artifacts.model.FacetTypes; |
|
21 import org.dive4elements.river.artifacts.resources.Resources; |
|
22 import org.dive4elements.river.artifacts.states.DefaultState; |
|
23 import org.dive4elements.river.artifacts.states.WaterlevelPairSelectState; |
|
24 import org.w3c.dom.Element; |
|
25 |
|
26 /** |
|
27 * Copy of {@link WaterlevelPairSelectState}. We must copy instead of crate an abstraction, else we break the |
|
28 * serialization of {@link WaterlevelPairSelectState}. |
|
29 * State in which the user selects 1 to n pairs of Waterlevels and alikes. |
|
30 */ |
|
31 public abstract class DatacagePairSelectState extends DefaultState implements FacetTypes { |
|
32 |
|
33 private static final long serialVersionUID = 1L; |
|
34 |
|
35 /** The log that is used in this state. */ |
|
36 private static Logger log = Logger.getLogger(DatacagePairSelectState.class); |
|
37 |
|
38 private final String dataId; |
|
39 |
|
40 private final String uiProvider; |
|
41 |
|
42 /** |
|
43 * Name of the state data this state is responsible for. |
|
44 */ |
|
45 public DatacagePairSelectState(final String uiProvider, final String dataId) { |
|
46 this.uiProvider = uiProvider; |
|
47 this.dataId = dataId; |
|
48 } |
|
49 |
|
50 /** Specify to display a datacage_twin_panel. */ |
|
51 @Override |
|
52 protected final String getUIProvider() { |
|
53 return this.uiProvider; |
|
54 } |
|
55 |
|
56 /** |
|
57 * Overridden to do nothing. |
|
58 */ |
|
59 @Override |
|
60 public final Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
|
61 // Get data and do stuff, do not calculate |
|
62 return ""; |
|
63 } |
|
64 |
|
65 /** |
|
66 * Create elements for document (prepopulated with data, if any). |
|
67 * |
|
68 * @param artifact |
|
69 * D4EArtifact to get data from. |
|
70 * @param name |
|
71 * DataName, expceted to be dataId given in constructor. |
|
72 */ |
|
73 @Override |
|
74 protected final Element[] createItems(final ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
|
75 log.debug("createItems: " + name); |
|
76 |
|
77 if (name.equals(this.dataId)) { |
|
78 final Element item = ProtocolUtils.createArtNode(cr, "item", null, null); |
|
79 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null); |
|
80 final Element value = ProtocolUtils.createArtNode(cr, "value", null, null); |
|
81 |
|
82 final D4EArtifact flys = (D4EArtifact) artifact; |
|
83 |
|
84 final String s = flys.getDataAsString(name); |
|
85 value.setTextContent(s); |
|
86 item.appendChild(label); |
|
87 item.appendChild(value); |
|
88 return new Element[] { item }; |
|
89 } |
|
90 |
|
91 return new Element[] {}; |
|
92 } |
|
93 |
|
94 /** |
|
95 * Creats the data element used for the static part of DESCRIBE document. |
|
96 */ |
|
97 @Override |
|
98 protected final Element createStaticData(final D4EArtifact flys, final ElementCreator creator, final CallContext cc, final String name, final String value, |
|
99 final String type) { |
|
100 final Element dataElement = creator.create("data"); |
|
101 creator.addAttr(dataElement, "name", name, true); |
|
102 creator.addAttr(dataElement, "type", type, true); |
|
103 |
|
104 final Element itemElement = creator.create("item"); |
|
105 creator.addAttr(itemElement, "value", value, true); |
|
106 |
|
107 final String[] labels = WaterlevelPairSelectState.getLabels(cc, value); |
|
108 final Object[] obj = new Object[] { labels[0] }; |
|
109 |
|
110 // TODO own i18n |
|
111 final String attrValue = Resources.getMsg(cc.getMeta(), "wsp.selected.string", "wsp.selected.string", obj); |
|
112 |
|
113 creator.addAttr(itemElement, "label", attrValue, true); |
|
114 dataElement.appendChild(itemElement); |
|
115 |
|
116 return dataElement; |
|
117 } |
|
118 } |