KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > packtag > implementation > IBloomCssPackStrategy


1 /**
2  * Project pack:tag >> http://packtag.sf.net
3  *
4  * This software is published under the terms of the LGPL
5  * License version 2.1, a copy of which has been included with this
6  * distribution in the 'lgpl.txt' file.
7  *
8  * Last author: $Author: danielgalan $
9  * Last modified: $Date: 2007/04/22 19:04:25 $
10  * Revision: $Revision: 1.1 $
11  *
12  * $Log: IBloomCssPackStrategy.java,v $
13  * Revision 1.1 2007/04/22 19:04:25 danielgalan
14  * pack.tag moved from subversion to good old CVS
15  *
16  */

17 package net.sf.packtag.implementation;
18
19 import java.io.InputStream JavaDoc;
20
21 import net.sf.packtag.strategy.AbstractPackStrategy;
22 import net.sf.packtag.strategy.PackException;
23
24
25
26 /**
27  * Strategy to compress CSS files
28  *
29  * @author Daniel Galán y Martins
30  * @version $Revision: 1.1 $
31  */

32 public class IBloomCssPackStrategy extends AbstractPackStrategy {
33     
34     private static final String JavaDoc IBLOOM_REGEX_COMMENTS = "/\\*[^*]*\\*+([^/][^*]*\\*+)*/";
35     private static final String JavaDoc IBLOOM_REGEX_SPACES = "(\r\n)|(\r)|(\n)|(\t)|( +)";
36     private static final String JavaDoc EMPTY_STRING = "";
37
38     public String JavaDoc pack(InputStream JavaDoc resourceAsStream) throws PackException {
39         String JavaDoc resourceAsString = resourceToString(resourceAsStream);
40         // remove comments
41
String JavaDoc result = resourceAsString.replaceAll(IBLOOM_REGEX_COMMENTS, EMPTY_STRING);
42         // remove tabs, spaces, newlines, etc.
43
result = result.replaceAll(IBLOOM_REGEX_SPACES, EMPTY_STRING);
44         return result.trim();
45     }
46
47 }
48
Popular Tags