As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
AndreasWhat particular benefit do you see in replacing standard web script lifecycle (executable script connecting to model and carrying out operations and then using presentation template as a view)?Grails controllers do offer extended functionality, such as :1) Single controller is responsible for multiple operations and views where webscirpt has one operation by default (unless you use parameters to select right method).2) URL mapping is more concise way of describing URL bindings than whole bunch of webscript descriptors. This is actually not about controllers but about framework approach. Webscripts approach allows better modularity, but less functional.3) Allows redirect and webflow - nice thing but embedding Spring Web Flow in the product, like Grails did, may be an overkill.Anything else you are thinking about?ThanksAlexander
<bean id="webscript.default" parent="webscript" class="org.alfresco.web.scripts.DeclarativeWebScript" scope="prototype"/>
<bean id="webscript.default" parent="webscript" class="org.alfresco.module.GroovyProcessor.WebScript.DeclarativeWebScript" scope="prototype"> <property name="serviceRegistry"> <ref bean="ServiceRegistry"/> </property> </bean>
import groovy.lang.Binding; import groovy.lang.GroovyCodeSource; import groovy.lang.GroovyShell; import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import org.alfresco.web.scripts.PresentationScriptProcessor; import org.alfresco.web.scripts.ScriptContent; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class SuperPresentationScriptProcessor extends PresentationScriptProcessor { private static final Log logger = LogFactory .getLog(SuperPresentationScriptProcessor.class); private Map<String, GroovyCodeSource> groovyScriptCache = new ConcurrentHashMap<String, GroovyCodeSource>( 256); private boolean groovyEnabled = true; public SuperPresentationScriptProcessor() { super(); logger.debug("In god we trust :)"); } /** AbstractWebScript has .js hard coded */ @Override public Object executeScript(ScriptContent location, Map<String, Object> model) { logger.debug("Execute script " + location.getPath()); String path = location.getPath(); Object retval = null; if (isGroovyEnabled() && path.endsWith(".groovy")) { logger.debug("Its groovy !"); HashMap<String, Object> variables = new HashMap<String, Object>(); Map<String, Object> mod = model; if (mod != null) { for (String key : mod.keySet()) { Object obj = mod.get(key); variables.put(key, obj); } } else { mod = new HashMap<String, Object>(); } variables.put("model", mod); GroovyCodeSource gs = this.groovyScriptCache.get(path); if (gs == null) { String codeBase = ""; String name = "Groovy_" + UUID.randomUUID().toString().replaceAll("-", ""); gs = new GroovyCodeSource(location.getInputStream(), name, ""); this.groovyScriptCache.put(path, gs); } else { logger.debug("Using cached instance of groovy script " + path); } GroovyShell groovyShell = new GroovyShell(new Binding(variables)); retval = groovyShell.evaluate(gs); logger.debug("Groovy script " + path + " executed"); } else { logger.debug("Its not groovy"); retval = super.executeScript(location, model); } logger.debug("model ready = " + model.get("ready")); return retval;// Nobody cares about it actually ! } @Override public void reset() { super.reset(); this.groovyScriptCache.clear(); } /** * AbstractWebScript passes .js hardcoded - try .js and .groovy * protected ScriptDetails getExecuteScript(String mimetype) * ScriptResourceHelper.recurseScriptImports calls * ScriptResourceLoader.loadScriptResource */ @Override public ScriptContent findScript(String path) { logger.debug("find script " + path); String basePath = path.replaceAll("\\.js", ""); ScriptContent scriptContent = super.findScript(basePath + ".js"); if (scriptContent == null && isGroovyEnabled()) { logger.debug("No script with path " + basePath + ".js found, trying " + basePath + ".groovy"); scriptContent = super.findScript(basePath + ".groovy"); } if (scriptContent != null) { logger.debug("Got script for base path " + basePath + " : " + scriptContent.getPath()); } else { logger.debug("Got no script for base path " + basePath); } return scriptContent; } public boolean isGroovyEnabled() { return groovyEnabled; } public void setGroovyEnabled(boolean groovyEnabled) { this.groovyEnabled = groovyEnabled; } }
def documentPath = nodeService.getPath(document)