Search in sources :

Example 6 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder in project jackrabbit by apache.

the class CyclicNodeTypeRegistrationTest method testRegisterCyclicChildNodeTypesAndSupertypes.

/**
     * Basically a test of a Graffito use case.
     */
public void testRegisterCyclicChildNodeTypesAndSupertypes() {
    /**
         * Constructs node types with the following structure:
         * [Folder] > CmsObject
         * + folders (Folder)
         * + documents (Document)
         *
         * [CmsObject]
         * + parentFolder (Folder)
         *
         * [Document] > CmsObject
         * - size (long)
         *
         */
    final QNodeTypeDefinitionBuilder folder = new QNodeTypeDefinitionBuilder();
    folder.setName(nameFactory.create("", "Folder"));
    final QNodeTypeDefinitionBuilder cmsObject = new QNodeTypeDefinitionBuilder();
    cmsObject.setName(nameFactory.create("", "CmsObject"));
    cmsObject.setSupertypes(new Name[] { NameConstants.NT_BASE });
    QNodeDefinitionBuilder parentFolder = new QNodeDefinitionBuilder();
    parentFolder.setRequiredPrimaryTypes(new Name[] { folder.getName() });
    parentFolder.setName(nameFactory.create("", "parentFolder"));
    parentFolder.setDeclaringNodeType(cmsObject.getName());
    cmsObject.setChildNodeDefs(new QNodeDefinition[] { parentFolder.build() });
    final QNodeTypeDefinitionBuilder document = new QNodeTypeDefinitionBuilder();
    document.setName(nameFactory.create("", "Document"));
    document.setSupertypes(new Name[] { cmsObject.getName() });
    QPropertyDefinitionBuilder sizeProp = new QPropertyDefinitionBuilder();
    sizeProp.setName(nameFactory.create("", "size"));
    sizeProp.setRequiredType(PropertyType.LONG);
    sizeProp.setDeclaringNodeType(document.getName());
    document.setPropertyDefs(new QPropertyDefinition[] { sizeProp.build() });
    folder.setSupertypes(new Name[] { cmsObject.getName() });
    QNodeDefinitionBuilder folders = new QNodeDefinitionBuilder();
    folders.setRequiredPrimaryTypes(new Name[] { folder.getName() });
    folders.setName(nameFactory.create("", "folders"));
    folders.setDeclaringNodeType(folder.getName());
    QNodeDefinitionBuilder documents = new QNodeDefinitionBuilder();
    documents.setRequiredPrimaryTypes(new Name[] { document.getName() });
    documents.setName(nameFactory.create("", "documents"));
    documents.setDeclaringNodeType(folder.getName());
    folder.setChildNodeDefs(new QNodeDefinition[] { folders.build(), documents.build() });
    ntDefCollection = new LinkedList<QNodeTypeDefinition>();
    ntDefCollection.add(folder.build());
    ntDefCollection.add(document.build());
    ntDefCollection.add(cmsObject.build());
    try {
        ntreg.registerNodeTypes(ntDefCollection);
    } catch (InvalidNodeTypeDefException e) {
        assertFalse(e.getMessage(), true);
        e.printStackTrace();
    } catch (RepositoryException e) {
        assertFalse(e.getMessage(), true);
        e.printStackTrace();
    }
    boolean allNTsAreRegistered = ntreg.isRegistered(folder.getName()) && ntreg.isRegistered(document.getName()) && ntreg.isRegistered(cmsObject.getName());
    assertTrue(allNTsAreRegistered);
}
Also used : QNodeTypeDefinition(org.apache.jackrabbit.spi.QNodeTypeDefinition) QNodeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder) QPropertyDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder) RepositoryException(javax.jcr.RepositoryException) QNodeTypeDefinitionBuilder(org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)

Example 7 with QNodeDefinitionBuilder

use of org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder 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

QNodeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeDefinitionBuilder)7 RepositoryException (javax.jcr.RepositoryException)4 QNodeTypeDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder)4 Name (org.apache.jackrabbit.spi.Name)3 QNodeTypeDefinition (org.apache.jackrabbit.spi.QNodeTypeDefinition)3 ArrayList (java.util.ArrayList)2 QPropertyDefinitionBuilder (org.apache.jackrabbit.spi.commons.nodetype.QPropertyDefinitionBuilder)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)1 ElementIterator (org.apache.jackrabbit.webdav.xml.ElementIterator)1 Element (org.w3c.dom.Element)1