Search in sources :

Example 41 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 42 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)

Example 43 with FileSystemException

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

the class XMLPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    // delete binary values (stored as files)
    InternalValue[] values = state.getValues();
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            InternalValue val = values[i];
            if (val != null) {
                val.deleteBinaryResource();
            }
        }
    }
    // delete property file
    String propFilePath = buildPropFilePath(state.getPropertyId());
    FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
    try {
        if (propFile.exists()) {
            // delete resource and prune empty parent folders
            propFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName();
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) InternalValue(org.apache.jackrabbit.core.value.InternalValue) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 44 with FileSystemException

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

the class XMLPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String propFilePath = buildPropFilePath(id);
    try {
        if (!itemStateFS.isFile(propFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(propFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            PropertyState state = createNew(id);
            readState(walker, state);
            return state;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to read property state: " + id.toString();
    log.debug(msg);
    throw new ItemStateException(msg, e);
}
Also used : DOMWalker(org.apache.jackrabbit.core.util.DOMWalker) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 45 with FileSystemException

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

the class XMLPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    NodeId id = state.getNodeId();
    String nodeFilePath = buildNodeFilePath(id);
    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: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NodeId(org.apache.jackrabbit.core.id.NodeId) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

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