Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8141405

Public API equivalent to com.sun.xml.txw2.output.IndentingXMLStreamWriter

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: None
    • Component/s: xml
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      Jigsaw will disallow access to internal packages, then it would be useful to create a public API allowing to obtain an indenting XMLStreamWriter.

      Currently some XML API [1,2] provide public API for indenting, but StAX don't. Having public API always would be better.

      [1]: http://docs.oracle.com/javase/8/docs/api/javax/xml/bind/Marshaller.html#JAXB_FORMATTED_OUTPUT
      [2]: http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/OutputKeys.html#INDENT

      JUSTIFICATION :
      Using internal API for this feature is an usual solution (when not copying data and avoiding an external dependency for only this small feature).

      http://stackoverflow.com/questions/290326/stax-xml-formatting-in-java
      http://stackoverflow.com/questions/4616383/xmlstreamwriter-indentation

      Jigsaw will remove access to internal classes disallowing this feature. Having a public API providing equivalent API is useful for upgrading applications.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The simplest solution would be adding a new constant INDENT used when setting properties on the factory given existing method:

      String indentStep = " ";
      javax.xml.stream.XMLOutputFactory.setProperty(INDENT, indentStep);

      (indentStep == null) would mean no indentation like currently.
      (indentStep != null) would provide an instance of indenting XMLStreamWriter with setIndentStep set to the value.

      Given getIndentStep/setIndentStep is currently the only specific part of com.sun.xml.txw2.output.IndentingXMLStreamWriter, all the used feature will be public.

      It can be imagined another possible future enhancement: the choice of end-of-line (currently harcoded to UNIX \n). Allowing choice of end-of-line would probably require a second constant:
      javax.xml.stream.XMLOutputFactory.setProperty(INDENT_EOL, "\n");

      If value types exists in this time-frame, the two constants can possibly be merged in only one, setting the two properties in one step.

        Attachments

          Activity

            People

            • Assignee:
              joehw Joe Wang
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: