AnsweredAssumed Answered

create folder structure

Question asked by enkidu on Dec 16, 2013
Latest reply on Dec 19, 2013 by enkidu
hi mates,

i want to create a folder structure.. my code looks like this:


   @Override
   protected void executeImpl(Action uAction, NodeRef uNodeRef) {
      
      try {
      
         List<String> data = new ArrayList<String>();
         
         data.add("folderone");
         data.add("foldertwo");
                  
         checkFolder(data);
         
      } catch (Exception e) {
         // TODO Auto-generated catch block
         throw new AlfrescoRuntimeException("Error "+e.toString());   
      }       
   }

   private boolean checkFolder(List<String> folderName) {
      
      boolean folderCheck = false;
      StringBuilder strBuilder = new StringBuilder();
      
      StoreRef store = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
      String base = "//app:company_home/st:sites/cm:folders";
      
      for(String data : folderName) {
         
         strBuilder.append("/cm:"+search.ISO9075Encode(data));
         
         String query = "//app:company_home/st:sites/cm:folders"+strBuilder.toString();
         ResultSet rs = searchService.query(store, SearchService.LANGUAGE_XPATH, query);
         logger.error("ResultSet: "+rs.length()+" - Query: "+query+" Base: "+base);
         if(rs.length()==0) {
            rs = searchService.query(store, SearchService.LANGUAGE_XPATH, base);
            NodeRef ref = rs.getNodeRef(0);            
            fileFolderService.create(ref, search.ISO9075Decode(data), ContentModel.TYPE_FOLDER);
         }
         base = base+strBuilder.toString();
      }
      return folderCheck;
   }



when i pass just one folder to the List then it works.. but when i add two or more i get and indexoutofbounceexception. any ideas??

Outcomes