Search in sources :

Example 6 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class NodeTypeManagerImpl method getPrimaryNodeTypes.

/**
     * {@inheritDoc}
     */
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
    Name[] ntNames = ntReg.getRegisteredNodeTypes();
    ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
    for (Name ntName : ntNames) {
        NodeType nt = getNodeType(ntName);
        if (!nt.isMixin()) {
            list.add(nt);
        }
    }
    return new NodeTypeIteratorAdapter(list);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) Name(org.apache.jackrabbit.spi.Name)

Example 7 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class NodeTypesReport method getNodeTypes.

/**
     * Parse the Xml element in the info object an return an interator over
     * the specified node types.
     *
     * @return
     * @throws RepositoryException
     * @throws DavException
     */
private static NodeTypeIterator getNodeTypes(Session session, ReportInfo info) throws RepositoryException, DavException {
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    // check the simple types first...
    if (info.containsContentElement(XML_REPORT_ALLNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getAllNodeTypes();
    } else if (info.containsContentElement(XML_REPORT_MIXINNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getMixinNodeTypes();
    } else if (info.containsContentElement(XML_REPORT_PRIMARYNODETYPES, ItemResourceConstants.NAMESPACE)) {
        return ntMgr.getPrimaryNodeTypes();
    } else {
        // None of the simple types. test if a report for individual
        // nodetype was request. If not, the request body is not valid.
        List<Element> elemList = info.getContentElements(XML_NODETYPE, ItemResourceConstants.NAMESPACE);
        if (elemList.isEmpty()) {
            // throw exception if the request body does not contain a single nodetype element
            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "NodeTypes report: request body has invalid format.");
        }
        // todo: find better solution...
        List<NodeType> ntList = new ArrayList<NodeType>();
        for (Element el : elemList) {
            String nodetypeName = DomUtil.getChildTextTrim(el, XML_NODETYPENAME, ItemResourceConstants.NAMESPACE);
            if (nodetypeName != null) {
                ntList.add(ntMgr.getNodeType(nodetypeName));
            }
        }
        return new NodeTypeIteratorAdapter(ntList);
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) DavException(org.apache.jackrabbit.webdav.DavException) JcrDavException(org.apache.jackrabbit.webdav.jcr.JcrDavException) Element(org.w3c.dom.Element) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)

Example 8 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class NodeTypeManagerImpl method registerNodeTypes.

//--------------------------------------------------< new JSR 283 methods >
/**
     * Registers or updates the specified <code>Collection</code> of
     * <code>NodeTypeDefinition</code> objects. This method is used to register
     * or update a set of node types with mutual dependencies. Returns an
     * iterator over the resulting <code>NodeType</code> objects.
     * <p>
     * The effect of the method is "all or nothing"; if an error occurs, no node
     * types are registered or updated.
     * <p>
     * Throws an <code>InvalidNodeTypeDefinitionException</code> if a
     * <code>NodeTypeDefinition</code> within the <code>Collection</code> is
     * invalid or if the <code>Collection</code> contains an object of a type
     * other than <code>NodeTypeDefinition</code>.
     * <p>
     * Throws a <code>NodeTypeExistsException</code> if <code>allowUpdate</code>
     * is <code>false</code> and a <code>NodeTypeDefinition</code> within the
     * <code>Collection</code> specifies a node type name that is already
     * registered.
     * <p>
     * Throws an <code>UnsupportedRepositoryOperationException</code> if this
     * implementation does not support node type registration.
     *
     * @param definitions a collection of <code>NodeTypeDefinition</code>s
     * @param allowUpdate a boolean
     * @return the registered node types.
     * @throws InvalidNodeTypeDefinitionException if a
     *  <code>NodeTypeDefinition</code> within the <code>Collection</code> is
     *  invalid or if the <code>Collection</code> contains an object of a type
     *  other than <code>NodeTypeDefinition</code>.
     * @throws NodeTypeExistsException if <code>allowUpdate</code> is
     *  <code>false</code> and a <code>NodeTypeDefinition</code> within the
     *  <code>Collection</code> specifies a node type name that is already
     *  registered.
     * @throws UnsupportedRepositoryOperationException if this implementation
     *  does not support node type registration.
     * @throws RepositoryException if another error occurs.
     * @since JCR 2.0
     */
public NodeTypeIterator registerNodeTypes(NodeTypeDefinition[] definitions, boolean allowUpdate) throws InvalidNodeTypeDefinitionException, NodeTypeExistsException, UnsupportedRepositoryOperationException, RepositoryException {
    // make sure the editing session is allowed to register node types.
    context.getAccessManager().checkRepositoryPermission(Permission.NODE_TYPE_DEF_MNGMT);
    NodeTypeRegistry registry = context.getNodeTypeRegistry();
    // split the node types into new and already registered node types.
    // this way we can register new node types together with already
    // registered node types which make circular dependencies possible
    List<QNodeTypeDefinition> addedDefs = new ArrayList<QNodeTypeDefinition>();
    List<QNodeTypeDefinition> modifiedDefs = new ArrayList<QNodeTypeDefinition>();
    for (NodeTypeDefinition definition : definitions) {
        // convert to QNodeTypeDefinition
        QNodeTypeDefinition def = toNodeTypeDef(definition);
        if (registry.isRegistered(def.getName())) {
            if (allowUpdate) {
                modifiedDefs.add(def);
            } else {
                throw new NodeTypeExistsException(definition.getName());
            }
        } else {
            addedDefs.add(def);
        }
    }
    try {
        ArrayList<NodeType> result = new ArrayList<NodeType>();
        // register new node types
        result.addAll(registerNodeTypes(addedDefs));
        // re-register already existing node types
        for (QNodeTypeDefinition nodeTypeDef : modifiedDefs) {
            registry.reregisterNodeType(nodeTypeDef);
            result.add(getNodeType(nodeTypeDef.getName()));
        }
        return new NodeTypeIteratorAdapter(result);
    } catch (InvalidNodeTypeDefException e) {
        throw new InvalidNodeTypeDefinitionException(e.getMessage(), e);
    }
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)

Example 9 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class NodeTypeManagerImpl method getPrimaryNodeTypes.

/**
     * {@inheritDoc}
     */
public NodeTypeIterator getPrimaryNodeTypes() throws RepositoryException {
    Name[] ntNames = context.getNodeTypeRegistry().getRegisteredNodeTypes();
    Arrays.sort(ntNames);
    ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
    for (Name ntName : ntNames) {
        NodeType nt = getNodeType(ntName);
        if (!nt.isMixin()) {
            list.add(nt);
        }
    }
    return new NodeTypeIteratorAdapter(list);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) Name(org.apache.jackrabbit.spi.Name)

Example 10 with NodeTypeIteratorAdapter

use of org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter in project jackrabbit by apache.

the class NodeTypeManagerImpl method getAllNodeTypes.

//------------------------------------------------------< NodeTypeManager >
/**
     * {@inheritDoc}
     */
public NodeTypeIterator getAllNodeTypes() throws RepositoryException {
    Name[] ntNames = context.getNodeTypeRegistry().getRegisteredNodeTypes();
    Arrays.sort(ntNames);
    ArrayList<NodeType> list = new ArrayList<NodeType>(ntNames.length);
    for (Name ntName : ntNames) {
        list.add(getNodeType(ntName));
    }
    return new NodeTypeIteratorAdapter(list);
}
Also used : NodeType(javax.jcr.nodetype.NodeType) ArrayList(java.util.ArrayList) NodeTypeIteratorAdapter(org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeType (javax.jcr.nodetype.NodeType)16 NodeTypeIteratorAdapter (org.apache.jackrabbit.commons.iterator.NodeTypeIteratorAdapter)16 ArrayList (java.util.ArrayList)11 Name (org.apache.jackrabbit.spi.Name)6 Tree (org.apache.jackrabbit.oak.api.Tree)4 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)3 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)3 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)2 Set (java.util.Set)1 RepositoryException (javax.jcr.RepositoryException)1 InvalidNodeTypeDefinitionException (javax.jcr.nodetype.InvalidNodeTypeDefinitionException)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)1 Root (org.apache.jackrabbit.oak.api.Root)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 QNodeTypeDefinitionImpl (org.apache.jackrabbit.spi.commons.QNodeTypeDefinitionImpl)1 DavException (org.apache.jackrabbit.webdav.DavException)1 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)1