use of com.sun.xml.bind.marshaller.CharacterEscapeHandler in project ANNIS by korpling.
the class GuavaEscaperMarshallerProvider method getContext.
@Override
public Marshaller getContext(Class<?> type) {
JAXBContext context = contextCache.computeIfAbsent(type, new Function<Class<?>, JAXBContext>() {
@Override
public JAXBContext apply(Class<?> t) {
try {
return JAXBContext.newInstance(t);
} catch (JAXBException ex) {
log.error("Can't create JAXB context", ex);
}
return null;
}
});
if (context != null) {
try {
Marshaller m = context.createMarshaller();
m.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() {
@Override
public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
String asString = new String(ch, start, length);
Escaper e = isAttVal ? XmlEscapers.xmlAttributeEscaper() : XmlEscapers.xmlContentEscaper();
out.write(e.escape(asString));
}
});
return m;
} catch (JAXBException ex) {
log.error("Can't create XML marshaller", ex);
}
}
return null;
}
use of com.sun.xml.bind.marshaller.CharacterEscapeHandler in project entando-core by entando.
the class CDataCharacterEscapeHandler method useStandardEscape.
private void useStandardEscape(char[] ch, int start, int length, boolean isAttVal, Writer writer) throws IOException {
CharacterEscapeHandler escapeHandler = StandardEscapeHandler.getInstance();
escapeHandler.escape(ch, start, length, isAttVal, writer);
}
Aggregations