Changeset 417

Show
Ignore:
Timestamp:
11/11/08 09:07:39 (2 months ago)
Author:
arneke
Message:

Added ability to grab configuration from geoserver data directory

Location:
trunk/geowebcache/src/main/java/org/geowebcache
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/geowebcache/src/main/java/org/geowebcache/cache/file/FileCache.java

    r348 r417  
    3535import org.geowebcache.cache.CacheException; 
    3636import org.geowebcache.cache.CacheKey; 
    37 import org.geowebcache.layer.wms.WMSLayer; 
    3837import org.geowebcache.tile.Tile; 
    3938import org.geowebcache.util.GWCVars; 
  • trunk/geowebcache/src/main/java/org/geowebcache/util/XMLConfiguration.java

    r416 r417  
    3636import org.apache.commons.logging.LogFactory; 
    3737import org.geowebcache.GeoWebCacheException; 
     38import org.geowebcache.cache.CacheException; 
    3839import org.geowebcache.cache.CacheFactory; 
     40import org.geowebcache.cache.file.FileCache; 
     41import org.geowebcache.cache.file.FilePathKey2; 
    3942import org.geowebcache.layer.Grid; 
    4043import org.geowebcache.layer.TileLayer; 
     
    7275    private File configH = null; 
    7376 
     77    private FileCache fileCache = null; 
     78     
    7479    /** 
    7580     * XMLConfiguration class responsible for reading/writing layer 
     
    320325        /* 
    321326         * Try  
    322          * 1) absolute path  
    323          * 2) relative path  
    324          * 3) standard paths 
     327         * 1) absolute path (specified in bean defn) 
     328         * 2) relative path (specified in bean defn) 
     329         * 3) environment variables 
     330         * 4) standard paths 
    325331         */ 
    326332        if (absPath != null) { 
     
    331337                    + configH.getAbsolutePath()); 
    332338        } else if (relPath == null) { 
    333             for (int i = 0; i < CONFIGURATION_REL_PATHS.length; i++) { 
    334                 relPath = CONFIGURATION_REL_PATHS[i]; 
    335                 if (File.separator.equals("\\")) { 
    336                     relPath = relPath.replace("/", "\\"); 
     339            // Try env variables 
     340            File tmpPath = null; 
     341 
     342            if (fileCache != null) { 
     343                try { 
     344                    // Careful, this appends a separator 
     345                    tmpPath = new File(fileCache.getDefaultPrefix(CONFIGURATION_FILE_NAME)); 
     346 
     347                    if (tmpPath.exists() && tmpPath.canRead()) { 
     348                        String filePath = tmpPath.getAbsolutePath(); 
     349                        configH = new File(filePath.substring(0,  
     350                                filePath.length() 
     351                                - CONFIGURATION_FILE_NAME.length() - 1)); 
     352                    } 
     353                } catch (CacheException ce) { 
     354                    // Ignore 
    337355                } 
    338  
    339                 File tmpPath = new File(baseDir + relPath + File.separator 
    340                         + CONFIGURATION_FILE_NAME); 
    341  
    342                 if (tmpPath.exists()) { 
    343                     log.info("No configuration directory was specified, using " 
    344                             + tmpPath.getAbsolutePath()); 
    345                     configH = new File(baseDir + relPath); 
     356            } 
     357 
     358            // Finally, try "standard" paths if we have to. 
     359            if (configH == null) { 
     360                for (int i = 0; i < CONFIGURATION_REL_PATHS.length; i++) { 
     361                    relPath = CONFIGURATION_REL_PATHS[i]; 
     362                    if (File.separator.equals("\\")) { 
     363                        relPath = relPath.replace("/", "\\"); 
     364                    } 
     365 
     366                    tmpPath = new File(baseDir + relPath + File.separator 
     367                            + CONFIGURATION_FILE_NAME); 
     368 
     369                    if (tmpPath.exists() && tmpPath.canRead()) { 
     370                        log.info("No configuration directory was specified, using " 
     371                                        + tmpPath.getAbsolutePath()); 
     372                        configH = new File(baseDir + relPath); 
     373                    } 
    346374                } 
    347375            } 
     
    349377        
    350378        if(configH == null) { 
    351             log.error("Failed to find geowebcache.xml, please specify an absolute path " 
    352                     +"in geowebcache-servlet.xml!"); 
     379            log.error("Failed to find geowebcache.xml"); 
    353380        } else { 
    354381            log.info("Configuration directory set to: "+ configH.getAbsolutePath()); 
     
    370397    public void setAbsolutePath(String absPath) { 
    371398        this.absPath = absPath; 
     399    } 
     400     
     401    public void setFileCache(FileCache fileCache) { 
     402        this.fileCache = fileCache; 
    372403    } 
    373404