Package org.faceless.publisher.ext
Class MailExtension
java.lang.Object
org.faceless.publisher.ext.MailExtension
- All Implemented Interfaces:
ReportFactoryExtension,ResourceLoader
Allow the loading of javax.mail.internet.WrapMimeMessage 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".
Email is converted into HTML in several steps:
- The Email is parsed and a JSON structure created which has details on all the metadata (headers etc) as well as the URLs for the various parts of the messages.
- The JSON structure is converted to HTML using a template - the API ships with two pre-defined ZTemplate templates for a default conversion and one complying with EA-PDF 1.0
The conversion to JSON is not configurable, but the conversion from JSON to HTML is entirely under user control and can be configured with the following environment properties
- bfo-ext-mail
- Either the name of a predefined template, or the URL of the template to apply
- bfo-ext-mail-template-type
- The template format, which may be "freemarker" or "ztemplate". If not specified, the API will attempt to guess this based on the template URL, defaulting to "ztemplate"
- bfo-ext-mail-template-output-type
- Set to "text/xml" if the template generates XML rather than HTML
- bfo-ext-mail-template-NNN
- Any additional parameters will be set on the template processing instruction
- bfo-ext-mail-NNN
- Any additional parameters will be set in the "env" map of the JSON
- Since:
- 1.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn abstract interface representing a Mail message -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(MailExtension.Message message, Report report) Given aMailExtension.Message, convert it to an object and callReport.load(java.lang.Object)with the result.voidconfigure(Json json) Configure the extension.booleanAttempt 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.Given a Message (as an InputStream, javax.mail.internet.MimeMessage or jakarta.mail.internet.MimeMessage) return aMailExtension.Messagethat wraps it.voidregister(ReportFactory factory) Notify this object it has beem added to a ReportFactory.booleansupports(ResourceDescriptor descriptor) Return true if this ResourceLoader could load a descriptor of the specified type.voidunregister(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, waitMethods inherited from interface org.faceless.publisher.ext.ReportFactoryExtension
register, unregisterMethods inherited from interface org.faceless.publisher.resource.ResourceLoader
isTrustRequired
-
Constructor Details
-
MailExtension
public MailExtension()
-
-
Method Details
-
register
Description copied from interface:ReportFactoryExtensionNotify 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:
registerin interfaceReportFactoryExtension
-
unregister
Description copied from interface:ReportFactoryExtensionNotify 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:
unregisterin interfaceReportFactoryExtension
-
configure
public void configure(Json json) Description copied from interface:ReportFactoryExtensionConfigure 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:
configurein interfaceReportFactoryExtension
-
loadMessage
Given a Message (as an InputStream, javax.mail.internet.MimeMessage or jakarta.mail.internet.MimeMessage) return aMailExtension.Messagethat wraps it.- Throws:
IOException
-
load
Description copied from interface:ReportFactoryExtensionAttempt 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,Readeror similar, and return true. If this extension cannot load the specified type of object, return false. This is the default.- Specified by:
loadin interfaceReportFactoryExtension- Throws:
IOException
-
apply
Given aMailExtension.Message, convert it to an object and callReport.load(java.lang.Object)with the result. The default implementation converts the message to Json and makes use of thebfo-ext-mailand other environment properties to convert that JSON to HTML by processing it with aProcessingInstructionthat loads a template. Custom conversion is possible by overriding this method.- Parameters:
message- the messagereport- the report- Throws:
IOException
-
supports
Description copied from interface:ResourceLoaderReturn 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:
supportsin interfaceResourceLoader
-
load
public ResourceFlavor load(ResourceDescriptor descriptor, Resource resource, URL2Connection con) throws Exception Description copied from interface:ResourceLoaderAttempt 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:
loadin 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
-