if (request.getCookies() != null) { selectedOrg = RequestUtil.getCookieValue(RequestUtil.PROP_COOKIE_ORG, request.getCookies()); }
if (request.getCookies() != null) selectedOrg = RequestUtil.getCookieValue((String) config.get(RequestUtil.PROP_COOKIE_ORG), request.getCookies());
    private void showLoginPage(final HttpServletRequest request, final HttpServletResponse response, String errorType)    throws IOException, ServletException {        // Get configuration.        final Properties config = getConfig();        HashMap serviceProperties = null;        // Get the login ticket name and set the base authentication page URL.        final String loginTicketId = request.getParameter(config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM));        request.setAttribute(RequestUtil.ATTR_BASE_URL, config.getProperty(RequestUtil.PROP_LOGIN_URL_PREFIX) + "?" + config.getProperty(RequestUtil.PROP_LOGIN_TICKET_PARAM) + "=" + loginTicketId);        // Get service properties and set security level.        try {            serviceProperties = MoriaController.getServiceProperties(loginTicketId);            request.setAttribute(RequestUtil.ATTR_SEC_LEVEL, "" + MoriaController.getSecLevel(loginTicketId));        } catch (UnknownTicketException e) {            errorType = RequestUtil.ERROR_UNKNOWN_TICKET;        } catch (IllegalInputException e) {            errorType = RequestUtil.ERROR_UNKNOWN_TICKET;        } catch (InoperableStateException e) {            errorType = RequestUtil.ERROR_MORIA_DOWN;        }        // Set error message, if any.        request.setAttribute(RequestUtil.ATTR_ERROR_TYPE, errorType);        // Decide which language to use for login page.        String serviceLang = null;        if (serviceProperties != null)            serviceLang = (String) serviceProperties.get(RequestUtil.CONFIG_LANG);        String langFromCookie = null;        if (request.getCookies() != null)            langFromCookie = RequestUtil.getCookieValue((String) config.get(RequestUtil.PROP_COOKIE_LANG), request.getCookies());        final ResourceBundle bundle = RequestUtil.getBundle(RequestUtil.BUNDLE_LOGIN, request.getParameter(RequestUtil.PARAM_LANG), langFromCookie, serviceLang, request.getHeader("Accept-Language"), (String) config.get(RequestUtil.PROP_LOGIN_DEFAULT_LANGUAGE));        request.setAttribute(RequestUtil.ATTR_BUNDLE, bundle);        /* Configured values */        request.setAttribute(RequestUtil.ATTR_ORGANIZATIONS, RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_ORG, bundle.getLocale().getLanguage()));        request.setAttribute(RequestUtil.ATTR_LANGUAGES, RequestUtil.parseConfig(getConfig(), RequestUtil.PROP_LANGUAGE, RequestUtil.PROP_COMMON));        /* Selected realm */        String selectedOrg = request.getParameter(RequestUtil.PARAM_ORG);        if (selectedOrg == null || selectedOrg.equals("")) {            if (request.getCookies() != null) {                selectedOrg = RequestUtil.getCookieValue(RequestUtil.PROP_COOKIE_ORG, request.getCookies());            }            if (selectedOrg == null || selectedOrg.equals("")) {                if (serviceProperties != null) {                    selectedOrg = (String) serviceProperties.get(RequestUtil.CONFIG_HOME);                }            }        }        request.setAttribute(RequestUtil.ATTR_SELECTED_ORG, selectedOrg);        // Did the user select a different language?        request.setAttribute(RequestUtil.ATTR_SELECTED_LANG, bundle.getLocale());        if (request.getParameter(RequestUtil.PARAM_LANG) != null)            response.addCookie(RequestUtil.createCookie((String) config.get(RequestUtil.PROP_COOKIE_LANG), request.getParameter(RequestUtil.PARAM_LANG), new Integer((String) config.get(RequestUtil.PROP_COOKIE_LANG_TTL)).intValue()));        /* Service attributes */        if (serviceProperties != null) {            request.setAttribute(RequestUtil.ATTR_CLIENT_NAME, serviceProperties.get(RequestUtil.CONFIG_DISPLAY_NAME));            request.setAttribute(RequestUtil.ATTR_CLIENT_URL, serviceProperties.get(RequestUtil.CONFIG_URL));        }        /* Process jsp */        final RequestDispatcher rd = getServletContext().getNamedDispatcher("Login.JSP");        rd.forward(request, response);    }