teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5863: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5863: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.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: teichmann@5831: import org.dive4elements.artifacts.CallMeta; teichmann@5831: import org.dive4elements.artifacts.GlobalContext; raimund@2737: teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils; raimund@2737: teichmann@5831: import org.dive4elements.river.themes.Theme; teichmann@5831: import org.dive4elements.river.themes.ThemeGroup; teichmann@5831: teichmann@5831: import org.dive4elements.river.themes.ThemeFactory; teichmann@5866: import org.dive4elements.river.artifacts.context.RiverContext; 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: */ teichmann@5868: public class ThemeListingService extends D4EService { 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 = teichmann@5866: ThemeFactory.getThemeGroups((RiverContext) 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 :