Changeset 394
- Timestamp:
- 09/08/08 21:59:46 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java
r388 r394 18 18 19 19 import java.io.File; 20 import java.io.FilenameFilter;21 20 import java.io.IOException; 22 21 import java.util.ArrayList; … … 56 55 57 56 public class XMLConfiguration implements Configuration, ApplicationContextAware { 58 private static Log log = LogFactory 59 .getLog(org.geowebcache.util.XMLConfiguration.class); 57 private static Log log = LogFactory.getLog(org.geowebcache.util.XMLConfiguration.class); 60 58 61 59 private static final String CONFIGURATION_FILE_NAME = "geowebcache.xml"; 62 60 61 private static final String[] CONFIGURATION_REL_PATHS = 62 { "/WEB-INF/classes", "/../resources" }; 63 63 64 private WebApplicationContext context; 64 65 … … 69 70 private String relPath = null; 70 71 71 private File config DirH = null;72 private File configH = null; 72 73 73 74 /** … … 85 86 86 87 private File findConfFile() throws GeoWebCacheException { 87 if (config DirH == null) {88 if (configH == null) { 88 89 determineConfigDirH(); 89 90 } 90 91 91 92 File xmlFile = null; 92 if (config DirH != null) {93 if (configH != null) { 93 94 // Find the property file 94 xmlFile = new File(config DirH.getAbsolutePath() + File.separator + CONFIGURATION_FILE_NAME);95 xmlFile = new File(configH.getAbsolutePath() + File.separator + CONFIGURATION_FILE_NAME); 95 96 } else { 96 97 throw new GeoWebCacheException("Unable to determine configuration directory."); … … 98 99 99 100 if (xmlFile != null) { 100 log.trace("Found configuration file in " 101 + configDirH.getAbsolutePath()); 101 log.trace("Found configuration file in "+ configH.getAbsolutePath()); 102 102 } else { 103 throw new GeoWebCacheException("Found no configuration file in "+ config DirH.getAbsolutePath());103 throw new GeoWebCacheException("Found no configuration file in "+ configH.getAbsolutePath()); 104 104 } 105 105 … … 225 225 */ 226 226 public boolean deleteLayer(String layerName) { 227 if (config DirH == null) {227 if (configH == null) { 228 228 determineConfigDirH(); 229 229 } 230 230 231 231 File xmlFile = null; 232 if (config DirH != null) {232 if (configH != null) { 233 233 // Find the property file and process each one into a TileLayer 234 xmlFile = new File(config DirH.getAbsolutePath() + File.separator + "geowebcache.xml");234 xmlFile = new File(configH.getAbsolutePath() + File.separator + "geowebcache.xml"); 235 235 } 236 236 237 237 if (xmlFile != null) { 238 log.trace("Found configuration file in "+ config DirH.getAbsolutePath());238 log.trace("Found configuration file in "+ configH.getAbsolutePath()); 239 239 } else { 240 log.error("Found no configuration file in "+ config DirH.getAbsolutePath());240 log.error("Found no configuration file in "+ configH.getAbsolutePath()); 241 241 return false; 242 242 } … … 245 245 Document docc = loadIntoDocument(xmlFile); 246 246 Element root = docc.getDocumentElement(); 247 // find the layer to delete This assumes that ALL layer names are 248 // distinct 247 249 248 NodeList nl = docc.getElementsByTagName("layer-name"); 250 249 … … 302 301 } catch (ParserConfigurationException pce) { 303 302 log.error(pce.getMessage()); 304 //System.err.println(pce.getMessage());305 303 pce.printStackTrace(); 306 304 } catch (IOException ei) { 307 305 log.error("Exception occured while creating documet from file " + file.getAbsolutePath()); 308 //ei.printStackTrace(System.err);309 306 } catch (SAXException saxe) { 310 307 log.error(saxe.getMessage()); 311 //saxe.printStackTrace();312 308 } 313 309 return document; … … 318 314 319 315 if (absPath != null) { 320 config DirH = new File(absPath);316 configH = new File(absPath); 321 317 return; 322 318 } 323 319 324 325 320 /* Only keep going for relative directory */ 326 321 if (relPath == null) { 327 log.warn("No configuration directory was specified, trying /WEB-INF/classes");328 //String classpath = System.getProperty("java.class.path");329 //System.out.println(classpath);330 322 331 if(new File(baseDir + "/WEB-INF/classes/" + CONFIGURATION_FILE_NAME).exists()) { 332 relPath = "/WEB-INF/classes"; 333 } else if( new File(baseDir + "/../resources/" + CONFIGURATION_FILE_NAME).exists()) { 334 relPath = "/../resources"; 323 for(int i=0; i<CONFIGURATION_REL_PATHS.length; i++) { 324 relPath = CONFIGURATION_REL_PATHS[i]; 325 if(File.separator.equals("\\")) { 326 relPath = relPath.replace("/","\\"); 327 } 328 329 File tmpPath = new File(baseDir + relPath + File.separator + CONFIGURATION_FILE_NAME); 330 331 if(tmpPath.exists()) { 332 log.info("No configuration directory was specified, using "+tmpPath.getAbsolutePath()); 333 configH = new File(baseDir + relPath); 334 return; 335 } 335 336 } 336 } //else { 337 // if (File.separator.equals("\\") 338 // && relPath.equals("/WEB-INF/classes")) { 339 // log.warn("You seem to be running on windows, changing search path to \\WEB-INF\\classes"); 340 // relPath = "\\WEB-INF\\classes"; 341 // } 342 //} 343 344 configDirH = new File(baseDir + relPath); 345 346 log.info("Configuration directory set to: " 347 + configDirH.getAbsolutePath()); 348 349 if (!configDirH.exists() || !configDirH.canRead()) { 350 log.error(configDirH.getAbsoluteFile() 351 + " cannot be read or does not exist!"); 337 338 log.error("Failed to find geowebcache.xml, please specify an absolute path in geowebcache-servlet.xml!"); 339 } 340 configH = new File(baseDir + relPath); 341 342 log.info("Configuration directory set to: "+ configH.getAbsolutePath()); 343 344 if (!configH.exists() || !configH.canRead()) { 345 log.error(configH.getAbsoluteFile()+ " cannot be read or does not exist!"); 352 346 } 353 347 } 354 348 355 349 public String getIdentifier() { 356 return config DirH.getAbsolutePath();350 return configH.getAbsolutePath(); 357 351 } 358 352
