01-29-2009 04:31 AM
02-02-2009 03:06 PM
02-02-2009 11:38 PM
02-03-2009 12:42 AM
02-03-2009 10:00 AM
02-06-2009 08:27 PM
<bean id="webscript.default" parent="webscript" class="org.alfresco.web.scripts.DeclarativeWebScript" scope="prototype"/>
has to be changed to:
<bean id="webscript.default" parent="webscript" class="org.alfresco.module.GroovyProcessor.WebScript.DeclarativeWebScript" scope="prototype">
<property name="serviceRegistry">
<ref bean="ServiceRegistry"/>
</property>
</bean>
02-07-2009 04:38 AM
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;
}
}
02-08-2009 08:29 AM
02-09-2009 12:05 AM
02-10-2009 02:32 PM
def documentPath = nodeService.getPath(document)
02-10-2009 03:13 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.