286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * Copyright 1999-2002,2004 The Apache Software Foundation.
286N/A *
286N/A * Licensed under the Apache License, Version 2.0 (the "License");
286N/A * you may not use this file except in compliance with the License.
286N/A * You may obtain a copy of the License at
286N/A *
286N/A * http://www.apache.org/licenses/LICENSE-2.0
286N/A *
286N/A * Unless required by applicable law or agreed to in writing, software
286N/A * distributed under the License is distributed on an "AS IS" BASIS,
286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286N/A * See the License for the specific language governing permissions and
286N/A * limitations under the License.
286N/A */
286N/A
286N/A
286N/Apackage com.sun.org.apache.xml.internal.serialize;
286N/A
286N/A
286N/Aimport java.io.OutputStream;
286N/Aimport java.io.Writer;
286N/Aimport java.io.UnsupportedEncodingException;
286N/Aimport com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
286N/A
286N/A/**
286N/A * Default serializer factory can construct serializers for the three
286N/A * markup serializers (XML, HTML, XHTML ).
286N/A *
286N/A *
286N/A * @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a>
286N/A * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
286N/A */
286N/Afinal class SerializerFactoryImpl
286N/A extends SerializerFactory
286N/A{
286N/A
286N/A
286N/A private String _method;
286N/A
286N/A
286N/A SerializerFactoryImpl( String method )
286N/A {
286N/A _method = method;
286N/A if ( ! _method.equals( Method.XML ) &&
286N/A ! _method.equals( Method.HTML ) &&
286N/A ! _method.equals( Method.XHTML ) &&
286N/A ! _method.equals( Method.TEXT ) ) {
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{method});
286N/A throw new IllegalArgumentException(msg);
286N/A }
286N/A }
286N/A
286N/A
286N/A public Serializer makeSerializer( OutputFormat format )
286N/A {
286N/A Serializer serializer;
286N/A
286N/A serializer = getSerializer( format );
286N/A serializer.setOutputFormat( format );
286N/A return serializer;
286N/A }
286N/A
286N/A
286N/A
286N/A public Serializer makeSerializer( Writer writer,
286N/A OutputFormat format )
286N/A {
286N/A Serializer serializer;
286N/A
286N/A serializer = getSerializer( format );
286N/A serializer.setOutputCharStream( writer );
286N/A return serializer;
286N/A }
286N/A
286N/A
286N/A public Serializer makeSerializer( OutputStream output,
286N/A OutputFormat format )
286N/A throws UnsupportedEncodingException
286N/A {
286N/A Serializer serializer;
286N/A
286N/A serializer = getSerializer( format );
286N/A serializer.setOutputByteStream( output );
286N/A return serializer;
286N/A }
286N/A
286N/A
286N/A private Serializer getSerializer( OutputFormat format )
286N/A {
286N/A if ( _method.equals( Method.XML ) ) {
286N/A return new XMLSerializer( format );
286N/A } else if ( _method.equals( Method.HTML ) ) {
286N/A return new HTMLSerializer( format );
286N/A } else if ( _method.equals( Method.XHTML ) ) {
286N/A return new XHTMLSerializer( format );
286N/A } else if ( _method.equals( Method.TEXT ) ) {
286N/A return new TextSerializer();
286N/A } else {
286N/A String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.SERIALIZER_DOMAIN, "MethodNotSupported", new Object[]{_method});
286N/A throw new IllegalStateException(msg);
286N/A }
286N/A }
286N/A
286N/A
286N/A protected String getSupportedMethod()
286N/A {
286N/A return _method;
286N/A }
286N/A
286N/A
286N/A}