Search in sources :

Example 51 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException 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 52 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException 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 53 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class DefinitionUtil method buildQItemDefinition.

/**
     * 
     * @param declaringNodeType
     * @param itemDefElement
     * @param resolver
     * @param builder
     * @throws RepositoryException
     */
private static void buildQItemDefinition(Name declaringNodeType, Element itemDefElement, NamePathResolver resolver, QItemDefinitionBuilder builder) throws RepositoryException {
    try {
        String attr = itemDefElement.getAttribute(DECLARINGNODETYPE_ATTRIBUTE);
        if (attr != null) {
            Name dnt = resolver.getQName(attr);
            if (declaringNodeType != null && !declaringNodeType.equals(dnt)) {
                throw new RepositoryException("Declaring nodetype mismatch: In element = '" + dnt + "', Declaring nodetype = '" + declaringNodeType + "'");
            }
            builder.setDeclaringNodeType(dnt);
        } else {
            builder.setDeclaringNodeType(declaringNodeType);
        }
        if (itemDefElement.hasAttribute(NAME_ATTRIBUTE)) {
            String nAttr = itemDefElement.getAttribute(NAME_ATTRIBUTE);
            if (nAttr.length() > 0) {
                builder.setName((isAnyName(nAttr)) ? NameConstants.ANY_NAME : resolver.getQName(nAttr));
            } else {
                builder.setName(NameConstants.ROOT);
            }
        } else {
            // TODO: check if correct..
            builder.setName(NameConstants.ANY_NAME);
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    if (itemDefElement.hasAttribute(AUTOCREATED_ATTRIBUTE)) {
        builder.setAutoCreated(Boolean.valueOf(itemDefElement.getAttribute(AUTOCREATED_ATTRIBUTE)));
    }
    if (itemDefElement.hasAttribute(MANDATORY_ATTRIBUTE)) {
        builder.setMandatory(Boolean.valueOf(itemDefElement.getAttribute(MANDATORY_ATTRIBUTE)));
    }
    if (itemDefElement.hasAttribute(PROTECTED_ATTRIBUTE)) {
        builder.setProtected(Boolean.valueOf(itemDefElement.getAttribute(PROTECTED_ATTRIBUTE)));
    }
    if (itemDefElement.hasAttribute(ONPARENTVERSION_ATTRIBUTE)) {
        builder.setOnParentVersion(OnParentVersionAction.valueFromName(itemDefElement.getAttribute(ONPARENTVERSION_ATTRIBUTE)));
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 54 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class DefinitionUtil method createQNodeTypeDefinition.

static QNodeTypeDefinition createQNodeTypeDefinition(Element ntdElement, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException {
    QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
    // NOTE: the server should send the namespace-mappings as addition ns-defininitions
    try {
        if (ntdElement.hasAttribute(NAME_ATTRIBUTE)) {
            builder.setName(resolver.getQName(ntdElement.getAttribute(NAME_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(PRIMARYITEMNAME_ATTRIBUTE)) {
            builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute(PRIMARYITEMNAME_ATTRIBUTE)));
        }
        Element child = DomUtil.getChildElement(ntdElement, SUPERTYPES_ELEMENT, null);
        if (child != null) {
            ElementIterator stIter = DomUtil.getChildren(child, SUPERTYPE_ELEMENT, null);
            List<Name> qNames = new ArrayList<Name>();
            while (stIter.hasNext()) {
                Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
                qNames.add(st);
            }
            builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
        }
        if (ntdElement.hasAttribute(ISMIXIN_ATTRIBUTE)) {
            builder.setMixin(Boolean.valueOf(ntdElement.getAttribute(ISMIXIN_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)) {
            builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute(HASORDERABLECHILDNODES_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISABSTRACT_ATTRIBUTE)) {
            builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute(ISABSTRACT_ATTRIBUTE)));
        }
        if (ntdElement.hasAttribute(ISQUERYABLE_ATTRIBUTE)) {
            builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute(ISQUERYABLE_ATTRIBUTE)));
        }
        // nodeDefinitions
        ElementIterator it = DomUtil.getChildren(ntdElement, CHILDNODEDEFINITION_ELEMENT, null);
        List<QNodeDefinition> nds = new ArrayList<QNodeDefinition>();
        while (it.hasNext()) {
            nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
        }
        builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
        // propertyDefinitions
        it = DomUtil.getChildren(ntdElement, PROPERTYDEFINITION_ELEMENT, null);
        List<QPropertyDefinition> pds = new ArrayList<QPropertyDefinition>();
        while (it.hasNext()) {
            pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolver, qValueFactory));
        }
        builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
    } catch (NameException e) {
        log.error(e.getMessage());
        throw new RepositoryException(e);
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Element(org.w3c.dom.Element) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) QNodeDefinition(org.apache.jackrabbit.spi.QNodeDefinition) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder) Name(org.apache.jackrabbit.spi.Name)

Example 55 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class DefinitionUtil method createQNodeDefinition.

/**
     * 
     * @param declaringNodeType
     * @param ndefElement
     * @param resolver
     * @return
     * @throws RepositoryException
     */
static QNodeDefinition createQNodeDefinition(Name declaringNodeType, Element ndefElement, NamePathResolver resolver) throws RepositoryException {
    QNodeDefinitionBuilder builder = new QNodeDefinitionBuilder();
    buildQItemDefinition(declaringNodeType, ndefElement, resolver, builder);
    // NOTE: the server should send the namespace-mappings as addition ns-defininitions
    try {
        if (ndefElement.hasAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE)) {
            Name defaultPrimaryType = resolver.getQName(ndefElement.getAttribute(DEFAULTPRIMARYTYPE_ATTRIBUTE));
            builder.setDefaultPrimaryType(defaultPrimaryType);
        }
        Element reqPrimaryTypes = DomUtil.getChildElement(ndefElement, REQUIREDPRIMARYTYPES_ELEMENT, null);
        if (reqPrimaryTypes != null) {
            ElementIterator it = DomUtil.getChildren(reqPrimaryTypes, REQUIREDPRIMARYTYPE_ELEMENT, null);
            while (it.hasNext()) {
                builder.addRequiredPrimaryType(resolver.getQName(DomUtil.getTextTrim(it.nextElement())));
            }
        } else {
            builder.addRequiredPrimaryType(NameConstants.NT_BASE);
        }
        if (ndefElement.hasAttribute(SAMENAMESIBLINGS_ATTRIBUTE)) {
            builder.setAllowsSameNameSiblings(Boolean.valueOf(ndefElement.getAttribute(SAMENAMESIBLINGS_ATTRIBUTE)));
        }
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
    return builder.build();
}
Also used : ElementIterator(org.apache.jackrabbit.webdav.xml.ElementIterator) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Element(org.w3c.dom.Element) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)65 RepositoryException (javax.jcr.RepositoryException)44 Name (org.apache.jackrabbit.spi.Name)38 Path (org.apache.jackrabbit.spi.Path)20 NamespaceException (javax.jcr.NamespaceException)17 ArrayList (java.util.ArrayList)16 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)9 SAXException (org.xml.sax.SAXException)8 Node (javax.jcr.Node)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 InvalidQueryException (javax.jcr.query.InvalidQueryException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 IOException (java.io.IOException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 Value (javax.jcr.Value)5 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)5 AccessDeniedException (javax.jcr.AccessDeniedException)4 NodeType (javax.jcr.nodetype.NodeType)4 VersionException (javax.jcr.version.VersionException)4