javax.jcr.nodetype.NodeTypeManager Java Examples

The following examples show how to use javax.jcr.nodetype.NodeTypeManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void registerNodeTypes() throws Exception {
    LOG.info("Register node types");
    Session session = getSession();
    final String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes();
    boolean createNamespace = true;
    for (String jcrNamespace : jcrNamespaces) {
        if (jcrNamespace.equals("mycollab")) {
            createNamespace = false;
            LOG.debug("Jackrabbit OCM namespace exists.");
        }
    }
    if (createNamespace) {
        session.getWorkspace().getNamespaceRegistry()
                .registerNamespace("mycollab", "http://www.esofthead.com/mycollab");
        LOG.debug("Successfully created Mycollab content namespace.");
    }
    if (session.getRootNode() == null) {
        throw new ContentException("Jcr session setup not successful.");
    }

    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    manager.registerNodeType(createMyCollabContentType(manager), true);
    manager.registerNodeType(createMyCollabFolderType(manager), true);
    session.logout();
}
 
Example #2
Source File: PageSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void registerNodeTypes() throws Exception {
    LOG.info("Register node types");
    Session session = getSession();
    final String[] jcrNamespaces = session.getWorkspace().getNamespaceRegistry().getPrefixes();
    boolean createNamespace = true;
    for (String jcrNamespace : jcrNamespaces) {
        if (jcrNamespace.equals("wiki")) {
            createNamespace = false;
            LOG.debug("Jackrabbit OCM namespace exists.");
        }
    }
    if (createNamespace) {
        session.getWorkspace().getNamespaceRegistry().registerNamespace("wiki", "http://www.esofthead.com/wiki");
        LOG.debug("Successfully created MyCollab content namespace.");
    }
    if (session.getRootNode() == null) {
        throw new ContentException("Jcr session setup not successful.");
    }

    NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
    manager.registerNodeType(createWikiPageType(manager), true);
    manager.registerNodeType(createWikiFolderType(manager), true);
    session.logout();
}
 
Example #3
Source File: AbstractExporter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private InputStream getNodeTypes(Session s, Collection<String> nodeTypes)
        throws IOException, RepositoryException {
    NodeTypeManager ntMgr = s.getWorkspace().getNodeTypeManager();
    // init with repository predefined node types
    Set<String> written = new HashSet<String>();
    written.addAll(ServiceProviderFactory.getProvider().getBuiltInNodeTypeNames());
    StringWriter out = new StringWriter();
    CNDWriter w = ServiceProviderFactory.getProvider().getCNDWriter(out, s, true);
    for (String nt: nodeTypes) {
        writeNodeType(ntMgr.getNodeType(nt), w, written);
    }
    w.close();
    return new ByteArrayInputStream(out.getBuffer().toString().getBytes("utf-8"));
}
 
Example #4
Source File: ContentSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private NodeTypeTemplate createMyCollabFolderType(NodeTypeManager manager) throws RepositoryException {
    // Create content node type
    NodeTypeTemplate contentTypeTemplate = manager.createNodeTypeTemplate();

    contentTypeTemplate.setAbstract(false);
    contentTypeTemplate.setMixin(false);
    contentTypeTemplate.setName("mycollab:folder");
    contentTypeTemplate.setPrimaryItemName("folder");
    contentTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_FOLDER});
    contentTypeTemplate.setQueryable(true);
    contentTypeTemplate.setOrderableChildNodes(false);

    PropertyDefinitionTemplate createdPropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    createdPropertyTemplate.setMultiple(false);
    createdPropertyTemplate.setName("mycollab:createdUser");
    createdPropertyTemplate.setMandatory(true);
    createdPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(createdPropertyTemplate);

    PropertyDefinitionTemplate descPropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    descPropertyTemplate.setMultiple(false);
    descPropertyTemplate.setName("jcr:description");
    descPropertyTemplate.setMandatory(false);
    descPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(descPropertyTemplate);

    return contentTypeTemplate;
}
 
Example #5
Source File: PageSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private NodeTypeTemplate createWikiFolderType(NodeTypeManager manager) throws RepositoryException {
    // Create content node type
    NodeTypeTemplate folderTypeTemplate = manager.createNodeTypeTemplate();

    folderTypeTemplate.setAbstract(false);
    folderTypeTemplate.setMixin(false);
    folderTypeTemplate.setName("wiki:folder");
    folderTypeTemplate.setPrimaryItemName("folder");
    folderTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_FOLDER});
    folderTypeTemplate.setQueryable(true);
    folderTypeTemplate.setOrderableChildNodes(false);

    PropertyDefinitionTemplate createdPropertyTemplate = manager.createPropertyDefinitionTemplate();
    createdPropertyTemplate.setMultiple(false);
    createdPropertyTemplate.setName("wiki:createdUser");
    createdPropertyTemplate.setMandatory(true);
    createdPropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(createdPropertyTemplate);

    PropertyDefinitionTemplate namePropertyTemplate = manager.createPropertyDefinitionTemplate();
    namePropertyTemplate.setMultiple(false);
    namePropertyTemplate.setName("wiki:name");
    namePropertyTemplate.setMandatory(true);
    namePropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(namePropertyTemplate);

    PropertyDefinitionTemplate descPropertyTemplate = manager.createPropertyDefinitionTemplate();
    descPropertyTemplate.setMultiple(false);
    descPropertyTemplate.setName("wiki:description");
    descPropertyTemplate.setMandatory(true);
    descPropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(descPropertyTemplate);
    return folderTypeTemplate;
}
 
Example #6
Source File: JcrRepositoryStatisticsGatheringTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String type )
    throws RepositoryException
{
    NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
    nodeType.setMixin( true );
    nodeType.setName( type );
    nodeTypeManager.registerNodeType( nodeType, false );
}
 
Example #7
Source File: WorkspaceWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@Override
public NodeTypeManager getNodeTypeManager() throws RepositoryException {
    return new NodeTypeManagerWrapper(delegate.getNodeTypeManager());
}
 
Example #8
Source File: NodeTypeManagerWrapper.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
public NodeTypeManagerWrapper(NodeTypeManager nodeTypeManager) {
    this.nodeTypeManager = nodeTypeManager;
}
 
Example #9
Source File: WorkspaceImpl.java    From jackalope with Apache License 2.0 4 votes vote down vote up
@Override
public NodeTypeManager getNodeTypeManager() throws RepositoryException {
    return null;
}
 
Example #10
Source File: ContentSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
private NodeTypeTemplate createMyCollabContentType(NodeTypeManager manager) throws RepositoryException {
    LOG.info("Register mycollab content type");
    NodeType hierachyNode = manager.getNodeType(NodeType.NT_HIERARCHY_NODE);
    // Create content node type
    NodeTypeTemplate contentTypeTemplate = manager.createNodeTypeTemplate(hierachyNode);

    contentTypeTemplate.setAbstract(false);
    contentTypeTemplate.setMixin(false);
    contentTypeTemplate.setName("mycollab:content");
    contentTypeTemplate.setPrimaryItemName("content");
    contentTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_HIERARCHY_NODE});
    contentTypeTemplate.setQueryable(true);
    contentTypeTemplate.setOrderableChildNodes(false);

    PropertyDefinitionTemplate createdUserPropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    createdUserPropertyTemplate.setMultiple(false);
    createdUserPropertyTemplate.setName("mycollab:createdUser");
    createdUserPropertyTemplate.setMandatory(true);
    createdUserPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(createdUserPropertyTemplate);

    PropertyDefinitionTemplate contentPathPropertyTemplate = manager.createPropertyDefinitionTemplate();
    contentPathPropertyTemplate.setMultiple(false);
    contentPathPropertyTemplate.setName("mycollab:contentPath");
    contentPathPropertyTemplate.setMandatory(false);
    contentPathPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(contentPathPropertyTemplate);

    PropertyDefinitionTemplate thumbnailPathPropertyTemplate = manager.createPropertyDefinitionTemplate();
    thumbnailPathPropertyTemplate.setMultiple(false);
    thumbnailPathPropertyTemplate.setName("mycollab:thumbnailPath");
    thumbnailPathPropertyTemplate.setMandatory(false);
    thumbnailPathPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(thumbnailPathPropertyTemplate);

    PropertyDefinitionTemplate lastModifiedUserPropertyTemplate = manager.createPropertyDefinitionTemplate();
    lastModifiedUserPropertyTemplate.setMultiple(false);
    lastModifiedUserPropertyTemplate.setName("mycollab:lastModifiedUser");
    lastModifiedUserPropertyTemplate.setMandatory(true);
    lastModifiedUserPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(lastModifiedUserPropertyTemplate);

    PropertyDefinitionTemplate mimeTypePropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    mimeTypePropertyTemplate.setMultiple(false);
    mimeTypePropertyTemplate.setName("mycollab:mimeType");
    mimeTypePropertyTemplate.setMandatory(false);
    mimeTypePropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(mimeTypePropertyTemplate);

    PropertyDefinitionTemplate sizePropertyTemplate = manager.createPropertyDefinitionTemplate();
    sizePropertyTemplate.setMultiple(false);
    sizePropertyTemplate.setName("mycollab:size");
    sizePropertyTemplate.setMandatory(true);
    sizePropertyTemplate.setRequiredType(PropertyType.LONG);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(sizePropertyTemplate);

    return contentTypeTemplate;
}
 
Example #11
Source File: PageSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
private NodeTypeTemplate createWikiPageType(NodeTypeManager manager) throws RepositoryException {
    LOG.info("Register MyCollab content type");
    NodeType hierachyNode = manager.getNodeType(NodeType.NT_HIERARCHY_NODE);
    // Create content node type
    NodeTypeTemplate pageTypeTemplate = manager.createNodeTypeTemplate(hierachyNode);

    pageTypeTemplate.setAbstract(false);
    pageTypeTemplate.setMixin(false);
    pageTypeTemplate.setName("wiki:page");
    pageTypeTemplate.setPrimaryItemName("page");
    pageTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_HIERARCHY_NODE});
    pageTypeTemplate.setQueryable(true);
    pageTypeTemplate.setOrderableChildNodes(false);
    LOG.debug("PROPERTY {} {}",
            pageTypeTemplate.getDeclaredPropertyDefinitions().length,
            pageTypeTemplate.getDeclaredChildNodeDefinitions().length);

    PropertyDefinitionTemplate subjectPropertyTemplate = manager.createPropertyDefinitionTemplate();
    subjectPropertyTemplate.setMultiple(false);
    subjectPropertyTemplate.setName("wiki:subject");
    subjectPropertyTemplate.setMandatory(true);
    subjectPropertyTemplate.setRequiredType(PropertyType.STRING);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(subjectPropertyTemplate);

    PropertyDefinitionTemplate contentPropertyTemplate = manager.createPropertyDefinitionTemplate();
    contentPropertyTemplate.setMultiple(false);
    contentPropertyTemplate.setName("wiki:content");
    contentPropertyTemplate.setMandatory(true);
    contentPropertyTemplate.setRequiredType(PropertyType.STRING);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(contentPropertyTemplate);

    PropertyDefinitionTemplate lockPropertyTemplate = manager.createPropertyDefinitionTemplate();
    lockPropertyTemplate.setMultiple(false);
    lockPropertyTemplate.setName("wiki:isLock");
    lockPropertyTemplate.setMandatory(false);
    lockPropertyTemplate.setRequiredType(PropertyType.BOOLEAN);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(lockPropertyTemplate);

    PropertyDefinitionTemplate statusPropertyTemplate = manager.createPropertyDefinitionTemplate();
    statusPropertyTemplate.setMultiple(false);
    statusPropertyTemplate.setName("wiki:status");
    statusPropertyTemplate.setMandatory(true);
    statusPropertyTemplate.setRequiredType(PropertyType.STRING);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(statusPropertyTemplate);

    PropertyDefinitionTemplate categoryPropertyTemplate = manager.createPropertyDefinitionTemplate();
    categoryPropertyTemplate.setMultiple(false);
    categoryPropertyTemplate.setName("wiki:category");
    categoryPropertyTemplate.setMandatory(false);
    categoryPropertyTemplate.setRequiredType(PropertyType.STRING);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(categoryPropertyTemplate);

    PropertyDefinitionTemplate createdPropertyTemplate = manager.createPropertyDefinitionTemplate();
    createdPropertyTemplate.setMultiple(false);
    createdPropertyTemplate.setName("wiki:createdUser");
    createdPropertyTemplate.setMandatory(true);
    createdPropertyTemplate.setRequiredType(PropertyType.STRING);
    pageTypeTemplate.getPropertyDefinitionTemplates().add(createdPropertyTemplate);

    return pageTypeTemplate;
}