--- Paul Sandoz <Paul.Sandoz_at_Sun.COM> wrote:
> Tatu Saloranta wrote:
> > --- Paul Sandoz <Paul.Sandoz_at_Sun.COM> wrote:
...
> > In this particular case, it would be possible to
> write
> > an XMLStreamWriter delegate which mostly just
> calls
> > actual stream writer as-is, but changes calls to
> > writeCharacters() to writeCData().
>
> Can a writeCData() implementation only bracket with
> "<![CDATA[" and
> "]]>" if escaping would otherwise be required? Or
> would this result in
> all character data being bracketed?
The way I think it would be done, the custom wrapper
implementation (class that implements XMLStreamWriter
by acting as a proxy to underlying concrete stream
writer impl) could definitely redirect only some calls
(or even split a single call to multiple different
ones).
Something like:
---
public class MyStreamWriter implements
XMLStreamWriter()
{
// ...
public void writeCharacters(String text) // throws...
{
if (shouldUseCData(text)) {
mImpl.writeCData(text);
} else {
mImpl.writeCharacters(text);
}
}
// other methods just pass to mImpl without checks
}
XMLStreamWriter swImpl =
XMLOutputFactory.createXMLStreamWriter(...);
XMLStreamWriter sw = new MyStreamWriter(swImpl);
marshaller.marshal(myObject, sw);
---
The question, then, is if and how to configure Jersey
to use that stream writer impl. It would even be
possible to create one's own XMLOutputFactory to
produce such wrapped writers (and use system property
to make JDK use that).
But hopefully that would not be necessary.
-+ Tatu +-