Agent System POND 1.2 (28.2.2002)

FIM.Util.XML
Class XMLUtils

java.lang.Object
  |
  +--FIM.Util.XML.XMLUtils

public class XMLUtils
extends Object

Miscellaneous utility functions connected with XML: Quoting of text for use in a CDATA-Section, conversion to of byte arrays to a hex-string and back, and comparing to byte arrays.

Version:
1.0
Author:
Michael Sonntag

Constructor Summary
XMLUtils()
           
 
Method Summary
static String CDATAQuoteText(String str)
          Converts a string, so that it can be used in a CDATA section without problems.
static String CDATAUnquoteText(String str)
          Converts a string from quoted back to normal.
static boolean equalByteArrays(byte[] ar1, byte[] ar2)
          Compares to byte arrays.
static void main(String[] args)
           
static byte[] toByteArray(String str)
          Converts a string of hexadecimal characters into an array of bytes.
static String toHexString(byte[] data)
          Converts an array of bytes to a hex-string.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtils

public XMLUtils()
Method Detail

CDATAQuoteText

public static final String CDATAQuoteText(String str)
Converts a string, so that it can be used in a CDATA section without problems. This means, it stays exactly the same, only "]]>" has to be changed (or the section would be ended prematurely on parsing).
Actual implementation: "]]>" is replaced by "].]>". If "].]>" does occur in the text, it is doubled ("].]>].]>"). This allows recreating the original text and avoiding the end of the CDATA section code.
Parameters:
the - string to quote
Returns:
the quoted string
See Also:
CDATAUnquoteText(String)

CDATAUnquoteText

public static final String CDATAUnquoteText(String str)
Converts a string from quoted back to normal.
Parameters:
the - string to unquote
Returns:
the original string
See Also:
CDATAQuoteText(String)

toHexString

public static final String toHexString(byte[] data)
Converts an array of bytes to a hex-string.
Parameters:
data - the array to convert
Returns:
a string with the data in hexadecimal representation

toByteArray

public static final byte[] toByteArray(String str)
Converts a string of hexadecimal characters into an array of bytes.
Parameters:
str - the string to convert
Returns:
an array of bytes
Throws:
IllegalArgumentException - if the string is not a valid hexadecimal string

equalByteArrays

public static final boolean equalByteArrays(byte[] ar1,
                                            byte[] ar2)
Compares to byte arrays. The arrays must have the same length and contain exactly the same data.
Parameters:
ar1 - the first array to compare
ar2 - the second array to compare
Returns:
true if both arrays have the same length and contain the same bytes

main

public static void main(String[] args)

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.