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
public abstract class AbstractResourceReader extends AbstractReader
Abstract reader for Ametys resources. If the resource is an image, this reader handles resizing and cropping.
-
-
Field Summary
Fields Modifier and Type Field Description protected static Collection<String>
__ALLOWED_OUTPUT_FORMATS
List of allowed output formatsprotected static String
__DEFAULT_FORMAT
Default returned formatprotected static Collection<String>
__UNRESIZABLE_FORMATS
List of format that cannot be resized-
Fields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source
-
-
Constructor Summary
Constructors Constructor Description AbstractResourceReader()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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
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.protected abstract String
getFilename()
Returns the resource's name.protected abstract InputStream
getInputStream()
Returns the resource'sInputStream
.protected String
getKeySuffix()
Helper method to compute a suffix based on resizing and cropping properties.protected abstract long
getLength()
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 Detail
-
__DEFAULT_FORMAT
protected static final String __DEFAULT_FORMAT
Default returned format- See Also:
- Constant Field Values
-
__ALLOWED_OUTPUT_FORMATS
protected static final Collection<String> __ALLOWED_OUTPUT_FORMATS
List of allowed output formats
-
__UNRESIZABLE_FORMATS
protected static final Collection<String> __UNRESIZABLE_FORMATS
List of format that cannot be resized
-
-
Constructor Detail
-
AbstractResourceReader
public AbstractResourceReader()
-
-
Method Detail
-
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
public void generate() throws IOException, SAXException, ProcessingException
-
generateThumbnail
protected void generateThumbnail(InputStream is, String format) throws IOException
Generate the thumbnail inOutputStream
out- Parameters:
is
- original imageformat
- format of the file- Throws:
IOException
- if an error occurs when manipulating streams.
-
getInputStream
protected abstract InputStream getInputStream()
Returns the resource'sInputStream
.- Returns:
- the resource's
InputStream
.
-
getFilename
protected abstract String getFilename()
Returns the resource's name.- Returns:
- the resource's name.
-
getEncodedFilename
protected abstract String 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
protected abstract long getLength()
Returns the resource's length.- Returns:
- the resource's length.
-
processImage
protected boolean processImage(String fileExtension)
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
protected String getKeySuffix()
Helper method to compute a suffix based on resizing and cropping properties.- Returns:
- a String to be used in cache keys.
-
-