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

Bradley S. Huffman hip at a.cs.okstate.edu
Tue Mar 22 07:21:28 PST 2005


Jason Hunter writes:

> > I start to put code in XMLOutputter.setFormat to copy all fields from
> > userFormat to preserveFormat except the ones related to formating (setInden
> t
> > and setTexMode). But then if a field was ever added to Format or the text m
> odes
> > change, then we'd have to remember to also change XMLOutputter. It just see
> med
> > better to keep things in one place.
> > 
> > Brad
> 
> That's no different from the status quo.  Today if you add a Format text 
> mode, that new mode means nothing unless you also change XMLOutputter. 
> The two classes are already tightly coupled.  Format is in essence a 
> struct used by XMLOutputter.  There are patterns where the XMLOutputter 
> could rely on code rather than property values in the Format class, but 
> we haven't done that.  So thus I don't see the extra knowledge between 
> the two classes as a problem.  :)

True. No wait, not really. XMLOutputter cares about *what* properties are set,
but doesn't know *which* properties to set for a given format. Right now,
without digging into code, there is not way to know what properties are set
for pretty, preserve, or compact. By doing it in XMLOutputter.setFormat,
now XMLOutputter must know that to do preserve mode, it must set these certain
properties on Format. So at the time, I thought it was best left to Format
to set the properties for the various modes. It already does it for
getRawFormat(), getCompactFormat(), and getPrettyFormat().

Also at the time I was thinking that the 3 provide formats are just a copy of
some other format with a few properties changed, so it seemed
sensible that say getPrettyFormat() was just getPrettyFormat(new Format()),
getRawFormat() was just getRawFormat(new Format()), etc., and in 
XMLOutputter preserveFormat is just a copy of userFormat with a few properties
set, so getRawFormat(userFormat).

But either way it's not that big of deal. I do think just for consistency 
userFormat, currentFormat, and preserveFormat should be non-static, non-final,
protected in XMLOutputter. Right now subclasses have access to the instance of
currentFormat and preserveFormat, but only a copy of userFormat through
getFormat(). Also you can tweak (screw up :) the fields on currentFormat and
preserveFormat, but only change the instance of currentFormat.

Brad


More information about the jdom-interest mailing list