org.w3c.mwi.mobileok.basic
Class ObjectResourceExtractor

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

public class ObjectResourceExtractor
extends java.lang.Object
implements ResourceExtractor

Extracts resources defined within object elements in the given XHTML resource, and resources defined in img elements that appear as the fallback content of an object element that would not be rendered by browsers.

In practice, the class implements the Object Element Processing Rule defined in the W3C mobileOK Basic Tests 1.0 specification.

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

Field Summary
private  java.util.Collection<java.net.URI> extractedImageUris
          Internal list of extracted image URIs.
private  java.util.List<Resource> knownResources
          List of resources already retrieved.
private  int resourceDepth
          Depth of the resource bein parsed.
 
Constructor Summary
ObjectResourceExtractor()
          Default constructor.
 
Method Summary
private  void extractImages(org.w3c.dom.Element parent, java.net.URI baseURI)
          Extracts yet-unknown URIs of images that are direct children of the given object element, but that are not children of another object element.
private  java.util.List<Resource> extractObjectsResources(java.util.List<org.w3c.dom.Node> topLevelObjects, java.net.URI baseURI)
          Recursive method to extract the list of objects resources that are referenced by the given objects and that need to be retrieved to render the given list of objects.
 java.util.List<Resource> extractResources(Resource resource, java.util.List<Resource> knownResources)
          Extracts additional resources from the given one.
private  java.util.List<org.w3c.dom.Node> getTopLevelObjects(org.w3c.dom.Element parent)
          Returns the list of first generation object elements that are children of the given Element, skipping any intermediary markup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extractedImageUris

private java.util.Collection<java.net.URI> extractedImageUris
Internal list of extracted image URIs.


knownResources

private java.util.List<Resource> knownResources
List of resources already retrieved.


resourceDepth

private int resourceDepth
Depth of the resource bein parsed.

Constructor Detail

ObjectResourceExtractor

public ObjectResourceExtractor()
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.

extractObjectsResources

private java.util.List<Resource> extractObjectsResources(java.util.List<org.w3c.dom.Node> topLevelObjects,
                                                         java.net.URI baseURI)
Recursive method to extract the list of objects resources that are referenced by the given objects and that need to be retrieved to render the given list of objects.

Recursive parsing is needed for object elements because of the possibility to define fallback mechanisms.

Note the function needs to access the tester configuration per-thread singleton. Since extraction is typically done using multithreading, make sure the singleton is set in the thread that calls this function!

Parameters:
topLevelObjects - the list of top-level-objects known at this level.
baseURI - base URI against which relative URIS should be resolved.
Returns:
the list of object and image resources that need to be retrieved to render the given list of objects. May return an empty list.

getTopLevelObjects

private java.util.List<org.w3c.dom.Node> getTopLevelObjects(org.w3c.dom.Element parent)
Returns the list of first generation object elements that are children of the given Element, skipping any intermediary markup.

Parameters:
parent - Element to parse.
Returns:
the list of top level object elements in given Element.

extractImages

private void extractImages(org.w3c.dom.Element parent,
                           java.net.URI baseURI)
Extracts yet-unknown URIs of images that are direct children of the given object element, but that are not children of another object element.

Objects are parsed recursively. Each time the fallback content would be rendered by browsers, the images contained within this fallback content would be rendered as well, and need to be taken into account.

Parameters:
parent - Object parent to parse
baseURI - base URI against which relative URIS will be resolved.