/** The root of the data directory. */ public File root() { return resourceLoader.getBaseDirectory(); }
/** * Performs a resource lookup, optionally specifying the containing directory. * * @param parentFile The containing directory, optionally null. * @param location The name of the resource to lookup, can be absolute or relative. * @return The file handle representing the resource, or null if the resource could not be * found. * @throws IOException In the event of an I/O error. */ public File find(File parentFile, String location) throws IOException { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest( "Looking up resource " + location + " with parent " + (parentFile != null ? parentFile.getPath() : "null")); } Resource resource = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.find(resource); }
/** * Performs a directory lookup, creating the file if it does not exist. * * @param parentFile The containing directory, possibly null. * @param location The components of the path that make up the location of the directory to find * or create. */ public File findOrCreateDirectory(File parentFile, String... location) throws IOException { Resource directory = get(Paths.convert(getBaseDirectory(), parentFile, location)); return directory.dir(); // will create directory as needed }
/** * Performs a directory lookup, creating the file if it does not exist. * * @param parentFile The containing directory, may be null. * @param location The location of the directory to find or create. * @return The file handle. * @throws IOException If any i/o errors occur. */ public File findOrCreateDirectory(File parentFile, String location) throws IOException { Resource directory = get(Paths.convert(getBaseDirectory(), parentFile, location)); return directory.dir(); // will create directory as needed }
@Override protected void readConfiguration(GeoServer geoServer, XStreamPersister xp) throws Exception { // look for legacy services.xml File f = resourceLoader.find("services.xml"); if (f != null) { // load configuration LegacyConfigurationImporter importer = new LegacyConfigurationImporter(); importer.setConfiguration(geoServer); importer.imprt(resourceLoader.getBaseDirectory()); } else { LOGGER.warning("No configuration file found."); } } }
/** * Creates a new file. * * <p>Calls through to {@link #createFile(File, String)} * * @param location Location of file to create, either absolute or relative. * @param parentFile The containing directory for the file. * @return The file handle of the created file. * @throws IOException In the event of an I/O error. */ public File createFile(File parentFile, String... location) throws IOException { Resource resource = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.createNewFile(resource); }
/** * Creates a new directory specifying components of the location, and the containing directory. * * <p>Calls through to {@link #createDirectory(String)} * * @param parentFile The containing directory, possibly null. * @param location The components of the path that make up the location of the directory to * create * @return newly created directory */ public File createDirectory(File parentFile, String... location) throws IOException { Resource directory = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.createNewDirectory(directory); }
/** * Creates a new directory, optionally specifying a containing directory. * * <p>Relative paths are created relative to {@link #baseDirectory}. If {@link #baseDirectory} * is not set, an IOException is thrown. * * <p>If <code>location</code> already exists as a file, an IOException is thrown. * * @param parentFile The containing directory, may be null. * @param location Location of directory to create, either absolute or relative. * @return The file handle of the created directory. */ public File createDirectory(File parentFile, String location) throws IOException { Resource directory = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.createNewDirectory(directory); }
private GeoServerDataDirectory createGeoServerDataDirectoryMock(String path) { // we mock the file so linux paths are not convert in windows paths and vice-versa File mockedPath = EasyMock.createMock(File.class); EasyMock.expect(mockedPath.getPath()).andReturn(path).anyTimes(); // mocked data directory that will use our mocked file GeoServerResourceLoader resourceLoader = EasyMock.createMock(GeoServerResourceLoader.class); EasyMock.expect(resourceLoader.getBaseDirectory()).andReturn(mockedPath).anyTimes(); EasyMock.replay(mockedPath, resourceLoader); return new GeoServerDataDirectory(resourceLoader); } }
/** * Creates a new file. * * <p>Relative paths are created relative to {@link #baseDirectory}. * * <p>If {@link #baseDirectory} is not set, an IOException is thrown. * * <p>If <code>location</code> already exists as a directory, an IOException is thrown. * * @param location Location of file to create, either absolute or relative. * @param parentFile The containing directory for the file. * @return The file handle of the created file. * @throws IOException In the event of an I/O error. */ public File createFile(File parentFile, String location) throws IOException { Resource resource = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.createNewFile(resource); }
/** * Performs a resource lookup, optionally specifying a containing directory. * * <pre> * Example: * File f = resourceLoader.find( "data", "shapefiles", "foo.shp" ); * </pre> * * @param parentFile The parent directory, may be null. * @param location The components of the path of the resource to lookup. * @return The file handle representing the resource, or null if the resource could not be * found. * @throws IOException Any I/O errors that occur. */ public File find(File parentFile, String... location) throws IOException { Resource resource = get(Paths.convert(getBaseDirectory(), parentFile, location)); return Resources.find(resource); }
if (!new File(logFileName).isAbsolute()) { logFileName = new File(loader.getBaseDirectory(), logFileName).getAbsolutePath(); LoggingInitializer.LOGGER.fine( "Non-absolute pathname detected for logfile. Setting logfile relative to data dir.");
@Override protected void readCatalog(Catalog catalog, XStreamPersister xp) throws Exception { catalog.setResourceLoader(resourceLoader); // look for legacy catalog.xml File f = resourceLoader.find("catalog.xml"); if (f != null) { LegacyCatalogImporter catalogImporter = new LegacyCatalogImporter(); catalogImporter.setResourceLoader(resourceLoader); catalogImporter.setCatalog(catalog); catalogImporter.imprt(resourceLoader.getBaseDirectory()); } else { LOGGER.warning("No catalog file found."); } }
@Test public void testFindDataFileForAbsolutePath() throws IOException { GeoServerResourceLoader loader = getResourceLoader(); final File dataDir = loader.getBaseDirectory(); final String absolutePath = dataDir.getCanonicalPath() + SEPARATOR_CHAR + RAIN_DATA_PATH; final File file = loader.url(absolutePath); assertNotNull(file); }
@Test public void testLoadGibberish() throws Exception { // we should get a log message, but the startup should continue File service = new File(getDataDirectory().getResourceLoader().getBaseDirectory(), "service.xml"); FileUtils.writeStringToFile(service, "duDaDa"); getGeoServer().reload(); assertEquals(0, geoServer.getServices().size()); }
@Test public void testSetBaseDirectory() throws IOException { GeoServerResourceLoader loader = new GeoServerResourceLoader(); assertNull(loader.getBaseDirectory()); assertEquals(ResourceStore.EMPTY, loader.getResourceStore()); tempFolder.create(); File tempDir = tempFolder.getRoot(); loader.setBaseDirectory(tempDir); assertEquals(tempDir, loader.getBaseDirectory()); assertTrue(loader.getResourceStore() instanceof FileSystemResourceStore); ResourceStore mockStore = EasyMock.createMock(ResourceStore.class); loader = new GeoServerResourceLoader(mockStore); assertNull(loader.getBaseDirectory()); assertEquals(mockStore, loader.getResourceStore()); loader.setBaseDirectory(tempDir); assertEquals(tempDir, loader.getBaseDirectory()); assertEquals(mockStore, loader.getResourceStore()); } }
importer.imprt(resourceLoader.getBaseDirectory());
new LegacyConfigurationImporter(geoServer).imprt(resourceLoader.getBaseDirectory());
MockCatalogBuilder b = new MockCatalogBuilder(catalog, loader.getBaseDirectory()); b.setCallback(this);
private File findConfigFile() throws IOException { File configFile = resourceLoader.find(CONFIG_FILE_NAME); if (configFile == null) { configFile = new File(resourceLoader.getBaseDirectory(), CONFIG_FILE_NAME); } return configFile; }