Class TemporaryDocumentPreviewService
java.lang.Object
com.saperion.ngc.viewer.temporary.TemporaryDocumentPreviewService
- All Implemented Interfaces:
Serializable
This service class is used to cache the binary content of uploaded documents in order to be
displayed by a indexing masks viewer.
- Author:
- sts
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic TemporaryDocumentId
cacheDocument
(byte[] document) Caches the document represented by the given byte array.static TemporaryDocumentId
cacheDocument
(InputStream stream) Caches the document represented by the given input stream.static TemporaryDocumentId
cacheDocument
(org.zkoss.util.media.Media media) Caches the document represented by the given media.static void
disable()
Disables the temporary document preview service.static boolean
enable
(long maxViewSizeInBytes) Enables the temporary document preview service.static InputStream
Returns a previously cached document as anInputStream
.static byte[]
Returns a previously cached document as a byte array.static boolean
Indicates if this services is enabled and if temporary documents can be cached.
-
Method Details
-
enable
public static boolean enable(long maxViewSizeInBytes) Enables the temporary document preview service.- Parameters:
maxViewSizeInBytes
- maximum size of viewable documents- Returns:
- true, if enabling was successful, false otherwise.
-
disable
public static void disable()Disables the temporary document preview service. -
isEnabled
public static boolean isEnabled()Indicates if this services is enabled and if temporary documents can be cached.- Returns:
- true, if this services is enabled, false otherwise.
-
cacheDocument
public static TemporaryDocumentId cacheDocument(InputStream stream) throws ViewSizeException, NotEnabledException, InternalCacheException Caches the document represented by the given input stream.- Parameters:
stream
- The document stream to cache.- Returns:
- a
TemporaryDocumentId
identifying the cached document. - Throws:
ViewSizeException
- when the document is too large to cacheInternalCacheException
- if the caching of the temporary content failedNotEnabledException
- if this service is not enabled or a failure occurred.
-
cacheDocument
public static TemporaryDocumentId cacheDocument(byte[] document) throws ViewSizeException, NotEnabledException, InternalCacheException Caches the document represented by the given byte array.- Parameters:
document
- The document to cache.- Returns:
- a
TemporaryDocumentId
identifying the cached document. - Throws:
ViewSizeException
- when the document is too large to cacheInternalCacheException
- if the caching of the temporary content failedNotEnabledException
- if this service is not enabled or a failure occurred.
-
cacheDocument
public static TemporaryDocumentId cacheDocument(org.zkoss.util.media.Media media) throws ViewSizeException, NotEnabledException, InternalCacheException Caches the document represented by the given media.- Parameters:
media
- The document to cache.- Returns:
- a
TemporaryDocumentId
identifying the cached document. - Throws:
ViewSizeException
- when the document is too large to cacheInternalCacheException
- if the caching of the temporary content failedNotEnabledException
- if this service is not enabled or a failure occurred.IOException
- if reading from the media failed
-
getDocumentAsByteArray
Returns a previously cached document as a byte array.- Parameters:
id
- The id of a previously cached document.- Returns:
- the cached document as a byte array.
- Throws:
Exception
- if this service is not enabled, the requested document is not available in cache or a failure occurred.
-
getDocument
public static InputStream getDocument(TemporaryDocumentId id) throws NotEnabledException, com.saperion.cache.exception.ElementNotFoundException, InternalCacheException Returns a previously cached document as anInputStream
.- Parameters:
id
- The id of a previously cached document.- Returns:
- the cached document as an
InputStream
. - Throws:
NotEnabledException
- if this service is not enabled,com.saperion.cache.exception.ElementNotFoundException
- if the requested document is not available in cacheInternalCacheException
- if an error occurred while reading from the cache
-