Search in sources :

Example 61 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class EditNodeCategoriesDialog method init.

// ------------------------------------------------------------------------------
// Dialog implementation
@Override
public void init(Map<String, String> parameters) {
    super.init(parameters);
    // reset variables
    this.categories = null;
    this.addedCategory = null;
    // retrieve parameters
    String nodeRef = parameters.get("nodeRef");
    // make sure nodeRef was supplied
    ParameterCheck.mandatoryString("nodeRef", nodeRef);
    // create the node
    this.node = new Node(new NodeRef(nodeRef));
    // determine description for dialog
    FacesContext context = FacesContext.getCurrentInstance();
    if (getDictionaryService().isSubClass(this.node.getType(), ContentModel.TYPE_FOLDER)) {
        this.description = Application.getMessage(context, "editcategory_space_description");
    } else {
        this.description = Application.getMessage(context, "editcategory_description");
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) Node(org.alfresco.web.bean.repository.Node)

Example 62 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class ClipboardBean method addClipboardNode.

/**
 * Add a clipboard node to the clipboard ready for a cut/copy operation
 *
 * @param ref     NodeRef of the item for the operation
 * @param parent  Parent of the item for the operation
 * @param mode    ClipboardStatus for the operation
 */
private void addClipboardNode(NodeRef ref, NodeRef parent, ClipboardStatus mode) {
    // construct item based on store protocol
    ClipboardItem item = null;
    if (StoreRef.PROTOCOL_WORKSPACE.equals(ref.getStoreRef().getProtocol())) {
        item = new WorkspaceClipboardItem(ref, parent, mode, customPasteViewIds);
    }
    if (item != null) {
        // check for duplicates first
        boolean foundDuplicate = false;
        for (int i = 0; i < items.size(); i++) {
            if (items.get(i).equals(item)) {
                // found a duplicate replace with new instance as copy mode may have changed
                items.set(i, item);
                foundDuplicate = true;
                break;
            }
        }
        // if duplicate not found, then append to list
        if (foundDuplicate == false) {
            items.add(item);
        }
        // add a message to inform the user of the clipboard state now if configured
        FacesContext context = FacesContext.getCurrentInstance();
        if (Application.getClientConfig(context).isClipboardStatusVisible()) {
            String pattern = Application.getMessage(context, "node_added_clipboard");
            String msg = MessageFormat.format(pattern, items.size());
            FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
            context.addMessage(null, facesMsg);
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) FacesMessage(javax.faces.application.FacesMessage)

Example 63 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class AjaxServlet method service.

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    // set default character encoding for the response
    response.setCharacterEncoding("utf-8");
    response.setContentType("text/xml;charset=UTF-8");
    long startTime = 0;
    String uri = request.getRequestURI();
    if (logger.isDebugEnabled()) {
        final String queryString = request.getQueryString();
        logger.debug("Processing URL: " + uri + ((queryString != null && queryString.length() > 0) ? ("?" + queryString) : ""));
    }
    // dump the request headers
    if (headersLogger.isDebugEnabled()) {
        final Enumeration<?> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            final String name = (String) headers.nextElement();
            headersLogger.debug(name + ": " + request.getHeader(name));
        }
    }
    try {
        // Make sure the user is authenticated, if not throw an error to return the
        // 500 Internal Server Error code back to the client
        AuthenticationStatus status = servletAuthenticate(request, response, false);
        if (status == AuthenticationStatus.Failure) {
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied: User not authenticated");
            return;
        }
        setNoCacheHeaders(response);
        uri = uri.substring(request.getContextPath().length() + "/".length());
        final String[] tokens = uri.split("/");
        if (tokens.length < 3) {
            throw new AlfrescoRuntimeException("Servlet URL did not contain all required args: " + uri);
        }
        // retrieve the command from the URL
        final String commandName = tokens[1];
        // retrieve the binding expression from the URL
        final String expression = tokens[2];
        // setup the faces context
        final FacesContext facesContext = FacesHelper.getFacesContext(request, response, getServletContext());
        // start a timer
        if (perfLogger.isDebugEnabled())
            startTime = System.currentTimeMillis();
        // instantiate the relevant command
        AjaxCommand command = null;
        if (Command.invoke.toString().equals(commandName)) {
            command = new InvokeCommand();
        } else if (Command.get.toString().equals(commandName)) {
            command = new GetCommand();
        } else {
            throw new AlfrescoRuntimeException("Unrecognised command received: " + commandName);
        }
        // execute the command
        command.execute(facesContext, expression, request, response);
    } catch (RuntimeException error) {
        handleError(response, error);
    } finally {
        // measure the time taken
        if (perfLogger.isDebugEnabled()) {
            perfLogger.debug("Time to execute command: " + (System.currentTimeMillis() - startTime) + "ms");
        }
        ContextHolder.setContext(null);
    }
}
Also used : AuthenticationStatus(org.alfresco.web.app.servlet.AuthenticationStatus) FacesContext(javax.faces.context.FacesContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 64 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class EditContentPropertiesCommand method execute.

/**
 * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
 */
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
    ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
    ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
    ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
    FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
    BrowseBean browseBean = (BrowseBean) FacesHelper.getManagedBean(fc, BrowseBean.BEAN_NAME);
    // setup context from url args in properties map
    String strNodeRef = (String) properties.get(PROP_NODEREF);
    ParameterCheck.mandatoryString(PROP_NODEREF, strNodeRef);
    browseBean.setDocument(new Node(new NodeRef(strNodeRef)));
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:editContentProperties");
    String viewId = fc.getViewRoot().getViewId();
    try {
        sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
    } catch (Exception e) {
        throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
    }
    return null;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) BrowseBean(org.alfresco.web.bean.BrowseBean) Node(org.alfresco.web.bean.repository.Node) ServletContext(javax.servlet.ServletContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 65 with FacesContext

use of javax.faces.context.FacesContext in project acs-community-packaging by Alfresco.

the class ManageTaskDialogCommand method execute.

/**
 * @see org.alfresco.web.app.servlet.command.Command#execute(org.alfresco.service.ServiceRegistry, java.util.Map)
 */
public Object execute(ServiceRegistry serviceRegistry, Map<String, Object> properties) {
    ServletContext sc = (ServletContext) properties.get(PROP_SERVLETCONTEXT);
    ServletRequest req = (ServletRequest) properties.get(PROP_REQUEST);
    ServletResponse res = (ServletResponse) properties.get(PROP_RESPONSE);
    FacesContext fc = FacesHelper.getFacesContext(req, res, sc, "/jsp/close.jsp");
    WorkflowBean wfBean = (WorkflowBean) FacesHelper.getManagedBean(fc, WorkflowBean.BEAN_NAME);
    // setup dialog context from url args in properties map
    String taskId = (String) properties.get(PROP_TASKID);
    ParameterCheck.mandatoryString(PROP_TASKID, taskId);
    String taskType = (String) properties.get(PROP_TASKTYPE);
    ParameterCheck.mandatoryString(PROP_TASKTYPE, taskType);
    wfBean.setupTaskDialog(taskId, taskType);
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:manageTask");
    String viewId = fc.getViewRoot().getViewId();
    try {
        sc.getRequestDispatcher(BaseServlet.FACES_SERVLET + viewId).forward(req, res);
    } catch (Exception e) {
        throw new AlfrescoRuntimeException("Unable to forward to viewId: " + viewId, e);
    }
    return null;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) FacesContext(javax.faces.context.FacesContext) ServletContext(javax.servlet.ServletContext) WorkflowBean(org.alfresco.web.bean.workflow.WorkflowBean) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NavigationHandler(javax.faces.application.NavigationHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

FacesContext (javax.faces.context.FacesContext)361 NodeRef (org.alfresco.service.cmr.repository.NodeRef)61 Node (org.alfresco.web.bean.repository.Node)44 UserTransaction (javax.transaction.UserTransaction)43 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)27 ExternalContext (javax.faces.context.ExternalContext)26 SelectItem (javax.faces.model.SelectItem)26 QName (org.alfresco.service.namespace.QName)25 FacesMessage (javax.faces.application.FacesMessage)24 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)22 Map (java.util.Map)21 ResourceBundle (java.util.ResourceBundle)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)19 MapNode (org.alfresco.web.bean.repository.MapNode)18 UIViewRoot (javax.faces.component.UIViewRoot)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)16 Serializable (java.io.Serializable)15