edu.sdsc.inca.util
Class StringMethods

java.lang.Object
  extended byedu.sdsc.inca.util.StringMethods

public class StringMethods
extends java.lang.Object

A class of useful static utility methods that really don't fit elsewhere.

Author:
Jim Hayes <jhayes@sdsc.edu>

Field Summary
static java.util.regex.Pattern LEADING_TAG
           
static java.lang.String MIME_DELIM
           
 
Constructor Summary
StringMethods()
           
 
Method Summary
static void appendToStringBuffer(java.lang.StringBuffer buffer, java.lang.String[] strings)
          Append a series of strings to the specified string buffer.
static int compareTo(java.lang.String left, java.lang.String right)
          Returns an indicator of the relationship between two operands.
static java.lang.String fileContents(java.lang.String path)
          Returns the contents of a specified file as a String, with lines from the file delimited by newlines (\n).
static java.lang.String fileContentsFromClasspath(java.lang.String filename)
          Find a file from the classpath and return the contents as a string.
static java.lang.String join(java.lang.String separator, java.lang.String[] values)
          Joins the separate strings in values into a single string with fields separated by the value of separator and returns that new string.
protected static java.lang.String mimeMessage(java.lang.String address, java.lang.String subject, java.lang.String message, java.io.File[] attachments, java.lang.String[] types)
          Construct a multi-part MIME email message that can contain attachments.
static void sendEmail(java.lang.String address, java.lang.String subject, java.lang.String message)
          Send a notification email to the specified email address.
static void sendEmail(java.lang.String address, java.lang.String subject, java.lang.String message, java.io.File[] attachments, java.lang.String[] types)
          Send a notification email to the specified email address.
static java.lang.String xmlContentToHtml(java.lang.String xml, java.lang.String indent)
          Translates XML content into an HTML table for easy viewing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIME_DELIM

public static final java.lang.String MIME_DELIM
See Also:
Constant Field Values

LEADING_TAG

public static final java.util.regex.Pattern LEADING_TAG
Constructor Detail

StringMethods

public StringMethods()
Method Detail

appendToStringBuffer

public static void appendToStringBuffer(java.lang.StringBuffer buffer,
                                        java.lang.String[] strings)
Append a series of strings to the specified string buffer.

Parameters:
buffer - A string buffer.
strings - The strings to append to it.

compareTo

public static int compareTo(java.lang.String left,
                            java.lang.String right)
Returns an indicator of the relationship between two operands.

Parameters:
left - the left operand
right - the right operand
Returns:
a negative number if left < right, a positive number if left > right, 0 if the two are equal

fileContents

public static java.lang.String fileContents(java.lang.String path)
                                     throws java.io.IOException
Returns the contents of a specified file as a String, with lines from the file delimited by newlines (\n).

Parameters:
path - the path to the file to read
Returns:
the file contents
Throws:
java.io.IOException - on an open/read error

fileContentsFromClasspath

public static java.lang.String fileContentsFromClasspath(java.lang.String filename)
                                                  throws java.io.IOException
Find a file from the classpath and return the contents as a string.

Parameters:
filename - The name of the file to search for in the classpath.
Returns:
The contents of the file.
Throws:
java.io.IOException

join

public static java.lang.String join(java.lang.String separator,
                                    java.lang.String[] values)
Joins the separate strings in values into a single string with fields separated by the value of separator and returns that new string.

Parameters:
separator - The string that will separate the values.
values - The list of strings that should be joined
Returns:
The new joined string.

sendEmail

public static void sendEmail(java.lang.String address,
                             java.lang.String subject,
                             java.lang.String message)
Send a notification email to the specified email address.

Parameters:
address - The email address to send the email to.
subject - The subject of the email.
message - The message body of the email

sendEmail

public static void sendEmail(java.lang.String address,
                             java.lang.String subject,
                             java.lang.String message,
                             java.io.File[] attachments,
                             java.lang.String[] types)
Send a notification email to the specified email address.

Parameters:
address - The email address to send the email to.
subject - The subject of the email.
message - The message body of the email
attachments - List of files to attach.
types - The types of attachments of the files (e.g., text/html)

xmlContentToHtml

public static java.lang.String xmlContentToHtml(java.lang.String xml,
                                                java.lang.String indent)
Translates XML content into an HTML table for easy viewing.

Parameters:
xml - XML content--either a series of (balanced) tags or text
indent - an indent string used to pretty-print the HTML; the top-level call will typically pass an empty string
Returns:
an XML table that displays the content

mimeMessage

protected static java.lang.String mimeMessage(java.lang.String address,
                                              java.lang.String subject,
                                              java.lang.String message,
                                              java.io.File[] attachments,
                                              java.lang.String[] types)
                                       throws java.io.IOException
Construct a multi-part MIME email message that can contain attachments.

Parameters:
address - The email address the message will be sent to.
subject - The subject of the email message.
message - The body of the email message.
attachments - List of files to attach.
types - The types of attachments of the files (e.g., text/html)
Returns:
The MIME text that can be sent to sendmail
Throws:
java.io.IOException