AnsweredAssumed Answered

Check if a folder exist

Question asked by chicco0386 on Sep 16, 2010
Latest reply on Jul 5, 2011 by mrogers
Hi all,
I've this function that create a folder:
public static Reference createFolder(String folderName) throws RepositoryFault, RemoteException {

        RepositoryServiceSoapBindingStub repoService = WebServiceFactory.getRepositoryService();
        String currentPath = getCompanyHome().getPath();
        String newPath = currentPath.concat("/cm:").concat(folderName);
        Reference folder = getCompanyHome();
        try {
            Node[] nodeFolder = repoService.get(new Predicate(new Reference[] { folder }, getStore(), null));
            folder = nodeFolder[0].getReference();
            if (log.isDebugEnabled()) {
                log.debug("createFolder, la cartella [" + folderName + "] esiste già");
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("createFolder, la cartella [" + folderName + "] NON esiste, procedo nella sua creazione");
            ParentReference parent = new ParentReference(getStore(), null, ConfigManager.getInstance().getConfigValue(""), Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, folderName));
            NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, folderName) };
            CMLCreate cmlCreate = new CMLCreate(folderName, parent, null, null, null, Constants.TYPE_FOLDER, properties);
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] { cmlCreate });
            UpdateResult[] updateResults = repoService.update(cml);
            folder = updateResults[0].getDestination();

        return folder;

It's work fine if the folder doesn't exist or if the name folder to create is without white space.
If the folder name contains white space and the folder already exist, the function say me that the folder doesn't exist and so it goes to create it, but I've the error that the folder is duplicate.

I found that the problem is that the folder name with with space into alfresco is stored with special character.
For example:
if I call the method with this folder name "[Test] Ciao – Pluto" and this folder exist into Alfresco, the function don't find it because the alfresco folder name is store like this "_x005b_Test_x005d__x0020_Ciao_x0020_–_x0020_Pluto".

Now I look if there is a method of Alfresco web service API that convert a string in the alfresco folder name, or if there is another method for look if a folder name (with specials characters) exist into alfresco.