Search in sources :

Example 51 with NamespaceException

use of javax.jcr.NamespaceException 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 52 with NamespaceException

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

the class LogUtil method saveGetIdString.

/**
     * Failsafe conversion of an <code>ItemId</code> to a human readable string
     * resolving the path part of the specified id using the given path resolver.
     *
     * @param itemId
     * @param pathResolver
     * @return a String representation of the given <code>ItemId</code>.
     */
public static String saveGetIdString(ItemId itemId, PathResolver pathResolver) {
    Path p = itemId.getPath();
    if (p == null || pathResolver == null) {
        return itemId.toString();
    } else {
        StringBuffer bf = new StringBuffer();
        String uniqueID = itemId.getUniqueID();
        if (uniqueID != null) {
            bf.append(uniqueID).append(" - ");
        }
        String jcrPath;
        try {
            jcrPath = pathResolver.getJCRPath(p);
        } catch (NamespaceException e) {
            jcrPath = p.toString();
        }
        bf.append(jcrPath);
        return bf.toString();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamespaceException(javax.jcr.NamespaceException)

Example 53 with NamespaceException

use of javax.jcr.NamespaceException 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 54 with NamespaceException

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

the class DocViewImportHandler method parseNames.

/**
     * Parses the given string as a list of JCR names. Any whitespace sequence
     * is supported as a names separator instead of just a single space to
     * be more liberal in what we accept. The current namespace context is
     * used to convert the prefixed name strings to Names.
     *
     * @param value string value
     * @return the parsed names
     * @throws SAXException if an invalid name was encountered
     */
private Name[] parseNames(String value) throws SAXException {
    String[] names = value.split("\\p{Space}+");
    Name[] qnames = new Name[names.length];
    for (int i = 0; i < names.length; i++) {
        try {
            qnames[i] = resolver.getQName(names[i]);
        } catch (NameException ne) {
            throw new SAXException("Invalid name: " + names[i], ne);
        } catch (NamespaceException e) {
            throw new SAXException("Invalid name: " + names[i], e);
        }
    }
    return qnames;
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException)

Example 55 with NamespaceException

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

the class ValueFactoryQImpl method createValue.

/**
     * {@inheritDoc}
     */
public Value createValue(String value, int type) throws ValueFormatException {
    try {
        QValue qvalue;
        if (type == PropertyType.NAME) {
            Name name = resolver.getQName(value);
            qvalue = qfactory.create(name);
        } else if (type == PropertyType.PATH) {
            Path path = resolver.getQPath(value, false);
            qvalue = qfactory.create(path);
        } else {
            qvalue = qfactory.create(value, type);
        }
        return new QValueValue(qvalue, resolver);
    } catch (IllegalNameException ex) {
        throw new ValueFormatException(ex);
    } catch (MalformedPathException ex) {
        throw new ValueFormatException(ex);
    } catch (NamespaceException ex) {
        throw new ValueFormatException(ex);
    } catch (ValueFormatException ex) {
        throw ex;
    } catch (RepositoryException ex) {
        throw new ValueFormatException(ex);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) QValue(org.apache.jackrabbit.spi.QValue) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) ValueFormatException(javax.jcr.ValueFormatException) NamespaceException(javax.jcr.NamespaceException) RepositoryException(javax.jcr.RepositoryException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NamespaceException (javax.jcr.NamespaceException)56 Name (org.apache.jackrabbit.spi.Name)26 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)17 Path (org.apache.jackrabbit.spi.Path)13 InvalidQueryException (javax.jcr.query.InvalidQueryException)10 RepositoryException (javax.jcr.RepositoryException)7 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)7 NamespaceRegistry (javax.jcr.NamespaceRegistry)6 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)6 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 IOException (java.io.IOException)5 Session (javax.jcr.Session)5 DerefQueryNode (org.apache.jackrabbit.spi.commons.query.DerefQueryNode)5 PropertyFunctionQueryNode (org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode)5 SAXException (org.xml.sax.SAXException)5 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)4 NodeTypeQueryNode (org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode)4 NotQueryNode (org.apache.jackrabbit.spi.commons.query.NotQueryNode)4 OrderQueryNode (org.apache.jackrabbit.spi.commons.query.OrderQueryNode)4 QueryNode (org.apache.jackrabbit.spi.commons.query.QueryNode)4