Search in sources :

Example 36 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class PropertyValueOperand method getPropertyState.

/**
     * Returns the property state for the given score node or <code>null</code>
     * if none exists.
     *
     * @param sn the current score node.
     * @param context the evaluation context.
     * @return the property state or <code>null</code>.
     * @throws RepositoryException if an error occurs while reading.
     */
public final PropertyState getPropertyState(ScoreNode sn, EvaluationContext context) throws RepositoryException {
    ItemStateManager ism = context.getItemStateManager();
    PropertyId propId = new PropertyId(sn.getNodeId(), operand.getPropertyQName());
    try {
        return (PropertyState) ism.getItemState(propId);
    } catch (NoSuchItemStateException e) {
        return null;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 37 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class XMLPersistenceManager method exists.

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

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class XMLPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String propFilePath = buildPropFilePath(state.getPropertyId());
    FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
    try {
        propFile.makeParentDirs();
        OutputStream os = propFile.getOutputStream();
        // write property state to xml file
        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 typeName;
            int type = state.getType();
            try {
                typeName = PropertyType.nameFromValue(type);
            } catch (IllegalArgumentException iae) {
                // should never be getting here
                throw new ItemStateException("unexpected property-type ordinal: " + type, iae);
            }
            writer.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n");
            writer.write("<" + PROPERTY_ELEMENT + " " + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" " + PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" " + MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" " + MODCOUNT_ATTRIBUTE + "=\"" + state.getModCount() + "\" " + TYPE_ATTRIBUTE + "=\"" + typeName + "\">\n");
            // values
            writer.write("\t<" + VALUES_ELEMENT + ">\n");
            InternalValue[] values = state.getValues();
            if (values != null) {
                for (int i = 0; i < values.length; i++) {
                    writer.write("\t\t<" + VALUE_ELEMENT + ">");
                    InternalValue val = values[i];
                    if (val != null) {
                        if (type == PropertyType.BINARY) {
                            // special handling required for binary value:
                            // put binary value in BLOB store
                            InputStream in = val.getStream();
                            String blobId = blobStore.createId(state.getPropertyId(), i);
                            try {
                                blobStore.put(blobId, in, val.getLength());
                            } finally {
                                IOUtils.closeQuietly(in);
                            }
                            // store id of BLOB as property value
                            writer.write(blobId);
                            // in BLOB store and discard old value instance (e.g. temp file)
                            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(blobId);
                                values[i] = InternalValue.create(fsRes);
                            } else {
                                in = blobStore.get(blobId);
                                try {
                                    values[i] = InternalValue.create(in);
                                } finally {
                                    try {
                                        in.close();
                                    } catch (IOException e) {
                                    // ignore
                                    }
                                }
                            }
                            val.discard();
                        } else {
                            writer.write(Text.encodeIllegalXMLCharacters(val.toString()));
                        }
                    }
                    writer.write("</" + VALUE_ELEMENT + ">\n");
                }
            }
            writer.write("\t</" + VALUES_ELEMENT + ">\n");
            writer.write("</" + PROPERTY_ELEMENT + ">\n");
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        String msg = "failed to store property state: " + state.getParentId() + "/" + state.getName();
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) IOException(java.io.IOException) 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) BufferedWriter(java.io.BufferedWriter) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ResourceBasedBLOBStore(org.apache.jackrabbit.core.persistence.util.ResourceBasedBLOBStore) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer)

Example 39 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class XMLPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String nodeFilePath = buildNodeFilePath(id);
    try {
        if (!itemStateFS.isFile(nodeFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(nodeFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            String ntName = walker.getAttribute(NODETYPE_ATTRIBUTE);
            NodeState state = createNew(id);
            state.setNodeTypeName(factory.create(ntName));
            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 node state: " + id;
    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) NodeState(org.apache.jackrabbit.core.state.NodeState) 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) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 40 with ItemStateException

use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.

the class XMLPersistenceManager 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)

Aggregations

ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)141 RepositoryException (javax.jcr.RepositoryException)87 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)86 NodeId (org.apache.jackrabbit.core.id.NodeId)44 NodeState (org.apache.jackrabbit.core.state.NodeState)39 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)31 IOException (java.io.IOException)28 InvalidItemStateException (javax.jcr.InvalidItemStateException)27 PropertyState (org.apache.jackrabbit.core.state.PropertyState)24 SQLException (java.sql.SQLException)23 PropertyId (org.apache.jackrabbit.core.id.PropertyId)22 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)19 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)19 Name (org.apache.jackrabbit.spi.Name)17 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 InternalValue (org.apache.jackrabbit.core.value.InternalValue)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)13 InputStream (java.io.InputStream)12