01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xml.serialize;
19:
20: import java.io.OutputStream;
21: import java.io.Writer;
22: import java.io.UnsupportedEncodingException;
23: import org.apache.xerces.dom.DOMMessageFormatter;
24:
25: /**
26: * Default serializer factory can construct serializers for the three
27: * markup serializers (XML, HTML, XHTML ).
28: *
29: * @deprecated This class was deprecated in Xerces 2.9.0. It is recommended
30: * that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation
31: * API for XML (TrAX) for serializing XML and HTML. See the Xerces documentation for more
32: * information.
33: * @version $Revision: 476047 $ $Date: 2006-11-16 23:27:45 -0500 (Thu, 16 Nov 2006) $
34: * @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a>
35: * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
36: */
37: final class SerializerFactoryImpl extends SerializerFactory {
38:
39: private String _method;
40:
41: SerializerFactoryImpl(String method) {
42: _method = method;
43: if (!_method.equals(Method.XML) && !_method.equals(Method.HTML)
44: && !_method.equals(Method.XHTML)
45: && !_method.equals(Method.TEXT)) {
46: String msg = DOMMessageFormatter.formatMessage(
47: DOMMessageFormatter.SERIALIZER_DOMAIN,
48: "MethodNotSupported", new Object[] { method });
49: throw new IllegalArgumentException(msg);
50: }
51: }
52:
53: public Serializer makeSerializer(OutputFormat format) {
54: Serializer serializer;
55:
56: serializer = getSerializer(format);
57: serializer.setOutputFormat(format);
58: return serializer;
59: }
60:
61: public Serializer makeSerializer(Writer writer, OutputFormat format) {
62: Serializer serializer;
63:
64: serializer = getSerializer(format);
65: serializer.setOutputCharStream(writer);
66: return serializer;
67: }
68:
69: public Serializer makeSerializer(OutputStream output,
70: OutputFormat format) throws UnsupportedEncodingException {
71: Serializer serializer;
72:
73: serializer = getSerializer(format);
74: serializer.setOutputByteStream(output);
75: return serializer;
76: }
77:
78: private Serializer getSerializer(OutputFormat format) {
79: if (_method.equals(Method.XML)) {
80: return new XMLSerializer(format);
81: } else if (_method.equals(Method.HTML)) {
82: return new HTMLSerializer(format);
83: } else if (_method.equals(Method.XHTML)) {
84: return new XHTMLSerializer(format);
85: } else if (_method.equals(Method.TEXT)) {
86: return new TextSerializer();
87: } else {
88: String msg = DOMMessageFormatter.formatMessage(
89: DOMMessageFormatter.SERIALIZER_DOMAIN,
90: "MethodNotSupported", new Object[] { _method });
91: throw new IllegalStateException(msg);
92: }
93: }
94:
95: protected String getSupportedMethod() {
96: return _method;
97: }
98:
99: }
|