NetCharts Server

netcharts.server.util
Class Util

java.lang.Object
  |
  +--netcharts.server.util.Util

public class Util
extends java.lang.Object

Assorted utility methods.


Constructor Summary
Util()
           
 
Method Summary
static java.lang.String appendToQueryString(java.util.Hashtable variables, java.util.Hashtable excludes, java.lang.String queryString)
          Appends the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable to the HTTP query string supplied.
static java.lang.String appendToQueryString(java.util.Hashtable variables, java.util.Vector excludes, java.lang.String queryString)
          Appends the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable to the HTTP query string supplied.
static java.lang.String appendToQueryString(java.lang.String parameterName, java.lang.String parameterValue, java.lang.String queryString)
          Appends the new parameter and value to the HTTP query string supplied.
static void checkHashtableParametersForChart(java.util.Hashtable vars)
          Ensures that the Hashtable contains no parameters that we add specifically and that there is a type parameter.
static void combineHashtables(java.util.Hashtable orig, java.util.Hashtable toAdd)
          Appends one Hashtable to another.
static java.lang.Object[][] convertNCXMLToObjectArray(byte[] ncxml)
          Converts NCXML into an Object[][].
static java.lang.Object[][] convertNCXMLToObjectArray(org.xml.sax.InputSource source)
          Converts NCXML into an Object[][].
static java.lang.Object[][] convertNCXMLToObjectArray(java.lang.String ncxml)
          Converts NCXML into an Object[][].
static java.sql.ResultSet convertObjectArrayToResultSet(java.lang.Object[][] data, boolean useFirstRowAsColumnNames)
          Converts an Object[][] into a ResultSet.
static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data)
          Converts an ResultSet into NCXML.
static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data, boolean useColumnNamesAsFirstRow)
          Converts an ResultSet into NCXML.
static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data, boolean useColumnNamesAsFirstRow, java.lang.String encoding)
          Converts an ResultSet into NCXML.
static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data, java.lang.String encoding)
          Converts an ResultSet into NCXML.
static java.lang.Object[][] convertResultSetToObjectArray(java.sql.ResultSet rs)
          Converts an ResultSet into a Object[][].
static java.lang.Object[][] convertResultSetToObjectArray(java.sql.ResultSet rs, boolean useColumnNamesAsFirstRow)
          Converts an ResultSet into a Object[][].
static java.lang.String convertToCSV(java.lang.Object[][] data, char delimiter)
          Converts an Object[][] into CSV.
static java.lang.String convertToNCXML(java.lang.Object[][] data)
          Converts an Object[][] into NCXML.
static java.lang.String convertToNCXML(java.lang.Object[][] data, java.lang.String encoding)
          Converts an Object[][] into NCXML.
static java.util.Vector convertToVector(java.lang.Object[][] data)
          Converts an Object[][] into a Vector.
static java.lang.String createQueryString(java.util.Hashtable variables, java.util.Hashtable excludes)
          Creates a HTTP query string containing the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable.
static java.lang.String createQueryString(java.util.Hashtable variables, java.util.Vector excludes)
          Creates a HTTP query string containing the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable.
static java.lang.String encode(java.lang.String s)
          URL encode the string but ignore /'s.
static java.lang.String formatForHtml(java.lang.String in)
          HTML encodes the string
static java.lang.String formatForXML(java.lang.String in)
          Encodes the string for inclusion within XML.
static byte[] getBytes(java.lang.String data, java.lang.String encoding)
          Get bytes from a string given a String and an encoding mechanism.
static java.lang.String getEncodingForXMLPI(java.lang.String encoding)
          Get the XML PI attribute representing the encoding.
static java.lang.String getRelativePath(java.lang.String absolutePath1, java.lang.String absolutePath2)
          Resolves an absolute path against another to get a relative path.
Case insensitive
Examples of input/output combinations: absolutePath1="c:\\folder1\\" absolutePath2="c:\\folder1\\sub-folder1\\" getRelativePath=".\\sub-folder1\\" absolutePath1="c:\\folder1\\" absolutePath2="c:\\folder1\\sub-folder1\\file.txt" getRelativePath=".\\sub-folder1\\file.txt" absolutePath1="c:\\folder1\\sub-folder1\\" absolutePath2="c:\\folder2\\" getRelativePath="..\\..\\folder2\\" If the drives are different then an absolute path must be returned.
For example: absolutePath1="c:\\folder1\\" absolutePath2="d:\\folder2\\" getRelativePath="d:\\folder2\\"
static java.lang.String[] getResultSetColumnNames(java.sql.ResultSet data)
          Get the column nbames of a ResultSet.
static java.lang.String newString(byte[] data, java.lang.String encoding)
          Make a new string given a byte array and an encoding mechanism.
static java.lang.String newString(chartworks.es.util.ServerReply sr)
          Make a new string given the ServerReply's content byte array and character encoding.
static java.util.Hashtable parseParameters(java.lang.String parameters)
           
static byte[] readBytesFully(java.io.InputStream input)
          Reads the InputStream into the byte array.
static java.lang.String removeQueryParameter(java.lang.String queryString, java.lang.String parameter, boolean all)
          Removes a parameter from an existing query string.
static java.lang.String replaceVar(java.lang.String origString, java.lang.String variable, java.lang.String newValue, boolean all)
          Replaces the variable string with the replacement value.
static void resetResultSet(java.sql.ResultSet rs)
          Reset a ResultSet to before its first row.
static java.lang.String urlEncode(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

combineHashtables

public static void combineHashtables(java.util.Hashtable orig,
                                     java.util.Hashtable toAdd)
Appends one Hashtable to another.
Parameters:
orig - The Hashtable to add to.
toAdd - The Hashtable to add from.

appendToQueryString

public static java.lang.String appendToQueryString(java.lang.String parameterName,
                                                   java.lang.String parameterValue,
                                                   java.lang.String queryString)
Appends the new parameter and value to the HTTP query string supplied.
Parameters:
parameterName - The name of the parameter to add to the query string.
parameterValue - The value of the parameter to add to the query string.
queryString - The query string to append to.

createQueryString

public static java.lang.String createQueryString(java.util.Hashtable variables,
                                                 java.util.Hashtable excludes)
Creates a HTTP query string containing the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable.
Parameters:
variables - The set of key/value pairs to add to the query string.
excludes - The set of key/value pairs to exclude from the query string.

appendToQueryString

public static java.lang.String appendToQueryString(java.util.Hashtable variables,
                                                   java.util.Hashtable excludes,
                                                   java.lang.String queryString)
Appends the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable to the HTTP query string supplied.
Parameters:
variables - The set of key/value pairs to add to the query string.
excludes - The set of key/value pairs to exclude from the query string (can be null).
queryString - The query string to append to.

createQueryString

public static java.lang.String createQueryString(java.util.Hashtable variables,
                                                 java.util.Vector excludes)
Creates a HTTP query string containing the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable.
Parameters:
variables - The set of key/value pairs to add to the query string.
excludes - The set of parameters to exclude from the query string.

appendToQueryString

public static java.lang.String appendToQueryString(java.util.Hashtable variables,
                                                   java.util.Vector excludes,
                                                   java.lang.String queryString)
Appends the set of key/value pairs contained within the variables Hashtable that do not exist in the excludes Hashtable to the HTTP query string supplied.
Parameters:
variables - The set of key/value pairs to add to the query string.
excludes - The set of parameters to exclude from the query string (can be null).
queryString - The query string to append to.

removeQueryParameter

public static java.lang.String removeQueryParameter(java.lang.String queryString,
                                                    java.lang.String parameter,
                                                    boolean all)
Removes a parameter from an existing query string.
Parameters:
queryString - The query string to append to.
parameter - The parameter to remove.
all - Whether all occurrences of this parameter should be removed.

replaceVar

public static java.lang.String replaceVar(java.lang.String origString,
                                          java.lang.String variable,
                                          java.lang.String newValue,
                                          boolean all)
Replaces the variable string with the replacement value.
Parameters:
origString - The original string containing variable to replace.
variable - The variable to replace.
newValue - The value to replace the variable with.
all - Whether or not all variable instances should be replaced.

checkHashtableParametersForChart

public static void checkHashtableParametersForChart(java.util.Hashtable vars)
Ensures that the Hashtable contains no parameters that we add specifically and that there is a type parameter.
Parameters:
vars - The original string containing variable to replace.

readBytesFully

public static byte[] readBytesFully(java.io.InputStream input)
Reads the InputStream into the byte array.
Parameters:
input - The InputStream containing the input.

formatForHtml

public static java.lang.String formatForHtml(java.lang.String in)
HTML encodes the string
Parameters:
in - The string to encode for HTML.

formatForXML

public static java.lang.String formatForXML(java.lang.String in)
Encodes the string for inclusion within XML.
Parameters:
in - The string to encode.

parseParameters

public static java.util.Hashtable parseParameters(java.lang.String parameters)

encode

public static java.lang.String encode(java.lang.String s)
URL encode the string but ignore /'s.

convertToNCXML

public static java.lang.String convertToNCXML(java.lang.Object[][] data)
Converts an Object[][] into NCXML.
Parameters:
data - The data to convert.

convertToNCXML

public static java.lang.String convertToNCXML(java.lang.Object[][] data,
                                              java.lang.String encoding)
Converts an Object[][] into NCXML.
Parameters:
data - The data to convert.
encoding - The encoding to use for the xml doc.

convertToCSV

public static java.lang.String convertToCSV(java.lang.Object[][] data,
                                            char delimiter)
Converts an Object[][] into CSV.
Parameters:
data - The data to convert.

convertToVector

public static java.util.Vector convertToVector(java.lang.Object[][] data)
Converts an Object[][] into a Vector.
Parameters:
data - The data to convert.

convertResultSetToNCXML

public static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data)
Converts an ResultSet into NCXML.
Parameters:
data - The data to convert.

convertResultSetToNCXML

public static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data,
                                                       boolean useColumnNamesAsFirstRow)
Converts an ResultSet into NCXML.
Parameters:
data - The data to convert.
useColumnNamesAsFirstRow - Whether to use the column names as the first row of data.

convertResultSetToNCXML

public static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data,
                                                       java.lang.String encoding)
Converts an ResultSet into NCXML.
Parameters:
data - The data to convert.
encoding - The encoding to use for the xml doc.

convertResultSetToNCXML

public static java.lang.String convertResultSetToNCXML(java.sql.ResultSet data,
                                                       boolean useColumnNamesAsFirstRow,
                                                       java.lang.String encoding)
Converts an ResultSet into NCXML.
Parameters:
data - The data to convert.
useColumnNamesAsFirstRow - Whether to use the column names as the first row of data.
encoding - The encoding to use for the xml doc.

resetResultSet

public static void resetResultSet(java.sql.ResultSet rs)
Reset a ResultSet to before its first row.

getResultSetColumnNames

public static java.lang.String[] getResultSetColumnNames(java.sql.ResultSet data)
Get the column nbames of a ResultSet.
Parameters:
data - The ResultSet.
Returns:
The column names in a String array or null if error.

convertNCXMLToObjectArray

public static java.lang.Object[][] convertNCXMLToObjectArray(byte[] ncxml)
Converts NCXML into an Object[][].
Parameters:
ncxml - The NCXML to convert.

convertNCXMLToObjectArray

public static java.lang.Object[][] convertNCXMLToObjectArray(java.lang.String ncxml)
Converts NCXML into an Object[][].
Parameters:
ncxml - The NCXML to convert.

convertNCXMLToObjectArray

public static java.lang.Object[][] convertNCXMLToObjectArray(org.xml.sax.InputSource source)
Converts NCXML into an Object[][].
Parameters:
source - The NCXML to convert.

convertResultSetToObjectArray

public static java.lang.Object[][] convertResultSetToObjectArray(java.sql.ResultSet rs)
Converts an ResultSet into a Object[][].
Parameters:
rs - The data to convert.

convertResultSetToObjectArray

public static java.lang.Object[][] convertResultSetToObjectArray(java.sql.ResultSet rs,
                                                                 boolean useColumnNamesAsFirstRow)
Converts an ResultSet into a Object[][].
Parameters:
rs - The data to convert.
useColumnNamesAsFirstRow - Whether to make the column names the first row of the object array.

convertObjectArrayToResultSet

public static java.sql.ResultSet convertObjectArrayToResultSet(java.lang.Object[][] data,
                                                               boolean useFirstRowAsColumnNames)
Converts an Object[][] into a ResultSet.
Parameters:
data - The data to convert.
useFirstRowAsColumnNames - Whether to make the first row of the object array the column names of the ResultSet.

newString

public static java.lang.String newString(chartworks.es.util.ServerReply sr)
Make a new string given the ServerReply's content byte array and character encoding. Encoding can be null to mean the platform default encoding.

newString

public static java.lang.String newString(byte[] data,
                                         java.lang.String encoding)
Make a new string given a byte array and an encoding mechanism. Encoding can be null to mean the platform default encoding.

getBytes

public static byte[] getBytes(java.lang.String data,
                              java.lang.String encoding)
Get bytes from a string given a String and an encoding mechanism. Encoding can be null to mean the platform default encoding.

getEncodingForXMLPI

public static java.lang.String getEncodingForXMLPI(java.lang.String encoding)
Get the XML PI attribute representing the encoding. Return empty string if there is no encoding specified.

getRelativePath

public static java.lang.String getRelativePath(java.lang.String absolutePath1,
                                               java.lang.String absolutePath2)
Resolves an absolute path against another to get a relative path.
Case insensitive
Examples of input/output combinations: If the drives are different then an absolute path must be returned.
For example: absolutePath1="c:\\folder1\\" absolutePath2="d:\\folder2\\" getRelativePath="d:\\folder2\\"

urlEncode

public static java.lang.String urlEncode(java.lang.String s)

NetCharts Server


Visual Mining, Inc.
15825 Shady Grove Rd.
Suite 20
Rockville, MD 20850
800.308.0731
301.947.8293 FAX

Copyright © Visual Mining, Inc. 1996 - 2007
All Rights Reserved.

NetCharts Server TM is a registered trademark of Visual Mining, Inc. Other brands and their products are trademarks of their respective holders.

Last Modified: Jun 14, 2007