equal
deleted
inserted
replaced
21 * $Id: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $ |
21 * $Id: TransformerImpl.java,v 1.10 2007/06/13 01:57:09 joehw Exp $ |
22 */ |
22 */ |
23 |
23 |
24 package com.sun.org.apache.xalan.internal.xsltc.trax; |
24 package com.sun.org.apache.xalan.internal.xsltc.trax; |
25 |
25 |
|
26 import com.sun.org.apache.xalan.internal.utils.FactoryImpl; |
26 import java.io.File; |
27 import java.io.File; |
27 import java.io.FileOutputStream; |
28 import java.io.FileOutputStream; |
28 import java.io.IOException; |
29 import java.io.IOException; |
29 import java.io.InputStream; |
30 import java.io.InputStream; |
30 import java.io.OutputStream; |
31 import java.io.OutputStream; |
180 private XSLTCDTMManager _dtmManager = null; |
181 private XSLTCDTMManager _dtmManager = null; |
181 |
182 |
182 /** |
183 /** |
183 * A reference to an object that creates and caches XMLReader objects. |
184 * A reference to an object that creates and caches XMLReader objects. |
184 */ |
185 */ |
185 private XMLReaderManager _readerManager = XMLReaderManager.getInstance(); |
186 private XMLReaderManager _readerManager; |
186 |
187 |
187 /** |
188 /** |
188 * A flag indicating whether we use incremental building of the DTM. |
189 * A flag indicating whether we use incremental building of the DTM. |
189 */ |
190 */ |
190 //private boolean _isIncremental = false; |
191 //private boolean _isIncremental = false; |
197 |
198 |
198 /** |
199 /** |
199 * State of the secure processing feature. |
200 * State of the secure processing feature. |
200 */ |
201 */ |
201 private boolean _isSecureProcessing = false; |
202 private boolean _isSecureProcessing = false; |
|
203 |
|
204 /** |
|
205 * Indicates whether implementation parts should use |
|
206 * service loader (or similar). |
|
207 * Note the default value (false) is the safe option.. |
|
208 */ |
|
209 private boolean _useServicesMechanism; |
202 |
210 |
203 /** |
211 /** |
204 * A hashtable to store parameters for the identity transform. These |
212 * A hashtable to store parameters for the identity transform. These |
205 * are not needed during the transformation, but we must keep track of |
213 * are not needed during the transformation, but we must keep track of |
206 * them to be fully complaint with the JAXP API. |
214 * them to be fully complaint with the JAXP API. |
249 _translet = (AbstractTranslet) translet; |
257 _translet = (AbstractTranslet) translet; |
250 _properties = createOutputProperties(outputProperties); |
258 _properties = createOutputProperties(outputProperties); |
251 _propertiesClone = (Properties) _properties.clone(); |
259 _propertiesClone = (Properties) _properties.clone(); |
252 _indentNumber = indentNumber; |
260 _indentNumber = indentNumber; |
253 _tfactory = tfactory; |
261 _tfactory = tfactory; |
|
262 _useServicesMechanism = _tfactory.useServicesMechnism(); |
|
263 _readerManager = XMLReaderManager.getInstance(_useServicesMechanism); |
254 //_isIncremental = tfactory._incremental; |
264 //_isIncremental = tfactory._incremental; |
255 } |
265 } |
256 |
266 |
257 /** |
267 /** |
258 * Return the state of the secure processing feature. |
268 * Return the state of the secure processing feature. |
264 /** |
274 /** |
265 * Set the state of the secure processing feature. |
275 * Set the state of the secure processing feature. |
266 */ |
276 */ |
267 public void setSecureProcessing(boolean flag) { |
277 public void setSecureProcessing(boolean flag) { |
268 _isSecureProcessing = flag; |
278 _isSecureProcessing = flag; |
|
279 } |
|
280 /** |
|
281 * Return the state of the services mechanism feature. |
|
282 */ |
|
283 public boolean useServicesMechnism() { |
|
284 return _useServicesMechanism; |
|
285 } |
|
286 |
|
287 /** |
|
288 * Set the state of the services mechanism feature. |
|
289 */ |
|
290 public void setServicesMechnism(boolean flag) { |
|
291 _useServicesMechanism = flag; |
269 } |
292 } |
270 |
293 |
271 /** |
294 /** |
272 * Returns the translet wrapped inside this Transformer or |
295 * Returns the translet wrapped inside this Transformer or |
273 * null if this is the identity transform. |
296 * null if this is the identity transform. |
345 _method = (String) _properties.get(OutputKeys.METHOD); |
368 _method = (String) _properties.get(OutputKeys.METHOD); |
346 |
369 |
347 // Get encoding using getProperty() to use defaults |
370 // Get encoding using getProperty() to use defaults |
348 _encoding = (String) _properties.getProperty(OutputKeys.ENCODING); |
371 _encoding = (String) _properties.getProperty(OutputKeys.ENCODING); |
349 |
372 |
350 _tohFactory = TransletOutputHandlerFactory.newInstance(); |
373 _tohFactory = TransletOutputHandlerFactory.newInstance(_useServicesMechanism); |
351 _tohFactory.setEncoding(_encoding); |
374 _tohFactory.setEncoding(_encoding); |
352 if (_method != null) { |
375 if (_method != null) { |
353 _tohFactory.setOutputMethod(_method); |
376 _tohFactory.setOutputMethod(_method); |
354 } |
377 } |
355 |
378 |
433 if (systemId.startsWith("file:")) { |
456 if (systemId.startsWith("file:")) { |
434 // if StreamResult(File) or setSystemID(File) was used, |
457 // if StreamResult(File) or setSystemID(File) was used, |
435 // the systemId will be URI encoded as a result of File.toURI(), |
458 // the systemId will be URI encoded as a result of File.toURI(), |
436 // it must be decoded for use by URL |
459 // it must be decoded for use by URL |
437 try{ |
460 try{ |
438 Class clazz = ObjectFactory.findProviderClass("java.net.URI", ObjectFactory.findClassLoader(), true); |
461 URI uri = new URI(systemId) ; |
439 Constructor construct = clazz.getConstructor(new Class[] {java.lang.String.class} ); |
|
440 URI uri = (URI) construct.newInstance(new Object[]{systemId}) ; |
|
441 systemId = "file:"; |
462 systemId = "file:"; |
442 |
463 |
443 String host = uri.getHost(); // decoded String |
464 String host = uri.getHost(); // decoded String |
444 String path = uri.getPath(); //decoded String |
465 String path = uri.getPath(); //decoded String |
445 if (path == null) { |
466 if (path == null) { |
452 systemId += "//" + host + path; |
473 systemId += "//" + host + path; |
453 } else { |
474 } else { |
454 systemId += "//" + path; |
475 systemId += "//" + path; |
455 } |
476 } |
456 } |
477 } |
457 catch(ClassNotFoundException e){ |
|
458 // running on J2SE 1.3 which doesn't have URI Class so OK to ignore |
|
459 //ClassNotFoundException. |
|
460 } |
|
461 catch (Exception exception) { |
478 catch (Exception exception) { |
462 // URI exception which means nothing can be done so OK to ignore |
479 // URI exception which means nothing can be done so OK to ignore |
463 } |
480 } |
464 |
481 |
465 url = new URL(systemId); |
482 url = new URL(systemId); |
522 |
539 |
523 if (_dtmManager == null) { |
540 if (_dtmManager == null) { |
524 _dtmManager = |
541 _dtmManager = |
525 (XSLTCDTMManager)_tfactory.getDTMManagerClass() |
542 (XSLTCDTMManager)_tfactory.getDTMManagerClass() |
526 .newInstance(); |
543 .newInstance(); |
|
544 _dtmManager.setServicesMechnism(_useServicesMechanism); |
527 } |
545 } |
528 dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true, |
546 dom = (DOM)_dtmManager.getDTM(source, false, wsfilter, true, |
529 false, false, 0, hasIdCall); |
547 false, false, 0, hasIdCall); |
530 } else if (_dom != null) { |
548 } else if (_dom != null) { |
531 dom = _dom; |
549 dom = _dom; |
693 (source instanceof SAXSource && |
711 (source instanceof SAXSource && |
694 ((SAXSource)source).getInputSource()==null && |
712 ((SAXSource)source).getInputSource()==null && |
695 ((SAXSource)source).getXMLReader()==null )|| |
713 ((SAXSource)source).getXMLReader()==null )|| |
696 (source instanceof DOMSource && |
714 (source instanceof DOMSource && |
697 ((DOMSource)source).getNode()==null)){ |
715 ((DOMSource)source).getNode()==null)){ |
698 DocumentBuilderFactory builderF = |
716 DocumentBuilderFactory builderF = FactoryImpl.getDOMFactory(_useServicesMechanism); |
699 DocumentBuilderFactory.newInstance(); |
717 DocumentBuilder builder = builderF.newDocumentBuilder(); |
700 DocumentBuilder builder = |
|
701 builderF.newDocumentBuilder(); |
|
702 String systemID = source.getSystemId(); |
718 String systemID = source.getSystemId(); |
703 source = new DOMSource(builder.newDocument()); |
719 source = new DOMSource(builder.newDocument()); |
704 |
720 |
705 // Copy system ID from original, empty Source to new |
721 // Copy system ID from original, empty Source to new |
706 if (systemID != null) { |
722 if (systemID != null) { |
972 while (e.hasMoreTokens()) { |
988 while (e.hasMoreTokens()) { |
973 translet.addCdataElement(e.nextToken()); |
989 translet.addCdataElement(e.nextToken()); |
974 } |
990 } |
975 } |
991 } |
976 } |
992 } |
|
993 else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) { |
|
994 if (value != null && value.equals("yes")) { |
|
995 translet._isStandalone = true; |
|
996 } |
|
997 } |
977 } |
998 } |
978 } |
999 } |
979 |
1000 |
980 /** |
1001 /** |
981 * This method is used to pass any properties to the output handler |
1002 * This method is used to pass any properties to the output handler |
1029 } |
1050 } |
1030 } |
1051 } |
1031 else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) { |
1052 else if (name.equals(OutputPropertiesFactory.S_BUILTIN_EXTENSIONS_UNIVERSAL +"indent-amount")) { |
1032 if (value != null) { |
1053 if (value != null) { |
1033 handler.setIndentAmount(Integer.parseInt(value)); |
1054 handler.setIndentAmount(Integer.parseInt(value)); |
|
1055 } |
|
1056 } |
|
1057 else if (name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE)) { |
|
1058 if (value != null && value.equals("yes")) { |
|
1059 handler.setIsStandalone(true); |
1034 } |
1060 } |
1035 } |
1061 } |
1036 else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) { |
1062 else if (name.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) { |
1037 if (value != null) { |
1063 if (value != null) { |
1038 StringTokenizer e = new StringTokenizer(value); |
1064 StringTokenizer e = new StringTokenizer(value); |
1144 name.equals(OutputKeys.CDATA_SECTION_ELEMENTS) || |
1170 name.equals(OutputKeys.CDATA_SECTION_ELEMENTS) || |
1145 name.equals(OutputKeys.MEDIA_TYPE) || |
1171 name.equals(OutputKeys.MEDIA_TYPE) || |
1146 name.equals(OutputKeys.OMIT_XML_DECLARATION) || |
1172 name.equals(OutputKeys.OMIT_XML_DECLARATION) || |
1147 name.equals(OutputKeys.STANDALONE) || |
1173 name.equals(OutputKeys.STANDALONE) || |
1148 name.equals(OutputKeys.VERSION) || |
1174 name.equals(OutputKeys.VERSION) || |
|
1175 name.equals(OutputPropertiesFactory.ORACLE_IS_STANDALONE) || |
1149 name.charAt(0) == '{'); |
1176 name.charAt(0) == '{'); |
1150 } |
1177 } |
1151 |
1178 |
1152 /** |
1179 /** |
1153 * Checks if a given output property is default (2nd layer only) |
1180 * Checks if a given output property is default (2nd layer only) |
1250 */ |
1277 */ |
1251 public DOM retrieveDocument(String baseURI, String href, Translet translet) { |
1278 public DOM retrieveDocument(String baseURI, String href, Translet translet) { |
1252 try { |
1279 try { |
1253 // Argument to document function was: document(''); |
1280 // Argument to document function was: document(''); |
1254 if (href.length() == 0) { |
1281 if (href.length() == 0) { |
1255 href = new String(baseURI); |
1282 href = baseURI; |
1256 } |
1283 } |
1257 |
1284 |
1258 /* |
1285 /* |
1259 * Fix for bug 24188 |
1286 * Fix for bug 24188 |
1260 * Incase the _uriResolver.resolve(href,base) is null |
1287 * Incase the _uriResolver.resolve(href,base) is null |