1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 23 package com.sun.org.apache.xml.internal.serialize; 24 25 26 import java.io.OutputStream; 27 import java.io.Writer; 28 import java.io.UnsupportedEncodingException; 29 import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter; 30 31 /** 32 * Default serializer factory can construct serializers for the three 33 * markup serializers (XML, HTML, XHTML ). 34 * 35 * 36 * @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a> 37 * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a> 38 * 39 * @deprecated As of JDK 9, Xerces 2.9.0, Xerces DOM L3 Serializer implementation 40 * is replaced by that of Xalan. Main class 41 * {@link com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl} is replaced 42 * by {@link com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl}. 43 */ 44 final class SerializerFactoryImpl 45 extends SerializerFactory 46 { 47 48 49 private String _method; 50 51 52 SerializerFactoryImpl( String method ) 53 { 54 _method = method; 55 if ( ! _method.equals( Method.XML ) && 56 ! _method.equals( Method.HTML ) && 57 ! _method.equals( Method.XHTML ) && 58 ! _method.equals( Method.TEXT ) ) { 59 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{method}); 60 throw new IllegalArgumentException(msg); 61 } 62 } 63 64 65 public Serializer makeSerializer( OutputFormat format ) 66 { 67 Serializer serializer; 68 69 serializer = getSerializer( format ); 70 serializer.setOutputFormat( format ); 71 return serializer; 72 } 73 74 75 76 public Serializer makeSerializer( Writer writer, 77 OutputFormat format ) 78 { 79 Serializer serializer; 80 81 serializer = getSerializer( format ); 82 serializer.setOutputCharStream( writer ); 83 return serializer; 84 } 85 86 87 public Serializer makeSerializer( OutputStream output, 88 OutputFormat format ) 89 throws UnsupportedEncodingException 90 { 91 Serializer serializer; 92 93 serializer = getSerializer( format ); 94 serializer.setOutputByteStream( output ); 95 return serializer; 96 } 97 98 99 private Serializer getSerializer( OutputFormat format ) 100 { 101 if ( _method.equals( Method.XML ) ) { 102 return new XMLSerializer( format ); 103 } else if ( _method.equals( Method.HTML ) ) { 104 return new HTMLSerializer( format ); 105 } else if ( _method.equals( Method.XHTML ) ) { 106 return new XHTMLSerializer( format ); 107 } else if ( _method.equals( Method.TEXT ) ) { 108 return new TextSerializer(); 109 } else { 110 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method}); 111 throw new IllegalStateException(msg); 112 } 113 } 114 115 116 protected String getSupportedMethod() 117 { 118 return _method; 119 } 120 121 122 }