Search in sources :

Example 86 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class BufferedStringValue method getInternalValue.

public InternalValue getInternalValue(int type) throws ValueFormatException, RepositoryException {
    try {
        if (type == PropertyType.BINARY) {
            // decode using Reader
            if (length() < 0x10000) {
                // < 65kb: deserialize BINARY type in memory
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Base64.decode(retrieve(), baos);
                //baos.close();
                return InternalValue.create(baos.toByteArray());
            } else {
                // >= 65kb: deserialize BINARY type
                // using Reader and temporary file
                Base64ReaderInputStream in = new Base64ReaderInputStream(reader());
                return InternalValue.createTemporary(in);
            }
        } else {
            // current namespace context of xml document
            return InternalValue.create(ValueHelper.convert(retrieveString(), type, valueFactory), nsContext);
        }
    } catch (IOException e) {
        throw new RepositoryException("Error accessing property value", e);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 87 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class ClonedInputSource method read.

private static char[] read(Reader reader) throws RepositoryException {
    if (reader != null) {
        try {
            final int bufferSize = 4096;
            CharArrayWriter w = new CharArrayWriter(bufferSize);
            char[] buffer = new char[bufferSize];
            while (true) {
                int numRead = reader.read(buffer);
                if (numRead > 0) {
                    w.write(buffer, 0, numRead);
                }
                if (numRead != bufferSize) {
                    break;
                }
            }
            return w.toCharArray();
        } catch (IOException e) {
            throw new RepositoryException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException ignore) {
            }
        }
    } else {
        return null;
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter)

Example 88 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DocViewImportHandler method startElement.

//-------------------------------------------------------< ContentHandler >
/**
     * {@inheritDoc}
     * <p>
     * See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
     * regarding special handling of multi-valued properties on export.
     */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    // process buffered character data
    processCharacters();
    try {
        Name nodeName = NameFactoryImpl.getInstance().create(namespaceURI, localName);
        // process node name
        nodeName = processName(nodeName);
        // properties
        NodeId id = null;
        Name nodeTypeName = null;
        Name[] mixinTypes = null;
        List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
        for (int i = 0; i < atts.getLength(); i++) {
            if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
                // see http://issues.apache.org/jira/browse/JCR-620#action_12448164
                continue;
            }
            Name propName = NameFactoryImpl.getInstance().create(atts.getURI(i), atts.getLocalName(i));
            // process property name
            propName = processName(propName);
            // value(s)
            String attrValue = atts.getValue(i);
            TextValue[] propValues;
            // always assume single-valued property for the time being
            // until a way of properly serializing/detecting multi-valued
            // properties on re-import is found (see JCR-325);
            // see also DocViewSAXEventGenerator#leavingProperties(Node, int)
            // todo proper multi-value serialization support
            propValues = new TextValue[1];
            propValues[0] = new StringValue(attrValue, resolver, valueFactory);
            if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
                // jcr:primaryType
                if (attrValue.length() > 0) {
                    try {
                        nodeTypeName = resolver.getQName(attrValue);
                    } catch (NameException ne) {
                        throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
                    }
                }
            } else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
                // jcr:mixinTypes
                mixinTypes = parseNames(attrValue);
            } else if (propName.equals(NameConstants.JCR_UUID)) {
                // jcr:uuid
                if (attrValue.length() > 0) {
                    id = NodeId.valueOf(attrValue);
                }
            } else {
                props.add(new PropInfo(propName, PropertyType.UNDEFINED, propValues));
            }
        }
        NodeInfo node = new NodeInfo(nodeName, nodeTypeName, mixinTypes, id);
        // all information has been collected, now delegate to importer
        importer.startNode(node, props);
        // push current node data onto stack
        stack.push(node);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 89 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class DocViewImportHandler method processCharacters.

/**
     * Translates character data reported by the
     * <code>{@link #characters(char[], int, int)}</code> &
     * <code>{@link #ignorableWhitespace(char[], int, int)}</code> SAX events
     * into a  <code>jcr:xmltext</code> child node with one
     * <code>jcr:xmlcharacters</code> property.
     *
     * @throws SAXException if an error occurs
     * @see #appendCharacters(char[], int, int)
     */
private void processCharacters() throws SAXException {
    try {
        if (textHandler != null && textHandler.length() > 0) {
            // there is character data that needs to be added to
            // the current node
            // check for pure whitespace character data
            Reader reader = textHandler.reader();
            try {
                int ch;
                while ((ch = reader.read()) != -1) {
                    if (ch > 0x20) {
                        break;
                    }
                }
                if (ch == -1) {
                    // the character data consists of pure whitespace, ignore
                    log.debug("ignoring pure whitespace character data...");
                    // reset handler
                    textHandler.dispose();
                    textHandler = null;
                    return;
                }
            } finally {
                reader.close();
            }
            NodeInfo node = new NodeInfo(NameConstants.JCR_XMLTEXT, null, null, null);
            TextValue[] values = new TextValue[] { textHandler };
            ArrayList<PropInfo> props = new ArrayList<PropInfo>();
            props.add(new PropInfo(NameConstants.JCR_XMLCHARACTERS, PropertyType.STRING, values));
            // call Importer
            importer.startNode(node, props);
            importer.endNode(node);
            // reset handler
            textHandler.dispose();
            textHandler = null;
        }
    } catch (IOException ioe) {
        String msg = "internal error while processing internal buffer data";
        log.error(msg, ioe);
        throw new SAXException(msg, ioe);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : ArrayList(java.util.ArrayList) Reader(java.io.Reader) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 90 with RepositoryException

use of javax.jcr.RepositoryException in project jackrabbit by apache.

the class WorkspaceInitTest method testIdleTime.

public void testIdleTime() throws Exception {
    // simply access the workspace, which will cause
    // initialization of SlowQueryHandler.
    List threads = new ArrayList();
    for (int i = 0; i < 10; i++) {
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    getHelper().getSuperuserSession("wsp-init-test").logout();
                } catch (RepositoryException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();
        threads.add(t);
    }
    for (Iterator it = threads.iterator(); it.hasNext(); ) {
        ((Thread) it.next()).join();
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException)

Aggregations

RepositoryException (javax.jcr.RepositoryException)1236 Node (javax.jcr.Node)289 Session (javax.jcr.Session)182 IOException (java.io.IOException)156 ArrayList (java.util.ArrayList)106 Name (org.apache.jackrabbit.spi.Name)94 DavException (org.apache.jackrabbit.webdav.DavException)90 Test (org.junit.Test)87 Value (javax.jcr.Value)80 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)76 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)72 Path (org.apache.jackrabbit.spi.Path)67 ItemNotFoundException (javax.jcr.ItemNotFoundException)65 PathNotFoundException (javax.jcr.PathNotFoundException)65 NodeId (org.apache.jackrabbit.core.id.NodeId)64 Property (javax.jcr.Property)61 HashMap (java.util.HashMap)53 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)53 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)52 InvalidItemStateException (javax.jcr.InvalidItemStateException)50