public class IstiXmlUtils extends ErrorMessageMgr
| Modifier and Type | Field and Description | 
|---|---|
static java.lang.String | 
ISO_8859_1_ENCODING_FORMAT
ISO-8859-1 encoding. 
 | 
protected boolean | 
loadFileOpenedFlag
Flag set true if file opened successfully by 'loadFile()' method. 
 | 
protected Element | 
rootElement
Root element in file. 
 | 
static boolean | 
useDocumentFlag
Use document flag. 
 | 
static java.lang.String | 
UTF_8_ENCODING_FORMAT
UTF-8 encoding. 
 | 
static java.lang.String | 
XML_FILE_EXTENSION
XML file extension. 
 | 
static java.lang.String | 
XML_STYLESHEET
XML stylesheet text. 
 | 
static java.lang.String | 
XML_STYLESHEET_PROCESSING_INSTRUCTION
XML stylesheet processing text. 
 | 
static SAXBuilder | 
xmlBuilderObj
Static JDOM XML Document builder object (without validation). 
 | 
static XMLOutputter | 
xmlFileOutputterObj
Static JDOM XML text output formatter object (for file output). 
 | 
static XMLOutputter | 
xmlFixedStrOutputterObj
Static text output formatter object (for "fixed" string output). 
 | 
static XMLOutputter | 
xmlStrOutputterObj
Static JDOM XML text output formatter object (for string output). 
 | 
| Constructor and Description | 
|---|
IstiXmlUtils()
Constructs a XML utilities object. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
static java.lang.String | 
addXmlFileExtension(java.lang.String fileName)
Adds the ".xml" file extension to a file name. 
 | 
void | 
clearErrorMessage()
Clears the error message string. 
 | 
static java.lang.String | 
convertFromEscapedCodes(java.lang.String srcStr,
                       int maxEscVal)
Converts "#;" escape strings in the given data to characters. 
 | 
static CDATA | 
createCdata(java.lang.String text)
Create the CDATA (Unparsed) Character Data. 
 | 
Element | 
createRootElement(java.lang.String name)
Creates the root element with the specified name. 
 | 
static java.lang.String | 
ctrlCharsFromEscapedCodes(java.lang.String srcStr)
Converts "#;" escape strings in the given data to control
 characters. 
 | 
static java.lang.String | 
ctrlCharsToEscapedCodes(java.lang.String srcStr)
Converts control characters and characters greater than 127 in the
 given data to "#;" escape strings. 
 | 
static boolean | 
ctrlCharsToEscapedCodes(java.lang.StringBuffer buff)
Converts control characters and characters greater than 127 in the
 given data to "#;" escape strings. 
 | 
static java.lang.String | 
elementToFixedString(Element xmlMsgObj)
Converts a JDOM 'Element' object to an XML-format string. 
 | 
static java.lang.String | 
elementToString(Element xmlMsgObj)
Converts a JDOM 'Element' object to an XML-format string. 
 | 
static java.lang.String | 
elementToString(Element xmlMsgObj,
               boolean normalizeFlag)
Converts a JDOM 'Element' object to an XML-format string. 
 | 
protected Element | 
findElement(java.lang.String attribute,
           java.lang.String value)
Finds the element with the specified attribute value. 
 | 
protected Element | 
findElement(java.lang.String attribute,
           java.lang.String value,
           Element element)
Finds the element with the specified attribute value. 
 | 
static Element | 
getAnyNSChild(Element parentElem,
             java.lang.String childNameStr)
Returns the first child element within the given element with the
 given local name (regardless of namespace). 
 | 
static java.lang.String | 
getChildDataFixedStr(Element parentElementObj)
Converts all the child elements of the given element to strings
 and returns the concatenation of all the strings. 
 | 
static java.lang.String | 
getChildDataStr(Element parentElementObj)
Converts all the child elements of the given element to strings
 and returns the concatenation of all the strings. 
 | 
static java.lang.String | 
getChildDataStr(Element parentElementObj,
               boolean normalizeFlag)
Converts all the child elements of the given element to strings
 and returns the concatenation of all the strings. 
 | 
protected static java.lang.String | 
getChildDataStr(Element parentElementObj,
               boolean normalizeFlag,
               boolean fixStrFlag)
Converts all the child elements of the given element to strings
 and returns the concatenation of all the strings. 
 | 
protected java.lang.Object | 
getComponentForClass(java.lang.String className)
Creates a new instance of the class represented by the class or
 interface with the given string name. 
 | 
static java.lang.String | 
getEncodedString(java.lang.String s,
                java.lang.String encoding)
Gets the encoded string. 
 | 
boolean | 
getErrorFlag()
Returns true if an error was detected. 
 | 
java.lang.String | 
getErrorMessage()
Returns message string for last error (or 'No error' if none). 
 | 
boolean | 
getLoadFileOpenedFlag()
Returns the flag indicator of whether or not the XML file was
 successfully opened in the last call to 'loadFile()'. 
 | 
Element | 
getRootElement()
Gets the root element that was loaded. 
 | 
boolean | 
loadFile(java.lang.String fileName,
        java.lang.String rootElementName)
Loads an XML file. 
 | 
boolean | 
loadFile(java.lang.String fileName,
        java.lang.String rootElementName,
        java.util.Properties urlRequestProps)
Loads an XML file. 
 | 
boolean | 
loadStream(java.io.InputStream stmObj,
          java.lang.String rootElementName)
Loads an XML data from an input stream. 
 | 
boolean | 
loadStream(java.io.InputStream stmObj,
          java.lang.String rootElementName,
          java.lang.String fileName)
Loads an XML data from an input stream. 
 | 
boolean | 
loadStream(java.io.Reader rdrObj,
          java.lang.String rootElementName)
Loads an XML data from an input stream. 
 | 
boolean | 
loadStream(java.io.Reader rdrObj,
          java.lang.String rootElementName,
          java.lang.String fileName)
Loads an XML data from an input stream. 
 | 
boolean | 
saveToFile(java.lang.String fileName)
Saves the "root" element loaded via 'loadFile()' to a file. 
 | 
boolean | 
saveToFile(java.lang.String fileName,
          Element elemObj)
Saves an element to a file. 
 | 
static void | 
saveToStream(java.io.OutputStream stmObj,
            Element elemObj)
Saves an element to a stream. 
 | 
static void | 
saveToStream(java.io.Writer wtrObj,
            Element elemObj)
Saves an element to a stream. 
 | 
static void | 
setDocumentStylesheet(Document documentObj,
                     java.lang.String uri)
Sets the Document stylesheet. 
 | 
static void | 
setElementNamespace(Element elementObj,
                   Namespace namespaceObj)
Sets the element namespace. 
 | 
static void | 
setElementNamespace(Element elementObj,
                   java.lang.String prefix,
                   java.lang.String uri)
Sets the element namespace. 
 | 
protected void | 
setErrorMessage(java.lang.String str)
Enters an error message (if none previously entered). 
 | 
static void | 
setFileLineSeparator(java.lang.String lineSeparator)
This will set the newline separator ( 
lineSeparator). | 
static void | 
setFileOmitDeclaration(boolean flgVal)
Sets whether the XML declaration will be omitted while outputting to files. 
 | 
static void | 
setFileOmitEncoding(boolean flgVal)
Sets whether the document encoding will be omitted while outputting to files. 
 | 
static void | 
setFileOutExpandEmptyElements(boolean flgVal)
Sets whether empty elements are expanded from
  
<tagName/> to
 <tagName></tagName>
 while outputting to files. | 
static void | 
setFileOutIndent(java.lang.String indentStr)
Sets the indent  
String to use while outputting to files. | 
static void | 
setFileOutNewlines(boolean flgVal)
Sets whether newlines should be added while outputting to files. 
 | 
static void | 
setFileOutTextTrim(boolean flgVal)
Sets whether the text has leading/trailing whitespace trimmed while
 outputting to files. 
 | 
static void | 
setLoadExternalDTDFeature(boolean flgVal)
Sets the state of the load-external-DTD feature on the SAX parser. 
 | 
void | 
setRootElement(Element elemObj)
Sets the root element. 
 | 
static void | 
setStrOutExpandEmptyElements(boolean flgVal)
Sets whether empty elements are expanded from
  
<tagName/> to
 <tagName></tagName>
 while outputting to strings. | 
static void | 
setStrOutIndent(java.lang.String indentStr)
Sets the indent  
String to use while outputting to strings. | 
static void | 
setStrOutNewlines(boolean flgVal)
Sets whether newlines should be added while outputting to strings. 
 | 
static void | 
setStrOutTextTrim(boolean flgVal)
Sets whether the text has leading/trailing whitespace trimmed while
 outputting to strings. 
 | 
static void | 
setTrimAllWhite(boolean flgVal)
Sets whether the whitespace between elements will be trimmed or not. 
 | 
static Element | 
stringToElement(java.lang.String xmlStr)
Converts an XML-format string to a JDOM 'Element' object. 
 | 
clearErrorMessageString, clearFetchedErrorMessage, enterErrorMessageString, getErrorMessageFlag, getErrorMessageString, getUnfetchedMessageFlag, setErrorMessageStringpublic static boolean useDocumentFlag
protected boolean loadFileOpenedFlag
protected Element rootElement
public static final java.lang.String XML_STYLESHEET
public static final java.lang.String XML_STYLESHEET_PROCESSING_INSTRUCTION
public static final java.lang.String XML_FILE_EXTENSION
public static final SAXBuilder xmlBuilderObj
public static final XMLOutputter xmlStrOutputterObj
public static final XMLOutputter xmlFileOutputterObj
public static final XMLOutputter xmlFixedStrOutputterObj
public static final java.lang.String UTF_8_ENCODING_FORMAT
public static final java.lang.String ISO_8859_1_ENCODING_FORMAT
public static void setTrimAllWhite(boolean flgVal)
flgVal - true to trim, false otherwise.public static void setDocumentStylesheet(Document documentObj,
                                         java.lang.String uri)
documentObj - the 'Document' object.uri - String URI of the stylesheet.public static void setFileOmitDeclaration(boolean flgVal)
flgVal - true to omit the XML declaration.public static void setFileOmitEncoding(boolean flgVal)
flgVal - true to omit the document encoding.public static void setFileOutNewlines(boolean flgVal)
flgVal - true indicates new lines should be
 added for beautification.public static void setFileOutIndent(java.lang.String indentStr)
String to use while outputting to files.
 This is usually a String of empty spaces. If you pass
 null, or the empty string (""), then no indentation will
 happen.  Default: none (null)indentStr - String to use for indentation.public static void setFileOutTextTrim(boolean flgVal)
flgVal - true to trim the leading/trailing whitespace,
 false to use text verbatim.public static void setElementNamespace(Element elementObj,
                                       java.lang.String prefix,
                                       java.lang.String uri)
elementObj - the 'Element' object.prefix - String prefix to map to
               Namespace.uri - String URI of new Namespace.public static void setElementNamespace(Element elementObj,
                                       Namespace namespaceObj)
elementObj - the 'Element' object.namespaceObj - the 'Namespace' object.public static void setFileLineSeparator(java.lang.String lineSeparator)
lineSeparator).
 The default is \r\n. Note that if the "newlines"
 property is false, this value is irrelevant.lineSeparator - String line separator to use or
 null for the system default.setFileOutNewlinespublic static void setFileOutExpandEmptyElements(boolean flgVal)
<tagName/> to
 <tagName></tagName>
 while outputting to files.  Default: falseflgVal - true to expand elements.public static void setStrOutNewlines(boolean flgVal)
flgVal - true indicates new lines should be
 added for beautification.public static void setStrOutIndent(java.lang.String indentStr)
String to use while outputting to strings.
 This is usually a String of empty spaces. If you pass
 null, or the empty string (""), then no indentation will
 happen.  Default: none (null)indentStr - String to use for indentation.public static void setStrOutTextTrim(boolean flgVal)
flgVal - true to trim the leading/trailing whitespace,
 false to use text verbatim.public static void setStrOutExpandEmptyElements(boolean flgVal)
<tagName/> to
 <tagName></tagName>
 while outputting to strings.  Default: falseflgVal - true to expand elements.public static void setLoadExternalDTDFeature(boolean flgVal)
flgVal - true to enable to loading of external DTD files; false
 to disable to loading of external DTD files.public static java.lang.String addXmlFileExtension(java.lang.String fileName)
fileName - the file name to use.protected java.lang.Object getComponentForClass(java.lang.String className)
new expression with an empty argument list.  The class
 is initialized if it has not already been initialized.className - the fully qualified name of the desired class.protected Element findElement(java.lang.String attribute,
                              java.lang.String value)
attribute - the attribute of the element to find.value - the attribute value of the element to find.protected Element findElement(java.lang.String attribute,
                              java.lang.String value,
                              Element element)
attribute - the attribute of the element to find.value - the attribute value of the element to find.element - the element to start with.public static CDATA createCdata(java.lang.String text)
text - content of CDATA.public Element getRootElement()
public void setRootElement(Element elemObj)
elemObj - the element object to use.createRootElementpublic boolean loadFile(java.lang.String fileName,
                        java.lang.String rootElementName)
fileName - the name of the XML file to load.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.public boolean loadFile(java.lang.String fileName,
                        java.lang.String rootElementName,
                        java.util.Properties urlRequestProps)
fileName - the name of the XML file to load.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.urlRequestProps - the request properties to use for URL connections
                     or null if none.public boolean getLoadFileOpenedFlag()
public boolean loadStream(java.io.Reader rdrObj,
                          java.lang.String rootElementName,
                          java.lang.String fileName)
rdrObj - input stream to use.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.fileName - filename string to use for error messages, or null
 for no filename.public boolean loadStream(java.io.Reader rdrObj,
                          java.lang.String rootElementName)
rdrObj - input stream to use.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.public boolean loadStream(java.io.InputStream stmObj,
                          java.lang.String rootElementName,
                          java.lang.String fileName)
stmObj - input stream to use.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.fileName - filename string to use for error messages, or null
 for no filename.public boolean loadStream(java.io.InputStream stmObj,
                          java.lang.String rootElementName)
stmObj - input stream to use.rootElementName - the expected name of the root element in the
 XML file, or null to accept any name.public boolean saveToFile(java.lang.String fileName,
                          Element elemObj)
fileName - the name of the file to use.elemObj - element object to be saved.public boolean saveToFile(java.lang.String fileName)
fileName - the name of the file to use.public boolean getErrorFlag()
public java.lang.String getErrorMessage()
public void clearErrorMessage()
public Element createRootElement(java.lang.String name)
name - String name of element.protected void setErrorMessage(java.lang.String str)
str - the error message.public static java.lang.String elementToString(Element xmlMsgObj,
                                               boolean normalizeFlag)
                                        throws java.io.IOException
xmlMsgObj - the JDOM 'Element' object to use.normalizeFlag - if true then the returned string is normalized
 by removing CR/LF characters (all surrounding whitespace is
 removed and internal whitespace is changed to a single space).java.io.IOException - if an error occurs while converting.public static java.lang.String elementToString(Element xmlMsgObj)
                                        throws java.io.IOException
xmlMsgObj - the JDOM 'Element' object to use.java.io.IOException - if an error occurs while converting.public static java.lang.String elementToFixedString(Element xmlMsgObj)
                                             throws java.io.IOException
xmlMsgObj - the JDOM 'Element' object to use.java.io.IOException - if an error occurs while converting.public static Element stringToElement(java.lang.String xmlStr)
                               throws JDOMException
xmlStr - the XML-format string to use.JDOMException - if an error occurs while parsing.public static void saveToStream(java.io.Writer wtrObj,
                                Element elemObj)
                         throws java.io.IOException
wtrObj - output stream to use.elemObj - element object to be saved.java.io.IOException - if an error occurs.public static void saveToStream(java.io.OutputStream stmObj,
                                Element elemObj)
                         throws java.io.IOException
stmObj - output stream to use.elemObj - element object to be saved.java.io.IOException - if an error occurs.protected static java.lang.String getChildDataStr(Element parentElementObj,
                                                  boolean normalizeFlag,
                                                  boolean fixStrFlag)
parentElementObj - the element object to use.normalizeFlag - if true then the returned string is normalized
 by removing CR/LF characters (all surrounding whitespace is
 removed and internal whitespace is changed to a single space).fixStrFlag - true to "fix" string data (whitespace between
 elements removed and control characters within elements encoded
 to "#;" strings); false to normalize string data.public static java.lang.String getChildDataStr(Element parentElementObj,
                                               boolean normalizeFlag)
parentElementObj - the element object to use.normalizeFlag - if true then the returned string is normalized
 by removing CR/LF characters (all surrounding whitespace is
 removed and internal whitespace is changed to a single space).public static java.lang.String getChildDataStr(Element parentElementObj)
parentElementObj - the element object to use.public static java.lang.String getChildDataFixedStr(Element parentElementObj)
parentElementObj - the element object to use.public static Element getAnyNSChild(Element parentElem,
                                    java.lang.String childNameStr)
parentElem - element containing the child element.childNameStr - name of child element to match, or null to
 match the first child element found.public static java.lang.String getEncodedString(java.lang.String s,
                                                java.lang.String encoding)
s - the string to encode.encoding - set encoding format.  Use XML-style names like
                 "UTF-8" or "ISO-8859-1" or "US-ASCII"public static boolean ctrlCharsToEscapedCodes(java.lang.StringBuffer buff)
buff - data buffer to be read and modified.public static java.lang.String ctrlCharsToEscapedCodes(java.lang.String srcStr)
srcStr - source string for data.public static java.lang.String convertFromEscapedCodes(java.lang.String srcStr,
                                                       int maxEscVal)
srcStr - source string for data.maxEscVal - maximum value for "#;" codes, or 0 for no maximum.public static java.lang.String ctrlCharsFromEscapedCodes(java.lang.String srcStr)
srcStr - source string for data.