Class ActionUtilsImpl
- All Implemented Interfaces:
ActionUtils
ActionUtilsImpl
is the default implementation of the
ActionUtils
interface for the application.- Author:
- David Tobey
- See Also:
-
Field Summary
Modifier and TypeFieldDescription(package private) static org.apache.commons.logging.Log
(package private) static org.apache.commons.logging.Log
(package private) static org.apache.commons.logging.Log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInventoryMessages
(Map results, BaseForm baseForm) Adds non-error messages to the request related to inventory.buildParameterMap
(javax.servlet.http.HttpServletRequest request) Creates a string-based Map based on all the request parameters.createTrackingNumberLink
(String trackingNumber) Returns the URL link to look up a given tracking number's status, on either the UPS, USPS, or FedEx website.findCheckoutScreen
(BaseForm baseForm) Determines what checkout screen to direct the user to based on the status of the session and the store's database configuration.formatDate
(String dbDate, Locale locale) Given aString
representing a date as stored in the database, returns a more human-readable version suitable for display.generateCodeFromName
(String name) Given a String name, creates a URL-safe code that can be used for the "code" field of many domain entities that require it.getRequestParamsDebugMessage
(javax.servlet.http.HttpServletRequest request) Given a request object, converts all the incoming parameters to a string for debugging.loadEstimatedShippingOptions
(BaseForm baseForm) Load a set of estimated shipping options for the current cart.makeFilenameNice
(String originalFileName) Eliminates non-standard characters from a file name so it can be safely saved across various file systems.boolean
onAdministratorPreRequestEnd
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Runs at the beginning of each request to the administrator interface, after system objects have been initialized.boolean
onCustomerPreRequestEnd
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Runs at the beginning of each request to the customer interface, after system objects have been initialized.boolean
onPreRequestEnd
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Runs at the beggining of each request, after system objects have been initialized.parseGenericTemplate
(BaseForm baseForm, String template) Parses a string template with variables contained in a givenBaseForm
.parseLostPasswordTemplate
(Customer customer, BaseForm baseForm, String template) Parses a string template with variables contained in a givenBaseForm
andCustomer
.parseLostPasswordTemplateAdvanced
(Customer customer, BaseForm baseForm, String template, String token) parseLowStockTemplate
(BaseForm baseForm, Map lowStockEmail, String template) Parses a string template with variables contained in a givenBaseForm
and aMap
holding information about a SKU.void
processApplicationMessages
(org.apache.struts.action.ActionMessages errors, org.apache.struts.action.ActionMessages messages, Collection<ApplicationMessage> applicationMessages) void
processAuditLogging
(javax.servlet.http.HttpServletRequest request) Create log entries in the application's audit logs, containing all the key information about each request.processCartAddResults
(Map results, BaseForm baseForm) Process the results of adding an item or items to the cart.void
processSavedCartCookie
(BaseForm baseForm, Map parameters, javax.servlet.http.HttpServletResponse response) If the system settings permit it, add a persistent cookie to the user's browser identifying the cart so it can be loaded on a later visit.Reads a text file and returns its contents as a string.replaceOrderItems
(StringBuffer source, Collection orderItems, String currencyCode, Locale locale, BusinessObjectUtils utils) Parses aStringBuffer
, inserting order item data.replaceValue
(StringBuffer source, String value, String token) Replaces the given token, or placeholder, with the given value in the givenStringBuffer
.protected void
saveErrors
(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages errors) boolean
saveFile
(String filename, InputStream file) Saves an input stream as a file at a given location.protected void
saveMessages
(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages messages) void
sendMultipartEmail
(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password) Sends a multipart text and HTML email from the store.void
sendMultipartEmail
(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding) Sends a multipart text and HTML email from the store.void
sendMultipartEmail
(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding, String attachmentName, byte[] attachment, String attachmentType) Sends a multipart text and HTML email from the store.void
sendMultipartEmail
(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding, String attachmentName, byte[] attachment, String attachmentType, Map<String, String> extraHeaders) boolean
validateBillingFields
(BaseForm baseForm) Validates the required billing address fields in the user's cart.boolean
validateDeliveryFields
(BaseForm baseForm) Validates the required delivery address fields in the user's cart.boolean
Writes a text file to a given location.
-
Field Details
-
log
static org.apache.commons.logging.Log log -
customerAuditLog
static org.apache.commons.logging.Log customerAuditLog -
adminAuditLog
static org.apache.commons.logging.Log adminAuditLog
-
-
Constructor Details
-
ActionUtilsImpl
public ActionUtilsImpl()
-
-
Method Details
-
parseGenericTemplate
Description copied from interface:ActionUtils
Parses a string template with variables contained in a givenBaseForm
. Used to parse email templates for dynamically generated emails the store generates.The string template may have a number of placeholders deliniated by "%%". (E.g. "%%STORE_NAME%%"). This method replaces the placeholders with values from the
BaseForm
, be they settings from the database such as the store's name, or values from the current user's order.Note that with the release of 2.0, order invoice emails are now generated from JSP templates in the
/WEB-INF/layouts/default/order
directory, rather than by using this method.- Specified by:
parseGenericTemplate
in interfaceActionUtils
- Parameters:
baseForm
- Contains variables that will be used to replace the template's placeholders.template
- AString
containing placeholders that this method will replace.- Returns:
- The parsed template.
-
replaceValue
Replaces the given token, or placeholder, with the given value in the givenStringBuffer
.- Parameters:
source
- TheStringBuffer
being parsed.value
- The value the placeholder is being replaced with.token
- The placeholder being replaced.- Returns:
- The parsed
StringBuffer
.
-
replaceOrderItems
public StringBuffer replaceOrderItems(StringBuffer source, Collection orderItems, String currencyCode, Locale locale, BusinessObjectUtils utils) Parses aStringBuffer
, inserting order item data. Loops through the "%%START_ITEMS%%" and "%%END_ITEMS%%" placeholders, inserting data from a givenCollection
ofOrderItem
objects. Used to parse the invoice email template upon order completion.- Parameters:
source
- TheStringBuffer
being parsed.orderItems
- ACollection
ofOrderItem
objects whose data is used to parse the source.- Returns:
- The parsed
StringBuffer
.
-
parseLostPasswordTemplateAdvanced
public String parseLostPasswordTemplateAdvanced(Customer customer, BaseForm baseForm, String template, String token) - Specified by:
parseLostPasswordTemplateAdvanced
in interfaceActionUtils
-
parseLostPasswordTemplate
Description copied from interface:ActionUtils
Parses a string template with variables contained in a givenBaseForm
andCustomer
. Used to parse the lost password email template.The string template may have a number of placeholders deliniated by "%%". (E.g. "%%USERNAME%%"). This method replaces the placeholders with values from the
BaseForm
andCustomer
, be they settings from the database such as the store's name, or the current customer's user name and password.- Specified by:
parseLostPasswordTemplate
in interfaceActionUtils
- Parameters:
customer
- The currentCustomer
whose lost password is being emailed.baseForm
- Contains variables that will be used to replace the template's placeholders.template
- The template for the lost password email, which is being parsed.- Returns:
- The parsed template.
-
parseLowStockTemplate
Description copied from interface:ActionUtils
Parses a string template with variables contained in a givenBaseForm
and aMap
holding information about a SKU. Used to parse the low stock email template.- Specified by:
parseLowStockTemplate
in interfaceActionUtils
- Parameters:
baseForm
- Contains variables that will be used to replace the template's placeholders.lowStockEmail
- AMap
containing information about a SKU that has hit its low stock level.template
- The template for the low stock email, which is being parsed.- Returns:
- The parsed template.
-
sendMultipartEmail
public void sendMultipartEmail(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password) throws Exception Description copied from interface:ActionUtils
Sends a multipart text and HTML email from the store. Used for sending order notifications, invoices, lost password emails, and low stock emails.- Specified by:
sendMultipartEmail
in interfaceActionUtils
- Parameters:
toEmails
- A comma-separated list of email addresses the email is being sent to.ccEmails
- A comma-separated list of email addresses the email is being copied to.bccEmails
- A comma-separated list of email addresses the email is being blind copied to.fromEmail
- The email address used as the email's from address.smtpServer
- The SMTP server to be used to send the email.subject
- The subject used for the email.textMessage
- The message for the text part of the email.htmlMessage
- The message for the HTML part of the email.username
- Username for SMTP authentication, or null if no authentication is required.password
- Password for SMTP authentication, or null if no authentication is required.- Throws:
Exception
-
sendMultipartEmail
public void sendMultipartEmail(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding) throws Exception Description copied from interface:ActionUtils
Sends a multipart text and HTML email from the store. Used for sending order notifications, invoices, lost password emails, and low stock emails.- Specified by:
sendMultipartEmail
in interfaceActionUtils
- Parameters:
toEmails
- A comma-separated list of email addresses the email is being sent to.ccEmails
- A comma-separated list of email addresses the email is being copied to.bccEmails
- A comma-separated list of email addresses the email is being blind copied to.fromEmail
- The email address used as the email's from address.smtpServer
- The SMTP server to be used to send the email.subject
- The subject used for the email.textMessage
- The message for the text part of the email.htmlMessage
- The message for the HTML part of the email.username
- Username for SMTP authentication, or null if no authentication is required.password
- Password for SMTP authentication, or null if no authentication is required.characterEncoding
- Optional character encoding to be used for the email. If null or empty, no particular encoding is specified.- Throws:
Exception
-
sendMultipartEmail
public void sendMultipartEmail(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding, String attachmentName, byte[] attachment, String attachmentType) throws Exception Description copied from interface:ActionUtils
Sends a multipart text and HTML email from the store. Used for sending order notifications, invoices, lost password emails, and low stock emails.- Specified by:
sendMultipartEmail
in interfaceActionUtils
- Parameters:
toEmails
- A comma-separated list of email addresses the email is being sent to.ccEmails
- A comma-separated list of email addresses the email is being copied to.bccEmails
- A comma-separated list of email addresses the email is being blind copied to.fromEmail
- The email address used as the email's from address.smtpServer
- The SMTP server to be used to send the email.subject
- The subject used for the email.textMessage
- The message for the text part of the email.htmlMessage
- The message for the HTML part of the email.username
- Username for SMTP authentication, or null if no authentication is required.password
- Password for SMTP authentication, or null if no authentication is required.characterEncoding
- Optional character encoding to be used for the email. If null or empty, no particular encoding is specified.attachmentName
- Name of the attachment (report.xls)attachment
- Byte array of data for simple attachmentsattachmentType
- The mime type of the attachment (application/vnd.ms-excel)- Throws:
Exception
-
sendMultipartEmail
public void sendMultipartEmail(String toEmails, String ccEmails, String bccEmails, String fromEmail, String smtpServer, String subject, String textMessage, String htmlMessage, String username, String password, String smtpPort, String characterEncoding, String attachmentName, byte[] attachment, String attachmentType, Map<String, String> extraHeaders) throws Exception- Throws:
Exception
-
formatDate
Given aString
representing a date as stored in the database, returns a more human-readable version suitable for display. (Specifically, uses this mask to format the date:MMM d, yyyy HH:mm:ss
.)- Parameters:
dbDate
- The date as stored in the database.locale
- The local to use to format the date.- Returns:
- A more human-readable date suitable for display.
-
findCheckoutScreen
Description copied from interface:ActionUtils
Determines what checkout screen to direct the user to based on the status of the session and the store's database configuration. The possible screen names returned are:- "catalogMode", if the store's "catalogMode" database setting is set.
- "cart", if the user's cart is empty.
- "forceLogin", if the "forceLogin" database setting is set and the user is not logged in.
- "inviteLogin", if the "inviteLogin" database setting is set and the user has not declined to log in and is not logged in.
- "checkoutAddresses", if the user has not entered in all the required address fields for the order, and the "useComboScreen" setting is not set.
- "checkoutPayment", if payment information is required, the total of the current order is greater than zero, and the "useComboScreen" setting is not set.
- "checkoutCombo", if the user has not entered in all the required address fields, or if payment information is required, and if the "useComboScreen" setting is set.
- "checkoutConfirm", if none of the other screens apply.
The above screen names correspond to
ActionForward
s defined in the "/WEB-INF/conf/order/struts-config-order.xml" file.- Specified by:
findCheckoutScreen
in interfaceActionUtils
- Parameters:
baseForm
- The form class corresponding to the current request. Holds various properties of the request to help action classes communicate with the rest of the application.- Returns:
- A string identifying the name of the checkout screen to direct the user to.
- Throws:
Exception
-
validateBillingFields
Description copied from interface:ActionUtils
Validates the required billing address fields in the user's cart. Loops through the "billingRequired" database setting to check which fields are required.- Specified by:
validateBillingFields
in interfaceActionUtils
- Parameters:
baseForm
- The form class corresponding to the current request. Holds various properties of the request to help action classes communicate with the rest of the application.- Returns:
true
if all the required billing fields are present in the user's cart.false
if not.- Throws:
Exception
-
validateDeliveryFields
Description copied from interface:ActionUtils
Validates the required delivery address fields in the user's cart. Loops through the "deliveryRequired" database setting to check which fields are required.- Specified by:
validateDeliveryFields
in interfaceActionUtils
- Parameters:
baseForm
- The form class corresponding to the current request. Holds various properties of the request to help action classes communicate with the rest of the application.- Returns:
true
if all the required billing fields are present in the user's cart.false
if not.- Throws:
Exception
-
makeFilenameNice
Description copied from interface:ActionUtils
Eliminates non-standard characters from a file name so it can be safely saved across various file systems.- Specified by:
makeFilenameNice
in interfaceActionUtils
- Returns:
- A modified version of the file name with non-standard characters eliminated
- Throws:
Exception
-
readFile
Description copied from interface:ActionUtils
Reads a text file and returns its contents as a string.- Specified by:
readFile
in interfaceActionUtils
- Returns:
- The file's contents as a string
- Throws:
Exception
-
writeFile
Description copied from interface:ActionUtils
Writes a text file to a given location.- Specified by:
writeFile
in interfaceActionUtils
- Returns:
- Always true if no exceptions
- Throws:
Exception
-
saveFile
Description copied from interface:ActionUtils
Saves an input stream as a file at a given location.- Specified by:
saveFile
in interfaceActionUtils
- Returns:
- true, if saving the file succeeded
- Throws:
Exception
-
onPreRequestEnd
public boolean onPreRequestEnd(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Description copied from interface:ActionUtils
Runs at the beggining of each request, after system objects have been initialized. Called from the BaseRequestProcessor.- Specified by:
onPreRequestEnd
in interfaceActionUtils
- Returns:
- true, if the request should proceed
-
onCustomerPreRequestEnd
public boolean onCustomerPreRequestEnd(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Description copied from interface:ActionUtils
Runs at the beginning of each request to the customer interface, after system objects have been initialized. Called from the CustomerRequestProcessor.- Specified by:
onCustomerPreRequestEnd
in interfaceActionUtils
- Returns:
- true, if the request should proceed
-
onAdministratorPreRequestEnd
public boolean onAdministratorPreRequestEnd(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Description copied from interface:ActionUtils
Runs at the beginning of each request to the administrator interface, after system objects have been initialized. Called from the CustomerRequestProcessor.- Specified by:
onAdministratorPreRequestEnd
in interfaceActionUtils
- Returns:
- true, if the request should proceed
-
processAuditLogging
public void processAuditLogging(javax.servlet.http.HttpServletRequest request) Description copied from interface:ActionUtils
Create log entries in the application's audit logs, containing all the key information about each request.- Specified by:
processAuditLogging
in interfaceActionUtils
-
processSavedCartCookie
public void processSavedCartCookie(BaseForm baseForm, Map parameters, javax.servlet.http.HttpServletResponse response) Description copied from interface:ActionUtils
If the system settings permit it, add a persistent cookie to the user's browser identifying the cart so it can be loaded on a later visit.A cookie with the name "sscsctoken" and the value of the user's session id will be saved in the browser and recorded in the sscOrder database table's "savedCartToken" field.
- Specified by:
processSavedCartCookie
in interfaceActionUtils
- Parameters:
baseForm
- The instance ofCartAddForm
corresponding to the request.parameters
- The parameters of the add to cart request.response
- The servlet's response object, used to save the cookie to the browser.
-
processCartAddResults
Description copied from interface:ActionUtils
Process the results of adding an item or items to the cart. This method first sends out low stock inventory emails. It then adds error messages for customers if required attributes were missing from the request or the item or items are out of stock.In the case of an error, the attribute "errorProductCode" is set in the request, corresponding to the product code of the first item being added to the cart. If the submission came from a product page, this will tell the
ProductForm
to populate the request with that product's data, so the errors can be displayed on the product page.Finally, this method calls the
addInventoryMessages
method, to populate the request with (non-error) messages relating to inventory.- Specified by:
processCartAddResults
in interfaceActionUtils
- Parameters:
results
- The Map of results returned by the call to theexecute
method of this class.baseForm
- The instance ofCartAddForm
corresponding to the request.- Returns:
- A String, "success" or "failure", corresponding to the
ActionFoward
that theexecute
method will return.
-
addInventoryMessages
Description copied from interface:ActionUtils
Adds non-error messages to the request related to inventory. Two types of messages may be added.- Messages indicating that the quantity of an item was more than its inventory level and that therefore the quantity was automatically lowered to match the amount in stock.
- Messages indicating that with this request a product has just hit its out of stock level.
- Specified by:
addInventoryMessages
in interfaceActionUtils
- Parameters:
results
- The Map of results returned by the call to theexecute
method of this class.baseForm
- The instance ofCartAddForm
corresponding to the current request.
-
loadEstimatedShippingOptions
Description copied from interface:ActionUtils
Load a set of estimated shipping options for the current cart. The options may be merely estimates because the shopper may not have defined a delivery address yet, if he has not logged in or entered addresses during checkout. In these cases, the default city, state, country, and ZIP defined in the database settings are used.- Specified by:
loadEstimatedShippingOptions
in interfaceActionUtils
- Returns:
- A Collection of Maps representing the various shipping options and their rates.
-
buildParameterMap
Description copied from interface:ActionUtils
Creates a string-based Map based on all the request parameters.- Specified by:
buildParameterMap
in interfaceActionUtils
- Returns:
- A map representing all the request parameters.
- Throws:
Exception
-
getRequestParamsDebugMessage
Description copied from interface:ActionUtils
Given a request object, converts all the incoming parameters to a string for debugging. The values of certain parameters such as passwords are masked for security.- Specified by:
getRequestParamsDebugMessage
in interfaceActionUtils
- Parameters:
request
- The current request object.- Returns:
- A String representing the name value pairs of the request parameters.
-
saveErrors
protected void saveErrors(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages errors) -
saveMessages
protected void saveMessages(javax.servlet.http.HttpServletRequest request, org.apache.struts.action.ActionMessages messages) -
generateCodeFromName
Description copied from interface:ActionUtils
Given a String name, creates a URL-safe code that can be used for the "code" field of many domain entities that require it.- Specified by:
generateCodeFromName
in interfaceActionUtils
-
createTrackingNumberLink
Description copied from interface:ActionUtils
Returns the URL link to look up a given tracking number's status, on either the UPS, USPS, or FedEx website.- Specified by:
createTrackingNumberLink
in interfaceActionUtils
- Returns:
- The URL for the tracking number on the UPS, USPS, or FedEx website
-
processApplicationMessages
public void processApplicationMessages(org.apache.struts.action.ActionMessages errors, org.apache.struts.action.ActionMessages messages, Collection<ApplicationMessage> applicationMessages) - Specified by:
processApplicationMessages
in interfaceActionUtils
-