Exemple #1
0
  /**
   * @param req
   * @param res
   */
  public void service(ServletRequest req, ServletResponse res)
      throws ServletException, IOException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    // timestamp requested
    String sTimeStamp = (String) req.getParameter(TIMESTAMP);
    long timestamp = (sTimeStamp != null) ? Long.parseLong(sTimeStamp) : 0;
    // file request info
    String fileName = URLUtils.getFileName(request.getPathInfo());
    String extension = URLUtils.getFileExtension(fileName);

    // filename requested is a minimized js file and its strict name correspond to a group name.
    String grpName = URLUtils.getStrictFileName(fileName);

    Map groups = AbstractConfigurationLoader.getInstance().getUpdatedGroups();

    Group group = (Group) groups.get(grpName);

    // Starting to build js-minimized
    if (group != null) {
      ByteArrayOutputStream bufferOut = new ByteArrayOutputStream(OUT_BUFFER_SIZE);
      try {
        if (AbstractGroupBuilder.getInstance()
            .buildGroupJsIfNeeded(group, bufferOut, getServletContext())) {
          group.getJsBuffer().update(bufferOut.toByteArray(), timestamp);
        }
        bufferOut.flush();
      } finally {
        bufferOut.close();
      }
    }

    // Add content-type to response flow
    response.setContentType(
        URLUtils.getMimeTypeByExtension(extension) + "; CHARSET=" + URLUtils.DEFAULT_ENCODING);

    ResourcesBuffer buffer = null;
    if (extension != null && extension.toLowerCase().equals("js")) buffer = group.getJsBuffer();
    else buffer = group.getCssBuffer();

    response.getOutputStream().write(buffer.getData(), 0, buffer.getData().length);
  }
Exemple #2
0
  // Retrieve server file system path
  private String getRealPath(ServletConfig config) {

    String realPath = URLUtils.getRealPath(this, config.getServletContext(), "");
    return realPath;
  }