/** * Constructs the template loader. * * @param caller The "calling" class, used to look up templates based with {@link * Class#getResource(String)}, may be <code>null</code> * @param rl The geoserver resource loader * @throws IOException */ public GeoServerTemplateLoader(Class caller, GeoServerResourceLoader rl) throws IOException { this(caller, new GeoServerDataDirectory(rl)); }
/** * Retrieve the workspace configuration XML as a Resource * * @param ws The workspace * @return A {@link Resource} */ public @Nonnull Resource config(WorkspaceInfo ws) { Resource r = get(ws, WORKSPACE_XML); assert r != null; return r; }
@Override protected String convertPropertyValue(String property) { return property.replace("${GEOSERVER_DATA_DIR}", data.root().getPath()); } }
private void removeStyle(StyleInfo s) throws IOException { Resource sld = dd.style(s); if (Resources.exists(sld)) { Resource sldBackup = dd.get(sld.path() + ".bak"); int i = 1; while (Resources.exists(sldBackup)) { sldBackup = dd.get(sld.path() + ".bak." + i++); } LOGGER.fine("Removing the SLD as well but making backup " + sldBackup.name()); sld.renameTo(sldBackup); } }
@Test public void testGetParamsFixesDatabaseFilePath() { Catalog catalog = getCatalog(); ResourcePool pool = new ResourcePool(catalog); DataStoreInfo ds = getCatalog().getFactory().createDataStore(); ds.getConnectionParameters().put("database", "file:data/test.gpkg"); Map newParams = pool.getParams(ds.getConnectionParameters(), getResourceLoader()); GeoServerDataDirectory dataDir = new GeoServerDataDirectory(getResourceLoader()); String absolutePath = dataDir.get("data/test.gpkg").dir().getAbsolutePath(); assertNotEquals(newParams.get("database"), "file:data/test.gpkg"); assertTrue(((String) newParams.get("database")).contains(absolutePath)); }
@Before public void setUp() throws Exception { ctx = new ClassPathXmlApplicationContext( "GeoServerDataDirectoryTest-applicationContext.xml", getClass()); ctx.refresh(); dataDir = new GeoServerDataDirectory(Files.createTempDirectory("data").toFile()); dataDir.root().deleteOnExit(); }
@Test public void testParsedStyle() throws IOException { File styleDir = new File(dataDir.root(), "styles"); styleDir.mkdir(); // Copy the sld to the temp style dir File styleFile = new File(styleDir, "external.sld"); Files.copy(this.getClass().getResourceAsStream("external.sld"), styleFile.toPath()); File iconFile = new File(styleDir, "icon.png"); assertFalse(iconFile.exists()); StyleInfoImpl si = new StyleInfoImpl(null); si.setName(""); si.setId(""); si.setFormat("sld"); si.setFormatVersion(new Version("1.0.0")); si.setFilename(styleFile.getName()); Style s = dataDir.parsedStyle(si); // Verify style is actually parsed correctly Symbolizer symbolizer = s.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0); assertTrue(symbolizer instanceof PointSymbolizer); GraphicalSymbol graphic = ((PointSymbolizer) symbolizer).getGraphic().graphicalSymbols().get(0); assertTrue(graphic instanceof ExternalGraphic); assertEquals(((ExternalGraphic) graphic).getLocation(), iconFile.toURI().toURL()); // GEOS-7025: verify the icon file is not created if it doesn't already exist assertFalse(iconFile.exists()); }
@Test public void testNullWorkspace() { assertEquals(dataDir.get((WorkspaceInfo) null, "test").path(), dataDir.get("test").path()); assertEquals( dataDir.getStyles((WorkspaceInfo) null, "test").path(), dataDir.getStyles("test").path()); assertEquals( dataDir.getLayerGroups((WorkspaceInfo) null, "test").path(), dataDir.getLayerGroups("test").path()); }
Resource resource = null; GeoServerResourceLoader resources = catalog.getResourceLoader(); GeoServerDataDirectory data = new GeoServerDataDirectory(resources); String stylePath = reqPath.substring(7); int slash = stylePath.indexOf('/'); if (workspace != null) { String wsStylePath = stylePath.substring(slash + 1); resource = data.getStyles(workspace, wsStylePath); if (resource.getType() == Type.UNDEFINED) { resource = data.getStyles(wsStylePath); resource = data.getStyles(stylePath);
public WPSStorageCleaner(GeoServerDataDirectory dataDirectory) throws IOException, ConfigurationException { // get the temporary storage for WPS storage = dataDirectory.findOrCreateDir("temp/wps"); }
/** * Verifies that the style resource for the passed style does not yet exist, throwing an * appropriate exception if it does * * @param info The style info to test. Filename should be set. * @throws RestException if the style resource associated with the style info exists. */ private void checkStyleResourceNotExists(StyleInfo info) throws RestException { // ensure that a existing resource does not already exist, because we may not want to // overwrite it GeoServerDataDirectory dataDir = new GeoServerDataDirectory(catalog.getResourceLoader()); if (dataDir.style(info).getType() != Resource.Type.UNDEFINED) { throw new RestException( "Style resource " + info.getFilename() + " already exists.", HttpStatus.FORBIDDEN); } } }
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); ImporterTestUtils.setComparisonTolerance(); // init xmlunit Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("xlink", "http://www.w3.org/1999/xlink"); namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); namespaces.put("wms", "http://www.opengis.net/wms"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); // add test importer properties file to the temporary data dir. For testing purposes only dd = new GeoServerDataDirectory(testData.getDataDirectoryRoot()); GeoServerExtensionsHelper.singleton("dataDirectory", dd, GeoServerDataDirectory.class); // write out a simple shell script in the data dir and make it executable File importerConfigLocation = dd.findOrCreateDir("importer"); File importerConfigProps = new File(importerConfigLocation, "importer.properties"); IOUtils.copy( ImporterTestSupport.class .getClassLoader() .getResourceAsStream("importer.properties"), importerConfigProps); }
void handleSchemaOverride(List<AttributeTypeInfo> atts, FeatureTypeInfo ft) throws IOException { GeoServerDataDirectory dd = new GeoServerDataDirectory(catalog.getResourceLoader()); File schemaFile = dd.findSuppResourceFile(ft, "schema.xsd"); if (schemaFile == null) { schemaFile = dd.findSuppLegacyResourceFile(ft, "schema.xsd"); if (schemaFile == null) { File oldSchemaFile = dd.findSuppResourceFile(ft, "schema.xml"); if (oldSchemaFile == null) { oldSchemaFile = dd.findSuppLegacyResourceFile(ft, "schema.xml");
/** * Retrieve the logging configuration XML as a Resource * * @param l The settings * @return A {@link Resource} */ public @Nonnull Resource config(LoggingInfo l) { Resource r = getRoot("logging.xml"); assert r != null; return r; }
@RunTestSetup @Test public void testGeoServerReload() throws Exception { Catalog cat = getCatalog(); FeatureTypeInfo lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertFalse("foo".equals(lakes.getTitle())); GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader()); File info = dd.findResourceFile(lakes); // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml"); FileReader in = new FileReader(info); Element dom = ReaderUtils.parse(in); Element title = ReaderUtils.getChildElement(dom, "title"); title.getFirstChild().setNodeValue("foo"); OutputStream output = new FileOutputStream(info); try { TransformerFactory.newInstance() .newTransformer() .transform(new DOMSource(dom), new StreamResult(output)); } finally { output.close(); } getGeoServer().reload(); lakes = cat.getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertEquals("foo", lakes.getTitle()); }
/** * Returns the SLD file for the specified style, if the file does not exist null is returned. * * @deprecated As of GeoServer 2.6, replaced by {@link #style(StyleInfo, String...)} */ public File findStyleSldFile(StyleInfo s) throws IOException { Resource resource = style(s); return Resources.file(resource); }
} else { file = Paths.toFile(root(), resource.path()); URL u = fileToUrlPreservingCqlTemplates(file);
/** * Retrieve a resource in the the styles directory. An empty path will retrieve the directory * itself. * * @return A {@link Resource} */ public @Nonnull Resource getStyles(String... path) { Resource r = getStyles(null, path); assert r != null; return r; }