comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java @ 3814:8083f6384023

merged flys-artifacts/pre2.6-2012-01-04
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:56 +0200
parents 94871b7ce9e9
children e8fc770d2f8c
comparison
equal deleted inserted replaced
1491:2a00f4849738 3814:8083f6384023
1 package de.intevation.flys.artifacts;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6
7 import javax.xml.xpath.XPathConstants;
8
9 import org.apache.log4j.Logger;
10
11 import org.w3c.dom.Document;
12 import org.w3c.dom.Element;
13 import org.w3c.dom.Node;
14
15 import de.intevation.artifacts.Artifact;
16 import de.intevation.artifacts.ArtifactNamespaceContext;
17 import de.intevation.artifacts.CallContext;
18 import de.intevation.artifacts.Hook;
19
20 import de.intevation.artifacts.common.utils.XMLUtils;
21 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
22
23 import de.intevation.artifactdatabase.state.Output;
24
25 import de.intevation.flys.artifacts.datacage.Recommendations;
26
27
28 public class CollectionMonitor implements Hook {
29
30 public static final String XPATH_RESULT = "/art:result";
31
32
33 private static final Logger logger =
34 Logger.getLogger(CollectionMonitor.class);
35
36
37 @Override
38 public void setup(Node cfg) {
39 }
40
41
42 @Override
43 public void execute(Artifact artifact, CallContext context, Document doc) {
44 FLYSArtifact flys = (FLYSArtifact) artifact;
45
46 Element result = (Element) XMLUtils.xpath(
47 doc,
48 XPATH_RESULT,
49 XPathConstants.NODE,
50 ArtifactNamespaceContext.INSTANCE);
51
52 ElementCreator creator = new ElementCreator(
53 doc,
54 ArtifactNamespaceContext.NAMESPACE_URI,
55 ArtifactNamespaceContext.NAMESPACE_PREFIX);
56
57 Element recommended = creator.create("recommended-artifacts");
58 result.appendChild(recommended);
59
60 String[] outs = extractOutputNames(flys, context);
61 Map<String, Object> params = getNoneUserSpecificParameters(flys, context);
62
63 Recommendations rec = Recommendations.getInstance();
64 rec.recommend(flys, null, outs, params, recommended);
65 }
66
67
68 /**
69 * Get outputnames from current state (only the ones for which
70 * facets exist).
71 */
72 public static String[] extractOutputNames(
73 FLYSArtifact flys,
74 CallContext context)
75 {
76 List<Output> outs = flys.getCurrentOutputs(context);
77
78 int num = outs == null ? 0 : outs.size();
79
80 String[] names = new String[num];
81
82 for (int i = 0; i < num; i++) {
83 names[i] = outs.get(i).getName();
84 }
85
86 return names;
87 }
88
89
90 protected Map<String, Object> getNoneUserSpecificParameters(
91 FLYSArtifact flys,
92 CallContext context)
93 {
94 Map<String, Object> params = new HashMap<String, Object>(1);
95 params.put("recommended", "true");
96
97 return params;
98 }
99 }
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org