cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the value of aspect?

jlbarrera
Champ in-the-making
Champ in-the-making
I want get the value of aspect. How i can make this?
Thanks!
13 REPLIES 13

jlbarrera
Champ in-the-making
Champ in-the-making
NodeRef categoryRef = (NodeRef)this.nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale")); 

With this code i access to cm:locale property, but  …i dont not how to get the value…(Spanish..English…etc)

In categoryRef is stored:
workspace://SpacesStore/9472c578-c478-11da-8be5-db2bb273e6f3

jlbarrera
Champ in-the-making
Champ in-the-making
Ok this is the way:

this.categoryRef = (NodeRef)nodeService.getProperty(this.nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale"));

String Documentlanguage = Repository.getNameForNode(nodeService, this.categoryRef);

In Documentlanguage is stored a string with the language of the document.

aznk
Champ in-the-making
Champ in-the-making
Hi,
I tried to launched the same code from a client (inspired from the sdk samples)  :
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       Repository repository = (Repository)context.getBean("JCR.Repository");
   

       Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
   
       try
       {

           ServiceRegistry serviceRegistry = (ServiceRegistry) context.getBean(ServiceRegistry.SERVICE_REGISTRY);
            NodeService nodeService = serviceRegistry.getNodeService();
           
            StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
            NodeRef nodeRef = nodeService.getRootNode(storeRef);
         
            NodeRef nameProp = (NodeRef)nodeService.getProperty(nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale"));
       
          
            String name = null;
          
            if (nameProp != null)
            {
               name = nameProp.toString();
            }
          
           
            System.out.println(name);
           

           session.save();
       }
       finally
       {
           session.logout();
           System.exit(0);
       }

but I'm always getting  null in the nameProp variable and I know that an object has this localizable aspect. What's wrong ?

jlbarrera
Champ in-the-making
Champ in-the-making
nodeRef must be a node reference

this.nodeRef = ref.getNodeRef();

this.categoryRef = (NodeRef)nodeService.getProperty(this.nodeRef, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "locale"));

In this example ref is a Node.