Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java @ 806:2cea76f1112e
Added Javadoc in utils package.
gnv-artifacts/trunk@888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Apr 2010 13:10:39 +0000 |
parents | 6cff63d0c434 |
children | a645bd23c1c8 |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Thu Apr 08 11:31:44 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java Thu Apr 08 13:10:39 2010 +0000 @@ -32,29 +32,56 @@ import org.w3c.dom.NodeList; /** + * This class iterates over a bunch of directories, searches for meta + * information coresponding to shapefiles and creates a mapfile which is used by + * a <i>MapServer</i>. + * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class MapfileGenerator extends Thread { + /** + * The configured template path. + */ public static final String TEMPLATE_PATH = "/artifact-database/gnv/map-generator/templates/path/text()"; + /** + * The configured template mapfile. + */ public static final String TEMPLATE_MAPFILE = "/artifact-database/gnv/map-generator/templates/maptemplate/text()"; + /** + * The configured mapfile path. + */ public static final String MAPFILE_PATH = "/artifact-database/gnv/map-generator/mapfile/@path"; + /** + * The configured shapefile base directory where the subdirectories for each + * artifact are stored. + */ public static final String SHAPEFILE_BASE_DIR = "/artifact-database/gnv/shapefile-directory/@path"; + /** + * The configured velocity logfile. + */ public static final String VELOCITY_LOGFILE = "/artifact-database/velocity/logfile/@path"; + /** + * The name of the file storing meta information coresponding to shapefiles. + */ public static final String META_FILE_NAME = "meta.xml"; + /** + * The XPath to layer nodes in the meta information xml file. + */ public static final String XPATH_LAYER = "/art:meta/art:layer"; + public static final String XPATH_LAYER_NAME = "art:name"; public static final String XPATH_LAYER_TITLE = "art:title"; public static final String XPATH_LAYER_TYPE = "art:type"; @@ -83,11 +110,23 @@ } + /** + * A main method which can be used to create a mapfile without a running + * artifact server.<br> + * <b>NOTE:</b> This method is not implemented yet! + * + * @param args Arguments. + */ public static void main(String[] args) { // TODO IMPLEMENT ME } + /** + * Returns the instance of this generator. + * + * @return the instance. + */ public static synchronized MapfileGenerator getInstance() { if (instance == null) { instance = new MapfileGenerator(); @@ -99,6 +138,9 @@ } + /** + * Triggers the mapfile generation process. + */ public void update() { synchronized (lock) { logger.debug("update"); @@ -108,6 +150,10 @@ } + /** + * Thread to generate a mapfile. + */ + @Override public void run() { logger.debug("Start MapfileGenerator thread..."); try { @@ -131,12 +177,22 @@ } } + /** + * Method to check the existance of a template file. + * + * @param templateID The name of a template. + * @return true, of the template exists - otherwise false. + */ public boolean templateExists(String templateID){ Template template = getTemplateByName(templateID); return template != null; } + /** + * Method which starts searching for meta information file and mapfile + * generation. + */ protected void generate() { File basedir = new File(getShapefileBaseDir()); List layers = new ArrayList(); @@ -145,6 +201,11 @@ } + /** + * Returns the VelocityEngine used for the template mechanism. + * + * @return the velocity engine. + */ protected VelocityEngine getVelocityEngine() { if (velocityEngine == null) { velocityEngine = new VelocityEngine(); @@ -160,6 +221,12 @@ } + /** + * Initialize velocity. + * + * @param engine Velocity engine. + * @throws Exception if an error occured while initializing velocity. + */ protected void setupVelocity(VelocityEngine engine) throws Exception { @@ -183,6 +250,11 @@ } + /** + * Returns the path specifying the logfile for velocity. + * + * @return Velocity logfile path. + */ protected String getVelocityLogfile() { if (velocityLogfile == null) velocityLogfile = Config.getStringXPath(VELOCITY_LOGFILE); @@ -191,6 +263,11 @@ } + /** + * Returns the base directory storing the templates. + * + * @return the template base directory. + */ protected String getTemplateBaseDir() { if (templatePath == null) { templatePath = Config.getStringXPath(TEMPLATE_PATH); @@ -201,6 +278,12 @@ } + /** + * Returns a template specified by <i>model</i>. + * + * @param model The name of the template. + * @return a template. + */ protected Template getTemplateByName(String model) { if (model.indexOf(".vm") < 0) { model = model.concat(".vm"); @@ -223,6 +306,12 @@ } + /** + * Returns the mapfile template. + * + * @return the mapfile template. + * @throws Exception if an error occured while reading the configuration. + */ protected Template getMapfileTemplate() throws Exception { @@ -231,6 +320,11 @@ } + /** + * Returns the base directory storing the shapefiles. + * + * @return the shapefile base directory. + */ protected String getShapefileBaseDir() { if (shapefileDirectory == null) { shapefileDirectory = Config.getStringXPath(SHAPEFILE_BASE_DIR); @@ -241,6 +335,11 @@ } + /** + * Returns the mapfile. + * + * @return the mapfile. + */ protected File getMapfile() { if (mapfile == null) { String tmp = Config.getStringXPath(MAPFILE_PATH); @@ -252,6 +351,13 @@ } + /** + * Search for meta information file in <i>file</i> and store the layer + * information in <i>store</i> if a meta file was found. + * + * @param file The root directory to be searched for meta files. + * @param store A list storing <code>LayerInfo</code> objects. + */ protected void searchMetaInformation(File file, List store) { if (file.isDirectory()) { File[] files = file.listFiles(); @@ -276,6 +382,13 @@ } + /** + * Parses a meta information file and returns necessary information as + * <code>LayerInfo</code> array. + * + * @param file Meta information file. + * @return Array of LayerInfo objects. + */ protected LayerInfo[] parseMeta(File file) { Document meta = XMLUtils.parseDocument(file); List layers = new ArrayList(); @@ -302,6 +415,12 @@ } + /** + * Parses a node storing layer information and returns them. + * + * @param layer Node storing information about a layer. + * @return a LayerInfo object. + */ protected LayerInfo parseLayer(Node layer) { LayerInfo info = new LayerInfo(); @@ -342,6 +461,13 @@ } + /** + * Parses attributes in layer nodes. + * + * @param node A node containing layer information. + * @param xpath XPath specifying an attribute. + * @return Attribute as string. + */ protected String parseLayerAttr(Node node, String xpath) { return (String) XMLUtils.xpath( node, @@ -351,6 +477,11 @@ } + /** + * Creates a mapfile with the layer information stored in <i>layers</i>. + * + * @param layers Layer information. + */ protected void writeMapfile(List layers) { String tmpMapName = "mapfile" + new Date().getTime();