use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class ObjectPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(NodeState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String nodeFilePath = buildNodeFilePath(state.getNodeId());
FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
try {
if (nodeFile.exists()) {
// delete resource and prune empty parent folders
nodeFile.delete(true);
}
} catch (FileSystemException fse) {
String msg = "failed to delete node state: " + state.getNodeId();
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class NamespaceRegistryImpl method store.
private void store() throws RepositoryException {
FileSystemResource propFile = new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
try {
propFile.makeParentDirs();
OutputStream os = propFile.getOutputStream();
Properties props = new Properties();
// store mappings in properties
for (String prefix : prefixToURI.keySet()) {
String uri = prefixToURI.get(prefix);
props.setProperty(escapePropertyKey(prefix), uri);
}
try {
props.store(os, null);
} finally {
// make sure stream is closed
os.close();
}
} catch (Exception e) {
String msg = "failed to persist namespace registry";
log.debug(msg);
throw new RepositoryException(msg, e);
}
FileSystemResource indexFile = new FileSystemResource(nsRegStore, NS_IDX_RESOURCE);
try {
indexFile.makeParentDirs();
OutputStream os = indexFile.getOutputStream();
Properties props = new Properties();
// store mappings in properties
for (String uri : uriToIndex.keySet()) {
String index = uriToIndex.get(uri).toString();
props.setProperty(escapePropertyKey(uri), index);
}
try {
props.store(os, null);
} finally {
// make sure stream is closed
os.close();
}
} catch (Exception e) {
String msg = "failed to persist namespace registry index.";
log.debug(msg);
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class NamespaceRegistryImpl method load.
private void load() throws RepositoryException {
FileSystemResource propFile = new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
FileSystemResource idxFile = new FileSystemResource(nsRegStore, NS_IDX_RESOURCE);
try {
if (!propFile.exists()) {
// clear existing mappings
clear();
// default namespace (if no prefix is specified)
map(Name.NS_EMPTY_PREFIX, Name.NS_DEFAULT_URI);
// declare the predefined mappings
// rep:
map(Name.NS_REP_PREFIX, Name.NS_REP_URI);
// jcr:
map(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
// nt:
map(Name.NS_NT_PREFIX, Name.NS_NT_URI);
// mix:
map(Name.NS_MIX_PREFIX, Name.NS_MIX_URI);
// sv:
map(Name.NS_SV_PREFIX, Name.NS_SV_URI);
// xml:
map(Name.NS_XML_PREFIX, Name.NS_XML_URI);
// persist mappings
store();
return;
}
// check if index file exists
Properties indexes = new Properties();
if (idxFile.exists()) {
InputStream in = idxFile.getInputStream();
try {
indexes.load(in);
} finally {
in.close();
}
}
InputStream in = propFile.getInputStream();
try {
Properties props = new Properties();
props.load(in);
// clear existing mappings
clear();
// read mappings from properties
for (Object p : props.keySet()) {
String prefix = (String) p;
String uri = props.getProperty(prefix);
String idx = indexes.getProperty(escapePropertyKey(uri));
// JCR-888: Backwards compatibility check
if (idx == null && uri.equals("")) {
idx = indexes.getProperty(uri);
}
if (idx != null) {
map(unescapePropertyKey(prefix), uri, Integer.decode(idx));
} else {
map(unescapePropertyKey(prefix), uri);
}
}
} finally {
in.close();
}
if (!idxFile.exists()) {
store();
}
} catch (Exception e) {
String msg = "failed to load namespace registry";
log.debug(msg);
throw new RepositoryException(msg, e);
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class SearchIndex method createSynonymProviderConfigResource.
/**
* Creates a file system resource to the synonym provider configuration.
*
* @return a file system resource or <code>null</code> if no path was
* configured.
* @throws FileSystemException if an exception occurs accessing the file
* system.
* @throws IOException if another exception occurs.
*/
protected FileSystemResource createSynonymProviderConfigResource() throws FileSystemException, IOException {
if (synonymProviderConfigPath != null) {
FileSystemResource fsr;
// simple sanity check
if (synonymProviderConfigPath.endsWith(FileSystem.SEPARATOR)) {
throw new FileSystemException("Invalid synonymProviderConfigPath: " + synonymProviderConfigPath);
}
if (fs == null) {
fs = new LocalFileSystem();
int lastSeparator = synonymProviderConfigPath.lastIndexOf(FileSystem.SEPARATOR_CHAR);
if (lastSeparator != -1) {
File root = new File(path, synonymProviderConfigPath.substring(0, lastSeparator));
((LocalFileSystem) fs).setRoot(root.getCanonicalFile());
fs.init();
fsr = new FileSystemResource(fs, synonymProviderConfigPath.substring(lastSeparator + 1));
} else {
((LocalFileSystem) fs).setPath(path);
fs.init();
fsr = new FileSystemResource(fs, synonymProviderConfigPath);
}
synonymProviderConfigFs = fs;
} else {
fsr = new FileSystemResource(fs, synonymProviderConfigPath);
}
return fsr;
} else {
// path not configured
return null;
}
}
use of org.apache.jackrabbit.core.fs.FileSystemResource in project jackrabbit by apache.
the class RetentionRegistryImplTest method createFileSystem.
private FileSystem createFileSystem() {
FileSystem fs = new MemoryFileSystem();
BufferedWriter writer = null;
try {
fs.createFolder("/");
FileSystemResource file = new FileSystemResource(fs, "/retention");
writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream()));
writer.write(((NodeImpl) childN).getNodeId().toString());
} catch (FileSystemException e) {
log.error(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
} finally {
IOUtils.closeQuietly(writer);
}
return fs;
}
Aggregations