Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/OutputParser.java @ 1190:f514894ec2fd
merged flys-artifacts/2.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:17 +0200 |
parents | 59ae2a823e73 |
children | a70e0cbc5e02 |
comparison
equal
deleted
inserted
replaced
917:b48c36076e17 | 1190:f514894ec2fd |
---|---|
1 package de.intevation.flys.collections; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.List; | |
6 import java.util.Map; | |
7 | |
8 import org.apache.log4j.Logger; | |
9 | |
10 import de.intevation.artifacts.ArtifactDatabase; | |
11 import de.intevation.artifacts.ArtifactDatabaseException; | |
12 import de.intevation.artifacts.CallContext; | |
13 import de.intevation.artifacts.CallMeta; | |
14 | |
15 import de.intevation.artifactdatabase.state.DefaultOutput; | |
16 import de.intevation.artifactdatabase.state.Facet; | |
17 import de.intevation.artifactdatabase.state.Output; | |
18 | |
19 import de.intevation.flys.artifacts.FLYSArtifact; | |
20 import de.intevation.flys.artifacts.model.ManagedFacetAdapter; | |
21 | |
22 | |
23 public class OutputParser { | |
24 | |
25 /** Constant XPath that points to the outputmodes of an artifact.*/ | |
26 public static final String XPATH_ARTIFACT_OUTPUTMODES = | |
27 "/art:result/art:outputmodes/art:output"; | |
28 | |
29 | |
30 private static Logger logger = Logger.getLogger(OutputParser.class); | |
31 | |
32 protected ArtifactDatabase db; | |
33 protected CallMeta meta; | |
34 protected CallContext context; | |
35 | |
36 protected Map<String, Output> outs; | |
37 | |
38 | |
39 public OutputParser(ArtifactDatabase db, CallContext context) { | |
40 this.db = db; | |
41 this.meta = context.getMeta(); | |
42 this.context = context; | |
43 this.outs = new HashMap<String, Output>(); | |
44 } | |
45 | |
46 | |
47 public void parse(String uuid) | |
48 throws ArtifactDatabaseException | |
49 { | |
50 logger.debug("OutputParser.parse: " + uuid); | |
51 | |
52 FLYSArtifact flys = (FLYSArtifact) db.getRawArtifact(uuid); | |
53 | |
54 List<Output> outList = flys.getOutputs(context); | |
55 | |
56 for (Output out: outList) { | |
57 String name = out.getName(); | |
58 | |
59 Output o = outs.get(name); | |
60 int pos = 1; | |
61 | |
62 if (o == null) { | |
63 o = new DefaultOutput( | |
64 out.getName(), | |
65 out.getDescription(), | |
66 out.getMimeType(), | |
67 new ArrayList<Facet>(), | |
68 out.getType()); | |
69 | |
70 outs.put(name, o); | |
71 } | |
72 else { | |
73 pos = o.getFacets().size() + 1; | |
74 } | |
75 | |
76 List<Facet> facets = facet2ManagedFacet(uuid, out.getFacets(), pos); | |
77 o.addFacets(facets); | |
78 } | |
79 } | |
80 | |
81 | |
82 public Map<String, Output> getOuts() { | |
83 return outs; | |
84 } | |
85 | |
86 | |
87 protected List<Facet> facet2ManagedFacet( | |
88 String uuid, | |
89 List<Facet> old, | |
90 int pos) | |
91 { | |
92 List<Facet> newFacets = new ArrayList<Facet>(old.size()); | |
93 | |
94 for (Facet f: old) { | |
95 newFacets.add(new ManagedFacetAdapter(f, uuid, pos++, 1)); | |
96 } | |
97 | |
98 return newFacets; | |
99 } | |
100 } | |
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |