Web Scripts:

- samples
- fix "execute" javascript error
- fix hidden exception when status template had errors
- addition of 'roothome' script & template root object

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6011 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-18 22:34:29 +00:00
parent e2dd65b1b4
commit 5f5d83d00b
6 changed files with 42 additions and 10 deletions

View File

@@ -34,7 +34,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.jscript.ScriptableHashMap;
import org.alfresco.repo.template.AbsoluteUrlMethod;
import org.alfresco.service.ServiceRegistry;
@@ -226,16 +225,21 @@ public abstract class AbstractWebScript implements WebScript
if (getDescription().getRequiredAuthentication() != RequiredAuthentication.none &&
getDescription().getRequiredTransaction() != RequiredTransaction.none)
{
NodeRef rootHome = scriptContext.getRootHome();
if (rootHome != null)
{
model.put("roothome", rootHome);
}
NodeRef companyHome = scriptContext.getCompanyHome();
if (companyHome != null)
{
model.put("companyhome", new ScriptNode(scriptContext.getCompanyHome(), serviceRegistry));
model.put("companyhome", companyHome);
}
NodeRef person = scriptContext.getPerson();
if (person != null)
{
model.put("person", new ScriptNode(person, serviceRegistry));
model.put("userhome", new ScriptNode(scriptContext.getUserHome(person), serviceRegistry));
model.put("person", person);
model.put("userhome", scriptContext.getUserHome(person));
}
}
@@ -273,10 +277,15 @@ public abstract class AbstractWebScript implements WebScript
if (getDescription().getRequiredAuthentication() != RequiredAuthentication.none &&
getDescription().getRequiredTransaction() != RequiredTransaction.none)
{
NodeRef rootHome = scriptContext.getRootHome();
if (rootHome != null)
{
model.put("roothome", rootHome);
}
NodeRef companyHome = scriptContext.getCompanyHome();
if (companyHome != null)
{
model.put("companyhome", scriptContext.getCompanyHome());
model.put("companyhome", companyHome);
}
NodeRef person = scriptContext.getPerson();
if (person != null)
@@ -316,7 +325,10 @@ public abstract class AbstractWebScript implements WebScript
*/
final protected void renderTemplate(String templatePath, Map<String, Object> model, Writer writer)
{
long start = System.currentTimeMillis();
getWebScriptRegistry().getTemplateProcessor().process(templatePath, model, writer);
if (logger.isDebugEnabled())
logger.debug("Rendered template " + templatePath + " in " + (System.currentTimeMillis() - start) + "ms");
}
/**
@@ -521,7 +533,10 @@ public abstract class AbstractWebScript implements WebScript
*/
final protected void executeScript(ScriptLocation location, Map<String, Object> model)
{
long start = System.currentTimeMillis();
getWebScriptRegistry().getScriptProcessor().executeScript(location, model);
if (logger.isDebugEnabled())
logger.debug("Executed script " + location.toString() + " in " + (System.currentTimeMillis() - start) + "ms");
}
/**

View File

@@ -105,7 +105,7 @@ public class ScriptProcessor
*/
public Object executeScript(ScriptLocation location, Map<String, Object> model)
{
return scriptService.executeScript(location, model);
return scriptService.executeScript("javascript", location, model);
}
/**

View File

@@ -24,6 +24,7 @@
*/
package org.alfresco.web.scripts;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.alfresco.repo.template.FreeMarkerProcessor;
@@ -123,8 +124,13 @@ public class TemplateProcessor extends FreeMarkerProcessor implements Applicatio
Template template = templateConfig.getTemplate(templatePath);
hasTemplate = (template != null);
}
catch(FileNotFoundException e)
{
// NOTE: return false as template is not found
}
catch(IOException e)
{
throw new WebScriptException("Failed to retrieve template " + templatePath, e);
}
return hasTemplate;
}

View File

@@ -188,6 +188,17 @@ public class WebScriptContext implements ApplicationContextAware, ApplicationLis
});
}
/**
* Gets the root home of the company home store
*
* @return root node ref
*/
public NodeRef getRootHome()
{
return nodeService.getRootNode(companyHomeStore);
}
/**
* Gets the Company Home
*
@@ -224,5 +235,5 @@ public class WebScriptContext implements ApplicationContextAware, ApplicationLis
{
return (NodeRef)nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
}
}