Ejemplo n.º 1
0
 @Override
 public void destroy() {
   Collection<GlobalContext> allGlobalContext = null;
   try {
     allGlobalContext = GlobalContextFactory.getAllGlobalContext(getServletContext());
   } catch (Exception ex) {
     ex.printStackTrace();
   }
   if (allGlobalContext != null) {
     for (GlobalContext globalContext : allGlobalContext) {
       globalContext.destroy();
     }
   }
   if (mailingThread != null) {
     mailingThread.stop = true;
     synchronized (mailingThread.stop) {
       try {
         mailingThread.stop.wait();
         logger.info("mailing thread stopped");
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
   }
   threadManager.stop = true;
   synchronized (threadManager.stop) {
     try {
       threadManager.stop.wait();
       logger.info("thread manager stopped");
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
   super.destroy();
   StaticConfig.getInstance(getServletContext()).shutdown();
 }
Ejemplo n.º 2
0
  public void process(HttpServletRequest request, HttpServletResponse response, boolean post)
      throws ServletException {

    try {

      COUNT_ACCESS++;

      logger.fine("uri : " + request.getRequestURI()); // TODO: remove
      // debug trace

      StaticConfig staticConfig = StaticConfig.getInstance(getServletContext());

      /** init log * */
      long startTime = System.currentTimeMillis();

      String requestLabel = request.getPathInfo();

      request.setCharacterEncoding(ContentContext.CHARACTER_ENCODING);

      RequestService requestService = RequestService.getInstance(request);

      // content type cannot be set to html if portlet resource - TODO:
      // clean process method (with filter ?)
      if (requestService.getParameter("javlo-portlet-resource", null) == null
          || requestService.getParameter("javlo-portlet-id", null) == null) {
        response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);
      }

      GlobalContext globalContext = GlobalContext.getInstance(request);
      Thread.currentThread().setName("AccessServlet-" + globalContext.getContextKey());

      ContentContext ctx = ContentContext.getContentContext(request, response);
      ctx.setPostRequest(post);

      globalContext.initExternalService(ctx);

      if (FIRST_REQUEST) {
        synchronized (FIRST_REQUEST) {
          if (FIRST_REQUEST) {
            FIRST_REQUEST = false;
            try {
              GlobalContext.getDefaultContext(request.getSession());
              GlobalContext.getMasterContext(request.getSession());
              if (globalContext.getDMZServerIntra() != null) {
                SynchroThread synchro =
                    (SynchroThread)
                        AbstractThread.createInstance(
                            staticConfig.getThreadFolder(), SynchroThread.class);
                synchro.initSynchronisationThread(
                    staticConfig, globalContext, request.getSession().getServletContext());
                synchro.store();
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }

      /** get info from system to browser * */
      if (ctx.getCurrentEditUser() != null
          && request != null
          && request.getPathInfo() != null
          && request.getPathInfo().endsWith("info.txt")) {
        response.setContentType("text/plain");
        PrintStream out = new PrintStream(response.getOutputStream());
        writeInfo(out);
        out.println("");
        out.println("User-Agent : " + request.getHeader("User-Agent"));
        out.println("");
        globalContext.writeInfo(request.getSession(), out);
        out.println("");
        globalContext.writeInstanceInfo(ctx, out);
        ContentService content = ContentService.getInstance(globalContext);
        out.println("");
        ctx.getCurrentPage().printInfo(ctx, out);
        out.println("");
        out.println("latest update by : " + content.getAttribute(ctx, "user.update"));
        out.close();
        return;
      }

      /** CACHE * */
      if (ctx.isAsViewMode()
          && ctx.getCurrentPage().isCacheable(ctx)
          && globalContext.isPreviewMode()
          && globalContext.getPublishDate() != null
          && request.getMethod().equalsIgnoreCase("get")
          && request.getParameter("webaction") == null) {
        long lastModified = globalContext.getPublishDate().getTime();
        response.setDateHeader(NetHelper.HEADER_LAST_MODIFIED, lastModified);
        response.setHeader("Cache-Control", "max-age=60,must-revalidate");
        long lastModifiedInBrowser = request.getDateHeader(NetHelper.HEADER_IF_MODIFIED_SINCE);
        if (lastModified > 0 && lastModified / 1000 <= lastModifiedInBrowser / 1000) {
          COUNT_304++;
          response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
          return;
        }
      } else {
        response.setHeader("Cache-Control", "max-age=0,no-cache");
      }

      ctx.getCurrentTemplate();
      request.setAttribute("frontCache", globalContext.getFrontCache(ctx));

      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            requestLabel
                + " : first ContentContext "
                + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                + " sec.");
        logger.fine("device : " + ctx.getDevice());
      }

      I18nAccess i18nAccess = I18nAccess.getInstance(ctx);

      i18nAccess.requestInit(ctx);
      ctx.getRequest().setAttribute("list", ListService.getInstance(ctx).getAllList(ctx));

      /* ******** */
      /* SECURITY */
      /* ******** */

      if (request.getServletPath().equals("/edit") || request.getServletPath().equals("/preview")) {
        if (!globalContext.isEditable()) {
          InfoBean.updateInfoBean(ctx);
          response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);
          request.setAttribute("edit", "true");
          ServletHelper.includeBlocked(request, response);
          return;
        }
      }

      if (ctx.getRenderMode() == ContentContext.VIEW_MODE
          || ctx.getRenderMode() == ContentContext.PREVIEW_MODE
          || ctx.getRenderMode() == ContentContext.TIME_MODE
          || ctx.getRenderMode() == ContentContext.PAGE_MODE
          || ctx.getRenderMode() == ContentContext.MAILING_MODE) {
        if (!globalContext.isView()) {
          String sessionKey = "__unlock_content__";
          String pwd = request.getParameter("block-password");
          if (pwd != null && pwd.trim().length() > 0) { // unlock with
            // special
            // pwd
            if (pwd.equals(globalContext.getBlockPassword())) {
              request.getSession().setAttribute(sessionKey, "true");
            } else {
              Thread.sleep(5000); // if bad password wait 5 sec
            }
          }
          if (request.getSession().getAttribute(sessionKey) == null) {
            InfoBean.updateInfoBean(ctx);
            response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);
            ServletHelper.includeBlocked(request, response);
            return;
          }
        }
      }

      if (request.getServletPath().equals("/edit")) {
        EditContext editCtx = EditContext.getInstance(globalContext, request.getSession());
        ctx.setArea(editCtx.getCurrentArea());
        if (ctx.getCurrentEditUser() == null) {
          InfoBean.updateInfoBean(ctx);
          response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);
          String jspForLogin = editCtx.getLoginRenderer();
          getServletContext().getRequestDispatcher(jspForLogin).include(request, response);
          return;
        }
      }

      RequestHelper.traceMailingFeedBack(ctx);

      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            requestLabel
                + " : i18nAccess.requestInit(ctx) "
                + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                + " sec.");
      }

      /* ********************** */
      /* CHECK SYSTEM INTEGRITY */
      /* ********************** */

      if (ctx.getRenderMode() == ContentContext.EDIT_MODE) {
        long minSize = staticConfig.getMinFreeSpaceOnDataFolder();
        if (new File(staticConfig.getAllDataFolder()).getFreeSpace() < minSize) {
          logger.warning("not enough space on data disk.");
          MessageRepository messageRepository = MessageRepository.getInstance(ctx);
          messageRepository.setGlobalMessageAndNotification(
              ctx,
              new GenericMessage(
                  "WARNING : Space left on device becoming to low.  Please log off and contact the administrator.",
                  GenericMessage.ERROR));
          String msg =
              "no enough free space on data device : "
                  + new File(staticConfig.getAllDataFolder()).getFreeSpace()
                  + " bytes free.";
          DebugListening.getInstance().sendError(request, msg);
          RemoteMessageService remoteMessageService =
              RemoteMessageService.getInstance(globalContext);
          remoteMessageService.addMessage(RemoteMessage.ADMIN_LEVEL, RemoteMessage.WARNING, msg);
        }
      }

      /* welcome popup */
      if (requestService.getParameter("popup", "").equals("welcome")) {
        String url = staticConfig.getWelcomePopupURL(ctx.getLanguage());
        if ((url != null) && (url.length() > 0)) {
          PopupMessage.setPopupMessage(request.getSession(), new URL(url));
        }
      }

      org.javlo.helper.Logger localLogger = new org.javlo.helper.Logger();

      localLogger.startCount("sid");

      /** ************************** */
      /** EXCECUTE CRYPTED ACTION * */
      /** ************************** */
      String encodedParam = requestService.getParameter("_sid_", null);

      if ((encodedParam != null) && (request.getAttribute("_sid_") == null)) {
        request.setAttribute("_sid_", "true");
        String decodeParam = URLHelper.httpDecryptData(encodedParam);
        String url = request.getServletPath() + request.getPathInfo() + decodeParam;

        response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);

        getServletContext().getRequestDispatcher(url).include(request, response);
        return;
      }

      localLogger.endCount("sid", "sid traitement");

      /** ************************************* * */
      /** INIT MAILING SERVER FOR UNSUBSCRIBE * * */
      /** ************************************* * */

      /*
       * localLogger.startCount("mailing"); MailingContext mCtx =
       * MailingContext.getInstance(request.getSession());
       * mCtx.setUnsubscribeHost(request.getServerName());
       * mCtx.setUnsubscribePort(request.getServerPort());
       * localLogger.endCount("mailing", "mailing lauch");
       */

      localLogger.startCount("execute action");

      if (ctx.getRenderMode() == ContentContext.EDIT_MODE) {

        /** * update module status before action ** */
        ModulesContext moduleContext =
            ModulesContext.getInstance(request.getSession(), globalContext);
        moduleContext.initContext(request, response);

        i18nAccess.setCurrentModule(
            globalContext, request.getSession(), moduleContext.getCurrentModule());

        EditContext editCtx = EditContext.getInstance(globalContext, request.getSession());
        ctx.setArea(editCtx.getCurrentArea());
      }

      try {
        String action = ServletHelper.execAction(ctx);
        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              requestLabel
                  + " : action "
                  + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                  + " sec.");
        }

        ContentService content = ContentService.getInstance(globalContext);
        if (ctx.getCurrentPage() != null) {
          ctx.getCurrentPage().updateLinkedData(ctx);
        }
        MenuElement elem = content.getNavigation(ctx).getNoErrorFreeCurrentPage(ctx);
        /** INIT TEMPLATE * */
        if (ctx.getCurrentTemplate() == null || action != null) { // action
          // can
          // change
          // the
          // template
          Template template = null;
          if (elem != null) {
            template = ctx.getCurrentTemplate();
            if (template != null) {
              template = template.getFinalTemplate(ctx);
            }
            ctx.setCurrentTemplate(template);
          }
        }
        Template template = ctx.getCurrentTemplate();

        if (ctx.getRenderMode() != ContentContext.EDIT_MODE) {
          /** * CHECK CONTENT AVAIBILITY ** */
          boolean checkContentAviability = true;
          if (ctx.getRenderMode() == ContentContext.PREVIEW_MODE) {
            EditContext editCtx = EditContext.getInstance(globalContext, request.getSession());
            checkContentAviability = !editCtx.isEditPreview();
          }
          ContentContext newCtx = new ContentContext(ctx);
          if (checkContentAviability) {
            if (!content.contentExistForContext(newCtx)) {
              newCtx.setContentLanguage(newCtx.getLanguage());
              if (globalContext.isAutoSwitchToDefaultLanguage()) {
                Iterator<String> defaultLgs = globalContext.getDefaultLanguages().iterator();
                while (!content.contentExistForContext(newCtx) && defaultLgs.hasNext()) {
                  String lg = defaultLgs.next();
                  newCtx.setRequestContentLanguage(lg);
                }
              }
              if (!content.contentExistForContext(newCtx)) {
                logger.fine(
                    "content not found in "
                        + ctx.getPath()
                        + " lg:"
                        + ctx.getRequestContentLanguage());
                // ctx.setSpecialContentRenderer("/jsp/view/content_not_found.jsp");
              } else {
                ctx = newCtx;
                ctx.storeInRequest(request);
              }
            }
          }
        }

        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              requestLabel
                  + " : content integrity "
                  + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                  + " sec.");
        }

        localLogger.endCount("execute action", "execute action = " + action);

        if (StringHelper.isTrue(
            requestService.getParameter(RequestHelper.CLOSE_WINDOW_PARAMETER, "false"))) {
          String newURL =
              requestService.getParameter(RequestHelper.CLOSE_WINDOW_URL_PARAMETER, null);

          response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);

          PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));
          out.println("<script type=\"text/javascript\">");
          out.println("if (window.opener != null) {");
          if (newURL == null) {
            out.println("	window.opener.location.href = window.opener.location.href;");
          } else {
            out.println("	window.opener.location.href = '" + newURL + "';");
          }
          out.println("	if (window.opener.progressWindow) {");
          out.println("		window.opener.progressWindow.close();");
          out.println("	}");
          out.println("}");
          out.println("if (window.parent != null) {");
          if (newURL == null) {
            out.println("	window.parent.location.href = window.parent.location.href;");
          } else {
            out.println("	window.parent.location.href = '" + newURL + "';");
          }
          out.println("}");
          out.println("window.close();");
          out.println("</script>");
          out.close();
          return;
        }

        localLogger.startCount("tracking");

        /** ******* */
        /* TRACKING */
        /** ******* */
        if (StringHelper.isTrue(request.getParameter("tracking"), true)) {
          localLogger.startCount("tracking1");
          Tracker.trace(request, response);
          localLogger.endCount("tracking", "tracking user");
        }

        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              requestLabel
                  + " : tracking "
                  + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                  + " sec.");
        }

        InfoBean infoBean = InfoBean.updateInfoBean(ctx);

        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              requestLabel
                  + " : InfoBean "
                  + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                  + " sec.");
        }

        /* **** */
        /* EDIT */
        /* **** */

        if (request.getServletPath().equals("/edit")) {

          /* ********************* */
          /* ****** MODULES ****** */
          /* ********************* */
          ServletHelper.prepareModule(ctx);

          EditContext editCtx = EditContext.getInstance(globalContext, request.getSession());
          ctx.setArea(editCtx.getCurrentArea());
          if (editCtx.getAjaxRenderer() != null) {
            response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);

            getServletContext()
                .getRequestDispatcher(editCtx.getAjaxRenderer())
                .include(request, response);
            editCtx.setAjaxRenderer(null);
          } else {
            if (template != null) {
              if (!template.getAreas().contains(ctx.getArea())) {
                editCtx.setCurrentArea(ComponentBean.DEFAULT_AREA);
                ctx.setArea(ComponentBean.DEFAULT_AREA);
              }
              ctx.setCurrentTemplate(template);
            }

            response.setContentType("text/html; charset=" + ContentContext.CHARACTER_ENCODING);

            File editCSS =
                new File(
                    URLHelper.mergePath(globalContext.getStaticFolder(), "/edit/specific.css"));
            if (editCSS.exists()) {
              String savePathPrefix = ctx.getPathPrefix();
              ContentContext.setForcePathPrefix(request, globalContext.getContextKey());
              String cssURL =
                  URLHelper.createResourceURL(
                      ctx,
                      URLHelper.mergePath(
                          globalContext.getStaticConfig().getStaticFolder(), "/edit/specific.css"));
              request.setAttribute("specificCSS", cssURL);
              ContentContext.setForcePathPrefix(request, savePathPrefix);
            }
            if (request.getAttribute("specificCSS") == null) {
              GlobalContext masterContext =
                  GlobalContextFactory.getMasterGlobalContext(
                      request.getSession().getServletContext());
              if (masterContext != null) {
                editCSS =
                    new File(
                        URLHelper.mergePath(masterContext.getStaticFolder(), "/edit/specific.css"));
                if (editCSS.exists()) {
                  String savePathPrefix = ctx.getPathPrefix();
                  ContentContext.setForcePathPrefix(request, masterContext.getContextKey());
                  String cssURL =
                      URLHelper.createResourceURL(
                          ctx,
                          URLHelper.mergePath(
                              globalContext.getStaticConfig().getStaticFolder(),
                              "/edit/specific.css"));
                  request.setAttribute("specificCSS", cssURL);
                  ContentContext.setForcePathPrefix(request, savePathPrefix);
                }
              } else {
                logger.severe("master context not found.");
              }
            }

            getServletContext()
                .getRequestDispatcher(editCtx.getEditTemplate())
                .include(request, response);
          }
          localLogger.endCount("edit", "include edit");
        } else { // view

          request.setAttribute("social", SocialService.getInstance(globalContext));

          localLogger.startCount("content");

          if (request.getServletPath().equals("/preview")) {
            EditContext editCtx = EditContext.getInstance(globalContext, request.getSession());
            request.setAttribute("editPreview", editCtx.isEditPreview());
          }

          if (!globalContext.isVisible()) {
            ServletHelper.includeBlocked(request, response);
            return;
          }

          String path = ctx.getPath();

          if (ctx.getFormat().equalsIgnoreCase("xml")) {

            response.setContentType("text/xml; charset=" + ContentContext.CHARACTER_ENCODING);
            Writer out = response.getWriter();
            out.write(XMLHelper.getPageXML(ctx, elem));

          } else if (ctx.getFormat().equalsIgnoreCase("png")
              || ctx.getFormat().equalsIgnoreCase("jpg")) {

            String fileFormat = ctx.getFormat().toLowerCase();
            response.setContentType("image/" + fileFormat + ";");
            OutputStream out = response.getOutputStream();
            ContentContext viewCtx = ctx.getContextWithOtherRenderMode(ContentContext.VIEW_MODE);
            viewCtx.setAbsoluteURL(true);
            viewCtx.setFormat("html");
            String url;
            Map<String, String> params = new HashMap<String, String>();
            params.put(Device.FORCE_DEVICE_PARAMETER_NAME, "image");
            if (request.getParameter(Template.FORCE_TEMPLATE_PARAM_NAME) != null) {
              params.put(
                  Template.FORCE_TEMPLATE_PARAM_NAME,
                  request.getParameter(Template.FORCE_TEMPLATE_PARAM_NAME));
            }
            params.put("clean-html", "true");
            url = URLHelper.createURL(viewCtx, params);

            int width = 1280;
            String widthParam = request.getParameter("width");
            if (widthParam != null) {
              width = Integer.parseInt(widthParam);
            }

            Java2DRenderer renderer = new Java2DRenderer(url, width);
            BufferedImage img = renderer.getImage();
            FSImageWriter imageWriter = new FSImageWriter();
            imageWriter.write(img, out);

          } else if (ctx.getFormat().equalsIgnoreCase("pdf")) {
            response.setContentType("application/pdf;");
            OutputStream out = response.getOutputStream();
            ContentContext viewCtx = ctx.getContextWithOtherRenderMode(ContentContext.VIEW_MODE);
            viewCtx.setAbsoluteURL(true);
            viewCtx.setFormat("html");
            viewCtx.resetDMZServerInter();

            Map<String, String> params = new HashMap<String, String>();
            params.put(Device.FORCE_DEVICE_PARAMETER_NAME, "pdf");
            params.put(ContentContext.FORCE_ABSOLUTE_URL, "true");
            params.put(ContentContext.NO_DMZ_PARAM_NAME, "true");
            if (!globalContext.isView() && globalContext.getBlockPassword() != null) {
              params.put("block-password", globalContext.getBlockPassword());
            }

            if (request.getParameter(Template.FORCE_TEMPLATE_PARAM_NAME) != null) {
              params.put(
                  Template.FORCE_TEMPLATE_PARAM_NAME,
                  request.getParameter(Template.FORCE_TEMPLATE_PARAM_NAME));
            }

            params.put("clean-html", "true");

            String url = URLHelper.createURL(viewCtx, params);

            /*
             * if (staticConfig.getApplicationLogin() != null) { url
             * = URLHelper.addCredential(url,
             * staticConfig.getApplicationLogin(),
             * staticConfig.getApplicationPassword()); }
             * PDFConvertion.getInstance().convertXHTMLToPDF(url,
             * out);
             */
            PDFConvertion.getInstance()
                .convertXHTMLToPDF(
                    new URL(url),
                    staticConfig.getApplicationLogin(),
                    staticConfig.getApplicationPassword(),
                    out);

          } else if (ctx.getFormat().equalsIgnoreCase("cxml")) {

            String realPath = ContentManager.getPath(request);
            MenuElement agendaPage =
                ContentService.getInstance(globalContext)
                    .getNavigation(ctx)
                    .searchChild(ctx, realPath);

            response.setContentType("text/xml; charset=" + ContentContext.CHARACTER_ENCODING);
            Date startDate =
                StringHelper.parseSortableDate(
                    requestService.getParameter("start-date", "1900-01-01"));
            Date endDate =
                StringHelper.parseSortableDate(
                    requestService.getParameter("end-date", "2100-01-01"));
            String agendaXML = TimeHelper.exportAgenda(ctx, agendaPage, startDate, endDate);
            response.getWriter().write(agendaXML);
          } else {
            if (elem == null) {
              logger.warning("bad path : " + path);
            }
            if ((template == null)
                || (!template.exist())
                || (template.getRendererFullName(ctx) == null)) {
              ServletHelper.includeBlocked(request, response);
            } else {
              if (ctx.getRenderMode() == ContentContext.VIEW_MODE) {
                content.getNavigation(ctx).getNoErrorFreeCurrentPage(ctx).addAccess(ctx);
              }

              if (ctx.getSpecialContentRenderer() != null) {
                Template specialTemplate =
                    TemplateFactory.getTemplates(getServletContext())
                        .get(template.getSpecialRendererTemplate());
                if (specialTemplate != null) {
                  template = specialTemplate;
                }
              }

              /** check page securised * */
              if (globalContext.getActivationKey() != null) {
                String activationKey = requestService.getParameter("activation-key", null);
                if (activationKey != null
                    && activationKey.equals(globalContext.getActivationKey())) {
                  globalContext.setActivationKey(null);
                } else {
                  ctx.setSpecialContentRenderer("/jsp/view/activation.jsp");
                }
              }

              if (ctx.getCurrentPage().getUserRoles().size() > 0) {
                if (ctx.getCurrentUser() == null) {
                  ctx.setSpecialContentRenderer("/jsp/view/login.jsp");
                } else {
                  Set<String> roles = new HashSet<String>(ctx.getCurrentUser().getRoles());
                  roles.retainAll(ctx.getCurrentPage().getUserRoles());
                  if (roles.size() == 0
                      && !(ctx.getCurrentUser().isEditor()
                          && AdminUserSecurity.getInstance()
                              .haveRight(ctx.getCurrentUser(), AdminUserSecurity.CONTENT_ROLE))) {
                    ctx.setSpecialContentRenderer("/jsp/view/login.jsp");
                  }
                }
              }

              if (ctx.getGlobalContext().isCollaborativeMode()) {
                Set<String> pageRoles = ctx.getCurrentPage().getEditorRolesAndParent();
                if ((pageRoles.size() > 0 || ctx.getCurrentEditUser() == null)
                    && !ctx.getCurrentPage().getName().equals("registration")) { // leave
                  // access
                  // to
                  // registration
                  // page.
                  if (ctx.getCurrentEditUser() == null
                      || !ctx.getCurrentEditUser().validForRoles(pageRoles)) {
                    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
                    ctx.setSpecialContentRenderer("/jsp/view/no_access.jsp");
                  }
                }
              }

              ctx.setCurrentTemplate(template);

              if (ctx.getRenderMode() == ContentContext.PREVIEW_MODE
                  && staticConfig.isFixPreview()) {
                ctx.getRequest()
                    .setAttribute("components", ComponentFactory.getComponentForDisplay(ctx));

                /** ********************* */
                /** ** Shared Content *** */
                /** ********************* */
                SharedContentService.prepare(ctx);
              }

              /** check content * */
              if (!ctx.isContentFound()) {

                if (staticConfig.isRedirectWidthName()) {
                  String pageName =
                      StringHelper.getFileNameWithoutExtension(
                          StringHelper.getFileNameFromPath(request.getRequestURI()));
                  MenuElement newPage = content.getNavigation(ctx).searchChildFromName(pageName);
                  if (newPage != null) {
                    String forwardURL = URLHelper.createURL(ctx, newPage);
                    NetHelper.sendRedirectPermanently(response, forwardURL);
                    logger.info("redirect permanently : " + pageName + " to " + forwardURL);
                    return;
                  }
                }

                ctx.getResponse()
                    .setStatus(
                        HttpServletResponse.SC_NOT_FOUND, "page not found : " + ctx.getPath());
                if (ctx.isAsViewMode()) {
                  MenuElement page404 =
                      content.getNavigation(ctx).searchChildFromName(staticConfig.get404PageName());
                  if (page404 != null) {
                    ctx.setCurrentPageCached(page404);
                  }
                }
              }

              String area = requestService.getParameter("only-area", null);
              if (area != null) {
                getServletContext()
                    .getRequestDispatcher("/jsp/view/content_view.jsp?area=" + area)
                    .include(request, response);
              } else {
                String jspPath = template.getRendererFullName(ctx);
                getServletContext().getRequestDispatcher(jspPath).include(request, response);
              }
            }
          }
          localLogger.endCount("content", "include content");

          if (logger.isLoggable(Level.FINE)) {
            logger.fine(
                requestLabel
                    + " : render "
                    + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                    + " sec.");
          }
        }

        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              requestLabel
                  + " : all process method "
                  + df.format((double) (System.currentTimeMillis() - startTime) / (double) 1000)
                  + " sec.");
        }

        if (StringHelper.isTrue(request.getSession().getAttribute(InfoBean.NEW_SESSION_PARAM))) {
          request.getSession().removeAttribute(InfoBean.NEW_SESSION_PARAM);
        }

      } catch (Throwable t) {

        t.printStackTrace();

        response.setStatus(503);

        Writer out = response.getWriter();
        out.write(
            "<div style=\"margin-top: 50px; margin-left: auto; margin-right: auto; border: 2px #ff0000 solid; width: 500px; padding: 3px;\" id=\"fatal-error\">");
        out.write(
            "<h1 style=\"margin: 0px; padding: 1px; font-size: 120%; text-align: center;\">Techinal error.</h1>");
        out.write(
            "<p style=\"text-align: center;\"><a href=\"mailto:"
                + staticConfig.getManualErrorEmail()
                + "?subject=fatal error in javlo : "
                + globalContext.getContextKey()
                + "\">Describe your error in a email.</a></p>");
        out.write(
            "<p style=\"padding: 10px 10px 10px 10px; margin-bottom: 10px; color: #000000; border: 1px solid #ff0000; background-color: #ffeaea;\">"
                + t.getMessage()
                + "</p>");
        out.write("</div>");

        DebugListening.getInstance().sendError(request, t, "path=" + request.getRequestURI());
      } finally {
        PersistenceService persistenceService = PersistenceService.getInstance(globalContext);
        if (persistenceService.isAskStore()) {
          persistenceService.store(ctx);
        }
      }
    } catch (Exception ioe) {
      ioe.printStackTrace();
    }
  }