X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Futil%2FSimpleXmlGenerator.java;h=440683bdbe39d4c54e79412f2644237e5b56a7c1;hb=e4126a1787b7045a53f6074e9ef15681c9f5fde4;hp=fbddb0a8ba3ab2bea9b855db047e2409da154a0f;hpb=276d9a69fa796728169c2992921a1e4bd875f549;p=jpim.git diff --git a/src/de/j32/util/SimpleXmlGenerator.java b/src/de/j32/util/SimpleXmlGenerator.java index fbddb0a..440683b 100644 --- a/src/de/j32/util/SimpleXmlGenerator.java +++ b/src/de/j32/util/SimpleXmlGenerator.java @@ -18,110 +18,105 @@ import org.xml.sax.helpers.AttributesImpl; public class SimpleXmlGenerator { - TransformerHandler handler_; - Stack openElements_ = new Stack(); - - public SimpleXmlGenerator(OutputStream os, String encoding) - throws UnsupportedEncodingException - { - SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - // factory.setAttribute("indent-number", new Integer(2)); - try { - handler_ = factory.newTransformerHandler(); - } - catch (TransformerConfigurationException e) { - throw new AssertionError("XML/SAX transformer configuration error"); - } - catch (TransformerFactoryConfigurationError e) { - throw new AssertionError("XML/SAX transformer factory configuration error"); - } - Transformer tf = handler_.getTransformer(); - tf.setOutputProperty(OutputKeys.ENCODING,encoding); - // if (doctype != null) - // tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype); - // tf.setOutputProperty(OutputKeys.INDENT,indent ? "yes" : "no"); - handler_.setResult(new StreamResult(new OutputStreamWriter(os, encoding))); - } - - public void startDocument() - throws SAXException - { - handler_.startDocument(); - } - - public void start(String name) - throws SAXException - { - handler_.startElement("","",name,null); - openElements_.add(name); - } - - public static class Attributes - { - AttributesImpl attributes_ = new AttributesImpl(); - - public Attributes attribute(String name, String value) - { - attributes_.addAttribute("","",name,"CDATA",value); - return this; - } - - AttributesImpl getAttributes() - { - return attributes_; - } - - Attributes() {} - } - - public Attributes attribute(String name, String value) - { - Attributes a = new Attributes(); - return a.attribute(name, value); - } - - public void start(String name, Attributes attrs) - throws SAXException - { - handler_.startElement("","",name, attrs.getAttributes()); - openElements_.push(name); - } - - public void end() - throws SAXException - { - handler_.endElement("","",openElements_.pop()); - } - - public void empty(String name) - throws SAXException - { - start(name); - end(); - } - - public void empty(String name, Attributes attrs) - throws SAXException - { - start(name, attrs); - end(); - } - - public void text(String text) - throws SAXException - { - handler_.characters(text.toCharArray(), 0, text.length()); - } - - public void nl() - throws SAXException - { - text("\n"); - } - - public void endDocument() - throws SAXException - { - handler_.endDocument(); - } + TransformerHandler handler_; + Stack openElements_ = new Stack(); + + public SimpleXmlGenerator(OutputStream os, String encoding) + throws UnsupportedEncodingException + { + SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory + .newInstance(); + // factory.setAttribute("indent-number", new Integer(2)); + try { + handler_ = factory.newTransformerHandler(); + } + catch (TransformerConfigurationException e) { + throw new AssertionError("XML/SAX transformer configuration error"); + } + catch (TransformerFactoryConfigurationError e) { + throw new AssertionError( + "XML/SAX transformer factory configuration error"); + } + Transformer tf = handler_.getTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, encoding); + // if (doctype != null) + // tf.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype); + // tf.setOutputProperty(OutputKeys.INDENT,indent ? "yes" : "no"); + handler_.setResult(new StreamResult( + new OutputStreamWriter(os, encoding))); + } + + public void startDocument() throws SAXException + { + handler_.startDocument(); + } + + public void start(String name) throws SAXException + { + handler_.startElement("", "", name, null); + openElements_.add(name); + } + + public static class Attributes + { + AttributesImpl attributes_ = new AttributesImpl(); + + public Attributes attribute(String name, String value) + { + attributes_.addAttribute("", "", name, "CDATA", value); + return this; + } + + AttributesImpl getAttributes() + { + return attributes_; + } + + Attributes() + {} + } + + public Attributes attribute(String name, String value) + { + Attributes a = new Attributes(); + return a.attribute(name, value); + } + + public void start(String name, Attributes attrs) throws SAXException + { + handler_.startElement("", "", name, attrs.getAttributes()); + openElements_.push(name); + } + + public void end() throws SAXException + { + handler_.endElement("", "", openElements_.pop()); + } + + public void empty(String name) throws SAXException + { + start(name); + end(); + } + + public void empty(String name, Attributes attrs) throws SAXException + { + start(name, attrs); + end(); + } + + public void text(String text) throws SAXException + { + handler_.characters(text.toCharArray(), 0, text.length()); + } + + public void nl() throws SAXException + { + text("\n"); + } + + public void endDocument() throws SAXException + { + handler_.endDocument(); + } }