コード例 #1
0
ファイル: WikiReadCSS.java プロジェクト: minnseop/ph-css
 /**
  * Read a CSS 3.0 declaration from a file using UTF-8 encoding.
  *
  * @param aFile The file to be read. May not be <code>null</code>.
  * @return <code>null</code> if the file has syntax errors.
  */
 public static CascadingStyleSheet readCSS30(final File aFile) {
   // UTF-8 is the fallback if neither a BOM nor @charset rule is present
   final CascadingStyleSheet aCSS =
       CSSReader.readFromFile(aFile, CCharset.CHARSET_UTF_8_OBJ, ECSSVersion.CSS30);
   if (aCSS == null) {
     // Most probably a syntax error
     s_aLogger.warn("Failed to read CSS - please see previous logging entries!");
     return null;
   }
   return aCSS;
 }
コード例 #2
0
  public String process(String css) {
    CascadingStyleSheet cascadingStyleSheet =
        CSSReader.readFromString(
            css,
            CCharset.CHARSET_UTF_8_OBJ,
            ECSSVersion.CSS30,
            new DoNothingCSSParseErrorHandler());

    processRules(cascadingStyleSheet.getAllRules());

    return _cssWriter.getCSSAsString(cascadingStyleSheet);
  }
コード例 #3
0
  protected String formatCss(String css) {
    CascadingStyleSheet cascadingStyleSheet =
        CSSReader.readFromString(
            css,
            CCharset.CHARSET_UTF_8_OBJ,
            ECSSVersion.CSS30,
            new DoNothingCSSParseErrorHandler());

    CSSWriterSettings cssWriterSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);

    cssWriterSettings.setOptimizedOutput(false);
    cssWriterSettings.setRemoveUnnecessaryCode(Boolean.TRUE);

    CSSWriter cssWriter = new CSSWriter(cssWriterSettings);

    return cssWriter.getCSSAsString(cascadingStyleSheet);
  }