Search in sources :

Example 1 with MenuItemCursor

use of org.santfeliu.faces.menu.model.MenuItemCursor in project gdmatrix by gdmatrix.

the class NodeEditBean method isCustomCSS.

public boolean isCustomCSS() {
    MenuItemCursor cursor = (MenuItemCursor) getValue("#{item}");
    if (cursor == null)
        cursor = getCursor();
    String docId = (String) cursor.getDirectProperties().get(UserSessionBean.NODE_CSS);
    return docId != null;
}
Also used : MenuItemCursor(org.santfeliu.faces.menu.model.MenuItemCursor)

Example 2 with MenuItemCursor

use of org.santfeliu.faces.menu.model.MenuItemCursor in project gdmatrix by gdmatrix.

the class NodeEditBean method getEditRoles.

public Set getEditRoles() {
    HashSet roles = new HashSet();
    MenuItemCursor mic = getCursor();
    try {
        roles.addAll(mic.getEditRoles());
    } catch (Exception ex) {
    }
    return roles;
}
Also used : MenuItemCursor(org.santfeliu.faces.menu.model.MenuItemCursor) HashSet(java.util.HashSet)

Example 3 with MenuItemCursor

use of org.santfeliu.faces.menu.model.MenuItemCursor in project gdmatrix by gdmatrix.

the class NodeEditBean method getRootNodeId.

public String getRootNodeId() {
    analyzeWorkspaceChange();
    if (rootNodeId == null) {
        MenuItemCursor root = getCursor().getRoot();
        rootNodeId = root.getMid();
    }
    return rootNodeId;
}
Also used : MenuItemCursor(org.santfeliu.faces.menu.model.MenuItemCursor)

Example 4 with MenuItemCursor

use of org.santfeliu.faces.menu.model.MenuItemCursor in project gdmatrix by gdmatrix.

the class CMSListener method beforePhase.

@Override
public void beforePhase(PhaseEvent pe) {
    if (pe.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {
        forcedLanguage = MatrixConfig.getProperty(FORCED_LANGUAGE_PROP);
        if (forcedLanguage == null)
            forcedLanguage = "ca";
        try {
            String value = MatrixConfig.getProperty(REDIRECTION_LIMIT_PROP);
            redirectionLimit = (value != null ? Integer.valueOf(value) : 2);
        } catch (NumberFormatException ex) {
            // default value
            redirectionLimit = 2;
        }
        String value = MatrixConfig.getProperty(CLIENT_SECURE_PORT_PROP);
        if (value != null)
            clientSecurePort = Integer.parseInt(value);
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();
        application = context.getApplication();
        UserSessionBean userSessionBean = UserSessionBean.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
        HttpSession session = request.getSession();
        try {
            // restore request charset encoding
            String charset = (String) session.getAttribute(CHARSET_ATTR);
            if (charset != null)
                request.setCharacterEncoding(charset);
            // securize session
            enterSecureSession(session, request);
            MenuItemCursor mic = getRequestedMenuItem(request, userSessionBean);
            if (mic != null) {
                redirectByUrl(context, userSessionBean, mic);
                if (context.getResponseComplete() || context.getRenderResponse())
                    return;
                loginFromParameters(context, userSessionBean);
                if (context.getResponseComplete() || context.getRenderResponse())
                    return;
                loginFromCertificate(context, userSessionBean);
                if (context.getResponseComplete() || context.getRenderResponse())
                    return;
                redirectSecure(context, userSessionBean, mic);
                if (context.getResponseComplete() || context.getRenderResponse())
                    return;
                requestAuthentication(context, userSessionBean, mic);
                if (context.getResponseComplete() || context.getRenderResponse())
                    return;
                executeRequestedMenuItem(context, userSessionBean, mic);
            } else {
                // Normal faces lifecycle
                userChangeDetection(context, userSessionBean);
            }
        } catch (Exception ex) {
            userSessionBean.getMenuModel().setAllVisible(false);
        }
    } else if (pe.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
        FacesContext context = FacesContext.getCurrentInstance();
        if (!context.getResponseComplete()) {
            UserSessionBean userSessionBean = UserSessionBean.getCurrentInstance();
            ExternalContext externalContext = context.getExternalContext();
            HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
            response.setHeader(HttpUtils.X_USER_HEADER, userSessionBean.getUserId());
            System.out.println("\n>>>> Render ---------------------------------\n");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) HttpSession(javax.servlet.http.HttpSession) MenuItemCursor(org.santfeliu.faces.menu.model.MenuItemCursor) UserSessionBean(org.santfeliu.web.UserSessionBean) HttpServletResponse(javax.servlet.http.HttpServletResponse) MenuException(org.santfeliu.faces.menu.model.MenuException)

Example 5 with MenuItemCursor

use of org.santfeliu.faces.menu.model.MenuItemCursor in project gdmatrix by gdmatrix.

the class CMSListener method getRequestedMenuItem.

private MenuItemCursor getRequestedMenuItem(HttpServletRequest request, UserSessionBean userSessionBean) throws Exception {
    // Do not execute menuItem in forward requests
    if (request.getAttribute(FORWARD_REQUEST_URI) != null)
        return null;
    MenuItemCursor menuItem = null;
    if (userSessionBean.getWorkspaceId() == null) {
        userSessionBean.initDefaultWorkspaceId();
    }
    String workspaceId = (String) request.getParameter(WORKSPACEID_PARAM);
    if (// change workspace
    workspaceId != null) {
        userSessionBean.setWorkspaceId(workspaceId);
    }
    String browserType = (String) request.getParameter(BROWSER_TYPE_PARAM);
    if (// change browser type
    browserType != null) {
        userSessionBean.setBrowserType(browserType);
    }
    MenuModel menuModel = userSessionBean.getMenuModel();
    menuModel.setAllVisible(true);
    String mid = null;
    String topic = (String) request.getParameter(TOPIC_PARAM);
    if (// by topic
    topic != null) {
        try {
            menuItem = menuModel.getMenuItemByTopic(topic);
        } catch (// TopicNotFound or MenuItemNotFound
        MenuException ex) {
            menuItem = userSessionBean.getSelectedMenuItem();
        }
    } else // by mid
    {
        mid = (String) request.getParameter(XMID_PARAM);
        if (mid == null) {
            String method = request.getMethod();
            if ("GET".equals(method)) {
                mid = (String) request.getParameter(SMID_PARAM);
                if (mid == null && !isPathException(request)) {
                    mid = userSessionBean.getSelectedMid();
                }
            }
        }
        if (mid != null) {
            try {
                menuItem = menuModel.getMenuItemByMid(mid);
            } catch (// MenuItemNotFound
            MenuException ex) {
                menuItem = userSessionBean.getSelectedMenuItem();
            }
        }
    }
    // register menuItem in request attribute
    request.setAttribute(NEXT_MENU_ITEM_ATTR, menuItem);
    menuModel.setAllVisible(false);
    return menuItem;
}
Also used : MenuItemCursor(org.santfeliu.faces.menu.model.MenuItemCursor) MenuException(org.santfeliu.faces.menu.model.MenuException) MenuModel(org.santfeliu.faces.menu.model.MenuModel)

Aggregations

MenuItemCursor (org.santfeliu.faces.menu.model.MenuItemCursor)292 UserSessionBean (org.santfeliu.web.UserSessionBean)39 ArrayList (java.util.ArrayList)27 MenuModel (org.santfeliu.faces.menu.model.MenuModel)22 Map (java.util.Map)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 HashMap (java.util.HashMap)10 ExternalContext (javax.faces.context.ExternalContext)9 NewView (org.matrix.news.NewView)8 Date (java.util.Date)7 HashSet (java.util.HashSet)7 CMSAction (org.santfeliu.web.bean.CMSAction)7 FacesContext (javax.faces.context.FacesContext)6 ResponseWriter (javax.faces.context.ResponseWriter)6 Node (org.matrix.cms.Node)6 Locale (java.util.Locale)5 Set (java.util.Set)5 List (java.util.List)4 Document (org.matrix.doc.Document)4 HtmlBrowser (org.santfeliu.faces.browser.HtmlBrowser)4