com.softslate.commerce.businessobjects.core
Class BusinessObjectUtilsImpl

java.lang.Object
  extended by com.softslate.commerce.businessobjects.core.BusinessObjectUtilsImpl
All Implemented Interfaces:
BusinessObjectUtils

public class BusinessObjectUtilsImpl
extends java.lang.Object
implements BusinessObjectUtils

A utility object containing various methods used by BusinessProcessors in performing business logic.

Each BusinessProcessors is able to retrieve an instance of BusinessObjectUtils by calling its utils method.

Author:
David Tobey

Field Summary
(package private) static org.apache.commons.logging.Log log
           
 
Constructor Summary
BusinessObjectUtilsImpl()
           
 
Method Summary
 java.lang.String formatDateTime(java.util.Date dateTime)
          Formats a Date object into a string suitable for storage in the database.
 java.lang.String formatPrice(double rawPrice, java.lang.String currencyCode, java.util.Locale locale)
          Formats a double into a string suitable for displaying the double as a price.
 java.lang.String formatPrice(java.lang.Double rawPrice, java.lang.String currencyCode, java.util.Locale locale)
          Formats a Double into a string suitable for displaying the double as a price, or a price representing 0 if the Double is null.
 java.util.Collection getMapsFromBeans(java.util.Collection beans)
          Given a collection of bean objects returns a collection of Maps describing each bean's properties.
 org.w3c.dom.Document parse(java.io.InputStream xmlStream, boolean ignoreWhitespace)
          Returns a DOM Level2 document that represents the given document.
 java.util.Date parseDateTime(java.lang.String dateTime)
          Parses a string (typically taken from a database query) into a Date object.
 org.w3c.dom.Node parsePartialDocument(java.lang.String xml)
          Parses a section of XML and returns the first Element node found
 java.util.Map parseResponseData(java.lang.String response)
          Parses a query string of name value pairs into a Map.
 java.lang.String prepareRequestData(java.util.Map params, boolean urlEncode)
          Prepares a string, which may optionally be url-encoded, for use with an HTTP request, given a map of the request's parameters.
 java.lang.String sendHTTPPost(java.lang.String urlString, java.lang.String postData, boolean followRedirect)
          Sends an HTTP request using the POST method to a given URL.
 boolean stringArrayValuesGreaterThan(java.lang.String[] paramValues, int value)
          Determines if at least one element in a string array is greater than a given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.commons.logging.Log log
Constructor Detail

BusinessObjectUtilsImpl

public BusinessObjectUtilsImpl()
Method Detail

formatDateTime

public java.lang.String formatDateTime(java.util.Date dateTime)
Description copied from interface: BusinessObjectUtils
Formats a Date object into a string suitable for storage in the database.

Specified by:
formatDateTime in interface BusinessObjectUtils
Returns:
a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.

parseDateTime

public java.util.Date parseDateTime(java.lang.String dateTime)
Description copied from interface: BusinessObjectUtils
Parses a string (typically taken from a database query) into a Date object.

Specified by:
parseDateTime in interface BusinessObjectUtils
Returns:
a String in the form of "yyyy-MM-dd HH:mm:ss:SSS" suitable for storage in the database.

formatPrice

public java.lang.String formatPrice(java.lang.Double rawPrice,
                                    java.lang.String currencyCode,
                                    java.util.Locale locale)
Description copied from interface: BusinessObjectUtils
Formats a Double into a string suitable for displaying the double as a price, or a price representing 0 if the Double is null.

Specified by:
formatPrice in interface BusinessObjectUtils
Returns:
a String suitable for displaying the double as a price.

formatPrice

public java.lang.String formatPrice(double rawPrice,
                                    java.lang.String currencyCode,
                                    java.util.Locale locale)
Description copied from interface: BusinessObjectUtils
Formats a double into a string suitable for displaying the double as a price.

Specified by:
formatPrice in interface BusinessObjectUtils
Returns:
a String suitable for displaying the double as a price.

prepareRequestData

public java.lang.String prepareRequestData(java.util.Map params,
                                           boolean urlEncode)
                                    throws java.lang.Exception
Description copied from interface: BusinessObjectUtils
Prepares a string, which may optionally be url-encoded, for use with an HTTP request, given a map of the request's parameters.

Specified by:
prepareRequestData in interface BusinessObjectUtils
Parameters:
params - A Map of key-value String pairs representing the parameters of the request.
urlEncode - If true, the keys and values in the string will be url-encoded.
Returns:
A String representing a valid URL-encoded query string.
Throws:
java.lang.Exception

sendHTTPPost

public java.lang.String sendHTTPPost(java.lang.String urlString,
                                     java.lang.String postData,
                                     boolean followRedirect)
                              throws java.lang.Exception
Description copied from interface: BusinessObjectUtils
Sends an HTTP request using the POST method to a given URL.

Specified by:
sendHTTPPost in interface BusinessObjectUtils
Parameters:
urlString - The URL to send the request to.
postData - A String representing a valid URL-encoded query string.
followRedirect - A boolean indicating whether redirects should be followed.
Returns:
A String representing the server's response, or the Location header if redirects are not to be followed.
Throws:
java.lang.Exception

getMapsFromBeans

public java.util.Collection getMapsFromBeans(java.util.Collection beans)
Description copied from interface: BusinessObjectUtils
Given a collection of bean objects returns a collection of Maps describing each bean's properties.

Specified by:
getMapsFromBeans in interface BusinessObjectUtils
Returns:
A Collection of Maps describing the beans.

parse

public org.w3c.dom.Document parse(java.io.InputStream xmlStream,
                                  boolean ignoreWhitespace)
                           throws javax.xml.parsers.ParserConfigurationException,
                                  org.xml.sax.SAXException,
                                  java.io.IOException
Returns a DOM Level2 document that represents the given document.

Specified by:
parse in interface BusinessObjectUtils
Parameters:
xmlStream - An InputStream that is the source of the XML data
ignoreWhitespace - This is passed through to the DocumentBuilder.
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

parsePartialDocument

public org.w3c.dom.Node parsePartialDocument(java.lang.String xml)
                                      throws javax.xml.parsers.ParserConfigurationException,
                                             org.xml.sax.SAXException,
                                             java.io.IOException
Parses a section of XML and returns the first Element node found

Specified by:
parsePartialDocument in interface BusinessObjectUtils
Parameters:
xml - The XML to be parsed in String form
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

parseResponseData

public java.util.Map parseResponseData(java.lang.String response)
                                throws java.lang.Exception
Description copied from interface: BusinessObjectUtils
Parses a query string of name value pairs into a Map.

Specified by:
parseResponseData in interface BusinessObjectUtils
Parameters:
response - A String key-value pairs in the form of a URL query string
Returns:
A Map representing the query string.
Throws:
java.lang.Exception

stringArrayValuesGreaterThan

public boolean stringArrayValuesGreaterThan(java.lang.String[] paramValues,
                                            int value)
Description copied from interface: BusinessObjectUtils
Determines if at least one element in a string array is greater than a given value.

Specified by:
stringArrayValuesGreaterThan in interface BusinessObjectUtils
Parameters:
paramValues - The string array being tested.
value - The value for the string array's elements to be tested against.
Returns:
true if at least one element in a string array is greater than a given value. false if not.


Copyright © SoftSlate, LLC 2003–2005