org.apache.jackrabbit.net
Class JCRJarURLConnection

java.lang.Object
  extended by java.net.URLConnection
      extended by org.apache.jackrabbit.net.JCRURLConnection
          extended by org.apache.jackrabbit.net.JCRJarURLConnection

public class JCRJarURLConnection
extends JCRURLConnection

The JCRJarURLConnection extends the JCRURLConnection class to support accessing archive files stored in a JCR Repository.

Just like the base class, this class requires the URL to resolve, either directly or through primary item chain, to a repository Property.

Access to this connections property and archive entry content is perpared with the connect(), which after calling the base class implementation to find the property tries to find the archive entry and set the connection's fields according to the entry. This implementation's connect() method fails if the named entry does not exist in the archive.

The getInputStream() method either returns an stream on the archive entry or on the archive depending on whether an entry path is specified in the URL or not. Like the base class implementation, this implementation returns a new InputStream on each invocation.

If an entry path is defined on the URL, the header fields are set from the archive entry:

Content-TypeGuessed from the entry name or application/octet-stream if the type cannot be guessed from the name
Content-Encodingnull
Content-LengthThe size of the entry
Last-ModifiedThe last modification time of the entry

If no entry path is defined on the URL, the header fields are set from the property by the base class implementation with the exception of the content type, which is set to application/java-archive by the connect() method.

Note that this implementation does only support archives stored in the JCR Repository, no other contained storage such as file or http is supported.

This class is not intended to be subclassed or instantiated by clients.

Author:
Felix Meschberger

Field Summary
protected static String APPLICATION_JAR
          The name of the MIME content type for this connection's content if no entry path is defined on the URL (value is "application/java-archive").
 
Fields inherited from class org.apache.jackrabbit.net.JCRURLConnection
APPLICATION_OCTET, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE, LAST_MODIFIED, TEXT_PLAIN
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
 
Method Summary
 void connect()
          Connects to the URL setting the header fields and preparing for the JCRURLConnection.getProperty() and getInputStream() methods.
 InputStream getInputStream()
          Returns an input stream that reads from this open connection.
 
Methods inherited from class org.apache.jackrabbit.net.JCRURLConnection
failure, getContentEncoding, getContentLength, getContentType, getHandler, getHeaderField, getHeaderField, getHeaderFieldKey, getHeaderFields, getItem, getLastModified, getPath, getProperty, getSession, setContentEncoding, setContentLength, setContentType, setLastModified, setProperty
 
Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldDate, getHeaderFieldInt, getIfModifiedSince, getOutputStream, getPermission, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

APPLICATION_JAR

protected static final String APPLICATION_JAR
The name of the MIME content type for this connection's content if no entry path is defined on the URL (value is "application/java-archive").

See Also:
Constant Field Values
Method Detail

connect

public void connect()
             throws IOException
Connects to the URL setting the header fields and preparing for the JCRURLConnection.getProperty() and getInputStream() methods.

After calling the base class implemenation to get the basic connection, the entry is looked for in the archive to set the content type, content length and last modification time header fields according to the named entry. If no entry is defined on the URL, only the content type header field is set to application/java-archive.

When this method successfully returns, this connection is considered connected. In case of an exception thrown, the connection is not connected.

Overrides:
connect in class JCRURLConnection
Throws:
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.

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns an input stream that reads from this open connection. If not entry path is specified in the URL, this method returns the input stream providing access to the archive as a whole. Otherwise the input stream returned is a JarInputStream positioned at the start of the named entry.

NOTES:

Calling this method implicitly calls connect() to ensure the connection is open.

Overrides:
getInputStream in class JCRURLConnection
Returns:
The InputStream on the archive or the entry if specified.
Throws:
IOException - if an error occurrs opening the connection through connect() or creating the InputStream on the repository Property.
See Also:
JCRURLConnection.connect()


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.