1 57 58 59 package com.sun.org.apache.xml.internal.serialize; 60 61 62 import java.io.OutputStream ; 63 import java.io.Writer ; 64 import java.io.UnsupportedEncodingException ; 65 import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter; 66 67 76 final class SerializerFactoryImpl 77 extends SerializerFactory 78 { 79 80 81 private String _method; 82 83 84 SerializerFactoryImpl( String method ) 85 { 86 _method = method; 87 if ( ! _method.equals( Method.XML ) && 88 ! _method.equals( Method.HTML ) && 89 ! _method.equals( Method.XHTML ) && 90 ! _method.equals( Method.TEXT ) ) { 91 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object []{method}); 92 throw new IllegalArgumentException (msg); 93 } 94 } 95 96 97 public Serializer makeSerializer( OutputFormat format ) 98 { 99 Serializer serializer; 100 101 serializer = getSerializer( format ); 102 serializer.setOutputFormat( format ); 103 return serializer; 104 } 105 106 107 108 public Serializer makeSerializer( Writer writer, 109 OutputFormat format ) 110 { 111 Serializer serializer; 112 113 serializer = getSerializer( format ); 114 serializer.setOutputCharStream( writer ); 115 return serializer; 116 } 117 118 119 public Serializer makeSerializer( OutputStream output, 120 OutputFormat format ) 121 throws UnsupportedEncodingException 122 { 123 Serializer serializer; 124 125 serializer = getSerializer( format ); 126 serializer.setOutputByteStream( output ); 127 return serializer; 128 } 129 130 131 private Serializer getSerializer( OutputFormat format ) 132 { 133 if ( _method.equals( Method.XML ) ) { 134 return new XMLSerializer( format ); 135 } else if ( _method.equals( Method.HTML ) ) { 136 return new HTMLSerializer( format ); 137 } else if ( _method.equals( Method.XHTML ) ) { 138 return new XHTMLSerializer( format ); 139 } else if ( _method.equals( Method.TEXT ) ) { 140 return new TextSerializer(); 141 } else { 142 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object []{_method}); 143 throw new IllegalStateException (msg); 144 } 145 } 146 147 148 protected String getSupportedMethod() 149 { 150 return _method; 151 } 152 153 154 } 155 156 | Popular Tags |