com.softcorporation.xmllight
Class XMLLight

java.lang.Object
  |
  +--com.softcorporation.xmllight.XMLLight

public class XMLLight
extends java.lang.Object

XML Light Utilities.


Field Summary
static boolean debug
          Debug flag.
static java.lang.String XML_DEFINITION
           
 
Method Summary
static java.lang.String clearComments(java.lang.String doc)
          Removes the comments in XML document.
static java.lang.String decode(java.lang.String s)
          Decodes the entities in string.
static java.lang.String encode(java.lang.String value)
          Encodes (escapes) XML entities in string.
static java.lang.String encode(java.lang.String value, boolean canonical)
          Encodes (escapes) XML entities in string.
static int findClosingTag(java.lang.String doc, java.lang.String tag, int[] pos, boolean validate)
          Sets Element from input string representing XML Element with shift to the beginning of the element in the string.
static int findOpeningTag(java.lang.String doc, java.lang.String tag, int[] pos, boolean validate)
          Sets Element from input string representing XML Element with shift to the beginning of the element in the string.
static Element getElem(java.lang.String doc)
          Creates the XMLLight Element from the root element of XML document.
static Element getElem(java.lang.String doc, boolean validate)
          Creates the XMLLight Element from the root element of XML document.
static Element getElem(java.lang.String doc, int start, boolean validate)
          Creates XMLLight Element from XML document starting from position defined in pos[0].
static Element getElem(java.lang.String doc, java.lang.String elemName)
          Searches in XML Document for Element with name elemName and creates new XMLLight Element from XML document.
static Element getElem(java.lang.String doc, java.lang.String elemName, boolean validate)
          Searches in XML Document for Element with name elemName and creates new XMLLight Element from XML document.
static Element getElem(java.lang.String doc, java.lang.String tag, int start, boolean validate)
          Sets Element from input string representing XML Element with shift to the beginning of the element in the string.
static java.lang.String getXMLDocument(Element elem)
          Creates XML Document from XMLLight Element elem.
static java.lang.String replace(java.lang.String source, char chr, java.lang.String str)
          Replaces a character with string in source string.
static void setLogWriter(java.io.PrintStream output)
          Sets log output.
static int skipSpaces(java.lang.String doc, int start)
          Skips spaces
static void writeLog(java.lang.Exception ex)
          Prints log to the standard output (console) if debug = true.
static void writeLog(java.lang.String log)
          Prints log to the standard output (console) if debug = true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
Debug flag. If true: Debugging information goes to the standard output (console).


XML_DEFINITION

public static java.lang.String XML_DEFINITION
Method Detail

setLogWriter

public static void setLogWriter(java.io.PrintStream output)
Sets log output.

Parameters:
output - handles debug messages

writeLog

public static void writeLog(java.lang.String log)
Prints log to the standard output (console) if debug = true.

Parameters:
log - the debug message

writeLog

public static void writeLog(java.lang.Exception ex)
Prints log to the standard output (console) if debug = true.

Parameters:
ex - the Exception to log.

replace

public static java.lang.String replace(java.lang.String source,
                                       char chr,
                                       java.lang.String str)
Replaces a character with string in source string.

Parameters:
source - the source string
chr - the character
str - the string
Returns:
the string

encode

public static java.lang.String encode(java.lang.String value)
Encodes (escapes) XML entities in string.

Parameters:
value - the string
Returns:
the normilized string

encode

public static java.lang.String encode(java.lang.String value,
                                      boolean canonical)
Encodes (escapes) XML entities in string. The list of entities:
&lt; = <
&gt; = >
&apos; = '
&quot; = "
&amp; = &

Parameters:
value - the string to encode
canonical - if true then to normalize \n, \r
Returns:
the encoded string

decode

public static java.lang.String decode(java.lang.String s)
Decodes the entities in string. The list of entities:
&lt; = <
&gt; = >
&apos; = '
&quot; = "
&amp; = &

Returns:
decoded string

clearComments

public static java.lang.String clearComments(java.lang.String doc)
Removes the comments in XML document.

Returns:
clear from comments XML document

getXMLDocument

public static java.lang.String getXMLDocument(Element elem)
Creates XML Document from XMLLight Element elem.

Parameters:
elem - the XMLLight Element
Returns:
XML Document as a String

getElem

public static Element getElem(java.lang.String doc)
                       throws XMLLightException
Creates the XMLLight Element from the root element of XML document. If malformed XML found then returned Element errorCode equals 2.

Parameters:
doc - the XML document as a string
Returns:
XMLLight Element
XMLLightException

getElem

public static Element getElem(java.lang.String doc,
                              boolean validate)
                       throws XMLLightException
Creates the XMLLight Element from the root element of XML document. If malformed XML found then returned Element errorCode equals 2.

Parameters:
doc - the XML document as a string
Returns:
XMLLight Element
XMLLightException

getElem

public static Element getElem(java.lang.String doc,
                              int start,
                              boolean validate)
                       throws XMLLightException
Creates XMLLight Element from XML document starting from position defined in pos[0]. If malformed XML found then returned Element errorCode equals 2.

Parameters:
doc - the XML document as a string
Returns:
XMLLight Element
XMLLightException

getElem

public static Element getElem(java.lang.String doc,
                              java.lang.String elemName)
                       throws XMLLightException
Searches in XML Document for Element with name elemName and creates new XMLLight Element from XML document. If Element with elemName not found the value isEmply() of returned Element equals true. If error occured while parsing XML document the value errorCode of returned Element > 0.

Parameters:
doc - the XML document as a string
elemName - searched Element name
Returns:
XMLLight Element
XMLLightException

getElem

public static Element getElem(java.lang.String doc,
                              java.lang.String elemName,
                              boolean validate)
                       throws XMLLightException
Searches in XML Document for Element with name elemName and creates new XMLLight Element from XML document. If Element with elemName not found the value isEmply() of returned Element equals true. If error occured while parsing XML document the value errorCode of returned Element > 0.

Parameters:
doc - the XML document as a string
elemName - searched Element name
Returns:
XMLLight Element
XMLLightException

getElem

public static Element getElem(java.lang.String doc,
                              java.lang.String tag,
                              int start,
                              boolean validate)
                       throws XMLLightException
Sets Element from input string representing XML Element with shift to the beginning of the element in the string. Element reset as new Element if input string = null.

Parameters:
tag - tag name
Returns:
-1 - tag not found 0 - tag found, error occured 1 - tag found
XMLLightException

findOpeningTag

public static int findOpeningTag(java.lang.String doc,
                                 java.lang.String tag,
                                 int[] pos,
                                 boolean validate)
                          throws XMLLightException
Sets Element from input string representing XML Element with shift to the beginning of the element in the string. Element reset as new Element if input string = null.

Parameters:
tag - tag name
pos - [0] - from position [1] - found start of the tag [2] - found end of the tag
Returns:
-1 - tag not found 0 - tag found, error occured 1 - tag closed 2 - tag opened
XMLLightException

findClosingTag

public static int findClosingTag(java.lang.String doc,
                                 java.lang.String tag,
                                 int[] pos,
                                 boolean validate)
                          throws XMLLightException
Sets Element from input string representing XML Element with shift to the beginning of the element in the string. Element reset as new Element if input string = null.

Parameters:
tag - tag name
pos - [0] - from position [1] - found start of the tag [2] - found end of the tag
Returns:
-1 - tag not found 0 - tag found, error occured 1 - tag found
XMLLightException

skipSpaces

public static int skipSpaces(java.lang.String doc,
                             int start)
Skips spaces

Parameters:
start -