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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue