001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 /*
019 * $Id: SerializerFactory.java 468642 2006-10-28 06:55:10Z minchau $
020 */
021 package org.apache.xalan.serialize;
022
023 import java.io.IOException;
024 import java.io.OutputStream;
025 import java.io.Writer;
026 import java.util.Properties;
027
028 import org.w3c.dom.Node;
029 import org.xml.sax.ContentHandler;
030
031 /**
032 * Factory for creating serializers.
033 * @deprecated The new class to use is
034 * org.apache.xml.serializer.SerializerFactory
035 */
036 public abstract class SerializerFactory
037 {
038
039 private SerializerFactory()
040 {
041 }
042 /**
043 * Returns a serializer for the specified output method. Returns
044 * null if no implementation exists that supports the specified
045 * output method. For a list of the default output methods see
046 * {@link org.apache.xml.serializer.Method}.
047 *
048 * @param format The output format
049 * @return A suitable serializer, or null
050 * @throws IllegalArgumentException (apparently -sc) if method is
051 * null or an appropriate serializer can't be found
052 * @throws WrappedRuntimeException (apparently -sc) if an
053 * exception is thrown while trying to find serializer
054 * @deprecated Use org.apache.xml.serializer.SerializerFactory
055 */
056 public static Serializer getSerializer(Properties format)
057 {
058 org.apache.xml.serializer.Serializer ser;
059 ser = org.apache.xml.serializer.SerializerFactory.getSerializer(format);
060 SerializerFactory.SerializerWrapper si = new SerializerWrapper(ser);
061 return si;
062
063 }
064
065 /**
066 * This class just exists to wrap a new Serializer in the new package by
067 * an old one.
068 * @deprecated
069 */
070
071 private static class SerializerWrapper implements Serializer
072 {
073 private final org.apache.xml.serializer.Serializer m_serializer;
074 private DOMSerializer m_old_DOMSerializer;
075
076 SerializerWrapper(org.apache.xml.serializer.Serializer ser)
077 {
078 m_serializer = ser;
079
080 }
081
082 public void setOutputStream(OutputStream output)
083 {
084 m_serializer.setOutputStream(output);
085 }
086
087 public OutputStream getOutputStream()
088 {
089 return m_serializer.getOutputStream();
090 }
091
092 public void setWriter(Writer writer)
093 {
094 m_serializer.setWriter(writer);
095 }
096
097 public Writer getWriter()
098 {
099 return m_serializer.getWriter();
100 }
101
102 public void setOutputFormat(Properties format)
103 {
104 m_serializer.setOutputFormat(format);
105 }
106
107 public Properties getOutputFormat()
108 {
109 return m_serializer.getOutputFormat();
110 }
111
112 public ContentHandler asContentHandler() throws IOException
113 {
114 return m_serializer.asContentHandler();
115 }
116
117 /**
118 * @return an old style DOMSerializer that wraps a new one.
119 * @see org.apache.xalan.serialize.Serializer#asDOMSerializer()
120 */
121 public DOMSerializer asDOMSerializer() throws IOException
122 {
123 if (m_old_DOMSerializer == null)
124 {
125 m_old_DOMSerializer =
126 new DOMSerializerWrapper(m_serializer.asDOMSerializer());
127 }
128 return m_old_DOMSerializer;
129 }
130 /**
131 * @see org.apache.xalan.serialize.Serializer#reset()
132 */
133 public boolean reset()
134 {
135 return m_serializer.reset();
136 }
137
138 }
139
140 /**
141 * This class just wraps a new DOMSerializer with an old style one for
142 * migration purposes.
143 *
144 */
145 private static class DOMSerializerWrapper implements DOMSerializer
146 {
147 private final org.apache.xml.serializer.DOMSerializer m_dom;
148 DOMSerializerWrapper(org.apache.xml.serializer.DOMSerializer domser)
149 {
150 m_dom = domser;
151 }
152
153 public void serialize(Node node) throws IOException
154 {
155 m_dom.serialize(node);
156 }
157 }
158
159 }