
com.github.bingoohuang.springrestclient.xml.CDataXMLStreamWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-rest-client Show documentation
Show all versions of spring-rest-client Show documentation
convenient spring rest client for rest services
package com.github.bingoohuang.springrestclient.xml;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.regex.Pattern;
/**
* Implementation which is able to decide to use a CDATA section for a string.
*/
public class CDataXMLStreamWriter extends DelegatingXMLStreamWriter {
private static final Pattern XML_CHARS = Pattern.compile("[&<>]");
public CDataXMLStreamWriter(XMLStreamWriter del) {
super(del);
}
@Override
public void writeCharacters(String text) throws XMLStreamException {
boolean useCData = XML_CHARS.matcher(text).find();
if (useCData) {
super.writeCData(text);
} else {
super.writeCharacters(text);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy