1 57 58 59 package org.enhydra.apache.xml.serialize; 60 61 62 import java.io.OutputStream ; 63 import java.io.UnsupportedEncodingException ; 64 import java.io.Writer ; 65 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 throw new IllegalArgumentException ( "SER004 The method '" + method + "' is not supported by this factory\n" + method); 92 } 93 94 95 public Serializer makeSerializer( OutputFormat format ) 96 { 97 Serializer serializer; 98 99 serializer = getSerializer( format ); 100 serializer.setOutputFormat( format ); 101 return serializer; 102 } 103 104 105 106 public Serializer makeSerializer( Writer writer, 107 OutputFormat format ) 108 { 109 Serializer serializer; 110 111 serializer = getSerializer( format ); 112 serializer.setOutputCharStream( writer ); 113 return serializer; 114 } 115 116 117 public Serializer makeSerializer( OutputStream output, 118 OutputFormat format ) 119 throws UnsupportedEncodingException  120 { 121 Serializer serializer; 122 123 serializer = getSerializer( format ); 124 serializer.setOutputByteStream( output ); 125 return serializer; 126 } 127 128 129 private Serializer getSerializer( OutputFormat format ) 130 { 131 if ( _method.equals( Method.XML ) ) { 132 return new XMLSerializer( format ); 133 } else if ( _method.equals( Method.HTML ) ) { 134 return new HTMLSerializer( format ); 135 } else if ( _method.equals( Method.XHTML ) ) { 136 return new XHTMLSerializer( format ); 137 } else if ( _method.equals( Method.TEXT ) ) { 138 return new TextSerializer(); 139 } else { 140 throw new IllegalStateException ( "SER005 The method '" + _method + "' is not supported by this factory\n" + _method); 141 } 142 } 143 144 145 protected String getSupportedMethod() 146 { 147 return _method; 148 } 149 150 151 } 152 153 | Popular Tags |