annotate artifacts/src/main/java/org/dive4elements/river/artifacts/services/ThemeListingService.java @ 5866:9a6741ccf6d4

FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 15:14:30 +0200
parents 4897a58c8746
children 35b2d86c3fb5
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
9 package org.dive4elements.river.artifacts.services;
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import java.util.List;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import org.w3c.dom.Document;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import org.w3c.dom.Element;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import org.w3c.dom.Node;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
19 import org.dive4elements.artifacts.CallMeta;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
20 import org.dive4elements.artifacts.GlobalContext;
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
22 import org.dive4elements.artifacts.common.utils.XMLUtils;
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
24 import org.dive4elements.river.themes.Theme;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
25 import org.dive4elements.river.themes.ThemeGroup;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
26
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
27 import org.dive4elements.river.themes.ThemeFactory;
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
28 import org.dive4elements.river.artifacts.context.RiverContext;
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 /**
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 * This service provides a list of themes filtered by the theme name.
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 *
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 */
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 public class ThemeListingService extends FLYSService {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 /** The logger used in this service.*/
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 private static Logger logger = Logger.getLogger(ThemeListingService.class);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 private static final String XPATH_THEME_NAME = "/theme/@name";
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 protected Document doProcess(
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 Document data,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 GlobalContext context,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 CallMeta callMeta
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 ) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 logger.debug("ThemeListingService.process");
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 String name = XMLUtils.xpathString(data, XPATH_THEME_NAME, null);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 if (name == null) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 logger.warn("No theme name provided.");
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 Document result = XMLUtils.newDocument();
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 result,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 null,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 null);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 List<ThemeGroup> tgs =
5866
9a6741ccf6d4 FLYS artifacts: Renamed FLYSContext(Factory) to RiverContext(Factory).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
61 ThemeFactory.getThemeGroups((RiverContext) context);
2737
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 Element te = ec.create("themes");
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 for (ThemeGroup tg: tgs) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 Element elem = ec.create("themegroup");
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 if (tg.getName().equals("virtual")) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 continue;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 ec.addAttr(elem, "name", tg.getName());
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 Theme theme = tg.getThemeByName(name);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 Document d = theme.toXML();
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 Node imported = result.importNode(d.getDocumentElement(), true);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 elem.appendChild(imported);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 te.appendChild(elem);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 result.appendChild(te);
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 return result;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org