public class JCRURLConnection extends URLConnection
JCRURLConnection
is the URLConnection
implementation to access the data addressed by a JCR Repository URL.
As the primary use of a URLConnection
and thus the
JCRURLConnection
is to provide access to the content of a
resource identified by the URL, it is the primary task of this class to
identify and access a repository Property
based on the URL. This
main task is executed in the connect()
method.
Basically the guideposts to access content from a JCR Repository URL are the following:
jcr:content/jcr:data
or jcr:data
property is
used or the primary item chain starting with this node is followed until
no further primary items exist. If the final item is a property, that
property is used to provide the content.
connect()
fails and access to the content is not possible.
A note on the InputStream
available from
getInputStream()
: Unlike other implementations - for example
for file:
or http:
URLs - which return the same
stream on each call, this implementation returns a new stream on each
invocation.
The following header fields are implemented by this class:
Content-Length
Property.getLength()
method, which returns the size in bytes of the property's value for
binary values and the number of characters used for the string
representation of the value for all other value types.
Content-Type
jcr:mimeType
property of the property's parent node if existing. Otherwise the
guessContentTypeFromName
method is called on the
path
. If this does not yield a content type, it is
set to application/octet-stream
for binary properties and
to text/plain
for other types.
Content-Enconding
jcr:econding
property of the property's parent node if existing. Otherwise this
header field remains undefined (aka null
).
Last-Modified
jcr:lastModified
property of the property's parent node if existing. Otherwise the last
modification time is set to zero.
This class is not intended to be subclassed or instantiated by clients.
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connects to the URL setting the header fields and getting the contents.
|
String |
getContentEncoding()
Returns the content encoding of the data as a string.
|
int |
getContentLength()
Returns the content length of the data as an number.
|
String |
getContentType()
Returns the content type of the data as a string.
|
String |
getHeaderField(int i)
Get the header field with the given index.
|
String |
getHeaderField(String s)
Gets the named header field.
|
String |
getHeaderFieldKey(int i)
Get the name of the header field with the given index.
|
Map<String,List<String>> |
getHeaderFields()
Returns an unmodifiable map of all header fields.
|
InputStream |
getInputStream()
Returns an input stream that reads from this open connection.
|
long |
getLastModified()
Returns the value of the
last-modified header field. |
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentLengthLong, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldLong, getIfModifiedSince, getOutputStream, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
public void connect() throws IOException
The following algorithm is applied:
URLHandler
.
getPrimaryItem
method is
called on that node. If the node has no primary item, the connection
fails.
getPrimaryItem
is still a node, this method fails
because a Property
is required for a successfull
connection.
Property.getLength())
).
jcr:mimeType
,
jcr:encoding
, and jcr:lastModification
properties of the property's parent node if existing. Otherwise the
content encoding field is set to null
and the last
modification time is set to zero. The content type field is guessed
from the name of the URL item. If the content type cannot be
guessed, it is set to application/octet-stream
if the
property is of binary type or text/plain
otherwise.
When this method successfully returns, this connection is considered connected. In case of an exception thrown, the connection is not connected.
connect
in class URLConnection
IOException
- if an error occurrs retrieving the data property or
any of the header field value properties or if any other errors
occurrs. Any cuasing exception is set as the cause of this
exception.public InputStream getInputStream() throws IOException
NOTES:
InputStream
.
Calling this method implicitly calls connect()
to ensure the
connection is open.
getInputStream
in class URLConnection
IOException
- if an error occurrs opening the connection through
connect()
or creating the InputStream
on the
repository Property
.connect()
public String getHeaderField(String s)
null
.
Calling this method implicitly calls connect()
to ensure the
connection is open.
getHeaderField
in class URLConnection
s
- The name of the header field value to return.null
if not one of the
supported fields or the named field's value cannot be retrieved
from the data source.connect()
public String getHeaderField(int i)
getHeaderField(String)
only Content-Length, Content-Type,
Content-Encoding, and Last-Modified are supported. All indexes other
than 0, 1, 2 or 3 will return null
.
Calling this method implicitly calls connect()
to ensure the
connection is open.
getHeaderField
in class URLConnection
i
- The index of the header field value to return.null
if not one of the
supported fields or the known field's value cannot be retrieved
from the data source.connect()
public String getHeaderFieldKey(int i)
getHeaderField(String)
only Content-Length, Content-Type,
Content-Encoding and Last-Modified are supported. All indexes other than
0, 1, 2 or 3 will return null
.
Calling this method implicitly calls connect()
to ensure the
connection is open.
getHeaderFieldKey
in class URLConnection
i
- The index of the header field name to return.null
if not one of the
supported fields.connect()
public Map<String,List<String>> getHeaderFields()
Calling this method implicitly calls connect()
to ensure the
connection is open.
getHeaderFields
in class URLConnection
connect()
.connect()
public String getContentType()
Calling this method implicitly calls connect()
to ensure the
connection is open.
getContentType
in class URLConnection
null
if the
content type cannot be derived from the data source.connect()
public String getContentEncoding()
Calling this method implicitly calls connect()
to ensure the
connection is open.
getContentEncoding
in class URLConnection
null
if the
content encoding cannot be derived from the data source.connect()
public int getContentLength()
Calling this method implicitly calls connect()
to ensure the
connection is open.
getContentLength
in class URLConnection
connect()
public long getLastModified()
last-modified
header field. The
result is the number of milliseconds since January 1, 1970 GMT.
Calling this method implicitly calls connect()
to ensure the
connection is open.
getLastModified
in class URLConnection
URLConnection
was last modified, or -1 if not
known.connect()
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.