org.clapper.curn
Class CurnUtil

java.lang.Object
  extended by org.clapper.curn.CurnUtil

public class CurnUtil
extends java.lang.Object

Miscellaneous utility methods that are shared among classes, but don't logically belong anywhere in particular.

Version:
$Revision: 6491 $

Nested Class Summary
static class CurnUtil.IndexMarker
          Constants defining where rolled file indicators should go in the file name pattern.
 
Method Summary
static java.io.File createTempXMLFile()
          Create a temporary file for XML content.
static java.io.PrintWriter getErrorOut()
          Get a PrintWriter for writing error messages to the screen.
static java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
          Get the resource bundle.
static java.lang.String getResourceFromBundle(java.lang.String key, java.util.Locale locale)
          Get a string (resource) from the resource bundle.
static java.lang.String makeRollingFileWriterPattern(java.io.File file, CurnUtil.IndexMarker indexMarkerLoc)
          Transform a File object into a RollingFileWriter pattern.
static java.io.File mapConfiguredPathName(java.lang.String pathName)
          Map a configured path name to a File object.
static java.net.URL normalizeURL(java.lang.String url)
          Normalize a URL, by forcing its host name and protocol to lower case.
static java.net.URL normalizeURL(java.net.URL url)
          Normalize a URL, by forcing its host name and protocol to lower case.
static java.io.PrintWriter openOutputFile(java.io.File file, java.lang.String encoding, CurnUtil.IndexMarker indexMarkerLoc, int totalBackups)
          Open a file that might require backing up.
static java.lang.String urlToLookupKey(java.net.URL url)
          Convert a URL to a lookup key, by normalizing it and converting it to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

normalizeURL

public static java.net.URL normalizeURL(java.net.URL url)
Normalize a URL, by forcing its host name and protocol to lower case.

Parameters:
url - The URL to normalize.
Returns:
a new URL object representing the normalized URL
See Also:
normalizeURL(String)

normalizeURL

public static java.net.URL normalizeURL(java.lang.String url)
                                 throws java.net.MalformedURLException
Normalize a URL, by forcing its host name and protocol to lower case.

Parameters:
url - The URL to normalize, as a string
Returns:
a new URL object representing the normalized URL
Throws:
java.net.MalformedURLException - bad URL string
See Also:
normalizeURL(URL)

urlToLookupKey

public static java.lang.String urlToLookupKey(java.net.URL url)
Convert a URL to a lookup key, by normalizing it and converting it to a string. Calling this method ensures that everyone converts a URL to a key the same way.

Parameters:
url - the URL
Returns:
the lookup key (really, the normalized, stringified URL)

getResourceBundle

public static java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
Get the resource bundle.

Parameters:
locale - the locale to use, or null for the default
Returns:
the resource bundle
See Also:
Constants.BUNDLE_NAME, getResourceFromBundle(java.lang.String, java.util.Locale)

getResourceFromBundle

public static java.lang.String getResourceFromBundle(java.lang.String key,
                                                     java.util.Locale locale)
Get a string (resource) from the resource bundle.

Parameters:
key - the key for the resource to look up
locale - the locale to use, or null for the default
Returns:
the resource bundle, or null if the resource doesn't exist
See Also:
Constants.BUNDLE_NAME, getResourceBundle(java.util.Locale)

makeRollingFileWriterPattern

public static java.lang.String makeRollingFileWriterPattern(java.io.File file,
                                                            CurnUtil.IndexMarker indexMarkerLoc)
Transform a File object into a RollingFileWriter pattern.

Parameters:
file - the file
indexMarkerLoc - where the RollingFileWriter index marker should go
Returns:
the transformed path string

createTempXMLFile

public static java.io.File createTempXMLFile()
                                      throws java.io.IOException
Create a temporary file for XML content.

Returns:
the temp file
Throws:
java.io.IOException - error creating temporary file

openOutputFile

public static java.io.PrintWriter openOutputFile(java.io.File file,
                                                 java.lang.String encoding,
                                                 CurnUtil.IndexMarker indexMarkerLoc,
                                                 int totalBackups)
                                          throws org.clapper.util.io.IOExceptionExt
Open a file that might require backing up. Takes care of transforming the file name into a RollingFileWriter pattern, if necessary.

Parameters:
file - the file to open
encoding - encoding to use when opening the file, or null for the default
totalBackups - total backups to keep, if positive
indexMarkerLoc - where the RollingFileWriter index marker should go. Ignored unless totalBackups is positive.
Returns:
a PrintWriter for the output
Throws:
org.clapper.util.io.IOExceptionExt - on error

getErrorOut

public static java.io.PrintWriter getErrorOut()
Get a PrintWriter for writing error messages to the screen.

Returns:
a suitable PrintWriter

mapConfiguredPathName

public static java.io.File mapConfiguredPathName(java.lang.String pathName)
Map a configured path name to a File object. This method parses the path name and converts any Unix-style path separators to the appropriate separator for the current platform. Use of this method allows Unix-style paths in the configuration file, even on non-Unix systems (which also bypasses some parsing issues).

Parameters:
pathName - the path name to map
Returns:
an appropriate File object for the current system.


Copyright © 2004-2006 Brian M. Clapper. All Rights Reserved.