本文整理汇总了Java中com.helger.css.reader.CSSReader类的典型用法代码示例。如果您正苦于以下问题:Java CSSReader类的具体用法?Java CSSReader怎么用?Java CSSReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSSReader类属于com.helger.css.reader包,在下文中一共展示了CSSReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
public String process( String input )
{
CascadingStyleSheet css = CSSReader.readFromString( input, CCharset.CHARSET_UTF_8_OBJ, ECSSVersion.CSS30 );
CascadingStyleSheet out = new CascadingStyleSheet();
for( ICSSTopLevelRule rule : css.getAllRules() )
{
ICSSTopLevelRule outRule = filterRule( rule );
if( outRule != null )
out.addRule( outRule );
}
CSSWriterSettings settings = new CSSWriterSettings( ECSSVersion.CSS30, true );
settings.setRemoveUnnecessaryCode( true );
return new CSSWriter( settings ).getCSSAsString( out );
}
开发者ID:ltearno,项目名称:hexa.tools,代码行数:17,代码来源:CssRewriter.java
示例2: getRewrittenCSS
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
/**
* Get the rewritten version of the passed CSS code. This is done by
* interpreting the CSS and than writing it again with the passed settings.
* This can e.g. be used to create a compressed version of a CSS.
*
* @param sOriginalCSS
* The original CSS code to be compressed.
* @param aSettings
* The CSS writer settings to use. The version is used to read the
* original CSS.
* @return If compression failed because the CSS is invalid or whatsoever, the
* original CSS is returned, else the rewritten version is returned.
*/
@Nonnull
public static String getRewrittenCSS (@Nonnull final String sOriginalCSS, @Nonnull final CSSWriterSettings aSettings)
{
ValueEnforcer.notNull (sOriginalCSS, "OriginalCSS");
ValueEnforcer.notNull (aSettings, "Settings");
final CascadingStyleSheet aCSS = CSSReader.readFromString (sOriginalCSS, aSettings.getVersion ());
if (aCSS != null)
{
try
{
return new CSSWriter (aSettings).getCSSAsString (aCSS);
}
catch (final Exception ex)
{
s_aLogger.warn ("Failed to write optimized CSS!", ex);
}
}
return sOriginalCSS;
}
开发者ID:phax,项目名称:ph-css,代码行数:34,代码来源:CSSCompressor.java
示例3: parseToMediaQuery
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
/**
* 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 ();
}
开发者ID:phax,项目名称:ph-css,代码行数:27,代码来源:MediaQueryTools.java
示例4: test2
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void test2 () throws ParseException
{
final ParserCSS30TokenManager aTokenHdl = new ParserCSS30TokenManager (new CSSCharStream (new NonBlockingStringReader (CSS2)));
aTokenHdl.setDebugStream (System.out);
final ParserCSS30 aParser = new ParserCSS30 (aTokenHdl);
aParser.disable_tracing ();
final CSSNode aNode = aParser.styleSheet ();
assertNotNull (aNode);
final CascadingStyleSheet aCSS = CSSHandler.readCascadingStyleSheetFromNode (ECSSVersion.CSS30,
aNode,
CSSReader.getDefaultInterpretErrorHandler ());
assertNotNull (aCSS);
for (final ICSSTopLevelRule aTopLevelRule : aCSS.getAllFontFaceRules ())
assertTrue (aCSS.removeRule (aTopLevelRule).isChanged ());
}
开发者ID:phax,项目名称:ph-css,代码行数:19,代码来源:ParserCSS30Test.java
示例5: _testMe
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
private void _testMe (@Nonnull final File aFile, @Nonnull final ECSSVersion eVersion)
{
if (false)
s_aLogger.info (aFile.getAbsolutePath ());
// read and interpret
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, eVersion);
assertNotNull (aFile.getAbsolutePath (), aCSS);
// Both normal and optimized!
for (int i = 0; i < 2; ++i)
{
// write to buffer
final String sCSS = new CSSWriter (eVersion, i == 1).getCSSAsString (aCSS);
if (false)
System.out.println ("--" + i + "--\n" + sCSS);
// read again from buffer
assertEquals (aFile.getAbsolutePath () +
(i == 0 ? " unoptimized" : " optimized"),
aCSS,
CSSReader.readFromString (sCSS, eVersion));
}
}
开发者ID:phax,项目名称:ph-css,代码行数:25,代码来源:CSSWriterFuncTest.java
示例6: testRead30Write21
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testRead30Write21 () throws IOException
{
for (final File aFile : new FileSystemRecursiveIterator (new File ("src/test/resources/testfiles/css30/good/artificial")).withFilter (IFileFilter.filenameEndsWith (".css")))
{
final String sKey = aFile.getAbsolutePath ();
try
{
// read and interpret CSS 3.0
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, ECSSVersion.CSS30);
assertNotNull (sKey, aCSS);
// write to CSS 2.1
final NonBlockingStringWriter aSW = new NonBlockingStringWriter ();
new CSSWriter (ECSSVersion.CSS21).writeCSS (aCSS, aSW);
// This should throw an error
fail (sKey + " should have thrown an exception but got: " + aSW.getAsString ());
}
catch (final IllegalStateException ex)
{}
}
}
开发者ID:phax,项目名称:ph-css,代码行数:24,代码来源:CSSWriterFuncTest.java
示例7: testCompressCSS_Size
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testCompressCSS_Size ()
{
final CascadingStyleSheet aCSS = CSSReader.readFromStream (new ClassPathResource ("/testfiles/css21/good/phloc/test/content.css"),
StandardCharsets.UTF_8,
ECSSVersion.CSS30);
assertNotNull (aCSS);
// Only whitespace optimization
final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS21, true);
String sContent = new CSSWriter (aSettings).getCSSAsString (aCSS);
assertEquals (2846, sContent.length ());
// Also remove empty declarations
aSettings.setRemoveUnnecessaryCode (true);
sContent = new CSSWriter (aSettings).getCSSAsString (aCSS);
assertEquals (2839, sContent.length ());
}
开发者ID:phax,项目名称:ph-css,代码行数:19,代码来源:CSSWriterFuncTest.java
示例8: testWriteCertainRules
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testWriteCertainRules ()
{
final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, true);
aSettings.setWriteFontFaceRules (false);
aSettings.setWriteKeyframesRules (false);
aSettings.setWriteMediaRules (false);
aSettings.setWritePageRules (false);
final CSSWriter aWriter = new CSSWriter (aSettings).setWriteHeaderText (false);
// Some non-special rules
CascadingStyleSheet aCSS = CSSReader.readFromString (CSS3, ECSSVersion.CSS30);
assertNotNull (aCSS);
assertEquals ("h1{color:red;margin:1px}h2{color:rgb(1,2,3)}h3{}", aWriter.getCSSAsString (aCSS));
// Only @media rule
aCSS = CSSReader.readFromString (CSS4, ECSSVersion.CSS30);
assertNotNull (aCSS);
assertEquals ("", aWriter.getCSSAsString (aCSS));
// Nothing special
aCSS = CSSReader.readFromString (CSS5, ECSSVersion.CSS30);
assertNotNull (aCSS);
assertEquals ("h1{color:red;margin:1px}h2{color:red;margin:1px}", aWriter.getCSSAsString (aCSS));
}
开发者ID:phax,项目名称:ph-css,代码行数:26,代码来源:CSSWriterTest.java
示例9: readAllSelectors
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
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);
}
开发者ID:phax,项目名称:ph-css,代码行数:27,代码来源:WikiVisitSelectors.java
示例10: testIssue8
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testIssue8 ()
{
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue8.css");
assertTrue (aRes.exists ());
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
StandardCharsets.UTF_8,
ECSSVersion.CSS30,
new LoggingCSSParseErrorHandler ());
assertNotNull (aCSS);
assertEquals (1, aCSS.getStyleRuleCount ());
final CSSStyleRule aStyleRule = aCSS.getStyleRuleAtIndex (0);
assertNotNull (aStyleRule);
assertEquals (4, aStyleRule.getDeclarationCount ());
}
开发者ID:phax,项目名称:ph-css,代码行数:18,代码来源:Issue8Test.java
示例11: testIssue
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testIssue ()
{
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue21.css");
assertTrue (aRes.exists ());
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
.setCustomErrorHandler (new LoggingCSSParseErrorHandler ())
.setBrowserCompliantMode (true));
assertNotNull (aCSS);
if (false)
System.out.println (new CSSWriter (ECSSVersion.CSS30).getCSSAsString (aCSS));
assertEquals (2, aCSS.getRuleCount ());
assertEquals (2, aCSS.getStyleRuleCount ());
}
开发者ID:phax,项目名称:ph-css,代码行数:17,代码来源:Issue21Test.java
示例12: testIssue
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testIssue ()
{
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad_but_browsercompliant/issue19.css");
assertTrue (aRes.exists ());
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
.setCSSVersion (ECSSVersion.CSS30)
.setCustomErrorHandler (new LoggingCSSParseErrorHandler ())
.setBrowserCompliantMode (true));
assertNotNull (aCSS);
if (false)
System.out.println (new CSSWriter (ECSSVersion.CSS30).getCSSAsString (aCSS));
assertEquals (1, aCSS.getRuleCount ());
assertEquals (1, aCSS.getStyleRuleCount ());
}
开发者ID:phax,项目名称:ph-css,代码行数:18,代码来源:Issue19Test.java
示例13: testVisitContent30
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@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));
}
}
开发者ID:phax,项目名称:ph-css,代码行数:18,代码来源:CSSVisitor30FuncTest.java
示例14: testGetWrapped
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testGetWrapped ()
{
// Read and arbitrary CSS
final CascadingStyleSheet aBaseCSS = CSSReader.readFromString ("p { color:red;}", s_eVersion);
assertNotNull (aBaseCSS);
// Create structured media queries
final List <CSSMediaQuery> aMQs = MediaQueryTools.parseToMediaQuery ("screen", s_eVersion);
assertNotNull (aMQs);
// Wrap the source CSS with the specified media queries
final CascadingStyleSheet aWrappedCSS = MediaQueryTools.getWrappedInMediaQuery (aBaseCSS, aMQs, false);
assertNotNull (aWrappedCSS);
assertEquals ("@media screen{p{color:red}}", new CSSWriter (s_eVersion, true).getCSSAsString (aWrappedCSS));
}
开发者ID:phax,项目名称:ph-css,代码行数:17,代码来源:MediaQueryToolsTest.java
示例15: createRegistry
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
private IHtmlNotificationCssRegistry createRegistry(IResourceStream resourceStream) throws ServiceException {
CascadingStyleSheet sheet = CSSReader.readFromStream(new WicketResourceStreamToPhlocInputStreamProviderWrapper(resourceStream),
Charset.defaultCharset(), ECSSVersion.CSS30);
if (sheet == null) {
throw new ServiceException("An error occurred while parsing notification CSS; see the logs for details.");
} else {
return new SimplePhlocCssHtmlNotificationCssRegistry(sheet);
}
}
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:11,代码来源:PhlocCssHtmlNotificationCssServiceImpl.java
示例16: parse
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Override
public void parse(File cssFile) throws CssParsingException {
final CascadingStyleSheet data = CSSReader.readFromFile(cssFile, CCharset.CHARSET_UTF_8_OBJ, ECSSVersion.CSS30);
if (data == null) {
throw new CssParsingException();
}
CSSVisitor.visitCSS(data, new CssVisitor());
}
开发者ID:acharpen,项目名称:mocss,代码行数:9,代码来源:Css3Parser.java
示例17: asNativeFormat
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Override
public CascadingStyleSheet asNativeFormat()
{
CascadingStyleSheet css = null;
try
{
String cssString = new String(getData(), getInputEncoding());
css = CSSReader.readFromString(cssString, ECSSVersion.CSS30);
}
catch (IOException e)
{
logger.error("", e);
}
return css;
}
开发者ID:finanzer,项目名称:epubfx,代码行数:16,代码来源:CSSResource.java
示例18: testSimpleScssFile
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testSimpleScssFile() {
// Creates the file context and sets the precision option.
final Sass_File_Context fileContext = SassLibrary.INSTANCE.sass_make_file_context(this.simpleScssPath.toFile().getAbsolutePath());
final Sass_Context context = SassLibrary.INSTANCE.sass_file_context_get_context(fileContext);
final Sass_Options contextOptions = SassLibrary.INSTANCE.sass_context_get_options(context);
SassLibrary.INSTANCE.sass_option_set_source_map_contents(contextOptions, (byte) 1);
SassLibrary.INSTANCE.sass_option_set_omit_source_map_url(contextOptions, (byte) 0);
SassLibrary.INSTANCE.sass_option_set_source_map_file(contextOptions, this.simpleMapPath.toFile().getAbsolutePath());
SassLibrary.INSTANCE.sass_option_set_precision(contextOptions, 10);
// Performs the actual compilation.
final int compilerStatus = SassLibrary.INSTANCE.sass_compile_file_context(fileContext);
// Retrieves the CSS output string.
final String outputString;
final String sourceMapString;
try {
if (compilerStatus != 0) {
outputString = null;
sourceMapString = null;
final String errorMessage = SassLibrary.INSTANCE.sass_context_get_error_message(context);
fail(errorMessage);
} else {
outputString = SassLibrary.INSTANCE.sass_context_get_output_string(context);
sourceMapString = SassLibrary.INSTANCE.sass_context_get_source_map_string(context);
}
} finally {
SassLibrary.INSTANCE.sass_delete_file_context(fileContext);
}
// Asserts, that the creates cascading style sheet can be read and parsed.
final CascadingStyleSheet styleSheet = CSSReader.readFromString(outputString, ECSSVersion.LATEST);
assertNotNull(styleSheet);
assertNotNull(sourceMapString);
}
开发者ID:cathive,项目名称:sass-java,代码行数:40,代码来源:SassLibraryTest.java
示例19: testRemoveUnnecessaryCode2
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testRemoveUnnecessaryCode2 ()
{
final CascadingStyleSheet aCSS = CSSReader.readFromString (CSS4, ECSSVersion.CSS30);
assertNotNull (aCSS);
final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30,
false).setRemoveUnnecessaryCode (true);
final CSSWriter aWriter = new CSSWriter (aSettings).setWriteHeaderText (false);
assertEquals ("@media print {\n" +
" h1 {\n" +
" color:red;\n" +
" margin:1px;\n" +
" }\n" +
"\n" +
" h2 { color:rgb(1,2,3); }\n" +
"\n" +
" @keyframes x {\n" +
" from {\n" +
" align:left;\n" +
" color:#123;\n" +
" }\n" +
" to { x:y; }\n" +
" }\n" +
"\n" +
" @page {\n" +
" margin:1in;\n" +
" marks:none;\n" +
" }\n" +
"\n" +
" @page :first { margin:2in; }\n" +
"\n" +
" @font-face {\n" +
" font-family:'Soho';\n" +
" src:url(Soho.eot);\n" +
" }\n" +
"\n" +
" @font-face { src:local('Soho Gothic Pro'); }\n" +
"}\n",
aWriter.getCSSAsString (aCSS));
}
开发者ID:phax,项目名称:ph-css,代码行数:41,代码来源:CSSWriterTest.java
示例20: testHeaderText
import com.helger.css.reader.CSSReader; //导入依赖的package包/类
@Test
public void testHeaderText ()
{
final CascadingStyleSheet aCSS = CSSReader.readFromString (CSS5, ECSSVersion.CSS30);
assertNotNull (aCSS);
// Non-optimized version
CSSWriter aWriter = new CSSWriter (ECSSVersion.CSS30, false).setWriteHeaderText (true).setHeaderText ("Unit test");
assertEquals ("/*\n" +
" * Unit test\n" +
" */\n" +
"h1 {\n" +
" color:red;\n" +
" margin:1px;\n" +
"}\n" +
"\n" +
"h2 {\n" +
" color:red;\n" +
" margin:1px;\n" +
"}\n",
aWriter.getCSSAsString (aCSS));
// Optimized version
aWriter = new CSSWriter (ECSSVersion.CSS30, true).setWriteHeaderText (true).setHeaderText ("Unit test2");
assertEquals ("/*\n" +
" * Unit test2\n" +
" */\n" +
"h1{color:red;margin:1px}h2{color:red;margin:1px}",
aWriter.getCSSAsString (aCSS));
}
开发者ID:phax,项目名称:ph-css,代码行数:31,代码来源:CSSWriterTest.java
注:本文中的com.helger.css.reader.CSSReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论