cancel
Showing results for 
Search instead for 
Did you mean: 

Create folder and subfolder via API Java

monocromo
Champ in-the-making
Champ in-the-making
Hi,
i would like create this structure /cm:documentLibrary/cm:TestPorting/cm:2388/cm:InVigore but i can't. Because when i create  the subfolder "inVigore" i have this error:
org.alfresco.service.cmr.repository.XPathException: 03242678 Error executing xpath: \n /app:company_home/st:sites/cm:prova-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388/cm:InVigore ‍‍‍


This is the code that create the folder:

boolean res = this.createFolder("2388","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting");boolean res1 = this.createFolder("Approvati","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388");boolean res2 = this.createFolder("inVigore","/app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting/cm:2388");‍‍‍‍‍


public boolean createFolder(String fileName,String percorso) throws Exception   {         // Avvio sessione        //AuthenticationUtils.startSession(user, password);                           try        {                     // Referenza al nodo padre in cui inserire il documento            Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");            ParentReference companyHomeParent = new ParentReference(storeRef, null, percorso, Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "folder"));                        //Richiesta del repository service e del content service            RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();                                   //Vettori delle proprietà           NamedValue[] contentProps = new NamedValue[1];                       //Assegnazione ai vettori delle proprietà            contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, fileName);             //Upload file custom                        CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_FOLDER, contentProps);                        // Blocco create CML            CML cml = new CML();            cml.setCreate(new CMLCreate[] {create});                        //Creazione effettiva del nodo            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);                              System.out.println("Cartella creata: " + fileName);            return true;        }        catch(Throwable e)        {            System.out.println(e.getMessage());            return false;        }        finally        {            // Fine della sessione            //AuthenticationUtils.endSession();                   }         }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


Where is the problem?
If i create more folder in /cm:documentLibrary/cm:TestPorting/cm:2388 i haven't problem but if i create a folder in cm:2388 java report the above error.
4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator
Hello,

leading digits in a path element need to be encoded for XPath - it may not be necessary in all constellations, but for simplicity should always be done. Alfresco provides a utility class for this: ISO9075 with methods getXPathName(QName).
Note that every fragment of your path need to be individually encoded before constructing the complete XPath - there is as far as I know no utility to encode an already constructed XPath.

Regards
Axel

monocromo
Champ in-the-making
Champ in-the-making
Thanks for reply, it is possible have an example for use the ISO9075's method?
I search in internet but i not found example.

afaust
Legendary Innovator
Legendary Innovator
Hello,

a simple example:
String[] fragments = "app:company_home/st:sites/cm:bosco-italia-spa/cm:documentLibrary/cm:TestPorting".split("/");StringBuilder builder = new StringBuilder();for(String fragment : fragments){   builder.append("/");   builder.append(ISO9075.getXPathName(QName.createQName(fragment, namespaceService), namespaceService));}String xpath = builder.toString();‍‍‍‍‍‍‍‍‍‍


Regards
Axel

monocromo
Champ in-the-making
Champ in-the-making
Thanks for reply.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.