Package org.ametys.core.util.cocoon
Class AbstractResourceReader
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.reading.AbstractReader
org.ametys.core.util.cocoon.AbstractResourceReader
- All Implemented Interfaces:
Poolable,Recyclable,Component,LogEnabled,Reader,SitemapModelComponent,SitemapOutputComponent
- Direct Known Subclasses:
AmetysResourceReader,UploadReader
Abstract reader for Ametys resources.
If the resource is an image, this reader handles resizing and cropping.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Collection<String>List of allowed output formatsprotected static final StringDefault returned formatprotected static final Collection<String>List of format that cannot be resizedFields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voiddoSetup(SourceResolver res, Map objModel, String src, Parameters par) voidgenerate()protected voidgenerateThumbnail(InputStream is, String format) Generate the thumbnail inOutputStreamoutprotected abstract StringIf needed, returns the resource's name, properly encoded for using in a "Content-Disposition" HTTP header.
May be null, in which case the result ofgetFilename()is used instead.protected abstract StringReturns the resource's name.protected abstract InputStreamReturns the resource'sInputStream.protected StringHelper method to compute a suffix based on resizing and cropping properties.protected abstract longReturns the resource's length.protected booleanprocessImage(String fileExtension) Determines if the file is an image and should be processed.voidsetup(SourceResolver sresolver, Map sObjectModel, String src, Parameters par) Methods inherited from class org.apache.cocoon.reading.AbstractReader
getLastModified, getMimeType, recycle, setOutputStream, shouldSetContentLengthMethods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Field Details
-
__DEFAULT_FORMAT
Default returned format- See Also:
-
__ALLOWED_OUTPUT_FORMATS
List of allowed output formats -
__UNRESIZABLE_FORMATS
List of format that cannot be resized
-
-
Constructor Details
-
AbstractResourceReader
public AbstractResourceReader()
-
-
Method Details
-
setup
public void setup(SourceResolver sresolver, Map sObjectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException - Specified by:
setupin interfaceSitemapModelComponent- Overrides:
setupin classAbstractReader- Throws:
ProcessingExceptionSAXExceptionIOException
-
doSetup
protected abstract void doSetup(SourceResolver res, Map objModel, String src, Parameters par) throws ProcessingException, IOException Called bysetup(SourceResolver, Map, String, Parameters). This method should be implemented by subclasses to retrieve the actual resource.- Parameters:
res- theSourceResolver.objModel- the Cocoon's object model.src- the source, as given by the sitemap.par- the parameters, as given by the sitemap.- Throws:
ProcessingException- if an error occurs while processing the resource.IOException- if an error occurs while accessing the resource.
-
generate
-
generateThumbnail
Generate the thumbnail inOutputStreamout- Parameters:
is- original imageformat- format of the file- Throws:
IOException- if an error occurs when manipulating streams.
-
getInputStream
Returns the resource'sInputStream.- Returns:
- the resource's
InputStream.
-
getFilename
Returns the resource's name.- Returns:
- the resource's name.
-
getEncodedFilename
If needed, returns the resource's name, properly encoded for using in a "Content-Disposition" HTTP header.
May be null, in which case the result ofgetFilename()is used instead.- Returns:
- the encoded resource's name, if any.
-
getLength
Returns the resource's length.- Returns:
- the resource's length.
-
processImage
Determines if the file is an image and should be processed.- Parameters:
fileExtension- The file extension to process- Returns:
trueif file is a image
-
getKeySuffix
Helper method to compute a suffix based on resizing and cropping properties.- Returns:
- a String to be used in cache keys.
-