annotate flys-artifacts/src/main/java/org/dive4elements/river/artifacts/services/ThemeListingService.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/ThemeListingService.java@2f7fed1eb4bf
children
rev   line source
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
1 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
2
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 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
4
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 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
6
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 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
8 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
9 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
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
11 import org.dive4elements.artifacts.CallMeta;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
12 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
13
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
14 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
15
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
16 import org.dive4elements.river.themes.Theme;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
17 import org.dive4elements.river.themes.ThemeGroup;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
18
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
19 import org.dive4elements.river.themes.ThemeFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 2763
diff changeset
20 import org.dive4elements.river.artifacts.context.FLYSContext;
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
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 /**
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 * 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
24 *
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 * @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
26 */
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 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
28
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 /** 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
30 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
31
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 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
33
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 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
35 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
36 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
37 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
38 ) {
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 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
40 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
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 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
43 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
44 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 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
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 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
48 result,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 null,
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 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
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 List<ThemeGroup> tgs =
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 ThemeFactory.getThemeGroups((FLYSContext) context);
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 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
56
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 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
58 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
59 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
60 continue;
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 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
63 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
64 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
65 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
66 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
67 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
68 }
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 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
71 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
72 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 }
83b22ccf48da Introduced theme groups and added new service to get themes filtered by name.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org