Package org.vosao.common

Examples of org.vosao.common.VosaoContext


     
    }
   
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
      VosaoContext ctx = VosaoContext.getInstance();
      ctx.setSkipURLs(skipURLs);
      HttpServletRequest httpRequest = (HttpServletRequest)request;
        HttpServletResponse httpResponse = (HttpServletResponse)response;
        String url = httpRequest.getServletPath();
        if (url.startsWith("/_ah/plugin")) {
          if (processPluginServlet(request, response)) {
            return;
          }
        }
        if (ctx.isSkipUrl(url)) {
            chain.doFilter(request, response);
            return;
        }
        if (!isLoggedIn(httpRequest) && servedFromCache(url, httpResponse)) {
          return;
        }
        SeoUrlEntity seoUrl = getDao().getSeoUrlDao().getByFrom(url);
        if (seoUrl != null) {
          httpResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
          httpResponse.setHeader("Location", seoUrl.getToLink());
          httpResponse.setHeader("Connection", "close");
            return;
        }
      try {
        if (getDao().getGroupDao().getGuestsGroup() == null) {
          httpResponse.sendRedirect("/setup");
          return;
        }
        PageEntity page = getPage(url, httpRequest);
        if (page != null) {
          renderPage(httpRequest, httpResponse, page, url);
          return;
        }
        if (url.equals("/")) {
          showNoApprovedContent(httpResponse);
          return;
        }
        ConfigEntity config = ctx.getConfig();
        if (!StringUtils.isEmpty(config.getSite404Url())) {
            page = getPage(config.getSite404Url(), httpRequest);
            if (page != null) {
              renderPage(httpRequest, httpResponse, page, url);
            }
        }
        httpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
      }
      catch (AccessDeniedException e) {
      HttpSession session = httpRequest.getSession(true);
            String userEmail = (String)session.getAttribute(
                AuthenticationFilter.USER_SESSION_ATTR);
            UserEntity user = getDao().getUserDao().getByEmail(userEmail);
        ConfigEntity config = ctx.getConfig();
        if (user != null) {
          renderMessage(httpResponse, Messages.get("access_denied_page"));
          return;
        }
        if (StringUtils.isEmpty(config.getSiteUserLoginUrl())) {
View Full Code Here


    }
    return bundles.get(locale);
  }
 
  public static String get(String key, Object...objects) {
    VosaoContext ctx = VosaoContext.getInstance();
    String pattern = "not found";
    if (isLocaleSupported(ctx.getLocale())) {
      pattern = getBundle(ctx.getRequest()).getString(key);
    }
    else {
      pattern = getDefaultBundle().getString(key);
    }
    if (objects != null) {
      MessageFormat formatter = new MessageFormat("");
      formatter.setLocale(ctx.getLocale());
      formatter.applyPattern(pattern);
      pattern = formatter.format(objects);
    }
    return pattern;
  }
View Full Code Here

   * Generate JavaScript JSON message bundle for JavaScript messages
   * localization.
   * @return JS file.
   */
  public static String getJSMessages() {
    VosaoContext ctx = VosaoContext.getInstance();
    String cached = (String)getBusiness().getSystemService().getCache().get(
        I18N_CACHE_KEY + ctx.getLanguage());
   
    logger.debug("checking is i18n_" + ctx.getLanguage() + " in cache: " + (cached != null ? "yes":"no"));
   
    if (cached != null) return cached; 
    Map<String, String> messages = new HashMap<String, String>();
    VosaoResourceBundle defaultBundle = getDefaultBundle();
    for (String key : Collections.list(defaultBundle.getKeys())) {
      try {
        messages.put(key, defaultBundle.getString(key));
      }
      catch (MissingResourceException e) {
      }
    }
    VosaoResourceBundle bundle = getBundle(ctx.getRequest());
    for (String key : Collections.list(bundle.getKeys())) {
      try {
        messages.put(key, bundle.getString(key));
      }
      catch (MissingResourceException e) {
      }
    }
    ConfigEntity config = VosaoContext.getInstance().getConfig();
    StringBuffer result = new StringBuffer();
    result.append("var locale = '").append(ctx.getLocale().toString())
        .append("';\n");
    result.append("var locale_language = '")
      .append(ctx.getLocale().getLanguage()).append("';\n");
    result.append("var default_language = '")
      .append(getBusiness().getDefaultLanguage()).append("';\n");
    result.append(
        "function messages(key) {\n"
        + "  if (_messages[key] == 'undefined') {\n"
        + "    return '__' + key + '__';\n"
        + "  } else {\n"
        + "    return _messages[key];\n"
        + "  }\n"
        + "}\n");
    result.append("var _messages = {\n");
    int i = 0;
    for (String key : messages.keySet()) {
      if (i++ > 0) {
        result.append(",");
      }
      result.append(" '").append(key).append("' : '")
        .append(filterForJS(messages.get(key)))
        .append("'\n");
    }
    result.append("};");
   
    cached = result.toString();
    getBusiness().getSystemService().getCache().put(
        I18N_CACHE_KEY + ctx.getLanguage(), cached);

    logger.debug("put i18n_" + ctx.getLanguage() + " to cache");
   
    return cached;
  }
View Full Code Here

   
    return cached;
  }
 
  public static void resetCache() {
    VosaoContext ctx = VosaoContext.getInstance();
    for (LanguageEntity language : ctx.getBusiness().getDao().getLanguageDao().select()) {
      getBusiness().getSystemService().getCache().remove(
          I18N_CACHE_KEY + language.getCode());
    }
  }
View Full Code Here

  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpSession session = httpRequest.getSession(true);
    VosaoContext ctx = VosaoContext.getInstance();
        boolean backService = isLoggedIn(httpRequest)
          && ctx.getUser() != null
          && !ctx.getUser().isSiteUser();
    enableFrontService(session);
        if (backService) {
          enableBackService(session);
        }
        chain.doFilter(request, response);
View Full Code Here

    return QuotaServiceFactory.getQuotaService();
  }

  @Override
  public long getRequestCPUTimeSeconds() {
    VosaoContext ctx = VosaoContext.getInstance();
    long result = (System.currentTimeMillis() - ctx.getStartTime())/1000;
    if (ctx.getRequestCount() == 1) {
      result += 15;
    }
    return result;
  }
View Full Code Here

 
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
      HttpServletRequest httpRequest = (HttpServletRequest)request;
      HttpSession session = httpRequest.getSession(true);
      VosaoContext ctx = VosaoContext.getInstance();
      if (session.getAttribute(Messages.LOCALE_KEY) == null) {
        ctx.setLocale(request.getLocale());
        session.setAttribute(Messages.LOCALE_KEY,
            request.getLocale());
      }
      else {
        ctx.setLocale((Locale)session.getAttribute(
            Messages.LOCALE_KEY));
      }
      if (httpRequest.getParameter("language") != null) {
        String languageCode = httpRequest.getParameter("language");
         Locale locale = getLocale(languageCode);
         logger.info("Locale " + locale.getDisplayName());
         ctx.setLocale(locale);
           session.setAttribute(Messages.LOCALE_KEY, locale);
      }
        chain.doFilter(request, response);
    }
View Full Code Here

      FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    HttpSession session = httpRequest.getSession();
        String url = httpRequest.getServletPath();
        VosaoContext ctx = VosaoContext.getInstance();
        autoLogin(httpRequest);
        String userEmail = (String)session.getAttribute(USER_SESSION_ATTR);
        UserEntity user = getDao().getUserDao().getByEmail(userEmail);
    if (user == null) {
      session.removeAttribute(USER_SESSION_ATTR);
      ctx.setUser(null);
      if (url.startsWith(CMS)) {
        String originalUrl = httpRequest.getRequestURI()
          + (httpRequest.getQueryString() == null ? "" :
            "?" + httpRequest.getQueryString());
        session.setAttribute(ORIGINAL_VIEW_KEY, originalUrl);
        httpResponse.sendRedirect(httpRequest.getContextPath()
            + LOGIN_VIEW);
        return;
      }
    }
    else {
      ctx.setUser(user);
      if (url.startsWith(CMS) && ctx.getUser().isSiteUser()) {
        httpResponse.sendRedirect("/");
        return;
      }     
    }
    chain.doFilter(request, response);
View Full Code Here

      super();
    }
 
    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
      VosaoContext ctx = VosaoContext.getInstance();
      ctx.setRequest((HttpServletRequest)request);
      ctx.setResponse((HttpServletResponse)response);
      ctx.setConfig(null);
      if (ctx.getMessageQueue() == null) {
          ctx.setMessageQueue(new MessageQueueImpl());
      }
      if (ctx.getBusiness() == null) {
          ctx.setBusiness(new BusinessImpl());
      }
      if (ctx.getFrontService() == null) {
          ctx.setFrontService(new FrontServiceImpl());
      }
      if (ctx.getBackService() == null) {
          ctx.setBackService(new BackServiceImpl());
      }
      ctx.getPageRenderingContext().clear();
      chain.doFilter(request, response);
      ctx.getPageRenderingContext().clear();
    }
View Full Code Here

TOP

Related Classes of org.vosao.common.VosaoContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.