|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.uima.pear.util.XMLUtil
public class XMLUtil
The XMLUtil
class provides miscellaneous XML utilities.
Field Summary | |
---|---|
static java.lang.String |
CDATA_SECTION_BEG
|
static java.lang.String |
CDATA_SECTION_END
|
protected static boolean |
DEFAULT_DYNAMIC_VALIDATION
|
protected static boolean |
DEFAULT_NAMESPACE_PREFIXES
|
protected static boolean |
DEFAULT_NAMESPACES
|
protected static boolean |
DEFAULT_SCHEMA_FULL_CHECKING
|
protected static boolean |
DEFAULT_SCHEMA_VALIDATION
|
protected static boolean |
DEFAULT_VALIDATION
|
static java.lang.String |
DYNAMIC_VALIDATION_FEATURE_ID
|
protected static java.lang.String |
FIRST_XML_CHARS
|
static java.lang.String |
NAMESPACE_PREFIXES_FEATURE_ID
|
static java.lang.String |
NAMESPACES_FEATURE_ID
XML parser feature ids |
static java.lang.String |
SCHEMA_FULL_CHECKING_FEATURE_ID
|
static java.lang.String |
SCHEMA_VALIDATION_FEATURE_ID
|
static java.lang.String |
VALIDATION_FEATURE_ID
|
static java.lang.String |
XML_ENCODING_TAG
|
static java.lang.String |
XML_HEADER_BEG
|
static java.lang.String |
XML_HEADER_END
|
Constructor Summary | |
---|---|
XMLUtil()
XMLUtil constructor comment. |
Method Summary | |
---|---|
static javax.xml.parsers.SAXParser |
createSAXParser()
Gets new instance of the SAXParser class and sets standard features. |
static java.lang.String |
detectXmlFileEncoding(java.io.File xmlFile)
Attempts to detect file encoding of a given XML file by analyzing it's first characters. |
static boolean |
isValidXmlFile(java.io.File xmlFile)
Tries to parse a given XML file using SAX parser. |
static void |
printAllXMLElements(java.util.Properties elements,
java.io.PrintWriter oWriter,
int level)
Prints entries of a given Properties object as XML elements to a given
PrintWriter , maintaining a given indentation level. |
static void |
printAllXMLElements(java.util.Properties elements,
java.lang.String[] tagOrder,
java.io.PrintWriter oWriter,
int level)
Prints entries of a given Properties object as XML elements to a given
PrintWriter , maintaining a specified tag order and a given indentation level. |
static void |
printAllXMLElements(java.util.Properties elements,
java.lang.String valueDelimiter,
java.lang.String[] tagOrder,
java.io.PrintWriter oWriter,
int level)
Prints entries of a given Properties object as XML elements to a given
PrintWriter , maintaining a specified tag order and a given indentation level. |
static void |
printError(java.lang.String type,
org.xml.sax.SAXParseException ex)
Prints SAX error message. |
static void |
printXMLElement(java.lang.String tag,
java.util.Properties attributes,
java.io.PrintWriter oWriter,
int level)
Prints a given XML element, which contains only given attributes, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElement(java.lang.String tag,
java.util.Properties attributes,
java.lang.String elemValue,
boolean putInCdataSection,
java.io.PrintWriter oWriter,
int level)
Prints a given XML element, which contains given attributes and a given string value, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElement(java.lang.String tag,
java.util.Properties attributes,
java.lang.String elemValue,
boolean putInCdataSection,
java.io.PrintWriter oWriter,
int level,
boolean useNewLine4Value)
Prints a given XML element, which contains given attributes and a given string value, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElement(java.lang.String tag,
java.util.Properties attributes,
java.lang.String elemValue,
java.io.PrintWriter oWriter,
int level)
Prints a given XML element, which contains given attributes and a given string value, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElement(java.lang.String tag,
java.lang.String elemValue,
boolean putInCdataSection,
java.io.PrintWriter oWriter,
int level)
Prints a given XML element, which contains only a given string value, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElement(java.lang.String tag,
java.lang.String elemValue,
java.io.PrintWriter oWriter,
int level)
Prints a given XML element, which contains only a given string value, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElements(java.lang.String tag,
java.lang.String elemValue,
java.lang.String valueDelimiter,
java.io.PrintWriter oWriter,
int level)
Prints multiple values of a given XML element, separated with a specified delimiter, to a given PrintWriter , maintaining a given indentation level. |
static void |
printXMLElementValue(java.lang.String elemValue,
boolean putInCdataSection,
java.io.PrintWriter oWriter,
int level)
Prints a given element value to a given PrintWriter , maintaining a given
indentation level. |
static void |
printXMLElementValue(java.lang.String elemValue,
java.io.PrintWriter oWriter,
int level)
Prints a given element value to a given PrintWriter , maintaining a given
indentation level. |
static void |
printXMLHeader(java.lang.String encoding,
java.io.PrintWriter oWriter)
Prints standard XML 1.0 header with a specified encoding to a given PrintStream . |
static void |
printXMLTag(java.lang.String tag,
java.io.PrintWriter oWriter,
boolean tagEnd,
int level)
Prints a given XML tag to a given PrintWriter , maintaining a given indentation
level. |
static void |
printXMLTag(java.lang.String tag,
java.util.Properties attributes,
java.io.PrintWriter oWriter,
boolean tagEnd,
int level)
Prints a given XML tag with given element attributes to a given PrintWriter ,
maintaining a given indentation level. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_HEADER_BEG
public static final java.lang.String XML_ENCODING_TAG
public static final java.lang.String XML_HEADER_END
public static final java.lang.String CDATA_SECTION_BEG
public static final java.lang.String CDATA_SECTION_END
public static final java.lang.String NAMESPACES_FEATURE_ID
public static final java.lang.String NAMESPACE_PREFIXES_FEATURE_ID
public static final java.lang.String VALIDATION_FEATURE_ID
public static final java.lang.String SCHEMA_VALIDATION_FEATURE_ID
public static final java.lang.String SCHEMA_FULL_CHECKING_FEATURE_ID
public static final java.lang.String DYNAMIC_VALIDATION_FEATURE_ID
protected static final boolean DEFAULT_NAMESPACES
protected static final boolean DEFAULT_NAMESPACE_PREFIXES
protected static final boolean DEFAULT_VALIDATION
protected static final boolean DEFAULT_SCHEMA_VALIDATION
protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING
protected static final boolean DEFAULT_DYNAMIC_VALIDATION
protected static final java.lang.String FIRST_XML_CHARS
Constructor Detail |
---|
public XMLUtil()
Method Detail |
---|
public static javax.xml.parsers.SAXParser createSAXParser() throws org.xml.sax.SAXException
SAXParser
class and sets standard features.
SAXParser
class.
org.xml.sax.SAXException
- if any parser exception occurred.public static java.lang.String detectXmlFileEncoding(java.io.File xmlFile) throws java.io.IOException
null
, otherwise it returns the detected encoding name. For more on UTF
encodings and its signatures see FAQ - UTF and BOM.
xmlFile
- The given XML file.
null
, if the file encoding cannot be
recognized or the file is not a valid XML file.
java.io.IOException
- If the given file cannot be read.public static boolean isValidXmlFile(java.io.File xmlFile) throws java.io.IOException
true
, if the parser
does not encounter fatal error, otherwise returns false
.
xmlFile
- The given XML file to be tested.
true
, if the given XML file can be parsed, false
otherwise.
java.io.IOException
- If the given file cannot be read.public static void printError(java.lang.String type, org.xml.sax.SAXParseException ex)
public static void printAllXMLElements(java.util.Properties elements, java.io.PrintWriter oWriter, int level) throws java.io.IOException
Properties
object as XML elements to a given
PrintWriter
, maintaining a given indentation level.
elements
- The given Properties
object.oWriter
- The given PrintWriter
object.level
- The given indentation level.
java.io.IOException
- if any I/O exception occurred.public static void printAllXMLElements(java.util.Properties elements, java.lang.String valueDelimiter, java.lang.String[] tagOrder, java.io.PrintWriter oWriter, int level) throws java.io.IOException
Properties
object as XML elements to a given
PrintWriter
, maintaining a specified tag order and a given indentation level.
Some elements may contain multiple values delimited by a specified value delimiter. Inserts new
line after each printed element.
elements
- The given Properties
object.valueDelimiter
- The specified value delimiter for multi-valued elements.tagOrder
- The String
array that specifies the tag order.oWriter
- The given PrintWriter
object.level
- The given indentation level.
java.io.IOException
- if any I/O exception occurred.public static void printAllXMLElements(java.util.Properties elements, java.lang.String[] tagOrder, java.io.PrintWriter oWriter, int level) throws java.io.IOException
Properties
object as XML elements to a given
PrintWriter
, maintaining a specified tag order and a given indentation level.
elements
- The given Properties
object.tagOrder
- The String
array that specifies the tag order.oWriter
- The given PrintWriter
object.level
- The given indentation level.
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.util.Properties attributes, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level.
tag
- The given XML tag.attributes
- The given XML element attributes.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.util.Properties attributes, java.lang.String elemValue, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. The string element
value (if exists) is printed 'as is' - without a CDATA section.
tag
- The given XML element tag.attributes
- The given XML element attributes.elemValue
- The given XML element value.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.util.Properties attributes, java.lang.String elemValue, boolean putInCdataSection, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. The string element
value (if exists) is printed within or without the CDATA section, depending on a given
boolean
flag value.
tag
- The given XML element tag.attributes
- The given XML element tag.elemValue
- The given XML element value.putInCdataSection
- If true
, puts the element value in the CDATA
section,
otherwise prints the element value without the CDATA
section.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.util.Properties attributes, java.lang.String elemValue, boolean putInCdataSection, java.io.PrintWriter oWriter, int level, boolean useNewLine4Value) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. The string element
value (if exists) may be printed inside a CDATA section, depending on the value of a given
'CDATA' boolean
flag. The element value may be printed on the same line as the
element tags, or on a new line, depending on the value of a given 'new-line'
boolean
flag.
tag
- The given XML element tag.attributes
- The given XML element attributes.elemValue
- The given XML element value.putInCdataSection
- If true
, the given element value is printed inside the CDATA section,
otherwise it's printed 'as is'.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).useNewLine4Value
- If true
, the given element value is printed on a new line, otherwise
it's printed on the same line as the element tags.
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.lang.String elemValue, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. The string element value is
printed 'as-is' without the CDATA block.
tag
- The given XML tag.elemValue
- The given XML element value.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElement(java.lang.String tag, java.lang.String elemValue, boolean putInCdataSection, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. The string element value
(if exists) is put into the CDATA block, if a given boolean
flag is
true
.
tag
- The given XML tag.elemValue
- The given XML element value.putInCdataSection
- If true
, puts the element value in the CDATA
section,
otherwise prints the element value without the CDATA
section.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElements(java.lang.String tag, java.lang.String elemValue, java.lang.String valueDelimiter, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation level. Inserts new line after each
printed element value.
tag
- The given XML element tag.elemValue
- The given XML element values (multi-value), separated with the given delimiter.valueDelimiter
- The given delimiter for multi-value elements.oWriter
- The given PrintWriter
object.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLElementValue(java.lang.String elemValue, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given
indentation level. By default, prints the element value 'as is' - not using the
CDATA
section.
elemValue
- The given element value.oWriter
- The given PrintWriter
object.level
- The given indentation level.
java.io.IOException
- if any I/O exception occurred.public static void printXMLElementValue(java.lang.String elemValue, boolean putInCdataSection, java.io.PrintWriter oWriter, int level) throws java.io.IOException
PrintWriter
, maintaining a given
indentation level. If a given boolean
'CDATA' flag is true
, puts
the element value in the CDATA
section, otherwise prints the element value 'as
is'.
elemValue
- The given element value.putInCdataSection
- If true
, puts the element value in the CDATA
section,
otherwise prints the element value without the CDATA
section.oWriter
- The given PrintWriter
object.level
- The given indentation level.
java.io.IOException
- if any I/O exception occurred.public static void printXMLHeader(java.lang.String encoding, java.io.PrintWriter oWriter) throws java.io.IOException
PrintStream
.
If no encoding is specified (null
or empty string), does not include the
encoding name in the header.
encoding
- The given XML encoding name or null
.oWriter
- The given output PrintStream
.
java.io.IOException
- if any I/O exception occurred.public static void printXMLTag(java.lang.String tag, java.io.PrintWriter oWriter, boolean tagEnd, int level) throws java.io.IOException
PrintWriter
, maintaining a given indentation
level.
tag
- The given XML tag.oWriter
- The given PrintWriter
object.tagEnd
- If false
prints the XML tag beginning brackets, otherwise prints the
the XML tag ending brackets.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.public static void printXMLTag(java.lang.String tag, java.util.Properties attributes, java.io.PrintWriter oWriter, boolean tagEnd, int level) throws java.io.IOException
PrintWriter
,
maintaining a given indentation level.
tag
- The given XML tag.attributes
- The given XML element attributes.oWriter
- The given PrintWriter
object.tagEnd
- If false
prints the XML tag beginning brackets, otherwise prints the
the XML tag ending brackets.level
- The given indentation level (number of marginal '\t' symbols).
java.io.IOException
- if any I/O exception occurred.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |