use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadBadButRecoverable.
protected final void testReadBadButRecoverable(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info(sKey);
// Handle each error as a fatal error!
final CollectingCSSParseErrorHandler aErrorHdl = new CollectingCSSParseErrorHandler();
m_aReaderSettings.setCustomErrorHandler(aErrorHdl.and(new LoggingCSSParseErrorHandler()));
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNotNull(sKey, aCSS);
assertTrue(sKey, aErrorHdl.hasParseErrors());
assertTrue(sKey, aErrorHdl.getParseErrorCount() > 0);
if (m_bDebug)
m_aLogger.info(aErrorHdl.getAllParseErrors().toString());
// Write optimized version and re-read it
final String sCSS = new CSSWriter(m_aWriterSettings.setOptimizedOutput(true)).getCSSAsString(aCSS);
assertNotNull(sKey, sCSS);
if (m_bDebug)
m_aLogger.info(sCSS);
final CascadingStyleSheet aCSSReRead = CSSReader.readFromStringReader(sCSS, m_aReaderSettings);
assertNotNull("Failed to parse:\n" + sCSS, aCSSReRead);
assertEquals(sKey, aCSS, aCSSReRead);
}
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class AbstractFuncTestCSSReader method testReadBad.
protected final void testReadBad(@Nonnull final String sBaseDir) {
final File aBaseDir = new File(sBaseDir);
if (!aBaseDir.exists())
throw new IllegalArgumentException("BaseDir " + sBaseDir + " does not exist!");
for (final File aFile : new FileSystemRecursiveIterator(aBaseDir).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (m_bDebug)
m_aLogger.info(sKey);
// Handle each error as a fatal error!
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, m_aReaderSettings);
assertNull(sKey, aCSS);
}
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSReader21SpecialFuncTest method testReadSpecialGood.
@Test
public void testReadSpecialGood() {
final ECSSVersion eVersion = ECSSVersion.CSS30;
final Charset aCharset = StandardCharsets.UTF_8;
final File aFile = new File("src/test/resources/testfiles/css21/good/artificial/test-url.css");
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, aCharset, eVersion);
assertNotNull(aCSS);
final String sCSS = new CSSWriter(eVersion, false).getCSSAsString(aCSS);
assertNotNull(sCSS);
if (false)
s_aLogger.info(sCSS);
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class MediaQueryTools method parseToMediaQuery.
/**
* Utility method to convert a media query string to a structured list of
* {@link CSSMediaQuery} objects.
*
* @param sMediaQuery
* The media query string to parse. May be <code>null</code>.
* @param eVersion
* The CSS version to use. May not be <code>null</code>.
* @return <code>null</code> if the passed media query is <code>null</code> or
* empty or not parsable.
*/
@Nullable
public static ICommonsList<CSSMediaQuery> parseToMediaQuery(@Nullable final String sMediaQuery, @Nonnull final ECSSVersion eVersion) {
if (StringHelper.hasNoText(sMediaQuery))
return null;
final String sCSS = "@media " + sMediaQuery + " {}";
final CascadingStyleSheet aCSS = CSSReader.readFromString(sCSS, eVersion);
if (aCSS == null)
return null;
final CSSMediaRule aMediaRule = aCSS.getAllMediaRules().get(0);
return aMediaRule.getAllMediaQueries();
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSVisitor30FuncTest method testVisitContent30.
@Test
public void testVisitContent30() {
for (final File aFile : new FileSystemRecursiveIterator(new File("src/test/resources/testfiles/css30/good")).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (true)
s_aLogger.info(sKey);
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(sKey, aCSS);
CSSVisitor.visitCSSUrl(aCSS, new MockUrlVisitor(sKey));
}
}
Aggregations