Oracle Fusion Middleware
Java API Reference for Oracle PDK Java
11g Release 1 (11.1.1)
E10691-01

oracle.portal.utils.xml.v2
Class XMLUtil

java.lang.Object
  extended by oracle.portal.utils.xml.v2.XMLUtil

public class XMLUtil
extends java.lang.Object

Class containing utility methods for parsing and manipulating XML documents.


Constructor Summary
XMLUtil()
           
 
Method Summary
static oracle.xml.parser.v2.XMLDocument applyXSL(oracle.xml.parser.v2.XMLDocument xmldoc, oracle.xml.parser.v2.XSLStylesheet xsl, java.io.OutputStream errOut)
          Apply the given stylesheet to the given XML document, reporting errors and warnings to the given OutputStream.
static int compareVersions(java.lang.String version1, java.lang.String version2)
          Compare the given version number strings.
static java.lang.String escapeForXMLAttribute(java.lang.String text)
          Properly escapes text for inclusion as XML attribute value.
static java.lang.String escapeForXMLText(java.lang.String text)
          Properly escapes text for inclusion in as XML text.
static java.lang.String escapeXML(java.lang.String text, boolean isAttribute)
          General utility to escape text for inclusion in XML - i.e. escapes &, >, and < if regular XML text or escapes &, >, <, ', and " if an XML attribute value.
static java.lang.String escapeXML(java.lang.String text, boolean isAttribute, boolean ignorePredefinedEnties)
          General utility to escape text for inclusion in XML - i.e. escapes &, >, and < if regular XML text or escapes &, >, <, ', and " if an XML attribute value.
static java.lang.String escapeXMLAttribute(java.lang.String text)
          Deprecated. As of 9.0.5, use escapeForXMLAttribute to properly escape attribute values
static java.lang.String escapeXMLText(java.lang.String text)
          Deprecated. As of 9.0.5, use escapeForXMLText to properly escape XML text
static boolean getBooleanValue(java.lang.String value)
          Convert the given String encoding of a boolean value ("true" or "false") to a boolean.
static java.util.Iterator getStyleSheetPIs(oracle.xml.parser.v2.XMLDocument doc)
          Get an Iterator of ProcessingInstructions from the given XML document which have a target of "xml-stylesheet".
static java.util.Iterator getTargetPIs(oracle.xml.parser.v2.XMLDocument doc, java.lang.String targetName)
          Get an Iterator of ProcessingInstructions from the given XML document which have the specified target (for example, "xml-stylesheet").
static int getVersionMajor(java.lang.String version)
          Given a version number string, get the integer corresponding to the 'major version'.
static java.util.Iterator getXslDocs(oracle.xml.parser.v2.XMLDocument doc)
          Get an Iterator of XSLStylesheets referenced by processing instructions in the given XML document which have a target of "xml-stylesheet".
static oracle.xml.parser.v2.XMLDocument parseDocument(java.io.InputStream docInputStream, java.io.OutputStream errOut)
          Parse an XML document from the given InputStream, reporting errors and warnings to the given OutputStream.
static oracle.xml.parser.v2.XMLDocument parseDocument(java.io.Reader docReader, java.io.OutputStream errOut)
          Parse an XML document from the given Reader, reporting errors and warnings to the given OutputStream.
static oracle.xml.parser.v2.XMLDocument parseDocument(java.net.URL docURL, java.io.OutputStream errOut)
          Parse an XML document from the given URL, reporting errors and warnings to the given OutputStream.
static java.util.Map parsePI(org.w3c.dom.ProcessingInstruction pi)
          Given a ProcessingInstruction whose data contains attribute/value pairs, return a Map which contains the attributes as keys and their corresponding values as values.
static oracle.xml.parser.v2.XSLStylesheet parseStylesheet(java.net.URL docURL, java.io.OutputStream errOut)
          Parse an XSL stylesheet from the given URL, reporting errors and warnings to the given OutputStream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

parseDocument

public static oracle.xml.parser.v2.XMLDocument parseDocument(java.io.InputStream docInputStream,
                                                             java.io.OutputStream errOut)
                                                      throws java.io.IOException,
                                                             org.xml.sax.SAXException
Parse an XML document from the given InputStream, reporting errors and warnings to the given OutputStream.

Parameters:
docInputStream - InputStream from which the document should be read
errOut - OutputStream to which parsing errors and warnings should be reported
Throws:
java.io.IOException - if an I/O error occurs
org.xml.sax.SAXException - if a parsing error occurs

parseDocument

public static oracle.xml.parser.v2.XMLDocument parseDocument(java.io.Reader docReader,
                                                             java.io.OutputStream errOut)
                                                      throws java.io.IOException,
                                                             org.xml.sax.SAXException
Parse an XML document from the given Reader, reporting errors and warnings to the given OutputStream.

Parameters:
docReader - Reader from which the document should be read
errOut - OutputStream to which parsing errors and warnings should be reported
Throws:
java.io.IOException - if an I/O error occurs
org.xml.sax.SAXException - if a parsing error occurs

parseDocument

public static oracle.xml.parser.v2.XMLDocument parseDocument(java.net.URL docURL,
                                                             java.io.OutputStream errOut)
                                                      throws java.io.IOException,
                                                             org.xml.sax.SAXException
Parse an XML document from the given URL, reporting errors and warnings to the given OutputStream.

Parameters:
docURL - URL from which the document should be read
errOut - OutputStream to which parsing errors and warnings should be reported
Throws:
java.io.IOException - if an I/O error occurs
org.xml.sax.SAXException - if a parsing error occurs

parseStylesheet

public static oracle.xml.parser.v2.XSLStylesheet parseStylesheet(java.net.URL docURL,
                                                                 java.io.OutputStream errOut)
                                                          throws java.io.IOException,
                                                                 org.xml.sax.SAXException,
                                                                 oracle.xml.parser.v2.XSLException
Parse an XSL stylesheet from the given URL, reporting errors and warnings to the given OutputStream.

Parameters:
docURL - URL from which the stylesheet should be read
errOut - OutputStream to which parsing errors and warnings should be reported
Throws:
java.io.IOException - if an I/O error occurs
org.xml.sax.SAXException - if a parsing error occurs
oracle.xml.parser.v2.XSLException - if the document is not a valid stylesheet

applyXSL

public static oracle.xml.parser.v2.XMLDocument applyXSL(oracle.xml.parser.v2.XMLDocument xmldoc,
                                                        oracle.xml.parser.v2.XSLStylesheet xsl,
                                                        java.io.OutputStream errOut)
                                                 throws java.io.IOException,
                                                        oracle.xml.parser.v2.XSLException
Apply the given stylesheet to the given XML document, reporting errors and warnings to the given OutputStream.

Parameters:
xmldoc - a parsed XML document
xsl - a parsed XSL stylesheet
errOut - OutputStream to which stylesheet processing errors should be reported
Throws:
java.io.IOException
oracle.xml.parser.v2.XSLException

getTargetPIs

public static java.util.Iterator getTargetPIs(oracle.xml.parser.v2.XMLDocument doc,
                                              java.lang.String targetName)
Get an Iterator of ProcessingInstructions from the given XML document which have the specified target (for example, "xml-stylesheet").

Parameters:
doc - the XML document
targetName - the target of the processing instructions to be returned
Returns:
Iterator of ProcessingInstructions from the given XML document which have the specified target.

getStyleSheetPIs

public static java.util.Iterator getStyleSheetPIs(oracle.xml.parser.v2.XMLDocument doc)
Get an Iterator of ProcessingInstructions from the given XML document which have a target of "xml-stylesheet".

Parameters:
doc - the XML document
Returns:
Iterator of ProcessingInstructions from the given XML document which have a target of "xml-stylesheet".

getXslDocs

public static java.util.Iterator getXslDocs(oracle.xml.parser.v2.XMLDocument doc)
                                     throws java.io.IOException,
                                            org.xml.sax.SAXException,
                                            oracle.xml.parser.v2.XSLException
Get an Iterator of XSLStylesheets referenced by processing instructions in the given XML document which have a target of "xml-stylesheet".

Parameters:
doc - the XML document
Returns:
Iterator of XSLStylesheets referenced by processing instructions in the given XML document which have a target of "xml-stylesheet".
Throws:
java.io.IOException
org.xml.sax.SAXException
oracle.xml.parser.v2.XSLException

parsePI

public static java.util.Map parsePI(org.w3c.dom.ProcessingInstruction pi)
                             throws org.xml.sax.SAXException
Given a ProcessingInstruction whose data contains attribute/value pairs, return a Map which contains the attributes as keys and their corresponding values as values.

Parameters:
pi - a processing instruction
Returns:
Map mapping processing instruction attributes to values
Throws:
org.xml.sax.SAXException

getBooleanValue

public static boolean getBooleanValue(java.lang.String value)
Convert the given String encoding of a boolean value ("true" or "false") to a boolean.

Parameters:
value - String representation of a boolean value
Returns:
true if the string is not null and matches the string "true" in a case-insensitive comparison

getVersionMajor

public static int getVersionMajor(java.lang.String version)
Given a version number string, get the integer corresponding to the 'major version'. For example, calling this method on the string "3.2.1" would return the integer 3.

Parameters:
version - a version number string, e.g. "3.2.1"
Returns:
the integer 'major version' represented by the digits before the first '.' in the string
Throws:
java.lang.NumberFormatException - if the string does not contain a valid integer major version

compareVersions

public static int compareVersions(java.lang.String version1,
                                  java.lang.String version2)
Compare the given version number strings.

Parameters:
version1 - First version number string to compare. Should consist of decimal characters separated by dots, e.g. "3.2.1".
version2 - Second version number string to compare. Should consist of decimal characters separated by dots, e.g. "3.2.1".
Returns:
An integer indicating whether version1 is greater than, equal to, or less than version2: 1 if version1 is greater, 0 if it is equal to version2, and -1 if version1 is less than version2.

escapeXMLAttribute

public static java.lang.String escapeXMLAttribute(java.lang.String text)
Deprecated. As of 9.0.5, use escapeForXMLAttribute to properly escape attribute values

Escapes text for inclusion in as XML attribute value. I.e. escapes &, >, <, ', and ". Any references to the predefined XML entities (amp, lt, gt, apos, quot) are not escaped by this method. Use escapeForXMLAttribute(String) escapeForXMLAttribute} unless you are really sure you want this behaviour.

Parameters:
text - the String to escape
Returns:
the escaped text

escapeXMLText

public static java.lang.String escapeXMLText(java.lang.String text)
Deprecated. As of 9.0.5, use escapeForXMLText to properly escape XML text

Escapes text for inclusion in as XML text. I.e. escapes &, > and <. Any references to the predefined XML entities (amp, lt, gt, apos, quot) are not escaped by this method. Use escapeForXMLText unless you are really sure you want this behaviour.

Parameters:
text - the String to escape
Returns:
the escaped text

escapeForXMLAttribute

public static java.lang.String escapeForXMLAttribute(java.lang.String text)
Properly escapes text for inclusion as XML attribute value.

Parameters:
text - the String to escape
Returns:
the escaped text

escapeForXMLText

public static java.lang.String escapeForXMLText(java.lang.String text)
Properly escapes text for inclusion in as XML text.

Parameters:
text - the String to escape
Returns:
the escaped text

escapeXML

public static java.lang.String escapeXML(java.lang.String text,
                                         boolean isAttribute)
General utility to escape text for inclusion in XML - i.e. escapes &, >, and < if regular XML text or escapes &, >, <, ', and " if an XML attribute value. Any references to the predefined XML entities (amp, lt, gt, apos, quot) are not escaped by this method.

Parameters:
text - the String to escape
isAttribute - indicates if the text should be escaped for inclusion as an attributes value. If false then regular text is assumed.
Returns:
the escaped text

escapeXML

public static java.lang.String escapeXML(java.lang.String text,
                                         boolean isAttribute,
                                         boolean ignorePredefinedEnties)
General utility to escape text for inclusion in XML - i.e. escapes &, >, and < if regular XML text or escapes &, >, <, ', and " if an XML attribute value.

Parameters:
text - the String to escape
isAttribute - indicates if the text should be escaped for inclusion as an attributes value. If false then regular text is assumed.
ignorePredefinedEnties - flag indicating whether references to the predefined XML entities (amp, lt, gt, apos, quot) in the text should be ignored and not escaped
Returns:
the escaped text.

Oracle Fusion Middleware
Java API Reference for Oracle PDK Java
11g Release 1 (11.1.1)
E10691-01

Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.