[jdom-interest] Test - Expanding <script> element.

Bradley S. Huffman hip at a.cs.okstate.edu
Thu Mar 17 12:15:48 PST 2005


Jason Hunter writes:

> Per Norrman wrote:
> 
> > Conclusion:
> > 
> > Probably, the temporary preserveFormat should reflect the
> > expandEmptyElement property of the userFormat.
> 
> I think you pegged it, Per.  We'll have to change the mechanism for 
> obtaining the preserveFormat instance in XMLOutputter to bring over the 
> pertinent attributes of the userFormat:
> 
> * expandEmptyElement
> * ignoreTrAXEscapingPIs
> * escapeStrategy

What about the other attributes that are non-formatting related but
subclassers want access too, since they have access to currentFormat?

How about these static methods in Format

    getRawFormat(Format old)
    getPrettyFormat(Format old)
    getCompactFormat(Format old)

that copy all other non-format related attributes of the old format and set
the format related attributes appropriately.

If that didn't make sense the diff's for Format and XMLOutputter are below.

Brad

*** Format.java	Thu Mar 17 14:06:02 2005
--- Format.new	Thu Mar 17 13:50:07 2005
***************
*** 76,81 ****
--- 76,83 ----
      private static final String CVS_ID =
              "@(#) $RCSfile: Format.java,v $ $Revision: 1.10 $ $Date: 2004/09/07 06:37:20 $ $Name:  $";
  
+     private static final Format DEFAULT_FORMAT = new Format();
+ 
      /**
       * Returns a new Format object that performs no whitespace changes, uses
       * the UTF-8 encoding, doesn't expand empty elements, includes the
***************
*** 82,95 ****
       * declaration and encoding, and uses the default entity escape strategy.
       * Tweaks can be made to the returned Format instance without affecting
       * other instances.
- 
       * @return                     a Format with no whitespace changes
       */
      public static Format getRawFormat() {
!         return new Format();
      }
  
      /**
       * Returns a new Format object that performs whitespace beautification with
       * 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements,
       * includes the declaration and encoding, and uses the default entity
--- 84,110 ----
       * declaration and encoding, and uses the default entity escape strategy.
       * Tweaks can be made to the returned Format instance without affecting
       * other instances.
       * @return                     a Format with no whitespace changes
       */
      public static Format getRawFormat() {
!         return getRawFormat(DEFAULT_FORMAT);
      }
  
      /**
+      * Returns a new Format object that is a clone of the supplied format
+      * but set to perform no whitespace changes. Tweaks can be made to the
+      * returned Format instance without affecting
+      * other instances.
+      * @return                     a Format with no whitespace changes
+      */
+     public static Format getRawFormat(Format old) {
+         Format f = (Format) old.clone();
+         f.setIndent(null);
+         f.setTextMode(TextMode.PRESERVE);
+         return f;
+     }
+ 
+     /**
       * Returns a new Format object that performs whitespace beautification with
       * 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements,
       * includes the declaration and encoding, and uses the default entity
***************
*** 100,106 ****
       * @return                     a Format with whitespace beautification
       */
      public static Format getPrettyFormat() {
!         Format f = new Format();
          f.setIndent(STANDARD_INDENT);
          f.setTextMode(TextMode.TRIM);
          return f;
--- 115,133 ----
       * @return                     a Format with whitespace beautification
       */
      public static Format getPrettyFormat() {
!         return getPrettyFormat(DEFAULT_FORMAT);
!     }
! 
!     /**
!      * Returns a new Format object that is a clone of the supplied format
!      * but set to perform whitespace beautification with 2-space indents.
!      * Tweaks can be made to the returned Format instance without affecting
!      * other instances.
!      *
!      * @return                     a Format with whitespace beautification
!      */
!     public static Format getPrettyFormat(Format old) {
!         Format f = (Format) old.clone();
          f.setIndent(STANDARD_INDENT);
          f.setTextMode(TextMode.TRIM);
          return f;
***************
*** 116,122 ****
       * @return                     a Format with whitespace normalization
       */
      public static Format getCompactFormat() {
!         Format f = new Format();
          f.setTextMode(TextMode.NORMALIZE);
          return f;
      }
--- 143,162 ----
       * @return                     a Format with whitespace normalization
       */
      public static Format getCompactFormat() {
!         return getCompactFormat(DEFAULT_FORMAT);
!     }
! 
!     /**
!      * Returns a new Format object that is a clone of the supplied format
!      * but set to perform whitespace normalization.
!      * Tweaks can be made to the returned Format instance without affecting
!      * other instances.
!      *
!      * @return                     a Format with whitespace normalization
!      */
!     public static Format getCompactFormat(Format old) {
!         Format f = (Format) old.clone();
!         f.setIndent(null);
          f.setTextMode(TextMode.NORMALIZE);
          return f;
      }

*** XMLOutputter.java	Thu Mar 17 14:06:02 2005
--- XMLOutputter.new	Thu Mar 17 14:00:00 2005
***************
*** 117,129 ****
      private static final String CVS_ID =
        "@(#) $RCSfile: XMLOutputter.java,v $ $Revision: 1.113 $ $Date: 2004/12/11 01:31:50 $ $Name:  $";
  
!     // For normal output
!     private Format userFormat = Format.getRawFormat();
  
!     // For xml:space="preserve"
!     protected static final Format preserveFormat = Format.getRawFormat();
  
!     // What's currently in use
      protected Format currentFormat = userFormat;
  
      /** Whether output escaping is enabled for the being processed
--- 117,135 ----
      private static final String CVS_ID =
        "@(#) $RCSfile: XMLOutputter.java,v $ $Revision: 1.113 $ $Date: 2004/12/11 01:31:50 $ $Name:  $";
  
!     /**
!      * Initial format set by the user.
!      */
!     protected Format userFormat = Format.getRawFormat();
  
!     /**
!      * Format to use whenever a xml:space="preserve" attribute is encountered.
!      */
!     protected Format preserveFormat = Format.getRawFormat();
  
!     /**
!      * Format that is currently in-scope.
!      */
      protected Format currentFormat = userFormat;
  
      /** Whether output escaping is enabled for the being processed
***************
*** 146,153 ****
       * before use.
       */
      public XMLOutputter(Format format) {
!         userFormat = (Format) format.clone();
!         currentFormat = userFormat;
      }
  
      /**
--- 152,158 ----
       * before use.
       */
      public XMLOutputter(Format format) {
!         setFormat(format);
      }
  
      /**
***************
*** 159,166 ****
       * @param that the XMLOutputter to clone
       */
      public XMLOutputter(XMLOutputter that) {
!         this.userFormat = (Format) that.userFormat.clone();
!         currentFormat = userFormat;
      }
  
      // * * * * * * * * * * Set parameters methods * * * * * * * * * *
--- 164,170 ----
       * @param that the XMLOutputter to clone
       */
      public XMLOutputter(XMLOutputter that) {
!         setFormat(that.userFormat);
      }
  
      // * * * * * * * * * * Set parameters methods * * * * * * * * * *
***************
*** 174,179 ****
--- 178,184 ----
       */
      public void setFormat(Format newFormat) {
          this.userFormat = (Format) newFormat.clone();
+         this.preserveFormat = Format.getRawFormat(userFormat);
          this.currentFormat = userFormat;
      }
  


More information about the jdom-interest mailing list