Changeset 394

Show
Ignore:
Timestamp:
09/08/08 21:59:46 (4 months ago)
Author:
arneke
Message:

Fix searchpaths so that it will hopefully work on Windows as well

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java

    r388 r394  
    1818 
    1919import java.io.File; 
    20 import java.io.FilenameFilter; 
    2120import java.io.IOException; 
    2221import java.util.ArrayList; 
     
    5655 
    5756public 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); 
    6058 
    6159    private static final String CONFIGURATION_FILE_NAME = "geowebcache.xml"; 
    6260     
     61    private static final String[] CONFIGURATION_REL_PATHS =  
     62        { "/WEB-INF/classes", "/../resources" }; 
     63     
    6364    private WebApplicationContext context; 
    6465 
     
    6970    private String relPath = null; 
    7071 
    71     private File configDirH = null; 
     72    private File configH = null; 
    7273 
    7374    /** 
     
    8586     
    8687    private File findConfFile() throws GeoWebCacheException { 
    87         if (configDirH == null) { 
     88        if (configH == null) { 
    8889            determineConfigDirH(); 
    8990        } 
    9091 
    9192        File xmlFile = null; 
    92         if (configDirH != null) { 
     93        if (configH != null) { 
    9394            // Find the property file 
    94             xmlFile = new File(configDirH.getAbsolutePath() + File.separator + CONFIGURATION_FILE_NAME); 
     95            xmlFile = new File(configH.getAbsolutePath() + File.separator + CONFIGURATION_FILE_NAME); 
    9596        } else { 
    9697            throw new GeoWebCacheException("Unable to determine configuration directory."); 
     
    9899 
    99100        if (xmlFile != null) { 
    100             log.trace("Found configuration file in " 
    101                     + configDirH.getAbsolutePath()); 
     101            log.trace("Found configuration file in "+ configH.getAbsolutePath()); 
    102102        } else { 
    103             throw new GeoWebCacheException("Found no configuration file in "+ configDirH.getAbsolutePath()); 
     103            throw new GeoWebCacheException("Found no configuration file in "+ configH.getAbsolutePath()); 
    104104        } 
    105105         
     
    225225     */ 
    226226    public boolean deleteLayer(String layerName) { 
    227         if (configDirH == null) { 
     227        if (configH == null) { 
    228228            determineConfigDirH(); 
    229229        } 
    230230 
    231231        File xmlFile = null; 
    232         if (configDirH != null) { 
     232        if (configH != null) { 
    233233            // Find the property file and process each one into a TileLayer 
    234             xmlFile = new File(configDirH.getAbsolutePath() + File.separator + "geowebcache.xml"); 
     234            xmlFile = new File(configH.getAbsolutePath() + File.separator + "geowebcache.xml"); 
    235235        } 
    236236 
    237237        if (xmlFile != null) { 
    238             log.trace("Found configuration file in "+ configDirH.getAbsolutePath()); 
     238            log.trace("Found configuration file in "+ configH.getAbsolutePath()); 
    239239        } else { 
    240             log.error("Found no configuration file in "+ configDirH.getAbsolutePath()); 
     240            log.error("Found no configuration file in "+ configH.getAbsolutePath()); 
    241241            return false; 
    242242        } 
     
    245245        Document docc = loadIntoDocument(xmlFile); 
    246246        Element root = docc.getDocumentElement(); 
    247         // find the layer to delete This assumes that ALL layer names are 
    248         // distinct 
     247 
    249248        NodeList nl = docc.getElementsByTagName("layer-name"); 
    250249 
     
    302301        } catch (ParserConfigurationException pce) { 
    303302            log.error(pce.getMessage()); 
    304             //System.err.println(pce.getMessage()); 
    305303            pce.printStackTrace(); 
    306304        } catch (IOException ei) { 
    307305            log.error("Exception occured while creating documet from file " + file.getAbsolutePath()); 
    308             //ei.printStackTrace(System.err); 
    309306        } catch (SAXException saxe) { 
    310307            log.error(saxe.getMessage()); 
    311             //saxe.printStackTrace(); 
    312308        } 
    313309        return document; 
     
    318314         
    319315        if (absPath != null) { 
    320             configDirH = new File(absPath); 
     316            configH = new File(absPath); 
    321317            return; 
    322318        } 
    323319 
    324          
    325320        /* Only keep going for relative directory */ 
    326321        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); 
    330322             
    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                } 
    335336            } 
    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!"); 
    352346        } 
    353347    } 
    354348 
    355349    public String getIdentifier() { 
    356         return configDirH.getAbsolutePath(); 
     350        return configH.getAbsolutePath(); 
    357351    } 
    358352