1 16 19 package org.apache.xalan.serialize; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.io.Writer ; 24 import java.util.Properties ; 25 26 import org.w3c.dom.Node ; 27 import org.xml.sax.ContentHandler ; 28 29 34 public abstract class SerializerFactory 35 { 36 37 private SerializerFactory() 38 { 39 } 40 54 public static Serializer getSerializer(Properties format) 55 { 56 org.apache.xml.serializer.Serializer ser; 57 ser = org.apache.xml.serializer.SerializerFactory.getSerializer(format); 58 SerializerFactory.SerializerWrapper si = new SerializerWrapper(ser); 59 return si; 60 61 } 62 63 68 69 private static class SerializerWrapper implements Serializer 70 { 71 private final org.apache.xml.serializer.Serializer m_serializer; 72 private DOMSerializer m_old_DOMSerializer; 73 74 SerializerWrapper(org.apache.xml.serializer.Serializer ser) 75 { 76 m_serializer = ser; 77 78 } 79 80 public void setOutputStream(OutputStream output) 81 { 82 m_serializer.setOutputStream(output); 83 } 84 85 public OutputStream getOutputStream() 86 { 87 return m_serializer.getOutputStream(); 88 } 89 90 public void setWriter(Writer writer) 91 { 92 m_serializer.setWriter(writer); 93 } 94 95 public Writer getWriter() 96 { 97 return m_serializer.getWriter(); 98 } 99 100 public void setOutputFormat(Properties format) 101 { 102 m_serializer.setOutputFormat(format); 103 } 104 105 public Properties getOutputFormat() 106 { 107 return m_serializer.getOutputFormat(); 108 } 109 110 public ContentHandler asContentHandler() throws IOException 111 { 112 return m_serializer.asContentHandler(); 113 } 114 115 119 public DOMSerializer asDOMSerializer() throws IOException 120 { 121 if (m_old_DOMSerializer == null) 122 { 123 m_old_DOMSerializer = 124 new DOMSerializerWrapper(m_serializer.asDOMSerializer()); 125 } 126 return m_old_DOMSerializer; 127 } 128 131 public boolean reset() 132 { 133 return m_serializer.reset(); 134 } 135 136 } 137 138 143 private static class DOMSerializerWrapper implements DOMSerializer 144 { 145 private final org.apache.xml.serializer.DOMSerializer m_dom; 146 DOMSerializerWrapper(org.apache.xml.serializer.DOMSerializer domser) 147 { 148 m_dom = domser; 149 } 150 151 public void serialize(Node node) throws IOException 152 { 153 m_dom.serialize(node); 154 } 155 } 156 157 } 158 | Popular Tags |