本文整理汇总了Java中javax.jcr.nodetype.NodeTypeManager类的典型用法代码示例。如果您正苦于以下问题:Java NodeTypeManager类的具体用法?Java NodeTypeManager怎么用?Java NodeTypeManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NodeTypeManager类属于javax.jcr.nodetype包,在下文中一共展示了NodeTypeManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerNodeTypes
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@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();
}
示例2: propertyDescriptors
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see org.modelspace.Descriptor#propertyDescriptors()
*/
@Override
public PropertyDescriptor[] propertyDescriptors() throws ModelspaceException {
return this.modelspace.run( new TaskWithResult< PropertyDescriptor[] >() {
/**
* {@inheritDoc}
*
* @see org.modelspace.internal.task.TaskWithResult#run(javax.jcr.Session)
*/
@Override
public PropertyDescriptor[] run( final Session session ) throws Exception {
final NodeTypeManager nodeTypeMgr = session.getWorkspace().getNodeTypeManager();
final PropertyDefinition[] propDefns = nodeTypeMgr.getNodeType( name ).getPropertyDefinitions();
final PropertyDescriptor[] propDescriptors = new PropertyDescriptor[ propDefns.length ];
int i = 0;
for ( final PropertyDefinition propDefn : propDefns ) {
propDescriptors[ i++ ] = new PropertyDescriptorImpl( propDefn );
}
return propDescriptors;
}
} );
}
示例3: getSessionMock
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Session getSessionMock() throws RepositoryException {
final String[] mockPrefixes = {MOCK_PREFIX};
final Session mockSession = mock(Session.class);
final Workspace mockWorkspace = mock(Workspace.class);
final NamespaceRegistry mockNameReg = mock(NamespaceRegistry.class);
final NodeTypeManager mockNTM = mock(NodeTypeManager.class);
final NodeTypeIterator mockNTI = mock(NodeTypeIterator.class);
final NodeType mockNodeType = mock(NodeType.class);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(mockNameReg);
when(mockNameReg.getPrefixes()).thenReturn(mockPrefixes);
when(mockNameReg.getURI(MOCK_PREFIX)).thenReturn(MOCK_URI_STRING);
when(mockWorkspace.getNodeTypeManager()).thenReturn(mockNTM);
when(mockNodeType.getName()).thenReturn("mockName");
when(mockNodeType.toString()).thenReturn("mockString");
when(mockNTM.getAllNodeTypes()).thenReturn(mockNTI);
when(mockNTI.hasNext()).thenReturn(true, false);
when(mockNTI.nextNodeType()).thenReturn(mockNodeType).thenThrow(
ArrayIndexOutOfBoundsException.class);
return mockSession;
}
示例4: SessionJcrTypeResolver
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
public SessionJcrTypeResolver(ResourceResolver resolver) {
NodeTypeManager m = null;
try {
if (resolver != null) {
m = resolver.adaptTo(Session.class).getWorkspace().getNodeTypeManager();
}
} catch (RepositoryException e) {
LOG.error("Can't get node type manager", e);
m = null;
}
nodeTypeManager = m;
}
示例5: initialize
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
static void initialize( Session session )
throws RepositoryException
{
// TODO: consider using namespaces for facets instead of the current approach:
// (if used, check if actually called by normal injection)
// for ( String facetId : metadataFacetFactories.keySet() )
// {
// session.getWorkspace().getNamespaceRegistry().registerNamespace( facetId, facetId );
// }
Workspace workspace = session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
if ( !Arrays.asList( registry.getPrefixes() ).contains( "archiva" ) )
{
registry.registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
}
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.NAMESPACE_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.PROJECT_VERSION_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.ARTIFACT_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.FACET_NODE_TYPE );
registerMixinNodeType( nodeTypeManager, JcrMetadataRepository.DEPENDENCY_NODE_TYPE );
}
示例6: registerMixinNodeType
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String name )
throws RepositoryException
{
NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
nodeType.setMixin( true );
nodeType.setName( name );
// for now just don't re-create - but in future if we change the definition, make sure to remove first as an
// upgrade path
if ( !nodeTypeManager.hasNodeType( name ) )
{
nodeTypeManager.registerNodeType( nodeType, false );
}
}
示例7: setUp
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@Override
@Before
public void setUp()
throws Exception
{
super.setUp();
File confFile = new File( "src/test/repository.xml" );
File dir = new File( "target/jcr" );
FileUtils.deleteDirectory( dir );
assertTrue( confFile.exists() );
assertFalse( dir.exists() );
TransientRepository repository = new TransientRepository( confFile, dir );
session = repository.login( new SimpleCredentials( "username", "password".toCharArray() ) );
// TODO: perhaps have an archiva-jcr-utils module shared by these plugins that does this and can contain
// structure information
Workspace workspace = session.getWorkspace();
NamespaceRegistry registry = workspace.getNamespaceRegistry();
registry.registerNamespace( "archiva", "http://archiva.apache.org/jcr/" );
NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
registerMixinNodeType( nodeTypeManager, "archiva:namespace" );
registerMixinNodeType( nodeTypeManager, "archiva:project" );
registerMixinNodeType( nodeTypeManager, "archiva:projectVersion" );
registerMixinNodeType( nodeTypeManager, "archiva:artifact" );
registerMixinNodeType( nodeTypeManager, "archiva:facet" );
metadataRepository = mock( MetadataRepository.class );
when( metadataRepository.canObtainAccess( Session.class ) ).thenReturn( true );
when( metadataRepository.obtainAccess( Session.class ) ).thenReturn( session );
repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
}
示例8: registerMixinNodeType
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
private static void registerMixinNodeType( NodeTypeManager nodeTypeManager, String type )
throws RepositoryException
{
NodeTypeTemplate nodeType = nodeTypeManager.createNodeTypeTemplate();
nodeType.setMixin( true );
nodeType.setName( type );
nodeTypeManager.registerNodeType( nodeType, false );
}
示例9: getNodeType
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
/**
* Returns an Optional containing the node type for the specified name if it exists otherwise empty.
*
* @param name
* the node types full name including it's name space
* @return an Optional containing the node type for the specified name if it exists otherwise empty.
*/
public Optional<NodeType> getNodeType(final String name) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "node type name is null or empty");
return JcrThrowables.wrapJcrExceptionsWithReturn(() -> {
NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
Optional<NodeType> optional = Optional.empty();
if (nodeTypeManager.hasNodeType(name)) {
NodeType nodeType = nodeTypeManager.getNodeType(name);
optional = Optional.of(nodeType);
}
return optional;
});
}
示例10: setUp
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
session = MgnlContext.getInstance().getJCRSession("website");
// register node type
NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
NodeTypeTemplate type = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, "mgnl:apex",
Arrays.asList(NodeType.NT_HIERARCHY_NODE, NodeType.MIX_REFERENCEABLE, NodeTypes.Created.NAME, NodeTypes.Activatable.NAME, NodeTypes.LastModified.NAME, NodeTypes.Renderable.NAME));
nodeTypeManager.registerNodeType(type, true);
session.save();
new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(rootTree));
session.save();
// silly but can't use : in name in util
session.move("/home/mgnl_apex", "/home/mgnl:apex");
session.move("/home/section/mgnl_apex", "/home/section/mgnl:apex");
session.move("/home/section2/mgnl_apex", "/home/section2/mgnl:apex");
session.move("/home/section/article/mgnl_apex", "/home/section/article/mgnl:apex");
session.move("/home/section2/article/mgnl_apex", "/home/section2/article/mgnl:apex");
session.save();
Components.getSingleton(RepositoryManager.class).createWorkspace("magnolia", "category");
Session catSession = MgnlContext.getInstance().getJCRSession("category");
// register node type
NodeTypeManager catNodeTypeManager = catSession.getWorkspace().getNodeTypeManager();
type = NodeTypeTemplateUtil.createSimpleNodeType(nodeTypeManager, "category", Arrays.asList(NodeType.NT_HIERARCHY_NODE, NodeType.MIX_REFERENCEABLE, NodeTypes.Created.NAME, NodeTypes.Activatable.NAME, NodeTypes.LastModified.NAME, NodeTypes.Renderable.NAME));
nodeTypeManager.registerNodeType(type, true);
catNode = catSession.getRootNode().addNode("foo", "category");
catNode.addNode("foobar", "mgnl:content");
catNode.setProperty("name", "myCategory");
catSession.save();
MgnlContext.setLocale(null);
ComponentsTestUtil.setInstance(I18nContentSupport.class, new DefaultI18nContentSupport());
}
示例11: createSinglePropertyDefTemplate
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
private PropertyDefinitionTemplate createSinglePropertyDefTemplate(Session session, NodeTypeManager mgr, String name, int propertyType) throws RepositoryException {
PropertyDefinitionTemplate propDefn = mgr.createPropertyDefinitionTemplate();
propDefn.setName(name);
propDefn.setRequiredType(propertyType);
ValueFactory valueFactory = session.getValueFactory();
propDefn.setMultiple(false);
propDefn.setFullTextSearchable(false);
propDefn.setQueryOrderable(false);
return propDefn;
}
示例12: createMultiPropertyDefTemplate
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
private PropertyDefinitionTemplate createMultiPropertyDefTemplate(final Session session, final NodeTypeManager mgr, final String name, final int propertyType)
throws RepositoryException {
PropertyDefinitionTemplate propDefn = mgr.createPropertyDefinitionTemplate();
propDefn.setName(name);
propDefn.setRequiredType(propertyType);
ValueFactory valueFactory = session.getValueFactory();
propDefn.setMultiple(true);
propDefn.setFullTextSearchable(false);
propDefn.setQueryOrderable(false);
return propDefn;
}
示例13: beforeEach
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@Override
public void beforeEach() throws Exception {
super.beforeEach();
URL cndResource = getClass().getResource("/nodetypes-modeshape.cnd");
File cnd = null;
try {
cnd = new File(cndResource.toURI());
SimpleProblems problems = new SimpleProblems();
ExecutionContext context = new ExecutionContext();
context.getNamespaceRegistry().register("sling", "http://sling.apache.org/jcr/sling/1.0");
context.getNamespaceRegistry().register("cq", "http://www.day.com/jcr/cq/1.0");
// Set up the importer ...
CndImporter importer = new CndImporter(context, true);
importer.importFrom(cnd, problems);
List<NodeTypeDefinition> ntds = importer.getNodeTypeDefinitions();
// Retrieve node type manager from the session
NodeTypeManager nodeTypeManager = ((Session) session).getWorkspace().getNodeTypeManager();
nodeTypeManager.registerNodeTypes(ntds.toArray(new NodeTypeDefinition[] {}), true);
for (NodeTypeDefinition ntd : ntds) {
System.out.println("Registered: " + ntd.getName());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
示例14: createMyCollabFolderType
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
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;
}
示例15: registerNodeTypes
import javax.jcr.nodetype.NodeTypeManager; //导入依赖的package包/类
@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();
}