Search in sources :

Example 61 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 62 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)

Example 63 with NameException

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

the class IdFactoryImpl method createPropertyId.

/**
     * Creates a <code>PropertyId</code> for the given <code>property</code>.
     *
     * @param property   the JCR Property.
     * @param resolver
     * @return the <code>PropertyId</code> for <code>property</code>.
     * @throws RepositoryException if an error occurs while reading from
     *                             <code>property</code>.
     */
public PropertyId createPropertyId(Property property, NamePathResolver resolver) throws RepositoryException {
    Node parent = property.getParent();
    NodeId nodeId = createNodeId(parent);
    String jcrName = property.getName();
    Name name;
    try {
        name = resolver.getQName(jcrName);
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
    return createPropertyId(nodeId, name);
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) NodeId(org.apache.jackrabbit.spi.NodeId) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name)

Example 64 with NameException

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

the class RepositoryServiceImpl method getNodeInfo.

/**
     * {@inheritDoc}
     */
public NodeInfo getNodeInfo(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException, RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    Node node = getNode(nodeId, sInfo);
    try {
        return new NodeInfoImpl(node, idFactory, sInfo.getNamePathResolver());
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 65 with NameException

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

the class RepositoryServiceImpl method getQNodeTypeDefinitions.

/**
     * {@inheritDoc}
     */
public Iterator<QNodeTypeDefinition> getQNodeTypeDefinitions(SessionInfo sessionInfo, Name[] nodetypeNames) throws RepositoryException {
    SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
    NodeTypeManager ntMgr = sInfo.getSession().getWorkspace().getNodeTypeManager();
    List<QNodeTypeDefinition> defs = new ArrayList<QNodeTypeDefinition>();
    for (Name nodetypeName : nodetypeNames) {
        try {
            String ntName = sInfo.getNamePathResolver().getJCRName(nodetypeName);
            NodeType nt = ntMgr.getNodeType(ntName);
            defs.add(new QNodeTypeDefinitionImpl(nt, sInfo.getNamePathResolver(), getQValueFactory()));
            // in addition pack all supertypes into the return value
            NodeType[] supertypes = nt.getSupertypes();
            for (NodeType supertype : supertypes) {
                defs.add(new QNodeTypeDefinitionImpl(supertype, sInfo.getNamePathResolver(), getQValueFactory()));
            }
        } catch (NameException e) {
            throw new RepositoryException(e);
        }
    }
    return defs.iterator();
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) QNodeTypeDefinitionImpl(org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)

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