author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58022 | 12885822f0c5 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
2 |
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
12005 | 3 |
*/ |
4 |
/* |
|
33349 | 5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
6 |
* contributor license agreements. See the NOTICE file distributed with |
|
7 |
* this work for additional information regarding copyright ownership. |
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
|
9 |
* (the "License"); you may not use this file except in compliance with |
|
10 |
* the License. You may obtain a copy of the License at |
|
12005 | 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 |
package com.sun.org.apache.xalan.internal.xsltc.trax; |
|
22 |
||
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
23 |
import com.sun.org.apache.xalan.internal.XalanConstants; |
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
24 |
import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase; |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
25 |
import com.sun.org.apache.xalan.internal.utils.ObjectFactory; |
20968 | 26 |
import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; |
47312 | 27 |
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager.Property; |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
28 |
import com.sun.org.apache.xalan.internal.utils.XMLSecurityPropertyManager; |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
29 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
30 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.SourceLoader; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
31 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
32 |
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
33 |
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
34 |
import com.sun.org.apache.xml.internal.utils.StopParseException; |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
35 |
import com.sun.org.apache.xml.internal.utils.StylesheetPIHandler; |
12005 | 36 |
import java.io.File; |
37 |
import java.io.FileInputStream; |
|
38 |
import java.io.FileNotFoundException; |
|
39 |
import java.io.FilenameFilter; |
|
40 |
import java.io.IOException; |
|
41 |
import java.io.InputStream; |
|
42 |
import java.net.MalformedURLException; |
|
43 |
import java.net.URL; |
|
39907 | 44 |
import java.util.ArrayList; |
12005 | 45 |
import java.util.Enumeration; |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
46 |
import java.util.List; |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
47 |
import java.util.Map; |
12005 | 48 |
import java.util.Properties; |
49 |
import java.util.zip.ZipEntry; |
|
50 |
import java.util.zip.ZipFile; |
|
51 |
import javax.xml.XMLConstants; |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
52 |
import javax.xml.catalog.CatalogException; |
47312 | 53 |
import javax.xml.catalog.CatalogFeatures.Feature; |
39907 | 54 |
import javax.xml.catalog.CatalogFeatures; |
55 |
import javax.xml.catalog.CatalogManager; |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
56 |
import javax.xml.catalog.CatalogResolver; |
12005 | 57 |
import javax.xml.transform.ErrorListener; |
58 |
import javax.xml.transform.Source; |
|
59 |
import javax.xml.transform.Templates; |
|
60 |
import javax.xml.transform.Transformer; |
|
61 |
import javax.xml.transform.TransformerConfigurationException; |
|
62 |
import javax.xml.transform.TransformerException; |
|
63 |
import javax.xml.transform.URIResolver; |
|
64 |
import javax.xml.transform.dom.DOMResult; |
|
65 |
import javax.xml.transform.dom.DOMSource; |
|
66 |
import javax.xml.transform.sax.SAXResult; |
|
67 |
import javax.xml.transform.sax.SAXSource; |
|
68 |
import javax.xml.transform.sax.SAXTransformerFactory; |
|
69 |
import javax.xml.transform.sax.TemplatesHandler; |
|
70 |
import javax.xml.transform.sax.TransformerHandler; |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
71 |
import javax.xml.transform.stax.*; |
12005 | 72 |
import javax.xml.transform.stream.StreamResult; |
73 |
import javax.xml.transform.stream.StreamSource; |
|
39907 | 74 |
import jdk.xml.internal.JdkXmlFeatures; |
75 |
import jdk.xml.internal.JdkXmlUtils; |
|
47312 | 76 |
import jdk.xml.internal.SecuritySupport; |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
77 |
import jdk.xml.internal.TransformErrorListener; |
12005 | 78 |
import org.xml.sax.InputSource; |
48577 | 79 |
import org.xml.sax.SAXException; |
12005 | 80 |
import org.xml.sax.XMLFilter; |
81 |
import org.xml.sax.XMLReader; |
|
82 |
||
83 |
/** |
|
48577 | 84 |
* Implementation of a JAXP TransformerFactory for Translets. |
12005 | 85 |
* @author G. Todd Miller |
86 |
* @author Morten Jorgensen |
|
87 |
* @author Santiago Pericas-Geertsen |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
88 |
* @LastModified: Aug 2019 |
12005 | 89 |
*/ |
90 |
public class TransformerFactoryImpl |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
91 |
extends SAXTransformerFactory implements SourceLoader |
12005 | 92 |
{ |
93 |
// Public constants for attributes supported by the XSLTC TransformerFactory. |
|
94 |
public final static String TRANSLET_NAME = "translet-name"; |
|
95 |
public final static String DESTINATION_DIRECTORY = "destination-directory"; |
|
96 |
public final static String PACKAGE_NAME = "package-name"; |
|
97 |
public final static String JAR_NAME = "jar-name"; |
|
98 |
public final static String GENERATE_TRANSLET = "generate-translet"; |
|
99 |
public final static String AUTO_TRANSLET = "auto-translet"; |
|
100 |
public final static String USE_CLASSPATH = "use-classpath"; |
|
101 |
public final static String DEBUG = "debug"; |
|
102 |
public final static String ENABLE_INLINING = "enable-inlining"; |
|
103 |
public final static String INDENT_NUMBER = "indent-number"; |
|
104 |
||
105 |
/** |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
106 |
* Default error listener |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
107 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
108 |
private final ErrorListener _defaultListener = new TransformErrorListener(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
109 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
110 |
/** |
12005 | 111 |
* This error listener is used only for this factory and is not passed to |
112 |
* the Templates or Transformer objects that we create. |
|
113 |
*/ |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
114 |
private ErrorListener _errorListener = _defaultListener; |
12005 | 115 |
|
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
116 |
// flag indicating whether there's an user's ErrorListener |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
117 |
private boolean _hasUserErrListener; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
118 |
|
12005 | 119 |
/** |
120 |
* This URIResolver is passed to all created Templates and Transformers |
|
121 |
*/ |
|
122 |
private URIResolver _uriResolver = null; |
|
123 |
||
124 |
/** |
|
125 |
* As Gregor Samsa awoke one morning from uneasy dreams he found himself |
|
126 |
* transformed in his bed into a gigantic insect. He was lying on his hard, |
|
127 |
* as it were armour plated, back, and if he lifted his head a little he |
|
128 |
* could see his big, brown belly divided into stiff, arched segments, on |
|
129 |
* top of which the bed quilt could hardly keep in position and was about |
|
130 |
* to slide off completely. His numerous legs, which were pitifully thin |
|
131 |
* compared to the rest of his bulk, waved helplessly before his eyes. |
|
132 |
* "What has happened to me?", he thought. It was no dream.... |
|
133 |
*/ |
|
134 |
protected final static String DEFAULT_TRANSLET_NAME = "GregorSamsa"; |
|
135 |
||
136 |
/** |
|
137 |
* The class name of the translet |
|
138 |
*/ |
|
139 |
private String _transletName = DEFAULT_TRANSLET_NAME; |
|
140 |
||
141 |
/** |
|
142 |
* The destination directory for the translet |
|
143 |
*/ |
|
144 |
private String _destinationDirectory = null; |
|
145 |
||
146 |
/** |
|
147 |
* The package name prefix for all generated translet classes |
|
148 |
*/ |
|
36520 | 149 |
private static final String DEFAULT_TRANSLATE_PACKAGE = "die.verwandlung"; |
150 |
private String _packageName = DEFAULT_TRANSLATE_PACKAGE; |
|
12005 | 151 |
|
152 |
/** |
|
153 |
* The jar file name which the translet classes are packaged into |
|
154 |
*/ |
|
155 |
private String _jarFileName = null; |
|
156 |
||
157 |
/** |
|
33349 | 158 |
* This Map is used to store parameters for locating |
12005 | 159 |
* <?xml-stylesheet ...?> processing instructions in XML docs. |
160 |
*/ |
|
33349 | 161 |
private Map<Source, PIParamWrapper> _piParams = null; |
12005 | 162 |
|
163 |
/** |
|
33349 | 164 |
* The above Map stores objects of this class. |
12005 | 165 |
*/ |
166 |
private static class PIParamWrapper { |
|
167 |
public String _media = null; |
|
168 |
public String _title = null; |
|
169 |
public String _charset = null; |
|
170 |
||
171 |
public PIParamWrapper(String media, String title, String charset) { |
|
172 |
_media = media; |
|
173 |
_title = title; |
|
174 |
_charset = charset; |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Set to <code>true</code> when debugging is enabled. |
|
180 |
*/ |
|
181 |
private boolean _debug = false; |
|
182 |
||
183 |
/** |
|
184 |
* Set to <code>true</code> when templates are inlined. |
|
185 |
*/ |
|
186 |
private boolean _enableInlining = false; |
|
187 |
||
188 |
/** |
|
189 |
* Set to <code>true</code> when we want to generate |
|
190 |
* translet classes from the stylesheet. |
|
191 |
*/ |
|
192 |
private boolean _generateTranslet = false; |
|
193 |
||
194 |
/** |
|
195 |
* If this is set to <code>true</code>, we attempt to use translet classes |
|
196 |
* for transformation if possible without compiling the stylesheet. The |
|
197 |
* translet class is only used if its timestamp is newer than the timestamp |
|
198 |
* of the stylesheet. |
|
199 |
*/ |
|
200 |
private boolean _autoTranslet = false; |
|
201 |
||
202 |
/** |
|
203 |
* If this is set to <code>true</code>, we attempt to load the translet |
|
204 |
* from the CLASSPATH. |
|
205 |
*/ |
|
206 |
private boolean _useClasspath = false; |
|
207 |
||
208 |
/** |
|
209 |
* Number of indent spaces when indentation is turned on. |
|
210 |
*/ |
|
211 |
private int _indentNumber = -1; |
|
212 |
||
213 |
/** |
|
214 |
* <p>State of secure processing feature.</p> |
|
215 |
*/ |
|
216 |
private boolean _isNotSecureProcessing = true; |
|
217 |
/** |
|
218 |
* <p>State of secure mode.</p> |
|
219 |
*/ |
|
220 |
private boolean _isSecureMode = false; |
|
12458 | 221 |
|
222 |
/** |
|
48577 | 223 |
* Indicates whether 3rd party parser may be used to override the system-default |
224 |
* Note the default value (false) is the safe option. |
|
225 |
* Note same as the old property useServicesMechanism |
|
12458 | 226 |
*/ |
48577 | 227 |
private boolean _overrideDefaultParser; |
12458 | 228 |
|
12005 | 229 |
/** |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
230 |
* protocols allowed for external references set by the stylesheet |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
231 |
* processing instruction, Import and Include element. |
17534 | 232 |
*/ |
233 |
private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT; |
|
234 |
/** |
|
235 |
* protocols allowed for external DTD references in source file and/or stylesheet. |
|
236 |
*/ |
|
237 |
private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT; |
|
238 |
||
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
239 |
private XMLSecurityPropertyManager _xmlSecurityPropertyMgr; |
20968 | 240 |
private XMLSecurityManager _xmlSecurityManager; |
17534 | 241 |
|
39907 | 242 |
private final JdkXmlFeatures _xmlFeatures; |
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
243 |
|
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
244 |
private ClassLoader _extensionClassLoader = null; |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
245 |
|
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
246 |
// Unmodifiable view of external extension function from xslt compiler |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
247 |
// It will be populated by user-specified extension functions during the |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
248 |
// type checking |
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
249 |
private Map<String, Class<?>> _xsltcExtensionFunctions; |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
250 |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
251 |
CatalogResolver _catalogUriResolver; |
39907 | 252 |
CatalogFeatures _catalogFeatures; |
253 |
CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder(); |
|
254 |
// Catalog features |
|
255 |
String _catalogFiles = null; |
|
256 |
String _catalogDefer = null; |
|
257 |
String _catalogPrefer = null; |
|
258 |
String _catalogResolve = null; |
|
259 |
||
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
260 |
int _cdataChunkSize = JdkXmlUtils.CDATA_CHUNK_SIZE_DEFAULT; |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
261 |
|
17534 | 262 |
/** |
12005 | 263 |
* javax.xml.transform.sax.TransformerFactory implementation. |
264 |
*/ |
|
265 |
public TransformerFactoryImpl() { |
|
17534 | 266 |
|
12005 | 267 |
if (System.getSecurityManager() != null) { |
268 |
_isSecureMode = true; |
|
269 |
_isNotSecureProcessing = false; |
|
270 |
} |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
271 |
|
39907 | 272 |
_xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing); |
48577 | 273 |
_overrideDefaultParser = _xmlFeatures.getFeature( |
274 |
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER); |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
275 |
_xmlSecurityPropertyMgr = new XMLSecurityPropertyManager(); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
276 |
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
277 |
Property.ACCESS_EXTERNAL_DTD); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
278 |
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
279 |
Property.ACCESS_EXTERNAL_STYLESHEET); |
20968 | 280 |
|
281 |
//Parser's security manager |
|
282 |
_xmlSecurityManager = new XMLSecurityManager(true); |
|
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
283 |
//Unmodifiable hash map with loaded external extension functions |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
284 |
_xsltcExtensionFunctions = null; |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
285 |
} |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
286 |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
287 |
public Map<String, Class<?>> getExternalExtensionsMap() { |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
288 |
return _xsltcExtensionFunctions; |
12005 | 289 |
} |
290 |
||
291 |
/** |
|
292 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
293 |
* Set the error event listener for the TransformerFactory, which is used |
|
294 |
* for the processing of transformation instructions, and not for the |
|
295 |
* transformation itself. |
|
296 |
* |
|
297 |
* @param listener The error listener to use with the TransformerFactory |
|
298 |
* @throws IllegalArgumentException |
|
299 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
300 |
@Override |
12005 | 301 |
public void setErrorListener(ErrorListener listener) |
302 |
throws IllegalArgumentException |
|
303 |
{ |
|
304 |
if (listener == null) { |
|
305 |
ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR, |
|
306 |
"TransformerFactory"); |
|
307 |
throw new IllegalArgumentException(err.toString()); |
|
308 |
} |
|
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
309 |
_hasUserErrListener = true; |
12005 | 310 |
_errorListener = listener; |
311 |
} |
|
312 |
||
313 |
/** |
|
314 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
315 |
* Get the error event handler for the TransformerFactory. |
|
316 |
* |
|
317 |
* @return The error listener used with the TransformerFactory |
|
318 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
319 |
@Override |
12005 | 320 |
public ErrorListener getErrorListener() { |
321 |
return _errorListener; |
|
322 |
} |
|
323 |
||
324 |
/** |
|
36520 | 325 |
* Returns the package name. |
326 |
*/ |
|
327 |
String getPackageName() { |
|
328 |
return _packageName; |
|
329 |
} |
|
330 |
||
331 |
/** |
|
12005 | 332 |
* javax.xml.transform.sax.TransformerFactory implementation. |
333 |
* Returns the value set for a TransformerFactory attribute |
|
334 |
* |
|
335 |
* @param name The attribute name |
|
336 |
* @return An object representing the attribute value |
|
337 |
* @throws IllegalArgumentException |
|
338 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
339 |
@Override |
12005 | 340 |
public Object getAttribute(String name) |
341 |
throws IllegalArgumentException |
|
342 |
{ |
|
343 |
// Return value for attribute 'translet-name' |
|
344 |
if (name.equals(TRANSLET_NAME)) { |
|
345 |
return _transletName; |
|
346 |
} |
|
347 |
else if (name.equals(GENERATE_TRANSLET)) { |
|
39907 | 348 |
return _generateTranslet; |
12005 | 349 |
} |
350 |
else if (name.equals(AUTO_TRANSLET)) { |
|
39907 | 351 |
return _autoTranslet; |
12005 | 352 |
} |
12458 | 353 |
else if (name.equals(ENABLE_INLINING)) { |
354 |
if (_enableInlining) |
|
355 |
return Boolean.TRUE; |
|
356 |
else |
|
357 |
return Boolean.FALSE; |
|
20968 | 358 |
} else if (name.equals(XalanConstants.SECURITY_MANAGER)) { |
359 |
return _xmlSecurityManager; |
|
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
360 |
} else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) { |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
361 |
return _extensionClassLoader; |
39907 | 362 |
} else if (JdkXmlUtils.CATALOG_FILES.equals(name)) { |
363 |
return _catalogFiles; |
|
364 |
} else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) { |
|
365 |
return _catalogDefer; |
|
366 |
} else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) { |
|
367 |
return _catalogPrefer; |
|
368 |
} else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) { |
|
369 |
return _catalogResolve; |
|
370 |
} else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { |
|
371 |
return buildCatalogFeatures(); |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
372 |
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) { |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
373 |
return _cdataChunkSize; |
12458 | 374 |
} |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
375 |
|
20968 | 376 |
/** Check to see if the property is managed by the security manager **/ |
377 |
String propertyValue = (_xmlSecurityManager != null) ? |
|
378 |
_xmlSecurityManager.getLimitAsString(name) : null; |
|
379 |
if (propertyValue != null) { |
|
380 |
return propertyValue; |
|
381 |
} else { |
|
382 |
propertyValue = (_xmlSecurityPropertyMgr != null) ? |
|
383 |
_xmlSecurityPropertyMgr.getValue(name) : null; |
|
384 |
if (propertyValue != null) { |
|
385 |
return propertyValue; |
|
386 |
} |
|
17534 | 387 |
} |
12005 | 388 |
|
389 |
// Throw an exception for all other attributes |
|
390 |
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name); |
|
391 |
throw new IllegalArgumentException(err.toString()); |
|
392 |
} |
|
393 |
||
394 |
/** |
|
395 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
396 |
* Sets the value for a TransformerFactory attribute. |
|
397 |
* |
|
398 |
* @param name The attribute name |
|
399 |
* @param value An object representing the attribute value |
|
400 |
* @throws IllegalArgumentException |
|
401 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
402 |
@Override |
12005 | 403 |
public void setAttribute(String name, Object value) |
404 |
throws IllegalArgumentException |
|
405 |
{ |
|
406 |
// Set the default translet name (ie. class name), which will be used |
|
407 |
// for translets that cannot be given a name from their system-id. |
|
408 |
if (name.equals(TRANSLET_NAME) && value instanceof String) { |
|
409 |
_transletName = (String) value; |
|
410 |
return; |
|
411 |
} |
|
412 |
else if (name.equals(DESTINATION_DIRECTORY) && value instanceof String) { |
|
413 |
_destinationDirectory = (String) value; |
|
414 |
return; |
|
415 |
} |
|
416 |
else if (name.equals(PACKAGE_NAME) && value instanceof String) { |
|
417 |
_packageName = (String) value; |
|
418 |
return; |
|
419 |
} |
|
420 |
else if (name.equals(JAR_NAME) && value instanceof String) { |
|
421 |
_jarFileName = (String) value; |
|
422 |
return; |
|
423 |
} |
|
424 |
else if (name.equals(GENERATE_TRANSLET)) { |
|
425 |
if (value instanceof Boolean) { |
|
39907 | 426 |
_generateTranslet = ((Boolean) value); |
12005 | 427 |
return; |
428 |
} |
|
429 |
else if (value instanceof String) { |
|
430 |
_generateTranslet = ((String) value).equalsIgnoreCase("true"); |
|
431 |
return; |
|
432 |
} |
|
433 |
} |
|
434 |
else if (name.equals(AUTO_TRANSLET)) { |
|
435 |
if (value instanceof Boolean) { |
|
39907 | 436 |
_autoTranslet = ((Boolean) value); |
12005 | 437 |
return; |
438 |
} |
|
439 |
else if (value instanceof String) { |
|
440 |
_autoTranslet = ((String) value).equalsIgnoreCase("true"); |
|
441 |
return; |
|
442 |
} |
|
443 |
} |
|
444 |
else if (name.equals(USE_CLASSPATH)) { |
|
445 |
if (value instanceof Boolean) { |
|
39907 | 446 |
_useClasspath = ((Boolean) value); |
12005 | 447 |
return; |
448 |
} |
|
449 |
else if (value instanceof String) { |
|
450 |
_useClasspath = ((String) value).equalsIgnoreCase("true"); |
|
451 |
return; |
|
452 |
} |
|
453 |
} |
|
454 |
else if (name.equals(DEBUG)) { |
|
455 |
if (value instanceof Boolean) { |
|
39907 | 456 |
_debug = ((Boolean) value); |
12005 | 457 |
return; |
458 |
} |
|
459 |
else if (value instanceof String) { |
|
460 |
_debug = ((String) value).equalsIgnoreCase("true"); |
|
461 |
return; |
|
462 |
} |
|
463 |
} |
|
464 |
else if (name.equals(ENABLE_INLINING)) { |
|
465 |
if (value instanceof Boolean) { |
|
39907 | 466 |
_enableInlining = ((Boolean) value); |
12005 | 467 |
return; |
468 |
} |
|
469 |
else if (value instanceof String) { |
|
470 |
_enableInlining = ((String) value).equalsIgnoreCase("true"); |
|
471 |
return; |
|
472 |
} |
|
473 |
} |
|
474 |
else if (name.equals(INDENT_NUMBER)) { |
|
475 |
if (value instanceof String) { |
|
476 |
try { |
|
477 |
_indentNumber = Integer.parseInt((String) value); |
|
478 |
return; |
|
479 |
} |
|
480 |
catch (NumberFormatException e) { |
|
481 |
// Falls through |
|
482 |
} |
|
483 |
} |
|
484 |
else if (value instanceof Integer) { |
|
39907 | 485 |
_indentNumber = ((Integer) value); |
12005 | 486 |
return; |
487 |
} |
|
488 |
} |
|
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
489 |
else if ( name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) { |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
490 |
if (value instanceof ClassLoader) { |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
491 |
_extensionClassLoader = (ClassLoader) value; |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
492 |
return; |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
493 |
} else { |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
494 |
final ErrorMsg err |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
495 |
= new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_VALUE_ERR, "Extension Functions ClassLoader"); |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
496 |
throw new IllegalArgumentException(err.toString()); |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
497 |
} |
39907 | 498 |
} else if (JdkXmlUtils.CATALOG_FILES.equals(name)) { |
499 |
_catalogFiles = (String) value; |
|
500 |
cfBuilder = CatalogFeatures.builder().with(Feature.FILES, _catalogFiles); |
|
501 |
return; |
|
502 |
} else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) { |
|
503 |
_catalogDefer = (String) value; |
|
504 |
cfBuilder = CatalogFeatures.builder().with(Feature.DEFER, _catalogDefer); |
|
505 |
return; |
|
506 |
} else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) { |
|
507 |
_catalogPrefer = (String) value; |
|
508 |
cfBuilder = CatalogFeatures.builder().with(Feature.PREFER, _catalogPrefer); |
|
509 |
return; |
|
510 |
} else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) { |
|
511 |
_catalogResolve = (String) value; |
|
512 |
cfBuilder = CatalogFeatures.builder().with(Feature.RESOLVE, _catalogResolve); |
|
513 |
return; |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
514 |
} else if (JdkXmlUtils.CDATA_CHUNK_SIZE.equals(name)) { |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
515 |
_cdataChunkSize = JdkXmlUtils.getValue(value, _cdataChunkSize); |
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
516 |
return; |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
517 |
} |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
518 |
|
20968 | 519 |
if (_xmlSecurityManager != null && |
520 |
_xmlSecurityManager.setLimit(name, XMLSecurityManager.State.APIPROPERTY, value)) { |
|
521 |
return; |
|
522 |
} |
|
523 |
||
524 |
if (_xmlSecurityPropertyMgr != null && |
|
525 |
_xmlSecurityPropertyMgr.setValue(name, XMLSecurityPropertyManager.State.APIPROPERTY, value)) { |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
526 |
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
527 |
Property.ACCESS_EXTERNAL_DTD); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
528 |
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
529 |
Property.ACCESS_EXTERNAL_STYLESHEET); |
17534 | 530 |
return; |
531 |
} |
|
12005 | 532 |
|
533 |
// Throw an exception for all other attributes |
|
534 |
final ErrorMsg err |
|
535 |
= new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_ERR, name); |
|
536 |
throw new IllegalArgumentException(err.toString()); |
|
537 |
} |
|
538 |
||
539 |
/** |
|
540 |
* <p>Set a feature for this <code>TransformerFactory</code> and <code>Transformer</code>s |
|
541 |
* or <code>Template</code>s created by this factory.</p> |
|
542 |
* |
|
543 |
* <p> |
|
544 |
* Feature names are fully qualified {@link java.net.URI}s. |
|
545 |
* Implementations may define their own features. |
|
546 |
* An {@link TransformerConfigurationException} is thrown if this <code>TransformerFactory</code> or the |
|
547 |
* <code>Transformer</code>s or <code>Template</code>s it creates cannot support the feature. |
|
548 |
* It is possible for an <code>TransformerFactory</code> to expose a feature value but be unable to change its state. |
|
549 |
* </p> |
|
550 |
* |
|
551 |
* <p>See {@link javax.xml.transform.TransformerFactory} for full documentation of specific features.</p> |
|
552 |
* |
|
553 |
* @param name Feature name. |
|
554 |
* @param value Is feature state <code>true</code> or <code>false</code>. |
|
555 |
* |
|
556 |
* @throws TransformerConfigurationException if this <code>TransformerFactory</code> |
|
557 |
* or the <code>Transformer</code>s or <code>Template</code>s it creates cannot support this feature. |
|
558 |
* @throws NullPointerException If the <code>name</code> parameter is null. |
|
559 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
560 |
@Override |
12005 | 561 |
public void setFeature(String name, boolean value) |
562 |
throws TransformerConfigurationException { |
|
563 |
||
564 |
// feature name cannot be null |
|
565 |
if (name == null) { |
|
566 |
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_FEATURE_NULL_NAME); |
|
567 |
throw new NullPointerException(err.toString()); |
|
568 |
} |
|
569 |
// secure processing? |
|
570 |
else if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { |
|
571 |
if ((_isSecureMode) && (!value)) { |
|
572 |
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SECUREPROCESSING_FEATURE); |
|
573 |
throw new TransformerConfigurationException(err.toString()); |
|
574 |
} |
|
575 |
_isNotSecureProcessing = !value; |
|
20968 | 576 |
_xmlSecurityManager.setSecureProcessing(value); |
17534 | 577 |
|
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
578 |
// set external access restriction when FSP is explicitly set |
34463
c269a10aca11
8132091: Clean up JAXP code that has dependency on Java version string
joehw
parents:
33349
diff
changeset
|
579 |
if (value) { |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
580 |
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD, |
39907 | 581 |
FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
582 |
_xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET, |
39907 | 583 |
FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
584 |
_accessExternalDTD = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
585 |
Property.ACCESS_EXTERNAL_DTD); |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
586 |
_accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue( |
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
587 |
Property.ACCESS_EXTERNAL_STYLESHEET); |
17534 | 588 |
} |
18890
25bdeca3173b
8016648: FEATURE_SECURE_PROCESSING set to true or false causes SAXParseException to be thrown
joehw
parents:
18352
diff
changeset
|
589 |
|
39907 | 590 |
if (value && _xmlFeatures != null) { |
591 |
_xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION, |
|
592 |
JdkXmlFeatures.State.FSP, false); |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
593 |
} |
12005 | 594 |
} |
595 |
else { |
|
48577 | 596 |
if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { |
597 |
// for compatibility, in secure mode, useServicesMechanism is determined by the constructor |
|
598 |
if (_isSecureMode) { |
|
599 |
return; |
|
600 |
} |
|
601 |
} |
|
39907 | 602 |
if (_xmlFeatures != null && |
603 |
_xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) { |
|
48577 | 604 |
if (name.equals(JdkXmlUtils.OVERRIDE_PARSER) || |
605 |
name.equals(JdkXmlFeatures.ORACLE_FEATURE_SERVICE_MECHANISM)) { |
|
606 |
_overrideDefaultParser = _xmlFeatures.getFeature( |
|
607 |
JdkXmlFeatures.XmlFeature.JDK_OVERRIDE_PARSER); |
|
608 |
} |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
609 |
return; |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
610 |
} |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
611 |
|
12005 | 612 |
// unknown feature |
613 |
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_UNSUPPORTED_FEATURE, name); |
|
614 |
throw new TransformerConfigurationException(err.toString()); |
|
615 |
} |
|
616 |
} |
|
617 |
||
618 |
/** |
|
619 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
620 |
* Look up the value of a feature (to see if it is supported). |
|
621 |
* This method must be updated as the various methods and features of this |
|
622 |
* class are implemented. |
|
623 |
* |
|
624 |
* @param name The feature name |
|
625 |
* @return 'true' if feature is supported, 'false' if not |
|
626 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
627 |
@Override |
12005 | 628 |
public boolean getFeature(String name) { |
629 |
// All supported features should be listed here |
|
630 |
String[] features = { |
|
631 |
DOMSource.FEATURE, |
|
632 |
DOMResult.FEATURE, |
|
633 |
SAXSource.FEATURE, |
|
634 |
SAXResult.FEATURE, |
|
635 |
StAXSource.FEATURE, |
|
636 |
StAXResult.FEATURE, |
|
637 |
StreamSource.FEATURE, |
|
638 |
StreamResult.FEATURE, |
|
639 |
SAXTransformerFactory.FEATURE, |
|
12458 | 640 |
SAXTransformerFactory.FEATURE_XMLFILTER, |
641 |
XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM |
|
12005 | 642 |
}; |
643 |
||
644 |
// feature name cannot be null |
|
645 |
if (name == null) { |
|
646 |
ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); |
|
647 |
throw new NullPointerException(err.toString()); |
|
648 |
} |
|
649 |
||
650 |
// Inefficient, but array is small |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
651 |
for (int i =0; i < features.length; i++) { |
12005 | 652 |
if (name.equals(features[i])) { |
653 |
return true; |
|
654 |
} |
|
655 |
} |
|
39907 | 656 |
|
12005 | 657 |
if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { |
39907 | 658 |
return !_isNotSecureProcessing; |
12005 | 659 |
} |
660 |
||
39907 | 661 |
/** Check to see if the property is managed by the JdkXmlFeatues **/ |
662 |
int index = _xmlFeatures.getIndex(name); |
|
663 |
if (index > -1) { |
|
664 |
return _xmlFeatures.getFeature(index); |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
665 |
} |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
666 |
|
12005 | 667 |
// Feature not supported |
668 |
return false; |
|
669 |
} |
|
12458 | 670 |
/** |
671 |
* Return the state of the services mechanism feature. |
|
672 |
*/ |
|
48577 | 673 |
public boolean overrideDefaultParser() { |
674 |
return _overrideDefaultParser; |
|
12458 | 675 |
} |
12005 | 676 |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
677 |
/** |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
678 |
* @return the feature manager |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
679 |
*/ |
39907 | 680 |
public JdkXmlFeatures getJdkXmlFeatures() { |
681 |
return _xmlFeatures; |
|
21467
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
682 |
} |
ed77f0ff062c
8004476: XSLT Extension Functions Don't Work in WebStart
joehw
parents:
20968
diff
changeset
|
683 |
|
12005 | 684 |
/** |
685 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
686 |
* Get the object that is used by default during the transformation to |
|
687 |
* resolve URIs used in document(), xsl:import, or xsl:include. |
|
688 |
* |
|
689 |
* @return The URLResolver used for this TransformerFactory and all |
|
690 |
* Templates and Transformer objects created using this factory |
|
691 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
692 |
@Override |
12005 | 693 |
public URIResolver getURIResolver() { |
694 |
return _uriResolver; |
|
695 |
} |
|
696 |
||
697 |
/** |
|
698 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
699 |
* Set the object that is used by default during the transformation to |
|
700 |
* resolve URIs used in document(), xsl:import, or xsl:include. Note that |
|
701 |
* this does not affect Templates and Transformers that are already |
|
702 |
* created with this factory. |
|
703 |
* |
|
704 |
* @param resolver The URLResolver used for this TransformerFactory and all |
|
705 |
* Templates and Transformer objects created using this factory |
|
706 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
707 |
@Override |
12005 | 708 |
public void setURIResolver(URIResolver resolver) { |
709 |
_uriResolver = resolver; |
|
710 |
} |
|
711 |
||
712 |
/** |
|
713 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
714 |
* Get the stylesheet specification(s) associated via the xml-stylesheet |
|
715 |
* processing instruction (see http://www.w3.org/TR/xml-stylesheet/) with |
|
716 |
* the document document specified in the source parameter, and that match |
|
717 |
* the given criteria. |
|
718 |
* |
|
719 |
* @param source The XML source document. |
|
720 |
* @param media The media attribute to be matched. May be null, in which |
|
721 |
* case the prefered templates will be used (i.e. alternate = no). |
|
722 |
* @param title The value of the title attribute to match. May be null. |
|
723 |
* @param charset The value of the charset attribute to match. May be null. |
|
724 |
* @return A Source object suitable for passing to the TransformerFactory. |
|
725 |
* @throws TransformerConfigurationException |
|
726 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
727 |
@Override |
12005 | 728 |
public Source getAssociatedStylesheet(Source source, String media, |
729 |
String title, String charset) |
|
730 |
throws TransformerConfigurationException { |
|
731 |
||
732 |
String baseId; |
|
48577 | 733 |
XMLReader reader = null; |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
734 |
InputSource isource; |
12005 | 735 |
|
736 |
/** |
|
737 |
* Fix for bugzilla bug 24187 |
|
738 |
*/ |
|
739 |
StylesheetPIHandler _stylesheetPIHandler = new StylesheetPIHandler(null,media,title,charset); |
|
740 |
||
741 |
try { |
|
742 |
||
743 |
if (source instanceof DOMSource ) { |
|
744 |
final DOMSource domsrc = (DOMSource) source; |
|
745 |
baseId = domsrc.getSystemId(); |
|
746 |
final org.w3c.dom.Node node = domsrc.getNode(); |
|
747 |
final DOM2SAX dom2sax = new DOM2SAX(node); |
|
748 |
||
749 |
_stylesheetPIHandler.setBaseId(baseId); |
|
750 |
||
751 |
dom2sax.setContentHandler( _stylesheetPIHandler); |
|
752 |
dom2sax.parse(); |
|
753 |
} else { |
|
48577 | 754 |
if (source instanceof SAXSource) { |
755 |
reader = ((SAXSource)source).getXMLReader(); |
|
756 |
} |
|
12005 | 757 |
isource = SAXSource.sourceToInputSource(source); |
758 |
baseId = isource.getSystemId(); |
|
759 |
||
760 |
if (reader == null) { |
|
48577 | 761 |
reader = JdkXmlUtils.getXMLReader(_overrideDefaultParser, |
762 |
!_isNotSecureProcessing); |
|
12005 | 763 |
} |
764 |
||
765 |
_stylesheetPIHandler.setBaseId(baseId); |
|
766 |
reader.setContentHandler(_stylesheetPIHandler); |
|
767 |
reader.parse(isource); |
|
768 |
||
769 |
} |
|
770 |
||
771 |
if (_uriResolver != null ) { |
|
772 |
_stylesheetPIHandler.setURIResolver(_uriResolver); |
|
773 |
} |
|
774 |
||
775 |
} catch (StopParseException e ) { |
|
776 |
// startElement encountered so do not parse further |
|
777 |
||
48577 | 778 |
} catch (SAXException | IOException e) { |
12005 | 779 |
throw new TransformerConfigurationException( |
780 |
"getAssociatedStylesheets failed", e); |
|
781 |
} |
|
782 |
||
783 |
return _stylesheetPIHandler.getAssociatedStylesheet(); |
|
784 |
||
785 |
} |
|
786 |
||
787 |
/** |
|
788 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
789 |
* Create a Transformer object that copies the input document to the result. |
|
790 |
* |
|
791 |
* @return A Transformer object that simply copies the source to the result. |
|
792 |
* @throws TransformerConfigurationException |
|
793 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
794 |
@Override |
12005 | 795 |
public Transformer newTransformer() |
796 |
throws TransformerConfigurationException |
|
797 |
{ |
|
39907 | 798 |
// create CatalogFeatures that is accessible by the Transformer |
799 |
// through the factory instance |
|
800 |
buildCatalogFeatures(); |
|
12005 | 801 |
TransformerImpl result = new TransformerImpl(new Properties(), |
802 |
_indentNumber, this); |
|
803 |
if (_uriResolver != null) { |
|
804 |
result.setURIResolver(_uriResolver); |
|
805 |
} |
|
806 |
||
807 |
if (!_isNotSecureProcessing) { |
|
808 |
result.setSecureProcessing(true); |
|
809 |
} |
|
810 |
return result; |
|
811 |
} |
|
812 |
||
813 |
/** |
|
814 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
815 |
* Process the Source into a Templates object, which is a a compiled |
|
816 |
* representation of the source. Note that this method should not be |
|
817 |
* used with XSLTC, as the time-consuming compilation is done for each |
|
818 |
* and every transformation. |
|
819 |
* |
|
820 |
* @return A Templates object that can be used to create Transformers. |
|
821 |
* @throws TransformerConfigurationException |
|
822 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
823 |
@Override |
12005 | 824 |
public Transformer newTransformer(Source source) throws |
825 |
TransformerConfigurationException |
|
826 |
{ |
|
827 |
final Templates templates = newTemplates(source); |
|
828 |
final Transformer transformer = templates.newTransformer(); |
|
829 |
if (_uriResolver != null) { |
|
830 |
transformer.setURIResolver(_uriResolver); |
|
831 |
} |
|
832 |
return(transformer); |
|
833 |
} |
|
834 |
||
835 |
/** |
|
836 |
* Pass warning messages from the compiler to the error listener |
|
837 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
838 |
private void passWarningsToListener(List<ErrorMsg> messages) |
12005 | 839 |
throws TransformerException |
840 |
{ |
|
841 |
if (_errorListener == null || messages == null) { |
|
842 |
return; |
|
843 |
} |
|
844 |
// Pass messages to listener, one by one |
|
845 |
final int count = messages.size(); |
|
846 |
for (int pos = 0; pos < count; pos++) { |
|
39907 | 847 |
ErrorMsg msg = messages.get(pos); |
12005 | 848 |
// Workaround for the TCK failure ErrorListener.errorTests.error001. |
849 |
if (msg.isWarningError()) |
|
850 |
_errorListener.error( |
|
851 |
new TransformerConfigurationException(msg.toString())); |
|
852 |
else |
|
853 |
_errorListener.warning( |
|
854 |
new TransformerConfigurationException(msg.toString())); |
|
855 |
} |
|
856 |
} |
|
857 |
||
858 |
/** |
|
859 |
* Pass error messages from the compiler to the error listener |
|
860 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
861 |
private void passErrorsToListener(List<ErrorMsg> messages) { |
12005 | 862 |
try { |
863 |
if (_errorListener == null || messages == null) { |
|
864 |
return; |
|
865 |
} |
|
866 |
// Pass messages to listener, one by one |
|
867 |
final int count = messages.size(); |
|
868 |
for (int pos = 0; pos < count; pos++) { |
|
39907 | 869 |
String message = messages.get(pos).toString(); |
12005 | 870 |
_errorListener.error(new TransformerException(message)); |
871 |
} |
|
872 |
} |
|
873 |
catch (TransformerException e) { |
|
874 |
// nada |
|
875 |
} |
|
876 |
} |
|
877 |
||
878 |
/** |
|
879 |
* javax.xml.transform.sax.TransformerFactory implementation. |
|
880 |
* Process the Source into a Templates object, which is a a compiled |
|
881 |
* representation of the source. |
|
882 |
* |
|
883 |
* @param source The input stylesheet - DOMSource not supported!!! |
|
884 |
* @return A Templates object that can be used to create Transformers. |
|
885 |
* @throws TransformerConfigurationException |
|
886 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
887 |
@Override |
12005 | 888 |
public Templates newTemplates(Source source) |
889 |
throws TransformerConfigurationException |
|
890 |
{ |
|
39907 | 891 |
TemplatesImpl templates; |
12005 | 892 |
// If the _useClasspath attribute is true, try to load the translet from |
893 |
// the CLASSPATH and create a template object using the loaded |
|
894 |
// translet. |
|
895 |
if (_useClasspath) { |
|
896 |
String transletName = getTransletBaseName(source); |
|
897 |
||
898 |
if (_packageName != null) |
|
899 |
transletName = _packageName + "." + transletName; |
|
900 |
||
901 |
try { |
|
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
902 |
final Class<?> clazz = ObjectFactory.findProviderClass(transletName, true); |
12005 | 903 |
resetTransientAttributes(); |
904 |
||
42247
52fafb950d5a
8158619: Very large CDATA section in XML document causes OOME
joehw
parents:
40582
diff
changeset
|
905 |
templates = new TemplatesImpl(new Class<?>[]{clazz}, transletName, null, _indentNumber, this); |
39907 | 906 |
if (_uriResolver != null) { |
907 |
templates.setURIResolver(_uriResolver); |
|
908 |
} |
|
909 |
return templates; |
|
12005 | 910 |
} |
911 |
catch (ClassNotFoundException cnfe) { |
|
912 |
ErrorMsg err = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, transletName); |
|
913 |
throw new TransformerConfigurationException(err.toString()); |
|
914 |
} |
|
915 |
catch (Exception e) { |
|
916 |
ErrorMsg err = new ErrorMsg( |
|
917 |
new ErrorMsg(ErrorMsg.RUNTIME_ERROR_KEY) |
|
918 |
+ e.getMessage()); |
|
919 |
throw new TransformerConfigurationException(err.toString()); |
|
920 |
} |
|
921 |
} |
|
922 |
||
923 |
// If _autoTranslet is true, we will try to load the bytecodes |
|
924 |
// from the translet classes without compiling the stylesheet. |
|
925 |
if (_autoTranslet) { |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
926 |
byte[][] bytecodes; |
12005 | 927 |
String transletClassName = getTransletBaseName(source); |
928 |
||
929 |
if (_packageName != null) |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
930 |
transletClassName = _packageName + "." + transletClassName; |
12005 | 931 |
|
932 |
if (_jarFileName != null) |
|
933 |
bytecodes = getBytecodesFromJar(source, transletClassName); |
|
934 |
else |
|
935 |
bytecodes = getBytecodesFromClasses(source, transletClassName); |
|
936 |
||
937 |
if (bytecodes != null) { |
|
938 |
if (_debug) { |
|
939 |
if (_jarFileName != null) |
|
940 |
System.err.println(new ErrorMsg( |
|
941 |
ErrorMsg.TRANSFORM_WITH_JAR_STR, transletClassName, _jarFileName)); |
|
942 |
else |
|
943 |
System.err.println(new ErrorMsg( |
|
944 |
ErrorMsg.TRANSFORM_WITH_TRANSLET_STR, transletClassName)); |
|
945 |
} |
|
946 |
||
947 |
// Reset the per-session attributes to their default values |
|
948 |
// after each newTemplates() call. |
|
949 |
resetTransientAttributes(); |
|
39907 | 950 |
templates = new TemplatesImpl(bytecodes, transletClassName, null, _indentNumber, this); |
951 |
if (_uriResolver != null) { |
|
952 |
templates.setURIResolver(_uriResolver); |
|
953 |
} |
|
954 |
return templates; |
|
12005 | 955 |
} |
956 |
} |
|
957 |
||
958 |
// Create and initialize a stylesheet compiler |
|
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
959 |
final XSLTC xsltc = new XSLTC(_xmlFeatures, _hasUserErrListener); |
12005 | 960 |
if (_debug) xsltc.setDebug(true); |
12458 | 961 |
if (_enableInlining) |
962 |
xsltc.setTemplateInlining(true); |
|
963 |
else |
|
964 |
xsltc.setTemplateInlining(false); |
|
965 |
||
12005 | 966 |
if (!_isNotSecureProcessing) xsltc.setSecureProcessing(true); |
17534 | 967 |
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, _accessExternalStylesheet); |
968 |
xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD); |
|
20968 | 969 |
xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager); |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
970 |
xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader); |
39907 | 971 |
|
972 |
// set Catalog features |
|
973 |
buildCatalogFeatures(); |
|
974 |
xsltc.setProperty(JdkXmlFeatures.CATALOG_FEATURES, _catalogFeatures); |
|
975 |
||
12005 | 976 |
xsltc.init(); |
29945
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
977 |
if (!_isNotSecureProcessing) |
4912169d22d3
8040228: TransformerConfigurationException occurs with security manager, FSP and XSLT Ext
aefimov
parents:
25868
diff
changeset
|
978 |
_xsltcExtensionFunctions = xsltc.getExternalExtensionFunctions(); |
12005 | 979 |
// Set a document loader (for xsl:include/import) if defined |
39907 | 980 |
if (_uriResolver != null || ( _catalogFiles != null |
981 |
&& _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG))) { |
|
12005 | 982 |
xsltc.setSourceLoader(this); |
983 |
} |
|
984 |
||
985 |
// Pass parameters to the Parser to make sure it locates the correct |
|
986 |
// <?xml-stylesheet ...?> PI in an XML input document |
|
987 |
if ((_piParams != null) && (_piParams.get(source) != null)) { |
|
988 |
// Get the parameters for this Source object |
|
33349 | 989 |
PIParamWrapper p = _piParams.get(source); |
12005 | 990 |
// Pass them on to the compiler (which will pass then to the parser) |
991 |
if (p != null) { |
|
992 |
xsltc.setPIParameters(p._media, p._title, p._charset); |
|
993 |
} |
|
994 |
} |
|
995 |
||
996 |
// Set the attributes for translet generation |
|
997 |
int outputType = XSLTC.BYTEARRAY_OUTPUT; |
|
998 |
if (_generateTranslet || _autoTranslet) { |
|
999 |
// Set the translet name |
|
1000 |
xsltc.setClassName(getTransletBaseName(source)); |
|
1001 |
||
1002 |
if (_destinationDirectory != null) |
|
1003 |
xsltc.setDestDirectory(_destinationDirectory); |
|
1004 |
else { |
|
1005 |
String xslName = getStylesheetFileName(source); |
|
1006 |
if (xslName != null) { |
|
1007 |
File xslFile = new File(xslName); |
|
1008 |
String xslDir = xslFile.getParent(); |
|
1009 |
||
1010 |
if (xslDir != null) |
|
1011 |
xsltc.setDestDirectory(xslDir); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
||
1015 |
if (_packageName != null) |
|
1016 |
xsltc.setPackageName(_packageName); |
|
1017 |
||
1018 |
if (_jarFileName != null) { |
|
1019 |
xsltc.setJarFileName(_jarFileName); |
|
1020 |
outputType = XSLTC.BYTEARRAY_AND_JAR_OUTPUT; |
|
1021 |
} |
|
1022 |
else |
|
1023 |
outputType = XSLTC.BYTEARRAY_AND_FILE_OUTPUT; |
|
1024 |
} |
|
1025 |
||
1026 |
// Compile the stylesheet |
|
1027 |
final InputSource input = Util.getInputSource(xsltc, source); |
|
1028 |
byte[][] bytecodes = xsltc.compile(null, input, outputType); |
|
1029 |
final String transletName = xsltc.getClassName(); |
|
1030 |
||
1031 |
// Output to the jar file if the jar file name is set. |
|
1032 |
if ((_generateTranslet || _autoTranslet) |
|
1033 |
&& bytecodes != null && _jarFileName != null) { |
|
1034 |
try { |
|
1035 |
xsltc.outputToJar(); |
|
1036 |
} |
|
1037 |
catch (java.io.IOException e) { } |
|
1038 |
} |
|
1039 |
||
1040 |
// Reset the per-session attributes to their default values |
|
1041 |
// after each newTemplates() call. |
|
1042 |
resetTransientAttributes(); |
|
1043 |
||
1044 |
// Pass compiler warnings to the error listener |
|
1045 |
if (_errorListener != this) { |
|
1046 |
try { |
|
1047 |
passWarningsToListener(xsltc.getWarnings()); |
|
1048 |
} |
|
1049 |
catch (TransformerException e) { |
|
1050 |
throw new TransformerConfigurationException(e); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
else { |
|
1054 |
xsltc.printWarnings(); |
|
1055 |
} |
|
1056 |
||
1057 |
// Check that the transformation went well before returning |
|
39907 | 1058 |
if (bytecodes == null) { |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1059 |
List<ErrorMsg> errs = xsltc.getErrors(); |
39907 | 1060 |
ErrorMsg err; |
1061 |
if (errs != null) { |
|
1062 |
err = errs.get(errs.size()-1); |
|
1063 |
} else { |
|
1064 |
err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR); |
|
1065 |
} |
|
1066 |
Throwable cause = err.getCause(); |
|
1067 |
TransformerConfigurationException exc; |
|
1068 |
if (cause != null) { |
|
1069 |
exc = new TransformerConfigurationException(cause.getMessage(), cause); |
|
1070 |
} else { |
|
1071 |
exc = new TransformerConfigurationException(err.toString()); |
|
1072 |
} |
|
1073 |
||
1074 |
// Pass compiler errors to the error listener |
|
1075 |
if (_errorListener != null) { |
|
1076 |
passErrorsToListener(xsltc.getErrors()); |
|
1077 |
||
1078 |
// As required by TCK 1.2, send a fatalError to the |
|
1079 |
// error listener because compilation of the stylesheet |
|
1080 |
// failed and no further processing will be possible. |
|
1081 |
try { |
|
1082 |
_errorListener.fatalError(exc); |
|
1083 |
} catch (TransformerException te) { |
|
1084 |
// well, we tried. |
|
1085 |
} |
|
1086 |
} |
|
1087 |
else { |
|
1088 |
xsltc.printErrors(); |
|
1089 |
} |
|
1090 |
throw exc; |
|
17534 | 1091 |
} |
12005 | 1092 |
|
39907 | 1093 |
templates = new TemplatesImpl(bytecodes, transletName, xsltc.getOutputProperties(), |
1094 |
_indentNumber, this); |
|
1095 |
if (_uriResolver != null) { |
|
1096 |
templates.setURIResolver(_uriResolver); |
|
12005 | 1097 |
} |
39907 | 1098 |
return templates; |
12005 | 1099 |
} |
1100 |
||
1101 |
/** |
|
1102 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1103 |
* Get a TemplatesHandler object that can process SAX ContentHandler |
|
1104 |
* events into a Templates object. |
|
1105 |
* |
|
1106 |
* @return A TemplatesHandler object that can handle SAX events |
|
1107 |
* @throws TransformerConfigurationException |
|
1108 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1109 |
@Override |
12005 | 1110 |
public TemplatesHandler newTemplatesHandler() |
1111 |
throws TransformerConfigurationException |
|
1112 |
{ |
|
39907 | 1113 |
// create CatalogFeatures that is accessible by the Handler |
1114 |
// through the factory instance |
|
1115 |
buildCatalogFeatures(); |
|
12005 | 1116 |
final TemplatesHandlerImpl handler = |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
50947
diff
changeset
|
1117 |
new TemplatesHandlerImpl(_indentNumber, this, _hasUserErrListener); |
12005 | 1118 |
if (_uriResolver != null) { |
1119 |
handler.setURIResolver(_uriResolver); |
|
1120 |
} |
|
1121 |
return handler; |
|
1122 |
} |
|
1123 |
||
1124 |
/** |
|
1125 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1126 |
* Get a TransformerHandler object that can process SAX ContentHandler |
|
1127 |
* events into a Result. This method will return a pure copy transformer. |
|
1128 |
* |
|
1129 |
* @return A TransformerHandler object that can handle SAX events |
|
1130 |
* @throws TransformerConfigurationException |
|
1131 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1132 |
@Override |
12005 | 1133 |
public TransformerHandler newTransformerHandler() |
1134 |
throws TransformerConfigurationException |
|
1135 |
{ |
|
1136 |
final Transformer transformer = newTransformer(); |
|
1137 |
if (_uriResolver != null) { |
|
1138 |
transformer.setURIResolver(_uriResolver); |
|
1139 |
} |
|
1140 |
return new TransformerHandlerImpl((TransformerImpl) transformer); |
|
1141 |
} |
|
1142 |
||
1143 |
/** |
|
1144 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1145 |
* Get a TransformerHandler object that can process SAX ContentHandler |
|
1146 |
* events into a Result, based on the transformation instructions |
|
1147 |
* specified by the argument. |
|
1148 |
* |
|
1149 |
* @param src The source of the transformation instructions. |
|
1150 |
* @return A TransformerHandler object that can handle SAX events |
|
1151 |
* @throws TransformerConfigurationException |
|
1152 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1153 |
@Override |
12005 | 1154 |
public TransformerHandler newTransformerHandler(Source src) |
1155 |
throws TransformerConfigurationException |
|
1156 |
{ |
|
1157 |
final Transformer transformer = newTransformer(src); |
|
1158 |
if (_uriResolver != null) { |
|
1159 |
transformer.setURIResolver(_uriResolver); |
|
1160 |
} |
|
1161 |
return new TransformerHandlerImpl((TransformerImpl) transformer); |
|
1162 |
} |
|
1163 |
||
1164 |
/** |
|
1165 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1166 |
* Get a TransformerHandler object that can process SAX ContentHandler |
|
1167 |
* events into a Result, based on the transformation instructions |
|
1168 |
* specified by the argument. |
|
1169 |
* |
|
1170 |
* @param templates Represents a pre-processed stylesheet |
|
1171 |
* @return A TransformerHandler object that can handle SAX events |
|
1172 |
* @throws TransformerConfigurationException |
|
1173 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1174 |
@Override |
12005 | 1175 |
public TransformerHandler newTransformerHandler(Templates templates) |
1176 |
throws TransformerConfigurationException |
|
1177 |
{ |
|
1178 |
final Transformer transformer = templates.newTransformer(); |
|
1179 |
final TransformerImpl internal = (TransformerImpl)transformer; |
|
1180 |
return new TransformerHandlerImpl(internal); |
|
1181 |
} |
|
1182 |
||
1183 |
/** |
|
1184 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1185 |
* Create an XMLFilter that uses the given source as the |
|
1186 |
* transformation instructions. |
|
1187 |
* |
|
1188 |
* @param src The source of the transformation instructions. |
|
1189 |
* @return An XMLFilter object, or null if this feature is not supported. |
|
1190 |
* @throws TransformerConfigurationException |
|
1191 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1192 |
@Override |
12005 | 1193 |
public XMLFilter newXMLFilter(Source src) |
1194 |
throws TransformerConfigurationException |
|
1195 |
{ |
|
1196 |
Templates templates = newTemplates(src); |
|
1197 |
if (templates == null) return null; |
|
1198 |
return newXMLFilter(templates); |
|
1199 |
} |
|
1200 |
||
1201 |
/** |
|
1202 |
* javax.xml.transform.sax.SAXTransformerFactory implementation. |
|
1203 |
* Create an XMLFilter that uses the given source as the |
|
1204 |
* transformation instructions. |
|
1205 |
* |
|
1206 |
* @param templates The source of the transformation instructions. |
|
1207 |
* @return An XMLFilter object, or null if this feature is not supported. |
|
1208 |
* @throws TransformerConfigurationException |
|
1209 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1210 |
@Override |
12005 | 1211 |
public XMLFilter newXMLFilter(Templates templates) |
1212 |
throws TransformerConfigurationException |
|
1213 |
{ |
|
1214 |
try { |
|
1215 |
return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates); |
|
1216 |
} |
|
1217 |
catch (TransformerConfigurationException e1) { |
|
1218 |
if (_errorListener != null) { |
|
1219 |
try { |
|
1220 |
_errorListener.fatalError(e1); |
|
1221 |
return null; |
|
1222 |
} |
|
1223 |
catch (TransformerException e2) { |
|
50947
fb46a7d38d6b
8206164: forgot to "throw" TransformerConfigurationException
joehw
parents:
48577
diff
changeset
|
1224 |
throw new TransformerConfigurationException(e2); |
12005 | 1225 |
} |
1226 |
} |
|
1227 |
throw e1; |
|
1228 |
} |
|
1229 |
} |
|
1230 |
||
1231 |
/** |
|
1232 |
* This method implements XSLTC's SourceLoader interface. It is used to |
|
1233 |
* glue a TrAX URIResolver to the XSLTC compiler's Input and Import classes. |
|
1234 |
* |
|
1235 |
* @param href The URI of the document to load |
|
1236 |
* @param context The URI of the currently loaded document |
|
1237 |
* @param xsltc The compiler that resuests the document |
|
1238 |
* @return An InputSource with the loaded document |
|
1239 |
*/ |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1240 |
@Override |
12005 | 1241 |
public InputSource loadSource(String href, String context, XSLTC xsltc) { |
1242 |
try { |
|
39907 | 1243 |
Source source = null; |
12005 | 1244 |
if (_uriResolver != null) { |
39907 | 1245 |
source = _uriResolver.resolve(href, context); |
1246 |
} |
|
1247 |
if (source == null && _catalogFiles != null && |
|
1248 |
_xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG)) { |
|
1249 |
if (_catalogUriResolver == null) { |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
1250 |
_catalogUriResolver = CatalogManager.catalogResolver(_catalogFeatures); |
12005 | 1251 |
} |
39907 | 1252 |
source = _catalogUriResolver.resolve(href, context); |
1253 |
} |
|
1254 |
if (source != null) { |
|
1255 |
return Util.getInputSource(xsltc, source); |
|
12005 | 1256 |
} |
1257 |
} |
|
1258 |
catch (TransformerException e) { |
|
1259 |
// should catch it when the resolver explicitly throws the exception |
|
1260 |
final ErrorMsg msg = new ErrorMsg(ErrorMsg.INVALID_URI_ERR, href + "\n" + e.getMessage(), this); |
|
1261 |
xsltc.getParser().reportError(Constants.FATAL, msg); |
|
1262 |
} |
|
40582
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
1263 |
catch (CatalogException e) { |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
1264 |
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CATALOG_EXCEPTION, href + "\n" + e.getMessage(), this); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
1265 |
xsltc.getParser().reportError(Constants.FATAL, msg); |
1dddef49982c
8163232: Catalog API: Consolidating CatalogResolver to support all XML Resolvers
joehw
parents:
39909
diff
changeset
|
1266 |
} |
12005 | 1267 |
|
1268 |
return null; |
|
1269 |
} |
|
1270 |
||
1271 |
/** |
|
39907 | 1272 |
* Build the CatalogFeatures object when a newTemplates or newTransformer is |
1273 |
* created. This will read any System Properties for the CatalogFeatures that |
|
1274 |
* may have been set. |
|
1275 |
*/ |
|
1276 |
private CatalogFeatures buildCatalogFeatures() { |
|
1277 |
// build will cause the CatalogFeatures to read SPs for those not set through the API |
|
1278 |
if (_catalogFeatures == null) { |
|
1279 |
_catalogFeatures = cfBuilder.build(); |
|
1280 |
} |
|
1281 |
||
1282 |
// update fields |
|
1283 |
_catalogFiles = _catalogFeatures.get(Feature.FILES); |
|
1284 |
_catalogDefer = _catalogFeatures.get(Feature.DEFER); |
|
1285 |
_catalogPrefer = _catalogFeatures.get(Feature.PREFER); |
|
1286 |
_catalogResolve = _catalogFeatures.get(Feature.RESOLVE); |
|
1287 |
||
1288 |
return _catalogFeatures; |
|
1289 |
} |
|
1290 |
||
1291 |
/** |
|
12005 | 1292 |
* Reset the per-session attributes to their default values |
1293 |
*/ |
|
1294 |
private void resetTransientAttributes() { |
|
1295 |
_transletName = DEFAULT_TRANSLET_NAME; |
|
1296 |
_destinationDirectory = null; |
|
36520 | 1297 |
_packageName = DEFAULT_TRANSLATE_PACKAGE; |
12005 | 1298 |
_jarFileName = null; |
1299 |
} |
|
1300 |
||
1301 |
/** |
|
1302 |
* Load the translet classes from local .class files and return |
|
1303 |
* the bytecode array. |
|
1304 |
* |
|
1305 |
* @param source The xsl source |
|
1306 |
* @param fullClassName The full name of the translet |
|
1307 |
* @return The bytecode array |
|
1308 |
*/ |
|
1309 |
private byte[][] getBytecodesFromClasses(Source source, String fullClassName) |
|
1310 |
{ |
|
1311 |
if (fullClassName == null) |
|
1312 |
return null; |
|
1313 |
||
1314 |
String xslFileName = getStylesheetFileName(source); |
|
1315 |
File xslFile = null; |
|
1316 |
if (xslFileName != null) |
|
1317 |
xslFile = new File(xslFileName); |
|
1318 |
||
1319 |
// Find the base name of the translet |
|
1320 |
final String transletName; |
|
1321 |
int lastDotIndex = fullClassName.lastIndexOf('.'); |
|
1322 |
if (lastDotIndex > 0) |
|
1323 |
transletName = fullClassName.substring(lastDotIndex+1); |
|
1324 |
else |
|
1325 |
transletName = fullClassName; |
|
1326 |
||
1327 |
// Construct the path name for the translet class file |
|
1328 |
String transletPath = fullClassName.replace('.', '/'); |
|
1329 |
if (_destinationDirectory != null) { |
|
1330 |
transletPath = _destinationDirectory + "/" + transletPath + ".class"; |
|
1331 |
} |
|
1332 |
else { |
|
1333 |
if (xslFile != null && xslFile.getParent() != null) |
|
1334 |
transletPath = xslFile.getParent() + "/" + transletPath + ".class"; |
|
1335 |
else |
|
1336 |
transletPath = transletPath + ".class"; |
|
1337 |
} |
|
1338 |
||
1339 |
// Return null if the translet class file does not exist. |
|
1340 |
File transletFile = new File(transletPath); |
|
1341 |
if (!transletFile.exists()) |
|
1342 |
return null; |
|
1343 |
||
1344 |
// Compare the timestamps of the translet and the xsl file. |
|
1345 |
// If the translet is older than the xsl file, return null |
|
1346 |
// so that the xsl file is used for the transformation and |
|
1347 |
// the translet is regenerated. |
|
1348 |
if (xslFile != null && xslFile.exists()) { |
|
1349 |
long xslTimestamp = xslFile.lastModified(); |
|
1350 |
long transletTimestamp = transletFile.lastModified(); |
|
1351 |
if (transletTimestamp < xslTimestamp) |
|
1352 |
return null; |
|
1353 |
} |
|
1354 |
||
1355 |
// Load the translet into a bytecode array. |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1356 |
List<byte[]> bytecodes = new ArrayList<>(); |
12005 | 1357 |
int fileLength = (int)transletFile.length(); |
1358 |
if (fileLength > 0) { |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1359 |
FileInputStream input; |
12005 | 1360 |
try { |
1361 |
input = new FileInputStream(transletFile); |
|
1362 |
} |
|
1363 |
catch (FileNotFoundException e) { |
|
1364 |
return null; |
|
1365 |
} |
|
1366 |
||
1367 |
byte[] bytes = new byte[fileLength]; |
|
1368 |
try { |
|
1369 |
readFromInputStream(bytes, input, fileLength); |
|
1370 |
input.close(); |
|
1371 |
} |
|
1372 |
catch (IOException e) { |
|
1373 |
return null; |
|
1374 |
} |
|
1375 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1376 |
bytecodes.add(bytes); |
12005 | 1377 |
} |
1378 |
else |
|
1379 |
return null; |
|
1380 |
||
1381 |
// Find the parent directory of the translet. |
|
1382 |
String transletParentDir = transletFile.getParent(); |
|
1383 |
if (transletParentDir == null) |
|
16953 | 1384 |
transletParentDir = SecuritySupport.getSystemProperty("user.dir"); |
12005 | 1385 |
|
1386 |
File transletParentFile = new File(transletParentDir); |
|
1387 |
||
1388 |
// Find all the auxiliary files which have a name pattern of "transletClass$nnn.class". |
|
1389 |
final String transletAuxPrefix = transletName + "$"; |
|
1390 |
File[] auxfiles = transletParentFile.listFiles(new FilenameFilter() { |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1391 |
@Override |
12005 | 1392 |
public boolean accept(File dir, String name) |
1393 |
{ |
|
1394 |
return (name.endsWith(".class") && name.startsWith(transletAuxPrefix)); |
|
1395 |
} |
|
1396 |
}); |
|
1397 |
||
1398 |
// Load the auxiliary class files and add them to the bytecode array. |
|
1399 |
for (int i = 0; i < auxfiles.length; i++) |
|
1400 |
{ |
|
1401 |
File auxfile = auxfiles[i]; |
|
1402 |
int auxlength = (int)auxfile.length(); |
|
1403 |
if (auxlength > 0) { |
|
1404 |
FileInputStream auxinput = null; |
|
1405 |
try { |
|
1406 |
auxinput = new FileInputStream(auxfile); |
|
1407 |
} |
|
1408 |
catch (FileNotFoundException e) { |
|
1409 |
continue; |
|
1410 |
} |
|
1411 |
||
1412 |
byte[] bytes = new byte[auxlength]; |
|
1413 |
||
1414 |
try { |
|
1415 |
readFromInputStream(bytes, auxinput, auxlength); |
|
1416 |
auxinput.close(); |
|
1417 |
} |
|
1418 |
catch (IOException e) { |
|
1419 |
continue; |
|
1420 |
} |
|
1421 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1422 |
bytecodes.add(bytes); |
12005 | 1423 |
} |
1424 |
} |
|
1425 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1426 |
// Convert the ArrayList of byte[] to byte[][]. |
12005 | 1427 |
final int count = bytecodes.size(); |
1428 |
if ( count > 0) { |
|
1429 |
final byte[][] result = new byte[count][1]; |
|
1430 |
for (int i = 0; i < count; i++) { |
|
47712 | 1431 |
result[i] = bytecodes.get(i); |
12005 | 1432 |
} |
1433 |
||
1434 |
return result; |
|
1435 |
} |
|
1436 |
else |
|
1437 |
return null; |
|
1438 |
} |
|
1439 |
||
1440 |
/** |
|
1441 |
* Load the translet classes from the jar file and return the bytecode. |
|
1442 |
* |
|
1443 |
* @param source The xsl source |
|
1444 |
* @param fullClassName The full name of the translet |
|
1445 |
* @return The bytecode array |
|
1446 |
*/ |
|
1447 |
private byte[][] getBytecodesFromJar(Source source, String fullClassName) |
|
1448 |
{ |
|
1449 |
String xslFileName = getStylesheetFileName(source); |
|
1450 |
File xslFile = null; |
|
1451 |
if (xslFileName != null) |
|
1452 |
xslFile = new File(xslFileName); |
|
1453 |
||
1454 |
// Construct the path for the jar file |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1455 |
String jarPath; |
12005 | 1456 |
if (_destinationDirectory != null) |
1457 |
jarPath = _destinationDirectory + "/" + _jarFileName; |
|
1458 |
else { |
|
1459 |
if (xslFile != null && xslFile.getParent() != null) |
|
1460 |
jarPath = xslFile.getParent() + "/" + _jarFileName; |
|
1461 |
else |
|
1462 |
jarPath = _jarFileName; |
|
1463 |
} |
|
1464 |
||
1465 |
// Return null if the jar file does not exist. |
|
1466 |
File file = new File(jarPath); |
|
1467 |
if (!file.exists()) |
|
1468 |
return null; |
|
1469 |
||
1470 |
// Compare the timestamps of the jar file and the xsl file. Return null |
|
1471 |
// if the xsl file is newer than the jar file. |
|
1472 |
if (xslFile != null && xslFile.exists()) { |
|
1473 |
long xslTimestamp = xslFile.lastModified(); |
|
1474 |
long transletTimestamp = file.lastModified(); |
|
1475 |
if (transletTimestamp < xslTimestamp) |
|
1476 |
return null; |
|
1477 |
} |
|
1478 |
||
1479 |
// Create a ZipFile object for the jar file |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1480 |
ZipFile jarFile; |
12005 | 1481 |
try { |
1482 |
jarFile = new ZipFile(file); |
|
1483 |
} |
|
1484 |
catch (IOException e) { |
|
1485 |
return null; |
|
1486 |
} |
|
1487 |
||
1488 |
String transletPath = fullClassName.replace('.', '/'); |
|
1489 |
String transletAuxPrefix = transletPath + "$"; |
|
1490 |
String transletFullName = transletPath + ".class"; |
|
1491 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1492 |
List<byte[]> bytecodes = new ArrayList<>(); |
12005 | 1493 |
|
1494 |
// Iterate through all entries in the jar file to find the |
|
1495 |
// translet and auxiliary classes. |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1496 |
Enumeration<? extends ZipEntry> entries = jarFile.entries(); |
12005 | 1497 |
while (entries.hasMoreElements()) |
1498 |
{ |
|
1499 |
ZipEntry entry = (ZipEntry)entries.nextElement(); |
|
1500 |
String entryName = entry.getName(); |
|
1501 |
if (entry.getSize() > 0 && |
|
1502 |
(entryName.equals(transletFullName) || |
|
1503 |
(entryName.endsWith(".class") && |
|
1504 |
entryName.startsWith(transletAuxPrefix)))) |
|
1505 |
{ |
|
1506 |
try { |
|
1507 |
InputStream input = jarFile.getInputStream(entry); |
|
1508 |
int size = (int)entry.getSize(); |
|
1509 |
byte[] bytes = new byte[size]; |
|
1510 |
readFromInputStream(bytes, input, size); |
|
1511 |
input.close(); |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1512 |
bytecodes.add(bytes); |
12005 | 1513 |
} |
1514 |
catch (IOException e) { |
|
1515 |
return null; |
|
1516 |
} |
|
1517 |
} |
|
1518 |
} |
|
1519 |
||
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47312
diff
changeset
|
1520 |
// Convert the ArrayList of byte[] to byte[][]. |
12005 | 1521 |
final int count = bytecodes.size(); |
1522 |
if (count > 0) { |
|
1523 |
final byte[][] result = new byte[count][1]; |
|
1524 |
for (int i = 0; i < count; i++) { |
|
47712 | 1525 |
result[i] = bytecodes.get(i); |
12005 | 1526 |
} |
1527 |
||
1528 |
return result; |
|
1529 |
} |
|
1530 |
else |
|
1531 |
return null; |
|
1532 |
} |
|
1533 |
||
1534 |
/** |
|
1535 |
* Read a given number of bytes from the InputStream into a byte array. |
|
1536 |
* |
|
1537 |
* @param bytes The byte array to store the input content. |
|
1538 |
* @param input The input stream. |
|
1539 |
* @param size The number of bytes to read. |
|
1540 |
*/ |
|
1541 |
private void readFromInputStream(byte[] bytes, InputStream input, int size) |
|
1542 |
throws IOException |
|
1543 |
{ |
|
1544 |
int n = 0; |
|
1545 |
int offset = 0; |
|
1546 |
int length = size; |
|
1547 |
while (length > 0 && (n = input.read(bytes, offset, length)) > 0) { |
|
1548 |
offset = offset + n; |
|
1549 |
length = length - n; |
|
1550 |
} |
|
1551 |
} |
|
1552 |
||
1553 |
/** |
|
1554 |
* Return the base class name of the translet. |
|
1555 |
* The translet name is resolved using the following rules: |
|
1556 |
* 1. if the _transletName attribute is set and its value is not "GregorSamsa", |
|
1557 |
* then _transletName is returned. |
|
1558 |
* 2. otherwise get the translet name from the base name of the system ID |
|
1559 |
* 3. return "GregorSamsa" if the result from step 2 is null. |
|
1560 |
* |
|
1561 |
* @param source The input Source |
|
1562 |
* @return The name of the translet class |
|
1563 |
*/ |
|
1564 |
private String getTransletBaseName(Source source) |
|
1565 |
{ |
|
1566 |
String transletBaseName = null; |
|
1567 |
if (!_transletName.equals(DEFAULT_TRANSLET_NAME)) |
|
1568 |
return _transletName; |
|
1569 |
else { |
|
1570 |
String systemId = source.getSystemId(); |
|
1571 |
if (systemId != null) { |
|
1572 |
String baseName = Util.baseName(systemId); |
|
1573 |
if (baseName != null) { |
|
1574 |
baseName = Util.noExtName(baseName); |
|
1575 |
transletBaseName = Util.toJavaName(baseName); |
|
1576 |
} |
|
1577 |
} |
|
1578 |
} |
|
1579 |
||
1580 |
return (transletBaseName != null) ? transletBaseName : DEFAULT_TRANSLET_NAME; |
|
1581 |
} |
|
1582 |
||
1583 |
/** |
|
1584 |
* Return the local file name from the systemId of the Source object |
|
1585 |
* |
|
1586 |
* @param source The Source |
|
1587 |
* @return The file name in the local filesystem, or null if the |
|
1588 |
* systemId does not represent a local file. |
|
1589 |
*/ |
|
1590 |
private String getStylesheetFileName(Source source) |
|
1591 |
{ |
|
1592 |
String systemId = source.getSystemId(); |
|
1593 |
if (systemId != null) { |
|
1594 |
File file = new File(systemId); |
|
1595 |
if (file.exists()) |
|
1596 |
return systemId; |
|
1597 |
else { |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1598 |
URL url; |
12005 | 1599 |
try { |
1600 |
url = new URL(systemId); |
|
1601 |
} |
|
1602 |
catch (MalformedURLException e) { |
|
1603 |
return null; |
|
1604 |
} |
|
1605 |
||
1606 |
if ("file".equals(url.getProtocol())) |
|
1607 |
return url.getFile(); |
|
1608 |
else |
|
1609 |
return null; |
|
1610 |
} |
|
1611 |
} |
|
1612 |
else |
|
1613 |
return null; |
|
1614 |
} |
|
1615 |
||
1616 |
/** |
|
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1617 |
* Returns a new instance of the XSLTC DTM Manager service. |
12005 | 1618 |
*/ |
18352
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1619 |
protected final XSLTCDTMManager createNewDTMManagerInstance() { |
a1e183c996d6
8013434: Xalan and Xerces internal ObjectFactory need rework
dfuchs
parents:
17991
diff
changeset
|
1620 |
return XSLTCDTMManager.createNewDTMManagerInstance(); |
12005 | 1621 |
} |
1622 |
} |