template = TemplateHelper.findTemplate(servletContext, userName,
template = TemplateHelper.findTemplate(servletContext, session, userName,
    public ActionForward execute(ActionMapping mapping,                                 ActionForm form,                                 HttpServletRequest request,                                 HttpServletResponse response)        throws Exception {        TemplateForm tf = (TemplateForm) form;        HttpSession session = request.getSession();        ServletContext servletContext = session.getServletContext();        String templateName = tf.getTemplateName();        String templateType = tf.getTemplateType();        boolean saveQuery = (request.getParameter("noSaveQuery") == null);        boolean skipBuilder = (request.getParameter("skipBuilder") != null);        boolean editTemplate = (request.getParameter("editTemplate") != null);        SessionMethods.logTemplateQueryUse(session, templateType, templateName);        String userName = ((Profile) session.getAttribute(Constants.PROFILE)).getUsername();        TemplateQuery template = TemplateHelper.findTemplate(servletContext, userName,                templateName, templateType);        // We're editing the query: load as a PathQuery        if (!skipBuilder && !editTemplate) {            TemplateQuery queryCopy = TemplateHelper.templateFormToTemplateQuery(tf, template);            SessionMethods.loadQuery(queryCopy.getPathQuery(), request.getSession(), response);            session.removeAttribute(Constants.TEMPLATE_BUILD_STATE);            form.reset(mapping, request);            return mapping.findForward("query");        } else if (editTemplate) {            // We want to edit the template: Load the query as a TemplateQuery            // Don't care about the form            // Reload the initial template            template = TemplateHelper.findTemplate(servletContext, userName,                                                   template.getName(), TemplateHelper.ALL_TEMPLATE);            if (template == null) {                recordMessage(new ActionMessage("errors.edittemplate.empty"), request);                return mapping.findForward("template");            }            SessionMethods.loadQuery(template, request.getSession(), response);            return mapping.findForward("query");        }        // Otherwise show the results: load the modified query from the template        TemplateQuery queryCopy = TemplateHelper.templateFormToTemplateQuery(tf, template);        SessionMethods.loadQuery(queryCopy, request.getSession(), response);        form.reset(mapping, request);        QueryMonitorTimeout clientState = new QueryMonitorTimeout(                Constants.QUERY_TIMEOUT_SECONDS * 1000);        MessageResources messages = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);        String qid = SessionMethods.startQuery(clientState, session, messages, saveQuery);        Thread.sleep(200);        return new ForwardParameters(mapping.findForward("waiting")).addParameter("qid", qid)                .forward();    }