Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/CollectionMonitor.java @ 3806:881fcd01e056
merged flys-artifacts/pre2.6-2011-11-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:50 +0200 |
parents | 33ade8153d74 |
children | 9eedda250280 |
comparison
equal
deleted
inserted
replaced
3802:e831dc29e572 | 3806:881fcd01e056 |
---|---|
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.State; | |
24 import de.intevation.artifactdatabase.state.Output; | |
25 | |
26 import de.intevation.flys.artifacts.datacage.Recommendations; | |
27 | |
28 | |
29 public class CollectionMonitor implements Hook { | |
30 | |
31 public static final String XPATH_RESULT = "/art:result"; | |
32 | |
33 | |
34 private static final Logger logger = | |
35 Logger.getLogger(CollectionMonitor.class); | |
36 | |
37 | |
38 @Override | |
39 public void setup(Node cfg) { | |
40 } | |
41 | |
42 | |
43 @Override | |
44 public void execute(Artifact artifact, CallContext context, Document doc) { | |
45 FLYSArtifact flys = (FLYSArtifact) artifact; | |
46 | |
47 Element result = (Element) XMLUtils.xpath( | |
48 doc, | |
49 XPATH_RESULT, | |
50 XPathConstants.NODE, | |
51 ArtifactNamespaceContext.INSTANCE); | |
52 | |
53 ElementCreator creator = new ElementCreator( | |
54 doc, | |
55 ArtifactNamespaceContext.NAMESPACE_URI, | |
56 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
57 | |
58 Element recommended = creator.create("recommended-artifacts"); | |
59 result.appendChild(recommended); | |
60 | |
61 String[] outs = extractOutputNames(flys, context); | |
62 Map<String, Object> params = getNoneUserSpecificParameters(flys, context); | |
63 | |
64 Recommendations rec = Recommendations.getInstance(); | |
65 rec.recommend(flys, null, outs, params, recommended); | |
66 } | |
67 | |
68 | |
69 public static String[] extractOutputNames( | |
70 FLYSArtifact flys, | |
71 CallContext context) | |
72 { | |
73 State state = flys.getCurrentState(context); | |
74 List<Output> outs = state.getOutputs(); | |
75 | |
76 int num = outs == null ? 0 : outs.size(); | |
77 | |
78 String[] names = new String[num]; | |
79 | |
80 for (int i = 0; i < num; i++) { | |
81 names[i] = outs.get(i).getName(); | |
82 } | |
83 | |
84 return names; | |
85 } | |
86 | |
87 | |
88 protected Map<String, Object> getNoneUserSpecificParameters( | |
89 FLYSArtifact flys, | |
90 CallContext context) | |
91 { | |
92 Map<String, Object> params = new HashMap<String, Object>(1); | |
93 params.put("recommended", "true"); | |
94 | |
95 return params; | |
96 } | |
97 } | |
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |