AnsweredAssumed Answered

Unable to navigate till custom space.

Question asked by amit_wmw@yahoo.com on Feb 23, 2009
Latest reply on Feb 26, 2009 by amit_wmw@yahoo.com
Hello

Below I wrote a simple program to get all workspace-id under my custom space(Amitspace). But I am unable to navigate till my custom space. Kindly let me know that with what should I replace query string (which I marked red in color in my program) to reach up to my custom space. Please get me out of this small issue.  Will be kind!
—————————————————————————————–
package org.alfresco.sample;

import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;

import org.springframework.context.ApplicationContext;  
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class FirstJCRClient
{
   
 
  
   public static void main(String[] args)      
   {
   
      try{
         
         
         
          ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
      
          Repository repository = (Repository)context.getBean("JCR.Repository");
         
          // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
          Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
          ServiceRegistry serviceRegistry = (ServiceRegistry)context.getBean("ServiceRegistry");
          StoreRef SR=new StoreRef("workspace://SpacesStore//app:companyHome//cm:Amitspace");
          SearchParameters sp = new SearchParameters();
           sp.addStore(SR);
           sp.setLanguage(SearchService.LANGUAGE_LUCENE);
           sp.setQuery("TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"");

           //sp.setQuery("@cm\\:name:\"Amit2\"" );
        
           org.alfresco.service.cmr.search.ResultSet results = null;
           try
           {
            
              results = serviceRegistry.getSearchService().query(sp);
               for(ResultSetRow row : results)
               {
              
                   NodeRef currentNodeRef = row.getNodeRef();
                 
                   System.out.println(currentNodeRef.toString());
                  
               }
         
         
           }
          
           catch (Exception exp ){
            System.out.println (" Caught exception " + exp);
            exp.printStackTrace();
         }
           finally
           {
               if(results != null)
               {
                 results.close();
                 session.logout();
                 System.exit(0);
               }
           } 
         
      }catch (Exception exp ){
         System.out.println (" Caught exception " + exp);
         exp.printStackTrace();
      }
      
      
   }
   
      

}
————————————————————————————

Thanks
Amit

Outcomes