XMLHelper converts XML string literals. More...
Static Public Member Functions | |
static String | encodeXMLString (final String s) |
Encode XML string literals. | |
static String | encodeXMLString (final String s, boolean cdata) |
Encode XML string literals, optionally in CDATA sections. | |
static String | decodeXMLString (final String s) |
Decode XML string literals. | |
static String | unescape (String s) |
remove escape characters from the specified string | |
static String | unescape (String s, char b, char e) |
remove escape characters from the specified string | |
Private Member Functions | |
XMLHelper () | |
private constructor to disable instantiation. |
XMLHelper converts XML string literals.
Definition at line 45 of file XMLHelper.java.
de.mfuchs.xmlstorage.XMLHelper.XMLHelper | ( | ) | [private] |
static String de.mfuchs.xmlstorage.XMLHelper.decodeXMLString | ( | final String | s ) | [static] |
Decode XML string literals.
Definition at line 110 of file XMLHelper.java.
Referenced by de.mfuchs.xmlstorage.stream.XMLStreamNode.getContent(), and de.mfuchs.xmlstorage.XMLNode.getContent().
{ StringBuffer buffer = new StringBuffer(); for(int i=0; i<s.length(); ++i) { char c = s.charAt(i); // handle string literals if (c == '&') { if (s.substring(i+1,i+4).equalsIgnoreCase("lt;")) { buffer.append('<'); i += 3; } else if (s.substring(i+1,i+4).equalsIgnoreCase("gt;")) { buffer.append('>'); i += 3; } else if (s.substring(i+1,i+5).equalsIgnoreCase("amp;")) { buffer.append('&'); i += 4; } else if (s.substring(i+1,i+6).equalsIgnoreCase("quot;")) { buffer.append('"'); i += 5; } else if (s.substring(i+1,i+6).equalsIgnoreCase("apos;")) { buffer.append('\''); i += 5; } else buffer.append(c); } // handle CDATA sections else if (c=='<' && s.regionMatches(i+1, "![CDATA[", 0, 8)) { int e = s.indexOf("]]>", i+9); if (e != -1) { i += 9; int l = e - i; buffer.append(s.substring(i, i+l)); i += 3; } else buffer.append(c); } else buffer.append(c); } return buffer.toString(); }
static String de.mfuchs.xmlstorage.XMLHelper.encodeXMLString | ( | final String | s, |
boolean | cdata | ||
) | [static] |
Encode XML string literals, optionally in CDATA sections.
Definition at line 65 of file XMLHelper.java.
{ StringBuffer buffer = new StringBuffer(); if (cdata) { buffer.append("<![CDATA["); buffer.append(s); buffer.append("]]>"); } else { for(int i=0; i<s.length(); ++i) { char c = s.charAt(i); switch(c) { case '<': buffer.append("<"); break; case '>': buffer.append(">"); break; case '&': buffer.append("&"); break; case '"': buffer.append("""); break; case '\'': buffer.append("'"); break; default: buffer.append(c); } } } return buffer.toString(); }
static String de.mfuchs.xmlstorage.XMLHelper.encodeXMLString | ( | final String | s ) | [static] |
Encode XML string literals.
Definition at line 57 of file XMLHelper.java.
Referenced by de.mfuchs.xmlstorage.stream.XMLStreamReader.characters(), de.mfuchs.xmlstorage.XMLDocReader.characters(), de.mfuchs.xmlstorage.XMLNode.prettyWriteWorker(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.setContent(), de.mfuchs.xmlstorage.XMLNode.setContent(), de.mfuchs.xmlstorage.XMLNode.smartWriteWorker(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.writeAttributes(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePost(), de.mfuchs.xmlstorage.stream.XMLStreamWriter.writePre(), and de.mfuchs.xmlstorage.XMLNode.writeWorker().
{ return encodeXMLString(s, false); }
static String de.mfuchs.xmlstorage.XMLHelper.unescape | ( | String | s ) | [static] |
remove escape characters from the specified string
Definition at line 155 of file XMLHelper.java.
References de.mfuchs.xmlstorage.XMLHelper.unescape().
Referenced by de.mfuchs.xmlstorage.XPathElement.parse(), and de.mfuchs.xmlstorage.XMLHelper.unescape().
{ return XMLHelper.unescape(s, '"', '"'); }
static String de.mfuchs.xmlstorage.XMLHelper.unescape | ( | String | s, |
char | b, | ||
char | e | ||
) | [static] |
remove escape characters from the specified string
Definition at line 161 of file XMLHelper.java.
{ // if (s.charAt(0) == b) // s = s.substring(1); // // if (s.length()>0 && end[-1]==e) // s = s.substring(0, s.length()-1); if (s.charAt(0) == b) if (s.length()>1 && s.charAt(s.length()-1)==e) s = s.substring(1, s.length()-1); return s; }