< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java

Print this page
rev 1063 : 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input


  59  * @author Santiago Pericas-Geertsen
  60  * @author G. Todd Miller
  61  * @author Morten Jorgensen
  62  * @author John Howard (johnh@schemasoft.com)
  63  */
  64 public final class XSLTC {
  65 
  66     // A reference to the main stylesheet parser object.
  67     private Parser _parser;
  68 
  69     // A reference to an external XMLReader (SAX parser) passed to us
  70     private XMLReader _reader = null;
  71 
  72     // A reference to an external SourceLoader (for use with include/import)
  73     private SourceLoader _loader = null;
  74 
  75     // A reference to the stylesheet being compiled.
  76     private Stylesheet _stylesheet;
  77 
  78     // Counters used by various classes to generate unique names.
  79     // private int _variableSerial     = 1;
  80     private int _modeSerial         = 1;
  81     private int _stylesheetSerial   = 1;
  82     private int _stepPatternSerial  = 1;
  83     private int _helperClassSerial  = 0;
  84     private int _attributeSetSerial = 0;
  85 
  86     private int[] _numberFieldIndexes;
  87 
  88     // Name index tables
  89     private int       _nextGType;  // Next available element type
  90     private Vector    _namesIndex; // Index of all registered QNames
  91     private Map<String, Integer> _elements;   // Map of all registered elements
  92     private Map<String, Integer> _attributes; // Map of all registered attributes
  93 
  94     // Namespace index tables
  95     private int       _nextNSType; // Next available namespace type
  96     private Vector    _namespaceIndex; // Index of all registered namespaces
  97     private Map<String, Integer> _namespaces; // Map of all registered namespaces
  98     private Map<String, Integer> _namespacePrefixes;// Map of all registered namespace prefixes
  99 


 126 
 127     /**
 128      * Set to true if template inlining is requested. Template
 129      * inlining used to be the default, but we have found that
 130      * Hotspots does a better job with shorter methods, so the
 131      * default is *not* to inline now.
 132      */
 133     private boolean _templateInlining = false;
 134 
 135     /**
 136      * State of the secure processing feature.
 137      */
 138     private boolean _isSecureProcessing = false;
 139 
 140     private boolean _useServicesMechanism = true;
 141 
 142     /**
 143      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
 144      */
 145     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 146      /**

 147      * protocols allowed for external DTD references in source file and/or stylesheet.
 148      */
 149     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 150 
 151     private XMLSecurityManager _xmlSecurityManager;
 152 
 153     private final JdkXmlFeatures _xmlFeatures;
 154 
 155     /**
 156     *  Extension function class loader variables
 157     */
 158 
 159     /* Class loader reference that will be used for external extension functions loading */


 160     private ClassLoader _extensionClassLoader;
 161 
 162     /**
 163     *  HashMap with the loaded classes
 164     */
 165     private final Map<String, Class<?>> _externalExtensionFunctions;
 166 
 167     /**
 168      * Catalog features
 169      */
 170     CatalogFeatures _catalogFeatures;
 171 
 172     /**
 173      * CDATA chunk size
 174      */
 175     int _cdataChunkSize;
 176 
 177     /**
 178      * XSLTC compiler constructor
 179      */
 180     public XSLTC(boolean useServicesMechanism, JdkXmlFeatures featureManager) {
 181         _parser = new Parser(this, useServicesMechanism);
 182         _xmlFeatures = featureManager;
 183         _extensionClassLoader = null;
 184         _externalExtensionFunctions = new HashMap<>();


 288     public Properties getOutputProperties() {
 289         return _parser.getOutputProperties();
 290     }
 291 
 292     /**
 293      * Initializes the compiler to compile a new stylesheet
 294      */
 295     public void init() {
 296         reset();
 297         _reader = null;
 298         _classes = new ArrayList<>();
 299         _bcelClasses = new ArrayList<>();
 300     }
 301 
 302     private void setExternalExtensionFunctions(String name, Class<?> clazz) {
 303         if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
 304             _externalExtensionFunctions.put(name, clazz);
 305         }
 306     }
 307 
 308     /*
 309      * Function loads an external extension function.
 310      * The filtering of function types (external,internal) takes place in FunctionCall class
 311      *
 312      */
 313     Class loadExternalFunction(String name) throws ClassNotFoundException {
 314         Class loaded = null;
 315         //Check if the function is not loaded already
 316         if (_externalExtensionFunctions.containsKey(name)) {
 317             loaded = _externalExtensionFunctions.get(name);
 318         } else if (_extensionClassLoader != null) {
 319             loaded = Class.forName(name, true, _extensionClassLoader);
 320             setExternalExtensionFunctions(name, loaded);
 321         }
 322         if (loaded == null) {
 323             throw new ClassNotFoundException(name);
 324         }
 325         //Return loaded class
 326         return (Class) loaded;
 327     }
 328 
 329     /*
 330      * Returns unmodifiable view of HashMap with loaded external extension
 331      * functions - will be needed for the TransformerImpl
 332     */
 333     public Map<String, Class<?>> getExternalExtensionFunctions() {
 334         return Collections.unmodifiableMap(_externalExtensionFunctions);
 335     }
 336 
 337     /**
 338      * Initializes the compiler to produce a new translet
 339      */
 340     private void reset() {
 341         _nextGType      = DTM.NTYPES;
 342         _elements       = new HashMap<>();
 343         _attributes     = new HashMap<>();
 344         _namespaces     = new HashMap<>();
 345         _namespaces.put("",new Integer(_nextNSType));
 346         _namesIndex     = new Vector(128);
 347         _namespaceIndex = new Vector(32);
 348         _namespacePrefixes = new HashMap<>();
 349         _stylesheet     = null;
 350         _parser.init();
 351         //_variableSerial     = 1;
 352         _modeSerial         = 1;
 353         _stylesheetSerial   = 1;
 354         _stepPatternSerial  = 1;
 355         _helperClassSerial  = 0;
 356         _attributeSetSerial = 0;
 357         _multiDocument      = false;
 358         _hasIdCall          = false;
 359         _numberFieldIndexes = new int[] {
 360             -1,         // LEVEL_SINGLE
 361             -1,         // LEVEL_MULTIPLE
 362             -1          // LEVEL_ANY
 363         };
 364         _externalExtensionFunctions.clear();
 365     }
 366 
 367     /**
 368      * Defines an external SourceLoader to provide the compiler with documents
 369      * referenced in xsl:include/import
 370      * @param loader The SourceLoader to use for include/import
 371      */




  59  * @author Santiago Pericas-Geertsen
  60  * @author G. Todd Miller
  61  * @author Morten Jorgensen
  62  * @author John Howard (johnh@schemasoft.com)
  63  */
  64 public final class XSLTC {
  65 
  66     // A reference to the main stylesheet parser object.
  67     private Parser _parser;
  68 
  69     // A reference to an external XMLReader (SAX parser) passed to us
  70     private XMLReader _reader = null;
  71 
  72     // A reference to an external SourceLoader (for use with include/import)
  73     private SourceLoader _loader = null;
  74 
  75     // A reference to the stylesheet being compiled.
  76     private Stylesheet _stylesheet;
  77 
  78     // Counters used by various classes to generate unique names.

  79     private int _modeSerial         = 1;
  80     private int _stylesheetSerial   = 1;
  81     private int _stepPatternSerial  = 1;
  82     private int _helperClassSerial  = 0;
  83     private int _attributeSetSerial = 0;
  84 
  85     private int[] _numberFieldIndexes;
  86 
  87     // Name index tables
  88     private int       _nextGType;  // Next available element type
  89     private Vector    _namesIndex; // Index of all registered QNames
  90     private Map<String, Integer> _elements;   // Map of all registered elements
  91     private Map<String, Integer> _attributes; // Map of all registered attributes
  92 
  93     // Namespace index tables
  94     private int       _nextNSType; // Next available namespace type
  95     private Vector    _namespaceIndex; // Index of all registered namespaces
  96     private Map<String, Integer> _namespaces; // Map of all registered namespaces
  97     private Map<String, Integer> _namespacePrefixes;// Map of all registered namespace prefixes
  98 


 125 
 126     /**
 127      * Set to true if template inlining is requested. Template
 128      * inlining used to be the default, but we have found that
 129      * Hotspots does a better job with shorter methods, so the
 130      * default is *not* to inline now.
 131      */
 132     private boolean _templateInlining = false;
 133 
 134     /**
 135      * State of the secure processing feature.
 136      */
 137     private boolean _isSecureProcessing = false;
 138 
 139     private boolean _useServicesMechanism = true;
 140 
 141     /**
 142      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
 143      */
 144     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 145 
 146     /**
 147      * protocols allowed for external DTD references in source file and/or stylesheet.
 148      */
 149     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 150 
 151     private XMLSecurityManager _xmlSecurityManager;
 152 
 153     private final JdkXmlFeatures _xmlFeatures;
 154 
 155     /**
 156      *  Extension function class loader variables
 157      */
 158 
 159     /**
 160      * Class loader reference that will be used for external extension functions loading
 161      */
 162     private ClassLoader _extensionClassLoader;
 163 
 164     /**
 165      *  HashMap with the loaded classes
 166      */
 167     private final Map<String, Class<?>> _externalExtensionFunctions;
 168 
 169     /**
 170      * Catalog features
 171      */
 172     CatalogFeatures _catalogFeatures;
 173 
 174     /**
 175      * CDATA chunk size
 176      */
 177     int _cdataChunkSize;
 178 
 179     /**
 180      * XSLTC compiler constructor
 181      */
 182     public XSLTC(boolean useServicesMechanism, JdkXmlFeatures featureManager) {
 183         _parser = new Parser(this, useServicesMechanism);
 184         _xmlFeatures = featureManager;
 185         _extensionClassLoader = null;
 186         _externalExtensionFunctions = new HashMap<>();


 290     public Properties getOutputProperties() {
 291         return _parser.getOutputProperties();
 292     }
 293 
 294     /**
 295      * Initializes the compiler to compile a new stylesheet
 296      */
 297     public void init() {
 298         reset();
 299         _reader = null;
 300         _classes = new ArrayList<>();
 301         _bcelClasses = new ArrayList<>();
 302     }
 303 
 304     private void setExternalExtensionFunctions(String name, Class<?> clazz) {
 305         if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
 306             _externalExtensionFunctions.put(name, clazz);
 307         }
 308     }
 309 
 310     /**
 311      * Function loads an external extension function.
 312      * The filtering of function types (external,internal) takes place in FunctionCall class
 313      *
 314      */
 315     Class loadExternalFunction(String name) throws ClassNotFoundException {
 316         Class loaded = null;
 317         //Check if the function is not loaded already
 318         if (_externalExtensionFunctions.containsKey(name)) {
 319             loaded = _externalExtensionFunctions.get(name);
 320         } else if (_extensionClassLoader != null) {
 321             loaded = Class.forName(name, true, _extensionClassLoader);
 322             setExternalExtensionFunctions(name, loaded);
 323         }
 324         if (loaded == null) {
 325             throw new ClassNotFoundException(name);
 326         }
 327         //Return loaded class
 328         return (Class) loaded;
 329     }
 330 
 331     /**
 332      * Returns unmodifiable view of HashMap with loaded external extension
 333      * functions - will be needed for the TransformerImpl
 334      */
 335     public Map<String, Class<?>> getExternalExtensionFunctions() {
 336         return Collections.unmodifiableMap(_externalExtensionFunctions);
 337     }
 338 
 339     /**
 340      * Initializes the compiler to produce a new translet
 341      */
 342     private void reset() {
 343         _nextGType      = DTM.NTYPES;
 344         _elements       = new HashMap<>();
 345         _attributes     = new HashMap<>();
 346         _namespaces     = new HashMap<>();
 347         _namespaces.put("",new Integer(_nextNSType));
 348         _namesIndex     = new Vector(128);
 349         _namespaceIndex = new Vector(32);
 350         _namespacePrefixes = new HashMap<>();
 351         _stylesheet     = null;
 352         _parser.init();

 353         _modeSerial         = 1;
 354         _stylesheetSerial   = 1;
 355         _stepPatternSerial  = 1;
 356         _helperClassSerial  = 0;
 357         _attributeSetSerial = 0;
 358         _multiDocument      = false;
 359         _hasIdCall          = false;
 360         _numberFieldIndexes = new int[] {
 361             -1,         // LEVEL_SINGLE
 362             -1,         // LEVEL_MULTIPLE
 363             -1          // LEVEL_ANY
 364         };
 365         _externalExtensionFunctions.clear();
 366     }
 367 
 368     /**
 369      * Defines an external SourceLoader to provide the compiler with documents
 370      * referenced in xsl:include/import
 371      * @param loader The SourceLoader to use for include/import
 372      */


< prev index next >