Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)

125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Raluca Munteanu
2016-04-26 13:03:25 +00:00
parent d6f9f50c39
commit dead3c3825
265 changed files with 44099 additions and 44099 deletions

View File

@@ -1,329 +1,329 @@
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.transaction.UserTransaction;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.CategoryService;
import org.alfresco.service.namespace.RegexQNamePattern;
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.repo.component.UITree.TreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CategoryBrowserPluginBean implements Serializable
{
private static final long serialVersionUID = -1493808456969763500L;
public static final String BEAN_NAME = "CategoryBrowserPluginBean";
private static final Log logger = LogFactory.getLog(CategoryBrowserPluginBean.class);
transient private CategoryService categoryService;
transient private NodeService nodeService;
private List<TreeNode> categoryRootNodes;
private Map<String, TreeNode> categoryNodes;
protected NodeRef previouslySelectedNode;
/**
* @param categoryService
* the categoryService to set
*/
public void setCategoryService(CategoryService categoryService)
{
this.categoryService = categoryService;
}
/**
* @return the categoryService
*/
private CategoryService getCategoryService()
{
//check for null in cluster environment
if(categoryService == null)
{
categoryService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getCategoryService();
}
return categoryService;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @return the nodeService
*/
private NodeService getNodeService()
{
//check for null in cluster environment
if(nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
public List<TreeNode> getCategoryRootNodes()
{
if (this.categoryRootNodes == null)
{
this.categoryRootNodes = new ArrayList<TreeNode>();
this.categoryNodes = new HashMap<String, TreeNode>();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
Collection<ChildAssociationRef> childRefs = this.getCategoryService().getRootCategories(
Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE);
for (ChildAssociationRef ref : childRefs)
{
NodeRef child = ref.getChildRef();
TreeNode node = createTreeNode(child);
this.categoryRootNodes.add(node);
this.categoryNodes.put(node.getNodeRef(), node);
}
tx.commit();
}
catch (Throwable err)
{
Utils.addErrorMessage("NavigatorPluginBean exception in getCompanyHomeRootNodes()", err);
try
{
if (tx != null)
{
tx.rollback();
}
}
catch (Exception tex)
{
}
}
}
return this.categoryRootNodes;
}
protected Map<String, TreeNode> getNodesMap()
{
return this.categoryNodes;
}
/**
* Retrieves the child folders for the noderef given in the 'noderef' parameter and caches the nodes against the area
* in the 'area' parameter.
*/
public void retrieveChildren() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMap();
if (nodeRefStr != null && currentNodes != null)
{
// get the given node's details
NodeRef parentNodeRef = new NodeRef(nodeRefStr);
TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
parentNode.setExpanded(true);
if (logger.isDebugEnabled())
logger.debug("retrieving children for noderef: " + parentNodeRef);
// remove any existing children as the latest ones will be added
// below
parentNode.removeChildren();
// get all the child folder objects for the parent
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef,
ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL);
List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
for (ChildAssociationRef ref : childRefs)
{
NodeRef nodeRef = ref.getChildRef();
logger.debug("retrieving child : " + nodeRef);
// build the XML representation of the child node
TreeNode childNode = createTreeNode(nodeRef);
parentNode.addChild(childNode);
currentNodes.put(childNode.getNodeRef(), childNode);
sortedNodes.add(childNode);
}
// order the tree nodes by the tree label
if (sortedNodes.size() > 1)
{
QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// generate the XML representation
StringBuilder xml = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
for (TreeNode childNode : sortedNodes)
{
xml.append(childNode.toXML());
}
xml.append("</nodes>");
// send the generated XML back to the tree
out.write(xml.toString());
if (logger.isDebugEnabled())
logger.debug("returning XML: " + xml.toString());
}
// commit the transaction
tx.commit();
}
catch (Throwable err)
{
try
{
if (tx != null)
{
tx.rollback();
}
}
catch (Exception tex)
{
}
}
}
/**
* Sets the state of the node given in the 'nodeRef' parameter to collapsed
*/
public void nodeCollapsed() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMap();
if (nodeRefStr != null && currentNodes != null)
{
TreeNode treeNode = currentNodes.get(nodeRefStr);
if (treeNode != null)
{
treeNode.setExpanded(false);
// we need to return something for the client to be happy!
out.write("<ok/>");
if (logger.isDebugEnabled())
logger.debug("Set node " + treeNode + " to collapsed state");
}
}
}
public void selectNode(NodeRef selectedNode, String area)
{
// if there is a currently selected node, get hold of
// it (from any of the areas) and reset to unselected
if (this.previouslySelectedNode != null)
{
TreeNode node = this.categoryNodes.get(this.previouslySelectedNode.toString());
if (node != null)
{
node.setSelected(false);
}
}
// find the node just selected and set its state to selected
if (selectedNode != null)
{
TreeNode node = this.categoryNodes.get(selectedNode.toString());
if (node != null)
{
node.setSelected(true);
}
}
this.previouslySelectedNode = selectedNode;
if (logger.isDebugEnabled())
logger.debug("Selected node: " + selectedNode);
}
/**
* Resets the selected node
*/
public void resetSelectedNode()
{
if (this.previouslySelectedNode != null)
{
TreeNode node = this.categoryNodes.get(this.previouslySelectedNode.toString());
if (node != null)
{
node.setSelected(false);
}
}
if (logger.isDebugEnabled())
logger.debug("Reset selected node: " + this.previouslySelectedNode);
}
/**
* Resets all the caches held by the bean.
*/
public void reset()
{
this.categoryNodes = null;
this.categoryRootNodes = null;
resetSelectedNode();
}
/**
* Creates a TreeNode object from the given NodeRef
*
* @param nodeRef
* The NodeRef to create the TreeNode from
*/
protected TreeNode createTreeNode(NodeRef nodeRef)
{
TreeNode node = new TreeNode(nodeRef.toString(), Repository.getNameForNode(this.getNodeService(), nodeRef),
(String) this.getNodeService().getProperty(nodeRef, ApplicationModel.PROP_ICON));
return node;
}
}
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.transaction.UserTransaction;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.CategoryService;
import org.alfresco.service.namespace.RegexQNamePattern;
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.repo.component.UITree.TreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CategoryBrowserPluginBean implements Serializable
{
private static final long serialVersionUID = -1493808456969763500L;
public static final String BEAN_NAME = "CategoryBrowserPluginBean";
private static final Log logger = LogFactory.getLog(CategoryBrowserPluginBean.class);
transient private CategoryService categoryService;
transient private NodeService nodeService;
private List<TreeNode> categoryRootNodes;
private Map<String, TreeNode> categoryNodes;
protected NodeRef previouslySelectedNode;
/**
* @param categoryService
* the categoryService to set
*/
public void setCategoryService(CategoryService categoryService)
{
this.categoryService = categoryService;
}
/**
* @return the categoryService
*/
private CategoryService getCategoryService()
{
//check for null in cluster environment
if(categoryService == null)
{
categoryService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getCategoryService();
}
return categoryService;
}
/**
* @param nodeService
* the nodeService to set
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @return the nodeService
*/
private NodeService getNodeService()
{
//check for null in cluster environment
if(nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
public List<TreeNode> getCategoryRootNodes()
{
if (this.categoryRootNodes == null)
{
this.categoryRootNodes = new ArrayList<TreeNode>();
this.categoryNodes = new HashMap<String, TreeNode>();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
tx.begin();
Collection<ChildAssociationRef> childRefs = this.getCategoryService().getRootCategories(
Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE);
for (ChildAssociationRef ref : childRefs)
{
NodeRef child = ref.getChildRef();
TreeNode node = createTreeNode(child);
this.categoryRootNodes.add(node);
this.categoryNodes.put(node.getNodeRef(), node);
}
tx.commit();
}
catch (Throwable err)
{
Utils.addErrorMessage("NavigatorPluginBean exception in getCompanyHomeRootNodes()", err);
try
{
if (tx != null)
{
tx.rollback();
}
}
catch (Exception tex)
{
}
}
}
return this.categoryRootNodes;
}
protected Map<String, TreeNode> getNodesMap()
{
return this.categoryNodes;
}
/**
* Retrieves the child folders for the noderef given in the 'noderef' parameter and caches the nodes against the area
* in the 'area' parameter.
*/
public void retrieveChildren() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
UserTransaction tx = null;
try
{
tx = Repository.getUserTransaction(context, true);
tx.begin();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMap();
if (nodeRefStr != null && currentNodes != null)
{
// get the given node's details
NodeRef parentNodeRef = new NodeRef(nodeRefStr);
TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
parentNode.setExpanded(true);
if (logger.isDebugEnabled())
logger.debug("retrieving children for noderef: " + parentNodeRef);
// remove any existing children as the latest ones will be added
// below
parentNode.removeChildren();
// get all the child folder objects for the parent
List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef,
ContentModel.ASSOC_SUBCATEGORIES, RegexQNamePattern.MATCH_ALL);
List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
for (ChildAssociationRef ref : childRefs)
{
NodeRef nodeRef = ref.getChildRef();
logger.debug("retrieving child : " + nodeRef);
// build the XML representation of the child node
TreeNode childNode = createTreeNode(nodeRef);
parentNode.addChild(childNode);
currentNodes.put(childNode.getNodeRef(), childNode);
sortedNodes.add(childNode);
}
// order the tree nodes by the tree label
if (sortedNodes.size() > 1)
{
QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
}
// generate the XML representation
StringBuilder xml = new StringBuilder(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
for (TreeNode childNode : sortedNodes)
{
xml.append(childNode.toXML());
}
xml.append("</nodes>");
// send the generated XML back to the tree
out.write(xml.toString());
if (logger.isDebugEnabled())
logger.debug("returning XML: " + xml.toString());
}
// commit the transaction
tx.commit();
}
catch (Throwable err)
{
try
{
if (tx != null)
{
tx.rollback();
}
}
catch (Exception tex)
{
}
}
}
/**
* Sets the state of the node given in the 'nodeRef' parameter to collapsed
*/
public void nodeCollapsed() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
Map params = context.getExternalContext().getRequestParameterMap();
String nodeRefStr = (String) params.get("nodeRef");
// work out which list to cache the nodes in
Map<String, TreeNode> currentNodes = getNodesMap();
if (nodeRefStr != null && currentNodes != null)
{
TreeNode treeNode = currentNodes.get(nodeRefStr);
if (treeNode != null)
{
treeNode.setExpanded(false);
// we need to return something for the client to be happy!
out.write("<ok/>");
if (logger.isDebugEnabled())
logger.debug("Set node " + treeNode + " to collapsed state");
}
}
}
public void selectNode(NodeRef selectedNode, String area)
{
// if there is a currently selected node, get hold of
// it (from any of the areas) and reset to unselected
if (this.previouslySelectedNode != null)
{
TreeNode node = this.categoryNodes.get(this.previouslySelectedNode.toString());
if (node != null)
{
node.setSelected(false);
}
}
// find the node just selected and set its state to selected
if (selectedNode != null)
{
TreeNode node = this.categoryNodes.get(selectedNode.toString());
if (node != null)
{
node.setSelected(true);
}
}
this.previouslySelectedNode = selectedNode;
if (logger.isDebugEnabled())
logger.debug("Selected node: " + selectedNode);
}
/**
* Resets the selected node
*/
public void resetSelectedNode()
{
if (this.previouslySelectedNode != null)
{
TreeNode node = this.categoryNodes.get(this.previouslySelectedNode.toString());
if (node != null)
{
node.setSelected(false);
}
}
if (logger.isDebugEnabled())
logger.debug("Reset selected node: " + this.previouslySelectedNode);
}
/**
* Resets all the caches held by the bean.
*/
public void reset()
{
this.categoryNodes = null;
this.categoryRootNodes = null;
resetSelectedNode();
}
/**
* Creates a TreeNode object from the given NodeRef
*
* @param nodeRef
* The NodeRef to create the TreeNode from
*/
protected TreeNode createTreeNode(NodeRef nodeRef)
{
TreeNode node = new TreeNode(nodeRef.toString(), Repository.getNameForNode(this.getNodeService(), nodeRef),
(String) this.getNodeService().getProperty(nodeRef, ApplicationModel.PROP_ICON));
return node;
}
}

View File

@@ -1,126 +1,126 @@
package org.alfresco.web.bean.ajax;
import java.io.File;
import java.io.Serializable;
import java.util.List;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.TempFileProvider;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.util.XMLUtil;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Bean managing the ajax servlet upload of a multi-part form containing file content
* to replace the content of a node within the repository.
*
* @author Mike Hatfield
*/
public class ContentUpdateBean implements Serializable
{
private static final long serialVersionUID = -7209326198823950952L;
private static Log logger = LogFactory.getLog(ContentUpdateBean.class);
/**
* Ajax method to update file content. A multi-part form is required as the input.
*
* "return-page" = javascript to execute on return from the upload request
* "nodeRef" = the nodeRef of the item to update the content of
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void updateFile() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = upload.parseRequest(request);
String strNodeRef = null;
String strFilename = null;
String strReturnPage = null;
File file = null;
for (FileItem item : fileItems)
{
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
strReturnPage = item.getString();
}
else if (item.isFormField() && item.getFieldName().equals("nodeRef"))
{
strNodeRef = item.getString();
}
else
{
strFilename = FilenameUtils.getName(item.getName());
file = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(file);
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax content update request: " + strFilename + " to nodeRef: " + strNodeRef + " return page: " + strReturnPage);
try
{
if (file != null && strNodeRef != null && strNodeRef.length() != 0)
{
NodeRef nodeRef = new NodeRef(strNodeRef);
if (nodeRef != null)
{
ServiceRegistry services = Repository.getServiceRegistry(fc);
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(file);
}
}
}
catch (Exception e)
{
strReturnPage = strReturnPage.replace("${UPLOAD_ERROR}", e.getMessage());
}
Document result = XMLUtil.newDocument();
Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
Node scriptText = result.createTextNode(strReturnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
logger.debug("Content update request complete.");
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
}
}
package org.alfresco.web.bean.ajax;
import java.io.File;
import java.io.Serializable;
import java.util.List;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.TempFileProvider;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.util.XMLUtil;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Bean managing the ajax servlet upload of a multi-part form containing file content
* to replace the content of a node within the repository.
*
* @author Mike Hatfield
*/
public class ContentUpdateBean implements Serializable
{
private static final long serialVersionUID = -7209326198823950952L;
private static Log logger = LogFactory.getLog(ContentUpdateBean.class);
/**
* Ajax method to update file content. A multi-part form is required as the input.
*
* "return-page" = javascript to execute on return from the upload request
* "nodeRef" = the nodeRef of the item to update the content of
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void updateFile() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = upload.parseRequest(request);
String strNodeRef = null;
String strFilename = null;
String strReturnPage = null;
File file = null;
for (FileItem item : fileItems)
{
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
strReturnPage = item.getString();
}
else if (item.isFormField() && item.getFieldName().equals("nodeRef"))
{
strNodeRef = item.getString();
}
else
{
strFilename = FilenameUtils.getName(item.getName());
file = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(file);
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax content update request: " + strFilename + " to nodeRef: " + strNodeRef + " return page: " + strReturnPage);
try
{
if (file != null && strNodeRef != null && strNodeRef.length() != 0)
{
NodeRef nodeRef = new NodeRef(strNodeRef);
if (nodeRef != null)
{
ServiceRegistry services = Repository.getServiceRegistry(fc);
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(file);
}
}
}
catch (Exception e)
{
strReturnPage = strReturnPage.replace("${UPLOAD_ERROR}", e.getMessage());
}
Document result = XMLUtil.newDocument();
Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
Node scriptText = result.createTextNode(strReturnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
logger.debug("Content update request complete.");
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
}
}

View File

@@ -1,229 +1,229 @@
package org.alfresco.web.bean.ajax;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.springframework.extensions.surf.util.URLDecoder;
import org.alfresco.web.app.servlet.BaseServlet;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.util.XMLUtil;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Bean managing the ajax servlet upload of a multi-part form containing file content
* to be added at a specific path in the server.
*
* @author Kevin Roast
*/
public class FileUploadBean implements Serializable
{
private static final long serialVersionUID = 4555828718375916674L;
private static Log logger = LogFactory.getLog(FileUploadBean.class);
/**
* Ajax method to upload file content. A multi-part form is required as the input.
*
* "return-page" = javascript to execute on return from the upload request
* "currentPath" = the cm:name based server path to upload the content into
* and the file item content.
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void uploadFile() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = upload.parseRequest(request);
FileUploadBean bean = new FileUploadBean();
String currentPath = null;
String filename = null;
String returnPage = null;
File file = null;
for (FileItem item : fileItems)
{
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
returnPage = item.getString();
}
else if (item.isFormField() && item.getFieldName().equals("currentPath"))
{
currentPath = URLDecoder.decode(item.getString());
}
else
{
filename = FilenameUtils.getName(item.getName());
file = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(file);
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax file upload request: " + filename + " to path: " + currentPath + " return page: " + returnPage);
try
{
if (file != null && currentPath != null && currentPath.length() != 0)
{
NodeRef containerRef = pathToNodeRef(fc, currentPath);
if (containerRef != null)
{
// Guess the mimetype
String mimetype = Repository.getMimeTypeForFileName(fc, filename);
// Now guess the encoding
String encoding = "UTF-8";
InputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(file));
encoding = Repository.guessEncoding(fc, is, mimetype);
}
catch (Throwable e)
{
// Bad as it is, it's not terminal
logger.error("Failed to guess character encoding of file: " + file, e);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e) {}
}
}
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(file);
cr.setMimetype(mimetype);
// create properties for content type
String author = null;
String title = null;
String description = null;
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
if (Repository.extractMetadata(fc, cr, contentProps))
{
author = (String)(contentProps.get(ContentModel.PROP_AUTHOR));
title = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_TITLE));
description = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_DESCRIPTION));
}
// default the title to the file name if not set
if (title == null)
{
title = filename;
}
ServiceRegistry services = Repository.getServiceRegistry(fc);
FileInfo fileInfo = services.getFileFolderService().create(
containerRef, filename, ContentModel.TYPE_CONTENT);
NodeRef fileNodeRef = fileInfo.getNodeRef();
// set the author aspect
if (author != null)
{
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, author);
services.getNodeService().addAspect(fileNodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
}
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, title);
titledProps.put(ContentModel.PROP_DESCRIPTION, description);
services.getNodeService().addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.setEncoding(encoding);
writer.putContent(file);
}
}
}
catch (Exception e)
{
returnPage = returnPage.replace("${UPLOAD_ERROR}", e.getMessage());
}
finally
{
if(file != null)
{
logger.debug("delete temporary file:" + file.getPath());
// Delete the temporary file
file.delete();
}
}
Document result = XMLUtil.newDocument();
Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
Node scriptText = result.createTextNode(returnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
{
logger.debug("File upload request complete.");
}
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
}
static NodeRef pathToNodeRef(FacesContext fc, String path)
{
// convert cm:name based path to a NodeRef
StringTokenizer t = new StringTokenizer(path, "/");
int tokenCount = t.countTokens();
String[] elements = new String[tokenCount];
for (int i=0; i<tokenCount; i++)
{
elements[i] = t.nextToken();
}
return BaseServlet.resolveWebDAVPath(fc, elements, false);
}
}
package org.alfresco.web.bean.ajax;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.filestore.FileContentReader;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.springframework.extensions.surf.util.URLDecoder;
import org.alfresco.web.app.servlet.BaseServlet;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.util.XMLUtil;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Bean managing the ajax servlet upload of a multi-part form containing file content
* to be added at a specific path in the server.
*
* @author Kevin Roast
*/
public class FileUploadBean implements Serializable
{
private static final long serialVersionUID = 4555828718375916674L;
private static Log logger = LogFactory.getLog(FileUploadBean.class);
/**
* Ajax method to upload file content. A multi-part form is required as the input.
*
* "return-page" = javascript to execute on return from the upload request
* "currentPath" = the cm:name based server path to upload the content into
* and the file item content.
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void uploadFile() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = upload.parseRequest(request);
FileUploadBean bean = new FileUploadBean();
String currentPath = null;
String filename = null;
String returnPage = null;
File file = null;
for (FileItem item : fileItems)
{
if (item.isFormField() && item.getFieldName().equals("return-page"))
{
returnPage = item.getString();
}
else if (item.isFormField() && item.getFieldName().equals("currentPath"))
{
currentPath = URLDecoder.decode(item.getString());
}
else
{
filename = FilenameUtils.getName(item.getName());
file = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(file);
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax file upload request: " + filename + " to path: " + currentPath + " return page: " + returnPage);
try
{
if (file != null && currentPath != null && currentPath.length() != 0)
{
NodeRef containerRef = pathToNodeRef(fc, currentPath);
if (containerRef != null)
{
// Guess the mimetype
String mimetype = Repository.getMimeTypeForFileName(fc, filename);
// Now guess the encoding
String encoding = "UTF-8";
InputStream is = null;
try
{
is = new BufferedInputStream(new FileInputStream(file));
encoding = Repository.guessEncoding(fc, is, mimetype);
}
catch (Throwable e)
{
// Bad as it is, it's not terminal
logger.error("Failed to guess character encoding of file: " + file, e);
}
finally
{
if (is != null)
{
try { is.close(); } catch (Throwable e) {}
}
}
// Try and extract metadata from the file
ContentReader cr = new FileContentReader(file);
cr.setMimetype(mimetype);
// create properties for content type
String author = null;
String title = null;
String description = null;
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(5, 1.0f);
if (Repository.extractMetadata(fc, cr, contentProps))
{
author = (String)(contentProps.get(ContentModel.PROP_AUTHOR));
title = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_TITLE));
description = DefaultTypeConverter.INSTANCE.convert(String.class, contentProps.get(ContentModel.PROP_DESCRIPTION));
}
// default the title to the file name if not set
if (title == null)
{
title = filename;
}
ServiceRegistry services = Repository.getServiceRegistry(fc);
FileInfo fileInfo = services.getFileFolderService().create(
containerRef, filename, ContentModel.TYPE_CONTENT);
NodeRef fileNodeRef = fileInfo.getNodeRef();
// set the author aspect
if (author != null)
{
Map<QName, Serializable> authorProps = new HashMap<QName, Serializable>(1, 1.0f);
authorProps.put(ContentModel.PROP_AUTHOR, author);
services.getNodeService().addAspect(fileNodeRef, ContentModel.ASPECT_AUTHOR, authorProps);
}
// apply the titled aspect - title and description
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(2, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, title);
titledProps.put(ContentModel.PROP_DESCRIPTION, description);
services.getNodeService().addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, titledProps);
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.setEncoding(encoding);
writer.putContent(file);
}
}
}
catch (Exception e)
{
returnPage = returnPage.replace("${UPLOAD_ERROR}", e.getMessage());
}
finally
{
if(file != null)
{
logger.debug("delete temporary file:" + file.getPath());
// Delete the temporary file
file.delete();
}
}
Document result = XMLUtil.newDocument();
Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
Node scriptText = result.createTextNode(returnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
{
logger.debug("File upload request complete.");
}
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
}
static NodeRef pathToNodeRef(FacesContext fc, String path)
{
// convert cm:name based path to a NodeRef
StringTokenizer t = new StringTokenizer(path, "/");
int tokenCount = t.countTokens();
String[] elements = new String[tokenCount];
for (int i=0; i<tokenCount; i++)
{
elements[i] = t.nextToken();
}
return BaseServlet.resolveWebDAVPath(fc, elements, false);
}
}

View File

@@ -1,85 +1,85 @@
package org.alfresco.web.bean.ajax;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean backing the ajax requests from the MySpaces portlet webscript.
*
* @author Kevin Roast
*/
public class MySpacesBean implements Serializable
{
private static final long serialVersionUID = -5684182834188359483L;
private static Log logger = LogFactory.getLog(MySpacesBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void createSpace() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String path = (String)requestMap.get("path");
String name = (String)requestMap.get("name");
String title = (String)requestMap.get("title");
String description = (String)requestMap.get("description");
if (logger.isDebugEnabled())
logger.debug("MySpacesBean.createSpace() path=" + path + " name=" + name +
" title=" + title + " description=" + description);
try
{
if (path != null && name != null)
{
NodeRef containerRef = FileUploadBean.pathToNodeRef(fc, path);
if (containerRef != null)
{
NodeService nodeService = Repository.getServiceRegistry(fc).getNodeService();
FileFolderService ffService = Repository.getServiceRegistry(fc).getFileFolderService();
FileInfo folderInfo = ffService.create(containerRef, name, ContentModel.TYPE_FOLDER);
if (logger.isDebugEnabled())
logger.debug("Created new folder: " + folderInfo.getNodeRef().toString());
// apply the uifacets aspect - icon, title and description properties
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, title);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, description);
nodeService.addAspect(folderInfo.getNodeRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
out.write("OK: " + folderInfo.getNodeRef().toString());
}
}
}
catch (FileExistsException ferr)
{
out.write("ERROR: A file with that name already exists.");
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
package org.alfresco.web.bean.ajax;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.model.ApplicationModel;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.spaces.CreateSpaceWizard;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean backing the ajax requests from the MySpaces portlet webscript.
*
* @author Kevin Roast
*/
public class MySpacesBean implements Serializable
{
private static final long serialVersionUID = -5684182834188359483L;
private static Log logger = LogFactory.getLog(MySpacesBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void createSpace() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String path = (String)requestMap.get("path");
String name = (String)requestMap.get("name");
String title = (String)requestMap.get("title");
String description = (String)requestMap.get("description");
if (logger.isDebugEnabled())
logger.debug("MySpacesBean.createSpace() path=" + path + " name=" + name +
" title=" + title + " description=" + description);
try
{
if (path != null && name != null)
{
NodeRef containerRef = FileUploadBean.pathToNodeRef(fc, path);
if (containerRef != null)
{
NodeService nodeService = Repository.getServiceRegistry(fc).getNodeService();
FileFolderService ffService = Repository.getServiceRegistry(fc).getFileFolderService();
FileInfo folderInfo = ffService.create(containerRef, name, ContentModel.TYPE_FOLDER);
if (logger.isDebugEnabled())
logger.debug("Created new folder: " + folderInfo.getNodeRef().toString());
// apply the uifacets aspect - icon, title and description properties
Map<QName, Serializable> uiFacetsProps = new HashMap<QName, Serializable>(4, 1.0f);
uiFacetsProps.put(ApplicationModel.PROP_ICON, CreateSpaceWizard.DEFAULT_SPACE_ICON_NAME);
uiFacetsProps.put(ContentModel.PROP_TITLE, title);
uiFacetsProps.put(ContentModel.PROP_DESCRIPTION, description);
nodeService.addAspect(folderInfo.getNodeRef(), ApplicationModel.ASPECT_UIFACETS, uiFacetsProps);
out.write("OK: " + folderInfo.getNodeRef().toString());
}
}
}
catch (FileExistsException ferr)
{
out.write("ERROR: A file with that name already exists.");
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}

View File

@@ -1,160 +1,160 @@
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.springframework.extensions.surf.util.I18NUtil;
import org.alfresco.repo.content.transform.TransformerInfoException;
import org.alfresco.repo.template.I18NMessageMethod;
import org.alfresco.repo.template.TemplateNode;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.FileTypeImageSize;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TemplateException;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.web.app.servlet.BaseTemplateContentServlet;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean used by an AJAX control to send information back on the
* requested node.
*
* @author gavinc
*/
public class NodeInfoBean implements Serializable
{
private static final long serialVersionUID = 137294178658919187L;
transient private NodeService nodeService;
private static final Log logger = LogFactory.getLog(NodeInfoBean.class);
/**
* Returns information on the node identified by the 'noderef'
* parameter found in the ExternalContext. If no noderef is supplied, then the template
* is executed without context.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendNodeInfo() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
String strTemplate = (String)requestMap.get("template");
if (strTemplate == null || strTemplate.length() == 0)
{
strTemplate = "node_summary_panel.ftl";
}
NodeRef nodeRef = null;
if (strNodeRef != null && strNodeRef.length() != 0)
{
nodeRef = new NodeRef(strNodeRef);
if (this.getNodeService().exists(nodeRef) == false)
{
out.write("<span class='errorMessage'>Node could not be found in the repository!</span>");
return;
}
}
try
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/" + strTemplate, getModel(nodeRef, requestMap), out);
}
catch (TemplateException ex)
{
// Try to catch TransformerInfoException to display it in NodeInfo pane.
// Fix bug reported in https://issues.alfresco.com/jira/browse/ETWOTWO-440
Throwable cause = ex.getCause();
while (cause != null)
{
cause = cause.getCause();
if (cause instanceof TransformerInfoException)
{
out.write("<tr><td colspan=\"2\"><span class='errorMessage'>" + cause.getMessage() + "</span></td></tr>");
return;
}
}
throw ex;
}
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param nodeService The NodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
private NodeService getNodeService()
{
if (nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(NodeRef nodeRef, Map<String, String> requestMap) throws ContentIOException
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
I18NUtil.registerResourceBundle("alfresco.messages.webclient");
// create api methods
model.put("date", new Date());
model.put("msg", new I18NMessageMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(context));
model.put("locale", I18NUtil.getLocale());
if (nodeRef != null)
{
model.put("node", new TemplateNode(
nodeRef,
Repository.getServiceRegistry(context),
this.imageResolver));
}
// add URL arguments as a map called 'args' to the root of the model
Map<String, String> args = new HashMap<String, String>(4, 1.0f);
for (String name : requestMap.keySet())
{
args.put(name, requestMap.get(name));
}
model.put("args", args);
return model;
}
/** Template Image resolver helper */
private TemplateImageResolver imageResolver = new TemplateImageResolver()
{
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
}
};
}
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.springframework.extensions.surf.util.I18NUtil;
import org.alfresco.repo.content.transform.TransformerInfoException;
import org.alfresco.repo.template.I18NMessageMethod;
import org.alfresco.repo.template.TemplateNode;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.cmr.repository.FileTypeImageSize;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TemplateException;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.web.app.servlet.BaseTemplateContentServlet;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean used by an AJAX control to send information back on the
* requested node.
*
* @author gavinc
*/
public class NodeInfoBean implements Serializable
{
private static final long serialVersionUID = 137294178658919187L;
transient private NodeService nodeService;
private static final Log logger = LogFactory.getLog(NodeInfoBean.class);
/**
* Returns information on the node identified by the 'noderef'
* parameter found in the ExternalContext. If no noderef is supplied, then the template
* is executed without context.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendNodeInfo() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
String strTemplate = (String)requestMap.get("template");
if (strTemplate == null || strTemplate.length() == 0)
{
strTemplate = "node_summary_panel.ftl";
}
NodeRef nodeRef = null;
if (strNodeRef != null && strNodeRef.length() != 0)
{
nodeRef = new NodeRef(strNodeRef);
if (this.getNodeService().exists(nodeRef) == false)
{
out.write("<span class='errorMessage'>Node could not be found in the repository!</span>");
return;
}
}
try
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/" + strTemplate, getModel(nodeRef, requestMap), out);
}
catch (TemplateException ex)
{
// Try to catch TransformerInfoException to display it in NodeInfo pane.
// Fix bug reported in https://issues.alfresco.com/jira/browse/ETWOTWO-440
Throwable cause = ex.getCause();
while (cause != null)
{
cause = cause.getCause();
if (cause instanceof TransformerInfoException)
{
out.write("<tr><td colspan=\"2\"><span class='errorMessage'>" + cause.getMessage() + "</span></td></tr>");
return;
}
}
throw ex;
}
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param nodeService The NodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
private NodeService getNodeService()
{
if (nodeService == null)
{
nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
}
return nodeService;
}
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(NodeRef nodeRef, Map<String, String> requestMap) throws ContentIOException
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
I18NUtil.registerResourceBundle("alfresco.messages.webclient");
// create api methods
model.put("date", new Date());
model.put("msg", new I18NMessageMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(context));
model.put("locale", I18NUtil.getLocale());
if (nodeRef != null)
{
model.put("node", new TemplateNode(
nodeRef,
Repository.getServiceRegistry(context),
this.imageResolver));
}
// add URL arguments as a map called 'args' to the root of the model
Map<String, String> args = new HashMap<String, String>(4, 1.0f);
for (String name : requestMap.keySet())
{
args.put(name, requestMap.get(name));
}
model.put("args", args);
return model;
}
/** Template Image resolver helper */
private TemplateImageResolver imageResolver = new TemplateImageResolver()
{
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
}
};
}

View File

@@ -1,99 +1,99 @@
package org.alfresco.web.bean.ajax;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean backing the ajax requests from various Portlet webscripts.
*
* @author Mike Hatfield
*/
public class PortletActionsBean implements Serializable
{
private static final long serialVersionUID = -8230154592621310289L;
private static Log logger = LogFactory.getLog(PortletActionsBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void deleteItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Repository.getServiceRegistry(fc).getFileFolderService().delete(new NodeRef(strNodeRef));
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void checkoutItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkout(new NodeRef(strNodeRef));
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void checkinItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Map<String, Serializable> props = new HashMap<String, Serializable>(2, 1.0f);
props.put(Version.PROP_DESCRIPTION, "");
props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkin(new NodeRef(strNodeRef), props);
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
package org.alfresco.web.bean.ajax;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.alfresco.web.bean.repository.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean backing the ajax requests from various Portlet webscripts.
*
* @author Mike Hatfield
*/
public class PortletActionsBean implements Serializable
{
private static final long serialVersionUID = -8230154592621310289L;
private static Log logger = LogFactory.getLog(PortletActionsBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void deleteItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Repository.getServiceRegistry(fc).getFileFolderService().delete(new NodeRef(strNodeRef));
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void checkoutItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkout(new NodeRef(strNodeRef));
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void checkinItem() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String strNodeRef = (String)requestMap.get("noderef");
if (strNodeRef != null && strNodeRef.length() != 0)
{
try
{
Map<String, Serializable> props = new HashMap<String, Serializable>(2, 1.0f);
props.put(Version.PROP_DESCRIPTION, "");
props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
Repository.getServiceRegistry(fc).getCheckOutCheckInService().checkin(new NodeRef(strNodeRef), props);
out.write("OK: " + strNodeRef);
}
catch (Throwable err)
{
out.write("ERROR: " + err.getMessage());
}
}
}
}

View File

@@ -1,90 +1,90 @@
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean which proxies requests to online presence servers.
*
* @author Mike Hatfield
*/
public class PresenceProxyBean implements Serializable
{
private static final long serialVersionUID = -3041576848188629589L;
private static Log logger = LogFactory.getLog(PresenceProxyBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void proxyRequest() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String url = (String)requestMap.get("url");
if (logger.isDebugEnabled())
logger.debug("PresenceProxyBean.proxyRequest() url=" + url);
if (url != null)
{
String response = getUrlResponse(url);
out.write(response);
}
}
/**
* Perform request
*/
public String getUrlResponse(String requestUrl)
{
String response = "";
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(requestUrl);
method.setRequestHeader("Accept", "*/*");
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
try
{
int statusCode = client.executeMethod(method);
if (statusCode == HttpStatus.SC_OK)
{
response = method.getResponseBodyAsString();
}
else
{
response = method.getStatusText();
}
}
catch (HttpException e)
{
response = e.getMessage();
}
catch (IOException e)
{
response = e.getMessage();
}
finally
{
// Release the connection.
method.releaseConnection();
}
return response;
}
}
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.web.app.servlet.ajax.InvokeCommand;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Bean which proxies requests to online presence servers.
*
* @author Mike Hatfield
*/
public class PresenceProxyBean implements Serializable
{
private static final long serialVersionUID = -3041576848188629589L;
private static Log logger = LogFactory.getLog(PresenceProxyBean.class);
@InvokeCommand.ResponseMimetype(value=MimetypeMap.MIMETYPE_HTML)
public void proxyRequest() throws Exception
{
FacesContext fc = FacesContext.getCurrentInstance();
ResponseWriter out = fc.getResponseWriter();
Map<String, String> requestMap = fc.getExternalContext().getRequestParameterMap();
String url = (String)requestMap.get("url");
if (logger.isDebugEnabled())
logger.debug("PresenceProxyBean.proxyRequest() url=" + url);
if (url != null)
{
String response = getUrlResponse(url);
out.write(response);
}
}
/**
* Perform request
*/
public String getUrlResponse(String requestUrl)
{
String response = "";
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(requestUrl);
method.setRequestHeader("Accept", "*/*");
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
try
{
int statusCode = client.executeMethod(method);
if (statusCode == HttpStatus.SC_OK)
{
response = method.getResponseBodyAsString();
}
else
{
response = method.getStatusText();
}
}
catch (HttpException e)
{
response = e.getMessage();
}
catch (IOException e)
{
response = e.getMessage();
}
finally
{
// Release the connection.
method.releaseConnection();
}
return response;
}
}

View File

@@ -1,144 +1,144 @@
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.template.I18NMessageMethod;
import org.alfresco.repo.template.Workflow;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.repository.FileTypeImageSize;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.web.app.servlet.BaseTemplateContentServlet;
import org.alfresco.web.bean.repository.Repository;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Bean used by an AJAX control to send information back on the requested workflow task.
*
* @author Kevin Roast
*/
public class TaskInfoBean implements Serializable
{
private static final long serialVersionUID = -6627537519541525897L;
transient private WorkflowService workflowService;
/**
* Returns information for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskInfo() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String)context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0)
{
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null)
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/task_summary_panel.ftl", getModel(task), out);
}
else
{
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
/**
* Returns the resource list for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskResources() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String)context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0)
{
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null)
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
}
else
{
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param workflowService The WorkflowService to set.
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
private WorkflowService getWorkflowService()
{
if (workflowService == null)
{
workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return workflowService;
}
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(WorkflowTask task)
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
I18NUtil.registerResourceBundle("alfresco.messages.webclient");
// create template api methods and objects
model.put("date", new Date());
model.put("msg", new I18NMessageMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(context));
model.put("locale", I18NUtil.getLocale());
model.put("task", new Workflow.WorkflowTaskItem(
Repository.getServiceRegistry(context),
this.imageResolver,
task));
return model;
}
/** Template Image resolver helper */
private TemplateImageResolver imageResolver = new TemplateImageResolver()
{
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
}
};
}
package org.alfresco.web.bean.ajax;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.alfresco.repo.template.I18NMessageMethod;
import org.alfresco.repo.template.Workflow;
import org.alfresco.repo.web.scripts.FileTypeImageUtils;
import org.alfresco.service.cmr.repository.FileTypeImageSize;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.web.app.servlet.BaseTemplateContentServlet;
import org.alfresco.web.bean.repository.Repository;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Bean used by an AJAX control to send information back on the requested workflow task.
*
* @author Kevin Roast
*/
public class TaskInfoBean implements Serializable
{
private static final long serialVersionUID = -6627537519541525897L;
transient private WorkflowService workflowService;
/**
* Returns information for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskInfo() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String)context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0)
{
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null)
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/task_summary_panel.ftl", getModel(task), out);
}
else
{
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
/**
* Returns the resource list for the workflow task identified by the 'taskId'
* parameter found in the ExternalContext.
* <p>
* The result is the formatted HTML to show on the client.
*/
public void sendTaskResources() throws IOException
{
FacesContext context = FacesContext.getCurrentInstance();
ResponseWriter out = context.getResponseWriter();
String taskId = (String)context.getExternalContext().getRequestParameterMap().get("taskId");
if (taskId == null || taskId.length() == 0)
{
throw new IllegalArgumentException("'taskId' parameter is missing");
}
WorkflowTask task = this.getWorkflowService().getTaskById(taskId);
if (task != null)
{
Repository.getServiceRegistry(context).getTemplateService().processTemplate(
"/alfresco/templates/client/task_resource_panel.ftl", getModel(task), out);
}
else
{
out.write("<span class='errorMessage'>Task could not be found.</span>");
}
}
// ------------------------------------------------------------------------------
// Bean getters and setters
/**
* @param workflowService The WorkflowService to set.
*/
public void setWorkflowService(WorkflowService workflowService)
{
this.workflowService = workflowService;
}
private WorkflowService getWorkflowService()
{
if (workflowService == null)
{
workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
}
return workflowService;
}
// ------------------------------------------------------------------------------
// Helper methods
private Map<String, Object> getModel(WorkflowTask task)
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, Object> model = new HashMap<String, Object>(8, 1.0f);
I18NUtil.registerResourceBundle("alfresco.messages.webclient");
// create template api methods and objects
model.put("date", new Date());
model.put("msg", new I18NMessageMethod());
model.put("url", new BaseTemplateContentServlet.URLHelper(context));
model.put("locale", I18NUtil.getLocale());
model.put("task", new Workflow.WorkflowTaskItem(
Repository.getServiceRegistry(context),
this.imageResolver,
task));
return model;
}
/** Template Image resolver helper */
private TemplateImageResolver imageResolver = new TemplateImageResolver()
{
public String resolveImagePathForName(String filename, FileTypeImageSize size)
{
return FileTypeImageUtils.getFileTypeImage(FacesContext.getCurrentInstance(), filename, size);
}
};
}