ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: tim@52: package de.intevation.gnv.artifacts.context; tim@52: sascha@1117: import de.intevation.artifacts.common.utils.Config; sascha@1117: import de.intevation.artifacts.common.utils.XMLUtils; sascha@779: sascha@779: import de.intevation.artifacts.ArtifactContextFactory; sascha@779: sascha@779: import de.intevation.gnv.artifacts.cache.CacheFactory; sascha@779: sascha@779: import de.intevation.gnv.chart.XMLChartTheme; sascha@779: sascha@779: import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException; sascha@779: ingo@1063: import de.intevation.gnv.geobackend.config.Configuration; ingo@1063: sascha@779: import de.intevation.gnv.raster.Filter; sascha@779: import de.intevation.gnv.raster.Palette; sascha@779: import de.intevation.gnv.raster.PaletteManager; sascha@779: sascha@521: import java.awt.Color; sascha@779: import java.awt.Dimension; sascha@521: import java.awt.Paint; sascha@521: sascha@779: import java.io.File; tim@52: import java.io.FileInputStream; tim@52: import java.io.FileNotFoundException; tim@52: import java.io.IOException; tim@52: import java.io.InputStream; ingo@369: sascha@438: import java.util.ArrayList; sascha@444: import java.util.Collections; sascha@779: import java.util.HashMap; sascha@779: import java.util.Properties; tim@52: tim@52: import org.apache.log4j.Logger; sascha@426: tim@52: import org.w3c.dom.Document; sascha@426: import org.w3c.dom.Element; sascha@426: import org.w3c.dom.NodeList; sascha@426: tim@52: /** ingo@791: * This factory class is used to create new GNVArtfactContext objects, ingo@791: * initialize required components and put them into the created context object ingo@791: * for being available in the application. sascha@803: * sascha@780: * @author Tim Englich sascha@780: * @author Ingo Weinzierl sascha@780: * @author Sascha L. Teichmann tim@52: */ tim@52: public class GNVArtifactContextFactory implements ArtifactContextFactory { tim@52: /** tim@52: * the logger, used to log exceptions and additonaly information tim@52: */ tim@52: private static Logger log = Logger.getLogger(GNVArtifactContext.class); tim@171: ingo@791: /** ingo@791: * ingo@791: */ sascha@778: public static final String XPATH_GEOBACKEND_CONFIGURATION = ingo@1063: "artifact-database/geo-backend"; tim@171: ingo@791: /** ingo@791: * ingo@791: */ sascha@778: public static final String XPATH_GEOBACKEND_QUERYCONFIGURATION = sascha@426: "artifact-database/geo-backend/query-configuration"; tim@171: sascha@778: private final static String CACHECONFIGNODEPATH = sascha@426: "/artifact-database/ehcache/configuration"; tim@171: sascha@778: private final static String CHARTCONFIGNODEPATH = sascha@442: "/artifact-database/gnv/charttemplate/configuration"; sascha@426: ingo@791: /** ingo@791: * ingo@791: */ sascha@426: public final static String PALETTES_PATH = sascha@442: "/artifact-database/gnv/palettes"; sascha@426: ingo@791: /** ingo@791: * ingo@791: */ sascha@426: public final static String PALETTE_ITEMS = sascha@426: "palette"; sascha@426: ingo@791: /** ingo@791: * ingo@791: */ sascha@443: public final static String HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES = sascha@443: "/artifact-database/gnv/horizontal-cross-section-profile/samples/@number"; ingo@358: ingo@791: /** ingo@791: * ingo@791: */ sascha@474: public final static String HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION = sascha@474: "/artifact-database/gnv/horizontal-cross-section/ground/@interpolation"; sascha@474: ingo@791: /** ingo@791: * ingo@791: */ tim@468: public final static String HORIZONTAL_CROSS_SECTION_SAMPLES = tim@468: "/artifact-database/gnv/horizontal-cross-section/samples/@number"; sascha@778: ingo@791: /** ingo@791: * ingo@791: */ sascha@593: public final static String HORIZONTAL_CROSS_SECTION_EXTRAPOLATION_ROUNDS = sascha@593: "/artifact-database/gnv/horizontal-cross-section/extrapolation/@rounds"; sascha@778: ingo@791: /** ingo@791: * ingo@791: */ sascha@472: public final static String HORIZONTAL_CROSS_SECTION_RESULT_SHAPEFILE_PATH = ingo@625: "/artifact-database/gnv/shapefile-directory/@path"; sascha@778: ingo@791: /** ingo@791: * ingo@791: */ sascha@444: public final static String VERTICAL_CROSS_SECTION_SAMPLES = sascha@444: "/artifact-database/gnv/vertical-cross-section/samples"; sascha@444: ingo@791: /** ingo@791: * ingo@791: */ sascha@444: public final static String VERTICAL_CROSS_SECTION_FILTERS = sascha@444: "/artifact-database/gnv/vertical-cross-section/filters/filter"; sascha@444: ingo@791: /** ingo@791: * ingo@791: */ sascha@463: public final static String VERTICAL_CROSS_SECTION_GROUND_INTERPOLATION = sascha@463: "/artifact-database/gnv/vertical-cross-section/ground/@interpolation"; sascha@463: ingo@791: /** ingo@791: * ingo@791: */ sascha@521: public final static String VERTICAL_CROSS_SECTION_GROUND_FILL_COLOR = sascha@521: "/artifact-database/gnv/vertical-cross-section/ground/@fill-color"; sascha@521: ingo@791: /** ingo@791: * ingo@791: */ ingo@646: public final static String XPATH_MAPSERVER_PATH = ingo@646: "/artifact-database/mapserver/server/@path"; ingo@646: ingo@791: /** ingo@791: * ingo@791: */ ingo@646: public final static String XPATH_MAP_PATH = ingo@863: "/artifact-database/gnv/map-generator/mapfile/@path"; ingo@646: tim@52: /** tim@52: * Constructor tim@52: */ tim@52: public GNVArtifactContextFactory() { tim@52: super(); tim@52: log.debug("GNVArtifactContextFactory.Constructor"); tim@52: } tim@52: tim@52: /** ingo@791: * Create a new {@link GNVArtifactContext} object and initialize all ingo@791: * components required by the application. sascha@803: * ingo@791: * @param config ingo@791: * @return GNVArtifactContext tim@52: * @see de.intevation.artifacts.ArtifactContextFactory#createArtifactContext(org.w3c.dom.Document) tim@52: */ tim@52: public Object createArtifactContext(Document config) { ingo@358: GNVArtifactContext returnValue = null; tim@52: try { tim@52: log.debug("GNVArtifactContextFactory.createArtifactContext"); ingo@630: ingo@1063: configureGeoBackend(config); tim@171: ingo@630: configureCache(config); tim@171: tim@52: returnValue = new GNVArtifactContext(config); ingo@358: sascha@426: configurePalettes(config, returnValue); sascha@426: sascha@426: configureChartTemplate(config, returnValue); sascha@426: sascha@443: configureHorizontalCrossSectionProfile(config, returnValue); sascha@426: tim@468: configureHorizontalCrossSection(config,returnValue); tim@468: sascha@444: configureVerticalCrossSection(config, returnValue); sascha@444: ingo@646: configureMapserver(config, returnValue); ingo@646: tim@52: } catch (FileNotFoundException e) { tim@171: log.error(e, e); tim@52: } catch (IOException e) { tim@171: log.error(e, e); tim@171: } catch (QueryContainerException e) { tim@171: log.error(e, e); tim@52: } tim@52: return returnValue; tim@52: } tim@52: ingo@1063: protected void configureGeoBackend(Document config) ingo@1063: throws FileNotFoundException, IOException, QueryContainerException ingo@1063: { ingo@1063: Configuration geoConf = Configuration.getInstance(); ingo@1063: String configDir = Config.getConfigDirectory().getAbsolutePath(); ingo@1063: geoConf.init(config, configDir, Config.CONFIG_DIR_PLACEHOLDER); ingo@1063: } ingo@1063: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@444: protected void configureVerticalCrossSection( sascha@444: Document config, sascha@444: GNVArtifactContext context sascha@444: ) { sascha@444: log.info("configuration of vertical cross section"); sascha@444: configureVerticalCrossSectionSamples(config, context); sascha@444: configureVerticalCrossSectionFilters(config, context); sascha@463: configureVerticalCrossSectionGroundInterpolation(config, context); sascha@521: configureVerticalCrossSectionGroundFillColor(config, context); sascha@521: } sascha@521: ingo@630: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: */ ingo@630: protected void configureCache(Document config) { ingo@630: String cacheConfigurationFile = Config.getStringXPath( ingo@630: config, CACHECONFIGNODEPATH); ingo@630: ingo@630: if (cacheConfigurationFile != null ingo@630: && !cacheConfigurationFile.equals("")) ingo@630: { ingo@630: log.info("Initialisation of the Cache"); ingo@630: cacheConfigurationFile = Config.replaceConfigDir( ingo@630: cacheConfigurationFile); ingo@630: ingo@630: CacheFactory cf = CacheFactory.getInstance(); ingo@630: cf.initializeCache(cacheConfigurationFile); ingo@630: } ingo@630: } ingo@630: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@521: protected void configureVerticalCrossSectionGroundFillColor( sascha@521: Document config, sascha@521: GNVArtifactContext context sascha@521: ) { sascha@521: log.info("configuration of vertical cross section ground fill color"); sascha@521: sascha@521: String fillColor = Config.getStringXPath( sascha@521: config, sascha@521: VERTICAL_CROSS_SECTION_GROUND_FILL_COLOR); sascha@521: sascha@521: Paint fill = sascha@521: GNVArtifactContext.DEFAULT_VERTICAL_CROSS_SECTION_GROUND_FILL; sascha@521: sascha@521: if (fillColor != null sascha@521: && (fillColor = fillColor.trim()).length() != 0) { sascha@521: try { sascha@521: Color color = Color.decode(fillColor); sascha@521: log.info("ground fill color: #" + sascha@521: Integer.toHexString(color.getRGB())); sascha@521: fill = color; sascha@521: } sascha@521: catch (NumberFormatException nfe) { sascha@521: log.error("'" + fillColor + "' is not a valid color"); sascha@521: } sascha@521: } sascha@521: sascha@521: context.put( sascha@521: GNVArtifactContext sascha@521: .VERTICAL_CROSS_SECTION_GROUND_FILL_KEY, sascha@521: fill); sascha@463: } sascha@463: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@463: protected void configureVerticalCrossSectionGroundInterpolation( sascha@463: Document config, sascha@463: GNVArtifactContext context sascha@463: ) { sascha@463: log.info("configuration of vertical cross section ground interpolation"); sascha@463: String interpolation = Config.getStringXPath( sascha@463: config, sascha@463: VERTICAL_CROSS_SECTION_GROUND_INTERPOLATION); sascha@463: sascha@778: if (interpolation == null sascha@463: || (interpolation = interpolation.trim()).length() == 0) { sascha@463: interpolation = GNVArtifactContext sascha@463: .DEFAULT_VERTICAL_CROSS_SECTION_GROUND_INTERPOLATION; sascha@463: } sascha@463: sascha@463: log.info("ground interpolation: " + interpolation); sascha@463: sascha@463: context.put( sascha@463: GNVArtifactContext sascha@463: .VERTICAL_CROSS_SECTION_GROUND_INTERPOLATION_KEY, sascha@463: interpolation); sascha@444: } sascha@444: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@444: protected void configureVerticalCrossSectionFilters( sascha@444: Document config, sascha@444: GNVArtifactContext context sascha@444: ) { sascha@444: log.info("configuration of vertical cross section filters"); sascha@444: sascha@444: NodeList filters = Config.getNodeSetXPath( sascha@444: VERTICAL_CROSS_SECTION_FILTERS); sascha@444: sascha@444: ArrayList filterFactories = sascha@444: new ArrayList(); sascha@444: sascha@444: if (filters == null) { sascha@444: log.warn("no filters found"); sascha@444: } sascha@444: else { sascha@444: for (int i = 0, N = filters.getLength(); i < N; ++i) { sascha@444: Element filterElement = (Element)filters.item(i); sascha@444: String factoryName = filterElement.getAttribute("factory"); sascha@444: if ((factoryName = factoryName.trim()).length() > 0) { sascha@444: try { sascha@444: Class clazz = Class.forName(factoryName); sascha@444: Filter.Factory filterFactory = sascha@444: (Filter.Factory)clazz.newInstance(); sascha@444: filterFactories.add(filterFactory); sascha@444: } sascha@444: catch (ClassNotFoundException cnfe) { sascha@444: log.error("filter class not found", cnfe); sascha@444: } sascha@444: catch (InstantiationException ie) { sascha@444: log.error("cannot instantiate filter factory", ie); sascha@444: } sascha@444: catch (IllegalAccessException iae) { sascha@444: log.error("cannot access filter factory", iae); sascha@444: } sascha@444: catch (ClassCastException cce) { sascha@444: log.error("not a filter factory class", cce); sascha@444: } sascha@444: } sascha@444: else { sascha@444: log.error("No factory name given"); sascha@444: } sascha@444: } sascha@444: } sascha@444: sascha@444: log.info("number of filters: " + filterFactories.size()); sascha@444: sascha@444: context.put( sascha@444: GNVArtifactContext.VERTICAL_CROSS_SECTION_FILTER_FACTORIES_KEY, sascha@444: Collections.unmodifiableList(filterFactories)); sascha@444: } sascha@444: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@444: protected void configureVerticalCrossSectionSamples( sascha@444: Document config, sascha@444: GNVArtifactContext context sascha@444: ) { sascha@444: log.info("configuration of vertical cross section samples"); sascha@444: sascha@444: Element samples = (Element)Config.getNodeXPath( sascha@444: VERTICAL_CROSS_SECTION_SAMPLES); sascha@444: sascha@444: Dimension sampleSize = new Dimension( sascha@444: GNVArtifactContext.DEFAULT_VERTICAL_CROSS_SECTION_SAMPLES); sascha@444: sascha@444: if (samples == null) { sascha@444: log.warn("no samples found"); sascha@444: } sascha@444: else { sascha@444: String widthString = samples.getAttribute("width"); sascha@444: if ((widthString = widthString.trim()).length() > 0) { sascha@444: try { sascha@444: sampleSize.width = Math.max(1, Integer.parseInt(widthString)); sascha@444: } sascha@444: catch (NumberFormatException nfe) { sascha@444: log.error("invalid value for width: '" + widthString + "'"); sascha@444: } sascha@444: } sascha@444: String heightString = samples.getAttribute("height"); sascha@444: if ((heightString = heightString.trim()).length() > 0) { sascha@444: try { sascha@444: sampleSize.height = Math.max(1, Integer.parseInt(heightString)); sascha@444: } sascha@444: catch (NumberFormatException nfe) { sascha@444: log.error("invalid value for height: '" + heightString + "'"); sascha@444: } sascha@444: } sascha@444: } sascha@778: log.info("samples (width x height): " + sascha@444: sampleSize.width + " x " + sampleSize.height); sascha@444: sascha@444: context.put( sascha@444: GNVArtifactContext.VERTICAL_CROSS_SECTION_SAMPLES_KEY, sascha@444: sampleSize); sascha@444: sascha@444: } sascha@444: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@443: protected void configureHorizontalCrossSectionProfile( sascha@443: Document config, sascha@443: GNVArtifactContext context sascha@443: ) sascha@443: { sascha@443: log.info("configuration of horizontal cross section profile"); sascha@443: sascha@443: String numSamples = Config.getStringXPath( sascha@443: config, sascha@443: HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES); sascha@443: sascha@443: Integer samples = sascha@443: GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES; sascha@443: sascha@443: if (numSamples == null) { sascha@443: log.warn("No number of samples found."); sascha@443: } sascha@443: else { sascha@443: try { sascha@443: samples = Integer.valueOf(numSamples); sascha@443: } sascha@443: catch (NumberFormatException nfe) { sascha@443: log.warn("Invalid integer for number of samples"); sascha@443: } sascha@443: } sascha@443: sascha@443: log.info("# horizontal cross section profile samples: " + samples); sascha@443: sascha@443: context.put( sascha@443: GNVArtifactContext.HORIZONTAL_CROSS_SECTION_PROFILE_SAMPLES_KEY, sascha@443: samples); sascha@443: } sascha@778: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ tim@468: protected void configureHorizontalCrossSection( sascha@472: Document config, sascha@472: GNVArtifactContext context sascha@472: ) { sascha@472: log.info("configuration of horizontal cross section"); sascha@472: sascha@472: configureHorizontalCrossSectionSamples(config, context); sascha@593: configureHorizontalCrossSectionExtrapolation(config, context); sascha@472: configureHorizontalCrossSectionResultShapeFilePath(config, context); sascha@474: configureHorizontalCrossSectionGroundInterpolation(config, context); sascha@474: } sascha@474: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@593: protected void configureHorizontalCrossSectionExtrapolation( sascha@593: Document config, sascha@593: GNVArtifactContext context sascha@593: ) sascha@593: { sascha@593: log.info( sascha@593: "configuration of horizontal cross section extrapolation"); sascha@593: sascha@593: String extrapolationRoundsValue = Config.getStringXPath( sascha@593: config, sascha@593: HORIZONTAL_CROSS_SECTION_EXTRAPOLATION_ROUNDS); sascha@593: sascha@593: Integer extrapolationRounds = sascha@593: GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_EXTRAPOLATION_ROUNDS; sascha@593: sascha@593: if (extrapolationRoundsValue != null sascha@593: && (extrapolationRoundsValue = extrapolationRoundsValue.trim()).length() > 0 sascha@593: ) { sascha@593: try { sascha@593: extrapolationRounds = sascha@593: Integer.valueOf(extrapolationRoundsValue); sascha@593: } sascha@593: catch (NumberFormatException nfe) { sascha@593: log.error( sascha@593: "'" + extrapolationRoundsValue + "' is not a valid integer"); sascha@593: } sascha@593: } sascha@593: sascha@593: log.info("extrapolation rounds: " + extrapolationRounds); sascha@593: sascha@593: context.put( sascha@593: GNVArtifactContext sascha@593: .HORIZONTAL_CROSS_SECTION_EXTRAPOLATION_ROUNDS_KEY, sascha@593: extrapolationRounds); sascha@593: } sascha@593: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@474: protected void configureHorizontalCrossSectionGroundInterpolation( sascha@474: Document config, sascha@474: GNVArtifactContext context sascha@474: ) sascha@474: { sascha@474: log.info( sascha@474: "configuration of horizontal cross section ground interpolation"); sascha@474: sascha@474: String interpolation = Config.getStringXPath( sascha@474: config, sascha@474: HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION); sascha@474: sascha@778: if (interpolation == null sascha@474: || (interpolation = interpolation.trim()).length() == 0) { sascha@474: interpolation = GNVArtifactContext sascha@474: .DEFAULT_HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION; sascha@474: } sascha@474: sascha@474: log.info("ground interpolation: " + interpolation); sascha@474: sascha@474: context.put( sascha@474: GNVArtifactContext sascha@474: .HORIZONTAL_CROSS_SECTION_GROUND_INTERPOLATION_KEY, sascha@474: interpolation); sascha@472: } sascha@472: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@472: protected void configureHorizontalCrossSectionResultShapeFilePath( sascha@472: Document config, sascha@472: GNVArtifactContext context sascha@472: ) sascha@472: { sascha@472: log.info( sascha@472: "configuration of horizontal cross section result shape file path"); sascha@472: sascha@778: File dir = sascha@472: GNVArtifactContext. sascha@472: DEFAULT_HORIZONTAL_CROSS_SECTION_PROFILE_SHAPEFILE_PATH; sascha@472: sascha@472: String path = Config.getStringXPath( sascha@472: config, sascha@472: HORIZONTAL_CROSS_SECTION_RESULT_SHAPEFILE_PATH); sascha@472: sascha@472: if (path != null && (path = path.trim()).length() > 0) { sascha@472: dir = new File(Config.replaceConfigDir(path)); sascha@472: } sascha@472: else { sascha@472: log.warn("No 'result-shapefile-directory' given"); sascha@472: } sascha@472: sascha@778: log.info("writing shape files to '" sascha@472: + dir.getAbsolutePath() + "'"); sascha@472: sascha@472: context.put( sascha@472: GNVArtifactContext sascha@472: .HORIZONTAL_CROSS_SECTION_RESULT_SHAPEFILE_PATH_KEY, sascha@472: dir); sascha@472: } sascha@472: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@472: protected void configureHorizontalCrossSectionSamples( sascha@472: Document config, sascha@472: GNVArtifactContext context sascha@472: ) sascha@472: { sascha@472: log.info("configuration of horizontal cross section samples"); sascha@472: String numSamples = Config.getStringXPath( sascha@472: config, sascha@472: HORIZONTAL_CROSS_SECTION_SAMPLES); sascha@472: sascha@472: Integer samples = sascha@472: GNVArtifactContext.DEFAULT_HORIZONTAL_CROSS_SECTION_SAMPLES; sascha@472: sascha@472: if (numSamples == null) { sascha@472: log.warn("No number of samples found."); sascha@472: } sascha@472: else { sascha@472: try { sascha@472: samples = Integer.valueOf(numSamples); sascha@472: } sascha@472: catch (NumberFormatException nfe) { sascha@472: log.warn("Invalid integer for number of samples"); sascha@472: } sascha@472: } sascha@472: sascha@472: log.info("# horizontal cross section profile samples: " + samples); sascha@472: sascha@472: context.put( sascha@472: GNVArtifactContext.HORIZONTAL_CROSS_SECTION_SAMPLES_KEY, sascha@472: samples); sascha@472: } sascha@472: sascha@443: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@426: protected void configureChartTemplate( sascha@426: Document config, sascha@426: GNVArtifactContext context sascha@426: ) { sascha@426: log.info("Initialisation of chart template"); sascha@426: String chartConfigFile = Config.getStringXPath( sascha@426: config, CHARTCONFIGNODEPATH sascha@426: ); sascha@426: sascha@426: XMLChartTheme theme = new XMLChartTheme("XMLChartTheme"); sascha@443: sascha@443: if (chartConfigFile == null) { sascha@443: log.warn("no configuration file for chart template found"); sascha@426: } sascha@426: else { sascha@443: chartConfigFile = Config.replaceConfigDir(chartConfigFile); sascha@443: log.debug("Parse xml configuration of " + chartConfigFile); sascha@443: sascha@443: Document tmpl = XMLUtils.parseDocument(new File(chartConfigFile)); sascha@443: if (tmpl != null) { sascha@443: theme.applyXMLConfiguration(tmpl); sascha@443: } sascha@443: else { sascha@443: log.error( sascha@443: "Cannot load chart template from '" + sascha@443: chartConfigFile + "'"); sascha@443: } sascha@426: } sascha@426: sascha@443: context.put(GNVArtifactContext.CHART_TEMPLATE_KEY, theme); sascha@426: } sascha@426: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ sascha@426: protected void configurePalettes( sascha@426: Document config, sascha@426: GNVArtifactContext context sascha@426: ) { sascha@426: log.info("configure palettes"); sascha@426: sascha@438: HashMap palettes = new HashMap(); sascha@426: sascha@442: Element node = (Element)Config.getNodeXPath(config, PALETTES_PATH); sascha@426: sascha@426: if (node == null) { sascha@426: log.error("No palettes found"); sascha@426: } sascha@426: else { sascha@442: NodeList pals = node.getElementsByTagName(PALETTE_ITEMS); sascha@442: for (int i = 0, N = pals==null?0:pals.getLength(); i < N; ++i) { sascha@426: Element pal = (Element)pals.item(i); sascha@438: String name = pal.getAttribute("name"); sascha@438: String description = pal.getAttribute("description"); sascha@438: String filename = pal.getAttribute("file"); sascha@438: String parameterIds = pal.getAttribute("parameter-ids"); sascha@426: sascha@438: if (name == null || (name = name.trim()).length() == 0) { sascha@426: log.error("Palette has no 'name' attribute."); sascha@426: } sascha@438: else if (filename == null sascha@438: || (filename = filename.trim()).length() == 0) { sascha@438: log.error("Palette '" + name + "' has no 'file' attribute."); sascha@438: } sascha@778: else if (parameterIds == null sascha@438: || (parameterIds = parameterIds.trim()).length() == 0) { sascha@438: log.error("no parameter ids given for '" + name + "'"); sascha@426: } sascha@426: else { sascha@438: ArrayList ids = new ArrayList(); sascha@438: for (String idString: parameterIds.split("[\t ,]+")) { sascha@438: try { sascha@438: ids.add(Integer.valueOf(idString)); sascha@438: } sascha@438: catch (NumberFormatException nfe) { sascha@438: log.error( sascha@438: "parameter id '" + idString + "' is integer"); sascha@438: } sascha@438: } sascha@426: filename = Config.replaceConfigDir(filename); sascha@426: Document document = XMLUtils.parseDocument( sascha@426: new File(filename)); sascha@426: if (document == null) { sascha@426: log.error("Cannot load palette file '" + sascha@426: filename + "'"); sascha@426: } sascha@426: else { sascha@438: PaletteManager manager = new PaletteManager( sascha@438: name, sascha@438: description, sascha@438: new Palette(document)); sascha@438: for (Integer id: ids) { sascha@438: palettes.put(id, manager); sascha@438: } sascha@426: } sascha@426: } sascha@438: } // for all palettes sascha@426: } sascha@426: sascha@443: context.put(GNVArtifactContext.PALETTES_KEY, palettes); sascha@426: } sascha@426: ingo@646: ingo@791: /** ingo@791: * ingo@791: * @param config ingo@791: * @param context ingo@791: */ ingo@646: protected void configureMapserver( ingo@646: Document config, ingo@646: GNVArtifactContext context ingo@646: ) { ingo@646: log.info("read configuration of mapserver."); ingo@646: ingo@646: String serverPath = (String) Config.getStringXPath( ingo@646: config, XPATH_MAPSERVER_PATH); ingo@646: ingo@646: String mapPath = (String) Config.getStringXPath( ingo@646: config, XPATH_MAP_PATH); ingo@863: mapPath = Config.replaceConfigDir(mapPath); ingo@646: ingo@646: if (serverPath != null && mapPath != null) { ingo@646: context.put(GNVArtifactContext.MAPSERVER_SERVER_PATH_KEY,serverPath); ingo@646: context.put(GNVArtifactContext.MAPSERVER_MAP_PATH_KEY, mapPath); ingo@646: } ingo@646: } ingo@646: tim@52: /** ingo@791: * Read some properties from config file specified by filePath. ingo@791: * ingo@791: * @param filePath Path to a cofig file. ingo@791: * @return Properties contained in filePath. ingo@791: * @throws FileNotFoundException if file specified by filePath is not ingo@791: * existing. ingo@791: * @throws IOException if an error occured while reading from file. tim@52: */ tim@52: private Properties getProperties(String filePath) sascha@426: throws FileNotFoundException, IOException sascha@426: { sascha@172: InputStream inputStream = null; sascha@172: try { sascha@172: inputStream = new FileInputStream(filePath); sascha@172: Properties properties = new Properties(); sascha@172: properties.load(inputStream); sascha@172: return properties; sascha@172: } sascha@172: finally { sascha@172: if (inputStream != null) { sascha@172: try { inputStream.close(); } sascha@172: catch (IOException ioe) {} sascha@172: } sascha@172: } tim@52: } tim@52: } sascha@836: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :