org.polliwog
Class Utilities

java.lang.Object
  extended by org.polliwog.Utilities

public class Utilities
extends java.lang.Object

Provides some general-purpose utilities.

 Last Modified By: $Author: barrygently $
 Last Modified On: $Date: 2005/07/04 14:00:01 $
 Current Revision: $Revision: 1.6 $
 


Constructor Summary
Utilities()
           
 
Method Summary
static boolean between(java.util.Date d, java.util.Date from, java.util.Date to)
          Return whether the date is between the from (inclusive) and to (inclusive).
static java.lang.String buildXMLAttributes(java.util.Map attrs)
           
static java.lang.String formatTime(com.gentlyweb.utils.TimeDuration t, java.lang.String format)
           
static java.lang.String formatTime(com.gentlyweb.utils.TimeDuration t, java.lang.String dys, java.lang.String hrs, java.lang.String mns, java.lang.String scs, java.lang.String div)
           
static java.util.List getAllGroupByResults(org.josql.QueryResults qr)
           
static org.jdom.Element getAsElement(java.net.URL url, java.lang.String zipExtension)
           
static java.lang.String getAsQueryString(java.util.Map parms)
           
static java.util.Map getHTTPStatusCodes()
          Get all the status codes defined in class: HttpURLConnection.
static int getPercent(int top, int bot)
          A utility to get the percentage of the top from the bottom.
static int getPercent(long top, long bot)
          A utility to get the percentage of the top from the bottom.
static java.util.Map getRequestParameters(java.lang.String q)
          Convert a string into a Map of name/value pairs, based on URL parameter encoding.
static java.net.URI getURI(java.lang.String u)
          Convert the passed in string to a URI.
static java.lang.String getValue(java.lang.StringBuffer buf, java.lang.String openQuoteToken, java.lang.String closeQuoteToken, java.lang.String escapedBy)
          Get the "next" value from the StringBuffer.
static java.util.List getXMLPathParts(java.lang.String xp)
           
static java.lang.String getXMLValue(java.util.List xmlPathParts, org.jdom.Element root)
           
static boolean startsWith(java.lang.String str, java.util.List values)
          Determine whether str starts with any of the values.
static void tokenize(java.lang.String str, java.lang.String token, boolean trim, java.util.List data)
          Tokenize a string based on token.
static void tokenize(java.lang.String str, java.lang.String token, boolean trim, java.util.Map data)
          Tokenize a string based on token.
static void trimLeadingWhitespace(java.lang.StringBuffer buf)
          Remove whitespace characters (as defined by Character.isWhitespace(char)) from the front of the passed in StringBuffer.
static void writeHTMLFile(java.lang.String wrapper, java.lang.String content, java.io.File loc, java.lang.Object o, VisitorData vd, Page p, boolean compress)
           
static java.util.Date zeroTimeFields(java.util.Date d)
          Zero the time fields of the passed in date.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

getRequestParameters

public static java.util.Map getRequestParameters(java.lang.String q)
Convert a string into a Map of name/value pairs, based on URL parameter encoding.

Parameters:
q - The string to break into the map.
Returns:
A Map of name/value pairs. If a parameter has multiple values against it then a List is returned against the name.

tokenize

public static void tokenize(java.lang.String str,
                            java.lang.String token,
                            boolean trim,
                            java.util.Map data)
Tokenize a string based on token. Put the resulting tokens into data.

Parameters:
str - The string to tokenize.
token - The string to tokenize on.
trim - If set to true then each token found will be trimmed before placing into data.
data - The Map to place the tokens into.

startsWith

public static boolean startsWith(java.lang.String str,
                                 java.util.List values)
Determine whether str starts with any of the values.

Parameters:
str - The string.
values - The list of values to check str against.
Returns:
true if str starts with any of the values, false otherwise.

tokenize

public static void tokenize(java.lang.String str,
                            java.lang.String token,
                            boolean trim,
                            java.util.List data)
Tokenize a string based on token. Put the resulting tokens into data.

Parameters:
str - The string to tokenize.
token - The string to tokenize on.
trim - If set to true then each token found will be trimmed before placing into data.
data - The List to place the tokens into.

getURI

public static java.net.URI getURI(java.lang.String u)
                           throws WeblogException
Convert the passed in string to a URI.

Parameters:
u - The string to convert to a URI.
Returns:
The URI.
Throws:
WeblogException - If the string cannot be converted to a URI.

trimLeadingWhitespace

public static void trimLeadingWhitespace(java.lang.StringBuffer buf)
Remove whitespace characters (as defined by Character.isWhitespace(char)) from the front of the passed in StringBuffer.

Parameters:
buf - The buffer to trim.

getValue

public static java.lang.String getValue(java.lang.StringBuffer buf,
                                        java.lang.String openQuoteToken,
                                        java.lang.String closeQuoteToken,
                                        java.lang.String escapedBy)
Get the "next" value from the StringBuffer. The value is either enclosed by the specified quotes (openQuoteToken and closeQuoteToken) or by a space. It should be noted that the value is "consumed" from the buffer, i.e. the value is removed from the buffer prior to returning.

Parameters:
buf - The buffer to get the value from.
openQuoteToken - The opening quote, set to null if there isn't one. The value returned will not contain this quote.
closeQuoteToken - The closing quote, set to null if there isn't one. The value returned will not contain this quote.
escapedBy - An escape character. The value returned will not contain this character also only the first character is the string is used.
Returns:
The value from the buffer. Note: as a side-effect the value is removed from the buffer.

getHTTPStatusCodes

public static java.util.Map getHTTPStatusCodes()
Get all the status codes defined in class: HttpURLConnection. It may be in the future that some of the codes names' will be modified here prior to being returned, for example: "Moved Temp" should really be "Redirect" since that has more meaning to a human being.

Returns:
A Map of integer code to name.

between

public static boolean between(java.util.Date d,
                              java.util.Date from,
                              java.util.Date to)
Return whether the date is between the from (inclusive) and to (inclusive). If the from is null then ensure that the date is before the to. If the to is null then ensure that the date is after the from. If from and to are both null then return false.

Parameters:
d - The date to check for.
from - The from date.
to - The to date.
Returns:
true if the date is between from and to, false otherwise.

zeroTimeFields

public static java.util.Date zeroTimeFields(java.util.Date d)
Zero the time fields of the passed in date.

Parameters:
d - The date.
Returns:
A new date with the time fields set to zero.

getPercent

public static int getPercent(int top,
                             int bot)
A utility to get the percentage of the top from the bottom.

Parameters:
top - The top part of the percentage i.e. 50/100.
bot - The bottom part of the percentage, i.e. 50/100.
Returns:
The percentage to the nearest int.

getPercent

public static int getPercent(long top,
                             long bot)
A utility to get the percentage of the top from the bottom.

Parameters:
top - The top part of the percentage i.e. 50/100.
bot - The bottom part of the percentage, i.e. 50/100.
Returns:
The percentage to the nearest int.

writeHTMLFile

public static void writeHTMLFile(java.lang.String wrapper,
                                 java.lang.String content,
                                 java.io.File loc,
                                 java.lang.Object o,
                                 VisitorData vd,
                                 Page p,
                                 boolean compress)
                          throws WeblogException
Throws:
WeblogException

formatTime

public static java.lang.String formatTime(com.gentlyweb.utils.TimeDuration t,
                                          java.lang.String format)

formatTime

public static java.lang.String formatTime(com.gentlyweb.utils.TimeDuration t,
                                          java.lang.String dys,
                                          java.lang.String hrs,
                                          java.lang.String mns,
                                          java.lang.String scs,
                                          java.lang.String div)

getAsQueryString

public static java.lang.String getAsQueryString(java.util.Map parms)

buildXMLAttributes

public static java.lang.String buildXMLAttributes(java.util.Map attrs)

getAsElement

public static org.jdom.Element getAsElement(java.net.URL url,
                                            java.lang.String zipExtension)
                                     throws org.jdom.JDOMException,
                                            java.io.IOException
Throws:
org.jdom.JDOMException
java.io.IOException

getXMLPathParts

public static java.util.List getXMLPathParts(java.lang.String xp)
                                      throws WeblogException
Throws:
WeblogException

getXMLValue

public static java.lang.String getXMLValue(java.util.List xmlPathParts,
                                           org.jdom.Element root)
                                    throws org.jdom.JDOMException
Throws:
org.jdom.JDOMException

getAllGroupByResults

public static java.util.List getAllGroupByResults(org.josql.QueryResults qr)


  Copyright © 2007 Gary Bentley. All Rights Reserved.