Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/AbstractState.java @ 226:41404961c804
Added support for facets - facets of output modes are read from configuration now.
artifacts/trunk@1626 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 30 Mar 2011 14:45:15 +0000 |
parents | 1a3fb29b8b2e |
children | 3d14fe6e05f7 |
comparison
equal
deleted
inserted
replaced
224:da92e7f8040b | 226:41404961c804 |
---|---|
12 import java.util.List; | 12 import java.util.List; |
13 import java.util.Map; | 13 import java.util.Map; |
14 | 14 |
15 import javax.xml.xpath.XPathConstants; | 15 import javax.xml.xpath.XPathConstants; |
16 | 16 |
17 import org.apache.log4j.Logger; | |
18 | |
17 import org.w3c.dom.Document; | 19 import org.w3c.dom.Document; |
18 import org.w3c.dom.Element; | 20 import org.w3c.dom.Element; |
19 import org.w3c.dom.Node; | 21 import org.w3c.dom.Node; |
20 import org.w3c.dom.NodeList; | 22 import org.w3c.dom.NodeList; |
21 | 23 |
44 public static final String XPATH_DESCRIPTION = "@description"; | 46 public static final String XPATH_DESCRIPTION = "@description"; |
45 | 47 |
46 /** The XPath to the output nodes of the state configuration.*/ | 48 /** The XPath to the output nodes of the state configuration.*/ |
47 public static final String XPATH_OUTPUT_MODES = "outputmodes/outputmode"; | 49 public static final String XPATH_OUTPUT_MODES = "outputmodes/outputmode"; |
48 | 50 |
51 /** The XPath to the list of facets relative to the output mode it belongs | |
52 * to.*/ | |
53 public static final String XPATH_FACETS = "facets/facet"; | |
54 | |
55 | |
56 /** The logger that is used in this class.*/ | |
57 private static Logger logger = Logger.getLogger(AbstractState.class); | |
58 | |
49 | 59 |
50 /** The ID of the state. */ | 60 /** The ID of the state. */ |
51 protected String id; | 61 protected String id; |
52 | 62 |
53 /** The description of the state. */ | 63 /** The description of the state. */ |
161 * Initialize the state based on the state node in the configuration. | 171 * Initialize the state based on the state node in the configuration. |
162 * | 172 * |
163 * @param config The state configuration node. | 173 * @param config The state configuration node. |
164 */ | 174 */ |
165 public void setup(Node config) { | 175 public void setup(Node config) { |
176 logger.info("AbstractState.setup"); | |
177 | |
166 id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING); | 178 id = (String) XMLUtils.xpath(config, XPATH_ID, XPathConstants.STRING); |
167 | 179 |
168 description = (String) XMLUtils.xpath( | 180 description = (String) XMLUtils.xpath( |
169 config, XPATH_DESCRIPTION, XPathConstants.STRING); | 181 config, XPATH_DESCRIPTION, XPathConstants.STRING); |
170 | 182 |
213 out, "@description", ArtifactNamespaceContext.INSTANCE); | 225 out, "@description", ArtifactNamespaceContext.INSTANCE); |
214 | 226 |
215 String mimetype = XMLUtils.xpathString( | 227 String mimetype = XMLUtils.xpathString( |
216 out, "@mime-type", ArtifactNamespaceContext.INSTANCE); | 228 out, "@mime-type", ArtifactNamespaceContext.INSTANCE); |
217 | 229 |
218 return name != null ? new DefaultOutput(name, desc, mimetype) : null; | 230 if (name == null) { |
231 return null; | |
232 } | |
233 | |
234 NodeList facets = (NodeList) XMLUtils.xpath( | |
235 out, | |
236 XPATH_FACETS, | |
237 XPathConstants.NODESET, | |
238 ArtifactNamespaceContext.INSTANCE); | |
239 | |
240 if (facets == null || facets.getLength() == 0) { | |
241 return new DefaultOutput(name, desc, mimetype); | |
242 } | |
243 | |
244 int num = facets.getLength(); | |
245 | |
246 List<Facet> facetList = new ArrayList<Facet>(num); | |
247 | |
248 for (int i = 0; i < num; i++) { | |
249 Facet facet = buildFacet(facets.item(i)); | |
250 | |
251 if (facet != null) { | |
252 facetList.add(facet); | |
253 } | |
254 } | |
255 | |
256 return new DefaultOutput(name, desc, mimetype, facetList); | |
257 } | |
258 | |
259 | |
260 /** | |
261 * A helper method that creates a Facet object based on the <i>facet</i> | |
262 * node. | |
263 * | |
264 * @param facet The facet node. | |
265 * | |
266 * @return a Facet object or null if no valid Facet was found. | |
267 */ | |
268 protected Facet buildFacet(Node facet) { | |
269 String name = XMLUtils.xpathString( | |
270 facet, "@name", ArtifactNamespaceContext.INSTANCE); | |
271 | |
272 String desc = XMLUtils.xpathString( | |
273 facet, "@description", ArtifactNamespaceContext.INSTANCE); | |
274 | |
275 return name != null ? new DefaultFacet(name, desc) : null; | |
219 } | 276 } |
220 | 277 |
221 | 278 |
222 /** | 279 /** |
223 * Describes the UI of the state. This method needs to be implemented by | 280 * Describes the UI of the state. This method needs to be implemented by |