From 1757cec4f86ef2350ed86278500d500d5cd7affd Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Thu, 27 Apr 2006 09:39:25 +0000 Subject: [PATCH] Checkpoint for the Rhino Script engine integration git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2720 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/application-context.xml | 1 + config/alfresco/public-services-context.xml | 45 ++++++++++- .../public-services-security-context.xml | 10 ++- config/alfresco/script-services-context.xml | 13 ++++ .../repo/template/TemplateServiceImpl.java | 6 +- .../cmr/repository/ScriptException.java | 61 +++++++++++++++ .../service/cmr/repository/ScriptService.java | 77 +++++++++++++++++++ .../service/cmr/repository/TemplateNode.java | 6 +- .../cmr/repository/TemplateService.java | 10 ++- 9 files changed, 214 insertions(+), 15 deletions(-) create mode 100644 config/alfresco/script-services-context.xml create mode 100644 source/java/org/alfresco/service/cmr/repository/ScriptException.java create mode 100644 source/java/org/alfresco/service/cmr/repository/ScriptService.java diff --git a/config/alfresco/application-context.xml b/config/alfresco/application-context.xml index 5a8d463010..4193a16672 100644 --- a/config/alfresco/application-context.xml +++ b/config/alfresco/application-context.xml @@ -16,6 +16,7 @@ + diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 645979f4b0..3169bd93d2 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -784,8 +784,7 @@ - - + @@ -822,7 +821,9 @@ + + org.alfresco.service.cmr.repository.TemplateService @@ -858,7 +859,47 @@ + + + + + + org.alfresco.service.cmr.repository.ScriptService + + + + + + + + + + + + + + + + + + + ${server.transaction.mode.default} + + + + + + + org.alfresco.service.cmr.repository.ScriptService + + + ScriptService Service + + + + + org.alfresco.service.cmr.model.FileFolderService diff --git a/config/alfresco/public-services-security-context.xml b/config/alfresco/public-services-security-context.xml index c1165c8a98..853fb2caba 100644 --- a/config/alfresco/public-services-security-context.xml +++ b/config/alfresco/public-services-security-context.xml @@ -671,8 +671,16 @@ - + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/script-services-context.xml b/config/alfresco/script-services-context.xml new file mode 100644 index 0000000000..464564d7de --- /dev/null +++ b/config/alfresco/script-services-context.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/repo/template/TemplateServiceImpl.java b/source/java/org/alfresco/repo/template/TemplateServiceImpl.java index 1dcd768708..7ef9eefe5b 100644 --- a/source/java/org/alfresco/repo/template/TemplateServiceImpl.java +++ b/source/java/org/alfresco/repo/template/TemplateServiceImpl.java @@ -128,7 +128,7 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA } public void processTemplateString(String engine, String template, Object model, Writer out) - throws TemplateException + throws TemplateException { try { @@ -146,15 +146,13 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA } } - public String processTemplateString(String engine, String template, Object model) - throws TemplateException + throws TemplateException { Writer out = new StringWriter(1024); processTemplateString(engine, template, model, out); return out.toString(); } - /** diff --git a/source/java/org/alfresco/service/cmr/repository/ScriptException.java b/source/java/org/alfresco/service/cmr/repository/ScriptException.java new file mode 100644 index 0000000000..111c9d181b --- /dev/null +++ b/source/java/org/alfresco/service/cmr/repository/ScriptException.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.service.cmr.repository; + +import org.alfresco.error.AlfrescoRuntimeException; + +/** + * @author Kevin Roast + */ +public class ScriptException extends AlfrescoRuntimeException +{ + /** + * @param msgId + */ + public ScriptException(String msgId) + { + super(msgId); + } + + /** + * @param msgId + * @param cause + */ + public ScriptException(String msgId, Throwable cause) + { + super(msgId, cause); + } + + /** + * @param msgId + * @param params + */ + public ScriptException(String msgId, Object[] params) + { + super(msgId, params); + } + + /** + * @param msgId + * @param msgParams + * @param cause + */ + public ScriptException(String msgId, Object[] msgParams, Throwable cause) + { + super(msgId, msgParams, cause); + } +} diff --git a/source/java/org/alfresco/service/cmr/repository/ScriptService.java b/source/java/org/alfresco/service/cmr/repository/ScriptService.java new file mode 100644 index 0000000000..0586120787 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/repository/ScriptService.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2005 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + */ +package org.alfresco.service.cmr.repository; + +import java.io.Writer; +import java.util.Map; + +/** + * Script Service. + *

+ * Provides an interface to services for executing the JavaScript engine against a script file + * against a Java object based scripting data model. + *

+ * The template file can either be in the repository (passed as NodeRef string) or on the classpath. + * Also a script String can be passed directly to the service via the executeScriptString() methods. + * Java objects are passed into the scripting engine and methods can be accessed directly from the script. + *

+ * A script is executed within a single transaction, any modifications to nodes or properties that fail + * and cause a rollback will rollback the entire script transaction. + * + * @author Kevin Roast + */ +public interface ScriptService +{ + /** + * Process a script against the supplied data model. + * + * @param scriptClasspath Script location as qualified classpath name + * @param model Object model to process script against + * + * @return output of the script (may be null or any valid wrapped JavaScript object) + * + * @throws ScriptException + */ + public Object executeScript(String scriptClasspath, Map model) + throws ScriptException; + + /** + * Process a script against the supplied data model. + * + * @param scriptRef Script NodeRef location + * @param model Object model to process script against + * + * @return output of the script (may be null or any valid wrapped JavaScript object) + * + * @throws ScriptException + */ + public Object executeScript(NodeRef scriptRef, Map model) + throws ScriptException; + + /** + * Process a script against the supplied data model. + * + * @param script Script content as a String. + * @param model Object model to process script against + * + * @return output of the script (may be null or any valid wrapped JavaScript object) + * + * @throws ScriptException + */ + public Object executeScriptString(String script, Map model) + throws ScriptException; +} diff --git a/source/java/org/alfresco/service/cmr/repository/TemplateNode.java b/source/java/org/alfresco/service/cmr/repository/TemplateNode.java index b8a0d3c58f..9341562d0b 100644 --- a/source/java/org/alfresco/service/cmr/repository/TemplateNode.java +++ b/source/java/org/alfresco/service/cmr/repository/TemplateNode.java @@ -91,8 +91,7 @@ public final class TemplateNode implements Serializable private Long size = null; private TemplateImageResolver imageResolver = null; private TemplateNode parent = null; - - private ChildAssociationRef primaryParentAssoc; + private ChildAssociationRef primaryParentAssoc = null; /** @@ -494,8 +493,7 @@ public final class TemplateNode implements Serializable } /** - * - * @return the primary parent association so we can get at the association QName and the association type QName. + * @return the primary parent association so we can access the association QName and association type QName. */ public ChildAssociationRef getPrimaryParentAssoc() { diff --git a/source/java/org/alfresco/service/cmr/repository/TemplateService.java b/source/java/org/alfresco/service/cmr/repository/TemplateService.java index e1ee46e7db..ff278cd529 100644 --- a/source/java/org/alfresco/service/cmr/repository/TemplateService.java +++ b/source/java/org/alfresco/service/cmr/repository/TemplateService.java @@ -25,8 +25,10 @@ import java.io.Writer; * and data model. *

* The service provides a configured list of available template engines. The template file - * can either be in the repository (passed as NodeRef string) or on the classpath. The data - * model is specified to the template engine. The FreeMarker template engine is used by default. + * can either be in the repository (passed as NodeRef string) or on the classpath. Also a template + * can be passed directly as a String using the processTemplateString() methods. + *

+ * The data model is specified to the template engine. The FreeMarker template engine is used by default. * * @author Kevin Roast */ @@ -67,7 +69,7 @@ public interface TemplateService * @throws TemplateException */ public String processTemplateString(String engine, String template, Object model) - throws TemplateException; + throws TemplateException; /** * Process a given template, provided as a string, against the supplied data model and report the @@ -81,7 +83,7 @@ public interface TemplateService * @throws TemplateException */ public void processTemplateString(String engine, String template, Object model, Writer out) - throws TemplateException; + throws TemplateException; /** * Return a TemplateProcessor instance for the specified engine name.