org.w3c.mwi.mobileok.basic
Class CssResourceExtractor

java.lang.Object
  extended by org.w3c.mwi.mobileok.basic.CssResourceExtractor
All Implemented Interfaces:
ResourceExtractor

public class CssResourceExtractor
extends java.lang.Object
implements ResourceExtractor

Extracts CSS resources referenced by the given resource that apply to the handheld or all media type.

3 types of CSS resources may be returned:

The extractor runs on XHTML web pages.

URIs whose scheme is not supported are ignored. As far as mobileOK is concerned, this means that URIs must use the scheme HTTP or HTTPS, but note the code actually relies on the list of ResourceRetriever defined in TesterConfiguration.

Version:
$Revision: 1.1 $
Author:
Francois Daoust

Constructor Summary
CssResourceExtractor()
          Default constructor.
 
Method Summary
private  java.util.List<Resource> extractEmbeddedCSS(org.w3c.dom.Document theDOM, java.net.URI parentUri, int parentDepth)
          Extracts the list of CSS Styles defined in style elements in the given DOM document.
private  java.util.List<java.net.URI> extractExternalCss(java.net.URI baseURI, org.w3c.dom.Document theDOM)
          Extracts the list of URIs of the CSS stylesheets referenced in the given DOM document.
private  java.util.List<Resource> extractInlineCSS(org.w3c.dom.Document theDOM, java.net.URI parentUri, int parentDepth)
          Extracts the list of CSS Styles defined in style attributes in the given DOM document.
 java.util.List<Resource> extractResources(Resource resource, java.util.List<Resource> knownResources)
          Extracts additional resources from the given one.
private  void processEmbeddedCSS(org.w3c.dom.NodeList nodeList, java.util.Collection<java.lang.String> embeddedCSS)
          Parses the list of style elements and adds the content of the elements that apply to the handheld, the all or to any media type.
private  void processInlineCSS(org.w3c.dom.NodeList nodeList, java.util.Map<java.lang.String,java.lang.Integer> inlineCSS)
          Parses the list of elements in search of style attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CssResourceExtractor

public CssResourceExtractor()
Default constructor.

Method Detail

extractResources

public java.util.List<Resource> extractResources(Resource resource,
                                                 java.util.List<Resource> knownResources)
Description copied from interface: ResourceExtractor
Extracts additional resources from the given one.

The extracted resources may contain resources that have already been previously extracted, but known resources should not be automatically copied to the returned list.

Specified by:
extractResources in interface ResourceExtractor
Parameters:
resource - resource to parse.
knownResources - list of known resources.
Returns:
list of resources extracted from the resource to parse, null when no resources were extracted.

extractExternalCss

private java.util.List<java.net.URI> extractExternalCss(java.net.URI baseURI,
                                                        org.w3c.dom.Document theDOM)
Extracts the list of URIs of the CSS stylesheets referenced in the given DOM document.

Such stylesheets are defined in:

Parameters:
baseURI - base URI against which relative URIS should be resolved.
theDOM - the DOM document to parse.
Returns:
the list of absolute URIs that identify the CSS stylesheets referenced by the DOM document.

extractEmbeddedCSS

private java.util.List<Resource> extractEmbeddedCSS(org.w3c.dom.Document theDOM,
                                                    java.net.URI parentUri,
                                                    int parentDepth)
Extracts the list of CSS Styles defined in style elements in the given DOM document.

Parameters:
theDOM - the DOM document to parse.
parentUri - URI of the resource being parsed.
parentDepth - depth of the resource being parsed.
Returns:
the list of CSS styles, where each string is the value of a style element.

processEmbeddedCSS

private void processEmbeddedCSS(org.w3c.dom.NodeList nodeList,
                                java.util.Collection<java.lang.String> embeddedCSS)
Parses the list of style elements and adds the content of the elements that apply to the handheld, the all or to any media type.

Parameters:
nodeList - the list of style elements to parse.
embeddedCSS - the list of embedded CSS styles to complete.

extractInlineCSS

private java.util.List<Resource> extractInlineCSS(org.w3c.dom.Document theDOM,
                                                  java.net.URI parentUri,
                                                  int parentDepth)
Extracts the list of CSS Styles defined in style attributes in the given DOM document.

Parameters:
theDOM - the DOM document to parse.
parentUri - URI of the resource being parsed.
parentDepth - depth of the resource being parsed.
Returns:
the list of CSS styles, where each string is the value of a style attribute.

processInlineCSS

private void processInlineCSS(org.w3c.dom.NodeList nodeList,
                              java.util.Map<java.lang.String,java.lang.Integer> inlineCSS)
Parses the list of elements in search of style attributes.

Parameters:
nodeList - the list of elements to parse (and that should contain a style attribute).
inlineCSS - the list of inline CSS styles to complete.