From 1ec0296c224f58b75f6ac6d544b084ec8451190c Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 11 Jul 2006 10:13:30 +0000 Subject: [PATCH] . Fix to issue in login page redirect code where URL arguments (e.g. for templates and scripts) were removed and not passed through. - this only affected the template/command servlets that were using parameters and had not already logged in . Support for 'path' argument on DownloadContentServlet for example /alfresco/download/direct?path=/Company%20Home/Kev's%20Home%20Space/myimage.jpg - paths are specified in a similar way to webdav path - they are 'cm:name' based URL encoded strings - this means we no longer need to have the NodeRef to a document to download it . Support for 'templatePath' and 'contextPath' URL arguments in TemplateContentServlet for example: /alfresco/template?templatePath=/Company%20Home/Data%20Dictionary/Presentation%20Templates/doc_info.ftl&contextPath=/Company%20Home/file.txt - the 'templatePath' argument specifies the cm:name based path to the template to execute - the 'contextPath' argument specifies the cm:name based path to the context for the template . Support for 'scriptPath' and 'contextPath' URL arguments in Script CommandProcessor for example: /alfresco/command/script/execute?scriptPath=/Company%20Home/Data%20Dictionary/Scripts/append%20copyright.js&contextPath=/Company%20Home/file.txt - the 'scriptPath' argument specifies the cm:name based path to the script to execute - the 'contextPath' argument specifies the cm:name based path to the context for the script . Adding debugging output to get timings for executing templates and scripts . Enhancements and additions to JavaScript API: setPermission() removePermission() get/setInheritsPermissions() git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3297 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/Node.java | 61 +++++++++++++++ .../repo/jscript/RhinoScriptService.java | 17 +++- .../repo/template/FreeMarkerProcessor.java | 77 +++++++++++++------ .../repo/template/TemplateServiceImpl.java | 9 ++- 4 files changed, 137 insertions(+), 27 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/Node.java b/source/java/org/alfresco/repo/jscript/Node.java index 2b36dedd14..8fe97a8c2b 100644 --- a/source/java/org/alfresco/repo/jscript/Node.java +++ b/source/java/org/alfresco/repo/jscript/Node.java @@ -47,6 +47,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; @@ -488,6 +489,66 @@ public final class Node implements Serializable return allowed; } + /** + * @return true if the node inherits permissions from the parent node, false otherwise + */ + public boolean inheritsPermissions() + { + return this.services.getPermissionService().getInheritParentPermissions(this.nodeRef); + } + + /** + * Set whether this node should inherit permissions from the parent node. + * + * @param inherit True to inherit parent permissions, false otherwise. + */ + public void setInheritsPermissions(boolean inherit) + { + this.services.getPermissionService().setInheritParentPermissions(this.nodeRef, inherit); + } + + /** + * Apply a permission for ALL users to the node. + * + * @param permission Permission to apply @see org.alfresco.service.cmr.security.PermissionService + */ + public void setPermission(String permission) + { + this.services.getPermissionService().setPermission(this.nodeRef, PermissionService.ALL_AUTHORITIES, permission, true); + } + + /** + * Apply a permission for the specified authority (e.g. username or group) to the node. + * + * @param permission Permission to apply @see org.alfresco.service.cmr.security.PermissionService + * @param authority Authority (generally a username or group name) to apply the permission for + */ + public void setPermission(String permission, String authority) + { + this.services.getPermissionService().setPermission(this.nodeRef, authority, permission, true); + } + + /** + * Remove a permission for ALL user from the node. + * + * @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService + */ + public void removePermission(String permission) + { + this.services.getPermissionService().deletePermission(this.nodeRef, PermissionService.ALL_AUTHORITIES, permission); + } + + /** + * Remove a permission for the specified authority (e.g. username or group) from the node. + * + * @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService + * @param authority Authority (generally a username or group name) to apply the permission for + */ + public void removePermission(String permission, String authority) + { + this.services.getPermissionService().deletePermission(this.nodeRef, authority, permission); + } + /** * @return Display path to this node */ diff --git a/source/java/org/alfresco/repo/jscript/RhinoScriptService.java b/source/java/org/alfresco/repo/jscript/RhinoScriptService.java index 96f880aafa..3dbe2ba130 100644 --- a/source/java/org/alfresco/repo/jscript/RhinoScriptService.java +++ b/source/java/org/alfresco/repo/jscript/RhinoScriptService.java @@ -35,6 +35,7 @@ import org.alfresco.service.cmr.repository.ScriptException; import org.alfresco.service.cmr.repository.ScriptService; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.namespace.QName; +import org.apache.log4j.Logger; import org.mozilla.javascript.Context; import org.mozilla.javascript.ImporterTopLevel; import org.mozilla.javascript.Scriptable; @@ -47,6 +48,8 @@ import org.mozilla.javascript.ScriptableObject; */ public class RhinoScriptService implements ScriptService { + private static final Logger logger = Logger.getLogger(RhinoScriptService.class); + /** The permission-safe node service */ private NodeService nodeService; @@ -191,7 +194,13 @@ public class RhinoScriptService implements ScriptService */ private Object executeScriptImpl(Reader reader, Map model) throws AlfrescoRuntimeException - { + { + long startTime = 0; + if (logger.isDebugEnabled()) + { + startTime = System.currentTimeMillis(); + } + // check that rhino script engine is available Context cx = Context.enter(); try @@ -226,6 +235,12 @@ public class RhinoScriptService implements ScriptService finally { cx.exit(); + + if (logger.isDebugEnabled()) + { + long endTime = System.currentTimeMillis(); + logger.debug("Time to execute script: " + (endTime - startTime) + "ms"); + } } } diff --git a/source/java/org/alfresco/repo/template/FreeMarkerProcessor.java b/source/java/org/alfresco/repo/template/FreeMarkerProcessor.java index b3ea0f06c6..d311575cc9 100644 --- a/source/java/org/alfresco/repo/template/FreeMarkerProcessor.java +++ b/source/java/org/alfresco/repo/template/FreeMarkerProcessor.java @@ -23,7 +23,6 @@ import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.TemplateException; import org.alfresco.service.cmr.repository.TemplateProcessor; -import org.alfresco.util.ISO9075; import org.apache.log4j.Logger; import freemarker.cache.MruCacheStorage; @@ -43,7 +42,10 @@ public class FreeMarkerProcessor implements TemplateProcessor private final static String MSG_ERROR_TEMPLATE_FAIL = "error_template_fail"; private final static String MSG_ERROR_TEMPLATE_IO = "error_template_io"; - private static Logger logger = Logger.getLogger(FreeMarkerProcessor.class); + private static final Logger logger = Logger.getLogger(FreeMarkerProcessor.class); + + /** Pseudo path to String based template */ + private static final String PATH = "string://fixed"; /** FreeMarker processor configuration */ private Configuration config = null; @@ -75,7 +77,9 @@ public class FreeMarkerProcessor implements TemplateProcessor } /** - * @return The FreeMarker config instance for this processor + * Get the FreeMarker configuration for this instance + * + * @return FreeMarker configuration */ private Configuration getConfig() { @@ -100,26 +104,30 @@ public class FreeMarkerProcessor implements TemplateProcessor return this.config; } + /** + * FreeMarker configuration for loading the specified template directly from a String + * + * @param path Pseudo Path to the template + * @param template Template content + * + * @return FreeMarker configuration + */ private Configuration getStringConfig(String path, String template) { + Configuration config = new Configuration(); - Configuration config = new Configuration(); - - // setup template cache - config.setCacheStorage(new MruCacheStorage(20, 0)); - - // use our custom loader to find templates on the ClassPath - StringTemplateLoader stringTemplateLoader = new StringTemplateLoader(); - stringTemplateLoader.putTemplate(path, template); - config.setTemplateLoader(stringTemplateLoader); - - // 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); - - return config; + // use our custom loader to load a template directly from a String + StringTemplateLoader stringTemplateLoader = new StringTemplateLoader(); + stringTemplateLoader.putTemplate(path, template); + config.setTemplateLoader(stringTemplateLoader); + + // 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); + + return config; } /** @@ -142,8 +150,12 @@ public class FreeMarkerProcessor implements TemplateProcessor try { + long startTime = 0; if (logger.isDebugEnabled()) - logger.debug("Executing template: " + template + " on model: " + model); + { + logger.debug("Executing template: " + template);// + " on model: " + model); + startTime = System.currentTimeMillis(); + } Template t = getConfig().getTemplate(template); if (t != null) @@ -162,6 +174,12 @@ public class FreeMarkerProcessor implements TemplateProcessor { throw new TemplateException(MSG_ERROR_NO_TEMPLATE, new Object[] {template}); } + + if (logger.isDebugEnabled()) + { + long endTime = System.currentTimeMillis(); + logger.debug("Time to execute template: " + (endTime - startTime) + "ms"); + } } catch (IOException ioerr) { @@ -169,8 +187,9 @@ public class FreeMarkerProcessor implements TemplateProcessor } } - private static final String PATH = "string://fixed"; - + /** + * @see org.alfresco.service.cmr.repository.TemplateProcessor#processString(java.lang.String, java.lang.Object, java.io.Writer) + */ public void processString(String template, Object model, Writer out) { if (template == null || template.length() == 0) @@ -188,8 +207,12 @@ public class FreeMarkerProcessor implements TemplateProcessor try { + long startTime = 0; if (logger.isDebugEnabled()) - logger.debug("Executing template: " + template + " on model: " + model); + { + logger.debug("Executing template: " + template);// + " on model: " + model); + startTime = System.currentTimeMillis(); + } Template t = getStringConfig(PATH, template).getTemplate(PATH); if (t != null) @@ -198,6 +221,12 @@ public class FreeMarkerProcessor implements TemplateProcessor { // perform the template processing against supplied data model t.process(model, out); + + if (logger.isDebugEnabled()) + { + long endTime = System.currentTimeMillis(); + logger.debug("Time to execute template: " + (endTime - startTime) + "ms"); + } } catch (Throwable err) { diff --git a/source/java/org/alfresco/repo/template/TemplateServiceImpl.java b/source/java/org/alfresco/repo/template/TemplateServiceImpl.java index 7ef9eefe5b..17294f2679 100644 --- a/source/java/org/alfresco/repo/template/TemplateServiceImpl.java +++ b/source/java/org/alfresco/repo/template/TemplateServiceImpl.java @@ -127,6 +127,9 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA return out.toString(); } + /** + * @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object, java.io.Writer) + */ public void processTemplateString(String engine, String template, Object model, Writer out) throws TemplateException { @@ -146,6 +149,9 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA } } + /** + * @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object) + */ public String processTemplateString(String engine, String template, Object model) throws TemplateException { @@ -154,7 +160,6 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA return out.toString(); } - /** * Return the TemplateProcessor implementation for the named template engine * @@ -169,7 +174,7 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA Map procMap = processors.get(); if (procMap == null) { - procMap = new HashMap(7, 1.0f); + procMap = new HashMap(2, 1.0f); processors.set(procMap); }