Search in sources :

Example 11 with FileSystemResource

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);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 12 with FileSystemResource

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);
    }
}
Also used : OutputStream(java.io.OutputStream) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) Properties(java.util.Properties) NamespaceException(javax.jcr.NamespaceException) AccessDeniedException(javax.jcr.AccessDeniedException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException)

Example 13 with FileSystemResource

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);
    }
}
Also used : InputStream(java.io.InputStream) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) Properties(java.util.Properties) NamespaceException(javax.jcr.NamespaceException) AccessDeniedException(javax.jcr.AccessDeniedException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException)

Example 14 with FileSystemResource

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;
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) LocalFileSystem(org.apache.jackrabbit.core.fs.local.LocalFileSystem) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) File(java.io.File)

Example 15 with FileSystemResource

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;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) MemoryFileSystem(org.apache.jackrabbit.core.fs.mem.MemoryFileSystem) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Aggregations

FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)37 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)23 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)19 OutputStream (java.io.OutputStream)9 IOException (java.io.IOException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 RepositoryException (javax.jcr.RepositoryException)7 NodeId (org.apache.jackrabbit.core.id.NodeId)7 InputStream (java.io.InputStream)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)6 BufferedOutputStream (java.io.BufferedOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 BufferedWriter (java.io.BufferedWriter)4 DataInputStream (java.io.DataInputStream)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 DataOutputStream (java.io.DataOutputStream)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3