/** * Path construction. * * @param path Items defining a Path * @return path Path used to identify a Resource */ public static String path(String... path) { return path(STRICT_PATH, path); }
/** * Quick check of path for invalid characters * * @param path * @return path * @throws IllegalArgumentException If path fails {@link #VALID} check */ public static String valid(String path) { return path(STRICT_PATH, path); }
/** * Retrieve a resource in the the styles directory of a workspace. An empty path will retrieve * the directory itself. A null workspace will return the resource in the global styles * directory * * @return A {@link Resource} */ public @Nonnull Resource getStyles(WorkspaceInfo wsi, String... path) { Resource r = get(wsi, Paths.path(STYLE_DIR, Paths.path(path))); assert r != null; return r; }
/** * Retrieve a resource in the the layer groups directory of a workspace. An empty path will * retrieve the directory itself. A null workspace will return the resource in the global layer * groups directory * * @return A {@link Resource} */ public @Nonnull Resource getLayerGroups(WorkspaceInfo wsi, String... path) { Resource r = get(wsi, Paths.path(LAYERGROUP_DIR, Paths.path(path))); assert r != null; return r; }
/** * 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(); }
/** * Retrieve a resource relative to the root of the data directory. An empty path will retrieve * the directory itself. * * @return A {@link Resource} */ public @Nonnull Resource getRoot(String... path) { Resource r = get(Paths.path(path)); assert r != null; return r; }
@Override public Resource get(String resourcePath) { if (resourcePath == null) { throw new NullPointerException("Resource path required"); } if ("".equals(resourcePath)) { return this; } return FileSystemResourceStore.this.get(Paths.path(path, resourcePath)); }
/** * Returns a directory under the {@link #root()} directory, if the directory does not exist it * will be created. * * @return directory (created if needed) */ public File findOrCreateDir(String... location) throws IOException { return get(Paths.path(location)).dir(); }
/** * Creates a new directory specifying components of the location. * * <p>Calls through to {@link #createDirectory(String)} */ public File createDirectory(String... location) throws IOException { Resource directory = get(Paths.path(location)); return Resources.createNewDirectory(directory); }
/** * Returns a file under the {@link #root()} directory, if the file does not exist null is * returned. */ public File findFile(String... location) throws IOException { Resource resource = get(Paths.path(location)); return Resources.find(resource); }
/** * Performs a directory lookup, creating the file if it does not exist. * * @param location The components of the path that make up the location of the directory to find * or create. */ public File findOrCreateDirectory(String... location) throws IOException { Resource directory = get(Paths.path(location)); return directory.dir(); // will create directory as needed }
@Deprecated private String path(StoreInfo store) { WorkspaceInfo workspace = store.getWorkspace(); return Paths.path("workspaces", workspace.getName(), store.getName()); }
/** * Retrieve a resource in the the configuration directory of a Store. An empty path will * retrieve the directory itself. * * @param store The store * @return A {@link Resource} */ public @Nonnull Resource get(StoreInfo store, String... path) { Resource r = get(store.getWorkspace(), store.getName(), Paths.path(path)); assert r != null; return r; }
/** * Retrieve a resource in the the configuration directory of a Resource. An empty path will * retrieve the directory itself. * * @param ri The store * @return A {@link Resource} */ public @Nonnull Resource get(ResourceInfo ri, String... path) { Resource r = get(ri.getStore(), ri.getName(), Paths.path(path)); assert r != null; return r; }
@Theory public void theoryAddingFileToDirectoryAddsResource(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); File dir = res.dir(); File file = new File(dir, "newFileCreatedDirectly"); assumeTrue(file.createNewFile()); Resource child = getResource(Paths.path(res.path(), "newFileCreatedDirectly")); Collection<Resource> children = res.list(); assertThat(child, is(defined())); assertThat(children, hasItem(child)); }