Example #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);
  }
Example #2
0
  protected void checkMergedJSFiles(Group group, String testFile, String encoding)
      throws Exception {

    // Recuperation du fichier minimize

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    AbstractGroupBuilder agb = AbstractGroupBuilder.getInstance();
    agb.buildGroupJsIfNeeded(group, baos, null);

    baos.flush();
    baos.close();

    testFile = "com/ideo/jso/junit/minimize/" + testFile;
    String testMerged = getFileContentAsString(testFile, encoding);

    System.out.println("---File " + testFile + ":");
    System.out.println(testMerged);
    System.out.println("--- Group " + group.getName() + ":");
    System.out.println(baos.toString(encoding));
    System.out.println("---");

    assertEquals(
        manageUnixWindowNewLine(testMerged), manageUnixWindowNewLine(baos.toString(encoding)));
  }