org.blojsom.util
Class BlojsomUtils

java.lang.Object
  extended byorg.blojsom.util.BlojsomUtils
All Implemented Interfaces:
BlojsomConstants

public class BlojsomUtils
extends java.lang.Object
implements BlojsomConstants

BlojsomUtils

Version:
$Id: BlojsomUtils.java,v 1.83 2006/03/25 04:14:27 czarneckid Exp $
Author:
David Czarnecki

Field Summary
static java.util.Comparator FILE_NAME_COMPARATOR
          Return a comparator to sort by name
static java.util.Comparator FILE_TIME_ASCENDING_COMPARATOR
          Return a comparator that uses a file's last modified time to order the files in ascending order.
static java.util.Comparator FILE_TIME_COMPARATOR
          Return a comparator that uses a file's last modified time to order the files.
 
Fields inherited from interface org.blojsom.util.BlojsomConstants
ADMINISTRATORS_IP, BLOG_ADMIN_URL_IP, BLOG_ADMINISTRATION_LOCALE_IP, BLOG_AUTHORIZATION_IP, BLOG_BASE_URL_IP, BLOG_BLACKLIST_FILE_IP, BLOG_COMMENTS_DIRECTORY_IP, BLOG_COMMENTS_ENABLED_IP, BLOG_COUNTRY_DEFAULT, BLOG_COUNTRY_IP, BLOG_DEFAULT_CATEGORY_EXCLUSION_MAPPING_IP, BLOG_DEFAULT_CATEGORY_MAPPING_IP, BLOG_DEFAULT_FETCHER, BLOG_DEFAULT_FILE_EXTENSION_IP, BLOG_DEFAULT_FLAVOR_IP, BLOG_DEFAULT_PROPERTIES, BLOG_DEPTH_IP, BLOG_DESCRIPTION_IP, BLOG_DIRECTORY_FILTER_IP, BLOG_EMAIL_ENABLED_IP, BLOG_ENTRIES_DISPLAY_DEFAULT, BLOG_ENTRIES_DISPLAY_IP, BLOG_ENTRY_META_DATA_EXTENSION_IP, BLOG_FILE_ENCODING_IP, BLOG_FILE_EXTENSIONS_IP, BLOG_HOME_IP, BLOG_LANGUAGE_DEFAULT, BLOG_LANGUAGE_IP, BLOG_NAME_IP, BLOG_OWNER, BLOG_OWNER_EMAIL, BLOG_PERMISSIONS_IP, BLOG_PINGBACKS_DIRECTORY_IP, BLOG_PINGBACKS_ENABLED_IP, BLOG_PROPERTIES_EXTENSIONS_IP, BLOG_TRACKBACK_DIRECTORY_IP, BLOG_TRACKBACKS_ENABLED_IP, BLOG_URL_IP, BLOJSOM_ALL_CATEGORIES, BLOJSOM_AUTHORIZATION_PROVIDER_IP, BLOJSOM_BLOG, BLOJSOM_BLOG_HOME_IP, BLOJSOM_BROADCASTER_IP, BLOJSOM_CATEGORIES, BLOJSOM_COMMENTS_ENABLED, BLOJSOM_CONFIGURATION_BASE_DIRECTORY_IP, BLOJSOM_CONFIGURATION_IP, BLOJSOM_DATE, BLOJSOM_DATE_ISO8601, BLOJSOM_DATE_OBJECT, BLOJSOM_DATE_UTC, BLOJSOM_DEFAULT_BROADCASTER, BLOJSOM_DEFAULT_CONFIGURATION_BASE_DIRECTORY, BLOJSOM_DEFAULT_RESOURCE_DIRECTORY, BLOJSOM_DEFAULT_RESOURCE_MANAGER, BLOJSOM_DEFAULT_TEMPLATES_DIRECTORY, BLOJSOM_DEFAULT_USER_IP, BLOJSOM_EMAIL_ENABLED, BLOJSOM_ENTRIES, BLOJSOM_FETCHER_IP, BLOJSOM_FLAVOR_CONFIGURATION_IP, BLOJSOM_INSTALLATION_DIRECTORY_IP, BLOJSOM_INSTALLED_LOCALES_IP, BLOJSOM_LAST_MODIFIED, BLOJSOM_LISTENER_CONFIGURATION_IP, BLOJSOM_PERMALINK, BLOJSOM_PERMALINK_NEXT_ENTRY, BLOJSOM_PERMALINK_PREVIOUS_ENTRY, BLOJSOM_PLUGIN_CHAIN, BLOJSOM_PLUGIN_CONFIGURATION_IP, BLOJSOM_PLUGINS, BLOJSOM_REQUESTED_CATEGORY, BLOJSOM_REQUESTED_FLAVOR, BLOJSOM_RESOURCE_DIRECTORY_IP, BLOJSOM_RESOURCE_MANAGER_BUNDLES_IP, BLOJSOM_RESOURCE_MANAGER_CONTEXT_KEY, BLOJSOM_RESOURCE_MANAGER_IP, BLOJSOM_SITE_URL, BLOJSOM_TEMPLATES_DIRECTORY_IP, BLOJSOM_USER, BLOJSOM_USERS_IP, BLOJSOM_VERSION, BLOJSOM_VERSION_NUMBER, CACHE_CONTROL_HTTP_HEADER, CATEGORY_PARAM, COMMENT_EXTENSION, DEFAULT_AUTHORIZATION_PROVIDER, DEFAULT_COMMENTS_DIRECTORY, DEFAULT_DIGEST_ALGORITHM, DEFAULT_DISPATCHER_CONFIGURATION_FILE, DEFAULT_ENTRY_EXTENSION, DEFAULT_FLAVOR_CONFIGURATION_FILE, DEFAULT_FLAVOR_HTML, DEFAULT_METADATA_EXTENSION, DEFAULT_PERMISSIONS_CONFIGURATION_FILE, DEFAULT_PINGBACKS_DIRECTORY, DEFAULT_PLUGIN_CONFIGURATION_FILE, DEFAULT_PROPERTIES_EXTENSIONS, DEFAULT_TRACKBACK_DIRECTORY, DESCRIPTION_KEY, DIGEST_ALGORITHM, FLAVOR_PARAM, HTTP_ETAG, HTTP_LASTMODIFIED, INFINITE_BLOG_DEPTH, ISO_8601_DATE_FORMAT, LINE_SEPARATOR, LINEAR_NAVIGATION_ENABLED_IP, MAX_HASHABLE_LENGTH, NAME_KEY, NO_CACHE_HTTP_HEADER_VALUE, OVERRIDE_LASTMODIFIED_PARAM, PAGE_PARAM, PAGE_PARAM_ARCHIVE, PERMALINK_PARAM, PINGBACK_EXTENSION, PLUGINS_PARAM, PRAGMA_HTTP_HEADER, PREFERRED_SYNDICATION_FLAVOR, RECURSIVE_CATEGORIES, REDIRECT_TO_PARAM, RFC_822_DATE_FORMAT, SHORT_ISO_8601_DATE_FORMAT, TRACKBACK_EXTENSION, USE_ENCRYPTED_PASSWORDS, UTC_DATE_FORMAT, UTF8, WHITESPACE, XMLRPC_ENABLED_IP
 
Method Summary
static java.lang.String addSlashes(java.lang.String input)
          Add preceeding and trailing slashes to an input string.
static java.util.Map arrayOfStringsToMap(java.lang.String[] array)
          Turn an array of strings into a Map where the keys and values are the input strings.
static java.lang.String arrayOfStringsToString(java.lang.String[] array)
          Turn an array of strings into a single string separated by commas.
static java.lang.String arrayOfStringsToString(java.lang.String[] array, java.lang.String separator)
          Turn an array of strings into a single string separated by a given delimeter.
static java.util.List arrayToList(java.lang.String[] input)
          Convert a String[] to a List
static java.util.Map blojsomPropertiesToMap(java.util.Properties properties)
          Convert a BlojsomProperties object to a Map.
static boolean checkMapForKey(java.util.Map map, java.lang.String key)
          Check to see if a given map contains a particular key.
static boolean checkNullOrBlank(java.lang.String input)
          Checks to see if the string is null or blank (after trimming)
static java.lang.String checkStartingAndEndingSlash(java.lang.String input)
          Add a '/' at the beginning and end of the input string if necessary.
static java.lang.String constructBaseURL(javax.servlet.http.HttpServletRequest httpServletRequest)
          Construct a blog base URL from the request
static java.lang.String constructBlogURL(javax.servlet.http.HttpServletRequest httpServletRequest, java.lang.String blogID)
          Construct a blog URL from the request
static java.lang.String convertRequestParams(javax.servlet.http.HttpServletRequest request)
          Convert the request parameters to a string
static java.lang.String convertRequestParams(javax.servlet.http.HttpServletRequest request, java.util.Map ignoreParams)
          Convert the request parameters to a string
static void copyDirectory(java.io.File sourceDirectory, java.io.File targetDirectory)
          Recursively copy a directory from a source to a target
static java.util.List csvToList(java.lang.String valuesAsString)
          Return a comma-separated list of Strings as a List; trims space around value
static int daysBetweenDates(java.util.Date startDate, java.util.Date endDate)
          Return the number of days between two dates
static boolean deleteDirectory(java.io.File directoryOrFile)
          Delete a directory (or file) and any sub-directories underneath the directory
static boolean deleteDirectory(java.io.File directoryOrFile, boolean removeDirectoryOrFile)
          Delete a directory (or file) and any sub-directories underneath the directory
static java.lang.String digestString(java.lang.String data)
          Performs an MD5 Digest onthe given String content
static java.lang.String digestString(java.lang.String data, java.lang.String algorithm)
          Performs an Digest onthe given String content for the given algorithm
static java.lang.String escapeMetaAndLink(java.lang.String input)
          Return an escaped string where <meta, <link tags are escaped
static java.lang.String escapeString(java.lang.String input)
          Return an escaped string where &, <, >, ", and ' are converted to their HTML equivalents
static java.lang.String escapeStringSimple(java.lang.String input)
          Return an escaped string where &, <, > are converted to their HTML equivalents
static BlogEntry fetchEntry(BlojsomFetcher fetcher, BlogUser blogUser, java.lang.String category, java.lang.String permalink)
          Fetch an BlogEntry given a category and permalink
static java.lang.String getBlogCategory(java.lang.String blogHome, java.lang.String requestedCategory)
          Strip off the blog home directory for a requested blog category
static java.lang.String getBlogEntryFilename(java.lang.String title, java.lang.String content)
          Return a filename appropriate for the blog entry content
static java.lang.String getBlogSiteURL(java.lang.String blogURL, java.lang.String servletPath)
          Return a URL to the main blog site without the servlet path requested
static java.lang.String getCalendarNavigationUrl(java.lang.String prefix, int month, int day, int year)
          Create a Calendar Navigatation URL
static java.lang.String getCategoryFromPath(java.lang.String pathInfo)
          Returns category information from the path provided to the method where the path provided is assumed to be everything after the servlet instance with a user id at the very beginning of the path.
static java.lang.String[] getCountriesForSystem(java.util.Locale locale)
          Return of a list of locale countries supported on this system (JVM)
static java.lang.String getDateKey(java.util.Date date)
          Return a string of "YYYYMMDD"
static java.io.FileFilter getDirectoryFilter()
          Return a file filter which only returns directories
static java.io.FileFilter getDirectoryFilter(java.lang.String[] excludedDirectories)
          Return a file filter which only returns directories that are not one of a list of excluded directories
static java.io.FileFilter getExtensionFilter(java.lang.String extension)
          Return a file filter which takes a single file extension to look for
static java.io.FileFilter getExtensionsFilter(java.lang.String[] extensions)
          Return a file filter which takes a list of file extensions to look for
static java.io.FileFilter getExtensionsFilter(java.lang.String[] extensions, java.lang.String[] excludedDirectories, boolean returnDirectories)
          Return a file filter which takes a list of file extensions to look for
static java.lang.String getFileExtension(java.lang.String filename)
          Return the file extension for a given filename or null if no file extension is present
static java.lang.String getFilename(java.lang.String filename)
          Return the filename without extension for a given filename
static java.io.File getFilenameForDate(java.lang.String filename)
          Return a filename with the date as a long value before the file extension.
static java.lang.String getFilenameForPermalink(java.lang.String permalink, java.lang.String[] blogEntryExtensions)
          Return only the filename of a permalink request
static java.lang.String getFilenameFromPath(java.lang.String filenameWithPath)
          Returns the base file name from the supplied file path.
static java.lang.String getFirstLine(java.lang.String input, int length)
          Extracts the first line in a given string, otherwise returns the first n bytes
static java.lang.String getFormattedDate(java.util.Date date, java.lang.String format, java.util.Locale locale)
          Return a date formatted date
static java.lang.String getHashableContent(java.lang.String content)
          Return a digested string of some content
static java.lang.String getISO8601Date(java.util.Date date)
          Return a date in ISO 8601 style http://www.w3.org/TR/NOTE-datetime
static java.lang.String getKeysAsStringList(java.util.Map input)
          Return the keys of a map as a comma-separated list
static java.lang.String[] getLanguagesForSystem(java.util.Locale locale)
          Return of a list of locale languages supported on this system (JVM)
static java.util.Locale getLocaleFromString(java.lang.String locale)
          Create a Locale object from a string of form language_country_variant
static java.io.FileFilter getRegularExpressionFilter(java.lang.String[] expressions)
          Return a file filter which takes a list of regular expressions to look for
static java.lang.String getRequestValue(java.lang.String key, javax.servlet.http.HttpServletRequest httpServletRequest)
          Tries to retrieve a given key using getParameter(key) and if not available, will use getAttribute(key) from the servlet request
static java.lang.String getRequestValue(java.lang.String key, javax.servlet.http.HttpServletRequest httpServletRequest, boolean preferAttributes)
          Tries to retrieve a given key using getParameter(key) and if not available, will use getAttribute(key) from the servlet request
static java.lang.String getRFC822Date(java.util.Date date)
          Return a date in RFC 822 style
static java.lang.String getTemplateForPage(java.lang.String flavorTemplate, java.lang.String page)
          Return the template name for a particular page
static java.lang.String[] getTimeZonesForSystem(java.util.Locale locale)
          Return of a list of time zone IDs supported on this system (JVM)
static java.lang.String getUserFromPath(java.lang.String pathInfo)
          Returns user id information from the path provided to the method where the path provided is assumed to be everything after the servlet instance with a user id at the very beginning of the path.
static java.lang.String getUTCDate(java.util.Date date)
          Return a date in UTC style
static void listDirectoriesInSubdirectories(java.io.File directory, java.lang.String parentDirectory, java.util.List directories)
          List the sub-directories in a sub-directory of a given directory and strip the parent directory from the path of the directories added to the list.
static void listFilesInSubdirectories(java.io.File directory, java.lang.String parentDirectory, java.util.List files)
          List the files in a sub-directory of a given directory and strip the parent directory from the path of the files added to the list.
static java.lang.String listToCSV(java.util.List values)
          Convert a list to a comma-separated string.
static java.util.Map listToMap(java.util.List values)
          Convert a list of values to a Map.
static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig, java.lang.String configurationFile)
          Try to load a properties file from disk.
static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig, java.lang.String configurationIP, boolean required)
          Try to load a properties file from disk
static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig, java.lang.String configurationIP, boolean required, boolean allowMultipleValues)
          Try to load a properties file from disk
static java.util.Properties mapToBlojsomProperties(java.util.Map map)
          Convert a Map to a BlojsomProperties.
static java.util.Properties mapToProperties(java.util.Map map)
          Convert a Map to a set of BlojsomProperties.
static java.util.Properties mapToProperties(java.util.Map map, java.lang.String encoding)
          Convert a Map to a set of BlojsomProperties
static java.lang.String normalize(java.lang.String path)
          Normalize a path to remove all ./, ../, .../, //, etc.
static java.lang.String nullToBlank(java.lang.String input)
          Check to see if the given input string is null and if so, return a blank string instead
static java.lang.String[] parseCommaList(java.lang.String commaList)
          Parse a comma-separated list of values; also parses over internal spaces
static java.lang.String[] parseDelimitedList(java.lang.String delimitedList, java.lang.String delimiter)
          Parse a delimited list of values
static java.lang.String[] parseDelimitedList(java.lang.String delimitedList, java.lang.String delimiter, boolean trim)
          Parse a delimited list of values
static java.lang.String[] parseLastComma(java.lang.String value)
          Parse a string into two separate strings based on the last comma in the input value
static java.lang.String[] parseOnlyCommaList(java.lang.String commaList)
          Parse a comma-separated list of values
static java.lang.String[] parseOnlyCommaList(java.lang.String commaList, boolean trim)
          Parse a comma-separated list of values
static java.util.Map propertiesToMap(java.util.Properties properties)
          Convert a set of Properties to a Map
static java.lang.String removeInitialSlash(java.lang.String input)
          Remove the initial "/" from a string
static java.util.List removeNullValues(java.util.List input)
          Remove null values from a given list
static java.lang.String removeSlashes(java.lang.String input)
          Remove the "/" from the beginning and end of a string
static java.lang.String removeTrailingSlash(java.lang.String input)
          Remove the trailing "/" from a string
static java.lang.String replace(java.lang.String str, java.lang.String pattern, java.lang.String replace)
          Replace any occurances of a string pattern within a string with a different string.
static void resolveDynamicBaseAndBlogURL(javax.servlet.http.HttpServletRequest httpServletRequest, Blog blog, java.lang.String blogID)
          Check to see if the blog base URL or blog URL are present.
static void setNoCacheControlHeaders(javax.servlet.http.HttpServletResponse httpServletResponse)
          Set various cache control HTTP headers so that the browser does not try and cache the page
static java.lang.String stripHTML(java.lang.String text)
          Strip all HTML from a given piece of text
static java.lang.String stripLineTerminators(java.lang.String input)
          Strip line terminator characters from an input string
static java.lang.String stripLineTerminators(java.lang.String input, java.lang.String replacement)
          Strip line terminator characters from an input string
static java.lang.String toHexString(byte[] buf, int offset, int length)
          Convert a byte array to a hex string
static java.lang.String urlDecode(java.lang.String input)
          Return a URL decoded string
static java.lang.String urlEncode(java.lang.String input)
          Return an input string URL encoded
static java.lang.String urlEncodeForLink(java.lang.String input)
          Return an input string URL encoded for a URL link where '/' show as '/'
static void visitFilesAndDirectories(java.util.Date today, java.lang.String[] extensions, java.lang.String[] excludedDirectories, java.io.File directoryOrFile, java.util.List items)
          Visit a set of directories and add items to a list matching a list of extensions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_TIME_COMPARATOR

public static final java.util.Comparator FILE_TIME_COMPARATOR
Return a comparator that uses a file's last modified time to order the files. If the files have the same last modified time, the file's names are compared to order the files.


FILE_TIME_ASCENDING_COMPARATOR

public static final java.util.Comparator FILE_TIME_ASCENDING_COMPARATOR
Return a comparator that uses a file's last modified time to order the files in ascending order. If the files have the same last modified time, the file's names are compared to order the files.


FILE_NAME_COMPARATOR

public static final java.util.Comparator FILE_NAME_COMPARATOR
Return a comparator to sort by name

Method Detail

getDirectoryFilter

public static java.io.FileFilter getDirectoryFilter()
Return a file filter which only returns directories

Returns:
File filter appropriate for filtering only directories

getDirectoryFilter

public static java.io.FileFilter getDirectoryFilter(java.lang.String[] excludedDirectories)
Return a file filter which only returns directories that are not one of a list of excluded directories

Parameters:
excludedDirectories - List of directories to exclude
Returns:
File filter appropriate for filtering only directories

getRFC822Date

public static java.lang.String getRFC822Date(java.util.Date date)
Return a date in RFC 822 style

Parameters:
date - Date
Returns:
Date formatted as RFC 822

getFormattedDate

public static java.lang.String getFormattedDate(java.util.Date date,
                                                java.lang.String format,
                                                java.util.Locale locale)
Return a date formatted date

Parameters:
date - Date
format - Date Format String
locale - Locale Locale for retrieving proper date symbols
Returns:
Date formatted date

getISO8601Date

public static java.lang.String getISO8601Date(java.util.Date date)
Return a date in ISO 8601 style http://www.w3.org/TR/NOTE-datetime

Parameters:
date - Date
Returns:
Date formatted as ISO 8601

getUTCDate

public static java.lang.String getUTCDate(java.util.Date date)
Return a date in UTC style

Parameters:
date - Date
Returns:
Date formatted as ISO 8601
Since:
blojsom 1.9.4

getRegularExpressionFilter

public static java.io.FileFilter getRegularExpressionFilter(java.lang.String[] expressions)
Return a file filter which takes a list of regular expressions to look for

Parameters:
expressions - List of regular expressions for files to retrieve
Returns:
File filter appropriate for filtering out a set of files based on regular expressions

getExtensionsFilter

public static java.io.FileFilter getExtensionsFilter(java.lang.String[] extensions)
Return a file filter which takes a list of file extensions to look for

Parameters:
extensions - List of file extensions
Returns:
File filter appropriate for filtering out a set of file extensions

getExtensionsFilter

public static java.io.FileFilter getExtensionsFilter(java.lang.String[] extensions,
                                                     java.lang.String[] excludedDirectories,
                                                     boolean returnDirectories)
Return a file filter which takes a list of file extensions to look for

Parameters:
extensions - List of file extensions
returnDirectories - Whether or not to return
Returns:
File filter appropriate for filtering out a set of file extensions
Since:
blojsom 2.20

getExtensionFilter

public static java.io.FileFilter getExtensionFilter(java.lang.String extension)
Return a file filter which takes a single file extension to look for

Parameters:
extension - File extension
Returns:
File filter appropriate for filtering out a single file extension

visitFilesAndDirectories

public static void visitFilesAndDirectories(java.util.Date today,
                                            java.lang.String[] extensions,
                                            java.lang.String[] excludedDirectories,
                                            java.io.File directoryOrFile,
                                            java.util.List items)
Visit a set of directories and add items to a list matching a list of extensions

Parameters:
extensions - Extensions to match
excludedDirectories - Directories to exclude
directoryOrFile - Starting directory
items - List of items
Since:
blojsom 2.20

parseCommaList

public static java.lang.String[] parseCommaList(java.lang.String commaList)
Parse a comma-separated list of values; also parses over internal spaces

Parameters:
commaList - Comma-separated list
Returns:
Individual strings from the comma-separated list

parseOnlyCommaList

public static java.lang.String[] parseOnlyCommaList(java.lang.String commaList)
Parse a comma-separated list of values

Parameters:
commaList - Comma-separated list
Returns:
Individual strings from the comma-separated list
Since:
blojsom 2.21

parseOnlyCommaList

public static java.lang.String[] parseOnlyCommaList(java.lang.String commaList,
                                                    boolean trim)
Parse a comma-separated list of values

Parameters:
commaList - Comma-separated list
trim - If the contents of the array should be trimmed
Returns:
Individual strings from the comma-separated list
Since:
blojsom 2.29

parseLastComma

public static java.lang.String[] parseLastComma(java.lang.String value)
Parse a string into two separate strings based on the last comma in the input value

Parameters:
value - Input
Returns:
Parsed string
Since:
blojsom 2.24

parseDelimitedList

public static java.lang.String[] parseDelimitedList(java.lang.String delimitedList,
                                                    java.lang.String delimiter)
Parse a delimited list of values

Parameters:
delimitedList - Delimited list
delimiter - Field Delimiter
Returns:
Individual strings from the comma-separated list

parseDelimitedList

public static java.lang.String[] parseDelimitedList(java.lang.String delimitedList,
                                                    java.lang.String delimiter,
                                                    boolean trim)
Parse a delimited list of values

Parameters:
delimitedList - Delimited list
delimiter - Field Delimiter
trim - If the contents of the array should be trimmed
Returns:
Individual strings from the comma-separated list
Since:
blojsom 2.29

convertRequestParams

public static java.lang.String convertRequestParams(javax.servlet.http.HttpServletRequest request)
Convert the request parameters to a string

Parameters:
request - Servlet request
Returns:
Request parameters in the form &name=value

convertRequestParams

public static java.lang.String convertRequestParams(javax.servlet.http.HttpServletRequest request,
                                                    java.util.Map ignoreParams)
Convert the request parameters to a string

Parameters:
request - Servlet request
ignoreParams - Parameters to ignore when converting the request
Returns:
Request parameters in the form &name=value
Since:
blojsom 2.28

getBlogCategory

public static java.lang.String getBlogCategory(java.lang.String blogHome,
                                               java.lang.String requestedCategory)
Strip off the blog home directory for a requested blog category

Parameters:
blogHome - Blog home value
requestedCategory - Requested blog category
Returns:
Blog category only

getBlogSiteURL

public static java.lang.String getBlogSiteURL(java.lang.String blogURL,
                                              java.lang.String servletPath)
Return a URL to the main blog site without the servlet path requested

Parameters:
blogURL - URL for the blog
servletPath - Servlet path under which the blog is placed
Returns:
URL to the blog up to the servlet path

escapeString

public static java.lang.String escapeString(java.lang.String input)
Return an escaped string where &, <, >, ", and ' are converted to their HTML equivalents

Parameters:
input - Unescaped string
Returns:
Escaped string containing HTML equivalents for &, <, >, ", and '

escapeStringSimple

public static java.lang.String escapeStringSimple(java.lang.String input)
Return an escaped string where &, <, > are converted to their HTML equivalents

Parameters:
input - Unescaped string
Returns:
Escaped string containing HTML equivalents for &, <, >
Since:
blojsom 2.27

escapeMetaAndLink

public static java.lang.String escapeMetaAndLink(java.lang.String input)
Return an escaped string where <meta, <link tags are escaped

Parameters:
input - Unescaped string
Returns:
Escaped string where <meta, <link tags are escaped

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String pattern,
                                       java.lang.String replace)
Replace any occurances of a string pattern within a string with a different string.

Parameters:
str - The source string. This is the string that will be searched and have the replacements
pattern - The pattern to look for in str
replace - The string to insert in the place of pattern
Returns:
String with replace occurences

getFileExtension

public static java.lang.String getFileExtension(java.lang.String filename)
Return the file extension for a given filename or null if no file extension is present

Parameters:
filename - Filename
Returns:
File extension without the . or null if no file extension is present

getFilename

public static java.lang.String getFilename(java.lang.String filename)
Return the filename without extension for a given filename

Parameters:
filename - Filename
Returns:
Filename up to the .
Since:
blojsom 1.9

getFilenameFromPath

public static java.lang.String getFilenameFromPath(java.lang.String filenameWithPath)
Returns the base file name from the supplied file path. On the surface, this would appear to be a trivial task. Apparently, however, some Linux JDKs do not implement File.getName() correctly for Windows paths, so we attempt to take care of that here.

Parameters:
filenameWithPath - The full path to the file.
Returns:
The base file name, from the end of the path.
Since:
blojsom 2.12

getDateKey

public static java.lang.String getDateKey(java.util.Date date)
Return a string of "YYYYMMDD"

Parameters:
date - Date from which to extract "key"
Returns:
String of "YYYYMMDD"

removeInitialSlash

public static java.lang.String removeInitialSlash(java.lang.String input)
Remove the initial "/" from a string

Parameters:
input - Input string
Returns:
Input string without initial "/" removed or null if the input was null

removeTrailingSlash

public static java.lang.String removeTrailingSlash(java.lang.String input)
Remove the trailing "/" from a string

Parameters:
input - Input string
Returns:
Input string with trailing "/" removed or null if the input was null

removeSlashes

public static final java.lang.String removeSlashes(java.lang.String input)
Remove the "/" from the beginning and end of a string

Parameters:
input - Input string
Returns:
Input string with beginning and ending "/" removed or null if the input was null
Since:
blojsom 2.26

getFirstLine

public static java.lang.String getFirstLine(java.lang.String input,
                                            int length)
Extracts the first line in a given string, otherwise returns the first n bytes

Parameters:
input - String from which to extract the first line
length - Number of bytes to return if line seperator isnot found
Returns:
the first line of the string

getTemplateForPage

public static final java.lang.String getTemplateForPage(java.lang.String flavorTemplate,
                                                        java.lang.String page)
Return the template name for a particular page

Parameters:
flavorTemplate - Flavor template filename
page - Requested page
Returns:

getRequestValue

public static final java.lang.String getRequestValue(java.lang.String key,
                                                     javax.servlet.http.HttpServletRequest httpServletRequest)
Tries to retrieve a given key using getParameter(key) and if not available, will use getAttribute(key) from the servlet request

Parameters:
key - Parameter to retrieve
httpServletRequest - Request
Returns:
Value of the key as a string, or null if there is no parameter/attribute

getRequestValue

public static final java.lang.String getRequestValue(java.lang.String key,
                                                     javax.servlet.http.HttpServletRequest httpServletRequest,
                                                     boolean preferAttributes)
Tries to retrieve a given key using getParameter(key) and if not available, will use getAttribute(key) from the servlet request

Parameters:
key - Parameter to retrieve
httpServletRequest - Request
preferAttributes - If request attributes should be checked before request parameters
Returns:
Value of the key as a string, or null if there is no parameter/attribute

getFilenameForPermalink

public static final java.lang.String getFilenameForPermalink(java.lang.String permalink,
                                                             java.lang.String[] blogEntryExtensions)
Return only the filename of a permalink request

Parameters:
permalink - Permalink request
blogEntryExtensions - Regex for blog entries so that we only pickup requests for valid blog entries
Returns:
Filename portion of permalink request

urlEncode

public static final java.lang.String urlEncode(java.lang.String input)
Return an input string URL encoded

Parameters:
input - Input string
Returns:
URL encoded string, null if the input was null, or input unmodified there is an encoding exception

urlEncodeForLink

public static final java.lang.String urlEncodeForLink(java.lang.String input)
Return an input string URL encoded for a URL link where '/' show as '/'

Parameters:
input - Input string
Returns:
URL encoded string, null if the input was null, or input unmodified there is an encoding exception
Since:
blojsom 2.09

urlDecode

public static final java.lang.String urlDecode(java.lang.String input)
Return a URL decoded string

Parameters:
input - Input string
Returns:
URL decoded string or null if either the input was null or there is a decoding exception

getCalendarNavigationUrl

public static java.lang.String getCalendarNavigationUrl(java.lang.String prefix,
                                                        int month,
                                                        int day,
                                                        int year)
Create a Calendar Navigatation URL

Parameters:
prefix - Any URL Prefix
month - Month of navigation
day - Day of navigation
year - Year of navigation
Returns:
Properly formatted calendar navigation url

digestString

public static java.lang.String digestString(java.lang.String data)
Performs an MD5 Digest onthe given String content

Parameters:
data - Content to digest
Returns:
The Hash as Hex String

digestString

public static java.lang.String digestString(java.lang.String data,
                                            java.lang.String algorithm)
Performs an Digest onthe given String content for the given algorithm

Parameters:
data - Content to digest
algorithm - the algorithm to use (MD5, SHA1)
Returns:
The Hash as Hex String

toHexString

public static java.lang.String toHexString(byte[] buf,
                                           int offset,
                                           int length)
Convert a byte array to a hex string

Parameters:
buf - Byte array to convert to hex string
offset - Starting offset for conversion
length - Length to convert
Returns:
Hex string representing the byte array

loadProperties

public static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig,
                                                  java.lang.String configurationIP,
                                                  boolean required)
                                           throws BlojsomException
Try to load a properties file from disk

Parameters:
servletConfig - Servlet configuration
configurationIP - Name of the file to load the properties from
required - If the properties file is required
Returns:
Properties from the file. NEVER returns null.
Throws:
BlojsomException - If there is an I/O error or if configurationIP is not set and required == true.
Since:
blojsom 1.9

loadProperties

public static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig,
                                                  java.lang.String configurationIP,
                                                  boolean required,
                                                  boolean allowMultipleValues)
                                           throws BlojsomException
Try to load a properties file from disk

Parameters:
servletConfig - Servlet configuration
configurationIP - Name of the file to load the properties from
required - If the properties file is required
allowMultipleValues - If the BlojsomProperties object should allow multiple values
Returns:
Properties from the file. NEVER returns null.
Throws:
BlojsomException - If there is an I/O error or if configurationIP is not set and required == true.
Since:
blojsom 1.9

loadProperties

public static java.util.Properties loadProperties(javax.servlet.ServletConfig servletConfig,
                                                  java.lang.String configurationFile)
                                           throws BlojsomException
Try to load a properties file from disk. In this method, the properties file to load must have an explicit path provided

Parameters:
servletConfig - Servlet configuration
configurationFile - Properties file to be loaded from disk (e.g. /WEB-INF/sample.properties)
Returns:
Loaded properties object
Throws:
BlojsomException - If there is an error loading the properties from disk
Since:
blojsom 2.0

normalize

public static java.lang.String normalize(java.lang.String path)
Normalize a path to remove all ./, ../, .../, //, etc. type references

Parameters:
path - Input path
Returns:
Normalized path

nullToBlank

public static java.lang.String nullToBlank(java.lang.String input)
Check to see if the given input string is null and if so, return a blank string instead

Parameters:
input - Input string
Returns:
Blank string if the input string is null, otherwise just return the input string
Since:
blojsom 1.9

propertiesToMap

public static java.util.Map propertiesToMap(java.util.Properties properties)
Convert a set of Properties to a Map

Parameters:
properties - Properties to be converted to a Map
Returns:
Map object containing all the keys and values from the original Properties object. If the Properties object was null, a new Map is returned with no values.
Since:
blojsom 2.0

blojsomPropertiesToMap

public static java.util.Map blojsomPropertiesToMap(java.util.Properties properties)
Convert a BlojsomProperties object to a Map. If the properties object is null an emtpy Map is returned.

Parameters:
properties - BlojsomProperties
Returns:
Map containing keys and values from the properties
Since:
blojsom 2.23

arrayOfStringsToString

public static java.lang.String arrayOfStringsToString(java.lang.String[] array,
                                                      java.lang.String separator)
Turn an array of strings into a single string separated by a given delimeter. If the incoming array is null, this method returns the null string.

Parameters:
array - Array of strings
separator - Separator between strings
Returns:
Single string containing all the strings from the original array separated by the given delimeter, or null if the input was null.
Since:
blojsom 2.14

arrayOfStringsToString

public static java.lang.String arrayOfStringsToString(java.lang.String[] array)
Turn an array of strings into a single string separated by commas. If the incoming array is null, this method returns the null string.

Parameters:
array - Array of strings
Returns:
Single string containing all the strings from the original array separated by commas, or null if the input was null.

mapToProperties

public static java.util.Properties mapToProperties(java.util.Map map,
                                                   java.lang.String encoding)
Convert a Map to a set of BlojsomProperties

Parameters:
map - Map to be converted to a BlojsomProperties object
encoding - Specific encoding to use when writing BlojsomProperties object
Returns:
BlojsomProperties object containing all the keys and values from the original Map object. If the Map object was null, a new BlojsomProperties is returned with no values.
Since:
blojsom 2.04

mapToBlojsomProperties

public static java.util.Properties mapToBlojsomProperties(java.util.Map map)
Convert a Map to a BlojsomProperties. If the map is null an empty BlojsomProperties object is returned.

Parameters:
map - Map
Returns:
BlojsomProperties object containing keys and values from the map
Since:
blojsom 2.23

mapToProperties

public static java.util.Properties mapToProperties(java.util.Map map)
Convert a Map to a set of BlojsomProperties. Uses the default encoding.

Parameters:
map - Map to be converted to a BlojsomProperties object
Returns:
BlojsomProperties object containing all the keys and values from the original Map object. If the Map object was null, a new BlojsomProperties is returned with no values.
Since:
blojsom 2.04

getCategoryFromPath

public static final java.lang.String getCategoryFromPath(java.lang.String pathInfo)
Returns category information from the path provided to the method where the path provided is assumed to be everything after the servlet instance with a user id at the very beginning of the path. For example, /david/this/is/the/category

Parameters:
pathInfo - Path information
Returns:
Everything after the second "/" character in the path
Since:
blojsom 2.0

getUserFromPath

public static final java.lang.String getUserFromPath(java.lang.String pathInfo)
Returns user id information from the path provided to the method where the path provided is assumed to be everything after the servlet instance with a user id at the very beginning of the path. For example, /david/this/is/the/category

Parameters:
pathInfo - Path information
Returns:
Everything before the second "/" character in the path
Since:
blojsom 2.0

deleteDirectory

public static boolean deleteDirectory(java.io.File directoryOrFile)
Delete a directory (or file) and any sub-directories underneath the directory

Parameters:
directoryOrFile - Directory or file to be deleted
Returns:
true if the directory (or file) could be deleted, false otherwise

deleteDirectory

public static boolean deleteDirectory(java.io.File directoryOrFile,
                                      boolean removeDirectoryOrFile)
Delete a directory (or file) and any sub-directories underneath the directory

Parameters:
directoryOrFile - Directory or file to be deleted
removeDirectoryOrFile - If the directory of file should be deleted in addition to the sub-directories
Returns:
true if the directory (or file) could be deleted, false otherwise
Since:
blojsom 2.21

copyDirectory

public static void copyDirectory(java.io.File sourceDirectory,
                                 java.io.File targetDirectory)
                          throws java.io.IOException
Recursively copy a directory from a source to a target

Parameters:
sourceDirectory - Source directory
targetDirectory - Destination directory
Throws:
java.io.IOException - If there is an error copying the files and directories
Since:
blojsom 2.06

arrayOfStringsToMap

public static java.util.Map arrayOfStringsToMap(java.lang.String[] array)
Turn an array of strings into a Map where the keys and values are the input strings. If the incoming array is null, this method returns an empty map.

Parameters:
array - Array of strings
Returns:
Map Map containing all the strings from the original array or an empty map if the incoming array is null.
Since:
blojsom 2.06

checkStartingAndEndingSlash

public static java.lang.String checkStartingAndEndingSlash(java.lang.String input)
Add a '/' at the beginning and end of the input string if necessary.

Parameters:
input - Input string
Returns:
String with a '/' at the beginning and end of the original string, null if the input was null
Since:
blojsom 2.06

checkNullOrBlank

public static boolean checkNullOrBlank(java.lang.String input)
Checks to see if the string is null or blank (after trimming)

Parameters:
input - Input string
Returns:
true if the string is null or blank (after trimming), false otherwise
Since:
blojsom 2.06

setNoCacheControlHeaders

public static void setNoCacheControlHeaders(javax.servlet.http.HttpServletResponse httpServletResponse)
Set various cache control HTTP headers so that the browser does not try and cache the page

Parameters:
httpServletResponse - Response
Since:
blojsom 2.06

checkMapForKey

public static boolean checkMapForKey(java.util.Map map,
                                     java.lang.String key)
Check to see if a given map contains a particular key. Returns true if and only if the map and key are not null and the map contains the key.

Parameters:
map - Map to check for given key
key - Key to check for in map
Returns:
Returns true if and only if the map and key are not null and the map contains the key.

daysBetweenDates

public static int daysBetweenDates(java.util.Date startDate,
                                   java.util.Date endDate)
Return the number of days between two dates

Parameters:
startDate - Start date
endDate - End date
Returns:
Number of days between two dates which may be 0 if either of the dates if null
Since:
blojsom 2.14

getFilenameForDate

public static java.io.File getFilenameForDate(java.lang.String filename)
Return a filename with the date as a long value before the file extension.

Parameters:
filename - Filename with extension
Returns:
Filename as {filename}-{date}.{file extension} or null if there was no file extension
Since:
blojsom 2.14

stripLineTerminators

public static java.lang.String stripLineTerminators(java.lang.String input)
Strip line terminator characters from an input string

Parameters:
input - Input string
Returns:
Input with line terminator characters stripped or null if the input was null
Since:
blojsom 2.14

stripLineTerminators

public static java.lang.String stripLineTerminators(java.lang.String input,
                                                    java.lang.String replacement)
Strip line terminator characters from an input string

Parameters:
input - Input string
replacement - Replacement string
Returns:
Input with line terminator characters stripped or null if the input was null
Since:
blojsom 2.30

getKeysAsStringList

public static java.lang.String getKeysAsStringList(java.util.Map input)
Return the keys of a map as a comma-separated list

Parameters:
input - Map
Returns:
Keys as a comma-separated list or an empty string if the input is null or contains no keys
Since:
blojsom 2.16

listToCSV

public static java.lang.String listToCSV(java.util.List values)
Convert a list to a comma-separated string. If values in the list are null, a space is printed. If the input is null or there are no items in the list, an empty string is returned.

Parameters:
values - List of values
Returns:
Comma-separated string
Since:
blojsom 2.18

listToMap

public static java.util.Map listToMap(java.util.List values)
Convert a list of values to a Map. null values are not placed in the returned Map.

Parameters:
values - List of values
Returns:
Map where each key and value pair is from the list of values
Since:
blojsom 2.23

csvToList

public static java.util.List csvToList(java.lang.String valuesAsString)
Return a comma-separated list of Strings as a List; trims space around value

Parameters:
valuesAsString - Comma-separated values
Returns:
Comma-separated list of Strings as a List
Since:
blojsom 2.21

constructBaseURL

public static java.lang.String constructBaseURL(javax.servlet.http.HttpServletRequest httpServletRequest)
Construct a blog base URL from the request

Parameters:
httpServletRequest - Request
Returns:
URL of the form http://server:port/context_path
Since:
blojsom 2.20

constructBlogURL

public static java.lang.String constructBlogURL(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                java.lang.String blogID)
Construct a blog URL from the request

Parameters:
httpServletRequest - Request
blogID - Blog ID
Returns:
URL of the form http://server:port/context_path/servlet_path/blog_id/
Since:
blojsom 2.20

resolveDynamicBaseAndBlogURL

public static void resolveDynamicBaseAndBlogURL(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                Blog blog,
                                                java.lang.String blogID)
Check to see if the blog base URL or blog URL are present. If not, construct them dynamically by calling constructBaseURL(javax.servlet.http.HttpServletRequest) and constructBlogURL(javax.servlet.http.HttpServletRequest, String).

Parameters:
httpServletRequest - Request
blog - Blog
blogID - Blog ID
Since:
blojsom 2.20

getHashableContent

public static java.lang.String getHashableContent(java.lang.String content)
Return a digested string of some content

Parameters:
content - Content from which to generate a hashed digest
Returns:
digestString(String)
Since:
blojsom 2.21

getBlogEntryFilename

public static java.lang.String getBlogEntryFilename(java.lang.String title,
                                                    java.lang.String content)
Return a filename appropriate for the blog entry content

Parameters:
title - Blog entry title
content - Blog entry content
Returns:
Filename for the new blog entry
Since:
blojsom 2.21

getLocaleFromString

public static java.util.Locale getLocaleFromString(java.lang.String locale)
Create a Locale object from a string of form language_country_variant

Parameters:
locale - Locale string of form language_country_variant
Returns:
Locale object with language, country, variant settings or Locale.getDefault() if locale input is null or blank
Since:
blojsom 2.21

getLanguagesForSystem

public static java.lang.String[] getLanguagesForSystem(java.util.Locale locale)
Return of a list of locale languages supported on this system (JVM)

Parameters:
locale - Locale used for sorting
Returns:
List of locale languages supported on this system (JVM)
Since:
blojsom 2.21

getCountriesForSystem

public static java.lang.String[] getCountriesForSystem(java.util.Locale locale)
Return of a list of locale countries supported on this system (JVM)

Parameters:
locale - Locale used for sorting
Returns:
Return of a list of locale countries supported on this system (JVM)
Since:
blojsom 2.21

getTimeZonesForSystem

public static java.lang.String[] getTimeZonesForSystem(java.util.Locale locale)
Return of a list of time zone IDs supported on this system (JVM)

Parameters:
locale - Locale used for sorting
Returns:
Return of a list of time zone IDs supported on this system (JVM)
Since:
blojsom 2.21

listFilesInSubdirectories

public static void listFilesInSubdirectories(java.io.File directory,
                                             java.lang.String parentDirectory,
                                             java.util.List files)
List the files in a sub-directory of a given directory and strip the parent directory from the path of the files added to the list.

Parameters:
directory - Sub-directory to start looking for files
parentDirectory - Parent directory to strip
files - List of files to add to
Since:
blojsom 2.23

listDirectoriesInSubdirectories

public static void listDirectoriesInSubdirectories(java.io.File directory,
                                                   java.lang.String parentDirectory,
                                                   java.util.List directories)
List the sub-directories in a sub-directory of a given directory and strip the parent directory from the path of the directories added to the list.

Parameters:
directory - Sub-directory to start looking for files
parentDirectory - Parent directory to strip
directories - List of directories to add to
Since:
blojsom 2.23

fetchEntry

public static BlogEntry fetchEntry(BlojsomFetcher fetcher,
                                   BlogUser blogUser,
                                   java.lang.String category,
                                   java.lang.String permalink)
                            throws BlojsomFetcherException
Fetch an BlogEntry given a category and permalink

Parameters:
fetcher - BlojsomFetcher
blogUser - BlogUser
category - Category
permalink - Entry
Returns:
BlogEntry
Throws:
BlojsomFetcherException - If there is an error loading the entry
Since:
blojsom 2.23

stripHTML

public static java.lang.String stripHTML(java.lang.String text)
Strip all HTML from a given piece of text

Parameters:
text - Text
Returns:
text stripped of HTML between < and > tags or null if input was null or blank if input was blank
Since:
blojsom 2.23

arrayToList

public static java.util.List arrayToList(java.lang.String[] input)
Convert a String[] to a List

Parameters:
input - String[]
Returns:
List from string array
Since:
blojsom 2.24

removeNullValues

public static java.util.List removeNullValues(java.util.List input)
Remove null values from a given list

Parameters:
input - List
Returns:
List with null values removed
Since:
blojsom 2.25

addSlashes

public static java.lang.String addSlashes(java.lang.String input)
Add preceeding and trailing slashes to an input string. If input is null a "/" is returned.

Parameters:
input - Input
Returns:
Input with preceeding and trailing slashes added
Since:
blojsom 2.26