Added isLocked, isLockOwner and hasLockAccess AVM properties to Freemarker and JavaScript APIs

FreeMarker config object now shared to make use of MRU caching in FreeMarker

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6207 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-07-11 15:59:59 +00:00
parent 0c1f0f5273
commit ac022ce7ca
4 changed files with 176 additions and 26 deletions

View File

@@ -24,10 +24,15 @@
*/ */
package org.alfresco.repo.jscript; package org.alfresco.repo.jscript;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.alfresco.model.WCMModel; import org.alfresco.model.WCMModel;
import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.locking.AVMLock;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
@@ -190,6 +195,60 @@ public class AVMNode extends ScriptNode
return this.avmRef.getName(); return this.avmRef.getName();
} }
/**
* @return true if the node is currently locked
*/
public boolean isLocked()
{
AVMLock lock = this.services.getAVMLockingService().getLock(
getWebProject(), path.substring(path.indexOf("/")));
return (lock != null);
}
public boolean jsGet_isLocked()
{
return isLocked();
}
/**
* @return true if this node is locked and the current user is the lock owner
*/
public boolean isLockOwner()
{
boolean lockOwner = false;
AVMLock lock = this.services.getAVMLockingService().getLock(
getWebProject(), path.substring(path.indexOf("/")));
if (lock != null)
{
List<String> lockUsers = lock.getOwners();
lockOwner = (lockUsers.contains(this.services.getAuthenticationService().getCurrentUserName()));
}
return lockOwner;
}
public boolean jsGet_isLockOwner()
{
return isLockOwner();
}
/**
* @return true if this user can perform operations on the node when locked.
* This is true if the item is either unlocked, or locked and the current user is the lock owner,
* or locked and the current user has Content Manager role in the associated web project.
*/
public boolean hasLockAccess()
{
return this.services.getAVMLockingService().hasAccess(
getWebProject(), path, this.services.getAuthenticationService().getCurrentUserName());
}
public boolean jsGet_hasLockAccess()
{
return hasLockAccess();
}
/** /**
* Copy this Node into a new parent destination. * Copy this Node into a new parent destination.
* *
@@ -298,6 +357,20 @@ public class AVMNode extends ScriptNode
return success; return success;
} }
/**
* @return The list of aspects applied to this node
*/
@Override
public Set<QName> getAspects()
{
if (this.aspects == null)
{
this.aspects = this.services.getAVMService().getAspects(this.version, this.path);
}
return this.aspects;
}
/** /**
* Reset the Node cached state * Reset the Node cached state
*/ */
@@ -316,6 +389,20 @@ public class AVMNode extends ScriptNode
this.deleted = descriptor.isDeleted(); this.deleted = descriptor.isDeleted();
} }
/**
* @return the WebProject identifier for the current path
*/
private String getWebProject()
{
String webProject = this.path.substring(0, this.path.indexOf(':'));
int index = webProject.indexOf("--");
if (index != -1)
{
webProject = webProject.substring(0, index);
}
return webProject;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@@ -116,7 +116,7 @@ public class ScriptNode implements Serializable, Scopeable
protected String id; protected String id;
/** The aspects applied to this node */ /** The aspects applied to this node */
private Set<QName> aspects = null; protected Set<QName> aspects = null;
/** The target associations for this node */ /** The target associations for this node */
private ScriptableQNameMap<String, Object> assocs = null; private ScriptableQNameMap<String, Object> assocs = null;

View File

@@ -39,6 +39,7 @@ import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.audit.AuditInfo; import org.alfresco.service.cmr.audit.AuditInfo;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor; import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.locking.AVMLock;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
@@ -268,6 +269,45 @@ public class AVMTemplateNode extends BasePermissionsNode
return this.avmRef.isDeleted(); return this.avmRef.isDeleted();
} }
/**
* @return true if the node is currently locked
*/
public boolean getIsLocked()
{
AVMLock lock = this.services.getAVMLockingService().getLock(
getWebProject(), path.substring(path.indexOf("/")));
return (lock != null);
}
/**
* @return true if this node is locked and the current user is the lock owner
*/
public boolean getIsLockOwner()
{
boolean lockOwner = false;
AVMLock lock = this.services.getAVMLockingService().getLock(
getWebProject(), path.substring(path.indexOf("/")));
if (lock != null)
{
List<String> lockUsers = lock.getOwners();
lockOwner = (lockUsers.contains(this.services.getAuthenticationService().getCurrentUserName()));
}
return lockOwner;
}
/**
* @return true if this user can perform operations on the node when locked.
* This is true if the item is either unlocked, or locked and the current user is the lock owner,
* or locked and the current user has Content Manager role in the associated web project.
*/
public boolean getHasLockAccess()
{
return this.services.getAVMLockingService().hasAccess(
getWebProject(), path, this.services.getAuthenticationService().getCurrentUserName());
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// TemplateProperties API // TemplateProperties API
@@ -381,8 +421,7 @@ public class AVMTemplateNode extends BasePermissionsNode
{ {
if (this.aspects == null) if (this.aspects == null)
{ {
this.aspects = new HashSet<QName>(); this.aspects = this.services.getAVMService().getAspects(this.version, this.path);
this.aspects.addAll(this.services.getAVMService().getAspects(this.version, this.path));
} }
return this.aspects; return this.aspects;
@@ -430,4 +469,22 @@ public class AVMTemplateNode extends BasePermissionsNode
{ {
return this.path; return this.path;
} }
// ------------------------------------------------------------------------------
// Private helpers
/**
* @return the WebProject identifier for the current path
*/
private String getWebProject()
{
String webProject = this.path.substring(0, this.path.indexOf(':'));
int index = webProject.indexOf("--");
if (index != -1)
{
webProject = webProject.substring(0, index);
}
return webProject;
}
} }

View File

@@ -74,6 +74,9 @@ public class FreeMarkerProcessor extends BaseProcessor implements TemplateProces
/** Pseudo path to String based template */ /** Pseudo path to String based template */
private static final String PATH = "string://fixed"; private static final String PATH = "string://fixed";
/** FreeMarker configuration object */
private Configuration config;
/** Template encoding */ /** Template encoding */
private String defaultEncoding; private String defaultEncoding;
@@ -92,31 +95,34 @@ public class FreeMarkerProcessor extends BaseProcessor implements TemplateProces
* *
* @return FreeMarker configuration * @return FreeMarker configuration
*/ */
protected Configuration getConfig() protected synchronized Configuration getConfig()
{ {
Configuration config = new Configuration(); if (config == null)
// setup template cache
config.setCacheStorage(new MruCacheStorage(2, 0));
// use our custom loader to find templates on the ClassPath
config.setTemplateLoader(new ClassPathRepoTemplateLoader(
this.services.getNodeService(), this.services.getContentService(), defaultEncoding));
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(new QNameAwareObjectWrapper());
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// localized template lookups off by default - as they create strange noderef lookups
// such as workspace://SpacesStore/01234_en_GB - causes problems for ns.exists() on DB2
config.setLocalizedLookup(false);
// set default template encoding
if (defaultEncoding != null)
{ {
config.setDefaultEncoding(defaultEncoding); config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(32, 32));
// use our custom loader to find templates on the ClassPath
config.setTemplateLoader(new ClassPathRepoTemplateLoader(
this.services.getNodeService(), this.services.getContentService(), defaultEncoding));
// use our custom object wrapper that can deal with QNameMap objects directly
config.setObjectWrapper(new QNameAwareObjectWrapper());
// rethrow any exception so we can deal with them
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// localized template lookups off by default - as they create strange noderef lookups
// such as workspace://SpacesStore/01234_en_GB - causes problems for ns.exists() on DB2
config.setLocalizedLookup(false);
// set default template encoding
if (defaultEncoding != null)
{
config.setDefaultEncoding(defaultEncoding);
}
} }
return config; return config;