1 23 24 package org.infoglue.cms.util.css; 25 26 import java.io.InputStreamReader ; 27 import java.io.Reader ; 28 import java.net.URL ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 import org.apache.log4j.Logger; 33 import org.w3c.css.sac.InputSource; 34 import org.w3c.dom.css.CSSRule; 35 import org.w3c.dom.css.CSSRuleList; 36 import org.w3c.dom.css.CSSStyleSheet; 37 38 import com.steadystate.css.parser.CSSOMParser; 39 40 45 46 public class CSSHelper 47 { 48 private final static Logger logger = Logger.getLogger(CSSHelper.class.getName()); 49 50 private String cssUrl = null; 51 52 public static CSSHelper getHelper() 53 { 54 return new CSSHelper(); 55 } 56 57 public void setCSSUrl(String url) 58 { 59 this.cssUrl = url; 60 } 61 62 public List getCSSRules() 63 { 64 List list = new ArrayList (); 65 66 try 67 { 68 Reader r = new InputStreamReader (new URL (this.cssUrl).openStream()); 69 70 CSSOMParser parser = new CSSOMParser(); 71 InputSource is = new InputSource(r); 72 73 CSSStyleSheet stylesheet = parser.parseStyleSheet(is); 74 CSSRuleList rules = stylesheet.getCssRules(); 75 76 for (int i = 0; i < rules.getLength(); i++) { 77 CSSRule rule = rules.item(i); 78 list.add(rule); 79 } 80 81 82 } 83 catch(Exception e) 84 { 85 logger.warn("An error occurred when reading css-rules: " + e.getMessage(), e); 86 } 87 88 return list; 89 } 90 91 } 92 | Popular Tags |