Project Wonder 5.0

er.attachment.processors
Class ERAttachmentProcessor<T extends ERAttachment>

java.lang.Object
  extended by er.attachment.processors.ERAttachmentProcessor<T>
Type Parameters:
T - the type of ERAttachment that this processor processes
Direct Known Subclasses:
ERDatabaseAttachmentProcessor, ERFileAttachmentProcessor, ERS3AttachmentProcessor

public abstract class ERAttachmentProcessor<T extends ERAttachment>
extends java.lang.Object

ERAttachmentProcessors provide the implementation of the communication with the attachment storage method, including import, URL generation, and stream generation.

ERAttachmentProcessors also provide support for path template variables. Read the er.attachment package.html for more information.

Author:
mschrag
Properties
er.attachment.maxSize the maximum size of an uploaded attachment
           
er.attachment.[configurationName].maxSize the maximum size of an uploaded attachment
           
er.attachment.[configurationName].storageTypeer.attachment.[configurationName].storageType
           
er.attachment.storageTypeer.attachment.storageType
           
er.attachment.[configurationName].proxyAsAttachmenter.attachment.[configurationName].proxyAsAttachment
           
er.attachment.proxyAsAttachmenter.attachment.proxyAsAttachment
           

Nested Class Summary
static class ERAttachmentProcessor.ERXAttachmentExceedsLengthException
          ERXAttachmentExceedsLengthException thrown when an attachment exceeds the maximum attachment size.
 
Field Summary
static org.apache.log4j.Logger log
           
 
Constructor Summary
ERAttachmentProcessor()
           
 
Method Summary
protected static java.lang.String _parsePathTemplate(ERAttachment attachment, java.lang.String templatePath, java.lang.String recommendedFileName)
          Parses a path template with ${ext}, ${fileName}, ${hash}, ${uuid}, and ${pk} variables in it.
abstract  T _process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile, java.lang.String recommendedFileName, java.lang.String mimeType, java.lang.String configurationName, java.lang.String ownerID, boolean pendingDelete)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
static void addAttachmentProcessorForType(ERAttachmentProcessor<?> processor, java.lang.String storageType)
          Adds a new attachment processor for the given storage type.
abstract  java.io.InputStream attachmentInputStream(T attachment)
          Returns an InputStream to the data of the given attachment.
 void attachmentInserted(T attachment)
          Called after an attachment has been inserted (from didInsert).
abstract  java.lang.String attachmentUrl(T attachment, com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context)
          Returns a URL to the attachment's data.
 IERAttachmentProcessorDelegate delegate()
          Returns the attachment processor delegate for this processor.
abstract  void deleteAttachment(T attachment)
          Deletes the attachment from the data store.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, ERPendingAttachment pendingAttachment)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile, java.lang.String recommendedFilePath)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile, java.lang.String recommendedFilePath, java.lang.String mimeType)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile, java.lang.String recommendedFilePath, java.lang.String mimeType, int width, int height, java.lang.String configurationName, java.lang.String ownerID)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
 T process(com.webobjects.eocontrol.EOEditingContext editingContext, java.io.File uploadedFile, java.lang.String recommendedFilePath, java.lang.String mimeType, java.lang.String configurationName, java.lang.String ownerID)
          Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it.
static
<T extends ERAttachment>
ERAttachmentProcessor<T>
processorForConfigurationName(java.lang.String configurationName)
          Returns the processor that corresponds to the given configuration name ("s3", "db", "file", etc).
static
<T extends ERAttachment>
ERAttachmentProcessor<T>
processorForType(java.lang.String storageType)
          Returns the processor that corresponds to the given storage type ("s3", "db", "file", etc).
static
<T extends ERAttachment>
ERAttachmentProcessor<T>
processorForType(T attachment)
          Returns the processor that corresponds to the given attachment.
static com.webobjects.foundation.NSMutableDictionary<java.lang.String,ERAttachmentProcessor<?>> processors()
          Returns all of the processors mapped by storageType.
protected  java.lang.String proxiedUrl(T attachment, com.webobjects.appserver.WOContext context)
          Returns a URL to the given attachment that routes via the ERAttachmentRequestHandler.
 boolean proxyAsAttachment(T attachment)
          Returns whether or not the proxy request handler should return this as an attachment with a Content-Disposition.
 void setDelegate(IERAttachmentProcessorDelegate delegate)
          Sets the attachment processor delegate for this processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
Constructor Detail

ERAttachmentProcessor

public ERAttachmentProcessor()
Method Detail

processors

public static com.webobjects.foundation.NSMutableDictionary<java.lang.String,ERAttachmentProcessor<?>> processors()
Returns all of the processors mapped by storageType.

Returns:
all of the processors mapped by storageType

processorForType

public static <T extends ERAttachment> ERAttachmentProcessor<T> processorForType(T attachment)
Returns the processor that corresponds to the given attachment.

Type Parameters:
T - the attachment type
Parameters:
attachment - the attachment to lookup a processor for
Returns:
the attachment's processor

processorForType

public static <T extends ERAttachment> ERAttachmentProcessor<T> processorForType(java.lang.String storageType)
Returns the processor that corresponds to the given storage type ("s3", "db", "file", etc).

Parameters:
storageType - the type of processor to lookup
Returns:
the storage type's processor

processorForConfigurationName

public static <T extends ERAttachment> ERAttachmentProcessor<T> processorForConfigurationName(java.lang.String configurationName)
Returns the processor that corresponds to the given configuration name ("s3", "db", "file", etc).

Parameters:
configurationName - the configuration name to use to lookup the default storage type
Returns:
the storage type's processor

addAttachmentProcessorForType

public static void addAttachmentProcessorForType(ERAttachmentProcessor<?> processor,
                                                 java.lang.String storageType)
Adds a new attachment processor for the given storage type.

Parameters:
processor - the processor
storageType - the storage type that corresponds to the processor

_parsePathTemplate

protected static java.lang.String _parsePathTemplate(ERAttachment attachment,
                                                     java.lang.String templatePath,
                                                     java.lang.String recommendedFileName)
Parses a path template with ${ext}, ${fileName}, ${hash}, ${uuid}, and ${pk} variables in it. See the ERAttachment top level documentation for more information.

Parameters:
attachment - the attachment being processed
templatePath - the template path definition
recommendedFileName - the original file name recommended by the uploading user

setDelegate

public void setDelegate(IERAttachmentProcessorDelegate delegate)
Sets the attachment processor delegate for this processor.

Parameters:
delegate - the attachment processor delegate for this processor

delegate

public IERAttachmentProcessorDelegate delegate()
Returns the attachment processor delegate for this processor.

Returns:
the attachment processor delegate for this processor

proxiedUrl

protected java.lang.String proxiedUrl(T attachment,
                                      com.webobjects.appserver.WOContext context)
Returns a URL to the given attachment that routes via the ERAttachmentRequestHandler.

Parameters:
attachment - the attachment to proxy
context - the context
Returns:
an ERAttachmentRequestHandler URL

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 java.io.File uploadedFile)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will NOT be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the file to attach (which will NOT be deleted at the end)
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 java.io.File uploadedFile,
                 java.lang.String recommendedFilePath)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the uploaded temporary file (which will be deleted at the end)
recommendedFilePath - the filename recommended by the user during import
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 java.io.File uploadedFile,
                 java.lang.String recommendedFilePath,
                 java.lang.String mimeType)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the uploaded temporary file (which will be deleted at the end)
recommendedFilePath - the filename recommended by the user during import
mimeType - the mimeType to use (null = guess based on file extension)
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 java.io.File uploadedFile,
                 java.lang.String recommendedFilePath,
                 java.lang.String mimeType,
                 java.lang.String configurationName,
                 java.lang.String ownerID)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the uploaded temporary file (which will be deleted at the end)
recommendedFilePath - the filename recommended by the user during import
mimeType - the mimeType to use (null = guess based on file extension)
configurationName - the name of the configuration settings to use for this processor (see top level docs)
ownerID - an arbitrary string that represents the ID of the "owner" of this thumbnail (Person.primaryKey, for instance)
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 java.io.File uploadedFile,
                 java.lang.String recommendedFilePath,
                 java.lang.String mimeType,
                 int width,
                 int height,
                 java.lang.String configurationName,
                 java.lang.String ownerID)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the uploaded temporary file (which will be deleted at the end)
recommendedFilePath - the filename recommended by the user during import
mimeType - the mimeType to use (null = guess based on file extension)
configurationName - the name of the configuration settings to use for this processor (see top level docs)
ownerID - an arbitrary string that represents the ID of the "owner" of this thumbnail (Person.primaryKey, for instance)
width - the desired width of the attachment
height - the desired height of the attachment
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

process

public T process(com.webobjects.eocontrol.EOEditingContext editingContext,
                 ERPendingAttachment pendingAttachment)
                               throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
pendingAttachment - the ERPendingAttachment that encapsulates the import information
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

attachmentInserted

public void attachmentInserted(T attachment)
Called after an attachment has been inserted (from didInsert).

Parameters:
attachment - the inserted attachment

proxyAsAttachment

public boolean proxyAsAttachment(T attachment)
Returns whether or not the proxy request handler should return this as an attachment with a Content-Disposition.

Returns:
true if the proxy should use a content-disposition

_process

public abstract T _process(com.webobjects.eocontrol.EOEditingContext editingContext,
                           java.io.File uploadedFile,
                           java.lang.String recommendedFileName,
                           java.lang.String mimeType,
                           java.lang.String configurationName,
                           java.lang.String ownerID,
                           boolean pendingDelete)
                                         throws java.io.IOException
Processes an uploaded file, imports it into the appropriate data store, and returns an ERAttachment that represents it. uploadedFile will be deleted after the import process is complete.

Parameters:
editingContext - the EOEditingContext to create the ERAttachment in
uploadedFile - the uploaded temporary file (which will be deleted at the end)
recommendedFileName - the filename recommended by the user during import
mimeType - the mimeType to use (null = guess based on file extension)
configurationName - the name of the configuration settings to use for this processor (see top level docs)
ownerID - an arbitrary string that represents the ID of the "owner" of this thumbnail (Person.primaryKey, for instance)
pendingDelete - if true, the uploadedFile will be deleted after import; if false, it will be left alone
Returns:
an ERAttachment that represents the file
Throws:
java.io.IOException - if the processing fails

attachmentInputStream

public abstract java.io.InputStream attachmentInputStream(T attachment)
                                                   throws java.io.IOException
Returns an InputStream to the data of the given attachment.

Parameters:
attachment - the attachment to retrieve the data for
Returns:
an InputStream onto the data
Throws:
java.io.IOException - if the stream cannot be created

attachmentUrl

public abstract java.lang.String attachmentUrl(T attachment,
                                               com.webobjects.appserver.WORequest request,
                                               com.webobjects.appserver.WOContext context)
Returns a URL to the attachment's data.

Parameters:
attachment - the attachment to generate a URL for
request - the current request
context - the current context
Returns:
a URL to the attachment's data

deleteAttachment

public abstract void deleteAttachment(T attachment)
                               throws java.io.IOException
Deletes the attachment from the data store.

Parameters:
attachment - the attachment to delete
Throws:
java.io.IOException - if the delete fails

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.