Class MailExtension
- All Implemented Interfaces:
ReportFactoryExtension
,ResourceLoader
Allow the loading of javax.mail.internet.MimeMessage
Mail messages
into the Report. They can be loaded by either passing an instance of that
class into the Report.load(java.lang.Object)
method, or by parsing an object of
media type "message/rfc822".
This class requires the javax.mail.internet
package; typically
the required Jars are called javax.mail.jar
and activation.jar
There are many different ways to format an RFC822 message in HTML, so this
class has the concept of a MailExtension.Configuration
to control that. There are several
configurations included with the API, and it's possible to create your own too.
We highly recommend the use of ZTemplate
templates to do this: all the included Configurations use this approach
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A Configuration controls how an arbitrary mail message is converted to input that can be used by BFO Publisher. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
configure
(Json json) Configure the extension.static MailExtension.Configuration
findConfiguration
(String name) Find a configuration from the list of available configurations that matches the specified name.static List<MailExtension.Configuration>
Return a read-only list the of the available configurations.getConfiguration
(Report report) Return the Configuration for the specified Report - this will check thebfo-ext-mail
environment
property on the Report (if specified) or the ReportFactory (ifreport
isnull
).boolean
Attempt to load the specified object into the specified Report.load
(ResourceDescriptor descriptor, Resource resource, URL2Connection con) Attempt to load a Resource from the specified URL2Connection.static MailExtension.Configuration
newTemplateConfiguration
(String name, String type, boolean xml, URL2 url) Create a new Configuration that will apply a template (eg ZTemplate or FreeMarker) to the JSON representation of the messagevoid
register
(ReportFactory factory) Notify this object it has beem added to a ReportFactory.void
Set the configuration option for email conversion.boolean
supports
(ResourceDescriptor descriptor) Return true if this ResourceLoader could load a descriptor of the specified type.void
unregister
(ReportFactory factory) Notify this object it has been removed from a ReportFactory.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.faceless.publisher.ext.ReportFactoryExtension
register, unregister
Methods inherited from interface org.faceless.publisher.resource.ResourceLoader
isTrustRequired
-
Constructor Details
-
MailExtension
public MailExtension()
-
-
Method Details
-
register
Description copied from interface:ReportFactoryExtension
Notify this object it has beem added to a ReportFactory. Will be called when this object is added to the list returned byReportFactory.getReportFactoryExtensions()
. The default implementation is a no-op.- Specified by:
register
in interfaceReportFactoryExtension
-
unregister
Description copied from interface:ReportFactoryExtension
Notify this object it has been removed from a ReportFactory. Will be called when this object is removed from the list returned byReportFactory.getReportFactoryExtensions()
. The default implementation is a no-op.- Specified by:
unregister
in interfaceReportFactoryExtension
-
configure
public void configure(Json json) Description copied from interface:ReportFactoryExtension
Configure the extension. This method will be called by the web-service immediately after the extension is added, to pass in any parameters set by the user. The default implementation does nothing- Specified by:
configure
in interfaceReportFactoryExtension
-
setConfiguration
Set the configuration option for email conversion.- Parameters:
conf
- a Configuration, ornull
to use the default.
-
getAvailableConfigurations
Return a read-only list the of the available configurations. -
findConfiguration
Find a configuration from the list of available configurations that matches the specified name. The name is compared case-insensitively and ignoring/ , - .
and whitespace.- Parameters:
name
- the name to match- Returns:
- the matching configuration, or
null
if none was found.
-
getConfiguration
Return the Configuration for the specified Report - this will check thebfo-ext-mail
environment
property on the Report (if specified) or the ReportFactory (ifreport
isnull
). If that is not set, or is set to an invalid valid, the value set bysetConfiguration(org.faceless.publisher.ext.MailExtension.Configuration)
is checked next, and that is null the first Configuration returned fromgetAvailableConfigurations()
is used.- Parameters:
report
- the Report to check for the environment variable; if null, the ReportFactory will be checked instead.- Returns:
- the
MailExtension.Configuration
used by this extension to convert aMimeMessage
to aReport
- See Also:
-
newTemplateConfiguration
public static MailExtension.Configuration newTemplateConfiguration(String name, String type, boolean xml, URL2 url) Create a new Configuration that will apply a template (eg ZTemplate or FreeMarker) to the JSON representation of the message- Parameters:
name
- the name of this configurationtype
- the type of template, currently "ztemplate" or "freemarker"xml
- if true, the template outputs XHTML, if false it outputs HTMLurl
- the URL of the template to apply
-
load
Description copied from interface:ReportFactoryExtension
Attempt to load the specified object into the specified Report. If this extension can load the specified type of object, it should configure the report however it needs to, eventually callReportFactoryExtension.load(java.lang.Object, org.faceless.publisher.Report)
with anInputSource
,Reader
or similar, and return true. If this extension cannot load the specified type of object, return false. This is the default.- Specified by:
load
in interfaceReportFactoryExtension
- Throws:
IOException
-
supports
Description copied from interface:ResourceLoader
Return true if this ResourceLoader could load a descriptor of the specified type. The resourceClass, outputClass and mediaType of the descriptor should be checked as appropriate. The MediaType in particular will not be a wildcard for normal use; it may be a wildcard if we're being called fromResourceManager.getResourceLoader(org.faceless.publisher.type.MediaType, java.lang.Class<?>)
.- Specified by:
supports
in interfaceResourceLoader
-
load
public ResourceFlavor load(ResourceDescriptor descriptor, Resource resource, URL2Connection con) throws Exception Description copied from interface:ResourceLoader
Attempt to load a Resource from the specified URL2Connection. If the ResourceLoader applies (it should test the resource mediatype and class) then it should load the resource from the URL. If the URI has a fragment and the loaded resource to ALL fragments, it should change the URI to have no fragment. Likewise if any aspect of the MediaType does not apply (i.e. the encoding) then it should remove it, so the Resource describes the widest possible URI and MediaType that would match this object. Finally, on success this method should set the Object on the resource, or throw an exception on failure. The supplied "con" will have an InputStream that is mark-capable already. If the stream is a gzip or brotli compresed stream, decompression will already be applied. The mediatype wil be set on "d". Returning null from this object is considered an error condition - if that happens we shouldn't have got here, and the only reason we did was because "supports" for the same descriptor returned true.- Specified by:
load
in interfaceResourceLoader
- Parameters:
descriptor
- the descriptor of what type of flavor we want.resource
- the Resource we're populatingcon
- the URLConnection to load the resource from- Returns:
- the new Flavor, or null if it doesn't apply.
- Throws:
Exception
-