Refine search
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; } }
Resource f = resourceLoader.get("services.xml"); if (!Resources.exists(f)) { f = resourceLoader.get("global.xml"); if (Resources.exists(f)) { try { GeoServerInfo global = depersist(xp, f, GeoServerInfo.class); geoServer.setGlobal(global); } catch (Exception e) { LOGGER.log( Level.WARNING, "Failed to load global configuration file '" + f.name() + "'", e); f = resourceLoader.get("logging.xml"); if (Resources.exists(f)) { try { LoggingInfo logging = depersist(xp, f, LoggingInfo.class); geoServer.setLogging(logging); } catch (Exception e) { LOGGER.log( Level.WARNING, "Failed to load logging configuration file '" + f.name() + "'", e); Resource workspaces = resourceLoader.get("workspaces"); if (Resources.exists(workspaces)) { for (Resource dir : workspaces.list()) {
@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."); } } }
/** * 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 }
/** * 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()); }
/** * processed parameters with relative URLs resolved against data directory. * * @param m * @param sc Context used to create GeoServerResourceLoader if required * @return processed parameters with relative URLs resolved against data directory * @deprecated Unused, call {@link ResourcePool#getParams(Map, GeoServerResourceLoader)} * directly. */ public static <K, V> Map<K, V> getParams(Map<K, V> m, ServletContext sc) { GeoServerResourceLoader loader; if (sc != null) { String basePath = GeoServerResourceLoader.lookupGeoServerDataDirectory(sc); File baseDir = new File(basePath); loader = new GeoServerResourceLoader(baseDir); } else { loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); } return ResourcePool.getParams(m, loader); }
if (catalog.getWorkspaceByName(prefix) == null) { addWorkspace(prefix, uri, catalog); File storeDir = catalog.getResourceLoader().findOrCreateDirectory(prefix); DataStoreInfo store = catalog.getDataStoreByName(prefix); if (store == null) { store = catalog.getFactory().createDataStore(); catalog.getResourceLoader() .copyFromClassPath(filename, new File(storeDir, filename), scope);
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
catalog2.setResourceLoader(resourceLoader); GeoServerResourcePersister rp = new GeoServerResourcePersister(resourceLoader); if (!legacy) { catalog2.addListener(cp); catalog2.addListener(rp); importer.imprt(resourceLoader.getBaseDirectory()); Resource featureTypesDir = resourceLoader.get("featureTypes"); if (featureTypesDir != null) { LegacyCatalogReader creader = new LegacyCatalogReader(); Map<String, Map<String, Object>> dataStores = creader.dataStores(); for (Resource featureTypeDir : featureTypesDir.list()) { if (featureTypeDir.getType() != Type.DIRECTORY) { continue; Resource featureTypeInfo = featureTypeDir.get("info.xml"); if (!Resources.exists(featureTypeInfo)) { continue; resourceLoader.get( Paths.path( "workspaces",
@Test public void testModifySettingsChangeWorkspace() throws Exception { testAddSettings(); WorkspaceInfo ws1 = catalog.getWorkspaceByName("acme"); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); ws2.setName("foo"); catalog.add(ws2); SettingsInfo settings = getGeoServer().getSettings(ws1); settings.setWorkspace(ws2); getGeoServer().save(settings); File f = catalog.getResourceLoader().find("workspaces", ws1.getName(), "settings.xml"); assertNull(f); f = catalog.getResourceLoader().find("workspaces", ws2.getName(), "settings.xml"); assertNotNull(f); Document dom = dom(f); assertXpathEvaluatesTo(ws2.getId(), "/settings/workspace/id", dom); }
private Resource findUserProperties() throws IOException { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); Resource propFile = loader.get("security/users.properties"); if (propFile.getType() == Type.RESOURCE) { GeoServerInfo global = GeoServerExtensions.bean(GeoServer.class).getGlobal(); if ((global != null) && (global.getAdminUsername() != null) os = propFile.out(); p.store(os, "Format: name=password,ROLE1,...,ROLEN"); os.close(); Resource serviceFile = loader.get("security/service.properties"); os = serviceFile.out(); is = GeoServerUserDao.class.getResourceAsStream("serviceTemplate.properties"); byte[] buffer = new byte[1024];
@BeforeClass public static void setupBaseCatalog() throws Exception { catalog = new CatalogImpl(); catalog.setResourceLoader(new GeoServerResourceLoader()); final WorkspaceInfo defaultWorkspace = catalog.getDefaultWorkspace(); cb.setWorkspace(defaultWorkspace); String nsURI = catalog.getDefaultNamespace().getURI(); URL buildings = MockData.class.getResource("Buildings.properties"); File testData = URLs.urlToFile(buildings).getParentFile(); DataStoreInfo storeInfo = cb.buildDataStore("store"); storeInfo.getConnectionParameters().put("directory", testData);
GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); URL url = null; try { File file = loader.url(imageURL); if (file.exists()) { url = URLs.fileToUrl(file); Resource layouts = loader.get("layouts"); if (layouts.getType() == Resource.Type.DIRECTORY) { Resource image = layouts.get(imageURL); if (image.getType() == Resource.Type.RESOURCE) { url = URLs.fileToUrl(image.file()); Resource image = loader.get(imageURL); if (image.getType() == Resource.Type.RESOURCE) { url = URLs.fileToUrl(image.file());
Resource resource = getResourceLoader().get("styles/legend.png"); getResourceLoader().copyFromClassPath("../legend.png", resource.file(), getClass()); LAYER_QNAME, LAYER_FILE, null, propertyMap, SystemTestData.class, getCatalog()); GeoServerInfo global = getGeoServer().getGlobal(); getGeoServer().save(global); WMSInfo wms = getGeoServer().getService(WMSInfo.class); wms.getSRS().add("EPSG:4326"); getGeoServer().save(wms);
if (isPost && storeName != null) { CoverageStoreInfo coverage = catalog.getCoverageStoreByName(storeName); if (coverage != null) { if (workspaceName == null URLs.urlToFile(new URL(coverage.getURL())).getPath(), catalog.getResourceLoader().get("")); catalog.getResourceLoader().get(Paths.path("data", workspaceName, storeName)); StringBuilder root = new StringBuilder(directory.path()); GeoServerExtensions.extensions(RESTUploadPathMapper.class);
@Override public void run() { try { // first check that temp/wcs is really there in the data dir GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); Resource wcs = loader.get("temp/wcs"); if (wcs.getType() != Type.DIRECTORY) { return; // nothing to cleanup } // ok, now scan for existing files there and clean up those that are too old long now = System.currentTimeMillis(); for (Resource f : wcs.list()) { if (now - f.lastmodified() > (expirationDelay * 1000)) { f.delete(); } } } catch (Exception e) { LOGGER.log( Level.WARNING, "Error occurred while trying to clean up " + "old coverages from temp storage", e); } }
Resources.fromURL(xmppServerEmbeddedCertFile.trim()); if (certFileResource != null) { this.certificateFile = certFileResource.file(); this.certificatePassword = xmppServerEmbeddedCertPwd.trim(); } else { GeoServerExtensions.bean(GeoServerResourceLoader.class); try { this.certificateFile = loader.createFile(xmppServerEmbeddedCertFile.trim()); loader.copyFromClassPath( xmppServerEmbeddedCertFile.trim(), this.certificateFile /*, this.certificateFile = loader.find(xmppServerEmbeddedCertFile.trim()); this.certificatePassword = xmppServerEmbeddedCertPwd.trim(); } catch (IOException e) {
/** * Tests that already cached icons are recreated if related SLD is newer (using Catalog events). */ @Test public void testCachedLegendURLUpdatedSize2() throws Exception { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); Resource sldResource = loader.get(Paths.path("styles", "Bridges.sld")); File sampleFile = getSampleFile("Bridges"); long lastTime = sampleFile.lastModified(); long lastLength = sampleFile.length(); long previousTime = sldResource.lastmodified(); sldResource.file().setLastModified(lastTime + 1000); catalog.firePostModified( catalog.getStyleByName("Bridges"), new ArrayList<String>(), new ArrayList(), new ArrayList()); TransformerBase tr = createTransformer(); tr.setIndentation(2); Document dom = WMSTestSupport.transform(req, tr); NodeList legendURLs = XPATH.getMatchingNodes(getLegendURLXPath("cite:Bridges"), dom); assertEquals(1, legendURLs.getLength()); Element legendURL = (Element) legendURLs.item(0); assertTrue(legendURL.hasAttribute("width")); assertEquals("20", legendURL.getAttribute("width")); assertTrue(legendURL.hasAttribute("height")); assertEquals("20", legendURL.getAttribute("height")); assertFalse(getSampleFile("Bridges").length() == lastLength); sldResource.file().setLastModified(previousTime); }
/** Copies a well known style out to the data directory and adds a catalog entry for it. */ void initializeStyle(Catalog catalog, String styleName, String sld) throws IOException { // copy the file out to the data directory if necessary Resource styleResource = resourceLoader.get(Paths.path("styles", sld)); if (!Resources.exists(styleResource)) { try (InputStream in = GeoServerLoader.class.getResourceAsStream(sld); OutputStream out = styleResource.out()) { IOUtils.copy(in, out); } } // create a style for it StyleInfo s = catalog.getFactory().createStyle(); s.setName(styleName); s.setFilename(sld); catalog.add(s); }
@Override public void saveConfiguration(GeoServerResourceLoader resourceLoader) throws IOException { GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class); for (Resource controlflow : getFileLocations()) { Resource targetDir = Files.asResource( resourceLoader.findOrCreateDirectory( Paths.convert( loader.getBaseDirectory(), controlflow.parent().dir()))); Resources.copy(controlflow.file(), targetDir); } }