1 16 17 18 package org.apache.xml.serialize; 19 20 21 import java.io.OutputStream ; 22 import java.io.Writer ; 23 import java.io.UnsupportedEncodingException ; 24 import org.apache.xerces.dom.DOMMessageFormatter; 25 26 35 final class SerializerFactoryImpl 36 extends SerializerFactory 37 { 38 39 40 private String _method; 41 42 43 SerializerFactoryImpl( String method ) 44 { 45 _method = method; 46 if ( ! _method.equals( Method.XML ) && 47 ! _method.equals( Method.HTML ) && 48 ! _method.equals( Method.XHTML ) && 49 ! _method.equals( Method.TEXT ) ) { 50 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object []{method}); 51 throw new IllegalArgumentException (msg); 52 } 53 } 54 55 56 public Serializer makeSerializer( OutputFormat format ) 57 { 58 Serializer serializer; 59 60 serializer = getSerializer( format ); 61 serializer.setOutputFormat( format ); 62 return serializer; 63 } 64 65 66 67 public Serializer makeSerializer( Writer writer, 68 OutputFormat format ) 69 { 70 Serializer serializer; 71 72 serializer = getSerializer( format ); 73 serializer.setOutputCharStream( writer ); 74 return serializer; 75 } 76 77 78 public Serializer makeSerializer( OutputStream output, 79 OutputFormat format ) 80 throws UnsupportedEncodingException 81 { 82 Serializer serializer; 83 84 serializer = getSerializer( format ); 85 serializer.setOutputByteStream( output ); 86 return serializer; 87 } 88 89 90 private Serializer getSerializer( OutputFormat format ) 91 { 92 if ( _method.equals( Method.XML ) ) { 93 return new XMLSerializer( format ); 94 } else if ( _method.equals( Method.HTML ) ) { 95 return new HTMLSerializer( format ); 96 } else if ( _method.equals( Method.XHTML ) ) { 97 return new XHTMLSerializer( format ); 98 } else if ( _method.equals( Method.TEXT ) ) { 99 return new TextSerializer(); 100 } else { 101 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object []{_method}); 102 throw new IllegalStateException (msg); 103 } 104 } 105 106 107 protected String getSupportedMethod() 108 { 109 return _method; 110 } 111 112 113 } 114 115 | Popular Tags |