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,ContentFileReader,FileReader,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_FORMATSList of allowed formatsprotected static String__DEFAULT_FORMATDefault returned formatprivate int_cropHeightprivate int_cropWidthprivate int_heightprivate int_maxHeightprivate int_maxWidthprivate boolean_readForDownloadprivate int_width-
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 voiddoSetup(SourceResolver res, Map objModel, String src, Parameters par)voidgenerate()protected voidgenerateThumbnail(InputStream is, String format)Generate the thumbnail inOutputStreamoutprotected abstract StringgetEncodedFilename()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 StringgetFilename()Returns the resource's name.protected abstract InputStreamgetInputStream()Returns the resource'sInputStream.protected StringgetKeySuffix()Helper method to compute a suffix based on resizing and cropping properties.protected abstract longgetLength()Returns the resource's length.protected booleanprocessImage()Determines if the file is an image and should be processed.voidsetup(SourceResolver resolver, Map objectModel, 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_FORMATS
protected static final Collection<String> __ALLOWED_FORMATS
List of allowed formats
-
_width
private int _width
-
_height
private int _height
-
_maxWidth
private int _maxWidth
-
_maxHeight
private int _maxHeight
-
_cropWidth
private int _cropWidth
-
_cropHeight
private int _cropHeight
-
_readForDownload
private boolean _readForDownload
-
-
Constructor Detail
-
AbstractResourceReader
public AbstractResourceReader()
-
-
Method Detail
-
setup
public void setup(SourceResolver resolver, Map objectModel, 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
public void generate() throws IOException, SAXException, ProcessingException
-
generateThumbnail
protected void generateThumbnail(InputStream is, String format) throws IOException
Generate the thumbnail inOutputStreamout- 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()
Determines if the file is an image and should be processed.- Returns:
trueif 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.
-
-