use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class Issue4Test method testIssue4.
@Test
public void testIssue4() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue4.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, new LoggingCSSParseErrorHandler());
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSVisitor30FuncTest method testVisitConstantCSS.
@Test
public void testVisitConstantCSS() {
// CSS 1
CascadingStyleSheet aCSS = CSSReader.readFromString(CSS1, ECSSVersion.CSS30);
assertNotNull(aCSS);
MockCountingUrlVisitor aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(4, aVisitor.getCount());
// CSS 2
aCSS = CSSReader.readFromString(CSS2, ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(18, aVisitor.getCount());
// CSS 3
aCSS = CSSReader.readFromString(CSS3, ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(1, aVisitor.getCount());
// CSS 4
aCSS = CSSReader.readFromString(CSS4, ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(1, aVisitor.getCount());
// CSS 5
aCSS = CSSReader.readFromString(CSS5, ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(0, aVisitor.getCount());
// CSS 6
aCSS = CSSReader.readFromString(CSS6, ECSSVersion.CSS30);
assertNotNull(aCSS);
aVisitor = new MockCountingUrlVisitor();
CSSVisitor.visitCSSUrl(aCSS, aVisitor);
assertEquals(3, aVisitor.getCount());
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class WikiVisitSelectors method readAllSelectors.
public void readAllSelectors() {
final String sStyle = "blockquote p,\r\n" + "blockquote ul,\r\n" + "blockquote ol {\r\n" + " line-height:normal;\r\n" + " font-style:italic;\r\n" + "}\r\n" + "\r\n" + "a { color:#FFEA6F; }\r\n" + "\r\n" + "a:hover { text-decoration:none; }\r\n" + "\r\n" + "img { border:none; }";
final CascadingStyleSheet aCSS = CSSReader.readFromString(sStyle, ECSSVersion.CSS30);
final ICommonsList<String> aAllSelectors = new CommonsArrayList<>();
CSSVisitor.visitCSS(aCSS, new DefaultCSSVisitor() {
@Override
public void onStyleRuleSelector(@Nonnull final CSSSelector aSelector) {
aAllSelectors.add(aSelector.getAsCSSString(new CSSWriterSettings(ECSSVersion.CSS30)));
}
});
System.out.println(aAllSelectors);
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class MainReadAllCSSOnDisc method main.
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
public static void main(final String[] args) {
int nFilesOK = 0;
int nFilesError = 0;
final ICommonsOrderedMap<File, ParseException> aErrors = new CommonsLinkedHashMap<>();
final Wrapper<File> aCurrentFile = new Wrapper<>();
final ICSSParseExceptionCallback aHdl = ex -> aErrors.put(aCurrentFile.get(), ex);
for (final File aFile : new FileSystemRecursiveIterator(new File("/")).withFilter(IFileFilter.filenameEndsWith(".css"))) {
if (false)
s_aLogger.info(aFile.getAbsolutePath());
aCurrentFile.set(aFile);
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30, aHdl);
if (aCSS == null) {
nFilesError++;
s_aLogger.warn(" " + aFile.getAbsolutePath() + " failed!");
} else
nFilesOK++;
}
s_aLogger.info("Done");
for (final Map.Entry<File, ParseException> aEntry : aErrors.entrySet()) s_aLogger.info(" " + aEntry.getKey().getAbsolutePath() + ":\n" + aEntry.getValue().getMessage() + "\n");
s_aLogger.info("OK: " + nFilesOK + "; Error: " + nFilesError);
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class WikiCreateFontFaceRuleFuncTest method test.
@Test
public void test() {
final CascadingStyleSheet aCSS = WikiCreateFontFaceRule.createFontFace("Your \"typeface\"", "local font name", "folder/", "myfont");
final String sCSS = new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS);
System.out.println(sCSS);
final CascadingStyleSheet aCSS2 = CSSReader.readFromString(sCSS, ECSSVersion.CSS30);
assertNotNull(aCSS2);
assertEquals(aCSS, aCSS2);
}
Aggregations