Class ClasspathResourceMessageTemplateDataSource
java.lang.Object
net.solarnetwork.central.mail.support.SimpleMessageDataSource
net.solarnetwork.central.mail.support.ClasspathResourceMessageTemplateDataSource
- All Implemented Interfaces:
MessageDataSource,MessageTemplateDataSource
public class ClasspathResourceMessageTemplateDataSource
extends SimpleMessageDataSource
implements MessageTemplateDataSource
MessageTemplateDataSource based on a locale-specific classpath
resource.
The getMessageTemplate() will load a classpath resource located at
the resource path passed to the class constructor. The resource path
must have a file extension, and first this method will insert
_lang before the file extension and attempt to use that
resource, where lang is the language value returned by
Locale.getLanguage() on the Locale object passed to the class
constructor.
If the language-specific resource is not found, it will try to use the
resource path exactly as configured. If that resource cannot be found, a
RuntimeException will be thrown.
-
Field Summary
Fields inherited from interface net.solarnetwork.central.mail.MessageTemplateDataSource
STANDARD_WORD_WRAP_COLUMN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBody()Get the message body.Get the custom ClassLoader to use when resolving the template resource.Get a Locale for the message.org.springframework.core.io.ResourceGet the message template.getModel()Get a message template model to merge into the message.Get a character column index at which to hard-wrap message text at.voidsetClassLoader(ClassLoader classLoader) Set a custom ClassLoader to use when resolving the template resource.voidsetWordWrapCharacterIndex(Integer wordWrapCharacterIndex) Set the word wrap character index.Methods inherited from class net.solarnetwork.central.mail.support.SimpleMessageDataSource
getAttachments, getSubject, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.solarnetwork.central.mail.MessageDataSource
getAttachmentsMethods inherited from interface net.solarnetwork.central.mail.MessageTemplateDataSource
getSubject
-
Constructor Details
-
ClasspathResourceMessageTemplateDataSource
public ClasspathResourceMessageTemplateDataSource(Locale locale, String subject, String resource, Map<String, ?> model) Construct with values.- Parameters:
locale- the locale to use when locating the message resourcesubject- the subject to useresource- the resource path to the message templatemodel- the mail merge model to use
-
-
Method Details
-
getLocale
Description copied from interface:MessageTemplateDataSourceGet a Locale for the message.- Specified by:
getLocalein interfaceMessageTemplateDataSource- Returns:
- a Locale
-
getMessageTemplate
public org.springframework.core.io.Resource getMessageTemplate()Description copied from interface:MessageTemplateDataSourceGet the message template.- Specified by:
getMessageTemplatein interfaceMessageTemplateDataSource- Returns:
- message template
-
getModel
Description copied from interface:MessageTemplateDataSourceGet a message template model to merge into the message.- Specified by:
getModelin interfaceMessageTemplateDataSource- Returns:
- Map of model objects
-
getBody
Description copied from interface:MessageDataSourceGet the message body.- Specified by:
getBodyin interfaceMessageDataSource- Overrides:
getBodyin classSimpleMessageDataSource- Returns:
- the message body, or null if none
-
getClassLoader
Get the custom ClassLoader to use when resolving the template resource.- Returns:
- classLoader The ClassLoader to use.
- Since:
- 1.1
-
setClassLoader
Set a custom ClassLoader to use when resolving the template resource.- Parameters:
classLoader- The ClassLoader to use.- Since:
- 1.1
-
getWordWrapCharacterIndex
Description copied from interface:MessageTemplateDataSourceGet a character column index at which to hard-wrap message text at. Return0to indicate no wrapping should occur.- Specified by:
getWordWrapCharacterIndexin interfaceMessageTemplateDataSource- Returns:
- The word wrap character column index, or null if unspecified.
-
setWordWrapCharacterIndex
Set the word wrap character index.- Parameters:
wordWrapCharacterIndex- The word wrap character index to set.- Since:
- 1.1
- See Also:
-