edu.sdsc.inca.util
Class XmlWrapper

java.lang.Object
  extended by edu.sdsc.inca.util.XmlWrapper
Direct Known Subclasses:
ResourcesWrapper, SuiteStagesWrapper, SuiteWrapper

public abstract class XmlWrapper
extends java.lang.Object

We provide a set of Wrapper classes which provide convenience methods for dealing with XML Bean classes generated from our Inca XML schemas. This class serves as the base class for these Wrapper classes

Author:
Shava Smallen <ssmallen@sdsc.edu>

Field Summary
protected static java.lang.String CDATA_PATTERN
           
protected static java.lang.String ELEMENT_CLOSE_PATTERN
           
protected static java.util.regex.Pattern PASSWORD_MACRO_VALUE_PATTERN
           
protected static java.lang.String PROCESSING_INSTRUCTION_PATTERN
           
protected static java.lang.String XML_COMMENT_PATTERN
           
protected static java.lang.String XML_NAME_PATTERN
           
protected static java.util.regex.Pattern XML_NODE_PATTERN
           
 
Constructor Summary
XmlWrapper()
           
 
Method Summary
static boolean configEqual(edu.sdsc.inca.dataModel.util.SeriesConfig config1, edu.sdsc.inca.dataModel.util.SeriesConfig config2)
          Return true if the given report series configs are equivalent.
static java.lang.String cryptSensitive(java.lang.String sensitiveText, java.lang.String passphrase, boolean decrypt)
          Decrypt/encrypt the values of name/value pairs where the name is a password/passphrase in the provided string.
static java.lang.String escape(java.lang.String unescaped)
          Escape illegal XML characters in a string.
static org.apache.xmlbeans.XmlOptions getPrettyPrintOptions()
          Return the standard printing options for XML documents.
static void main(java.lang.String[] args)
          Provides a command line client to encrypt/decrypt Inca XML files
static java.lang.String prettyPrint(java.lang.String xml, java.lang.String indent)
          Returns a copy of a specified XML document with added spacing and newlines to make it more readable.
static java.lang.String read(java.lang.String filePath, java.lang.String passphrase)
          Read in a XML file from disk and decrypt any passwords/passphrases contained in it.
static void save(java.lang.String xmlText, java.lang.String filePath, java.lang.String passphrase)
           
static java.lang.String unescape(java.lang.String escaped)
          Unescape escaped XML characters in a string.
protected static void validate(org.apache.xmlbeans.XmlObject xml)
          Validate the XML document and throw and XmlException if parsing fails.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSWORD_MACRO_VALUE_PATTERN

protected static java.util.regex.Pattern PASSWORD_MACRO_VALUE_PATTERN

XML_NAME_PATTERN

protected static java.lang.String XML_NAME_PATTERN

CDATA_PATTERN

protected static java.lang.String CDATA_PATTERN

ELEMENT_CLOSE_PATTERN

protected static java.lang.String ELEMENT_CLOSE_PATTERN

PROCESSING_INSTRUCTION_PATTERN

protected static java.lang.String PROCESSING_INSTRUCTION_PATTERN

XML_COMMENT_PATTERN

protected static java.lang.String XML_COMMENT_PATTERN

XML_NODE_PATTERN

protected static java.util.regex.Pattern XML_NODE_PATTERN
Constructor Detail

XmlWrapper

public XmlWrapper()
Method Detail

configEqual

public static boolean configEqual(edu.sdsc.inca.dataModel.util.SeriesConfig config1,
                                  edu.sdsc.inca.dataModel.util.SeriesConfig config2)
Return true if the given report series configs are equivalent. Two report series configs are equivalent if all their fields match with the exception of the <schedule> element if and only if the <scheduleSpec> element is present. The <scheduleSpec> element holds the schedule specified by the user (which may contain '?') and the <schedule> element holds the schedule selected by the agent. Note, that I could not find any equivalency function in xmlbeans so I convert both configs to string, strip off the outer <xml-fragment> tags and then compare the strings.

Parameters:
config1 - A series config describing how to run a reporter on a set of resources.
config2 - A series config describing how to run a reporter on a set of resources.
Returns:
True if the reporter set configs are equivalent and false otherwise.

cryptSensitive

public static java.lang.String cryptSensitive(java.lang.String sensitiveText,
                                              java.lang.String passphrase,
                                              boolean decrypt)
                                       throws CrypterException
Decrypt/encrypt the values of name/value pairs where the name is a password/passphrase in the provided string.

Parameters:
sensitiveText - A string possibly containing name/value password/passphrase pairs that needed to be encrypted/decrypted
passphrase - A string that can be used to decrypt/encrypt passwords/passphrases
decrypt - A value of true will attempt to decrypt the sensitive text while a value of false will attempt to encrypt the sensitive text.
Returns:
the encrypted/decrypted version of sensitiveText.
Throws:
CrypterException

escape

public static java.lang.String escape(java.lang.String unescaped)
Escape illegal XML characters in a string. The following characters are illegal in XML: < less than > greater than & ampersand ' apostrophe " quotation mark

Parameters:
unescaped - A string possibly containing illegal XML characters
Returns:
A properly escaped XML string.

read

public static java.lang.String read(java.lang.String filePath,
                                    java.lang.String passphrase)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException,
                                    CrypterException
Read in a XML file from disk and decrypt any passwords/passphrases contained in it.

Parameters:
filePath - A string containing a path to the xml file.
passphrase - A string containing the passphrase to use to decrypt the passwords.
Returns:
The contents of the XML file as a string.
Throws:
java.io.FileNotFoundException
java.io.IOException
CrypterException

save

public static void save(java.lang.String xmlText,
                        java.lang.String filePath,
                        java.lang.String passphrase)
                 throws CrypterException,
                        java.io.IOException
Throws:
CrypterException
java.io.IOException

unescape

public static java.lang.String unescape(java.lang.String escaped)
Unescape escaped XML characters in a string. The following characters need to be unescaped: < less than > greater than & ampersand ' apostrophe " quotation mark

Parameters:
escaped - A string possibly containing escaped XML characters
Returns:
A unescaped string.

validate

protected static void validate(org.apache.xmlbeans.XmlObject xml)
                        throws org.apache.xmlbeans.XmlException
Validate the XML document and throw and XmlException if parsing fails.

Throws:
org.apache.xmlbeans.XmlException

getPrettyPrintOptions

public static org.apache.xmlbeans.XmlOptions getPrettyPrintOptions()
Return the standard printing options for XML documents.

Returns:
An XmlOPtions object with pretty printing set.

prettyPrint

public static java.lang.String prettyPrint(java.lang.String xml,
                                           java.lang.String indent)
Returns a copy of a specified XML document with added spacing and newlines to make it more readable. Does not handle DOCTYPE, ENTITY, or NOTATION markup or mixed content.

Parameters:
xml - the XML document
indent - the text to use to indicate nesting levels; typically some number of spaces
Returns:
the specified text with inserted newlines and indentation

main

public static void main(java.lang.String[] args)
Provides a command line client to encrypt/decrypt Inca XML files

Parameters:
args -