Support for sub-types of folder in site.getContainer() - to allow for specialised types of component folder and backwards compatibility with existing models such as forum.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-05-29 11:37:42 +00:00
parent e09ae51c1d
commit 14660ea397
5 changed files with 56 additions and 10 deletions

View File

@@ -34,6 +34,7 @@ import org.alfresco.repo.site.SiteInfo;
import org.alfresco.repo.site.SiteService;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.mozilla.javascript.Scriptable;
/**
@@ -261,15 +262,31 @@ public class Site implements Serializable
/**
* Gets (or creates) the "container" folder for the specified component id
*
* NOTE: The container is of type cm:folder.
*
* @param componentId
* @return node representing the "container" folder
*/
public ScriptNode getContainer(String componentId)
{
return getContainer(componentId, null);
}
/**
* Gets (or creates) the "container" folder for the specified component id
*
* @param componentId
* @param folderType type of folder to create (if null, creates a standard folder)
* @return node representing the "container" folder (or null, if for some reason
* the container can not be created)
*/
public ScriptNode getContainer(String componentId, String folderType)
{
ScriptNode container = null;
try
{
NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId);
QName folderQName = (folderType == null) ? null : QName.createQName(folderType, serviceRegistry.getNamespaceService());
NodeRef containerNodeRef = this.siteService.getContainer(getShortName(), componentId, folderQName);
container = new ScriptNode(containerNodeRef, this.serviceRegistry, this.scope);
}
catch(AlfrescoRuntimeException e)
@@ -279,7 +296,7 @@ public class Site implements Serializable
}
return container;
}
/**
* Determine if the "container" folder for the specified component exists
*

View File

@@ -92,7 +92,14 @@ function testContainer()
test.assertTrue(hasContainer2);
var container2 = site.getContainer("folder.component");
test.assertNotNull(container2);
test.assertEquals(container, container2);
test.assertEquals(container, container2);
var container3 = site.getContainer("folder.component2", "cm:folder");
test.assertNotNull(container3);
test.assertEquals("{http://www.alfresco.org/model/content/1.0}folder", container3.type);
var container4 = site.getContainer("folder.component3", "app:projectfolder");
test.assertNotNull(container4);
test.assertEquals("{http://www.alfresco.org/model/application/1.0}projectfolder", container4.type);
}