Class ResourceResponse
- java.lang.Object
-
- org.xmlresolver.ResourceResponse
-
public class ResourceResponse extends java.lang.Object
AResourceResponse
is the return type for either an attempt to lookup a resource in the catalog or to resolve a resource. It encapsulates the results of the attempt.
-
-
Field Summary
Fields Modifier and Type Field Description ResourceRequest
request
The request for which this is the response.
-
Constructor Summary
Constructors Constructor Description ResourceResponse(ResourceRequest request)
The simplest constructor for an unsuccessful request.ResourceResponse(ResourceRequest request, boolean rejected)
This constructor is also for an unsuccessful request.ResourceResponse(ResourceRequest request, java.net.URI uri)
The constructor for a successful request (usually).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.xmlresolver.ResourceConnection
getConnection()
Get the resource connection.java.lang.String
getContentType()
Get the content type.java.lang.String
getEncoding()
Get the encoding.java.lang.String
getHeader(java.lang.String name)
Get the value of a specific header.java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaders()
Get the headers.java.io.InputStream
getInputStream()
Get the input stream.java.net.URI
getResolvedURI()
Get the resolved URI.int
getStatusCode()
Get the status code of the request.java.net.URI
getUnmaskedURI()
Get the resolved URI, irrespective of masking.java.net.URI
getURI()
Get the URI.boolean
isRejected()
Was this request rejected?boolean
isResolved()
Was this request successfully resolved?
-
-
-
Field Detail
-
request
public final ResourceRequest request
The request for which this is the response.
-
-
Constructor Detail
-
ResourceResponse
public ResourceResponse(ResourceRequest request)
The simplest constructor for an unsuccessful request.- Parameters:
request
- The request.
-
ResourceResponse
public ResourceResponse(ResourceRequest request, boolean rejected)
This constructor is also for an unsuccessful request.This constructor can explicitly indicate that the request was rejected. For example, if the
ResolverFeature.ACCESS_EXTERNAL_ENTITY
orResolverFeature.ACCESS_EXTERNAL_DOCUMENT
settings did not allow requests for a particular URI scheme.- Parameters:
request
- The request.rejected
- Was this request rejected?
-
ResourceResponse
public ResourceResponse(ResourceRequest request, java.net.URI uri)
The constructor for a successful request (usually).The
request
was satisfied with theuri
. If theuri
is null, the response will indicate that the request was unsuccessful.- Parameters:
request
- The request.uri
- The successfully resolved URI, or null.
-
-
Method Detail
-
getConnection
public org.xmlresolver.ResourceConnection getConnection()
Get the resource connection.If this response was accessed with a resource connection, it will be saved in the response.
- Returns:
- The connection.
-
getContentType
public java.lang.String getContentType()
Get the content type.- Returns:
- The content type, or null if it's unknown.
-
getInputStream
public java.io.InputStream getInputStream()
Get the input stream.If this resource is opened for reading by the resolution attempt, this is its readable stream.
Attempts to resolve a resource will provide a stream if one is available. Requests that simply inspect the catalog (with the lookup* methods) will not.
- Returns:
- The stream, or null if the resource wasn't opened.
-
isRejected
public boolean isRejected()
Was this request rejected?- Returns:
- True if the request was rejected, false otherwise.
-
isResolved
public boolean isResolved()
Was this request successfully resolved?- Returns:
- True if the request was resolved, false otherwise.
-
getURI
public java.net.URI getURI()
Get the URI.This is the initially resolved URI. The distinction between initial and final resolution arises when redirects come into play. Suppose you request
http://example.com/some.dtd
and that resolves in the catalog tohttp://example.com/version2/some.dtd
. The URI returned bygetURI()
will behttp://example.com/version2/some.dtd
. However, if an attempt to obtain that resource encounters redirection at, for example, the HTTP layer, then the actual URI returned may differ, seegetResolvedURI()
.- Returns:
- The URI.
-
getResolvedURI
public java.net.URI getResolvedURI()
Get the resolved URI.This is the finally resolved URI. The distinction between initial and final resolution arises when redirects come into play. Suppose you request
http://example.com/some.dtd
and that resolves in the catalog tohttp://example.com/version2/some.dtd
. If an attempt to obtain that resource encounters redirection at, for example, the HTTP layer, tohttp://cdn.example.com/version2/some.dtd
, the URI returned bygetResolvedURI()
will behttp://cdn.example.com/version2/some.dtd
. SeegetURI()
.If
ResolverFeature.MASK_JAR_URIS
is true and the resolved URI is a jar: URI, thegetURI()
is returned instead.- Returns:
- The resolved URI.
-
getUnmaskedURI
public java.net.URI getUnmaskedURI()
Get the resolved URI, irrespective of masking.Where
getResolvedURI()
will not return ajar:
URI if theResolverFeature.MASK_JAR_URIS
is true, this method always returns the actual, unmasked URI.- Returns:
- The resolved URI, unmasked.
-
getEncoding
public java.lang.String getEncoding()
Get the encoding.- Returns:
- The resource encoding, or null if the encoding is unknown.
-
getHeaders
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders()
Get the headers.This method never returns null, it returns an empty map if no headers are available.
- Returns:
- The headers, if headers are available.
-
getHeader
public java.lang.String getHeader(java.lang.String name)
Get the value of a specific header.This is a convenience method. Headers can be repeated, and consequently have multiple values. This method only returns the first value; that is, the value associated with the first header named
name
encountered during resolution.- Parameters:
name
- The header name.- Returns:
- The (first) value of that header, or null if no such header exists
- Throws:
java.lang.NullPointerException
- if name is null.
-
getStatusCode
public int getStatusCode()
Get the status code of the request.Successful requests return 200 irrespective of the URI scheme.
- Returns:
- the status code.
-
-