Create folder and subfolder via API Java
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2013 09:59 AM
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:
This is the code that create the folder:
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.
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.
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2013 06:45 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2013 08:37 AM
Thanks for reply, it is possible have an example for use the ISO9075's method?
I search in internet but i not found example.
I search in internet but i not found example.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2013 11:40 AM
Hello,
a simple example:
Regards
Axel
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2013 08:19 AM
Thanks for reply.
