Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

org.alfresco.repo.content
Class AbstractContentWriter
java.lang.Object
  org.alfresco.repo.content.AbstractContentWriter
All Implemented Interfaces:
ContentWriter, ContentAccessor
Direct Known Subclasses:
FileContentWriter

public abstract class AbstractContentWriter
extends Object
implements ContentWriter, ContentAccessor
Implements all the convenience methods of the interface. The only methods that need to be implemented, i.e. provide low-level content access are:
Author:
Derek Hulley

Constructor Summary
protected
AbstractContentWriter(String contentUrl, ContentReader existingContentReader)
Method Summary
void
addListener(ContentStreamListener listener)
          Adds the listener after checking that the output stream isn't already in use.
protected void
channelOpened()
          Derived classes can call this method to ensure that necessary trace logging is performed when the IO Channel is opened.
protected abstract ContentReader
createReader()
          A factory method for subclasses to implement that will ensure the proper implementation of the ContentWriter.getReader() method.
protected void
finalize()
protected FileChannel
getCallbackFileChannel(FileChannel directChannel, List<ContentStreamListener> listeners)
          Generate a callback instance of the FileChannel.
getContentData()
          Get the data representation of the content being accessed.
protected org.alfresco.repo.content.ContentLimitProvider
getContentLimitProvider()
          This method returns the configured ContentLimitProvider for this writer.
getContentOutputStream()
          Get a stream to write to the underlying channel.
getContentUrl()
          Retrieve the URL that this accessor references
protected abstract WritableByteChannel
getDirectWritableChannel()
          Provides low-level access to write content to the repository.
getEncoding()
          Get the encoding of the content being accessed
protected ContentReader
getExistingContentReader()
getFileChannel(boolean truncate)
          Provides read-write, random-access to the underlying content.
getLocale()
          Get the locale of the content being accessed
getMimetype()
          Get the content mimetype
getReader()
          Performs checks and copies required reader attributes
getWritableChannel()
          Provides low-level access to write to repository content.
void
guessEncoding()
          When the content has been written, attempt to guess the encoding of it.
void
guessMimetype(String filename)
          When the content has been written, attempt to guess the mimetype of it, using the filename and contents.
boolean
isChannelOpen()
          Gets the open/close state of the underlying IO Channel.
boolean
isClosed()
          An automatically created listener sets the flag
void
putContent(ContentReader reader)
          Copies content from the reader.
void
putContent(File file)
          Puts content to the repository direct from file
void
putContent(InputStream is)
          Puts content to the repository
void
putContent(String content)
          Makes use of the encoding, if available, to convert the string to bytes.
void
setContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider limitProvider)
protected void
setContentUrl(String contentUrl)
          Allow derived implementations to set the Content URL.
void
setEncoding(String encoding)
          Set the String encoding for this accessor
void
setLocale(Locale locale)
          Set the Locale for this accessor
void
setMimetype(String mimetype)
          Set the mimetype that must be used for accessing the content.
void
setMimetypeService(MimetypeService mimetypeService)
          Supplies the Mimetype Service to be used when guessing encoding and mimetype information.
toString()
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.alfresco.service.cmr.repository.ContentAccessor
getSize
Constructor Detail
AbstractContentWriter
protected AbstractContentWriter(String contentUrl,
                                ContentReader existingContentReader)
Parameters:
contentUrl - the content URL
existingContentReader - a reader of a previous version of this content
Method Detail
setContentLimitProvider
public void setContentLimitProvider(org.alfresco.repo.content.ContentLimitProvider limitProvider)

setMimetypeService
public void setMimetypeService(MimetypeService mimetypeService)
Supplies the Mimetype Service to be used when guessing encoding and mimetype information.

getExistingContentReader
protected ContentReader getExistingContentReader()
Returns:
Returns a reader onto the previous version of this content

addListener
public void addListener(ContentStreamListener listener)
Adds the listener after checking that the output stream isn't already in use.
Specified by:
addListener in interface ContentAccessor
Parameters:
listener - a listener that will be called for output stream event notification

createReader
protected abstract ContentReader createReader()
                                       throws ContentIOException
A factory method for subclasses to implement that will ensure the proper implementation of the ContentWriter.getReader() method.

Only the instance need be constructed. The required mimetype, encoding, etc will be copied across by this class.

Returns:
Returns a reader onto the location referenced by this instance. The instance must always be a new instance and never null.
Throws:
ContentIOException

getReader
public final ContentReader getReader()
                              throws ContentIOException
Performs checks and copies required reader attributes
Specified by:
getReader in interface ContentWriter
Returns:
Returns a reader onto the underlying content that this writer will or has written to
Throws:
ContentIOException

getContentLimitProvider
protected org.alfresco.repo.content.ContentLimitProvider getContentLimitProvider()
This method returns the configured ContentLimitProvider for this writer. By default a ContentLimitProvider.NoLimitProvider will be returned.
Since:
Thor

isClosed
public final boolean isClosed()
An automatically created listener sets the flag
Specified by:
isClosed in interface ContentWriter
Returns:
Return true if the content output stream has been used and closed otherwise false.

isChannelOpen
public boolean isChannelOpen()
Description copied from interface: ContentAccessor
Gets the open/close state of the underlying IO Channel.
Specified by:
isChannelOpen in interface ContentAccessor
Returns:
Returns true if the underlying IO Channel is open

getDirectWritableChannel
protected abstract WritableByteChannel getDirectWritableChannel()
                                                         throws ContentIOException
Provides low-level access to write content to the repository.

This is the only of the content writing methods that needs to be implemented by derived classes. All other content access methods make use of this in their underlying implementations.

Returns:
Returns a channel with which to write content
Throws:
ContentIOException - if the channel could not be opened

getWritableChannel
public final WritableByteChannel getWritableChannel()
                                             throws ContentIOException
Description copied from interface: ContentWriter
Provides low-level access to write to repository content.

The channel returned to the client should remain open (subject to timeouts) until closed by the client. All lock detection, read-only access and other concurrency issues are dealt with during this operation. It remains possible that implementations will throw exceptions when the channel is closed.

The stream will notify any listeners according to the listener interface.

Specified by:
getWritableChannel in interface ContentWriter
Returns:
Returns a channel with which to write content
Throws:
ContentIOException
See Also:
getDirectWritableChannel(), getCallbackWritableChannel(java.nio.channels.WritableByteChannel, List)

getFileChannel
public FileChannel getFileChannel(boolean truncate)
                           throws ContentIOException
Provides read-write, random-access to the underlying content. In general, this method should be considered more expensive than the sequential-access method, ContentWriter.getWritableChannel().

Underlying implementations use the truncate parameter to determine the most effective means of providing access to the content.

Specified by:
getFileChannel in interface ContentWriter
Parameters:
truncate - true to start with zero length content
Returns:
Returns a random-access channel onto the content
Throws:
ContentIOException

getContentOutputStream
public OutputStream getContentOutputStream()
                                    throws ContentIOException
Description copied from interface: ContentWriter
Get a stream to write to the underlying channel.
Specified by:
getContentOutputStream in interface ContentWriter
Returns:
Returns an output stream onto the underlying channel
Throws:
ContentIOException
See Also:
Channels.newOutputStream(java.nio.channels.WritableByteChannel)

putContent
public void putContent(ContentReader reader)
                throws ContentIOException
Description copied from interface: ContentWriter
Copies content from the reader.

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
reader - the reader acting as the source of the content
Throws:
ContentIOException
See Also:
ContentReader.getContentInputStream(), putContent(InputStream)

putContent
public final void putContent(InputStream is)
                      throws ContentIOException
Description copied from interface: ContentWriter
Puts content to the repository

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
is - the input stream from which the content will be read
Throws:
ContentIOException

putContent
public final void putContent(File file)
                      throws ContentIOException
Description copied from interface: ContentWriter
Puts content to the repository direct from file

All resources will be closed automatically.

Specified by:
putContent in interface ContentWriter
Parameters:
file - the file to load the content from
Throws:
ContentIOException

putContent
public final void putContent(String content)
                      throws ContentIOException
Makes use of the encoding, if available, to convert the string to bytes.
Specified by:
putContent in interface ContentWriter
Parameters:
content - a string representation of the content
Throws:
ContentIOException
See Also:
ContentAccessor.getEncoding()

guessEncoding
public void guessEncoding()
When the content has been written, attempt to guess the encoding of it.
Specified by:
guessEncoding in interface ContentWriter
See Also:
ContentWriter.guessEncoding()

guessMimetype
public void guessMimetype(String filename)
When the content has been written, attempt to guess the mimetype of it, using the filename and contents.
Specified by:
guessMimetype in interface ContentWriter
Parameters:
filename - The filename of the content (if known)
See Also:
ContentWriter.guessMimetype(String)

finalize
protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

toString
public String toString()
Overrides:
toString in class Object

getContentData
public ContentData getContentData()
Description copied from interface: ContentAccessor
Get the data representation of the content being accessed.

The content mimetype must be set before this method is called as the content data requires a mimetype whenever the content URL is specified.

Specified by:
getContentData in interface ContentAccessor
Returns:
Returns the content data

channelOpened
protected final void channelOpened()
Derived classes can call this method to ensure that necessary trace logging is performed when the IO Channel is opened.

getContentUrl
public String getContentUrl()
Description copied from interface: ContentAccessor
Retrieve the URL that this accessor references
Specified by:
getContentUrl in interface ContentAccessor
Returns:
the content URL

setContentUrl
protected void setContentUrl(String contentUrl)
Allow derived implementations to set the Content URL. This allows for implementations where the URL is not known when the accessor is first constructed.
Parameters:
contentUrl - the new content URL

getMimetype
public String getMimetype()
Description copied from interface: ContentAccessor
Get the content mimetype
Specified by:
getMimetype in interface ContentAccessor
Returns:
Returns a content mimetype

setMimetype
public void setMimetype(String mimetype)
Description copied from interface: ContentAccessor
Set the mimetype that must be used for accessing the content.

When dealing with a ContentWriter, you may wish to use ContentWriter.guessMimetype(String) to have this set for you based on the filename and contents.

Specified by:
setMimetype in interface ContentAccessor
Parameters:
mimetype - the underlying content's mimetype - null if unknown

getEncoding
public String getEncoding()
Description copied from interface: ContentAccessor
Get the encoding of the content being accessed
Specified by:
getEncoding in interface ContentAccessor
Returns:
Returns the content encoding - null if unknown

setEncoding
public void setEncoding(String encoding)
Description copied from interface: ContentAccessor
Set the String encoding for this accessor

When dealing with a ContentWriter, you may wish to use ContentWriter.guessMimetype(String) to have this set for you based on the contents.

Specified by:
setEncoding in interface ContentAccessor
Parameters:
encoding - the underlying content's encoding - null if unknown

getLocale
public Locale getLocale()
Description copied from interface: ContentAccessor
Get the locale of the content being accessed
Specified by:
getLocale in interface ContentAccessor
Returns:
Returns the content locale or null if unkown

setLocale
public void setLocale(Locale locale)
Description copied from interface: ContentAccessor
Set the Locale for this accessor
Specified by:
setLocale in interface ContentAccessor
Parameters:
locale - the content's locale, if known.

getCallbackFileChannel
protected FileChannel getCallbackFileChannel(FileChannel directChannel,
                                             List<ContentStreamListener> listeners)
                                      throws ContentIOException
Generate a callback instance of the FileChannel.
Parameters:
directChannel - the delegate that to perform the actual operations
listeners - the listeners to call
Returns:
Returns a new channel that functions just like the original, except that it issues callbacks to the listeners
Throws:
ContentIOException

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005–2016 Alfresco Software. All rights reserved.

Java API documentation generated with DocFlex/Javadoc 1.6.1 using JavadocPro template set.