/*
  * (non-Javadoc)
  *
  * @see
  * net.sf.ehcache.constructs.web.filter.CachingFilter#calculateKey(javax
  * .servlet.http.HttpServletRequest)
  */
 @Override
 protected String calculateKey(HttpServletRequest request) {
   // TODO Auto-generated method stub
   // String postId = request.getParameter("id");
   String requestURI = StringUtils.encoding(request.getPathInfo(), "ISO-8859-1", "UTF-8");
   if (!StringUtils.isBlank(requestURI)) {
     StringBuffer stringBuffer = new StringBuffer();
     stringBuffer.append(CacheTokens.POST_CACHE_PREFIX).append(requestURI);
     return stringBuffer.toString();
   }
   return null;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.mspring.mlog.web.freemarker.widget.render.AbstractWidgetRender#
   * nativeWidgetRender
   * (org.mspring.mlog.web.freemarker.widget.config.WidgetConfig,
   * org.mspring.mlog.web.freemarker.widget.http.HttpWidgetRequest,
   * org.mspring.mlog.web.freemarker.widget.http.HttpWidgetResponse)
   */
  @Override
  protected void nativeWidgetRender(
      WidgetConfig widgetConfig,
      HttpWidgetRequest widgetRequest,
      HttpWidgetResponse widgetResponse) {
    // TODO Auto-generated method stub
    if (widgetConfig == null) {
      return;
    }

    HttpWidget widget = getHttpWidgetCache(widgetConfig, widgetRequest, widgetResponse);
    if (widget != null) {
      return;
    }

    try {
      String path = widgetConfig.getPath();
      if (StringUtils.isNotBlank(path)) {
        try {
          widgetRequest.getRequestDispatcher(path).include(widgetRequest, widgetResponse);
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      // TODO: handle exception
      throw new WidgetNotFoundException("widget render exception!", e);
    }
  }
 public void setSkinfolder(String skinfolder) {
   if (StringUtils.isBlank(skinfolder)) {
     this.skinfolder = DEFAULT_SKIN_FOLDER;
   } else {
     this.skinfolder = skinfolder;
   }
 }
Exemple #4
0
  private String formatUrlParameters() {
    List<String> params = new ArrayList<String>();

    if (size != DEFAULT_SIZE) params.add("s=" + size);
    if (rating != DEFAULT_RATING) params.add("r=" + rating.getCode());
    if (defaultImage != GravatarDefaultImage.GRAVATAR_ICON)
      params.add("d=" + defaultImage.getCode());

    if (params.isEmpty()) return "";
    else return "?" + StringUtils.join(params.iterator(), "&");
  }
Exemple #5
0
 /*
  * (non-Javadoc)
  *
  * @see java.lang.Object#equals(java.lang.Object)
  */
 @Override
 public boolean equals(Object obj) {
   // TODO Auto-generated method stub
   if (obj != null && obj instanceof Tag) {
     Catalog c = (Catalog) obj;
     if (StringUtils.isNotBlank(c.getName()) && c.getName().equals(this.getName())) {
       return true;
     }
     if (c.getId() != null && c.getId().equals(this.getId())) {
       return true;
     }
   }
   return false;
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.mspring.mlog.service.PhotoUploadService#uploadPhoto(java.awt.image
   * .BufferedImage, java.lang.String)
   */
  @Override
  public String uploadPhoto(BufferedImage image, String fileName) throws IOException {
    // TODO Auto-generated method stub
    String formatName = StringUtils.getFileExtend(fileName);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ImageIO.write(image, formatName, bos);
    byte[] bytearray = bos.toByteArray();
    InputStream inputStream = new ByteArrayInputStream(bytearray);

    String url = fileService.uploadFile(fileName, inputStream, bytearray.length);

    inputStream.close();
    bos.close();
    return url;
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * net.sf.ehcache.constructs.web.filter.CachingFilter#buildPageInfo(javax
  * .servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
  * javax.servlet.FilterChain)
  */
 @Override
 protected PageInfo buildPageInfo(
     HttpServletRequest request, HttpServletResponse response, FilterChain chain)
     throws Exception {
   String key = calculateKey(request);
   PageInfo pageInfo = null;
   String originalThreadName = Thread.currentThread().getName();
   try {
     // checkNoReentry(request);
     Element element = null;
     if (!StringUtils.isBlank(key)) {
       element = this.blockingCache.get(key);
     }
     if ((element == null) || (element.getObjectValue() == null))
       try {
         pageInfo = buildPage(request, response, chain);
         if (pageInfo.isOk()) {
           log.debug(
               "PageInfo ok. Adding to cache "
                   + this.blockingCache.getName()
                   + " with key "
                   + key);
           this.blockingCache.put(new Element(key, pageInfo));
         } else {
           log.warn(
               "PageInfo was not ok(200). Putting null into cache "
                   + this.blockingCache.getName()
                   + " with key "
                   + key);
           this.blockingCache.put(new Element(key, null));
         }
       } catch (Throwable throwable) {
         this.blockingCache.put(new Element(key, null));
         throw new Exception(throwable);
       }
     else {
       pageInfo = (PageInfo) element.getObjectValue();
     }
   } catch (LockTimeoutException e) {
     throw e;
   } finally {
     Thread.currentThread().setName(originalThreadName);
   }
   return pageInfo;
 }