Search in sources :

Example 26 with FileSystemResource

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

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

the class InMemBundlePersistenceManager method loadContents.

/**
     * Reads the content of the hash maps from the file system
     *
     * @throws Exception if an error occurs
     */
public synchronized void loadContents() throws Exception {
    // read item states
    FileSystemResource fsRes = new FileSystemResource(wspFS, BUNDLE_FILE_PATH);
    if (!fsRes.exists()) {
        return;
    }
    BufferedInputStream bis = new BufferedInputStream(fsRes.getInputStream());
    DataInputStream in = new DataInputStream(bis);
    try {
        // number of entries
        int n = in.readInt();
        while (n-- > 0) {
            // id
            String s = in.readUTF();
            NodeId id = NodeId.valueOf(s);
            // data length
            int length = in.readInt();
            byte[] data = new byte[length];
            // data
            in.readFully(data);
            // store in map
            bundleStore.put(id, data);
        }
    } finally {
        in.close();
    }
    // read references
    fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
    bis = new BufferedInputStream(fsRes.getInputStream());
    in = new DataInputStream(bis);
    try {
        // number of entries
        int n = in.readInt();
        while (n-- > 0) {
            // target id
            String s = in.readUTF();
            NodeId id = NodeId.valueOf(s);
            // data length
            int length = in.readInt();
            byte[] data = new byte[length];
            // data
            in.readFully(data);
            // store in map
            refsStore.put(id, data);
        }
    } finally {
        in.close();
    }
    if (!useFileBlobStore) {
        // read blobs
        fsRes = new FileSystemResource(wspFS, BLOBS_FILE_PATH);
        bis = new BufferedInputStream(fsRes.getInputStream());
        in = new DataInputStream(bis);
        try {
            // number of entries
            int n = in.readInt();
            while (n-- > 0) {
                // id
                String id = in.readUTF();
                // data length
                int length = in.readInt();
                byte[] data = new byte[length];
                // data
                in.readFully(data);
                // store in map
                blobs.put(id, data);
            }
        } finally {
            in.close();
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) NodeId(org.apache.jackrabbit.core.id.NodeId) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) DataInputStream(java.io.DataInputStream)

Example 28 with FileSystemResource

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

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

the class XMLPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(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 {
        nodeFile.makeParentDirs();
        OutputStream os = nodeFile.getOutputStream();
        Writer writer = null;
        try {
            String encoding = DEFAULT_ENCODING;
            try {
                writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
            } catch (UnsupportedEncodingException e) {
                // should never get here!
                OutputStreamWriter osw = new OutputStreamWriter(os);
                encoding = osw.getEncoding();
                writer = new BufferedWriter(osw);
            }
            String parentId = (state.getParentId() == null) ? "" : state.getParentId().toString();
            String encodedNodeType = Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString());
            writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
            writer.write("<" + NODE_ELEMENT + " " + UUID_ATTRIBUTE + "=\"" + id + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + parentId + "\" " + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" " + NODETYPE_ATTRIBUTE + "=\"" + encodedNodeType + "\">\n");
            // mixin types
            writer.write("\t<" + MIXINTYPES_ELEMENT + ">\n");
            for (Name mixin : state.getMixinTypeNames()) {
                writer.write("\t\t<" + MIXINTYPE_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(mixin.toString()) + "\"/>\n");
            }
            writer.write("\t</" + MIXINTYPES_ELEMENT + ">\n");
            // properties
            writer.write("\t<" + PROPERTIES_ELEMENT + ">\n");
            for (Name propName : state.getPropertyNames()) {
                writer.write("\t\t<" + PROPERTY_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(propName.toString()) + "\">\n");
                // @todo serialize type, definition id and values
                writer.write("\t\t</" + PROPERTY_ELEMENT + ">\n");
            }
            writer.write("\t</" + PROPERTIES_ELEMENT + ">\n");
            // child nodes
            writer.write("\t<" + NODES_ELEMENT + ">\n");
            for (ChildNodeEntry entry : state.getChildNodeEntries()) {
                writer.write("\t\t<" + NODE_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(entry.getName().toString()) + "\" " + UUID_ATTRIBUTE + "=\"" + entry.getId() + "\">\n");
                writer.write("\t\t</" + NODE_ELEMENT + ">\n");
            }
            writer.write("\t</" + NODES_ELEMENT + ">\n");
            writer.write("</" + NODE_ELEMENT + ">\n");
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        String msg = "failed to write node state: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : OutputStream(java.io.OutputStream) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) 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) BufferedWriter(java.io.BufferedWriter) Name(org.apache.jackrabbit.spi.Name) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer)

Example 30 with FileSystemResource

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

the class XMLPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
    FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
    try {
        refsFile.makeParentDirs();
        OutputStream os = refsFile.getOutputStream();
        BufferedWriter writer = null;
        try {
            String encoding = DEFAULT_ENCODING;
            try {
                writer = new BufferedWriter(new OutputStreamWriter(os, encoding));
            } catch (UnsupportedEncodingException e) {
                // should never get here!
                OutputStreamWriter osw = new OutputStreamWriter(os);
                encoding = osw.getEncoding();
                writer = new BufferedWriter(osw);
            }
            writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
            writer.write("<" + NODEREFERENCES_ELEMENT + " " + TARGETID_ATTRIBUTE + "=\"" + refs.getTargetId() + "\">\n");
            // write references (i.e. the id's of the REFERENCE properties)
            for (PropertyId propId : refs.getReferences()) {
                writer.write("\t<" + NODEREFERENCE_ELEMENT + " " + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
            }
            writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        String msg = "failed to store " + refs;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) 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) BufferedWriter(java.io.BufferedWriter) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

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