Search in sources :

Example 11 with InvalidSerializedDataException

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

the class SysViewImportHandler method endElement.

/**
     * {@inheritDoc}
     */
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    // check element name
    ImportState state = stack.peek();
    if (NODE.equals(localName)) {
        // sv:node element
        if (!state.started) {
            // need to start & end current node
            processNode(state, true, true);
            state.started = true;
        } else {
            // need to end current node
            processNode(state, false, true);
        }
        // pop current state from stack
        stack.pop();
    } else if (PROPERTY.equals(localName)) {
        // have been collected and create node as necessary
        if (currentPropName.equals(NameConstants.JCR_PRIMARYTYPE)) {
            AppendableValue val = (AppendableValue) currentPropValues.get(0);
            String s = null;
            try {
                s = val.retrieve();
                state.nodeTypeName = resolver.getQName(s);
            } catch (IOException ioe) {
                throw new SAXException("error while retrieving value", ioe);
            } catch (NameException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            } catch (NamespaceException e) {
                throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
            }
        } else if (currentPropName.equals(NameConstants.JCR_MIXINTYPES)) {
            if (state.mixinNames == null) {
                state.mixinNames = new ArrayList<Name>(currentPropValues.size());
            }
            for (int i = 0; i < currentPropValues.size(); i++) {
                AppendableValue val = (AppendableValue) currentPropValues.get(i);
                String s = null;
                try {
                    s = val.retrieve();
                    Name mixin = resolver.getQName(s);
                    state.mixinNames.add(mixin);
                } catch (IOException ioe) {
                    throw new SAXException("error while retrieving value", ioe);
                } catch (NameException e) {
                    throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
                } catch (NamespaceException e) {
                    throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
                }
            }
        } else if (currentPropName.equals(NameConstants.JCR_UUID)) {
            AppendableValue val = (AppendableValue) currentPropValues.get(0);
            try {
                state.uuid = val.retrieve();
            } catch (IOException ioe) {
                throw new SAXException("error while retrieving value", ioe);
            }
        } else {
            Importer.TextValue[] values = currentPropValues.toArray(new Importer.TextValue[currentPropValues.size()]);
            Importer.PropInfo prop = new Importer.PropInfo(currentPropName, currentPropType, values);
            state.props.add(prop);
        }
        // reset temp fields
        currentPropValues.clear();
    } else if (VALUE.equals(localName)) {
        // sv:value element
        currentPropValues.add(currentPropValue);
        // reset temp fields
        currentPropValue = null;
    } else {
        throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
    }
}
Also used : InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Name(org.apache.jackrabbit.spi.Name) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NamespaceException(javax.jcr.NamespaceException)

Example 12 with InvalidSerializedDataException

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

the class SysViewImportHandler method startElement.

//-------------------------------------------------------< ContentHandler >
/**
     * {@inheritDoc}
     */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    // check namespace
    if (!Name.NS_SV_URI.equals(namespaceURI)) {
        throw new SAXException(new InvalidSerializedDataException("invalid namespace for element in system view xml document: " + namespaceURI));
    }
    // check element name
    if (NODE.equals(localName)) {
        // sv:node element
        // node name (value of sv:name attribute)
        String name = atts.getValue(Name.NS_SV_URI, NAME);
        if (name == null) {
            throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:node"));
        }
        if (!stack.isEmpty()) {
            // process current node first
            ImportState current = stack.peek();
            // need to start current node
            if (!current.started) {
                processNode(current, true, false);
                current.started = true;
            }
        }
        // push new ImportState instance onto the stack
        ImportState state = new ImportState();
        try {
            state.nodeName = resolver.getQName(name);
        } catch (NameException e) {
            throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
        } catch (NamespaceException e) {
            throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
        }
        stack.push(state);
    } else if (PROPERTY.equals(localName)) {
        // sv:property element
        // reset temp fields
        currentPropValues.clear();
        // property name (value of sv:name attribute)
        String name = atts.getValue(Name.NS_SV_URI, NAME);
        if (name == null) {
            throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:property"));
        }
        try {
            currentPropName = resolver.getQName(name);
        } catch (NameException e) {
            throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
        } catch (NamespaceException e) {
            throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
        }
        // property type (sv:type attribute)
        String type = atts.getValue(Name.NS_SV_URI, TYPE);
        if (type == null) {
            throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:type attribute of element sv:property"));
        }
        currentPropType = PropertyType.valueFromName(type);
    } else if (VALUE.equals(localName)) {
        // sv:value element
        // reset temp fields
        currentPropValue = new BufferedStringValue();
    } else {
        throw new SAXException(new InvalidSerializedDataException("unexpected element found in system view xml document: " + localName));
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) NamespaceException(javax.jcr.NamespaceException) SAXException(org.xml.sax.SAXException)

Example 13 with InvalidSerializedDataException

use of javax.jcr.InvalidSerializedDataException in project jackrabbit-oak by apache.

the class SessionImpl method importXML.

@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, RepositoryException {
    try {
        ContentHandler handler = getImportContentHandler(checkNotNull(parentAbsPath), uuidBehavior);
        new ParsingContentHandler(handler).parse(in);
    } catch (SAXException e) {
        Throwable exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new InvalidSerializedDataException("XML parse error", e);
        }
    } finally {
        // JCR-2903
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignore) {
            }
        }
    }
}
Also used : ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ContentHandler(org.xml.sax.ContentHandler) ParsingContentHandler(org.apache.jackrabbit.commons.xml.ParsingContentHandler) ToXmlContentHandler(org.apache.jackrabbit.commons.xml.ToXmlContentHandler) SAXException(org.xml.sax.SAXException)

Example 14 with InvalidSerializedDataException

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

the class SerializationTest method doTestNodeTypeConstraintViolation.

// ------------------< Node type constraint violation tests >--------------------------------
/**
     * Create a node named ntBase with node type nt:base
     * and creates a tree in the repository which will be exported
     * and reimported below the node ntBase.
     *
     * @param useWorkspace
     * @param useHandler
     * @throws RepositoryException
     * @throws FileNotFoundException
     * @throws IOException
     */
public void doTestNodeTypeConstraintViolation(boolean useWorkspace, boolean useHandler) throws Exception {
    treeComparator.createExampleTree();
    String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
    Node node = testRootNode.addNode("ntBase", nodetype);
    session.save();
    FileInputStream in = new FileInputStream(file);
    try {
        if (useHandler) {
            try {
                doImport(node.getPath(), in, useWorkspace, useHandler);
                fail("Node type constraint violation should throw a SAXException " + "during xml import using a Contenthandler.");
            } catch (SAXException se) {
            // ok
            }
        } else {
            try {
                doImport(node.getPath(), in, useWorkspace, useHandler);
                fail("Node type constraint violation should throw a  " + " InvalidSerializedDataException during xml import " + "using a Contenthandler.");
            } catch (InvalidSerializedDataException isde) {
            // ok
            }
        }
    } finally {
        try {
            in.close();
        } catch (IOException ignore) {
        }
    }
}
Also used : Node(javax.jcr.Node) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Aggregations

InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)14 SAXException (org.xml.sax.SAXException)12 IOException (java.io.IOException)10 RepositoryException (javax.jcr.RepositoryException)8 NamespaceException (javax.jcr.NamespaceException)5 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)5 ParsingContentHandler (org.apache.jackrabbit.commons.xml.ParsingContentHandler)4 ContentHandler (org.xml.sax.ContentHandler)4 Name (org.apache.jackrabbit.spi.Name)3 Node (javax.jcr.Node)2 ToXmlContentHandler (org.apache.jackrabbit.commons.xml.ToXmlContentHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 AccessControlException (java.security.AccessControlException)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 InvalidItemStateException (javax.jcr.InvalidItemStateException)1 ItemExistsException (javax.jcr.ItemExistsException)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 LoginException (javax.jcr.LoginException)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1