com.cybersource.ws.client
Class Utility

java.lang.Object
  extended by com.cybersource.ws.client.Utility

public class Utility
extends Object

Class containing useful constants and methods.


Field Summary
static String ENVIRONMENT
          Environment information.
static String VERSION
          Version number of this release.
 
Method Summary
static Element createElement(Document owner, String nsURI, String elementName, String textValue)
          Creates an Element object in the CyberSource namespace.
static Element getElement(Document owner, String elementName, String nsURI)
          Returns the Element object corresponding to the given element name.
static String getElementText(Document owner, String elementName, String nsURI)
          Returns the text value of the given element name in the CyberSource namespace.
static String getStackTrace(Exception e)
          Returns the stack trace of the supplied Exception object.
static String mapToString(Map src, boolean mask, int type)
          Converts the contents of a Map object into a string, one name-value pair to a line and the name and value are separated by an equal sign.
static DocumentBuilder newDocumentBuilder()
          Returns a DocumentBuilder object.
static String nodeToString(Node node)
          Returns the string representation of the given Node object.
static String nodeToString(Node node, int type)
          Returns the string representation of the given Node object.
static byte[] read(File file)
          Reads the content of the given file into a byte array.
static byte[] read(InputStream in)
          Reads the content of the given file into a byte array.
static byte[] read(String filename)
          Reads the content of the given file into a byte array.
static Properties readProperties(String[] commandLineArgs)
          Reads the properties from a file.
static Document readRequest(Properties props, String filename)
          Read the request xml file
static HashMap stringToMap(String src)
          Converts a name-value pair string into a Map object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
Version number of this release.

See Also:
Constant Field Values

ENVIRONMENT

public static final String ENVIRONMENT
Environment information.

Method Detail

nodeToString

public static String nodeToString(Node node,
                                  int type)
Returns the string representation of the given Node object. Used for logging or demo purposes only. As it employs some formatting parameters, parsing the string it returns may not result to a Node object exactly similar to the one passed to it.

Parameters:
node - the Node object whose string representation is wanted.
type - either PCI.REQUEST or PCI.REPLY. Used for masking.
Returns:
the string representation of the given Node object.

nodeToString

public static String nodeToString(Node node)
Returns the string representation of the given Node object. Used for logging or demo purposes only. As it employs some formatting parameters, parsing the string it returns may not result to a Node object exactly similar to the one passed to it.

Parameters:
node - the Node object whose string representation is wanted.
Returns:
the string representation of the given Node object.

readProperties

public static Properties readProperties(String[] commandLineArgs)
Reads the properties from a file. If no filename was specified in the command-line, it will look for "cybs.properties" in the current directory.

Parameters:
commandLineArgs - the command-line arguments.
Returns:
Properties object containing the run-time properties required by the clients.

read

public static byte[] read(String filename)
                   throws IOException
Reads the content of the given file into a byte array.

Parameters:
filename - name of the file to read.
Returns:
content of the file.
Throws:
IOException - if there was an error reading the file.

read

public static byte[] read(File file)
                   throws IOException
Reads the content of the given file into a byte array.

Parameters:
file - File object to read.
Returns:
content of the file
Throws:
IOException - if there was an error reading the file.

read

public static byte[] read(InputStream in)
                   throws IOException
Reads the content of the given file into a byte array.

Parameters:
in - InputStream object to read.
Returns:
content of the file
Throws:
IOException - if there was an error reading the file.

newDocumentBuilder

public static DocumentBuilder newDocumentBuilder()
                                          throws ParserConfigurationException
Returns a DocumentBuilder object.

Returns:
a DocumentBuilder object.
Throws:
ParserConfigurationException - if no suitable parser implementation is found.

getElement

public static Element getElement(Document owner,
                                 String elementName,
                                 String nsURI)
Returns the Element object corresponding to the given element name.

Parameters:
owner - Document object to search.
elementName - local name to search for.
nsURI - namespaceURI to used (may be null).
Returns:
the Element object corresponding to the given element name or null if none is found.

getElementText

public static String getElementText(Document owner,
                                    String elementName,
                                    String nsURI)
Returns the text value of the given element name in the CyberSource namespace.

Parameters:
owner - Document object to search.
elementName - local name to search for.
nsURI - namespaceURI to used (may be null).
Returns:
the text value of the given element name in the CyberSource namespace or null if none is found.

getStackTrace

public static String getStackTrace(Exception e)
Returns the stack trace of the supplied Exception object.

Parameters:
e - Exception object.
Returns:
the stack trace of the Exception object.

stringToMap

public static HashMap stringToMap(String src)
Converts a name-value pair string into a Map object.

Parameters:
src - String containing name-value pairs.
Returns:
resulting Map object; will be empty if the string was null or empty.

mapToString

public static String mapToString(Map src,
                                 boolean mask,
                                 int type)
Converts the contents of a Map object into a string, one name-value pair to a line and the name and value are separated by an equal sign.

Parameters:
src - Map object whose contents are being converted.
mask - Flag whether or not to mask "unsafe" fields.
type - Relevant only when mask is true, indicates whether this is the request or the reply map. Pass either PCI.REQUEST or PCI.REPLY.
Returns:
resulting string; will be empty if the Map object was null or empty.

readRequest

public static Document readRequest(Properties props,
                                   String filename)
Read the request xml file

Parameters:
props - Properties object to lookup properties in
filename - Filename of file containing XML request
Returns:
Document Request from filename read as document

createElement

public static Element createElement(Document owner,
                                    String nsURI,
                                    String elementName,
                                    String textValue)
Creates an Element object in the CyberSource namespace.

Parameters:
owner - Document object to own the Element object.
nsURI - Namespace URI to use.
elementName - local name of Element object to create.
textValue - text value of the new Element object.
Returns:
the newly created Element object.


Copyright © 2016. All Rights Reserved.