/** * Test if the file or directory denoted by this resource exists. * * @see File#exists() * @param resource Resource indicated * @return true If resource is not UNDEFINED */ public static boolean exists(Resource resource) { return resource != null && resource.getType() != Resource.Type.UNDEFINED; }
@Override public boolean accept(Resource obj) { return obj.getType() == Type.DIRECTORY; } }
@Override public Type getType() { return delegate.getType(); }
@Override public boolean matches(Object item) { if (item instanceof Resource) { return ((Resource) item).getType() != Type.UNDEFINED; } return false; }
/** Determines if the underlying file has been modified since the last check. */ public boolean isModified() { long now = System.currentTimeMillis(); if ((now - lastCheck) > 1000) { lastCheck = now; stale = (resource.getType() != Type.UNDEFINED) && (resource.lastmodified() != lastModified); } return stale; }
@Override public boolean matches(Object item) { if (item instanceof Resource) { Resource res = (Resource) item; return res.getType() == Type.RESOURCE; } return false; }
@Override public boolean matches(Object item) { if (item instanceof Resource) { return ((Resource) item).getType() == Type.UNDEFINED; } return false; }
@Override public boolean matches(Object item) { if (item instanceof Resource) { Resource res = (Resource) item; return res.getType() == Type.DIRECTORY; } return false; }
@Override protected URL validateRelativeURL(URL relativeUrl) { if (relativeUrl.getProtocol().equalsIgnoreCase("resource")) { String path = relativeUrl.getPath(); if (resourceLoader.get(path).getType() != Type.UNDEFINED) { return relativeUrl; } else { return null; } } else { return super.validateRelativeURL(relativeUrl); } }
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(); } }
@Override public void visit(ExternalGraphic exgr) { if (exgr.getOnlineResource() == null) { return; } try { final String location = exgr.getURI(); Resource r = resourceLoader.fromURL(location); if (r != null && r.getType() != Type.UNDEFINED) { resources.add(r); } } catch (IllegalArgumentException e) { GeoServerConfigPersister.LOGGER.log( Level.WARNING, "Error attemping to process SLD resource", e); } }
String loadMasterPasswordDigest() throws IOException { // look for file Resource pwDigestFile = security().get(MASTER_PASSWD_DIGEST_FILENAME); if (pwDigestFile.getType() == Type.RESOURCE) { InputStream fin = pwDigestFile.in(); try { return IOUtils.toString(fin); } finally { fin.close(); } } else { // compute and store char[] masterPasswd = getMasterPassword(); try { return computeAndSaveMasterPasswordDigest(masterPasswd); } finally { disposePassword(masterPasswd); } } }
/** loads the named entity config from persistence */ public C loadConfig(String name, MigrationHelper migrationHelper) throws IOException { Resource dir = getRoot().get(name); if (dir.getType() != Type.DIRECTORY) { return null; } XStreamPersister xp = persister(); if (migrationHelper != null) { migrationHelper.migrationPersister(xp); } return (C) loadConfigFile(dir, xp); }
public GeoServerSecurityManager(GeoServerDataDirectory dataDir) throws Exception { this.dataDir = dataDir; /* * JD we have to ensure that the master password is initialized first thing, before the * catalog since we need to decrypt configuration the passwords, the rest of the security * initializes occurs at the end of startup */ Resource masterpw = security().get(MASTER_PASSWD_CONFIG_FILENAME); if (masterpw.getType() == Type.RESOURCE) { init(loadMasterPasswordConfig()); } // if it doesn't exist this must be a migration startup... and this case should be // handled during migration where all the datastore passwords are processed // explicitly configPasswordEncryptionHelper = new ConfigurationPasswordEncryptionHelper(this); }
/** * Write the contents of a resource into another resource. Also supports directories * (recursively). * * @param data resource to read * @param destination resource to write to * @throws IOException If data could not be copied to destination */ public static void copy(Resource data, Resource destination) throws IOException { if (data.getType() == Type.DIRECTORY) { for (Resource child : data.list()) { copy(child, destination.get(child.name())); } } else { try (InputStream in = data.in()) { copy(in, destination); } } }
@Theory public void theoryParentIsDirectory(String path) throws Exception { Resource res = getResource(path); Resource parent = res.parent(); assumeThat(path + " not root", parent, notNullValue()); if (res.getType() != Type.UNDEFINED) { assertThat(path + " directory", parent, is(directory())); } }
private void renameStyle(StyleInfo s, String newName) throws IOException { // rename style definition file Resource style = dd.style(s); StyleHandler format = Styles.handler(s.getFormat()); Resource target = uniqueResource(style, newName, format.getFileExtension()); renameRes(style, target.name()); s.setFilename(target.name()); // rename generated sld if appropriate if (!SLDHandler.FORMAT.equals(format.getFormat())) { Resource sld = style.parent().get(FilenameUtils.getBaseName(style.name()) + ".sld"); if (sld.getType() == Type.RESOURCE) { LOGGER.fine("Renaming style resource " + s.getName() + " to " + newName); Resource generated = uniqueResource(sld, newName, "sld"); renameRes(sld, generated.name()); } } }
@Test public void testReloadDefaultStyles() throws Exception { // clear up all "point" styles final Resource styles = getDataDirectory().getStyles(); styles.list() .stream() .filter(r -> r.getType() == Resource.Type.RESOURCE && r.name().contains("point")) .forEach(r -> r.delete()); // reload getGeoServer().reload(); // check the default point style has been re-created final StyleInfo point = getCatalog().getStyleByName("point"); assertNotNull(point); }
@Test public void testChangeStyleWorkspaceRelativeResources() throws Exception { // move style to a different workspace final Catalog catalog = getCatalog(); final StyleInfo style = catalog.getStyleByName("relative"); final WorkspaceInfo secondaryWs = catalog.getWorkspaceByName("secondary"); style.setWorkspace(secondaryWs); catalog.save(style); // check the referenced image and svg has been moved keeping the relative position final Resource relativeImage = getDataDirectory().getStyles(secondaryWs, "images", "rockFillSymbol.png"); assertEquals(Resource.Type.RESOURCE, relativeImage.getType()); final Resource relativeSvg = getDataDirectory().getStyles(secondaryWs, "images", "square16.svg"); assertEquals(Resource.Type.RESOURCE, relativeSvg.getType()); } }