Search in sources :

Example 31 with FileSystemResource

use of org.apache.jackrabbit.core.fs.FileSystemResource 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)

Example 32 with FileSystemResource

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

the class XMLPersistenceManager method readState.

private void readState(DOMWalker walker, PropertyState state) throws ItemStateException {
    // first do some paranoid sanity checks
    if (!walker.getName().equals(PROPERTY_ELEMENT)) {
        String msg = "invalid serialization format (unexpected element: " + walker.getName() + ")";
        log.debug(msg);
        throw new ItemStateException(msg);
    }
    // check name
    if (!state.getName().equals(factory.create(walker.getAttribute(NAME_ATTRIBUTE)))) {
        String msg = "invalid serialized state: name mismatch";
        log.debug(msg);
        throw new ItemStateException(msg);
    }
    // check parentUUID
    NodeId parentId = NodeId.valueOf(walker.getAttribute(PARENTUUID_ATTRIBUTE));
    if (!parentId.equals(state.getParentId())) {
        String msg = "invalid serialized state: parentUUID mismatch";
        log.debug(msg);
        throw new ItemStateException(msg);
    }
    // now we're ready to read state
    // type
    String typeName = walker.getAttribute(TYPE_ATTRIBUTE);
    int type;
    try {
        type = PropertyType.valueFromName(typeName);
    } catch (IllegalArgumentException iae) {
        // should never be getting here
        throw new ItemStateException("unexpected property-type: " + typeName, iae);
    }
    state.setType(type);
    // multiValued
    String multiValued = walker.getAttribute(MULTIVALUED_ATTRIBUTE);
    state.setMultiValued(Boolean.parseBoolean(multiValued));
    // modification count
    String modCount = walker.getAttribute(MODCOUNT_ATTRIBUTE);
    state.setModCount(Short.parseShort(modCount));
    // values
    ArrayList<InternalValue> values = new ArrayList<InternalValue>();
    if (walker.enterElement(VALUES_ELEMENT)) {
        while (walker.iterateElements(VALUE_ELEMENT)) {
            // read serialized value
            String content = walker.getContent();
            if (PropertyType.STRING == type) {
                // STRING value can be empty; ignore length
                values.add(InternalValue.valueOf(content, type));
            } else if (content.length() > 0) {
                // non-empty non-STRING value
                if (type == PropertyType.BINARY) {
                    try {
                        // in the BLOB store
                        if (blobStore instanceof ResourceBasedBLOBStore) {
                            // optimization: if the BLOB store is resource-based
                            // retrieve the resource directly rather than having
                            // to read the BLOB from an input stream
                            FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(content);
                            values.add(InternalValue.create(fsRes));
                        } else {
                            InputStream in = blobStore.get(content);
                            try {
                                values.add(InternalValue.create(in));
                            } finally {
                                IOUtils.closeQuietly(in);
                            }
                        }
                    } catch (Exception e) {
                        String msg = "error while reading serialized binary value";
                        log.debug(msg);
                        throw new ItemStateException(msg, e);
                    }
                } else {
                    // non-empty non-STRING non-BINARY value
                    values.add(InternalValue.valueOf(content, type));
                }
            } else {
                // empty non-STRING value
                log.warn(state.getPropertyId() + ": ignoring empty value of type " + PropertyType.nameFromValue(type));
            }
        }
        walker.leaveElement();
    }
    state.setValues((InternalValue[]) values.toArray(new InternalValue[values.size()]));
}
Also used : ResourceBasedBLOBStore(org.apache.jackrabbit.core.persistence.util.ResourceBasedBLOBStore) InputStream(java.io.InputStream) NodeId(org.apache.jackrabbit.core.id.NodeId) ArrayList(java.util.ArrayList) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) InternalValue(org.apache.jackrabbit.core.value.InternalValue) 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) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 33 with FileSystemResource

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

the class XMLPersistenceManager method existsReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized boolean existsReferencesTo(NodeId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String refsFilePath = buildNodeReferencesFilePath(id);
        FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
        return refsFile.exists();
    } catch (FileSystemException fse) {
        String msg = "failed to check existence of references: " + id;
        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 34 with FileSystemResource

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

the class MultiDataStore method init.

/**
     * {@inheritDoc}
     */
public void init(String homeDir) throws RepositoryException {
    if (delayedDelete) {
        // First initialize the identifiersToDeleteFile
        LocalFileSystem fileSystem = new LocalFileSystem();
        fileSystem.setRoot(new File(homeDir));
        identifiersToDeleteFile = new FileSystemResource(fileSystem, FileSystem.SEPARATOR + IDENTIFIERS_TO_DELETE_FILE_KEY);
    }
    moveDataTaskThread = new Thread(new MoveDataTask(), "Jackrabbit-MulitDataStore-MoveDataTaskThread");
    moveDataTaskThread.setDaemon(true);
    moveDataTaskThread.start();
    log.info("MultiDataStore-MoveDataTask thread started; first run scheduled at " + moveDataTaskNextRun.getTime());
    if (delayedDelete) {
        try {
            // delayedDeleteSleep timeout ...
            if (identifiersToDeleteFile != null && identifiersToDeleteFile.exists() && (identifiersToDeleteFile.lastModified() + (delayedDeleteSleep * 1000)) < System.currentTimeMillis()) {
                deleteDelayedIdentifiersTaskThread = new Thread(//Start immediately ...
                new DeleteDelayedIdentifiersTask(0L), "Jackrabbit-MultiDataStore-DeleteDelayedIdentifiersTaskThread");
                deleteDelayedIdentifiersTaskThread.setDaemon(true);
                deleteDelayedIdentifiersTaskThread.start();
                log.info("Old entries in the " + IDENTIFIERS_TO_DELETE_FILE_KEY + " File found. DeleteDelayedIdentifiersTask-Thread started now.");
            }
        } catch (FileSystemException e) {
            throw new RepositoryException("I/O error while reading from '" + identifiersToDeleteFile.getPath() + "'", e);
        }
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) LocalFileSystem(org.apache.jackrabbit.core.fs.local.LocalFileSystem) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) File(java.io.File)

Example 35 with FileSystemResource

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

the class RepositoryImpl method loadRootNodeId.

/**
     * Returns the root node identifier. The identifier is loaded from
     * the <code>meta/rootUUID</code> file within the repository file system.
     * If such a file does not yet exist, the hardcoded default root node
     * identifier ({@link #ROOT_NODE_ID}) is used and written to that file.
     * <p>
     * This utility method should only be used by the constructor after the
     * repository file system has been initialised.
     *
     * @return root node identifier
     * @throws RepositoryException if the identifier can not be loaded or saved
     */
private NodeId loadRootNodeId() throws RepositoryException {
    try {
        FileSystemResource uuidFile = new FileSystemResource(context.getFileSystem(), "/meta/rootUUID");
        if (uuidFile.exists()) {
            // Load uuid of the repository's root node. It is stored in
            // text format (36 characters) for better readability.
            InputStream in = uuidFile.getInputStream();
            try {
                return NodeId.valueOf(IOUtils.toString(in, "US-ASCII"));
            } finally {
                IOUtils.closeQuietly(in);
            }
        } else {
            // Use hard-coded uuid for root node rather than generating
            // a different uuid per repository instance; using a
            // hard-coded uuid makes it easier to copy/move entire
            // workspaces from one repository instance to another.
            uuidFile.makeParentDirs();
            OutputStream out = uuidFile.getOutputStream();
            try {
                out.write(ROOT_NODE_ID.toString().getBytes("US-ASCII"));
                return ROOT_NODE_ID;
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    } catch (IOException e) {
        throw new RepositoryException("Failed to load or persist the root node identifier", e);
    } catch (FileSystemException fse) {
        throw new RepositoryException("Failed to access the root node identifier", fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) IOException(java.io.IOException)

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