Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/MapfileGenerator.java @ 624:6a3a1da5e680
Improved velocity configuration.
gnv-artifacts/trunk@696 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Feb 2010 10:43:25 +0000 |
parents | 65f09139e9b3 |
children | 40ead2d2a08d |
comparison
equal
deleted
inserted
replaced
623:65f09139e9b3 | 624:6a3a1da5e680 |
---|---|
50 public static final String MAPFILE_NAME = | 50 public static final String MAPFILE_NAME = |
51 "/artifact-database/map-generator/mapfile/name/text()"; | 51 "/artifact-database/map-generator/mapfile/name/text()"; |
52 | 52 |
53 public static final String SHAPEFILE_BASE_DIR = | 53 public static final String SHAPEFILE_BASE_DIR = |
54 "/artifact-database/map-generator/mapfile/shapefiles/text()"; | 54 "/artifact-database/map-generator/mapfile/shapefiles/text()"; |
55 | |
56 public static final String VELOCITY_LOGFILE = | |
57 "/artifact-database/velocity/logfile/@path"; | |
55 | 58 |
56 public static final String META_FILE_NAME = "meta.xml"; | 59 public static final String META_FILE_NAME = "meta.xml"; |
57 | 60 |
58 public static final String XPATH_LAYER = "/art:meta/art:layer"; | 61 public static final String XPATH_LAYER = "/art:meta/art:layer"; |
59 public static final String XPATH_LAYER_NAME = "art:name"; | 62 public static final String XPATH_LAYER_NAME = "art:name"; |
151 | 154 |
152 | 155 |
153 protected void setupVelocity(VelocityEngine engine) | 156 protected void setupVelocity(VelocityEngine engine) |
154 throws Exception | 157 throws Exception |
155 { | 158 { |
156 Properties ps = new Properties(); | 159 engine.setProperty( |
157 | |
158 ps.setProperty( | |
159 "input.encoding", | 160 "input.encoding", |
160 "UTF-8"); | 161 "UTF-8"); |
161 | 162 |
162 ps.setProperty( | 163 engine.setProperty( |
164 VelocityEngine.RUNTIME_LOG, | |
165 getVelocityLogfile()); | |
166 | |
167 engine.setProperty( | |
163 "resource.loader", | 168 "resource.loader", |
164 "class"); | 169 "file"); |
165 | 170 |
166 ps.setProperty( | 171 engine.setProperty( |
167 "class.resource.loader.class", | 172 "file.resource.loader.path", |
168 "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | 173 getTemplateBaseDir()); |
169 | 174 |
170 engine.init(ps); | 175 engine.init(); |
176 } | |
177 | |
178 | |
179 protected String getVelocityLogfile() { | |
180 if (velocityLogfile == null) | |
181 velocityLogfile = Config.getStringXPath(VELOCITY_LOGFILE); | |
182 | |
183 return velocityLogfile; | |
171 } | 184 } |
172 | 185 |
173 | 186 |
174 protected String getTemplateBaseDir() { | 187 protected String getTemplateBaseDir() { |
175 return Config.getStringXPath(TEMPLATE_PATH); | 188 if (templatePath == null) |
189 templatePath = Config.getStringXPath(TEMPLATE_PATH); | |
190 | |
191 return templatePath; | |
176 } | 192 } |
177 | 193 |
178 | 194 |
179 protected Template getTemplateByName(String model) { | 195 protected Template getTemplateByName(String model) { |
180 String templatePath = getTemplateBaseDir(); | 196 String templatePath = getTemplateBaseDir(); |
181 if (model.indexOf(".vm") < 0) { | 197 if (model.indexOf(".vm") < 0) { |
182 model = model.concat(".vm"); | 198 model = model.concat(".vm"); |
183 } | |
184 | |
185 File file = new File(templatePath, model); | |
186 if (!file.exists() || !file.canRead()) { | |
187 logger.warn("Can't find template file: " + file.getAbsolutePath()); | |
188 return null; | |
189 } | 199 } |
190 | 200 |
191 try { | 201 try { |
192 VelocityEngine engine = getVelocityEngine(); | 202 VelocityEngine engine = getVelocityEngine(); |
193 if (engine == null) { | 203 if (engine == null) { |
194 logger.error("Error while fetching VelocityEngine."); | 204 logger.error("Error while fetching VelocityEngine."); |
195 return null; | 205 return null; |
196 } | 206 } |
197 | 207 |
198 return engine.getTemplate(file.getAbsolutePath()); | 208 return engine.getTemplate(model); |
199 } | 209 } |
200 catch (Exception e) { | 210 catch (Exception e) { |
201 logger.warn(e, e); | 211 logger.warn(e, e); |
202 } | 212 } |
203 | 213 |