Tatu,
I have the CDATA set in my resource class.
@GET
@Path("/list")
@ProduceMime({"application/xml"})
public Response getRows() {
final Rows rows;
rows = processRowsResponse();
return Response.ok(rows).build();
}
private Rows processRowsResponse() {
List<RowType> rows = new ArrayList<RowType>();
RowType row = new RowType();
CellType cell = new CellType();
final String cdata = new StringBuilder().append("<![CDATA[<div
class=\"progressOuterRow\"><div class=\"progressInnerRow\"
style=\"width: ").append(result.toString()).append("px;\"></div><div
class=\"progressText\">").append(used).append("/").append(total).append("
MB</div></div>]]>").toString();
cell.setValue(cdata);
row.getCell().add(cell);
rows.add(row);
return rows;
}
I assume this CDATA will be sent as a string to the
XMLStreamWriter.writeCharacters() when the MessageBodyWriter<CellType>
is invoked.
May be I missing something here?
Thanks!
Arul
Tatu Saloranta wrote:
> Code below looks correct, but where does that "CDATA"
> come into String? Is it just added for testing?
>
> What seems to be happening is that for some reason
> content you are getting is already xml-escaped (or is
> fed to another xml stream writer); like OutputStream
> or Writer passing its content back to xml writer.
>
> -+ Tatu +-
>
> --- Arul Dhesiaseelan <arul_at_fluxcorp.com> wrote:
>
>
>> Paul,
>>
>> Here is my custom Stream writer. I just delegate
>> writeCData to
>> XMLStreamWriter. I will try with a standalone test.
>>
>> public class MyStreamWriter implements
>> XMLStreamWriter {
>> private XMLStreamWriter mImpl;
>>
>> public MyStreamWriter(XMLStreamWriter
>> xmlStreamWriter) throws
>> XMLStreamException {
>> this.mImpl = xmlStreamWriter;
>> }
>>
>> public void writeCData(String s) throws
>> XMLStreamException {
>> mImpl.writeCData(s);
>> }
>>
>> public void writeCharacters(String s) throws
>> XMLStreamException {
>> if (shouldUseCData(s)) {
>> System.out.println("Using CDATA");
>> mImpl.writeCData(s);
>> } else {
>> mImpl.writeCharacters(s);
>> }
>> }
>>
>> private boolean shouldUseCData(String s) {
>> if (s.contains("CDATA")) {
>> return true;
>> } else return false;
>> }
>> //removed other methods
>> }
>>
>> Am I missing something here?
>>
>> Thanks!
>> Arul
>>
>>