XStream
  1. XStream
  2. XSTR-271

Cannot overload PrettyPrintWriter#setValue

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I'd like to be able to have XStream.toXML (Object, Writer) use my own PrettyPrintWriter extension.

      There are two problems, though.

      1. XStream#toXML (Object, Writer) uses a hard-wired PrettyPrintWriter in that method.
      2. PrettyPrintWriter#setValue uses private booleans and methods, not accessible to sub-classes.

      My suggestion is to be able to write this:

      public class MyPrettyPrintWriter extends PrettyPrintWriter
      {
      ....

      public void setValue (String text)
      {
      readyForNewLine = false;
      tagIsEmpty = false;
      finishTag ();

      boolean hasXml = false;

      if (text.indexOf ('<') != -1)

      { hasXml = true; writer.write ("<[CDATA["); }

      writer.write (text);

      if (hasXml)

      { writer.write ("]]>"); }

      }
      }

      But, I have to duplicate quite a bit of code to achieve this; in other words, copy PrettyPrintWriter.java to MyPrettyPrintWriter.java, just to overload #setValue(), that's excessive.
      And I still have to overwrite XStream#toXML (Object, Writer).

      It would be better if the properties / methods in PrettyPrintWriter mentioned above were protected.
      And, it be really cool if there was a XStream#toXml (Object, HierarchicalStreamWriter).

      That would be proper Object Orientation.

      Thanks

        People

        • Assignee:
          Unassigned
          Reporter:
          Carlo Dapor
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: