Re: [xmlenc-devel] Late Merry Christmas
Brought to you by:
znerd
From: Henri Y. <ba...@ge...> - 2003-01-04 21:32:17
|
On Mon, 30 Dec 2002, Ernst de Haan wrote: > Hi Henri, > > > I've got a nightly build going, which I can happily do for xmlenc if you > > want too [would be easiest to put a maven project.xml in the home dir, > > but I can work around it and use ant instead, currently xmlenc doesn't > > build for me but I assume it's my fault]. > > What exactly do you mean? I checked the xmlenc source out, but when I 'ant'd, it had issues. I may have just been being sleepy as when I build it now it just complains that JDOM is not available. This is 0.18, and I've moved to 0.20 now. > > http://www.flamefew.net/~hen/xmlwriter-design.jpg > > Looks very good! Communication using UML diagrams is really nice. Only difference is that XmlStreamXmlWriter is now XmlEncXmlWriter, and that SchemaCheckingXmlWriter is still JarvXmlWriter. I've migrated to xmlenc 0.20. > > PrettyPrinting pretty prints on top of one of the other two [though it's > > not working atm]. > > Ah, real nice! Working now. I suspect it has issues, but I think I've tweaked and murdered Pete's code enough that it seems to work on basic tests. > > EmptyElement handles the different strategies for null/"". > > This one then wraps another instance, I presume? And what is the default > behaviour for other XmlWriters? They ignore the issue and pass things on. SimpleXmlWriter [xmlenc competitor as such] will print out "null" if passed null. > > Formatted handles DateFormat and NumberFormat, though I think it should > > be a bit more generic and map Classes to Formats. > > How exactly are these formats used? I can't see a use for them. Doesn't mean > there is none though... :-) At work, our biggest use of xml writing is to send xml to a Flash client. It's a real pain to have to keep remembering to do format.format(date) instead of just setting that format in the writer and then writing out whenever we want to. We also get told that numbers must not print decimal places and have to code that in. The XmlWriter interface writes Objects and not Strings, so using java.text.Format extensions to format those Objects is a nice trick. Currently FormattingXmlWriter has a NumberFormat and a DateFormat. I think it ought to map a Class to a Format. I suspect that this will often not be enough as you'll want to output a percentage, decimal and currency in the same xml, but they all map to Number etc. > > XmlIOFactory doesn't exist, but was what I was envisioning being the > > facade behind which lots of this would hide. Not too sure exactly how > > this would look though. > > Is this just the Factory pattern? Yeah. Basically, how should a user setup their chain of XmlWriters. They could do: Writer sw = new StringWriter(); XmlWriter xw = new XmlEncXmlWriter(sw); xw = new FormattingXmlWriter(xw).setDateFormat(new java.text.SimpleDateF ormat("yyyy-MM-dd")).setNumberFormat(new java.text.DecimalFormat("#")); xw = new EmptyElementXmlWriter(xw).setEmptyMode(EmptyElementXmlWriter.NU LL_EMPTY_MODE); xw = new PrettyPrinterXmlWriter(xw); [I've made all setXxx methods return their object. Probably breaks the Bean-ness, but I'm treating this as a play with the method-chaining viewpoint] or they could do: XmlWriter xw = XmlIO.prettyPrinter( XmlIO.emptyElement( XmlIO.NULL_EMPTY_MODE, XmlIO.formatted( "yyyy-MM-dd", "#", XmlIO.xmlenc( new StringWriter() ) ) ) ); Other XmlWriter changes: I've added getWriter() so that the underlying Writer is obtainable. While hiding this is good encapsulation, it also limits the user to the power of our API. If our API doesn't do it, they've no hope at hacking around. Plus they gave us the Writer in the first place anyway. Hen |