Search in sources :

Example 1 with BrowseBean

use of org.alfresco.web.bean.BrowseBean 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 2 with BrowseBean

use of org.alfresco.web.bean.BrowseBean in project acs-community-packaging by Alfresco.

the class UINavigator method broadcast.

/**
 * @see javax.faces.component.UIInput#broadcast(javax.faces.event.FacesEvent)
 */
public void broadcast(FacesEvent event) throws AbortProcessingException {
    if (event instanceof NavigatorEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        NavigatorEvent navEvent = (NavigatorEvent) event;
        // node or panel selected?
        switch(navEvent.getMode()) {
            case PANEL_SELECTED:
                {
                    String panelSelected = navEvent.getItem();
                    // a panel was selected, setup the context to make the panel
                    // the focus
                    NavigationBean nb = (NavigationBean) FacesHelper.getManagedBean(context, NavigationBean.BEAN_NAME);
                    if (nb != null) {
                        try {
                            if (logger.isDebugEnabled())
                                logger.debug("Selecting panel: " + panelSelected);
                            nb.processToolbarLocation(panelSelected, true);
                        } catch (InvalidNodeRefException refErr) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NOHOME), Application.getCurrentUser(context).getHomeSpaceId()), refErr);
                        } catch (Exception err) {
                            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
                        }
                    }
                    break;
                }
            case NODE_SELECTED:
                {
                    // a node was clicked in the tree
                    boolean nodeExists = true;
                    NodeRef nodeClicked = new NodeRef(navEvent.getItem());
                    // make sure the node exists still before navigating to it
                    UserTransaction tx = null;
                    try {
                        tx = Repository.getUserTransaction(context, true);
                        tx.begin();
                        NodeService nodeSvc = Repository.getServiceRegistry(context).getNodeService();
                        nodeExists = nodeSvc.exists(nodeClicked);
                        tx.commit();
                    } catch (Throwable err) {
                        try {
                            if (tx != null) {
                                tx.rollback();
                            }
                        } catch (Exception tex) {
                        }
                    }
                    if (nodeExists) {
                        // setup the context to make the node the current node
                        BrowseBean bb = (BrowseBean) FacesHelper.getManagedBean(context, BrowseBean.BEAN_NAME);
                        if (bb != null) {
                            if (logger.isDebugEnabled())
                                logger.debug("Selected node: " + nodeClicked);
                            bb.clickSpace(nodeClicked);
                        }
                    } else {
                        String msg = Application.getMessage(context, "navigator_node_deleted");
                        Utils.addErrorMessage(msg);
                    }
                    break;
                }
        }
    } else {
        super.broadcast(event);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NavigationBean(org.alfresco.web.bean.NavigationBean) BrowseBean(org.alfresco.web.bean.BrowseBean) NodeService(org.alfresco.service.cmr.repository.NodeService) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException)

Example 3 with BrowseBean

use of org.alfresco.web.bean.BrowseBean in project acs-community-packaging by Alfresco.

the class ExternalAccessServlet method service.

/**
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    String uri = req.getRequestURI();
    if (logger.isDebugEnabled())
        logger.debug("Processing URL: " + uri + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""));
    AuthenticationStatus status = servletAuthenticate(req, res);
    if (status == AuthenticationStatus.Failure) {
        return;
    }
    setNoCacheHeaders(res);
    uri = uri.substring(req.getContextPath().length());
    StringTokenizer t = new StringTokenizer(uri, "/");
    int tokenCount = t.countTokens();
    if (tokenCount < 2) {
        throw new IllegalArgumentException("Externally addressable URL did not contain all required args: " + uri);
    }
    // skip servlet name
    t.nextToken();
    String outcome = t.nextToken();
    // get rest of the tokens arguments
    String[] args = new String[tokenCount - 2];
    for (int i = 0; i < tokenCount - 2; i++) {
        args[i] = t.nextToken();
    }
    if (logger.isDebugEnabled())
        logger.debug("External outcome found: " + outcome);
    // we almost always need this bean reference
    FacesContext fc = FacesHelper.getFacesContext(req, res, getServletContext());
    BrowseBean browseBean = (BrowseBean) FacesHelper.getManagedBean(fc, "BrowseBean");
    // get services we need
    ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
    PermissionService permissionService = serviceRegistry.getPermissionService();
    // as we are potentially coming in from an external app reset the view stack
    Stack viewStack = (Stack) fc.getExternalContext().getSessionMap().get("_alfViewStack");
    if (viewStack != null) {
        viewStack.clear();
        if (logger.isDebugEnabled())
            logger.debug("Cleared view stack");
    }
    // setup is required for certain outcome requests
    if (OUTCOME_DOCDETAILS.equals(outcome)) {
        NodeRef nodeRef = null;
        if (args[0].equals(WebDAVServlet.WEBDAV_PREFIX)) {
            nodeRef = resolveWebDAVPath(fc, args);
        } else if (args.length == 3) {
            StoreRef storeRef = new StoreRef(args[0], args[1]);
            nodeRef = new NodeRef(storeRef, args[2]);
        }
        if (nodeRef != null) {
            // check that the user has at least READ access - else redirect to an error or login page
            if (!checkAccess(req, res, nodeRef, PermissionService.READ_CONTENT, true)) {
                return;
            }
            // setup the Document on the browse bean
            browseBean.setupContentAction(nodeRef.getId(), true);
        }
        // perform the appropriate JSF navigation outcome
        NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
        navigationHandler.handleNavigation(fc, null, "dialog:" + OUTCOME_DOCDETAILS);
    } else if (OUTCOME_SPACEDETAILS.equals(outcome)) {
        NodeRef nodeRef = null;
        if (args[0].equals(WebDAVServlet.WEBDAV_PREFIX)) {
            nodeRef = resolveWebDAVPath(fc, args);
        } else if (args.length == 3) {
            StoreRef storeRef = new StoreRef(args[0], args[1]);
            nodeRef = new NodeRef(storeRef, args[2]);
        }
        if (nodeRef != null) {
            // check that the user has at least READ access - else redirect to an error or login page
            if (!checkAccess(req, res, nodeRef, PermissionService.READ_CONTENT, true)) {
                return;
            }
            // setup the Space on the browse bean
            browseBean.setupSpaceAction(nodeRef.getId(), true);
        }
        // perform the appropriate JSF navigation outcome
        NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
        navigationHandler.handleNavigation(fc, null, "dialog:" + OUTCOME_SPACEDETAILS);
    } else if (OUTCOME_BROWSE.equals(outcome)) {
        NodeRef nodeRef = null;
        if (args.length != 0 && args[0].equals(WebDAVServlet.WEBDAV_PREFIX)) {
            nodeRef = resolveWebDAVPath(fc, args);
        } else if (args.length >= 3) {
            int offset = 0;
            offset = args.length - 3;
            StoreRef storeRef = new StoreRef(args[0 + offset], args[1 + offset]);
            nodeRef = new NodeRef(storeRef, args[2 + offset]);
        }
        if (nodeRef != null) {
            // check that the user has at least READ access - else redirect to an error or login page
            if (!checkAccess(req, res, nodeRef, PermissionService.READ_CONTENT, true)) {
                return;
            }
            // this call sets up the current node Id, and updates or initialises the
            // breadcrumb component with the selected node as appropriate.
            browseBean.updateUILocation(nodeRef);
            // force a "late" refresh of the BrowseBean to handle external servlet access URL
            browseBean.externalAccessRefresh();
            // check for view mode first argument
            if (args[0].equals(ARG_TEMPLATE)) {
                browseBean.setDashboardView(true);
            }
        // the above calls into BrowseBean setup the NavigationHandler automatically
        } else {
            // perform the appropriate JSF navigation outcome
            NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
            navigationHandler.handleNavigation(fc, null, outcome);
        }
    } else if (OUTCOME_MYALFRESCO.equals(outcome)) {
        // setup the Dashboard Manager ready for the page we want to display
        if (req.getParameter(ARG_PAGE) != null) {
            DashboardManager manager = (DashboardManager) FacesHelper.getManagedBean(fc, DashboardManager.BEAN_NAME);
            manager.getPageConfig().setCurrentPage(req.getParameter(ARG_PAGE));
        }
        // perform the appropriate JSF navigation outcome
        NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
        navigationHandler.handleNavigation(fc, null, outcome);
    } else if (OUTCOME_DIALOG.equals(outcome) || OUTCOME_WIZARD.equals(outcome)) {
        if (args.length != 0) {
            if (args.length > 1) {
                String currentNodeId = null;
                if (args[1].equals(WebDAVServlet.WEBDAV_PREFIX)) {
                    // Drop the first argument
                    String[] args2 = new String[args.length - 1];
                    for (int i = 1; i < args.length; i++) {
                        args2[i - 1] = args[i];
                        if (logger.isDebugEnabled()) {
                            logger.debug("Added segment " + args2[i - 1]);
                        }
                    }
                    NodeRef nodeRef = resolveWebDAVPath(fc, args2);
                    currentNodeId = nodeRef.getId();
                } else {
                    currentNodeId = args[1];
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("currentNodeId: " + currentNodeId);
                }
                // if a GUID was passed, use it to init the NavigationBean current context
                NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);
                navigator.setCurrentNodeId(currentNodeId);
                browseBean.setupSpaceAction(currentNodeId, true);
                // setup the Document on the browse bean
                // avoid java.lang.NullPointerException
                // at org.alfresco.web.bean.content.InviteContentUsersWizard.getPermissionsForType(InviteContentUsersWizard.java:49)
                // at org.alfresco.web.bean.wizard.BaseInviteUsersWizard.getRoles(BaseInviteUsersWizard.java:562)
                browseBean.setupContentAction(currentNodeId, true);
            }
            NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
            navigationHandler.handleNavigation(fc, null, outcome + ':' + args[0]);
        }
    } else if (OUTCOME_LOGOUT.equals(outcome)) {
        // special case for logout
        // invalidate ticket and clear the Security context for this thread
        Application.logOut(fc);
        res.sendRedirect(req.getContextPath() + FACES_SERVLET + Application.getLoginPage(getServletContext()));
        return;
    }
    // perform the forward to the page processed by the Faces servlet
    String viewId = fc.getViewRoot().getViewId();
    ViewSequenceUtils.nextViewSequence(fc);
    getServletContext().getRequestDispatcher(FACES_SERVLET + viewId).forward(req, res);
}
Also used : FacesContext(javax.faces.context.FacesContext) StoreRef(org.alfresco.service.cmr.repository.StoreRef) BrowseBean(org.alfresco.web.bean.BrowseBean) AlfrescoNavigationHandler(org.alfresco.web.app.AlfrescoNavigationHandler) NavigationHandler(javax.faces.application.NavigationHandler) Stack(java.util.Stack) PermissionService(org.alfresco.service.cmr.security.PermissionService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) StringTokenizer(java.util.StringTokenizer) DashboardManager(org.alfresco.web.bean.dashboard.DashboardManager) NavigationBean(org.alfresco.web.bean.NavigationBean) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 4 with BrowseBean

use of org.alfresco.web.bean.BrowseBean in project acs-community-packaging by Alfresco.

the class EditSpaceCommand 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.setActionSpace(new Node(new NodeRef(strNodeRef)));
    NavigationHandler navigationHandler = fc.getApplication().getNavigationHandler();
    navigationHandler.handleNavigation(fc, null, "dialog:editSpace");
    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)

Aggregations

FacesContext (javax.faces.context.FacesContext)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 BrowseBean (org.alfresco.web.bean.BrowseBean)4 NavigationHandler (javax.faces.application.NavigationHandler)3 ServletContext (javax.servlet.ServletContext)2 ServletRequest (javax.servlet.ServletRequest)2 ServletResponse (javax.servlet.ServletResponse)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 NavigationBean (org.alfresco.web.bean.NavigationBean)2 Node (org.alfresco.web.bean.repository.Node)2 IOException (java.io.IOException)1 Stack (java.util.Stack)1 StringTokenizer (java.util.StringTokenizer)1 AbortProcessingException (javax.faces.event.AbortProcessingException)1 UserTransaction (javax.transaction.UserTransaction)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 PermissionService (org.alfresco.service.cmr.security.PermissionService)1