@Override public void backup() throws IOException { backUpConfig(findOrCreateConfFile()); }
public GeoserverXMLResourceProvider( String providedConfigDirectory, String configFileName, ResourceStore resourceStore) throws ConfigurationException { this.configFileName = configFileName; this.configDirectory = inferConfigDirectory(resourceStore, providedConfigDirectory); LOGGER.info( String.format( "Will look for '%s' in directory '%s'.", configFileName, configDirectory.dir().getAbsolutePath())); }
@Override public boolean hasInput() { try { return Resources.exists(findOrCreateConfFile()); } catch (IOException e) { return false; } }
public String getLocation() throws IOException { return findConfigFile().path(); }
/** * Helper method that infers the directory that contains or will contain GWC configuration. * First we will check if a specific location was set using properties GEOWEBCACHE_CONFIG_DIR * and GEOWEBCACHE_CACHE_DIR, then we will check if a location was provided and then fallback on * the default location. */ private static Resource inferConfigDirectory( ResourceStore resourceStore, String providedConfigDirectory) { // check if a specific location was provided using a context property otherwise use the // provided directory String configDirectoryPath = findFirstDefined(GEOWEBCACHE_CONFIG_DIR_PROPERTY, GEOWEBCACHE_CACHE_DIR_PROPERTY) .orElse(providedConfigDirectory); // if the configuration directory stills not defined we use the default location if (configDirectoryPath == null) { configDirectoryPath = DEFAULT_CONFIGURATION_DIR_NAME; } // instantiate a resource for the configuration directory File configurationDirectory = new File(configDirectoryPath); if (configurationDirectory.isAbsolute()) { return Resources.fromPath(configurationDirectory.getAbsolutePath()); } // configuration directory path is relative to geoserver data directory return resourceStore.get(configDirectoryPath); }
public JDBCConfigurationStorage(ResourceStore store, GeoServerSecurityManager securityManager) { GeoserverXMLResourceProvider configProvider = (GeoserverXMLResourceProvider) GeoServerExtensions.bean("jdbcDiskQuotaConfigResourceProvider"); this.configDir = configProvider.getConfigDirectory(); this.passwordHelper = new JDBCPasswordEncryptionHelper(securityManager); securityManager.addListener(this); }
@Override public InputStream in() throws IOException { return findOrCreateConfFile().in(); }
private Resource findOrCreateConfFile() throws IOException { Resource xmlFile = findConfigFile(); if (Resources.exists(xmlFile)) { LOGGER.info("Found configuration file in " + configDirectory.path()); } else if (templateLocation != null) { LOGGER.warn( "Found no configuration file in config directory, will create one at '" + xmlFile.path() + "' from template " + getClass().getResource(templateLocation).toExternalForm()); // grab template from classpath try { IOUtils.copy(getClass().getResourceAsStream(templateLocation), xmlFile.out()); } catch (IOException e) { throw new IOException("Error copying template config to " + xmlFile.path(), e); } } return xmlFile; }
@Override public OutputStream out() throws IOException { return findOrCreateConfFile().out(); }