jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksandar Pecanov <peca...@mt.net.mk>
Subject Re: How to know if a NodeType already exist?
Date Fri, 28 Jul 2006 06:21:46 GMT
Here is some code I use. It's been written long before 1.0, and it might
just be a more sophisticated way to do this. However it works well all
the way to the latest trunk.

Hope it helps:

//-------------- CODE BEGINS HERE --------------------------------

public boolean doesNodeTypeExist(Session session, NodeType nt) 
throws Exception {

// Obtain node type manager
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();

// Replace manager with jackrabbit's implementation of it
NodeTypeManagerImpl managerImpl = (NodeTypeManagerImpl) manager;

Workspace w = session.getWorkspace();
NamespaceResolver reg = (NamespaceResolver) w.getNamespaceRegistry();

QName qname = QName.fromJCRName(nt.getName(), reg);
return managerImpl.getNodeTypeRegistry().isRegistered( qname );

//-------------- CODE ENDS HERE --------------------------------

On Thu, 2006-07-27 at 20:08 +0200, Nicolas wrote:
> Hi,
> How can I know that a nodeType already exist? I can look for it in the list
> of all NodeTypes (but I need first to build it) or catch the exception but
> both are somewhat inelegant. Is there anothe way?
> Thanks
> Nico
> my blog! http://www.deviant-abstraction.net !!

View raw message