Search in sources :

Example 1 with DoNothingCSSParseExceptionCallback

use of com.helger.css.handler.DoNothingCSSParseExceptionCallback in project ph-css by phax.

the class CSSReaderDeclarationListTest method testRead21.

@Test
public void testRead21() {
    final ICSSParseExceptionCallback aHdl = new DoNothingCSSParseExceptionCallback();
    for (final String sCSS : VALID) {
        final CSSDeclarationList aDL = CSSReaderDeclarationList.readFromString(sCSS, ECSSVersion.CSS30, aHdl);
        assertNotNull(aDL);
    }
    for (final String sCSS : INVALID) assertNull(sCSS, CSSReaderDeclarationList.readFromString(sCSS, ECSSVersion.CSS30, aHdl));
}
Also used : CSSDeclarationList(com.helger.css.decl.CSSDeclarationList) ICSSParseExceptionCallback(com.helger.css.handler.ICSSParseExceptionCallback) DoNothingCSSParseExceptionCallback(com.helger.css.handler.DoNothingCSSParseExceptionCallback) Test(org.junit.Test)

Example 2 with DoNothingCSSParseExceptionCallback

use of com.helger.css.handler.DoNothingCSSParseExceptionCallback in project ph-css by phax.

the class CSSReader 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 = _readStyleSheet(aCharStream, eVersion, getDefaultParseErrorHandler(), new DoNothingCSSParseExceptionCallback(), false);
        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)

Example 3 with DoNothingCSSParseExceptionCallback

use of com.helger.css.handler.DoNothingCSSParseExceptionCallback 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

DoNothingCSSParseExceptionCallback (com.helger.css.handler.DoNothingCSSParseExceptionCallback)3 CSSCharStream (com.helger.css.parser.CSSCharStream)2 CSSNode (com.helger.css.parser.CSSNode)2 CSSDeclarationList (com.helger.css.decl.CSSDeclarationList)1 ICSSParseExceptionCallback (com.helger.css.handler.ICSSParseExceptionCallback)1 Test (org.junit.Test)1