comparison flys-client/src/main/java/de/intevation/flys/client/server/CollectionHelper.java @ 809:e9337488bac3

The Collection now knows its already loaded recommendations - the CollectionView will not load recommendations that have already been loaded before. flys-client/trunk@2397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 22 Jul 2011 12:23:36 +0000
parents 374712890b94
children 0fe456332785
comparison
equal deleted inserted replaced
808:3187b268b311 809:e9337488bac3
12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; 12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
13 13
14 import de.intevation.flys.client.shared.model.AttributedTheme; 14 import de.intevation.flys.client.shared.model.AttributedTheme;
15 import de.intevation.flys.client.shared.model.Collection; 15 import de.intevation.flys.client.shared.model.Collection;
16 import de.intevation.flys.client.shared.model.OutputMode; 16 import de.intevation.flys.client.shared.model.OutputMode;
17 import de.intevation.flys.client.shared.model.Recommendation;
17 import de.intevation.flys.client.shared.model.Theme; 18 import de.intevation.flys.client.shared.model.Theme;
18 import de.intevation.flys.client.shared.model.ThemeList; 19 import de.intevation.flys.client.shared.model.ThemeList;
19 20
20 21
21 /** 22 /**
38 doc.appendChild(attr); 39 doc.appendChild(attr);
39 40
40 Map<String, OutputMode> tmpOuts = collection.getOutputModes(); 41 Map<String, OutputMode> tmpOuts = collection.getOutputModes();
41 42
42 Element outs = createOutputElements(cr, collection, tmpOuts); 43 Element outs = createOutputElements(cr, collection, tmpOuts);
44 Element recs = createRecommendationsElements(cr, collection);
43 45
44 if (outs != null) { 46 if (outs != null) {
45 attr.appendChild(outs); 47 attr.appendChild(outs);
48 }
49
50 if (recs != null) {
51 attr.appendChild(recs);
46 } 52 }
47 53
48 return doc; 54 return doc;
49 } 55 }
50 56
164 cr.addAttr(t, "description", theme.getDescription(), true); 170 cr.addAttr(t, "description", theme.getDescription(), true);
165 } 171 }
166 172
167 return t; 173 return t;
168 } 174 }
175
176
177 /**
178 * Creates a whole block with art:loaded-recommendations nodes.
179 *
180 * @param cr The ElementCreator used to create new elements.
181 * @param c The collection.
182 *
183 * @return an element with loaded recommendations.
184 */
185 protected static Element createRecommendationsElements(
186 ElementCreator cr,
187 Collection c)
188 {
189 System.out.println("CollectionHelper.createRecommendationsElements");
190
191 List<Recommendation> rs = c.getRecommendations();
192
193 if (rs == null || rs.size() == 0) {
194 System.err.println("Collection did not load recommendations: " +
195 c.identifier());
196 return null;
197 }
198
199 Element loaded = cr.create("loaded-recommendations");
200
201 for (Recommendation r: rs) {
202 Element recommendation = createRecommendationElement(cr, c, r);
203
204 if (recommendation != null) {
205 loaded.appendChild(recommendation);
206 }
207 }
208
209 return loaded;
210 }
211
212
213 /**
214 * Create a node art:recommended.
215 *
216 * @param cr The ElementCreator used to create new elements.
217 * @param c The collection.
218 * @param r The Recommendation.
219 *
220 * @return an element that represents an output mode with its themes.
221 */
222 protected static Element createRecommendationElement(
223 ElementCreator cr,
224 Collection c,
225 Recommendation r)
226 {
227 System.out.println("CollectionHelper.createRecommendationElement");
228
229 Element recommendation = cr.create("recommendation");
230 cr.addAttr(recommendation, "factory", r.getFactory(), true);
231 cr.addAttr(recommendation, "db-ids", r.getIDs(), true);
232
233 return recommendation;
234 }
169 } 235 }
170 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 236 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org