Search in sources :

Example 46 with ResponseWriter

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;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResponseWriter(javax.faces.context.ResponseWriter) TemplateException(org.alfresco.service.cmr.repository.TemplateException) TransformerInfoException(org.alfresco.repo.content.transform.TransformerInfoException)

Example 47 with ResponseWriter

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);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter)

Example 48 with ResponseWriter

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>");
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask)

Example 49 with ResponseWriter

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");
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 50 with ResponseWriter

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);
}
Also used : FacesContext(javax.faces.context.FacesContext) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) FileItem(org.apache.commons.fileupload.FileItem) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) ResponseWriter(javax.faces.context.ResponseWriter) ExternalContext(javax.faces.context.ExternalContext) ServiceRegistry(org.alfresco.service.ServiceRegistry) File(java.io.File)

Aggregations

ResponseWriter (javax.faces.context.ResponseWriter)88 Map (java.util.Map)16 UIComponent (javax.faces.component.UIComponent)14 FacesContext (javax.faces.context.FacesContext)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 ResourceBundle (java.util.ResourceBundle)10 NodeService (org.alfresco.service.cmr.repository.NodeService)10 Iterator (java.util.Iterator)9 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 List (java.util.List)7 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)5 UserTransaction (javax.transaction.UserTransaction)5 UIModeList (org.alfresco.web.ui.common.component.UIModeList)5 Serializable (java.io.Serializable)4 Node (org.alfresco.web.bean.repository.Node)4 QuickSort (org.alfresco.web.data.QuickSort)3 UIListItem (org.alfresco.web.ui.common.component.UIListItem)3