log.info("DEBUG: 8");
    private Template genLoginTemplate(HttpServletRequest request, HttpServletResponse response, Context context, Session session, String errorType) throws ParseErrorException, ResourceNotFoundException, MissingResourceException, Exception {        String bundleName = "login";        String acceptLanguage = request.getHeader("Accept-Language");        String sessionID = null;        ResourceBundle bundle = null;        ResourceBundle fallback = null;        log.info("DEBUG: 1");        if (session != null) {        log.info("DEBUG: 2");            sessionID = session.getID();        log.info("DEBUG: 3");            if (!session.authenticationInitiated()) {        log.info("DEBUG: 4");                log.warning("User tried to authenticate without requesting login page first. "+session.getID());                throw new Exception("Login page has to be requested before attempting login.");            }        }        if (acceptLanguage == null || acceptLanguage.equals(""))         log.info("DEBUG: 5");            acceptLanguage = "no";        StringTokenizer tokenizer = new StringTokenizer(acceptLanguage, ",");        Locale locale = null;        log.info("DEBUG: 6");        /* Find fallback resource bundle. */        try {        log.info("DEBUG: 7");            fallback = ResourceBundle.getBundle(bundleName, new Locale("bogus"));        }        catch (MissingResourceException e) {        log.info("DEBUG: 8");            /* No fallback */        }                    /* Parse Accept-Language and find matching resource bundle */        while (tokenizer.hasMoreTokens()) {        log.info("DEBUG: 9");            String lang = tokenizer.nextToken();            int index;        log.info("DEBUG: 10");            /* Languages are devided by ";" */            if ((index = lang.indexOf(";")) != -1) {        log.info("DEBUG: 11");                lang = lang.substring(0, index);            }        log.info("DEBUG: 12");            lang = lang.trim();        log.info("DEBUG: 13");            /* Language and country is devided by "-" (optional) */            if ((index = lang.indexOf("-")) != -1) {        log.info("DEBUG: 14");                lang = lang.substring(0, index);            }        log.info("DEBUG: 15");                                    locale = new Locale(lang);        log.info("DEBUG: 16");            bundle = ResourceBundle.getBundle(bundleName, locale);        log.info("DEBUG: 17");            /* Abort search if a bundle (not fallback) is found */            if (bundle != fallback)                 break;            /* About search if the fallback bundle is actually requested */            else if (bundle == fallback && locale.getLanguage().equals(Locale.getDefault().getLanguage()))                break;        }        log.info("DEBUG: 18");        /* Should never happen, but just in case. */        if (bundle == null)            bundle = ResourceBundle.getBundle(bundleName, new Locale("no"));               log.info("DEBUG: 19");        String wsName = null;        String wsURL  = null;        if (session != null) {        log.info("DEBUG: 20");            wsName = session.getWebService().getName();            wsURL  = session.getWebService().getUrl();        }        /* Set template-variables from properties */        for (Enumeration e = bundle.getKeys(); e.hasMoreElements();) {        log.info("DEBUG: 21");            String key = (String) e.nextElement();            String value = bundle.getString(key);            int index;                        /* This changes WS_NAME to hyperlink in all property             * strings from the bundle.*/            if ((index = value.indexOf("WS_NAME")) != -1 && wsName != null) {                value = value.substring(0, index)+"<A href=\""+wsURL+"\">"+wsName+"</A>"+value.substring(index+7, value.length());            }            context.put(key, value);        }           /* Get realm from cookie. */        log.info("DEBUG: 22");        Cookie[] cookies = request.getCookies();        context.put("preset_realm", "");        for (int i = 0; i < cookies.length; i++) {        log.info("DEBUG: 23");            if (cookies[i].getName().equals("realm")) {                context.put("preset_realm", cookies[i].getValue());            }        }        /* Set or reset error messages */        if (errorType != null) {        log.info("DEBUG: 24");            context.put("errorMessage", context.get("error_"+errorType));            context.put("errorDescription", context.get("error_"+errorType+"_desc"));        }             else {        log.info("DEBUG: 25");            context.remove("errorMessage");            context.remove("errorDescription");        }        if (sessionID != null) {         log.info("DEBUG: 26");            context.put("loginURL", loginURL+"?id="+sessionID);            String secLevel = session.getAttributesSecLevel().toLowerCase();            context.put("expl_data", context.get("expl_data_"+secLevel));            /* Detailed list of attributes */            if (showAllAttributes) {        log.info("DEBUG: 27");                Vector attrNames = new Vector();                HashMap attributes = session.getWebService().getAttributes();                for (Iterator it = attributes.keySet().iterator(); it.hasNext();) {        log.info("DEBUG: 28");                    attrNames.add(context.get("ldap_"+it.next()));                }                context.put("attrNames", attrNames);                /* Link to page with detailed attribute list. */                if (context.get("attrs_hide") != null)                    context.put("showHideLink", "<A href=\""+loginURL+"?id="+sessionID+"\">"+context.get("attrs_hide")+"</A>");                else                     context.put("showHideLink", "");            }            else if (context.get("attrs_show") != null) {        log.info("DEBUG: 29");                context.put("showHideLink", "<A href=\""+loginURL+"?id="+sessionID+"&showAttrs=yes\">"+context.get("attrs_show")+"</A>");            }            else                 context.put("showHideLink", "");        }        else             /* If no sessionID then remove loginURL */            context.remove("loginURL");        log.info("DEBUG: 30");                return getTemplate("login.vtl");    }