RE: Bug 25564 - CVS tagdiff does not escape XML characters
I noticed though that with JDK 1.4.2, even when requesting indenting, the resulting file is not indented :-( I have found this to be very implementation dependent, with the version I used, not setting the indent put every thing on a single line. I'll have to have a look at the xalan/xerces source code to see what is going on. Steve Dominique Devienne [EMAIL PROTECTED] 18/12/2003 16:53 Please respond to Ant Developers List To: Steven Murphy/DSD/LONDON/[EMAIL PROTECTED], 'Ant Developers List ' [EMAIL PROTECTED] cc: Subject:RE: Bug 25564 - CVS tagdiff does not escape XML characters Thanks Steven! Interesting ;-) Included below is my own twist on the technique you demonstated that allows to encapsulate the SAX/TrAX code. Clients just implement the XmlContentProvider, probably as an anonymous inner class at the same time as calling XmlWriter.write(). I noticed though that with JDK 1.4.2, even when requesting indenting, the resulting file is not indented :-( package com.lgc.buildmagic.util; import java.io.File; import java.io.Writer; import java.io.OutputStream; import java.io.IOException; // SAX classes import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.ContentHandler; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.XMLFilterImpl; // TrAX classes import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; public class XmlWriter { /** The mirror image of SAX's ContentHandler that writes to a handler. */ public interface XmlContentProvider { void writeTo(ContentHandler to) throws SAXException; } /** Just a dummy impl of the content provider interface above for testing. */ public static class MyProvider implements XmlContentProvider { public void writeTo(ContentHandler to) throws SAXException { final AttributesImpl attributes = new AttributesImpl(); to.startDocument(); to.startElement(, history-cache, history-cache, attributes); to.startElement(, entries, entries, attributes); to.startElement(, name, name, attributes); String name = Javahcache; to.characters(name.toCharArray(), 0, name.length()); to.endElement(, name, name); to.startElement(, tag, tag, attributes); String tag = tagtext/tag; to.characters(tag.toCharArray(), 0, tag.length()); to.endElement(, tag, tag); to.endElement(, entries, entries); to.endElement(, history-cache, history-cache); to.endDocument(); } } public void write(File file, XmlContentProvider provider) throws TransformerException { write(new StreamResult(file), provider); } public void write(OutputStream outputStream, XmlContentProvider provider) throws TransformerException { write(new StreamResult(outputStream), provider); } public void write(Writer writer, XmlContentProvider provider) throws TransformerException { write(new StreamResult(writer), provider); } /** * Writes SAX events sent by an XML provider using an identity transform. * * @param result The stream to write the result of the identity transform to. * @param provider The XML content provider. */ private void write(StreamResult result, final XmlContentProvider provider) throws TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, yes); XMLFilterImpl reader = new XMLFilterImpl() { public void parse(InputSource input) throws IOException, SAXException { provider.writeTo(getContentHandler()); } }; SAXSource source = new SAXSource(reader, new InputSource()); transformer.transform(source, result); } public static void main(String[] args) throws Exception { new XmlWriter().write(new File(XmlWriter.xml), new MyProvider()); } } -Original Message- From: [EMAIL PROTECTED] To: Ant Developers List Sent: 12/18/2003 7:36 AM Subject: RE: Bug 25564 - CVS tagdiff does not escape XML characters Hi, I have attached a file to the bug report. http://issues.apache.org/bugzilla/show_bug.cgi?id=25564 Steve Dominique Devienne [EMAIL PROTECTED] 17/12/2003 11:14 Please respond to Ant Developers List To: 'Antoine Levy-Lambert ' [EMAIL PROTECTED], 'Ant Developers List ' [EMAIL PROTECTED] cc: Subject:RE: Bug 25564 - CVS tagdiff does not escape XML characters From: [EMAIL
RE: Bug 25564 - CVS tagdiff does not escape XML characters
Actually, that's a good point. The tags are on different lines, not a single line, so maybe that's what they consider indented!?!? Given the fact that the processor cannot know whitespace is not significant, maybe it's even a better behavior. It's OK to 'indent' that way for XML to be consumed by an XSL stylesheet for example, but for generating XML to be potentially read by humans, the lack of real indenting (nested tag offset from parent tag) is problematic. Maybe the real answer is to adapt Ant's DOMElementWriter code to allow outputting directly (instead of requiring a DOM tree), and leverage the logic there to escape invalid characters... --DD -Original Message- From: [EMAIL PROTECTED] To: Ant Developers List Sent: 12/19/2003 5:35 AM Subject: RE: Bug 25564 - CVS tagdiff does not escape XML characters I noticed though that with JDK 1.4.2, even when requesting indenting, the resulting file is not indented :-( I have found this to be very implementation dependent, with the version I used, not setting the indent put every thing on a single line. I'll have to have a look at the xalan/xerces source code to see what is going on. Steve - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Bug 25564 - CVS tagdiff does not escape XML characters
Hi, I have attached a file to the bug report. http://issues.apache.org/bugzilla/show_bug.cgi?id=25564 Steve Dominique Devienne [EMAIL PROTECTED] 17/12/2003 11:14 Please respond to Ant Developers List To: 'Antoine Levy-Lambert ' [EMAIL PROTECTED], 'Ant Developers List ' [EMAIL PROTECTED] cc: Subject:RE: Bug 25564 - CVS tagdiff does not escape XML characters From: [EMAIL PROTECTED] My favoured way of generating XML from a class is to extend XMLFilterImpl and fire SAX events to a Transformer with no stylesheet and StreamResult of the required output file, inspired by Cocoon 2. Would you care to provide a concrete example please? Thanks, --DD - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Bug 25564 - CVS tagdiff does not escape XML characters
Thanks Steven! Interesting ;-) Included below is my own twist on the technique you demonstated that allows to encapsulate the SAX/TrAX code. Clients just implement the XmlContentProvider, probably as an anonymous inner class at the same time as calling XmlWriter.write(). I noticed though that with JDK 1.4.2, even when requesting indenting, the resulting file is not indented :-( package com.lgc.buildmagic.util; import java.io.File; import java.io.Writer; import java.io.OutputStream; import java.io.IOException; // SAX classes import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.ContentHandler; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.XMLFilterImpl; // TrAX classes import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; public class XmlWriter { /** The mirror image of SAX's ContentHandler that writes to a handler. */ public interface XmlContentProvider { void writeTo(ContentHandler to) throws SAXException; } /** Just a dummy impl of the content provider interface above for testing. */ public static class MyProvider implements XmlContentProvider { public void writeTo(ContentHandler to) throws SAXException { final AttributesImpl attributes = new AttributesImpl(); to.startDocument(); to.startElement(, history-cache, history-cache, attributes); to.startElement(, entries, entries, attributes); to.startElement(, name, name, attributes); String name = Javahcache; to.characters(name.toCharArray(), 0, name.length()); to.endElement(, name, name); to.startElement(, tag, tag, attributes); String tag = tagtext/tag; to.characters(tag.toCharArray(), 0, tag.length()); to.endElement(, tag, tag); to.endElement(, entries, entries); to.endElement(, history-cache, history-cache); to.endDocument(); } } public void write(File file, XmlContentProvider provider) throws TransformerException { write(new StreamResult(file), provider); } public void write(OutputStream outputStream, XmlContentProvider provider) throws TransformerException { write(new StreamResult(outputStream), provider); } public void write(Writer writer, XmlContentProvider provider) throws TransformerException { write(new StreamResult(writer), provider); } /** * Writes SAX events sent by an XML provider using an identity transform. * * @param result The stream to write the result of the identity transform to. * @param provider The XML content provider. */ private void write(StreamResult result, final XmlContentProvider provider) throws TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, yes); XMLFilterImpl reader = new XMLFilterImpl() { public void parse(InputSource input) throws IOException, SAXException { provider.writeTo(getContentHandler()); } }; SAXSource source = new SAXSource(reader, new InputSource()); transformer.transform(source, result); } public static void main(String[] args) throws Exception { new XmlWriter().write(new File(XmlWriter.xml), new MyProvider()); } } -Original Message- From: [EMAIL PROTECTED] To: Ant Developers List Sent: 12/18/2003 7:36 AM Subject: RE: Bug 25564 - CVS tagdiff does not escape XML characters Hi, I have attached a file to the bug report. http://issues.apache.org/bugzilla/show_bug.cgi?id=25564 Steve Dominique Devienne [EMAIL PROTECTED] 17/12/2003 11:14 Please respond to Ant Developers List To: 'Antoine Levy-Lambert ' [EMAIL PROTECTED], 'Ant Developers List ' [EMAIL PROTECTED] cc: Subject:RE: Bug 25564 - CVS tagdiff does not escape XML characters From: [EMAIL PROTECTED] My favoured way of generating XML from a class is to extend XMLFilterImpl and fire SAX events to a Transformer with no stylesheet and StreamResult of the required output file, inspired by Cocoon 2. Would you care to provide a concrete example please? Thanks, --DD - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Bug 25564 - CVS tagdiff does not escape XML characters
From: [EMAIL PROTECTED] My favoured way of generating XML from a class is to extend XMLFilterImpl and fire SAX events to a Transformer with no stylesheet and StreamResult of the required output file, inspired by Cocoon 2. Would you care to provide a concrete example please? Thanks, --DD - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bug 25564 - CVS tagdiff does not escape XML characters
Hi Steven, I will address this type of bug report once 1.6 is released. Right now, I prefer to concentrate my energy on getting the release done right. Cheers, Antoine - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, December 16, 2003 7:21 PM Subject: Bug 25564 - CVS tagdiff does not escape XML characters Server is down at the moment, so I cannot add to http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25564 Hi All, I have been looking through the problem source and the XML is generated by hand with code like writer.print(tagdiff ); if (mystartTag != null) { writer.print(startTag=\ + mystartTag + \ ); } else { writer.print(startDate=\ + mystartDate + \ ); } if (myendTag != null) { writer.print(endTag=\ + myendTag + \ ); } else { writer.print(endDate=\ + myendDate + \ ); } Which is all quite nasty. Firstlly, the problem could be fixed by adding a CDATA to the offending text, but this still leaves potential problems. My favoured way of generating XML from a class is to extend XMLFilterImpl and fire SAX events to a Transformer with no stylesheet and StreamResult of the required output file, inspired by Cocoon 2. Given that frequently the XML output of this task would be transformed to HTML using taggdiff.xsl then the processing would be more efficient to use that transformer from the outset; this would of course have to be optional in order not to break existing build files. The cvschangelog task is also guitly of handcrafting XML albeit using a CDATA for certain elements, again this task is also frequently followed by a style task. CvsTagDiff extends AbstractCvsTask yet ChangeLogTask does not, but both tasks are very similar, i.e: execute cvs command parse resultant file to memory output memory contents to XML And are both frequently followed by a style task, such similarity IMO should be exploited. Anyway, I am new to this open source apache stuff so appologies if I have omitted and stages or information. I am happy to perform this work myself of course. Steve - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]