com.cybersource.ws.client
Class Utility

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

public class Utility
extends java.lang.Object

Class containing useful constants and methods.


Field Summary
static java.lang.String ENVIRONMENT
          Environment information.
static java.lang.String VERSION
          Version number of this release.
 
Method Summary
static org.w3c.dom.Element createElement(org.w3c.dom.Document owner, java.lang.String nsURI, java.lang.String elementName, java.lang.String textValue)
          Creates an Element object in the CyberSource namespace.
static org.w3c.dom.Element getElement(org.w3c.dom.Document owner, java.lang.String elementName, java.lang.String nsURI)
          Returns the Element object corresponding to the given element name.
static java.lang.String getElementText(org.w3c.dom.Document owner, java.lang.String elementName, java.lang.String nsURI)
          Returns the text value of the given element name in the CyberSource namespace.
static java.lang.String getStackTrace(java.lang.Exception e)
          Returns the stack trace of the supplied Exception object.
static java.lang.String mapToString(java.util.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 javax.xml.parsers.DocumentBuilder newDocumentBuilder()
          Returns a DocumentBuilder object.
static java.lang.String nodeToString(org.w3c.dom.Node node)
          Returns the string representation of the given Node object.
static java.lang.String nodeToString(org.w3c.dom.Node node, int type)
          Returns the string representation of the given Node object.
static byte[] read(java.io.File file)
          Reads the content of the given file into a byte array.
static byte[] read(java.io.InputStream in)
          Reads the content of the given file into a byte array.
static byte[] read(java.lang.String filename)
          Reads the content of the given file into a byte array.
static java.util.Properties readProperties(java.lang.String[] commandLineArgs)
          Reads the properties from a file.
static org.w3c.dom.Document readRequest(java.util.Properties props, java.lang.String filename)
          Read the request xml file
static java.util.HashMap stringToMap(java.lang.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 java.lang.String VERSION
Version number of this release.

See Also:
Constant Field Values

ENVIRONMENT

public static final java.lang.String ENVIRONMENT
Environment information.

Method Detail

nodeToString

public static java.lang.String nodeToString(org.w3c.dom.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 java.lang.String nodeToString(org.w3c.dom.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 java.util.Properties readProperties(java.lang.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(java.lang.String filename)
                   throws java.io.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:
java.io.IOException - if there was an error reading the file.

read

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

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

read

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

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

newDocumentBuilder

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

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

getElement

public static org.w3c.dom.Element getElement(org.w3c.dom.Document owner,
                                             java.lang.String elementName,
                                             java.lang.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 java.lang.String getElementText(org.w3c.dom.Document owner,
                                              java.lang.String elementName,
                                              java.lang.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 java.lang.String getStackTrace(java.lang.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 java.util.HashMap stringToMap(java.lang.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 java.lang.String mapToString(java.util.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 org.w3c.dom.Document readRequest(java.util.Properties props,
                                               java.lang.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 org.w3c.dom.Element createElement(org.w3c.dom.Document owner,
                                                java.lang.String nsURI,
                                                java.lang.String elementName,
                                                java.lang.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 © 2017. All Rights Reserved.