6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2002,2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
|
|
21 |
|
|
22 |
package com.sun.org.apache.xml.internal.serialize;
|
|
23 |
|
12458
|
24 |
import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
|
16953
|
25 |
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
|
6
|
26 |
import java.io.OutputStream;
|
|
27 |
import java.io.Writer;
|
|
28 |
import java.io.UnsupportedEncodingException;
|
|
29 |
import java.util.Hashtable;
|
|
30 |
import java.util.StringTokenizer;
|
|
31 |
|
|
32 |
/**
|
|
33 |
*
|
|
34 |
*
|
|
35 |
* @author <a href="mailto:Scott_Boag/CAM/Lotus@lotus.com">Scott Boag</a>
|
|
36 |
* @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
|
|
37 |
*/
|
|
38 |
public abstract class SerializerFactory
|
|
39 |
{
|
|
40 |
|
|
41 |
|
|
42 |
public static final String FactoriesProperty = "com.sun.org.apache.xml.internal.serialize.factories";
|
|
43 |
|
|
44 |
|
|
45 |
private static Hashtable _factories = new Hashtable();
|
|
46 |
|
|
47 |
|
|
48 |
static
|
|
49 |
{
|
|
50 |
SerializerFactory factory;
|
|
51 |
String list;
|
|
52 |
StringTokenizer token;
|
|
53 |
String className;
|
|
54 |
|
|
55 |
// The default factories are always registered first,
|
|
56 |
// any factory specified in the properties file and supporting
|
|
57 |
// the same method will override the default factory.
|
|
58 |
factory = new SerializerFactoryImpl( Method.XML );
|
|
59 |
registerSerializerFactory( factory );
|
|
60 |
factory = new SerializerFactoryImpl( Method.HTML );
|
|
61 |
registerSerializerFactory( factory );
|
|
62 |
factory = new SerializerFactoryImpl( Method.XHTML );
|
|
63 |
registerSerializerFactory( factory );
|
|
64 |
factory = new SerializerFactoryImpl( Method.TEXT );
|
|
65 |
registerSerializerFactory( factory );
|
|
66 |
|
16953
|
67 |
list = SecuritySupport.getSystemProperty( FactoriesProperty );
|
6
|
68 |
if ( list != null ) {
|
|
69 |
token = new StringTokenizer( list, " ;,:" );
|
|
70 |
while ( token.hasMoreTokens() ) {
|
|
71 |
className = token.nextToken();
|
|
72 |
try {
|
12458
|
73 |
factory = (SerializerFactory) ObjectFactory.newInstance( className, true);
|
6
|
74 |
if ( _factories.containsKey( factory.getSupportedMethod() ) )
|
|
75 |
_factories.put( factory.getSupportedMethod(), factory );
|
|
76 |
} catch ( Exception except ) { }
|
|
77 |
}
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Register a serializer factory, keyed by the given
|
|
84 |
* method string.
|
|
85 |
*/
|
|
86 |
public static void registerSerializerFactory( SerializerFactory factory )
|
|
87 |
{
|
|
88 |
String method;
|
|
89 |
|
|
90 |
synchronized ( _factories ) {
|
|
91 |
method = factory.getSupportedMethod();
|
|
92 |
_factories.put( method, factory );
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Register a serializer factory, keyed by the given
|
|
99 |
* method string.
|
|
100 |
*/
|
|
101 |
public static SerializerFactory getSerializerFactory( String method )
|
|
102 |
{
|
|
103 |
return (SerializerFactory) _factories.get( method );
|
|
104 |
}
|
|
105 |
|
|
106 |
|
|
107 |
/**
|
|
108 |
* Returns the method supported by this factory and used to register
|
|
109 |
* the factory. This call is required so factories can be added from
|
|
110 |
* a properties file by knowing only the class name. This method is
|
|
111 |
* protected, it is only required by this class but must be implemented
|
|
112 |
* in derived classes.
|
|
113 |
*/
|
|
114 |
protected abstract String getSupportedMethod();
|
|
115 |
|
|
116 |
|
|
117 |
/**
|
|
118 |
* Create a new serializer based on the {@link OutputFormat}.
|
|
119 |
* If this method is used to create the serializer, the {@link
|
|
120 |
* Serializer#setOutputByteStream} or {@link Serializer#setOutputCharStream}
|
|
121 |
* methods must be called before serializing a document.
|
|
122 |
*/
|
|
123 |
public abstract Serializer makeSerializer(OutputFormat format);
|
|
124 |
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Create a new serializer, based on the {@link OutputFormat} and
|
|
128 |
* using the writer as the output character stream. If this
|
|
129 |
* method is used, the encoding property will be ignored.
|
|
130 |
*/
|
|
131 |
public abstract Serializer makeSerializer( Writer writer,
|
|
132 |
OutputFormat format );
|
|
133 |
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Create a new serializer, based on the {@link OutputFormat} and
|
|
137 |
* using the output byte stream and the encoding specified in the
|
|
138 |
* output format.
|
|
139 |
*
|
|
140 |
* @throws UnsupportedEncodingException The specified encoding is
|
|
141 |
* not supported
|
|
142 |
*/
|
|
143 |
public abstract Serializer makeSerializer( OutputStream output,
|
|
144 |
OutputFormat format )
|
|
145 |
throws UnsupportedEncodingException;
|
|
146 |
|
|
147 |
|
|
148 |
}
|