< prev index next >

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

Print this page
rev 959 : 8162598: XSLTC transformer swallows empty namespace declaration which is needed to undeclare default namespace
   1 /*
   2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   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
  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  * $Id: XSLTC.java,v 1.2.4.1 2005/09/05 09:51:38 pvedula Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  25 
  26 import com.sun.org.apache.bcel.internal.classfile.JavaClass;
  27 import com.sun.org.apache.xalan.internal.XalanConstants;
  28 import com.sun.org.apache.xalan.internal.utils.FeatureManager;
  29 import com.sun.org.apache.xalan.internal.utils.FeatureManager.Feature;
  30 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
  31 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
  32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
  33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
  34 import com.sun.org.apache.xml.internal.dtm.DTM;
  35 import java.io.BufferedOutputStream;
  36 import java.io.ByteArrayOutputStream;
  37 import java.io.File;
  38 import java.io.FileOutputStream;
  39 import java.io.IOException;
  40 import java.io.InputStream;
  41 import java.net.URL;
  42 import java.security.AccessController;
  43 import java.security.PrivilegedAction;

  44 import java.util.Collections;
  45 import java.util.Date;
  46 import java.util.Enumeration;
  47 import java.util.HashMap;
  48 import java.util.Map;
  49 import java.util.Properties;
  50 import java.util.Objects;
  51 import java.util.Vector;
  52 import java.util.jar.JarEntry;
  53 import java.util.jar.JarOutputStream;
  54 import java.util.jar.Manifest;
  55 import javax.xml.XMLConstants;
  56 import org.xml.sax.InputSource;
  57 import org.xml.sax.XMLReader;
  58 
  59 /**
  60  * @author Jacek Ambroziak
  61  * @author Santiago Pericas-Geertsen
  62  * @author G. Todd Miller
  63  * @author Morten Jorgensen


 141 
 142     private boolean _useServicesMechanism = true;
 143 
 144     /**
 145      * protocols allowed for external references set by the stylesheet processing instruction, Import and Include element.
 146      */
 147     private String _accessExternalStylesheet = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 148      /**
 149      * protocols allowed for external DTD references in source file and/or stylesheet.
 150      */
 151     private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT;
 152 
 153     private XMLSecurityManager _xmlSecurityManager;
 154 
 155     private final FeatureManager _featureManager;
 156 
 157     /**
 158     *  Extension function class loader variables
 159     */
 160 
 161     /* Class loader reference that will be used to external extension functions loading */
 162     private ClassLoader _extensionClassLoader;
 163 
 164     /**
 165     *  HashSet with the loaded classes
 166     */
 167     private final Map<String, Class> _externalExtensionFunctions;
 168 
 169     /**
 170      * XSLTC compiler constructor
 171      */
 172     public XSLTC(boolean useServicesMechanism, FeatureManager featureManager) {
 173         _parser = new Parser(this, useServicesMechanism);
 174         _featureManager = featureManager;
 175         _extensionClassLoader = null;
 176         _externalExtensionFunctions = new HashMap<>();
 177     }
 178 
 179     /**
 180      * Set the state of the secure processing feature.
 181      */
 182     public void setSecureProcessing(boolean flag) {
 183         _isSecureProcessing = flag;
 184     }
 185 


 269         return _parser.getOutputProperties();
 270     }
 271 
 272     /**
 273      * Initializes the compiler to compile a new stylesheet
 274      */
 275     public void init() {
 276         reset();
 277         _reader = null;
 278         _classes = new Vector();
 279         _bcelClasses = new Vector();
 280     }
 281 
 282     private void setExternalExtensionFunctions(String name, Class clazz) {
 283         if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
 284             _externalExtensionFunctions.put(name, clazz);
 285         }
 286     }
 287 
 288     /*
 289      * Function loads an external external extension functions.
 290      * The filtering of function types (external,internal) takes place in FunctionCall class
 291      *
 292      */
 293     Class loadExternalFunction(String name) throws ClassNotFoundException {
 294         Class loaded = null;
 295         //Check if the function is not loaded already
 296         if (_externalExtensionFunctions.containsKey(name)) {
 297             loaded = _externalExtensionFunctions.get(name);
 298         } else if (_extensionClassLoader != null) {
 299             loaded = Class.forName(name, true, _extensionClassLoader);
 300             setExternalExtensionFunctions(name, loaded);
 301         }
 302         if (loaded == null) {
 303             throw new ClassNotFoundException(name);
 304         }
 305         //Return loaded class
 306         return (Class) loaded;
 307     }
 308 
 309     /*


 587 
 588     /**
 589      * Set the XMLReader to use for parsing the next input stylesheet
 590      * @param reader XMLReader (SAX2 parser) to use
 591      */
 592     public void setXMLReader(XMLReader reader) {
 593         _reader = reader;
 594     }
 595 
 596     /**
 597      * Get the XMLReader to use for parsing the next input stylesheet
 598      */
 599     public XMLReader getXMLReader() {
 600         return _reader ;
 601     }
 602 
 603     /**
 604      * Get a Vector containing all compile error messages
 605      * @return A Vector containing all compile error messages
 606      */
 607     public Vector getErrors() {
 608         return _parser.getErrors();
 609     }
 610 
 611     /**
 612      * Get a Vector containing all compile warning messages
 613      * @return A Vector containing all compile error messages
 614      */
 615     public Vector getWarnings() {
 616         return _parser.getWarnings();
 617     }
 618 
 619     /**
 620      * Print all compile error messages to standard output
 621      */
 622     public void printErrors() {
 623         _parser.printErrors();
 624     }
 625 
 626     /**
 627      * Print all compile warning messages to standard output
 628      */
 629     public void printWarnings() {
 630         _parser.printWarnings();
 631     }
 632 
 633     /**
 634      * This method is called by the XPathParser when it encounters a call
 635      * to the document() function. Affects the DOM used by the translet.


   1 /*
   2  * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   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
  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.compiler;
  22 
  23 import com.sun.org.apache.bcel.internal.classfile.JavaClass;
  24 import com.sun.org.apache.xalan.internal.XalanConstants;
  25 import com.sun.org.apache.xalan.internal.utils.FeatureManager;
  26 import com.sun.org.apache.xalan.internal.utils.FeatureManager.Feature;
  27 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
  28 import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager;
  29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
  30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
  31 import com.sun.org.apache.xml.internal.dtm.DTM;
  32 import java.io.BufferedOutputStream;
  33 import java.io.ByteArrayOutputStream;
  34 import java.io.File;
  35 import java.io.FileOutputStream;
  36 import java.io.IOException;
  37 import java.io.InputStream;
  38 import java.net.URL;
  39 import java.security.AccessController;
  40 import java.security.PrivilegedAction;
  41 import java.util.ArrayList;
  42 import java.util.Collections;
  43 import java.util.Date;
  44 import java.util.Enumeration;
  45 import java.util.HashMap;
  46 import java.util.Map;
  47 import java.util.Properties;
  48 import java.util.Objects;
  49 import java.util.Vector;
  50 import java.util.jar.JarEntry;
  51 import java.util.jar.JarOutputStream;
  52 import java.util.jar.Manifest;
  53 import javax.xml.XMLConstants;
  54 import org.xml.sax.InputSource;
  55 import org.xml.sax.XMLReader;
  56 
  57 /**
  58  * @author Jacek Ambroziak
  59  * @author Santiago Pericas-Geertsen
  60  * @author G. Todd Miller
  61  * @author Morten Jorgensen


 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 FeatureManager _featureManager;
 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      * XSLTC compiler constructor
 169      */
 170     public XSLTC(boolean useServicesMechanism, FeatureManager featureManager) {
 171         _parser = new Parser(this, useServicesMechanism);
 172         _featureManager = featureManager;
 173         _extensionClassLoader = null;
 174         _externalExtensionFunctions = new HashMap<>();
 175     }
 176 
 177     /**
 178      * Set the state of the secure processing feature.
 179      */
 180     public void setSecureProcessing(boolean flag) {
 181         _isSecureProcessing = flag;
 182     }
 183 


 267         return _parser.getOutputProperties();
 268     }
 269 
 270     /**
 271      * Initializes the compiler to compile a new stylesheet
 272      */
 273     public void init() {
 274         reset();
 275         _reader = null;
 276         _classes = new Vector();
 277         _bcelClasses = new Vector();
 278     }
 279 
 280     private void setExternalExtensionFunctions(String name, Class clazz) {
 281         if (_isSecureProcessing && clazz != null && !_externalExtensionFunctions.containsKey(name)) {
 282             _externalExtensionFunctions.put(name, clazz);
 283         }
 284     }
 285 
 286     /*
 287      * Function loads an external extension function.
 288      * The filtering of function types (external,internal) takes place in FunctionCall class
 289      *
 290      */
 291     Class loadExternalFunction(String name) throws ClassNotFoundException {
 292         Class loaded = null;
 293         //Check if the function is not loaded already
 294         if (_externalExtensionFunctions.containsKey(name)) {
 295             loaded = _externalExtensionFunctions.get(name);
 296         } else if (_extensionClassLoader != null) {
 297             loaded = Class.forName(name, true, _extensionClassLoader);
 298             setExternalExtensionFunctions(name, loaded);
 299         }
 300         if (loaded == null) {
 301             throw new ClassNotFoundException(name);
 302         }
 303         //Return loaded class
 304         return (Class) loaded;
 305     }
 306 
 307     /*


 585 
 586     /**
 587      * Set the XMLReader to use for parsing the next input stylesheet
 588      * @param reader XMLReader (SAX2 parser) to use
 589      */
 590     public void setXMLReader(XMLReader reader) {
 591         _reader = reader;
 592     }
 593 
 594     /**
 595      * Get the XMLReader to use for parsing the next input stylesheet
 596      */
 597     public XMLReader getXMLReader() {
 598         return _reader ;
 599     }
 600 
 601     /**
 602      * Get a Vector containing all compile error messages
 603      * @return A Vector containing all compile error messages
 604      */
 605     public ArrayList<ErrorMsg> getErrors() {
 606         return _parser.getErrors();
 607     }
 608 
 609     /**
 610      * Get a Vector containing all compile warning messages
 611      * @return A Vector containing all compile error messages
 612      */
 613     public ArrayList<ErrorMsg> getWarnings() {
 614         return _parser.getWarnings();
 615     }
 616 
 617     /**
 618      * Print all compile error messages to standard output
 619      */
 620     public void printErrors() {
 621         _parser.printErrors();
 622     }
 623 
 624     /**
 625      * Print all compile warning messages to standard output
 626      */
 627     public void printWarnings() {
 628         _parser.printWarnings();
 629     }
 630 
 631     /**
 632      * This method is called by the XPathParser when it encounters a call
 633      * to the document() function. Affects the DOM used by the translet.


< prev index next >