Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/AreaArtifact.java @ 3818:dc18457b1cef
merged flys-artifacts/pre2.7-2012-03-16
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:59 +0200 |
parents | 76cedac30d35 |
children | 64dc2997b2dd |
comparison
equal
deleted
inserted
replaced
2456:60ab1054069d | 3818:dc18457b1cef |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.w3c.dom.Document; | |
9 | |
10 import de.intevation.artifacts.Artifact; | |
11 import de.intevation.artifacts.ArtifactFactory; | |
12 import de.intevation.artifacts.CallMeta; | |
13 | |
14 import de.intevation.flys.artifacts.model.AreaFacet; | |
15 | |
16 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
17 import de.intevation.artifacts.common.utils.XMLUtils; | |
18 | |
19 import de.intevation.flys.artifacts.states.AreaCreationState; | |
20 import de.intevation.flys.artifacts.states.StaticState; | |
21 | |
22 import de.intevation.artifactdatabase.state.Facet; | |
23 import de.intevation.artifactdatabase.state.State; | |
24 | |
25 | |
26 /** | |
27 * Artifact describing the area between two WKms. | |
28 */ | |
29 public class AreaArtifact extends StaticFLYSArtifact { | |
30 | |
31 /** Access ids of doc. */ | |
32 public static final String XPATH_IDS = "/art:action/art:ids/@value"; | |
33 | |
34 /** Name of Artifact. */ | |
35 public static final String AREA_ARTIFACT_NAME = "area_artifact"; | |
36 | |
37 /** Dataitem: Facet name. Facets with this name will be created (important | |
38 * to not have the area calculated in e.g. a CrossSection to be shown in | |
39 * LongitudinalSection. */ | |
40 protected static final String FACET_NAME = "area.facet"; | |
41 | |
42 /** Name of state. */ | |
43 public static final String STATIC_STATE_NAME = "state.area_artifact"; | |
44 | |
45 /** data item name to access upper curve. */ | |
46 protected static final String AREA_CURVE_OVER = "area.curve_over"; | |
47 | |
48 /** data item name to access lower curve. */ | |
49 protected static final String AREA_CURVE_UNDER = "area.curve_under"; | |
50 | |
51 /** data item name to access whether or not paint over and under. */ | |
52 protected static final String AREA_BETWEEN = "area.between"; | |
53 | |
54 /** Name of state. */ | |
55 protected static final String AREA_NAME = "area.name"; | |
56 | |
57 /** Own logger. */ | |
58 private static final Logger logger = | |
59 Logger.getLogger(AreaArtifact.class); | |
60 | |
61 | |
62 /** Return given name. */ | |
63 @Override | |
64 public String getName() { | |
65 return AREA_ARTIFACT_NAME; | |
66 } | |
67 | |
68 | |
69 /** Store ids, create an AreaFacet. */ | |
70 @Override | |
71 public void setup( | |
72 String identifier, | |
73 ArtifactFactory factory, | |
74 Object context, | |
75 CallMeta callMeta, | |
76 Document data) | |
77 { | |
78 logger.info("AreaArtifact.setup"); | |
79 | |
80 super.setup(identifier, factory, context, callMeta, data); | |
81 | |
82 // TODO yet unused. | |
83 String ids = XMLUtils.xpathString( | |
84 data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); | |
85 | |
86 // TODO this facet will be remodeled during next feed. | |
87 List<Facet> fs = new ArrayList<Facet>(); | |
88 fs.add(new AreaFacet(0, "", "TODO: I am an AreaFacet")); | |
89 | |
90 AreaCreationState state = (AreaCreationState) getCurrentState(context); | |
91 | |
92 if (!fs.isEmpty()) { | |
93 facets.put(getCurrentStateId(), fs); | |
94 } | |
95 } | |
96 | |
97 // TODO Data is not cached in this way. | |
98 | |
99 /** Do not copy data from daddyfact. */ | |
100 @Override | |
101 protected void initialize( | |
102 Artifact artifact, | |
103 Object context, | |
104 CallMeta callMeta) | |
105 { | |
106 // do nothing | |
107 } | |
108 | |
109 | |
110 /** | |
111 * Get name of facets to create. | |
112 */ | |
113 public String getFacetName() { | |
114 return getDataAsString(FACET_NAME); | |
115 } | |
116 | |
117 | |
118 /** | |
119 * Get dataprovider key for the 'lower' curve (we got that information fed | |
120 * from the client and store it as data). | |
121 */ | |
122 public String getLowerDPKey() { | |
123 return getDataAsString(AREA_CURVE_UNDER); | |
124 } | |
125 | |
126 | |
127 /** | |
128 * True if the whole area between the two curves shall be filled. | |
129 */ | |
130 public boolean getPaintBetween() { | |
131 String val = getDataAsString(AREA_BETWEEN); | |
132 | |
133 return val != null && val.equals("true"); | |
134 } | |
135 | |
136 | |
137 /** | |
138 * Get dataprovider key for the 'upper' curve (we got that information fed | |
139 * from the client and store it as data). | |
140 */ | |
141 public String getUpperDPKey() { | |
142 return getDataAsString(AREA_CURVE_OVER); | |
143 } | |
144 | |
145 | |
146 /** Return data item that is used to configure name of area. */ | |
147 public String getAreaName() { | |
148 return getDataAsString(AREA_NAME); | |
149 } | |
150 | |
151 | |
152 /** | |
153 * Create and return a new AreaCreationState with charting output. | |
154 */ | |
155 @Override | |
156 public State getCurrentState(Object cc) { | |
157 final List<Facet> fs = facets.get(getCurrentStateId()); | |
158 | |
159 AreaCreationState state = new AreaCreationState(); | |
160 | |
161 StaticState.addDefaultChartOutput(state, "cross_section", fs); | |
162 | |
163 return state; | |
164 } | |
165 | |
166 | |
167 /** | |
168 * Get a list containing the one and only State. | |
169 * @param context ignored. | |
170 * @return list with one and only state. | |
171 */ | |
172 @Override | |
173 protected List<State> getStates(Object context) { | |
174 ArrayList<State> states = new ArrayList<State>(); | |
175 states.add(getCurrentState(context)); | |
176 | |
177 return states; | |
178 } | |
179 | |
180 | |
181 /** Trivia. */ | |
182 protected State getState(Object context, String stateID) { | |
183 return getCurrentState(null); | |
184 } | |
185 } | |
186 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |