cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic path conversion of spaces to use in lucene query

kdejaeger
Champ in-the-making
Champ in-the-making
Hello,

Is there a way to dynamically convert a path like "Company Home/User Homes/user/folder" to "/app:company_home/app:user_homes/sys:user/cm:folder" ?
3 REPLIES 3

kdejaeger
Champ in-the-making
Champ in-the-making
Ok I made it myself  😎 and this is what it looks like :

    /**
     * input : /Company Home/User Homes/koen/subfolder
     * output : /app:company_home/app:user_homes/sys:koen/cm:subfolder
     * @return
     */
    private String convertFolderToXPathPrefix(NodeRef pHomeRef, String psFolderPath) {
      try {

         List<String> listPaths = new ArrayList();

         StringTokenizer T = new StringTokenizer(psFolderPath, "/", false);
         while (T.hasMoreTokens())
            listPaths.add(T.nextToken());
         listPaths.remove(0); //removing "Company Home"

         return m_nodeService.getPath(m_fileFolderService.resolveNamePath(pHomeRef, listPaths).getNodeRef()).toPrefixString(
               m_namespaceService);

      } catch (FileNotFoundException e) {
         //TODO
         e.printStackTrace();
         
         return null;
      }       
      
   }

kdejaeger
Champ in-the-making
Champ in-the-making
Also check this thread http://forums.alfresco.com/en/viewtopic.php?f=4&t=8062&start=0&st=0&sk=t&sd=a
It's about the restrictions of the first parameter of the resolveNamePath method.

pmonks
Star Contributor
Star Contributor
You should also use the org.alfresco.util.ISO9075 class to ISO-9075 escape each component of the path.  Although the ISO-9075 escaping rules mostly don't modify simple alphanumeric path elements, it does come into play for path components that start with numeric characters or contain whitespace, etc.

Cheers,
Peter