|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.mwi.mobileok.basic.CSSUtils
final class CSSUtils
Static helper class that defines useful methods to parse and validate CSS resources using the W3C CSS Validator.
AbstractCSSTestImplementation
,
CssContent
Field Summary | |
---|---|
private static java.util.regex.Pattern |
atMediaPattern
Regular expression to find CSS properties that use the at-media rules. |
private static java.util.regex.Pattern |
backgroundImagePattern
Regular expression to find the URI of images in background-image CSS properties. |
private static java.util.regex.Pattern |
backgroundPattern
Regular expression to find the URI of images in background CSS properties. |
private static java.util.regex.Pattern |
commentPattern
Regular expression to extract CSS comments. |
private static java.util.regex.Pattern |
importPattern
Regular expression to find the URI of external stylesheets imported by a CSS resource using quotes instead of a url(foo) pattern. |
private static java.util.regex.Pattern |
importUrlPattern
Regular expression to find the URI of external stylesheets imported by a CSS resource using a url(foo) pattern. |
private static java.util.regex.Pattern |
listImagePattern
Regular expression to find the URI of images in list-style-image CSS properties. |
Constructor Summary | |
---|---|
private |
CSSUtils()
Private constructor to prevent instanciation, since the class only defined static helper methods. |
Method Summary | |
---|---|
static int |
countExtraneousChars(java.lang.String css)
Computes the number of "useless" characters in the CSS, i.e. |
static void |
extractCSSErrors(java.util.Collection<ValidationLineAndColumnMessage> cssErrorMessageList,
org.w3c.css.css.StyleSheet styleSheet)
Extracts the CSS validation errors from the stylesheet returned by the W3C CSS validator. |
static java.util.List<java.net.URI> |
extractCSSImageResources(java.net.URI baseURI,
java.lang.String body)
Extracts the list of absolute URIs of the images referenced by the CSS. |
static void |
extractCSSWarnings(java.util.Collection<ValidationLineAndColumnMessage> cssWarningMessageList,
org.w3c.css.css.StyleSheet styleSheet)
Extracts the CSS validation warnings from the stylesheet returned by the W3C CSS validator. |
static org.w3c.css.css.StyleSheet |
getStylesheet(java.net.URI cssUri,
CssContent cssContent,
RetrievalElement retrieved)
Parses a CSS content with the W3C CSS validator and returns the result. |
static java.lang.String |
preprocessBody(java.net.URI baseURI,
java.lang.String cssBody,
java.util.Collection<java.net.URI> extractedCSSResources)
Parses a CSS string and only keeps the parts that need to be validated by the W3C CSS Validator. |
private static java.lang.String |
stripToLineBreaks(java.lang.String atMediaBody)
Returns a copy of the input string that only contains the line breaks, i.e. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.util.regex.Pattern importUrlPattern
url(foo)
pattern.
private static final java.util.regex.Pattern importPattern
url(foo)
pattern.
private static final java.util.regex.Pattern commentPattern
private static final java.util.regex.Pattern listImagePattern
list-style-image
CSS properties.
private static final java.util.regex.Pattern backgroundImagePattern
background-image
CSS properties.
private static final java.util.regex.Pattern backgroundPattern
background
CSS properties.
private static final java.util.regex.Pattern atMediaPattern
Constructor Detail |
---|
private CSSUtils()
Method Detail |
---|
public static org.w3c.css.css.StyleSheet getStylesheet(java.net.URI cssUri, CssContent cssContent, RetrievalElement retrieved)
Validation is performed against CSS Level 1, and only concerns the
CSS properties that apply to the handheld
media type.
cssUri
- URI of the CSS to parse. Cannot be null
.cssContent
- CSS Content to parse. Cannot be null
.
null
when validation fails.public static void extractCSSErrors(java.util.Collection<ValidationLineAndColumnMessage> cssErrorMessageList, org.w3c.css.css.StyleSheet styleSheet)
cssErrorMessageList
- the list of CSS validation errors to complete.styleSheet
- the stylesheet returned by the W3C CSS validator.public static void extractCSSWarnings(java.util.Collection<ValidationLineAndColumnMessage> cssWarningMessageList, org.w3c.css.css.StyleSheet styleSheet)
cssWarningMessageList
- the list of CSS validation warnings to complete.styleSheet
- the stylesheet returned by the W3C CSS validator.public static java.util.List<java.net.URI> extractCSSImageResources(java.net.URI baseURI, java.lang.String body)
URIs appear only once in the list, even though they may appear multiple times in the CSS.
baseURI
- base URI of the CSS, used to resolve relative URIs.body
- CSS content to parse.
public static java.lang.String preprocessBody(java.net.URI baseURI, java.lang.String cssBody, java.util.Collection<java.net.URI> extractedCSSResources)
See the CSS Style and Validity sections in the W3C mobileOK Basic Tests 1.0 standard for more details about CSS Style in mobileOK.
The method removes sections that do not need to be checked or that would trigger CSS Level 1 validation errors whereas they are valid in mobileOK. In short, the method:
@import
statementshandheld
media type (through @media
directives)@media
directives from blocks of CSS that
apply to the all
and handheld
media types.Line breaks are kept so that the position lines of potential errors and warnings in the processed CSS matches the original CSS as well.
Through the extractedCSSResources
parameter, the method
may also return the list of CSS resources imported by the CSS and that
applies to no media type or to the all
or handheld
media types.
baseURI
- base URI to use to resolve relative URIs.cssBody
- CSS to process.extractedCSSResources
- the list to fill of absolute URIs of CSS
resources imported by the CSS being parsed.
May be null
. URIs appear only
once in the list.
private static java.lang.String stripToLineBreaks(java.lang.String atMediaBody)
atMediaBody
- string to strip.
public static int countExtraneousChars(java.lang.String css)
css
- CSS to parse.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |