@Override public File file() { return delegate.file(); }
public File getFile() { return resource.file(); }
/** * Returns the configuration file for the specified workspace, if the file does not exist a file * object will still be returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #config(WorkspaceInfo)} */ @Deprecated public File findOrResolveWorkspaceFile(WorkspaceInfo ws) throws IOException { Resource workspaceFile = config(ws); return workspaceFile.file(); }
/** * Returns the configuration file for the specified store, if the file does not exist a file * object is still returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #get(StoreInfo, String...)} */ @Deprecated public File findOrResolveStoreFile(StoreInfo store) throws IOException { Resource resource = get(store); return resource.file(); }
/** * If create is true or if a file exists returns resource.file, otherwise it returns null. * * @see Resource#file() * @param resource Resource indicated * @param create true to create (if needed) * @return file, or null */ public static File file(Resource resource, boolean create) { final File f; if (resource == null) { f = null; } else if (create) { f = resource.file(); } else { if (resource.getType() == Type.RESOURCE) { f = resource.file(); } else { f = null; } } return f; }
/** * Returns the configuration file for the specified resource, if the file does not exist a file * object is still returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #config(FeatureTypeInfo, String...)}, * {@link #config(CoverageInfo, String...)}, {@link #config(WMSLayerInfo, String...)} */ @Deprecated public File findOrResolveResourceFile(ResourceInfo r) throws IOException { Resource resource = config(r); return resource.file(); }
/** * Returns the configuration file for the specified style, if the file does not exist a file * object is still returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #config(StyleInfo, String...)} */ public File findOrCreateStyleFile(StyleInfo s) throws IOException { Resource resource = config(s); return resource.file(); }
/** * Returns the configuration file for the specified layer, if the file does not exist a file * object is still returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #get(LayerInfo, String...)} */ public File findOrResolveLayerFile(LayerInfo layer) throws IOException { Resource resource = get(layer); return resource.file(); }
/** * Returns the SLD file for the specified style, if the file does not exist a file object is * still returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #style(StyleInfo, String...)} */ public File findOrCreateStyleSldFile(StyleInfo s) throws IOException { Resource resource = style(s); return resource.file(); }
public List validateGETMAP(InputSource xml, ServletContext servContext) { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); Resource schema = loader.get("data/capabilities/sld/GetMap.xsd"); File schemaFile = schema.file(); // File schemaFile = new File(GeoserverDataDirectory.getGeoserverDataDirectory(), // "/data/capabilities/sld/GetMap.xsd"); try { return validateGETMAP(xml, URLs.fileToUrl(schemaFile)); } catch (Exception e) { ArrayList al = new ArrayList(); al.add(new SAXException(e)); return al; } }
/** * Returns a file under the {@link #dataRoot()} directory, if the file does not exist it a file * object will still be returned. * * @deprecated Unused */ public File findOrResolveDataFile(String... location) throws IOException { Resource resource = get(Paths.path("data", Paths.path(location))); return resource.file(); }
/** * validates against the "normal" location of the schema (ie. * ".../capabilities/sld/StyleLayerDescriptor.xsd" uses the geoserver_home patch * * @param xml * @param req */ public List validateGETMAP(InputStream xml) { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); Resource schema = loader.get("data/capabilities/sld/GetMap.xsd"); File schemaFile = schema.file(); try { return validateGETMAP(xml, URLs.fileToUrl(schemaFile)); } catch (Exception e) { ArrayList al = new ArrayList(); al.add(new SAXException(e)); return al; } }
/** * Create a new file for the provided resource (this will only work for {@link * Resource.Type#UNDEFINED}). * * <p>This approach is a reproduction of GeoServerResourceLoader createNewFile logic. * * @param resource Resource indicated * @return newly created file * @throws IOException If path indicates a file (or directory) that already exists */ public static File createNewFile(Resource resource) throws IOException { switch (resource.getType()) { case DIRECTORY: throw new IOException( "New file " + resource.path() + " already exists as DIRECTORY"); case RESOURCE: throw new IOException( "New file " + resource.path() + " already exists as RESOURCE"); case UNDEFINED: return resource.file(); // will create directory as needed default: return null; } }
/** * Copies a resource located on the classpath to a specified path. * * <p>The <tt>resource</tt> is obtained from teh context class loader of the current thread. * When the <tt>to</tt> parameter is specified as a relative path it is considered to be * relative to {@link #getBaseDirectory()}. * * @param classpathResource The resource to copy. * @param location The destination to copy to. */ public void copyFromClassPath(String classpathResource, String location) throws IOException { Resource resource = get(Paths.convert(location)); copyFromClassPath(classpathResource, resource.file()); }
/** * Returns a file under the {@link #dataRoot()} directory. * * @param create Create file (if required) * @param location file location * @return File (created if needed) or null if not found * @deprecated Unused */ private File dataFile(boolean create, String... location) throws IOException { Resource resource = get(Paths.path("data", Paths.path(location))); if (create) { return resource.file(); } else { return Resources.file(resource); } }
/** * Locate the specified grid file. * * <p>It will look in GEOSERVER_DATA_DIR/user_projections * * @param grid the grid name/location * @return the fully resolved URL of the grid or null, if the resource cannot be located. */ @Override public URL locateGrid(String grid) { if (grid == null) return null; GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); if (loader == null) { return null; // must be test case still loading } Resource gridfile = loader.get("user_projections/" + grid); if (gridfile.getType() == Type.RESOURCE) { return URLs.fileToUrl(gridfile.file()); } else { return null; } } }
@Theory public void theoryNonDirectoriesHaveFileWithSameContents(String path) throws Exception { Resource res = getResource(path); assumeThat(res, not(directory())); byte[] test = {42, 29, 32, 120, 69, 0, 1}; try (OutputStream ostream = res.out()) { ostream.write(test); } byte[] result = new byte[test.length]; try (InputStream istream = new FileInputStream(res.file())) { istream.read(result); assertThat(istream.read(), is(-1)); } assertThat(result, equalTo(test)); }
@Theory public void theoryAlteringFileAltersResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, not(directory())); byte[] testResource = {42, 29, 32, 120, 69, 0, 1}; byte[] testFile = {27, 3, 5, 90, -120, -3}; // Write to resource try (OutputStream ostream = res.out()) { ostream.write(testResource); } // Write to file try (OutputStream ostream = new FileOutputStream(res.file())) { ostream.write(testFile); } // Read from resource byte[] result = new byte[testFile.length]; try (InputStream istream = res.in()) { istream.read(result); assertThat(istream.read(), is(-1)); } // Should be what was written to the file assertThat(result, equalTo(testFile)); }
@Theory public void theoryHaveFile(String path) throws Exception { Resource res = getResource(path); assumeThat(res, resource()); File result = res.file(); assertThat(result, notNullValue()); }
@Test public void resourcesTest() throws IOException { Resource source = getResource(); Resource directory = getDirectory(); Resources.copy(source.file(), directory); Resource target = directory.get(source.name()); assertTrue(Resources.exists(target)); assertEquals(target.name(), source.name()); } }