Add escape methods.
This commit is contained in:
parent
6d7db8b7ef
commit
6ed1e3b20b
1 changed files with 62 additions and 15 deletions
|
@ -16,6 +16,8 @@ import javax.xml.validation.Schema;
|
|||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -28,6 +30,51 @@ import org.xml.sax.SAXException;
|
|||
*/
|
||||
public class XMLTools
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public String escapeXMLNull(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (StringUtils.isBlank(source))
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = StringEscapeUtils.escapeXml(source);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public String unescapeXMLNull(final String source)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (StringUtils.isBlank(source))
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = StringEscapeUtils.unescapeXml(source);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -230,50 +277,50 @@ public class XMLTools
|
|||
{
|
||||
case XMLEvent.ATTRIBUTE:
|
||||
result = "ATTRIBUTE ";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.CDATA:
|
||||
result = "CDATA";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.CHARACTERS:
|
||||
result = "CHARACTERS [" + source.asCharacters().getData() + "]";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.COMMENT:
|
||||
result = "COMMENT";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.DTD:
|
||||
result = "DTD";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.END_DOCUMENT:
|
||||
result = "END_DOCUMENT";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.END_ELEMENT:
|
||||
result = "END_ELEMENT " + source.asEndElement().getName();
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.ENTITY_DECLARATION:
|
||||
result = "ENTITY_DECLARATION";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.ENTITY_REFERENCE:
|
||||
result = "ENTITY_REFERENCE";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.NAMESPACE:
|
||||
result = "NAMESPACE";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.NOTATION_DECLARATION:
|
||||
result = "NOTATION_DECLARATION";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.PROCESSING_INSTRUCTION:
|
||||
result = "PROCESSING_INSTRUCTION";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.SPACE:
|
||||
result = "SPACE";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.START_DOCUMENT:
|
||||
result = "START_DOCUMENT";
|
||||
break;
|
||||
break;
|
||||
case XMLEvent.START_ELEMENT:
|
||||
result = "START_ELEMENT [name=" + source.asStartElement().getName() + "][namespaceURI=" + source.asStartElement().getName().getNamespaceURI() + "][prefix="
|
||||
+ source.asStartElement().getName().getPrefix() + "][localPart=" + source.asStartElement().getName().getLocalPart() + "]";
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
result = null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue