comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 530:26e38b79658d

Connected the CollectionAttributeService with the artifact server - Collection modifications will now be stored in the artifact databae. flys-client/trunk@2018 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 27 May 2011 08:59:26 +0000
parents
children a0884f486711
comparison
equal deleted inserted replaced
529:a1048d310829 530:26e38b79658d
1 package de.intevation.flys.client.server;
2
3 import java.util.List;
4 import java.util.Map;
5
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Element;
8
9 import de.intevation.artifacts.common.ArtifactNamespaceContext;
10 import de.intevation.artifacts.common.utils.XMLUtils;
11 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
12
13 import de.intevation.flys.client.shared.model.Collection;
14 import de.intevation.flys.client.shared.model.OutputMode;
15 import de.intevation.flys.client.shared.model.Theme;
16 import de.intevation.flys.client.shared.model.ThemeList;
17
18
19 /**
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
21 */
22 public class CollectionHelper {
23
24 public static Document createAttribute(Collection collection) {
25 System.out.println("CollectionHelper.createAttribute");
26
27 Document doc = XMLUtils.newDocument();
28
29 ElementCreator cr = new ElementCreator(
30 doc,
31 ArtifactNamespaceContext.NAMESPACE_URI,
32 ArtifactNamespaceContext.NAMESPACE_PREFIX);
33
34 Element attr = cr.create("attribute");
35
36 doc.appendChild(attr);
37
38 Map<String, OutputMode> tmpOuts = collection.getOutputModes();
39
40 Element outs = createOutputElements(cr, collection, tmpOuts);
41
42 if (outs != null) {
43 attr.appendChild(outs);
44 }
45
46 return doc;
47 }
48
49
50 /**
51 * Creates a whole block with art:output nodes.
52 *
53 * @param cr The ElementCreator used to create new elements.
54 * @param c The collection.
55 * @param modes The OutputModes that should be included.
56 *
57 * @return an element with output modes.
58 */
59 protected static Element createOutputElements(
60 ElementCreator cr,
61 Collection c,
62 Map<String, OutputMode> mmodes)
63 {
64 System.out.println("CollectionHelper.createOutputElements");
65
66 java.util.Collection<OutputMode> modes = mmodes != null
67 ? mmodes.values()
68 : null;
69
70 if (modes == null || modes.size() == 0) {
71 System.err.println("Collection has no modes: " + c.identifier());
72 return null;
73 }
74
75 Element outs = cr.create("outputs");
76
77 for (OutputMode mode: modes) {
78 Element out = createOutputElement(cr, c, mode);
79
80 if (out != null) {
81 outs.appendChild(out);
82 }
83 }
84
85 return outs;
86 }
87
88
89 /**
90 * Create a node art:output that further consist of art:theme nodes.
91 *
92 * @param cr The ElementCreator used to create new elements.
93 * @param c The collection.
94 * @param mode The OutputMode.
95 *
96 * @return an element that represents an output mode with its themes.
97 */
98 protected static Element createOutputElement(
99 ElementCreator cr,
100 Collection collection,
101 OutputMode mode)
102 {
103 System.out.println("CollectionHelper.createOutputElement");
104
105 Element out = cr.create("output");
106 cr.addAttr(out, "name", mode.getName(), false);
107
108 ThemeList themeList = collection.getThemeList(mode.getName());
109 List<Theme> themes = themeList != null ? themeList.getThemes() : null;
110
111 if (themes == null || themes.size() == 0) {
112 System.err.println("No themes for output mode: " + mode.getName());
113 return null;
114 }
115
116 for (Theme theme: themes) {
117 Element t = createThemeElement(cr, collection, theme);
118
119 if (t != null) {
120 out.appendChild(t);
121 }
122 }
123
124 return out;
125 }
126
127
128 /**
129 * Creates a theme node art:theme that represents a curve in a chart or map.
130 *
131 * @param cr The ElementCreator used to create new elements.
132 * @param collection The collection.
133 * @param theme The theme whose attributes should be written to an element.
134 *
135 * @return an element that contains the informtion of the given theme.
136 */
137 protected static Element createThemeElement(
138 ElementCreator cr,
139 Collection collection,
140 Theme theme)
141 {
142 if (theme == null) {
143 return null;
144 }
145
146 Element t = cr.create("theme");
147
148 cr.addAttr(t, "active", theme.isActive() ? "1" : "0", true);
149 cr.addAttr(t, "artifact", theme.getArtifact(), true);
150 cr.addAttr(t, "facet", theme.getFacet(), true);
151 cr.addAttr(t, "pos", Integer.toString(theme.getPosition()), true);
152
153 return t;
154 }
155 }
156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org