@Override public File file() { return URLs.urlToFile(url); }
static OutputStream output(URL url, Resource configDir) throws IOException { // check for file url if ("file".equalsIgnoreCase(url.getProtocol())) { File f = URLs.urlToFile(url); if (!f.isAbsolute()) { // make relative to config dir return configDir.get(f.getPath()).out(); } else { return new FileOutputStream(f); } } else { URLConnection cx = url.openConnection(); cx.setDoOutput(true); return cx.getOutputStream(); } }
static InputStream input(URL url, Resource configDir) throws IOException { // check for a file url if ("file".equalsIgnoreCase(url.getProtocol())) { File f = URLs.urlToFile(url); // check if the file is relative if (!f.isAbsolute()) { // make it relative to the config directory for this password provider Resource res = configDir.get(f.getPath()); if (res.getType() != Type.RESOURCE) { // file must already exist. throw new FileNotFoundException(); } return res.in(); } else { return new FileInputStream(f); } } else { return url.openStream(); } }
/** * Used to look up a resource based on user provided url. * * <p>Supports * * <ul> * <li>Actual URL to external resource using http or ftp protocol - will return null * <li>Resource URL - will support resources from resource store * <li>File URL - will support absolute file references * <li>File URL - will support relative file references - this is deprecated, use resource: * instead * <li>Fake URLs - sde://user:pass@server:port - will return null. * </ul> * * @param baseDirectory base directory for resource: or relative file: paths * @param url the url * @return corresponding Resource */ public static Resource fromURL(Resource baseDirectory, URL url) { if (url.getProtocol().equalsIgnoreCase("resource")) { return baseDirectory.get(Paths.convert(url.getPath())); } else if (url.getProtocol().equalsIgnoreCase("file")) { return Files.asResource(URLs.urlToFile(url)); } else { return null; } }
public static File unpackTestDataDir() throws Exception { URL url = AbstractSecurityServiceTest.class.getResource("/data_dir/default"); if (!"file".equals(url.getProtocol())) { // means a dependency is using this directory via a jarfile, copy out manually File dataDir = File.createTempFile("data", "live", new File("./target")); dataDir.delete(); dataDir.mkdirs(); // TODO: instead of harcoding files, dynamically read all subentries from the jar // and copy them out FileUtils.copyURLToFile( AbstractSecurityServiceTest.class.getResource("/data_dir/default/dummy.txt"), new File(dataDir, "dummy.txt")); return dataDir; } return URLs.urlToFile(url); }
File file = URLs.urlToFile(url); if (file != null && file.exists() && file.isDirectory()) { String uri = request.getRequestURI();
return Files.asResource(URLs.urlToFile(new URL(url))); } catch (Exception e) {
@Before public void setUp() throws Exception { gs = new GeoServerImpl(); importer = new LegacyLoggingImporter(); importer.imprt(URLs.urlToFile(getClass().getResource("services.xml")).getParentFile()); }
@Before public void setUp() throws Exception { GeoServer gs = new GeoServerImpl(); gs.setFactory(new GeoServerFactoryImpl(gs)); importer = new LegacyConfigurationImporter(gs); importer.imprt(URLs.urlToFile(getClass().getResource("services.xml")).getParentFile()); }
/** @deprecated Use {@link URLs#urlToFile(URL)} */ public static File urlToFile(URL url) { return URLs.urlToFile(url); } }
@Test public void testSEStyleWithRelativePathProtocol() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative_protocol"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
@Test public void testSEStyleWithRelativePath() throws IOException { StyleInfo si = getCatalog().getStyleByName("relative"); assertNotNull(si); Style style = si.getStyle(); PolygonSymbolizer ps = (PolygonSymbolizer) style.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); ExternalGraphic eg = (ExternalGraphic) ps.getFill().getGraphicFill().graphicalSymbols().get(0); URI uri = eg.getOnlineResource().getLinkage(); assertNotNull(uri); File actual = URLs.urlToFile(uri.toURL()).getCanonicalFile(); assertEquals(rockFillSymbolFile, actual); }
/** * Helper method to check if for "url" parameter. * * @return url parameters as a File, or null if not applicable */ public File getFile() { URL url = (URL) connectionParameters.get("url"); return URLs.urlToFile(url); } /** @param format2 */
@Test public void testLookupFreshlyAdded() { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); String nsURI = catalog.getDefaultNamespace().getURI(); URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("freshOffTheBoat"); storeInfo.getConnectionParameters().put("directory", testData); storeInfo.getConnectionParameters().put("namespace", nsURI); catalog.save(storeInfo); CatalogRepository repository = getCatalog().getResourcePool().getRepository(); DataStore store = repository.dataStore(new NameImpl("freshOffTheBoat")); assertNotNull(store); } }
public static void fixH2DatabaseLocation( Map<String, Serializable> params, String parentLocation) throws MalformedURLException { if (params.containsKey(DATABASE_KEY)) { String dbname = (String) params.get(DATABASE_KEY); // H2 database URLs must not be percent-encoded: see GEOT-4262. params.put( DATABASE_KEY, "file:" + (new File(URLs.urlToFile(new URL(parentLocation)), dbname)) .getPath()); } }
@Before public void setUp() { URL url = DefaultGeoServerLoaderTest.class.getResource("/data_dir/nested_layer_groups"); GeoServerResourceLoader resourceLoader = new GeoServerResourceLoader(URLs.urlToFile(url)) { @Override public File createFile(File parentFile, String location) throws IOException { if ("hello.xml".equals(location)) { helloServiceSaved = true; } return super.createFile(parentFile, location); } }; GeoServerExtensionsHelper.singleton( "resourceLoader", resourceLoader, GeoServerResourceLoader.class); loader = new DefaultGeoServerLoader(resourceLoader); catalog = new CatalogImpl(); catalog.setResourceLoader(resourceLoader); XStreamPersisterFactory xpf = new XStreamPersisterFactory(); xp = xpf.createXMLPersister(); XStreamServiceLoader<HelloServiceInfo> helloLoader = new HelloServiceXStreamLoader(resourceLoader, "hello"); GeoServerExtensionsHelper.singleton("helloLoader", helloLoader, XStreamServiceLoader.class); }
File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("store"); storeInfo.getConnectionParameters().put("directory", testData);
@Before public void setUp() throws Exception { System.setProperty(TEST_SYSTEM_PROPERTY, TEST_SYSTEM_PROPERTY_VALUE); System.setProperty( TEST_FILE_SYSTEM_PROPERTY, URLs.urlToFile( InterpolationProperties.class.getResource( "/" + IDENTIFIER + ".file.properties")) .getPath()); }
public void testPreserveURLQuery() throws Exception { DefaultResourceLocator locator = new DefaultResourceLocator(); locator.setSourceUrl(getClass().getResource("test-data/blob.gif")); // Confirm still able to resolve to a File URL url = locator.locateResource("blob.gif?query=parameter"); assertEquals("query=parameter", url.getQuery()); File file = URLs.urlToFile(url); assertTrue(file.exists()); }