Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/sq/SQOverviewGenerator.java @ 3422:118fe1cc8cc8
OutGenerators got a setCollection() method; analogous to setMasterArtifact(). Registered the SQOverviewGenerator as OutGenerator for 'sq_overview' Output.
flys-artifacts/trunk@5076 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 20 Jul 2012 06:50:25 +0000 |
parents | 02d5731b43a2 |
children | 3fc5c914b1c1 |
comparison
equal
deleted
inserted
replaced
3421:c44ff50f4970 | 3422:118fe1cc8cc8 |
---|---|
26 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 26 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
27 import de.intevation.artifacts.common.utils.XMLUtils; | 27 import de.intevation.artifacts.common.utils.XMLUtils; |
28 import de.intevation.flys.artifacts.context.FLYSContext; | 28 import de.intevation.flys.artifacts.context.FLYSContext; |
29 import de.intevation.flys.collections.AttributeParser; | 29 import de.intevation.flys.collections.AttributeParser; |
30 import de.intevation.flys.collections.CollectionAttribute; | 30 import de.intevation.flys.collections.CollectionAttribute; |
31 import de.intevation.flys.collections.FLYSArtifactCollection; | |
31 import de.intevation.flys.exports.ChartGenerator; | 32 import de.intevation.flys.exports.ChartGenerator; |
32 import de.intevation.flys.exports.OutGenerator; | 33 import de.intevation.flys.exports.OutGenerator; |
33 import de.intevation.flys.exports.OutputHelper; | 34 import de.intevation.flys.exports.OutputHelper; |
34 | 35 |
35 public class SQOverviewGenerator | 36 public class SQOverviewGenerator |
37 { | 38 { |
38 private static Logger logger = Logger.getLogger(SQOverviewGenerator.class); | 39 private static Logger logger = Logger.getLogger(SQOverviewGenerator.class); |
39 | 40 |
40 public static final String XPATH_CHART_SIZE = | 41 public static final String XPATH_CHART_SIZE = |
41 "/art:action/art:attributes/art:size"; | 42 "/art:action/art:attributes/art:size"; |
43 | |
44 protected FLYSArtifactCollection collection; | |
42 | 45 |
43 protected Artifact master; | 46 protected Artifact master; |
44 | 47 |
45 protected Settings settings; | 48 protected Settings settings; |
46 | 49 |
62 Document attr, | 65 Document attr, |
63 boolean visible | 66 boolean visible |
64 ) { | 67 ) { |
65 logger.debug("doOut()"); | 68 logger.debug("doOut()"); |
66 | 69 |
67 logger.debug(XMLUtils.toString(attr)); | |
68 String name = artifactAndFacet.getData(context).toString(); | 70 String name = artifactAndFacet.getData(context).toString(); |
69 if(name != null) { | 71 if(name != null) { |
70 logger.debug("name: " + name); | 72 logger.debug("name: " + name); |
71 ChartGenerator g = | 73 ChartGenerator g = |
72 (ChartGenerator)FLYSContext.getOutGenerator( | 74 (ChartGenerator)FLYSContext.getOutGenerator( |
73 context, | 75 context, |
74 name, | 76 name, |
75 null); | 77 null); |
78 | |
76 if (g == null) { | 79 if (g == null) { |
77 logger.debug("generator is null."); | 80 logger.debug("generator is null."); |
78 return; | 81 return; |
79 } | 82 } |
80 logger.debug(XMLUtils.toString(attr)); | 83 |
81 OutputHelper helper = new OutputHelper(master.identifier()); | 84 OutputHelper helper = new OutputHelper(master.identifier()); |
85 Document collectionAttribute = collection.getAttribute(); | |
86 | |
82 try { | 87 try { |
83 AttributeParser parser = new AttributeParser(request); | 88 Document cAttr = getAttribute(context, collectionAttribute, name); |
84 CollectionAttribute cAttr = parser.getCollectionAttribute(); | |
85 | |
86 g.init(request, out, context); | 89 g.init(request, out, context); |
87 Document chartAttr = getAttribute(context, cAttr, name); | 90 |
88 logger.debug(XMLUtils.toString(chartAttr)); | 91 helper.doOut(g, name, name, cAttr, context); |
89 helper.doOut(g, name, name, request, context); | |
90 charts.add(g.generateChart()); | 92 charts.add(g.generateChart()); |
91 } catch (IOException e) { | 93 } |
94 catch (IOException e) { | |
92 logger.warn(e); | 95 logger.warn(e); |
93 } catch (ArtifactDatabaseException e) { | 96 } |
94 // TODO Auto-generated catch block | 97 catch (ArtifactDatabaseException e) { |
95 logger.warn(e); | 98 logger.warn(e); |
96 } | 99 } |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
104 charts = new ArrayList<JFreeChart>(); | 107 charts = new ArrayList<JFreeChart>(); |
105 } | 108 } |
106 | 109 |
107 public void setMasterArtifact(Artifact master) { | 110 public void setMasterArtifact(Artifact master) { |
108 this.master = master; | 111 this.master = master; |
112 } | |
113 | |
114 public void setCollection(FLYSArtifactCollection collection) { | |
115 this.collection = collection; | |
109 } | 116 } |
110 | 117 |
111 public void generate() throws IOException { | 118 public void generate() throws IOException { |
112 logger.debug("SQOverviewGenerator.generate"); | 119 logger.debug("SQOverviewGenerator.generate"); |
113 | 120 |
149 /** | 156 /** |
150 * Returns the "attribute" (part of description document) for a specific | 157 * Returns the "attribute" (part of description document) for a specific |
151 * output type. | 158 * output type. |
152 * | 159 * |
153 * @param context The CallContext object. | 160 * @param context The CallContext object. |
154 * @param cAttr The CollectionAttribute. | 161 * @param attr The xml attribute saved at the collection. |
155 * @param output The name of the desired output type. | 162 * @param output The name of the desired output type. |
156 * | 163 * |
157 * @return the attribute for the desired output type. | 164 * @return the attribute for the desired output type. |
158 */ | 165 */ |
159 protected Document getAttribute( | 166 protected Document getAttribute( |
160 CallContext context, | 167 CallContext context, |
161 CollectionAttribute cAttr, | 168 Document attr, |
162 String output) | 169 String output) |
163 throws ArtifactDatabaseException | 170 throws ArtifactDatabaseException |
164 { | 171 { |
165 Document attr = cAttr.toXML(); | 172 logger.debug("find specific XML node for Output: " + output); |
166 | 173 |
167 Map<String, String> vars = new HashMap<String, String>(); | 174 Map<String, String> vars = new HashMap<String, String>(); |
168 vars.put("output", output); | 175 vars.put("output", output); |
169 | 176 |
170 Node out = (Node) XMLUtils.xpath( | 177 Node out = (Node) XMLUtils.xpath( |
172 "art:attribute/art:outputs/art:output[@name=$output]", | 179 "art:attribute/art:outputs/art:output[@name=$output]", |
173 XPathConstants.NODE, | 180 XPathConstants.NODE, |
174 ArtifactNamespaceContext.INSTANCE, | 181 ArtifactNamespaceContext.INSTANCE, |
175 vars); | 182 vars); |
176 | 183 |
177 | |
178 if (out != null) { | 184 if (out != null) { |
179 Document o = XMLUtils.newDocument(); | 185 Document o = XMLUtils.newDocument(); |
180 | |
181 o.appendChild(o.importNode(out, true)); | 186 o.appendChild(o.importNode(out, true)); |
182 | 187 |
183 return o; | 188 return o; |
184 } | 189 } |
185 | 190 |