Mercurial > dive4elements > river
changeset 1057:d4a5d3941cc0
Build out/facet filter from XML document passed at creation time.
flys-artifacts/trunk@2527 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 22 Aug 2011 16:37:12 +0000 |
parents | bd1b751deab3 |
children | c37084f31c84 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java |
diffstat | 2 files changed, 62 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Aug 22 16:05:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Aug 22 16:37:12 2011 +0000 @@ -1,3 +1,8 @@ +2011-08-22 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: + Build out/facet filter from XML document passed at creation time. + 2011-08-22 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Aug 22 16:05:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon Aug 22 16:37:12 2011 +0000 @@ -6,6 +6,7 @@ import de.intevation.artifactdatabase.data.DefaultStateData; import de.intevation.artifactdatabase.data.StateData; +import de.intevation.artifactdatabase.state.DefaultFacet; import de.intevation.artifactdatabase.state.DefaultOutput; import de.intevation.artifactdatabase.state.Facet; import de.intevation.artifactdatabase.state.Output; @@ -76,6 +77,9 @@ public static final String XPATH_MODEL_ARTIFACT = "/art:action/art:template/@uuid"; + public static final String XPATH_FILTER = + "/art:action/art:filter/art:out"; + /** The constant string that shows that an operation was successful.*/ public static final String OPERATION_SUCCESSFUL = "SUCCESS"; @@ -182,6 +186,8 @@ logger.error(adbe, adbe); } } + + filterFacets = buildFilterFacets(data); } @@ -193,6 +199,57 @@ // do nothing here } + protected Map<String, List<Facet>> buildFilterFacets(Document document) { + + NodeList nodes = (NodeList)XMLUtils.xpath( + document, + XPATH_FILTER, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + if (nodes == null || nodes.getLength() == 0) { + return null; + } + + Map<String, List<Facet>> result = new HashMap<String, List<Facet>>(); + + for (int i = 0, N = nodes.getLength(); i < N; ++i) { + Element element = (Element)nodes.item(i); + String oName = element.getAttribute("name"); + if (oName.length() == 0) { + continue; + } + + List<Facet> facets = new ArrayList<Facet>(); + + NodeList facetNodes = element.getElementsByTagNameNS( + ArtifactNamespaceContext.NAMESPACE_URI, + "facet"); + + for (int j = 0, M = facetNodes.getLength(); j < M; ++j) { + Element facetElement = (Element)facetNodes.item(j); + + String fName = facetElement.getAttribute("name"); + + int index; + try { + index = Integer.parseInt(facetElement.getAttribute("index")); + } + catch (NumberFormatException nfe) { + logger.warn(nfe); + index = 0; + } + facets.add(new DefaultFacet(index, fName, "")); + } + + if (!facets.isEmpty()) { + result.put(oName, facets); + } + } + + return result; + } + /** * Insert new data included in <code>input</code> into the current state.