Class MinificationHandler

java.lang.Object
io.sf.carte.uparser.CommentRemovalHandler
io.sf.carte.uparser.MinificationHandler
All Implemented Interfaces:
ContentHandler<RuntimeException>, ControlHandler<RuntimeException>, TokenErrorHandler<RuntimeException>, TokenHandler2, TokenHandler3<RuntimeException>

public class MinificationHandler extends CommentRemovalHandler
A handler that minifies by removing comments and consecutive whitespace.

Example:


 String minify(String text) {
     String[] opening = { "/*", "<!--" };
     String[] closing = { "*/", "-->" };
     MinificationHandler handler = new MinificationHandler(text.length());
     TokenProducer tp = new TokenProducer(handler);
     tp.setHandleAllSeparators(false);
     try {
         tp.parseMultiComment(new StringReader(text), opening, closing);
     } catch (IOException e) {
     }
     return handler.getBuffer().toString();
 }
 
  • Constructor Details

    • MinificationHandler

      public MinificationHandler(int bufSize)
      Construct the handler with the given initial buffer size.
      Parameters:
      bufSize - the initial buffer size.
    • MinificationHandler

      public MinificationHandler(StringBuilder buffer)
      Construct the handler with the given buffer.
      Parameters:
      buffer - the buffer.
  • Method Details