本文整理汇总了Java中com.helger.css.ECSSVersion类的典型用法代码示例。如果您正苦于以下问题:Java ECSSVersion类的具体用法?Java ECSSVersion怎么用?Java ECSSVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ECSSVersion类属于com.helger.css包,在下文中一共展示了ECSSVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matches
import com.helger.css.ECSSVersion; //导入依赖的package包/类
public boolean matches(CSSSelector selector) {
for (ICSSSelectorMember member : selector.getAllMembers()) {
if (member instanceof CSSSelectorSimpleMember && !((CSSSelectorSimpleMember) member).isPseudo()) {
CSSSelectorSimpleMember simpleMember = (CSSSelectorSimpleMember) member;
if (!matches(simpleMember)) {
return false;
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Only simple selector members ('.class', 'name', '#id') are supported. The selector '{}' and the related declarations will be ignored.",
selector.getAsCSSString(new CSSWriterSettings(ECSSVersion.CSS30), 0));
}
return false;
}
}
return true;
}
示例2: process
import com.helger.css.ECSSVersion; //导入依赖的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 );
}
示例3: testIssue
import com.helger.css.ECSSVersion; //导入依赖的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 ());
}
示例4: isValidCSS
import com.helger.css.ECSSVersion; //导入依赖的package包/类
/**
* Check if the passed CSS resource can be parsed without error
*
* @param aRes
* The resource to be parsed. May not be <code>null</code>.
* @param aCharset
* The charset to be used for reading the CSS file. May not be
* <code>null</code>.
* @param eVersion
* The CSS version to be used for scanning. May not be
* <code>null</code>.
* @return <code>true</code> if the file can be parsed without error,
* <code>false</code> if not
*/
public static boolean isValidCSS (@Nonnull final IReadableResource aRes,
@Nonnull final Charset aCharset,
@Nonnull final ECSSVersion eVersion)
{
ValueEnforcer.notNull (aRes, "Resource");
ValueEnforcer.notNull (aCharset, "Charset");
ValueEnforcer.notNull (eVersion, "Version");
final Reader aReader = aRes.getReader (aCharset);
if (aReader == null)
{
s_aLogger.warn ("Failed to open CSS reader " + aRes);
return false;
}
return isValidCSS (aReader, eVersion);
}
示例5: testMargin1
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testMargin1 ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.MARGIN);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("margin:1px", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (4, aSplittedDecls.size ());
assertEquals ("margin-top:1px", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("margin-right:1px", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("margin-bottom:1px", aSplittedDecls.get (2).getAsCSSString (CWS));
assertEquals ("margin-left:1px", aSplittedDecls.get (3).getAsCSSString (CWS));
}
示例6: readFromStyleAttributeWithVisitor
import com.helger.css.ECSSVersion; //导入依赖的package包/类
public static void readFromStyleAttributeWithVisitor ()
{
final String sStyle = "color:red; background:fixed !important";
final CSSDeclarationList aDeclList = CSSReaderDeclarationList.readFromString (sStyle, ECSSVersion.CSS30);
if (aDeclList == null)
throw new IllegalStateException ("Failed to parse CSS: " + sStyle);
// Create a custom visitor
final ICSSVisitor aVisitor = new DefaultCSSVisitor ()
{
@Override
public void onDeclaration (@Nonnull final CSSDeclaration aDeclaration)
{
System.out.println (aDeclaration.getProperty () +
": " +
aDeclaration.getExpression ().getAsCSSString (new CSSWriterSettings (ECSSVersion.CSS30)) +
(aDeclaration.isImportant () ? " (important)" : " (not important)"));
}
};
CSSVisitor.visitAllDeclarations (aDeclList, aVisitor);
}
示例7: testPadding1
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testPadding1 ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.PADDING);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("padding:1px", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (4, aSplittedDecls.size ());
assertEquals ("padding-top:1px", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("padding-right:1px", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("padding-bottom:1px", aSplittedDecls.get (2).getAsCSSString (CWS));
assertEquals ("padding-left:1px", aSplittedDecls.get (3).getAsCSSString (CWS));
}
示例8: testBorder3b
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testBorder3b ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.BORDER);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("border:red 1px dashed", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (3, aSplittedDecls.size ());
assertEquals ("border-color:red", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("border-width:1px", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("border-style:dashed", aSplittedDecls.get (2).getAsCSSString (CWS));
}
示例9: testBorder1
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testBorder1 ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.BORDER);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("border:1px", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (3, aSplittedDecls.size ());
assertEquals ("border-width:1px", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("border-style:solid", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("border-color:black", aSplittedDecls.get (2).getAsCSSString (CWS));
}
示例10: isValidCSS
import com.helger.css.ECSSVersion; //导入依赖的package包/类
/**
* Check if the passed CSS resource can be parsed without error
*
* @param aRes
* The resource to be parsed. May not be <code>null</code>.
* @param aFallbackCharset
* The charset to be used for reading the CSS file in case neither a
* <code>@charset</code> rule nor a BOM is present. May not be
* <code>null</code>.
* @param eVersion
* The CSS version to be used for scanning. May not be
* <code>null</code>.
* @return <code>true</code> if the file can be parsed without error,
* <code>false</code> if not
*/
public static boolean isValidCSS (@Nonnull final IReadableResource aRes,
@Nonnull final Charset aFallbackCharset,
@Nonnull final ECSSVersion eVersion)
{
ValueEnforcer.notNull (aRes, "Resource");
ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset");
ValueEnforcer.notNull (eVersion, "Version");
final Reader aReader = aRes.getReader (aFallbackCharset);
if (aReader == null)
{
s_aLogger.warn ("Failed to open CSS reader " + aRes);
return false;
}
return isValidCSS (aReader, eVersion);
}
示例11: testWriteCertainRules
import com.helger.css.ECSSVersion; //导入依赖的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));
}
示例12: testReadSingleLineComments
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testReadSingleLineComments ()
{
final ECSSVersion eVersion = ECSSVersion.CSS30;
final Charset aCharset = StandardCharsets.UTF_8;
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-singleline-comments.css");
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset, eVersion);
assertNotNull (aCSS);
assertEquals (13, aCSS.getRuleCount ());
assertEquals (13, aCSS.getStyleRuleCount ());
// #any1 - #any5
assertEquals (2, aCSS.getStyleRuleAtIndex (1).getDeclarationCount ());
assertEquals (1, aCSS.getStyleRuleAtIndex (2).getDeclarationCount ());
assertEquals (1, aCSS.getStyleRuleAtIndex (3).getDeclarationCount ());
assertEquals (0, aCSS.getStyleRuleAtIndex (4).getDeclarationCount ());
assertEquals (0, aCSS.getStyleRuleAtIndex (5).getDeclarationCount ());
// .test1 - .test7
assertEquals (2, aCSS.getStyleRuleAtIndex (6).getDeclarationCount ());
assertEquals (3, aCSS.getStyleRuleAtIndex (7).getDeclarationCount ());
assertEquals (1, aCSS.getStyleRuleAtIndex (8).getDeclarationCount ());
assertEquals (1, aCSS.getStyleRuleAtIndex (9).getDeclarationCount ());
assertEquals (2, aCSS.getStyleRuleAtIndex (10).getDeclarationCount ());
assertEquals (2, aCSS.getStyleRuleAtIndex (11).getDeclarationCount ());
assertEquals (1, aCSS.getStyleRuleAtIndex (12).getDeclarationCount ());
}
示例13: testPadding2
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testPadding2 ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.PADDING);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("padding:1px 3px", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (4, aSplittedDecls.size ());
assertEquals ("padding-top:1px", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("padding-right:3px", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("padding-bottom:1px", aSplittedDecls.get (2).getAsCSSString (CWS));
assertEquals ("padding-left:3px", aSplittedDecls.get (3).getAsCSSString (CWS));
}
示例14: testMargin2
import com.helger.css.ECSSVersion; //导入依赖的package包/类
@Test
public void testMargin2 ()
{
final CSSShortHandDescriptor aSHD = CSSShortHandRegistry.getShortHandDescriptor (ECSSProperty.MARGIN);
assertNotNull (aSHD);
final CSSDeclaration aDecl = CSSReaderDeclarationList.readFromString ("margin:1px 3px", ECSSVersion.CSS30)
.getDeclarationAtIndex (0);
assertNotNull (aDecl);
final List <CSSDeclaration> aSplittedDecls = aSHD.getSplitIntoPieces (aDecl);
assertNotNull (aSplittedDecls);
assertEquals (4, aSplittedDecls.size ());
assertEquals ("margin-top:1px", aSplittedDecls.get (0).getAsCSSString (CWS));
assertEquals ("margin-right:3px", aSplittedDecls.get (1).getAsCSSString (CWS));
assertEquals ("margin-bottom:1px", aSplittedDecls.get (2).getAsCSSString (CWS));
assertEquals ("margin-left:3px", aSplittedDecls.get (3).getAsCSSString (CWS));
}
示例15: writeCSS30
import com.helger.css.ECSSVersion; //导入依赖的package包/类
/**
* Write a CSS 3.0 declaration to a file using UTF-8 encoding.
*
* @param aCSS
* The CSS to be written to a file. May not be <code>null</code>.
* @param aFile
* The file to be written. May not be <code>null</code>.
* @return {@link ESuccess#SUCCESS} if everything went okay, and
* {@link ESuccess#FAILURE} if an error occurred
*/
public ESuccess writeCSS30 (final CascadingStyleSheet aCSS, final File aFile)
{
// 1.param: version to write
// 2.param: false== non-optimized output
final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false);
try
{
final CSSWriter aWriter = new CSSWriter (aSettings);
// Write the @charset rule: (optional)
aWriter.setContentCharset (StandardCharsets.UTF_8.name ());
// Write a nice file header
aWriter.setHeaderText ("This file was generated by phloc-css\nGrab a copy at http://code.google.com/p/phloc-css");
// Convert the CSS to a String
final String sCSSCode = aWriter.getCSSAsString (aCSS);
// Finally write the String to a file
return SimpleFileIO.writeFile (aFile, sCSSCode, StandardCharsets.UTF_8);
}
catch (final Exception ex)
{
s_aLogger.error ("Failed to write the CSS to a file", ex);
return ESuccess.FAILURE;
}
}