raimund@2737: package de.intevation.flys.artifacts.services;
raimund@2737:
raimund@2737: import java.util.List;
raimund@2737:
raimund@2737: import org.apache.log4j.Logger;
raimund@2737:
raimund@2737: import org.w3c.dom.Document;
raimund@2737: import org.w3c.dom.Element;
raimund@2737: import org.w3c.dom.Node;
raimund@2737:
raimund@2737: import de.intevation.artifacts.CallMeta;
raimund@2737: import de.intevation.artifacts.GlobalContext;
raimund@2737:
raimund@2737: import de.intevation.artifacts.common.utils.XMLUtils;
raimund@2737:
raimund@2737: import de.intevation.flys.themes.Theme;
raimund@2737: import de.intevation.flys.themes.ThemeGroup;
raimund@2737:
raimund@2737: import de.intevation.flys.themes.ThemeFactory;
raimund@2737: import de.intevation.flys.artifacts.context.FLYSContext;
raimund@2737:
raimund@2737: /**
raimund@2737: * This service provides a list of themes filtered by the theme name.
raimund@2737: *
raimund@2737: * @author Raimund Renkert
raimund@2737: */
raimund@2737: public class ThemeListingService extends FLYSService {
raimund@2737:
raimund@2737: /** The logger used in this service.*/
raimund@2737: private static Logger logger = Logger.getLogger(ThemeListingService.class);
raimund@2737:
raimund@2737: private static final String XPATH_THEME_NAME = "/theme/@name";
raimund@2737:
raimund@2737: protected Document doProcess(
raimund@2737: Document data,
raimund@2737: GlobalContext context,
raimund@2737: CallMeta callMeta
raimund@2737: ) {
raimund@2737: logger.debug("ThemeListingService.process");
raimund@2737: String name = XMLUtils.xpathString(data, XPATH_THEME_NAME, null);
raimund@2737:
raimund@2737: if (name == null) {
raimund@2737: logger.warn("No theme name provided.");
raimund@2737: }
raimund@2737: Document result = XMLUtils.newDocument();
raimund@2737:
raimund@2737: XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
raimund@2737: result,
raimund@2737: null,
raimund@2737: null);
raimund@2737:
raimund@2737: List tgs =
raimund@2737: ThemeFactory.getThemeGroups((FLYSContext) context);
raimund@2737:
raimund@2737: Element te = ec.create("themes");
raimund@2737:
raimund@2737: for (ThemeGroup tg: tgs) {
raimund@2737: Element elem = ec.create("themegroup");
raimund@2737: if (tg.getName().equals("virtual")) {
raimund@2737: continue;
raimund@2737: }
raimund@2737: ec.addAttr(elem, "name", tg.getName());
raimund@2737: Theme theme = tg.getThemeByName(name);
raimund@2737: Document d = theme.toXML();
raimund@2737: Node imported = result.importNode(d.getDocumentElement(), true);
raimund@2737: elem.appendChild(imported);
raimund@2737: te.appendChild(elem);
raimund@2737: }
raimund@2737:
raimund@2737: result.appendChild(te);
raimund@2737: return result;
raimund@2737: }
raimund@2737: }
raimund@2737: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :