Search in sources :

Example 51 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class ObjectPersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(id);
    try {
        if (!itemStateFS.isFile(refsFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
    } catch (FileSystemException fse) {
        String msg = "failed to load references: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
    try {
        BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(refsFilePath));
        try {
            NodeReferences refs = new NodeReferences(id);
            Serializer.deserialize(refs, in);
            return refs;
        } finally {
            in.close();
        }
    } catch (Exception e) {
        String msg = "failed to load references: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) BufferedInputStream(java.io.BufferedInputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 52 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class ObjectPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
    FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
    try {
        if (refsFile.exists()) {
            // delete resource and prune empty parent folders
            refsFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete " + refs;
        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 53 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class PrivilegeRegistry method registerCustomDefinitions.

//---------------------------------------------< privilege registration >---
/**
     * Register the specified custom privilege definitions.
     * 
     * @param stubs
     * @throws RepositoryException If an error occurs.
     */
private void registerCustomDefinitions(Map<Name, PrivilegeDefinition> stubs) throws RepositoryException {
    if (customPrivilegesStore == null) {
        throw new UnsupportedOperationException("No privilege store defined.");
    }
    synchronized (registeredPrivileges) {
        Map<Name, Definition> definitions = createCustomDefinitions(stubs);
        try {
            // write the new custom privilege to the store and upon successful
            // update of the file system resource add finally it to the map of
            // registered privileges.
            customPrivilegesStore.append(definitions);
            cacheDefinitions(definitions);
        } catch (IOException e) {
            throw new RepositoryException("Failed to register custom privilegess.", e);
        } catch (FileSystemException e) {
            throw new RepositoryException("Failed to register custom privileges.", e);
        } catch (ParseException e) {
            throw new RepositoryException("Failed to register custom privileges.", e);
        }
    }
    for (Listener l : listeners.keySet()) {
        l.privilegesRegistered(stubs.keySet());
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) PrivilegeEventListener(org.apache.jackrabbit.core.cluster.PrivilegeEventListener) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ParseException(org.apache.jackrabbit.spi.commons.privilege.ParseException) Name(org.apache.jackrabbit.spi.Name)

Example 54 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class LockManagerImpl method save.

/**
     * Write locks to locks file
     */
private void save() {
    if (savingDisabled) {
        return;
    }
    final ArrayList<LockInfo> list = new ArrayList<LockInfo>();
    lockMap.traverse(new PathMap.ElementVisitor<LockInfo>() {

        public void elementVisited(PathMap.Element<LockInfo> element) {
            LockInfo info = element.get();
            if (!info.isSessionScoped()) {
                list.add(info);
            }
        }
    }, false);
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(locksFile.getOutputStream()));
        for (LockInfo info : list) {
            writer.write(info.getLockToken());
            // Store the timeout hint, if one is specified
            if (info.getTimeoutHint() != Long.MAX_VALUE) {
                writer.write(',');
                writer.write(Long.toString(info.getTimeoutHint()));
            }
            writer.newLine();
        }
    } catch (FileSystemException fse) {
        log.warn("I/O error while saving locks to '" + locksFile.getPath() + "': " + fse.getMessage());
        log.debug("Root cause: ", fse);
    } catch (IOException ioe) {
        log.warn("I/O error while saving locks to '" + locksFile.getPath() + "': " + ioe.getMessage());
        log.debug("Root cause: ", ioe);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) BufferedWriter(java.io.BufferedWriter)

Aggregations

FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)54 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)18 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)16 IOException (java.io.IOException)15 SQLException (java.sql.SQLException)15 File (java.io.File)11 ResultSet (java.sql.ResultSet)10 InputStream (java.io.InputStream)7 RepositoryException (javax.jcr.RepositoryException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 OutputStreamWriter (java.io.OutputStreamWriter)4 ArrayList (java.util.ArrayList)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 BufferedInputStream (java.io.BufferedInputStream)3 BufferedWriter (java.io.BufferedWriter)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Properties (java.util.Properties)3 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2