org.w3c.mwi.mobileok.basic
Class CssContent

java.lang.Object
  extended by org.w3c.mwi.mobileok.basic.DecodedContent
      extended by org.w3c.mwi.mobileok.basic.TextContent
          extended by org.w3c.mwi.mobileok.basic.CssContent

public class CssContent
extends TextContent

Represents a CSS content.

The class extends TextContent to add CSS validation.

CSS styles may appear in different forms in a Web resource:

This class is used to represent the three kinds of forms. The underlying RetrievalElement should be used to tell the difference:

Version:
$Revision: 1.1 $
Author:
The W3C mobileOK Checker Task Force

Nested Class Summary
static class CssContent.CssType
          Describes the different types of CSS content that may be handled.
 
Field Summary
private  java.lang.String css
          Original CSS styles as a string.
private  java.util.List<ValidationLineAndColumnMessage> cssErrorMessageList
          List of CSS validation errors.
private  java.util.List<ValidationLineAndColumnMessage> cssWarningMessageList
          List of CSS validation warnings.
private  int extraneousChars
          Number of non-significant whitespaces and comments in the CSS.
private  java.lang.String processedCSS
          CSS styles once processed.
private  CssContent.CssType type
          Type of CSS represented by this instance.
 
Constructor Summary
CssContent(java.net.URI uri, java.util.List<RetrievalElement> retrieved)
          Creates a class instance bound to the URI of a CSS resource.
 
Method Summary
 java.lang.String getCSS()
          Returns the raw CSS string that was retrieved using HTTP.
 java.util.List<ValidationLineAndColumnMessage> getCSSErrorMessageList()
          Returns the list of CSS validation error messages.
 java.util.List<ValidationLineAndColumnMessage> getCSSWarningMessageList()
          Returns the list of CSS validation warnings.
 int getExtraneousChars()
          Returns the number of non significant whitespaces and comments in the CSS.
 java.lang.String getProcessedCSS()
          Returns the CSS style, viewed from a mobileOK point of view, and prepared for CSS validation.
 int getTotalChars()
          Returns the number of characters in the original CSS block.
 CssContent.CssType getType()
          Returns the type of CSS this instance represents.
private  void insertLineInCssMessages(RetrievalElement retrieved)
          Appends the index of the line that contains the inline CSS style in each CSS validation error and/or warning message.
 boolean isValid()
          Returns true if the CSS is valid.
 org.w3c.dom.Node toMokiNode(org.w3c.dom.Document document, org.w3c.dom.Node parent)
          Serializes the content to its moki representation as a DOM node.
 
Methods inherited from class org.w3c.mwi.mobileok.basic.TextContent
getBody, getUTF8ErrorMessageList
 
Methods inherited from class org.w3c.mwi.mobileok.basic.DecodedContent
addByteErrorMessages, addLineAndColumnMessages
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cssErrorMessageList

private java.util.List<ValidationLineAndColumnMessage> cssErrorMessageList
List of CSS validation errors.


cssWarningMessageList

private java.util.List<ValidationLineAndColumnMessage> cssWarningMessageList
List of CSS validation warnings.


css

private final java.lang.String css
Original CSS styles as a string.


processedCSS

private final java.lang.String processedCSS
CSS styles once processed.


extraneousChars

private int extraneousChars
Number of non-significant whitespaces and comments in the CSS.


type

private CssContent.CssType type
Type of CSS represented by this instance.

Constructor Detail

CssContent

CssContent(java.net.URI uri,
           java.util.List<RetrievalElement> retrieved)
     throws TestException
Creates a class instance bound to the URI of a CSS resource.

The content is validated while it is instantiated.

Parameters:
uri - absolute URI of the resource.
retrieved - the retrieved representation of the resource.
Throws:
TestException - an unexpected error occurred while retrieving the resource.
Method Detail

insertLineInCssMessages

private void insertLineInCssMessages(RetrievalElement retrieved)
Appends the index of the line that contains the inline CSS style in each CSS validation error and/or warning message.

The method only adds the line number when the CSS style being considered is an inline CSS style contained within another resource.

Parameters:
retrieved - the last retrieved exchange that represents the resource.

isValid

public boolean isValid()
Returns true if the CSS is valid.

Overrides:
isValid in class TextContent
Returns:
true when CSS validation did not trigger any error, false otherwise.

getCSSErrorMessageList

public java.util.List<ValidationLineAndColumnMessage> getCSSErrorMessageList()
Returns the list of CSS validation error messages.

Returns:
a list of validation errors that include the position of the errors in the CSS.

getCSSWarningMessageList

public java.util.List<ValidationLineAndColumnMessage> getCSSWarningMessageList()
Returns the list of CSS validation warnings.

Returns:
a list of validation warnings that include the position of the warnings in the CSS.

getCSS

public java.lang.String getCSS()
Returns the raw CSS string that was retrieved using HTTP.

Returns:
the original CSS string.

getProcessedCSS

public java.lang.String getProcessedCSS()
Returns the CSS style, viewed from a mobileOK point of view, and prepared for CSS validation.

Returns:
the CSS Style.
See Also:
CSSUtils.preprocessBody(URI, String, java.util.Collection)

getTotalChars

public int getTotalChars()
Returns the number of characters in the original CSS block.

Returns:
the number of characters in the CSS, 0 when CSS is not defined or empty.

getExtraneousChars

public int getExtraneousChars()
Returns the number of non significant whitespaces and comments in the CSS.

Returns:
the number of "useless" characters in the CSS.

getType

public CssContent.CssType getType()
Returns the type of CSS this instance represents.

Returns:
the type of CSS this instance represents.

toMokiNode

public org.w3c.dom.Node toMokiNode(org.w3c.dom.Document document,
                                   org.w3c.dom.Node parent)
Serializes the content to its moki representation as a DOM node.

Overrides:
toMokiNode in class TextContent
Parameters:
document - DOM document the created node should belong to
parent - DOM node to which the representation should be appended.
Returns:
the moki representation of the resource as a DOM node.