|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.mwi.mobileok.basic.Resource
public class Resource
Encapsulates information and basic functionality to represent Web resources.
The information includes the absolute URI of the resource and the list of exchanges that were needed to retrieve the resource along with the representation of the resource in itself.
Nested Class Summary | |
---|---|
static class |
Resource.LoadType
Describes the different ways that a typical browser would handle a resource. |
Field Summary | |
---|---|
private TesterConfiguration |
config
Since the processing will be done in separate threads, we need some local reference to the configuration in use for current processing. |
private DecodedContent |
decodedContent
Decoded content. |
private boolean |
decodedFlag
Flag that asserts whether the resource has been decoded. |
private int |
depth
Depth of the resource in the Web created by the initial resource. |
private Resource.LoadType |
loadType
Browsing rendering type of the resource. |
private boolean |
parsedFlag
Flag that asserts whether the resource has been parsed to extract further resources. |
private ResourceContext |
resourceContext
Context that gave birth to the resource. |
private java.util.List<RetrievalElement> |
retrievedElements
Retrieved resource. |
private boolean |
retrievedFlag
Flag that asserts whether the resource has been retrieved. |
private static java.text.DateFormat[] |
RFC_2616_DATE_FORMATS
Possible date formats for HTTP header fields that contain a date. |
private java.net.URI |
uri
Absolute URI of the resource. |
Constructor Summary | |
---|---|
Resource(java.net.URI uri,
int depth,
ResourceContext resourceContext,
Resource.LoadType loadType)
Creates a class instance bound to a URI, a depth and a context. |
Method Summary | |
---|---|
static int |
compareUrisWithoutFragments(java.net.URI uri1,
java.net.URI uri2)
Compares two absolute URIs, leaving fragment parts aside |
void |
decode()
Decodes the content that has been previously retrieved. |
java.util.List<Resource> |
extractResources(java.util.List<Resource> knownResources)
Extract additional resources from the current resource. |
java.util.List<RetrievalElement> |
getAllRedirects()
Returns the complete list of exchanges, including the resource itself. |
DecodedContent |
getContent()
Returns the resource's decoded content. |
int |
getDepth()
Returns the depth of the resource in the web created by the initial resource. |
RetrievalElement |
getLastRedirect()
Returns the exchange that contains the resource itself. |
Resource.LoadType |
getLoadType()
Returns the load type of the resource. |
RetrievalElement |
getRedirect(int redirect)
Returns the exchange of the intermediate redirection identified by its index. |
int |
getRedirectCount()
Returns the number of redirections that were required to retrieve the resource. |
ResourceContext |
getResourceContext()
Returns the context that gave birth to the resource. |
java.net.URI |
getUri()
Returns the absolute URI of the resource. |
java.lang.String |
getURI(int redirect)
Returns the absolute URI of the intermediate redirection identified by its index. |
boolean |
hasBeenDecoded()
Returns true when the resource has been decoded. |
boolean |
hasBeenParsed()
Returns true when the resource has been parsed in search
of new resources. |
boolean |
hasBeenRetrieved()
Returns true when the resource has been retrieved. |
static boolean |
isValidDateHeader(java.lang.String dateHeader)
Checks that the date is valid according to RFC2616. |
static boolean |
isValidExpirationDate(java.lang.String currentDateStr,
java.lang.String expirationDateStr)
Checks that the expiration date lies in the future of given date. |
static java.net.URI |
massageURI(java.net.URI uri)
Makes sure that the URI is absolute, and automatically adds "http://" when it is not. |
private static java.util.Date |
parseDateHeader(java.lang.String dateHeader)
Parses a string representing a date in one of the formats defined in RFC 2616 as formats that must be parsed by an HTTP/1.1 server. |
static java.net.URI |
parseUri(java.net.URI baseUri,
java.lang.String uriString)
Checks that a URI string is a valid URI, and resolves it against a base URI. |
void |
retrieve()
Retrieves the resource. |
void |
setLoadType(Resource.LoadType type)
Sets the load type of the resource. |
org.w3c.dom.Node |
toMokiNode(org.w3c.dom.Document document)
Serializes the resource to a moki node. |
void |
useRetrievalInformation(java.util.List<RetrievalElement> retrieved)
Use the given retrieval material as the retrieved information of the resource. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.text.DateFormat[] RFC_2616_DATE_FORMATS
private final java.net.URI uri
private final int depth
private final ResourceContext resourceContext
private Resource.LoadType loadType
private java.util.List<RetrievalElement> retrievedElements
private DecodedContent decodedContent
private boolean retrievedFlag
private boolean decodedFlag
private boolean parsedFlag
private TesterConfiguration config
Constructor Detail |
---|
public Resource(java.net.URI uri, int depth, ResourceContext resourceContext, Resource.LoadType loadType)
uri
- absolute URI of the resource.depth
- the depth of the resource.resourceContext
- the context that gave birth to the resource.loadType
- browser rendering type for the resource. The
load type may be set afterwards through a call to
setLoadType(LoadType)
Method Detail |
---|
public static java.net.URI massageURI(java.net.URI uri)
uri
- URI to massage.
public final void retrieve()
The ResourceRetriever
that is used to retrieve the resource
depends on the URI scheme. The ResourceRetrieverFactory
instance
of the current TesterConfiguration
will be used to select the
dedicated one.
The function sets the retrievedFlag
flag.
public final void useRetrievalInformation(java.util.List<RetrievalElement> retrieved)
The function should be used whenever a resource that has already been retrieved needs to be created for another context, not to have to retrieve the resource twice.
The function sets the retrievedFlag
flag.
retrieved
- list of exchanges to use as retrieval informationpublic final void decode() throws TestException
Decoding typically depends on the content-type of the retrieved content. The
The function sets the decodedFlag
flag, except when the
resource has not been retrieved yet through a call to retrieve()
.
TestException
public final java.util.List<Resource> extractResources(java.util.List<Resource> knownResources)
All ResourceExtractor
s defined in the current
TesterConfiguration
are applied to the current resource.
The function sets the parsedFlag
flag, except when the
resource has not been retrieved or decoded yet.
knownResources
- list of resources that are already known.
null
when no
resources were extracted.public final java.net.URI getUri()
public final int getDepth()
public final ResourceContext getResourceContext()
Bear in mind that the ResourceContext
enumeration may be
extended to suit anyone's needs.
public final java.lang.String getURI(int redirect)
See getRedirectCount()
for more details on the meaning of
the term redirection.
redirect
- index of the redirection, starting at 0.
public final boolean hasBeenRetrieved()
true
when the resource has been retrieved.
Please note that a true
value does not entail that the
retrieval of the resource was a success.
The flag is set by the retrieve()
function.
true
when the resource has already been retrieved,
false
otherwise.public final boolean hasBeenDecoded()
true
when the resource has been decoded.
Please note that a true
value does not entail that the
the resource could be successfully decoded.
The flag is set by the decode()
function.
true
when the resource has already been decoded,
false
otherwise.public final boolean hasBeenParsed()
true
when the resource has been parsed in search
of new resources.
The flag is set by the extractResources(List)
function.
true
when the resource has already been parsed,
false
otherwise.public final Resource.LoadType getLoadType()
public final void setLoadType(Resource.LoadType type)
type
- load type to set.public final DecodedContent getContent()
null
when content was not or
could not be decoded.public final int getRedirectCount()
In the HTTP/HTTPS context, the term redirections represents the number of 302 redirect responses received before the final resource was reached. The term may have other meanings in other schemes.
public final RetrievalElement getRedirect(int redirect)
See getRedirectCount()
for more details on the meaning of
the term redirection.
redirect
- index of the redirection, starting at 0.
public final RetrievalElement getLastRedirect()
public final java.util.List<RetrievalElement> getAllRedirects()
public final org.w3c.dom.Node toMokiNode(org.w3c.dom.Document document)
The precise format of the moki node depends on the resource content.
document
- DOM document the created node should belong to
public static java.net.URI parseUri(java.net.URI baseUri, java.lang.String uriString)
baseUri
- base URI against which the URI should be resolveduriString
- URI string to check
null
when the URI is
not valid.public static int compareUrisWithoutFragments(java.net.URI uri1, java.net.URI uri2)
uri1
- First URI to compareuri2
- Second URI to compare
public static boolean isValidExpirationDate(java.lang.String currentDateStr, java.lang.String expirationDateStr)
currentDateStr
- current dateexpirationDateStr
- expiration date
true
when current date is in the
past of expiration date, false
otherwise. Returns true
when the
expiration date is invalid.public static boolean isValidDateHeader(java.lang.String dateHeader)
dateHeader
- date to parse.
true
when the date is valid,
false
otherwise.parseDateHeader(String)
private static java.util.Date parseDateHeader(java.lang.String dateHeader) throws java.text.ParseException
The formats are:
java.text.ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |