cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the name of the space from any .java file

unknown-user
Champ on-the-rise
Champ on-the-rise
Hello there. I have a problem Smiley Happy

What i want to do is to get the name of the space where the document is created. I know how to do it from a file which has a NavigatorBean, then with a getNavigation().getName(). But what i have in my .java file is only the NodeService, and a NodeRef.

Any ideas of how can i get the name of the space i am in?

This class is executed in a rule, so when this rule is executed, and this class does what it has to, at this point there must be a way of knowing the name of the space.

Thanks for any help.

Bird
7 REPLIES 7

gavinc
Champ in-the-making
Champ in-the-making
There is a method called getPrimaryParent on the NodeService, you can pass in the NodeRef you have, you can retrieve the parent NodeRef from the returned object and finally get the parents cm:name property.

Hope that helps.

unknown-user
Champ on-the-rise
Champ on-the-rise
thanks.
I have tried that, but what i get from :

QName qname = this.nodeService.getPrimaryParent(nodeRef).getQName()
    if (qname != null)
            {
               name = qname.getLocalName();
            }

What i get is the name of the file.

Then i have tried other things, such as retrieve the parend NodeRef… but then i am at the same point as a started. is a cercle!

I also tried do:

Path p = this.nodeService.getPath(nodeRef);
String camino = p.toDisplayPath(this.nodeService);

but what i get is the full path, and i only want to get the last folder.

Any ideas about this? I don't want to treat the String, so there have to be other ways.

Thanks for all.
Bird

gavinc
Champ in-the-making
Champ in-the-making
The code you need is as follows:


NodeRef parent = this.nodeService.getPrimaryParent(nodeRef).getParentRef();
String name = (String)this.nodeService.getProperty(parent, ContentModel.PROP_NAME);
‍‍‍‍

Hope that helps.

unknown-user
Champ on-the-rise
Champ on-the-rise
Thanks very much!

That works perfectly!

unknown-user
Champ on-the-rise
Champ on-the-rise
A new question about getting the name of one space. Not the working one, but another.

We have a QName, but anything else. Neither the nameservice, nor the nodeRef.

For example.

I have the tag "cm:my_space" (which cm is namespace.prefix, and my_space is the localname). That's the QName.

I need to know the Node or NodeRef of the namespace, so in that way i can get the name and description.

How can i do that?

Thanks in advance.
Bird

andy
Champ on-the-rise
Champ on-the-rise
Hi

You can do a search for QName.
See the search docs.

http://wiki.alfresco.com/wiki/Search

Regards

Andy

unknown-user
Champ on-the-rise
Champ on-the-rise
thanks!
that helped.
Bird