mirror of
https://github.com/Alfresco/acs-community-packaging.git
synced 2026-09-16 18:13:21 +00:00
- Fixes to web client so PHP templates can rendered as custom views.
- Expended PHP JAva API to provide basic read-only implementations. This allows naviagtion of a node structure, retrieval of properties and content details. - Added relevant unit tests - Implemented and tested doc_info.php example template git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5599 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -270,7 +270,7 @@ public abstract class BaseTemplateContentServlet extends BaseServlet
|
||||
* The model includes the usual template root objects such as 'companyhome', 'userhome',
|
||||
* 'person' and also includes the node specified on the servlet URL as 'space' and 'document'
|
||||
*
|
||||
* @param services ServiceRegistry required for TemplateNode construction
|
||||
* @param services ServiceRegistry
|
||||
* @param req Http request - for accessing Session and url args
|
||||
* @param templateRef NodeRef of the template itself
|
||||
* @param nodeRef NodeRef of the space/document to process template against
|
||||
@@ -295,7 +295,10 @@ public abstract class BaseTemplateContentServlet extends BaseServlet
|
||||
String name = (String)names.nextElement();
|
||||
args.put(name, req.getParameter(name));
|
||||
}
|
||||
root.put("args", args);
|
||||
root.put("args", args);
|
||||
|
||||
// Add the image resolver
|
||||
root.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
|
||||
|
||||
// method to allow client urls to be generated
|
||||
root.put("url", new URLHelper(req.getContextPath()));
|
||||
|
||||
@@ -40,11 +40,11 @@ import javax.transaction.UserTransaction;
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
@@ -615,13 +615,9 @@ public class DocumentDetailsBean extends BaseDetailsBean
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>(2, 1.0f);
|
||||
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
TemplateNode documentNode = new TemplateNode(getDocument().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("document", documentNode);
|
||||
TemplateNode spaceNode = new TemplateNode(this.navigator.getCurrentNode().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("space", spaceNode);
|
||||
model.put("document", getDocument().getNodeRef());
|
||||
model.put("space", this.navigator.getCurrentNode().getNodeRef());
|
||||
model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ import org.alfresco.filesys.smb.server.repo.ContentContext;
|
||||
import org.alfresco.filesys.smb.server.repo.ContentDiskInterface;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.rule.RuleService;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
@@ -486,15 +486,16 @@ public class NavigationBean
|
||||
public Map getTemplateModel()
|
||||
{
|
||||
HashMap model = new HashMap(1, 1.0f);
|
||||
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
TemplateNode spaceNode = new TemplateNode(getCurrentNode().getNodeRef(), Repository.getServiceRegistry(fc),
|
||||
new TemplateImageResolver() {
|
||||
public String resolveImagePathForName(String filename, boolean small) {
|
||||
return Utils.getFileTypeImage(filename, small);
|
||||
}
|
||||
});
|
||||
model.put("space", spaceNode);
|
||||
|
||||
model.put("space", getCurrentNode().getNodeRef());
|
||||
model.put(TemplateService.KEY_IMAGE_RESOLVER,
|
||||
new TemplateImageResolver()
|
||||
{
|
||||
public String resolveImagePathForName(String filename, boolean small)
|
||||
{
|
||||
return Utils.getFileTypeImage(filename, small);
|
||||
}
|
||||
});
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -37,14 +37,13 @@ import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.AlfrescoNavigationHandler;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.servlet.GuestTemplateContentServlet;
|
||||
import org.alfresco.web.app.servlet.TemplateContentServlet;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
@@ -159,11 +158,9 @@ public class SpaceDetailsBean extends BaseDetailsBean
|
||||
public Map getTemplateModel()
|
||||
{
|
||||
HashMap model = new HashMap(1, 1.0f);
|
||||
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
TemplateNode spaceNode = new TemplateNode(getSpace().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("space", spaceNode);
|
||||
|
||||
model.put("space", getSpace().getNodeRef());
|
||||
model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
@@ -123,7 +122,7 @@ public class TemplateMailHelperBean
|
||||
Map<String, Object> model = DefaultModelHelper.buildDefaultModel(
|
||||
services, Application.getCurrentUser(fc), templateRef);
|
||||
model.put("role", roleText);
|
||||
model.put("space", new TemplateNode(node, Repository.getServiceRegistry(fc), null));
|
||||
model.put("space", node);
|
||||
|
||||
body = services.getTemplateService().processTemplate("freemarker", templateRef.toString(), model);
|
||||
}
|
||||
|
||||
@@ -24,33 +24,11 @@
|
||||
*/
|
||||
package org.alfresco.web.bean.preview;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
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.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.BrowseBean;
|
||||
import org.alfresco.web.bean.NavigationBean;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.data.IDataContainer;
|
||||
import org.alfresco.web.data.QuickSort;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||
|
||||
/**
|
||||
* Backing bean for the Preview Document in Template action page
|
||||
@@ -74,17 +52,14 @@ public class DocumentPreviewBean extends BasePreviewBean
|
||||
*
|
||||
* @return model containing current document and current space info.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map getTemplateModel()
|
||||
{
|
||||
HashMap model = new HashMap(3, 1.0f);
|
||||
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
TemplateNode documentNode = new TemplateNode(getNode().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("document", documentNode);
|
||||
TemplateNode spaceNode = new TemplateNode(this.navigator.getCurrentNode().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("space", spaceNode);
|
||||
model.put("document", getNode().getNodeRef());
|
||||
model.put("space", this.navigator.getCurrentNode().getNodeRef());
|
||||
model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -24,33 +24,11 @@
|
||||
*/
|
||||
package org.alfresco.web.bean.preview;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.template.TemplateNode;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
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.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.BrowseBean;
|
||||
import org.alfresco.web.bean.NavigationBean;
|
||||
import org.alfresco.service.cmr.repository.TemplateService;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.data.IDataContainer;
|
||||
import org.alfresco.web.data.QuickSort;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||
|
||||
/**
|
||||
* Backing bean for the Preview Space in Template action page
|
||||
@@ -74,14 +52,13 @@ public class SpacePreviewBean extends BasePreviewBean
|
||||
*
|
||||
* @return model containing current document and current space info.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map getTemplateModel()
|
||||
{
|
||||
HashMap model = new HashMap(3, 1.0f);
|
||||
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
TemplateNode spaceNode = new TemplateNode(getNode().getNodeRef(),
|
||||
Repository.getServiceRegistry(fc), imageResolver);
|
||||
model.put("space", spaceNode);
|
||||
model.put("space", getNode().getNodeRef());
|
||||
model.put(TemplateService.KEY_IMAGE_RESOLVER, imageResolver);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -57,13 +57,10 @@ import org.apache.log4j.Logger;
|
||||
*/
|
||||
public class UITemplate extends SelfRenderingComponent
|
||||
{
|
||||
private final static String ENGINE_DEFAULT = "freemarker";
|
||||
//private final static String ENGINE_DEFAULT = "freemarker";
|
||||
|
||||
private static Logger logger = Logger.getLogger(UITemplate.class);
|
||||
|
||||
/** Template engine name */
|
||||
private String engine = null;
|
||||
|
||||
/** Template name/classpath */
|
||||
private String template = null;
|
||||
|
||||
@@ -93,10 +90,9 @@ public class UITemplate extends SelfRenderingComponent
|
||||
Object values[] = (Object[])state;
|
||||
// standard component attributes are restored by the super class
|
||||
super.restoreState(context, values[0]);
|
||||
this.engine = (String)values[1];
|
||||
this.template = (String)values[2];
|
||||
this.templatePath = (String)values[3];
|
||||
this.model = (Object)values[4];
|
||||
this.template = (String)values[1];
|
||||
this.templatePath = (String)values[2];
|
||||
this.model = (Object)values[3];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +101,7 @@ public class UITemplate extends SelfRenderingComponent
|
||||
public Object saveState(FacesContext context)
|
||||
{
|
||||
Object values[] = new Object[] {
|
||||
super.saveState(context), this.engine, this.template, this.templatePath, this.model};
|
||||
super.saveState(context), this.template, this.templatePath, this.model};
|
||||
return (values);
|
||||
}
|
||||
|
||||
@@ -145,24 +141,21 @@ public class UITemplate extends SelfRenderingComponent
|
||||
|
||||
if (templateRef != null && templateRef.length() != 0)
|
||||
{
|
||||
// get the class name of the processor to instantiate
|
||||
String engine = getEngine();
|
||||
|
||||
long startTime = 0;
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Using template processor name: " + engine);
|
||||
logger.debug("Using template processor");
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// get the data model to use - building default FreeMarker model as required
|
||||
Object model = getFreeMarkerModel(getModel(), templateRef);
|
||||
Object model = getTemplateModel(getModel(), templateRef);
|
||||
|
||||
// process the template against the model
|
||||
try
|
||||
{
|
||||
TemplateService templateService = Repository.getServiceRegistry(context).getTemplateService();
|
||||
templateService.processTemplate(engine, templateRef, model, context.getResponseWriter());
|
||||
templateService.processTemplate(templateRef, model, context.getResponseWriter());
|
||||
}
|
||||
catch (TemplateException err)
|
||||
{
|
||||
@@ -186,10 +179,10 @@ public class UITemplate extends SelfRenderingComponent
|
||||
*
|
||||
* @return Returns the data model to bind template against.
|
||||
*/
|
||||
private Object getFreeMarkerModel(Object model, String template)
|
||||
private Object getTemplateModel(Object model, String template)
|
||||
{
|
||||
if (getEngine().equals(ENGINE_DEFAULT))
|
||||
{
|
||||
//if (getEngine().equals(ENGINE_DEFAULT))
|
||||
//{
|
||||
// create an instance of the default FreeMarker template object model
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
ServiceRegistry services = Repository.getServiceRegistry(fc);
|
||||
@@ -215,7 +208,7 @@ public class UITemplate extends SelfRenderingComponent
|
||||
}
|
||||
|
||||
model = root;
|
||||
}
|
||||
// }
|
||||
|
||||
return model;
|
||||
}
|
||||
@@ -224,28 +217,6 @@ public class UITemplate extends SelfRenderingComponent
|
||||
// ------------------------------------------------------------------------------
|
||||
// Strongly typed component property accessors
|
||||
|
||||
/**
|
||||
* @return the name of the template engine to use.
|
||||
*/
|
||||
public String getEngine()
|
||||
{
|
||||
ValueBinding vb = getValueBinding("engine");
|
||||
if (vb != null)
|
||||
{
|
||||
this.engine = (String)vb.getValue(getFacesContext());
|
||||
}
|
||||
|
||||
return this.engine != null ? this.engine : ENGINE_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param engine the name of the template engine to use. A default is provided if none is set.
|
||||
*/
|
||||
public void setEngine(String engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the custom data model to bind template against. Not cached.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package org.alfresco.web.ui.repo.tag;
|
||||
|
||||
import javax.faces.component.UICommand;
|
||||
import javax.faces.component.UIComponent;
|
||||
|
||||
import org.alfresco.web.ui.common.tag.BaseComponentTag;
|
||||
@@ -58,7 +57,6 @@ public class TemplateTag extends BaseComponentTag
|
||||
{
|
||||
super.setProperties(component);
|
||||
|
||||
setStringProperty(component, "engine", this.engine);
|
||||
setStringProperty(component, "template", this.template);
|
||||
setStringProperty(component, "templatePath", this.templatePath);
|
||||
setStringBindingProperty(component, "model", this.model);
|
||||
@@ -71,21 +69,10 @@ public class TemplateTag extends BaseComponentTag
|
||||
{
|
||||
super.release();
|
||||
|
||||
this.engine = null;
|
||||
this.template = null;
|
||||
this.templatePath = null;
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the engine name
|
||||
*
|
||||
* @param engine the engine
|
||||
*/
|
||||
public void setEngine(String engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the template name
|
||||
@@ -121,9 +108,6 @@ public class TemplateTag extends BaseComponentTag
|
||||
/** the template name based path */
|
||||
private String templatePath;
|
||||
|
||||
/** the engine name */
|
||||
private String engine;
|
||||
|
||||
/** the template */
|
||||
private String template;
|
||||
|
||||
|
||||
@@ -1361,12 +1361,6 @@
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
|
||||
<attribute>
|
||||
<name>engine</name>
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
|
||||
<attribute>
|
||||
<name>template</name>
|
||||
|
||||
Reference in New Issue
Block a user