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