|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.reverseXSL.util.Formatters
public class Formatters
A collection of utility methods bound to formatting data.
Constructor Summary | |
---|---|
Formatters()
|
Method Summary | |
---|---|
static java.lang.String |
hexEscape(byte[] bytes,
int start,
int length)
Utility method to hex-encode a byte array so that it becomes XML-safe and readable whatever the enclosed byte values. |
static byte[] |
hexUnEscape(java.lang.String s)
Inverse of hexEscape(byte[], int, int) . |
static java.lang.String |
niceXML(java.lang.StringBuffer uglyXML,
java.lang.String indentPattern,
java.lang.String EOL)
There a BIG issue with indentation according to the JVM version and/or preferred XML parser on the classpath. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Formatters()
Method Detail |
---|
public static java.lang.String hexEscape(byte[] bytes, int start, int length)
NOTE: I have not found a proper XML character escaping method so here is one custom-developed based on a bare conversion table (fastest access) taking care of '&' , '>' , and '<' (for XML safeness) and all non-printable 7bit ASCII. Magic is, most EDI messages would just look like they are really (but for CR replaced by %0D)
bytes
- the binary (byte array) version of the data to encodestart
- the starting offset in the byte arraylength
- the number of bytes to hex-encode. If start+length is greater than the size of
the byte array, an array out of bounds exception is thrown as one shall expect.
public static byte[] hexUnEscape(java.lang.String s)
hexEscape(byte[], int, int)
.
s
- the string to decode into a byte array
public static java.lang.String niceXML(java.lang.StringBuffer uglyXML, java.lang.String indentPattern, java.lang.String EOL)
I wanted a method that worked in all circumstances; the issue is actually with space-only text nodes attached elsewhere in the XML document tree that reflect indentation and line feeds. Not only these may eat a significant portion of your XML documents, but diverse XSLT, DOM and SAX tools actually exhibit different behaviours with the result of scrambling the output. I was unable to find a common compatible core.
BEWARE OF LIMITATIONS: The formatting utility doesn't work on XML documents that mix non-blank text nodes with child elements within the same parent element... kind of bad practice indeed but actually fully allowed by the XML standards.
THEREFORE, PLEASE ENJOY THIS FACILITY ONLY FOR TESTING AND CONTINUE FEEDING LOCAL APPLICATIONS WITH POTENTIALLY UGLY XMLs. THEY DON'T CARE LIKE OUR EYES DO.
uglyXML
- whatever raw output that is anyhow a valid XML documentindentPattern
- try for instance " |" and see the magic!
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |