author | joehw |
Wed, 04 Oct 2017 10:54:18 -0700 | |
changeset 47312 | d4f959806fe9 |
parent 47216 | 71c04702a3d5 |
child 47359 | e1a6c0168741 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
47312 | 2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
3 |
* @LastModified: Sep 2017 |
|
12005 | 4 |
*/ |
5 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
12005 | 12 |
* |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
12005 | 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 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
12005 | 22 |
package com.sun.org.apache.xml.internal.serializer; |
23 |
||
23954 | 24 |
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey; |
25 |
import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; |
|
26 |
import com.sun.org.apache.xml.internal.serializer.utils.Utils; |
|
27 |
import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException; |
|
12005 | 28 |
import java.io.BufferedReader; |
29 |
import java.io.InputStream; |
|
30 |
import java.io.InputStreamReader; |
|
31 |
import java.io.UnsupportedEncodingException; |
|
32 |
import java.net.URL; |
|
33 |
import java.util.Enumeration; |
|
34 |
import java.util.HashMap; |
|
23954 | 35 |
import java.util.Locale; |
12005 | 36 |
import java.util.PropertyResourceBundle; |
37 |
import java.util.ResourceBundle; |
|
38 |
import javax.xml.transform.TransformerException; |
|
47312 | 39 |
import jdk.xml.internal.SecuritySupport; |
12005 | 40 |
|
41 |
/** |
|
42 |
* This class provides services that tell if a character should have |
|
43 |
* special treatement, such as entity reference substitution or normalization |
|
44 |
* of a newline character. It also provides character to entity reference |
|
45 |
* lookup. |
|
46 |
* |
|
47 |
* DEVELOPERS: See Known Issue in the constructor. |
|
48 |
* |
|
49 |
* @xsl.usage internal |
|
50 |
*/ |
|
51 |
final class CharInfo |
|
52 |
{ |
|
53 |
/** Given a character, lookup a String to output (e.g. a decorated entity reference). */ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
54 |
private HashMap m_charToString = new HashMap(); |
12005 | 55 |
|
56 |
/** |
|
57 |
* The name of the HTML entities file. |
|
58 |
* If specified, the file will be resource loaded with the default class loader. |
|
59 |
*/ |
|
60 |
public static final String HTML_ENTITIES_RESOURCE = |
|
61 |
"com.sun.org.apache.xml.internal.serializer.HTMLEntities"; |
|
62 |
||
63 |
/** |
|
64 |
* The name of the XML entities file. |
|
65 |
* If specified, the file will be resource loaded with the default class loader. |
|
66 |
*/ |
|
67 |
public static final String XML_ENTITIES_RESOURCE = |
|
68 |
"com.sun.org.apache.xml.internal.serializer.XMLEntities"; |
|
69 |
||
70 |
/** The horizontal tab character, which the parser should always normalize. */ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
71 |
public static final char S_HORIZONAL_TAB = 0x09; |
12005 | 72 |
|
73 |
/** The linefeed character, which the parser should always normalize. */ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
74 |
public static final char S_LINEFEED = 0x0A; |
12005 | 75 |
|
76 |
/** The carriage return character, which the parser should always normalize. */ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
77 |
public static final char S_CARRIAGERETURN = 0x0D; |
12005 | 78 |
|
79 |
/** This flag is an optimization for HTML entities. It false if entities |
|
80 |
* other than quot (34), amp (38), lt (60) and gt (62) are defined |
|
81 |
* in the range 0 to 127. |
|
82 |
* @xsl.usage internal |
|
83 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
84 |
final boolean onlyQuotAmpLtGt; |
12005 | 85 |
|
86 |
/** Copy the first 0,1 ... ASCII_MAX values into an array */ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
87 |
private static final int ASCII_MAX = 128; |
12005 | 88 |
|
89 |
/** Array of values is faster access than a set of bits |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
90 |
* to quickly check ASCII characters in attribute values. |
12005 | 91 |
*/ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
92 |
private boolean[] isSpecialAttrASCII = new boolean[ASCII_MAX]; |
12005 | 93 |
|
94 |
/** Array of values is faster access than a set of bits |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
95 |
* to quickly check ASCII characters in text nodes. |
12005 | 96 |
*/ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
97 |
private boolean[] isSpecialTextASCII = new boolean[ASCII_MAX]; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
98 |
|
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
99 |
private boolean[] isCleanTextASCII = new boolean[ASCII_MAX]; |
12005 | 100 |
|
101 |
/** An array of bits to record if the character is in the set. |
|
102 |
* Although information in this array is complete, the |
|
103 |
* isSpecialAttrASCII array is used first because access to its values |
|
104 |
* is common and faster. |
|
105 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
106 |
private int array_of_bits[] = createEmptySetOfIntegers(65535); |
12005 | 107 |
|
108 |
||
109 |
// 5 for 32 bit words, 6 for 64 bit words ... |
|
110 |
/* |
|
111 |
* This constant is used to shift an integer to quickly |
|
112 |
* calculate which element its bit is stored in. |
|
113 |
* 5 for 32 bit words (int) , 6 for 64 bit words (long) |
|
114 |
*/ |
|
115 |
private static final int SHIFT_PER_WORD = 5; |
|
116 |
||
117 |
/* |
|
118 |
* A mask to get the low order bits which are used to |
|
119 |
* calculate the value of the bit within a given word, |
|
120 |
* that will represent the presence of the integer in the |
|
121 |
* set. |
|
122 |
* |
|
123 |
* 0x1F for 32 bit words (int), |
|
124 |
* or 0x3F for 64 bit words (long) |
|
125 |
*/ |
|
126 |
private static final int LOW_ORDER_BITMASK = 0x1f; |
|
127 |
||
128 |
/* |
|
129 |
* This is used for optimizing the lookup of bits representing |
|
130 |
* the integers in the set. It is the index of the first element |
|
131 |
* in the array array_of_bits[] that is not used. |
|
132 |
*/ |
|
133 |
private int firstWordNotUsed; |
|
134 |
||
135 |
||
136 |
/** |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
137 |
* Constructor that reads in a resource file that describes the mapping of |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
138 |
* characters to entity references. |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
139 |
* This constructor is private, just to force the use |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
140 |
* of the getCharInfo(entitiesResource) factory |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
141 |
* |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
142 |
* Resource files must be encoded in UTF-8 and can either be properties |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
143 |
* files with a .properties extension assumed. Alternatively, they can |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
144 |
* have the following form, with no particular extension assumed: |
12005 | 145 |
* |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
146 |
* <pre> |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
147 |
* # First char # is a comment |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
148 |
* Entity numericValue |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
149 |
* quot 34 |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
150 |
* amp 38 |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
151 |
* </pre> |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
152 |
* |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
153 |
* @param entitiesResource Name of properties or resource file that should |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
154 |
* be loaded, which describes that mapping of characters to entity |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
155 |
* references. |
12005 | 156 |
*/ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
157 |
private CharInfo(String entitiesResource, String method) |
12005 | 158 |
{ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
159 |
this(entitiesResource, method, false); |
12005 | 160 |
} |
161 |
||
162 |
private CharInfo(String entitiesResource, String method, boolean internal) |
|
163 |
{ |
|
164 |
ResourceBundle entities = null; |
|
165 |
boolean noExtraEntities = true; |
|
166 |
||
167 |
// Make various attempts to interpret the parameter as a properties |
|
168 |
// file or resource file, as follows: |
|
169 |
// |
|
170 |
// 1) attempt to load .properties file using ResourceBundle |
|
171 |
// 2) try using the class loader to find the specified file a resource |
|
172 |
// file |
|
173 |
// 3) try treating the resource a URI |
|
174 |
||
23954 | 175 |
try { |
176 |
if (internal) { |
|
12005 | 177 |
// Load entity property files by using PropertyResourceBundle, |
178 |
// cause of security issure for applets |
|
179 |
entities = PropertyResourceBundle.getBundle(entitiesResource); |
|
23954 | 180 |
} else { |
181 |
ClassLoader cl = SecuritySupport.getContextClassLoader(); |
|
182 |
if (cl != null) { |
|
183 |
entities = PropertyResourceBundle.getBundle(entitiesResource, |
|
184 |
Locale.getDefault(), cl); |
|
185 |
} |
|
186 |
} |
|
187 |
} catch (Exception e) {} |
|
12005 | 188 |
|
189 |
if (entities != null) { |
|
190 |
Enumeration keys = entities.getKeys(); |
|
191 |
while (keys.hasMoreElements()){ |
|
192 |
String name = (String) keys.nextElement(); |
|
193 |
String value = entities.getString(name); |
|
194 |
int code = Integer.parseInt(value); |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
195 |
defineEntity(name, (char) code); |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
196 |
if (extraEntity(code)) |
12005 | 197 |
noExtraEntities = false; |
198 |
} |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
199 |
set(S_LINEFEED); |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
200 |
set(S_CARRIAGERETURN); |
12005 | 201 |
} else { |
202 |
InputStream is = null; |
|
23954 | 203 |
String err = null; |
12005 | 204 |
|
205 |
// Load user specified resource file by using URL loading, it |
|
206 |
// requires a valid URI as parameter |
|
207 |
try { |
|
208 |
if (internal) { |
|
209 |
is = CharInfo.class.getResourceAsStream(entitiesResource); |
|
210 |
} else { |
|
23954 | 211 |
ClassLoader cl = SecuritySupport.getContextClassLoader(); |
212 |
if (cl != null) { |
|
213 |
try { |
|
214 |
is = cl.getResourceAsStream(entitiesResource); |
|
215 |
} catch (Exception e) { |
|
216 |
err = e.getMessage(); |
|
217 |
} |
|
12005 | 218 |
} |
219 |
||
220 |
if (is == null) { |
|
221 |
try { |
|
222 |
URL url = new URL(entitiesResource); |
|
223 |
is = url.openStream(); |
|
23954 | 224 |
} catch (Exception e) { |
225 |
err = e.getMessage(); |
|
226 |
} |
|
12005 | 227 |
} |
228 |
} |
|
229 |
||
230 |
if (is == null) { |
|
231 |
throw new RuntimeException( |
|
232 |
Utils.messages.createMessage( |
|
233 |
MsgKey.ER_RESOURCE_COULD_NOT_FIND, |
|
23954 | 234 |
new Object[] {entitiesResource, err})); |
12005 | 235 |
} |
236 |
||
237 |
// Fix Bugzilla#4000: force reading in UTF-8 |
|
238 |
// This creates the de facto standard that Xalan's resource |
|
239 |
// files must be encoded in UTF-8. This should work in all |
|
240 |
// JVMs. |
|
241 |
// |
|
242 |
// %REVIEW% KNOWN ISSUE: IT FAILS IN MICROSOFT VJ++, which |
|
243 |
// didn't implement the UTF-8 encoding. Theoretically, we should |
|
244 |
// simply let it fail in that case, since the JVM is obviously |
|
245 |
// broken if it doesn't support such a basic standard. But |
|
246 |
// since there are still some users attempting to use VJ++ for |
|
247 |
// development, we have dropped in a fallback which makes a |
|
248 |
// second attempt using the platform's default encoding. In VJ++ |
|
249 |
// this is apparently ASCII, which is subset of UTF-8... and |
|
250 |
// since the strings we'll be reading here are also primarily |
|
251 |
// limited to the 7-bit ASCII range (at least, in English |
|
252 |
// versions of Xalan), this should work well enough to keep us |
|
253 |
// on the air until we're ready to officially decommit from |
|
254 |
// VJ++. |
|
255 |
||
256 |
BufferedReader reader; |
|
257 |
try { |
|
258 |
reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
|
259 |
} catch (UnsupportedEncodingException e) { |
|
260 |
reader = new BufferedReader(new InputStreamReader(is)); |
|
261 |
} |
|
262 |
||
263 |
String line = reader.readLine(); |
|
264 |
||
265 |
while (line != null) { |
|
266 |
if (line.length() == 0 || line.charAt(0) == '#') { |
|
267 |
line = reader.readLine(); |
|
268 |
||
269 |
continue; |
|
270 |
} |
|
271 |
||
272 |
int index = line.indexOf(' '); |
|
273 |
||
274 |
if (index > 1) { |
|
275 |
String name = line.substring(0, index); |
|
276 |
||
277 |
++index; |
|
278 |
||
279 |
if (index < line.length()) { |
|
280 |
String value = line.substring(index); |
|
281 |
index = value.indexOf(' '); |
|
282 |
||
283 |
if (index > 0) { |
|
284 |
value = value.substring(0, index); |
|
285 |
} |
|
286 |
||
287 |
int code = Integer.parseInt(value); |
|
288 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
289 |
defineEntity(name, (char) code); |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
290 |
if (extraEntity(code)) |
12005 | 291 |
noExtraEntities = false; |
292 |
} |
|
293 |
} |
|
294 |
||
295 |
line = reader.readLine(); |
|
296 |
} |
|
297 |
||
298 |
is.close(); |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
299 |
set(S_LINEFEED); |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
300 |
set(S_CARRIAGERETURN); |
12005 | 301 |
} catch (Exception e) { |
302 |
throw new RuntimeException( |
|
303 |
Utils.messages.createMessage( |
|
304 |
MsgKey.ER_RESOURCE_COULD_NOT_LOAD, |
|
305 |
new Object[] { entitiesResource, |
|
306 |
e.toString(), |
|
307 |
entitiesResource, |
|
308 |
e.toString()})); |
|
309 |
} finally { |
|
310 |
if (is != null) { |
|
311 |
try { |
|
312 |
is.close(); |
|
313 |
} catch (Exception except) {} |
|
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
318 |
/* initialize the array isCleanTextASCII[] with a cache of values |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
319 |
* for use by ToStream.character(char[], int , int) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
320 |
* and the array isSpecialTextASCII[] with the opposite values |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
321 |
* (all in the name of performance!) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
322 |
*/ |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
323 |
for (int ch = 0; ch <ASCII_MAX; ch++) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
324 |
if((((0x20 <= ch || (0x0A == ch || 0x0D == ch || 0x09 == ch))) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
325 |
&& (!get(ch))) || ('"' == ch)) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
326 |
{ |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
327 |
isCleanTextASCII[ch] = true; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
328 |
isSpecialTextASCII[ch] = false; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
329 |
} |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
330 |
else { |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
331 |
isCleanTextASCII[ch] = false; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
332 |
isSpecialTextASCII[ch] = true; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
333 |
} |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
334 |
|
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
335 |
|
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
336 |
|
12005 | 337 |
onlyQuotAmpLtGt = noExtraEntities; |
338 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
339 |
// initialize the array with a cache of the BitSet values |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
340 |
for (int i=0; i<ASCII_MAX; i++) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
341 |
isSpecialAttrASCII[i] = get(i); |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
342 |
|
12005 | 343 |
/* Now that we've used get(ch) just above to initialize the |
344 |
* two arrays we will change by adding a tab to the set of |
|
345 |
* special chars for XML (but not HTML!). |
|
346 |
* We do this because a tab is always a |
|
347 |
* special character in an XML attribute, |
|
348 |
* but only a special character in XML text |
|
349 |
* if it has an entity defined for it. |
|
350 |
* This is the reason for this delay. |
|
351 |
*/ |
|
352 |
if (Method.XML.equals(method)) |
|
353 |
{ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
354 |
isSpecialAttrASCII[S_HORIZONAL_TAB] = true; |
12005 | 355 |
} |
356 |
} |
|
357 |
||
358 |
/** |
|
359 |
* Defines a new character reference. The reference's name and value are |
|
360 |
* supplied. Nothing happens if the character reference is already defined. |
|
361 |
* <p>Unlike internal entities, character references are a string to single |
|
362 |
* character mapping. They are used to map non-ASCII characters both on |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
363 |
* parsing and printing, primarily for HTML documents. '<amp;' is an |
12005 | 364 |
* example of a character reference.</p> |
365 |
* |
|
366 |
* @param name The entity's name |
|
367 |
* @param value The entity's value |
|
368 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
369 |
private void defineEntity(String name, char value) |
12005 | 370 |
{ |
371 |
StringBuilder sb = new StringBuilder("&"); |
|
372 |
sb.append(name); |
|
373 |
sb.append(';'); |
|
374 |
String entityString = sb.toString(); |
|
375 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
376 |
defineChar2StringMapping(entityString, value); |
12005 | 377 |
} |
378 |
||
379 |
/** |
|
380 |
* Map a character to a String. For example given |
|
381 |
* the character '>' this method would return the fully decorated |
|
382 |
* entity name "<". |
|
383 |
* Strings for entity references are loaded from a properties file, |
|
384 |
* but additional mappings defined through calls to defineChar2String() |
|
385 |
* are possible. Such entity reference mappings could be over-ridden. |
|
386 |
* |
|
387 |
* This is reusing a stored key object, in an effort to avoid |
|
388 |
* heap activity. Unfortunately, that introduces a threading risk. |
|
389 |
* Simplest fix for now is to make it a synchronized method, or to give |
|
390 |
* up the reuse; I see very little performance difference between them. |
|
391 |
* Long-term solution would be to replace the hashtable with a sparse array |
|
392 |
* keyed directly from the character's integer value; see DTM's |
|
393 |
* string pool for a related solution. |
|
394 |
* |
|
395 |
* @param value The character that should be resolved to |
|
396 |
* a String, e.g. resolve '>' to "<". |
|
397 |
* |
|
398 |
* @return The String that the character is mapped to, or null if not found. |
|
399 |
* @xsl.usage internal |
|
400 |
*/ |
|
401 |
String getOutputStringForChar(char value) |
|
402 |
{ |
|
403 |
CharKey charKey = new CharKey(); |
|
404 |
charKey.setChar(value); |
|
405 |
return (String) m_charToString.get(charKey); |
|
406 |
} |
|
407 |
||
408 |
/** |
|
409 |
* Tell if the character argument that is from |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
410 |
* an attribute value should have special treatment. |
12005 | 411 |
* |
412 |
* @param value the value of a character that is in an attribute value |
|
413 |
* @return true if the character should have any special treatment, |
|
414 |
* such as when writing out attribute values, |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
415 |
* or entity references. |
12005 | 416 |
* @xsl.usage internal |
417 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
418 |
final boolean isSpecialAttrChar(int value) |
12005 | 419 |
{ |
420 |
// for performance try the values in the boolean array first, |
|
421 |
// this is faster access than the BitSet for common ASCII values |
|
422 |
||
423 |
if (value < ASCII_MAX) |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
424 |
return isSpecialAttrASCII[value]; |
12005 | 425 |
|
426 |
// rather than java.util.BitSet, our private |
|
427 |
// implementation is faster (and less general). |
|
428 |
return get(value); |
|
429 |
} |
|
430 |
||
431 |
/** |
|
432 |
* Tell if the character argument that is from a |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
433 |
* text node should have special treatment. |
12005 | 434 |
* |
435 |
* @param value the value of a character that is in a text node |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
436 |
* @return true if the character should have any special treatment, |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
437 |
* such as when writing out attribute values, |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
438 |
* or entity references. |
12005 | 439 |
* @xsl.usage internal |
440 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
441 |
final boolean isSpecialTextChar(int value) |
12005 | 442 |
{ |
443 |
// for performance try the values in the boolean array first, |
|
444 |
// this is faster access than the BitSet for common ASCII values |
|
445 |
||
446 |
if (value < ASCII_MAX) |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
447 |
return isSpecialTextASCII[value]; |
12005 | 448 |
|
449 |
// rather than java.util.BitSet, our private |
|
450 |
// implementation is faster (and less general). |
|
451 |
return get(value); |
|
452 |
} |
|
453 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
454 |
/** |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
455 |
* This method is used to determine if an ASCII character in |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
456 |
* a text node (not an attribute value) is "clean". |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
457 |
* @param value the character to check (0 to 127). |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
458 |
* @return true if the character can go to the writer as-is |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
459 |
* @xsl.usage internal |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
460 |
*/ |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
461 |
final boolean isTextASCIIClean(int value) |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
462 |
{ |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
463 |
return isCleanTextASCII[value]; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
464 |
} |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
465 |
|
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
466 |
|
23954 | 467 |
/** |
468 |
* Read an internal resource file that describes the mapping of |
|
469 |
* characters to entity references; Construct a CharInfo object. |
|
470 |
* |
|
471 |
* @param entitiesFileName Name of entities resource file that should |
|
472 |
* be loaded, which describes the mapping of characters to entity references. |
|
473 |
* @param method the output method type, which should be one of "xml", "html", and "text". |
|
474 |
* @return an instance of CharInfo |
|
475 |
* |
|
476 |
* @xsl.usage internal |
|
477 |
*/ |
|
478 |
static CharInfo getCharInfoInternal(String entitiesFileName, String method) |
|
479 |
{ |
|
480 |
CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName); |
|
481 |
if (charInfo != null) { |
|
482 |
return charInfo; |
|
483 |
} |
|
484 |
||
485 |
charInfo = new CharInfo(entitiesFileName, method, true); |
|
486 |
m_getCharInfoCache.put(entitiesFileName, charInfo); |
|
487 |
return charInfo; |
|
12005 | 488 |
} |
489 |
||
490 |
/** |
|
23954 | 491 |
* Constructs a CharInfo object using the following process to try reading |
492 |
* the entitiesFileName parameter: |
|
12005 | 493 |
* |
23954 | 494 |
* 1) attempt to load it as a ResourceBundle |
495 |
* 2) try using the class loader to find the specified file |
|
496 |
* 3) try opening it as an URI |
|
497 |
* |
|
498 |
* In case of 2 and 3, the resource file must be encoded in UTF-8 and have the |
|
499 |
* following format: |
|
12005 | 500 |
* <pre> |
501 |
* # First char # is a comment |
|
502 |
* Entity numericValue |
|
503 |
* quot 34 |
|
504 |
* amp 38 |
|
505 |
* </pre> |
|
506 |
* |
|
23954 | 507 |
* @param entitiesFileName Name of entities resource file that should |
508 |
* be loaded, which describes the mapping of characters to entity references. |
|
509 |
* @param method the output method type, which should be one of "xml", "html", and "text". |
|
510 |
* @return an instance of CharInfo |
|
12005 | 511 |
*/ |
512 |
static CharInfo getCharInfo(String entitiesFileName, String method) |
|
513 |
{ |
|
514 |
try { |
|
23954 | 515 |
return new CharInfo(entitiesFileName, method, false); |
12005 | 516 |
} catch (Exception e) {} |
517 |
||
518 |
String absoluteEntitiesFileName; |
|
519 |
||
520 |
if (entitiesFileName.indexOf(':') < 0) { |
|
521 |
absoluteEntitiesFileName = |
|
522 |
SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName); |
|
523 |
} else { |
|
524 |
try { |
|
525 |
absoluteEntitiesFileName = |
|
526 |
SystemIDResolver.getAbsoluteURI(entitiesFileName, null); |
|
527 |
} catch (TransformerException te) { |
|
528 |
throw new WrappedRuntimeException(te); |
|
529 |
} |
|
530 |
} |
|
531 |
||
23954 | 532 |
return new CharInfo(absoluteEntitiesFileName, method, false); |
12005 | 533 |
} |
534 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
535 |
/** Table of user-specified char infos. */ |
12005 | 536 |
private static HashMap m_getCharInfoCache = new HashMap(); |
537 |
||
538 |
/** |
|
539 |
* Returns the array element holding the bit value for the |
|
540 |
* given integer |
|
541 |
* @param i the integer that might be in the set of integers |
|
542 |
* |
|
543 |
*/ |
|
544 |
private static int arrayIndex(int i) { |
|
545 |
return (i >> SHIFT_PER_WORD); |
|
546 |
} |
|
547 |
||
548 |
/** |
|
549 |
* For a given integer in the set it returns the single bit |
|
550 |
* value used within a given word that represents whether |
|
551 |
* the integer is in the set or not. |
|
552 |
*/ |
|
553 |
private static int bit(int i) { |
|
554 |
int ret = (1 << (i & LOW_ORDER_BITMASK)); |
|
555 |
return ret; |
|
556 |
} |
|
557 |
||
558 |
/** |
|
559 |
* Creates a new empty set of integers (characters) |
|
560 |
* @param max the maximum integer to be in the set. |
|
561 |
*/ |
|
562 |
private int[] createEmptySetOfIntegers(int max) { |
|
563 |
firstWordNotUsed = 0; // an optimization |
|
564 |
||
565 |
int[] arr = new int[arrayIndex(max - 1) + 1]; |
|
566 |
return arr; |
|
567 |
||
568 |
} |
|
569 |
||
570 |
/** |
|
571 |
* Adds the integer (character) to the set of integers. |
|
572 |
* @param i the integer to add to the set, valid values are |
|
573 |
* 0, 1, 2 ... up to the maximum that was specified at |
|
574 |
* the creation of the set. |
|
575 |
*/ |
|
576 |
private final void set(int i) { |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
577 |
setASCIIdirty(i); |
12005 | 578 |
|
579 |
int j = (i >> SHIFT_PER_WORD); // this word is used |
|
580 |
int k = j + 1; |
|
581 |
||
582 |
if(firstWordNotUsed < k) // for optimization purposes. |
|
583 |
firstWordNotUsed = k; |
|
584 |
||
585 |
array_of_bits[j] |= (1 << (i & LOW_ORDER_BITMASK)); |
|
586 |
} |
|
587 |
||
588 |
||
589 |
/** |
|
590 |
* Return true if the integer (character)is in the set of integers. |
|
591 |
* |
|
592 |
* This implementation uses an array of integers with 32 bits per |
|
593 |
* integer. If a bit is set to 1 the corresponding integer is |
|
594 |
* in the set of integers. |
|
595 |
* |
|
596 |
* @param i an integer that is tested to see if it is the |
|
597 |
* set of integers, or not. |
|
598 |
*/ |
|
599 |
private final boolean get(int i) { |
|
600 |
||
601 |
boolean in_the_set = false; |
|
602 |
int j = (i >> SHIFT_PER_WORD); // wordIndex(i) |
|
603 |
// an optimization here, ... a quick test to see |
|
604 |
// if this integer is beyond any of the words in use |
|
605 |
if(j < firstWordNotUsed) |
|
606 |
in_the_set = (array_of_bits[j] & |
|
607 |
(1 << (i & LOW_ORDER_BITMASK)) |
|
608 |
) != 0; // 0L for 64 bit words |
|
609 |
return in_the_set; |
|
610 |
} |
|
611 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
612 |
// record if there are any entities other than |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
613 |
// quot, amp, lt, gt (probably user defined) |
12005 | 614 |
/** |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
615 |
* @return true if the entity |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
616 |
* @param code The value of the character that has an entity defined |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
617 |
* for it. |
12005 | 618 |
*/ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
619 |
private boolean extraEntity(int entityValue) |
12005 | 620 |
{ |
621 |
boolean extra = false; |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
622 |
if (entityValue < 128) |
12005 | 623 |
{ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
624 |
switch (entityValue) |
12005 | 625 |
{ |
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
626 |
case 34 : // quot |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
627 |
case 38 : // amp |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
628 |
case 60 : // lt |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
629 |
case 62 : // gt |
12005 | 630 |
break; |
631 |
default : // other entity in range 0 to 127 |
|
632 |
extra = true; |
|
633 |
} |
|
634 |
} |
|
635 |
return extra; |
|
636 |
} |
|
637 |
||
638 |
/** |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
639 |
* If the character is a printable ASCII character then |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
640 |
* mark it as not clean and needing replacement with |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
641 |
* a String on output. |
12005 | 642 |
* @param ch |
643 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
644 |
private void setASCIIdirty(int j) |
12005 | 645 |
{ |
646 |
if (0 <= j && j < ASCII_MAX) |
|
647 |
{ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
648 |
isCleanTextASCII[j] = false; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
649 |
isSpecialTextASCII[j] = true; |
12005 | 650 |
} |
651 |
} |
|
652 |
||
653 |
/** |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
654 |
* If the character is a printable ASCII character then |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
655 |
* mark it as and not needing replacement with |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
656 |
* a String on output. |
12005 | 657 |
* @param ch |
658 |
*/ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
659 |
private void setASCIIclean(int j) |
12005 | 660 |
{ |
661 |
if (0 <= j && j < ASCII_MAX) |
|
662 |
{ |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
663 |
isCleanTextASCII[j] = true; |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
664 |
isSpecialTextASCII[j] = false; |
12005 | 665 |
} |
666 |
} |
|
667 |
||
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
668 |
private void defineChar2StringMapping(String outputString, char inputChar) |
12005 | 669 |
{ |
670 |
CharKey character = new CharKey(inputChar); |
|
671 |
m_charToString.put(character, outputString); |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
672 |
set(inputChar); |
12005 | 673 |
} |
674 |
||
675 |
/** |
|
676 |
* Simple class for fast lookup of char values, when used with |
|
677 |
* hashtables. You can set the char, then use it as a key. |
|
678 |
* |
|
12902
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
679 |
* This class is a copy of the one in com.sun.org.apache.xml.internal.utils. |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
680 |
* It exists to cut the serializers dependancy on that package. |
0a840d92fa30
7151118: Regressions on 7u4 b11 comp. 7u4 b06 on specjvm2008.xml.transform subbenchmark
joehw
parents:
12458
diff
changeset
|
681 |
* |
12005 | 682 |
* @xsl.usage internal |
683 |
*/ |
|
684 |
private static class CharKey extends Object |
|
685 |
{ |
|
686 |
||
687 |
/** String value */ |
|
688 |
private char m_char; |
|
689 |
||
690 |
/** |
|
691 |
* Constructor CharKey |
|
692 |
* |
|
693 |
* @param key char value of this object. |
|
694 |
*/ |
|
695 |
public CharKey(char key) |
|
696 |
{ |
|
697 |
m_char = key; |
|
698 |
} |
|
699 |
||
700 |
/** |
|
701 |
* Default constructor for a CharKey. |
|
702 |
* |
|
703 |
* @param key char value of this object. |
|
704 |
*/ |
|
705 |
public CharKey() |
|
706 |
{ |
|
707 |
} |
|
708 |
||
709 |
/** |
|
710 |
* Get the hash value of the character. |
|
711 |
* |
|
712 |
* @return hash value of the character. |
|
713 |
*/ |
|
714 |
public final void setChar(char c) |
|
715 |
{ |
|
716 |
m_char = c; |
|
717 |
} |
|
718 |
||
719 |
||
720 |
||
721 |
/** |
|
722 |
* Get the hash value of the character. |
|
723 |
* |
|
724 |
* @return hash value of the character. |
|
725 |
*/ |
|
726 |
public final int hashCode() |
|
727 |
{ |
|
728 |
return (int)m_char; |
|
729 |
} |
|
730 |
||
731 |
/** |
|
732 |
* Override of equals() for this object |
|
733 |
* |
|
734 |
* @param obj to compare to |
|
735 |
* |
|
736 |
* @return True if this object equals this string value |
|
737 |
*/ |
|
738 |
public final boolean equals(Object obj) |
|
739 |
{ |
|
740 |
return ((CharKey)obj).m_char == m_char; |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
||
745 |
} |