public LockFile(Resource file) throws IOException { lockFileTarget = file; if (!Resources.exists(file)) { throw new IOException("Cannot lock a not existing file: " + file.path()); } lockFile = file.parent().get(lockFileTarget.name() + ".lock"); Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { // remove on shutdown @Override public void run() { lockFile.delete(); } })); }
/** * Parses the info.xml file into a DOM. * * <p>This method *must* be called before any other methods. * * @param file The info.xml file. * @throws IOException In event of a parser error. */ public void read(Resource file) throws IOException { parentDirectory = file.parent(); Reader reader = XmlCharsetDetector.getCharsetAwareReader(file.in()); try { featureType = ReaderUtils.parse(reader); } finally { reader.close(); } }
throws IOException { Resource dir = getResource().parent(); Resource newKSFile = dir.get(PREPARED_FILE_NAME); if (newKSFile.getType() != Type.UNDEFINED) {
@Override public boolean renameTo(Resource dest) { if (dest.parent().path().contains(path())) { LOGGER.log(Level.FINE, "Cannot rename a resource to a descendant of itself"); return false; } try { if (dest instanceof FileSystemResource) { rename(file, ((FileSystemResource) dest).file); } else if (dest instanceof Files.ResourceAdaptor) { rename(file, ((Files.ResourceAdaptor) dest).file); } else { return Resources.renameByCopy(this, dest); } } catch (IOException e) { LOGGER.log( Level.WARNING, "Failed to rename file resource " + path + " to " + dest.path(), e); return false; } return true; }
private void renameRes(Resource r, String newName) { rl.move(r.path(), r.parent().get(newName).path()); }
private void renameRes(Resource r, String newName) { try { rl.move(r.path(), r.parent().get(newName).path()); } catch (Exception e) { throw new CatalogException(e); } }
@Override public void commitMasterPasswordChange() throws IOException { Resource dir = getResource().parent(); Resource newKSFile = dir.get(PREPARED_FILE_NAME); Resource oldKSFile = dir.get(DEFAULT_FILE_NAME);
URI oldURI = new URI(old.path()); final URI relative = oldDirURI.relativize(oldURI); final Resource target = newDir.get(relative.getPath()).parent(); copyResToDir(old, target);
@Theory public void theoryChildrenKnowTheirParents(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); Collection<Resource> children = res.list(); assumeThat(children, not(empty())); // Make sure this resource has children for (Resource child : children) { Resource parent = child.parent(); assertThat(parent, equalTo(res)); } }
private void loadWmtsStore( StoreContents storeContents, CatalogImpl catalog, XStreamPersister xp) { final Resource storeResource = storeContents.resource; WMTSStoreInfo wmts = null; try { wmts = depersist(xp, storeContents.contents, WMTSStoreInfo.class); catalog.add(wmts); LOGGER.info("Loaded wmtsstore '" + wmts.getName() + "'"); } catch (Exception e) { LOGGER.log( Level.WARNING, "Failed to load wmts store '" + storeResource.name() + "'", e); return; } // load wmts layers LayerLoader<WMTSLayerInfo> coverageLoader = new LayerLoader<>(WMTSLayerInfo.class, xp, catalog); try (AsynchResourceIterator<LayerContents> it = new AsynchResourceIterator<>( storeResource.parent(), Resources.DirectoryFilter.INSTANCE, WMTS_LAYER_MAPPER)) { while (it.hasNext()) { LayerContents lc = it.next(); coverageLoader.accept(lc); } } }
try (AsynchResourceIterator<LayerContents> it = new AsynchResourceIterator<>( storeResource.parent(), Resources.DirectoryFilter.INSTANCE, COVERAGE_LAYER_MAPPER)) {
@Theory public void theoryParentsKnowTheirChildren(String path) throws Exception { Resource res = getResource(path); assumeThat(res, is(directory())); Resource parent = res.parent(); assumeThat(path, parent, notNullValue()); // Make sure this resource has a parent Collection<Resource> result = parent.list(); assertThat(path, result, hasItem(res)); // this assumed equals was written! }
@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 loadWmsStore( StoreContents storeContents, CatalogImpl catalog, XStreamPersister xp) { final Resource storeResource = storeContents.resource; WMSStoreInfo wms = null; try { wms = depersist(xp, storeContents.contents, WMSStoreInfo.class); catalog.add(wms); LOGGER.info( "Loaded wmsstore '" + wms.getName() + "', " + (wms.isEnabled() ? "enabled" : "disabled")); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to load wms store '" + storeResource.name() + "'", e); return; } // load wms layers LayerLoader<WMSLayerInfo> coverageLoader = new LayerLoader<>(WMSLayerInfo.class, xp, catalog); try (AsynchResourceIterator<LayerContents> it = new AsynchResourceIterator<>( storeResource.parent(), Resources.DirectoryFilter.INSTANCE, WMS_LAYER_MAPPER)) { while (it.hasNext()) { LayerContents lc = it.next(); coverageLoader.accept(lc); } } }
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()); } } }
f.renameTo(f.parent().get("catalog.xml.old"));