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
Modifier and TypeFieldDescriptionprotected static final Collection<String>
List of allowed output formatsprotected static final String
Default 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
doSetup
(SourceResolver res, Map objModel, String src, Parameters par) void
generate()
protected void
generateThumbnail
(InputStream is, String format) Generate the thumbnail inOutputStream
outprotected abstract String
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.protected abstract String
Returns the resource's name.protected abstract InputStream
Returns the resource'sInputStream
.protected String
Helper method to compute a suffix based on resizing and cropping properties.protected abstract long
Returns the resource's length.protected boolean
processImage
(String fileExtension) Determines if the file is an image and should be processed.void
setup
(SourceResolver sresolver, Map sObjectModel, String src, Parameters par) Methods inherited from class org.apache.cocoon.reading.AbstractReader
getLastModified, getMimeType, recycle, setOutputStream, shouldSetContentLength
Methods 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:
setup
in interfaceSitemapModelComponent
- Overrides:
setup
in classAbstractReader
- Throws:
ProcessingException
SAXException
IOException
-
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 inOutputStream
out- 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:
true
if 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.
-