Search in sources :

Example 6 with CSSCharStream

use of com.helger.css.parser.CSSCharStream in project ph-css by phax.

the class CSSReaderDeclarationList method isValidCSS.

/**
 * Check if the passed reader can be resembled to valid CSS content. This is
 * accomplished by fully parsing the CSS each time the method is called. This
 * is similar to calling
 * {@link #readFromStream(IHasInputStream, Charset, ECSSVersion)} and checking
 * for a non-<code>null</code> result.
 *
 * @param aReader
 *        The reader to use. May not be <code>null</code>.
 * @param eVersion
 *        The CSS version to use. May not be <code>null</code>.
 * @return <code>true</code> if the CSS is valid according to the version,
 *         <code>false</code> if not
 */
public static boolean isValidCSS(@Nonnull @WillClose final Reader aReader, @Nonnull final ECSSVersion eVersion) {
    ValueEnforcer.notNull(aReader, "Reader");
    ValueEnforcer.notNull(eVersion, "Version");
    try {
        final CSSCharStream aCharStream = new CSSCharStream(aReader);
        final CSSNode aNode = _readStyleDeclaration(aCharStream, eVersion, getDefaultParseErrorHandler(), new DoNothingCSSParseExceptionCallback());
        return aNode != null;
    } finally {
        StreamHelper.close(aReader);
    }
}
Also used : CSSCharStream(com.helger.css.parser.CSSCharStream) CSSNode(com.helger.css.parser.CSSNode) DoNothingCSSParseExceptionCallback(com.helger.css.handler.DoNothingCSSParseExceptionCallback)

Aggregations

CSSCharStream (com.helger.css.parser.CSSCharStream)6 CSSNode (com.helger.css.parser.CSSNode)5 Nullable (javax.annotation.Nullable)4 IHasReader (com.helger.commons.io.IHasReader)3 NonBlockingStringReader (com.helger.commons.io.stream.NonBlockingStringReader)3 ECSSVersion (com.helger.css.ECSSVersion)3 ICSSParseExceptionCallback (com.helger.css.handler.ICSSParseExceptionCallback)3 ICSSInterpretErrorHandler (com.helger.css.reader.errorhandler.ICSSInterpretErrorHandler)3 ICSSParseErrorHandler (com.helger.css.reader.errorhandler.ICSSParseErrorHandler)3 Reader (java.io.Reader)3 InputStreamAndCharset (com.helger.commons.charset.CharsetHelper.InputStreamAndCharset)2 IHasInputStream (com.helger.commons.io.IHasInputStream)2 DoNothingCSSParseExceptionCallback (com.helger.css.handler.DoNothingCSSParseExceptionCallback)2 InputStream (java.io.InputStream)2 Charset (java.nio.charset.Charset)2 ParseException (com.helger.css.parser.ParseException)1 ParserCSSCharsetDetector (com.helger.css.parser.ParserCSSCharsetDetector)1 ParserCSSCharsetDetectorTokenManager (com.helger.css.parser.ParserCSSCharsetDetectorTokenManager)1