org.alfresco.repo.content
Class AbstractContentWriter

java.lang.Object
  extended by org.alfresco.repo.content.AbstractContentAccessor
      extended by org.alfresco.repo.content.AbstractContentWriter
All Implemented Interfaces:
org.alfresco.service.cmr.repository.ContentAccessor, org.alfresco.service.cmr.repository.ContentWriter
Direct Known Subclasses:
FileContentWriter

public abstract class AbstractContentWriter
extends AbstractContentAccessor
implements org.alfresco.service.cmr.repository.ContentWriter

Implements all the convenience methods of the interface. The only methods that need to be implemented, i.e. provide low-level content access are:


Nested Class Summary
 
Nested classes/interfaces inherited from class org.alfresco.repo.content.AbstractContentAccessor
AbstractContentAccessor.CallbackFileChannel, AbstractContentAccessor.ChannelCloseCallbackAdvise
 
Constructor Summary
protected AbstractContentWriter(java.lang.String contentUrl, org.alfresco.service.cmr.repository.ContentReader existingContentReader)
           
 
Method Summary
 void addListener(org.alfresco.service.cmr.repository.ContentStreamListener listener)
          Adds the listener after checking that the output stream isn't already in use.
protected abstract  org.alfresco.service.cmr.repository.ContentReader createReader()
          A factory method for subclasses to implement that will ensure the proper implementation of the ContentWriter.getReader() method.
 java.io.OutputStream getContentOutputStream()
           
protected abstract  java.nio.channels.WritableByteChannel getDirectWritableChannel()
          Provides low-level access to write content to the repository.
protected  org.alfresco.service.cmr.repository.ContentReader getExistingContentReader()
           
 java.nio.channels.FileChannel getFileChannel(boolean truncate)
          
 org.alfresco.service.cmr.repository.ContentReader getReader()
          Performs checks and copies required reader attributes
 java.nio.channels.WritableByteChannel getWritableChannel()
           
 void guessEncoding()
          When the content has been written, attempt to guess the encoding of it.
 void guessMimetype(java.lang.String filename)
          When the content has been written, attempt to guess the mimetype of it, using the filename and contents.
 boolean isChannelOpen()
           
 boolean isClosed()
          An automatically created listener sets the flag
 void putContent(org.alfresco.service.cmr.repository.ContentReader reader)
           
 void putContent(java.io.File file)
           
 void putContent(java.io.InputStream is)
           
 void putContent(java.lang.String content)
          Makes use of the encoding, if available, to convert the string to bytes.
 void setMimetypeService(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)
          Supplies the Mimetype Service to be used when guessing encoding and mimetype information.
 
Methods inherited from class org.alfresco.repo.content.AbstractContentAccessor
channelOpened, finalize, getCallbackFileChannel, getContentData, getContentUrl, getEncoding, getLocale, getMimetype, setContentUrl, setEncoding, setLocale, setMimetype, 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
getContentData, getContentUrl, getEncoding, getLocale, getMimetype, getSize, setEncoding, setLocale, setMimetype
 

Constructor Detail

AbstractContentWriter

protected AbstractContentWriter(java.lang.String contentUrl,
                                org.alfresco.service.cmr.repository.ContentReader existingContentReader)
Parameters:
contentUrl - the content URL
existingContentReader - a reader of a previous version of this content
Method Detail

setMimetypeService

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


getExistingContentReader

protected org.alfresco.service.cmr.repository.ContentReader getExistingContentReader()
Returns:
Returns a reader onto the previous version of this content

addListener

public void addListener(org.alfresco.service.cmr.repository.ContentStreamListener listener)
Adds the listener after checking that the output stream isn't already in use.

Specified by:
addListener in interface org.alfresco.service.cmr.repository.ContentAccessor

createReader

protected abstract org.alfresco.service.cmr.repository.ContentReader createReader()
                                                                           throws org.alfresco.service.cmr.repository.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:
org.alfresco.service.cmr.repository.ContentIOException

getReader

public final org.alfresco.service.cmr.repository.ContentReader getReader()
                                                                  throws org.alfresco.service.cmr.repository.ContentIOException
Performs checks and copies required reader attributes

Specified by:
getReader in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException

isClosed

public final boolean isClosed()
An automatically created listener sets the flag

Specified by:
isClosed in interface org.alfresco.service.cmr.repository.ContentWriter

isChannelOpen

public boolean isChannelOpen()
Specified by:
isChannelOpen in interface org.alfresco.service.cmr.repository.ContentAccessor

getDirectWritableChannel

protected abstract java.nio.channels.WritableByteChannel getDirectWritableChannel()
                                                                           throws org.alfresco.service.cmr.repository.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:
org.alfresco.service.cmr.repository.ContentIOException - if the channel could not be opened

getWritableChannel

public final java.nio.channels.WritableByteChannel getWritableChannel()
                                                               throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getWritableChannel in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
AbstractContentWriter.getDirectWritableChannel(), #getCallbackWritableChannel()

getFileChannel

public java.nio.channels.FileChannel getFileChannel(boolean truncate)
                                             throws org.alfresco.service.cmr.repository.ContentIOException

Specified by:
getFileChannel in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException

getContentOutputStream

public java.io.OutputStream getContentOutputStream()
                                            throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
getContentOutputStream in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
Channels.newOutputStream(java.nio.channels.WritableByteChannel)

putContent

public void putContent(org.alfresco.service.cmr.repository.ContentReader reader)
                throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
putContent in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
ContentReader.getContentInputStream(), AbstractContentWriter.putContent(InputStream)

putContent

public final void putContent(java.io.InputStream is)
                      throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
putContent in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException

putContent

public final void putContent(java.io.File file)
                      throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
putContent in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.ContentIOException

putContent

public final void putContent(java.lang.String content)
                      throws org.alfresco.service.cmr.repository.ContentIOException
Makes use of the encoding, if available, to convert the string to bytes.

Specified by:
putContent in interface org.alfresco.service.cmr.repository.ContentWriter
Throws:
org.alfresco.service.cmr.repository.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 org.alfresco.service.cmr.repository.ContentWriter
See Also:
ContentWriter.guessEncoding()

guessMimetype

public void guessMimetype(java.lang.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 org.alfresco.service.cmr.repository.ContentWriter
See Also:
ContentWriter.guessMimetype(String)


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.