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/Aimport com.sun.org.apache.xerces.internal.utils.ObjectFactory;
524N/Aimport com.sun.org.apache.xerces.internal.utils.SecuritySupport;
286N/Aimport java.io.OutputStream;
286N/Aimport java.io.Writer;
286N/Aimport java.io.UnsupportedEncodingException;
286N/Aimport java.util.Hashtable;
286N/Aimport java.util.StringTokenizer;
286N/A
286N/A/**
286N/A *
286N/A *
286N/A * @version $Revision: 1.6 $ $Date: 2010-11-01 04:40:36 $
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/Apublic abstract class SerializerFactory
286N/A{
286N/A
286N/A
286N/A public static final String FactoriesProperty = "com.sun.org.apache.xml.internal.serialize.factories";
286N/A
286N/A
286N/A private static Hashtable _factories = new Hashtable();
286N/A
286N/A
286N/A static
286N/A {
286N/A SerializerFactory factory;
286N/A String list;
286N/A StringTokenizer token;
286N/A String className;
286N/A
286N/A // The default factories are always registered first,
286N/A // any factory specified in the properties file and supporting
286N/A // the same method will override the default factory.
286N/A factory = new SerializerFactoryImpl( Method.XML );
286N/A registerSerializerFactory( factory );
286N/A factory = new SerializerFactoryImpl( Method.HTML );
286N/A registerSerializerFactory( factory );
286N/A factory = new SerializerFactoryImpl( Method.XHTML );
286N/A registerSerializerFactory( factory );
286N/A factory = new SerializerFactoryImpl( Method.TEXT );
286N/A registerSerializerFactory( factory );
286N/A
524N/A list = SecuritySupport.getSystemProperty( FactoriesProperty );
286N/A if ( list != null ) {
286N/A token = new StringTokenizer( list, " ;,:" );
286N/A while ( token.hasMoreTokens() ) {
286N/A className = token.nextToken();
286N/A try {
286N/A factory = (SerializerFactory) ObjectFactory.newInstance( className, true);
286N/A if ( _factories.containsKey( factory.getSupportedMethod() ) )
286N/A _factories.put( factory.getSupportedMethod(), factory );
286N/A } catch ( Exception except ) { }
286N/A }
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * Register a serializer factory, keyed by the given
286N/A * method string.
286N/A */
286N/A public static void registerSerializerFactory( SerializerFactory factory )
286N/A {
286N/A String method;
286N/A
286N/A synchronized ( _factories ) {
286N/A method = factory.getSupportedMethod();
286N/A _factories.put( method, factory );
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * Register a serializer factory, keyed by the given
286N/A * method string.
286N/A */
286N/A public static SerializerFactory getSerializerFactory( String method )
286N/A {
286N/A return (SerializerFactory) _factories.get( method );
286N/A }
286N/A
286N/A
286N/A /**
286N/A * Returns the method supported by this factory and used to register
286N/A * the factory. This call is required so factories can be added from
286N/A * a properties file by knowing only the class name. This method is
286N/A * protected, it is only required by this class but must be implemented
286N/A * in derived classes.
286N/A */
286N/A protected abstract String getSupportedMethod();
286N/A
286N/A
286N/A /**
286N/A * Create a new serializer based on the {@link OutputFormat}.
286N/A * If this method is used to create the serializer, the {@link
286N/A * Serializer#setOutputByteStream} or {@link Serializer#setOutputCharStream}
286N/A * methods must be called before serializing a document.
286N/A */
286N/A public abstract Serializer makeSerializer(OutputFormat format);
286N/A
286N/A
286N/A /**
286N/A * Create a new serializer, based on the {@link OutputFormat} and
286N/A * using the writer as the output character stream. If this
286N/A * method is used, the encoding property will be ignored.
286N/A */
286N/A public abstract Serializer makeSerializer( Writer writer,
286N/A OutputFormat format );
286N/A
286N/A
286N/A /**
286N/A * Create a new serializer, based on the {@link OutputFormat} and
286N/A * using the output byte stream and the encoding specified in the
286N/A * output format.
286N/A *
286N/A * @throws UnsupportedEncodingException The specified encoding is
286N/A * not supported
286N/A */
286N/A public abstract Serializer makeSerializer( OutputStream output,
286N/A OutputFormat format )
286N/A throws UnsupportedEncodingException;
286N/A
286N/A
286N/A}