use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class NodeInfoBean method sendNodeInfo.
/**
* 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;
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class PresenceProxyBean method proxyRequest.
@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);
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class TaskInfoBean method sendTaskInfo.
/**
* 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>");
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class CategoryBrowserPluginBean method nodeCollapsed.
/**
* 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");
}
}
}
use of javax.faces.context.ResponseWriter in project acs-community-packaging by Alfresco.
the class ContentUpdateBean method updateFile.
/**
* 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);
}
Aggregations