1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.org.apache.xalan.internal;
  27 
  28 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
  29 
  30 /**
  31  * Commonly used constants.
  32  *
  33  * @author Huizhe Wang, Oracle
  34  *
  35  * @version $Id: Constants.java,v 1.14 2011-06-07 04:39:40 joehw Exp $
  36  */
  37 public final class XalanConstants {
  38 
  39     //
  40     // Constants
  41     //
  42     //Xerces security manager
  43     public static final String SECURITY_MANAGER =
  44             "http://apache.org/xml/properties/security-manager";
  45 
  46     //
  47     // Implementation limits: API properties
  48     //
  49     /** Oracle JAXP property prefix ("http://www.oracle.com/xml/jaxp/properties/"). */
  50     public static final String ORACLE_JAXP_PROPERTY_PREFIX =
  51         "http://www.oracle.com/xml/jaxp/properties/";
  52     /**
  53      * JDK entity expansion limit; Note that the existing system property
  54      * "entityExpansionLimit" with no prefix is still observed
  55      */
  56     public static final String JDK_ENTITY_EXPANSION_LIMIT =
  57             ORACLE_JAXP_PROPERTY_PREFIX + "entityExpansionLimit";
  58 
  59     /**
  60      * JDK element attribute limit; Note that the existing system property
  61      * "elementAttributeLimit" with no prefix is still observed
  62      */
  63     public static final String JDK_ELEMENT_ATTRIBUTE_LIMIT =
  64             ORACLE_JAXP_PROPERTY_PREFIX + "elementAttributeLimit";
  65 
  66     /**
  67      * JDK maxOccur limit; Note that the existing system property
  68      * "maxOccurLimit" with no prefix is still observed
  69      */
  70     public static final String JDK_MAX_OCCUR_LIMIT =
  71             ORACLE_JAXP_PROPERTY_PREFIX + "maxOccurLimit";
  72 
  73     /**
  74      * JDK total entity size limit
  75      */
  76     public static final String JDK_TOTAL_ENTITY_SIZE_LIMIT =
  77             ORACLE_JAXP_PROPERTY_PREFIX + "totalEntitySizeLimit";
  78 
  79     /**
  80      * JDK maximum general entity size limit
  81      */
  82     public static final String JDK_GENERAL_ENTITY_SIZE_LIMIT =
  83             ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
  84 
  85     /**
  86      * JDK node count limit in entities that limits the total number of nodes
  87      * in all of entity references.
  88      */
  89     public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
  90             ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
  91 
  92     /**
  93      * JDK maximum parameter entity size limit
  94      */
  95     public static final String JDK_PARAMETER_ENTITY_SIZE_LIMIT =
  96             ORACLE_JAXP_PROPERTY_PREFIX + "maxParameterEntitySizeLimit";
  97     /**
  98      * JDK maximum XML name limit
  99      */
 100     public static final String JDK_XML_NAME_LIMIT =
 101             ORACLE_JAXP_PROPERTY_PREFIX + "maxXMLNameLimit";
 102 
 103     /**
 104      * JDK maxElementDepth limit
 105      */
 106     public static final String JDK_MAX_ELEMENT_DEPTH =
 107             ORACLE_JAXP_PROPERTY_PREFIX + "maxElementDepth";
 108 
 109     /**
 110      * JDK property indicating whether the parser shall print out entity
 111      * count information
 112      * Value: a string "yes" means print, "no" or any other string means not.
 113      */
 114     public static final String JDK_ENTITY_COUNT_INFO =
 115             ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
 116 
 117     //
 118     // Implementation limits: corresponding System Properties of the above
 119     // API properties
 120     //
 121     /**
 122      * JDK entity expansion limit; Note that the existing system property
 123      * "entityExpansionLimit" with no prefix is still observed
 124      */
 125     public static final String SP_ENTITY_EXPANSION_LIMIT = "jdk.xml.entityExpansionLimit";
 126 
 127     /**
 128      * JDK element attribute limit; Note that the existing system property
 129      * "elementAttributeLimit" with no prefix is still observed
 130      */
 131     public static final String SP_ELEMENT_ATTRIBUTE_LIMIT =  "jdk.xml.elementAttributeLimit";
 132 
 133     /**
 134      * JDK maxOccur limit; Note that the existing system property
 135      * "maxOccurLimit" with no prefix is still observed
 136      */
 137     public static final String SP_MAX_OCCUR_LIMIT = "jdk.xml.maxOccurLimit";
 138 
 139     /**
 140      * JDK total entity size limit
 141      */
 142     public static final String SP_TOTAL_ENTITY_SIZE_LIMIT = "jdk.xml.totalEntitySizeLimit";
 143 
 144     /**
 145      * JDK maximum general entity size limit
 146      */
 147     public static final String SP_GENERAL_ENTITY_SIZE_LIMIT = "jdk.xml.maxGeneralEntitySizeLimit";
 148 
 149     /**
 150      * JDK node count limit in entities that limits the total number of nodes
 151      * in all of entity references.
 152      */
 153     public static final String SP_ENTITY_REPLACEMENT_LIMIT = "jdk.xml.entityReplacementLimit";
 154 
 155     /**
 156      * JDK maximum parameter entity size limit
 157      */
 158     public static final String SP_PARAMETER_ENTITY_SIZE_LIMIT = "jdk.xml.maxParameterEntitySizeLimit";
 159     /**
 160      * JDK maximum XML name limit
 161      */
 162     public static final String SP_XML_NAME_LIMIT = "jdk.xml.maxXMLNameLimit";
 163 
 164     /**
 165      * JDK maxElementDepth limit
 166      */
 167     public static final String SP_MAX_ELEMENT_DEPTH = "jdk.xml.maxElementDepth";
 168 
 169     /**
 170      * JDK TransformerFactory and Transformer attribute that specifies a class
 171      * loader that will be used for extension functions class loading
 172      * Value: a "null", the default value, means that the default EF class loading
 173      * path will be used.
 174      * Instance of ClassLoader: the specified instance of ClassLoader will be used
 175      * for extension functions loading during translation process
 176      */
 177     public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
 178 
 179     //legacy System Properties
 180     public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
 181     public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;
 182     public final static String MAX_OCCUR_LIMIT = "maxOccurLimit";
 183 
 184     /**
 185      * A string "yes" that can be used for properties such as getEntityCountInfo
 186      */
 187     public static final String JDK_YES = "yes";
 188 
 189     // Oracle Feature:
 190     /**
 191      * <p>Use Service Mechanism</p>
 192      *
 193      * <ul>
 194      *   <li>
 195          * {@code true} instruct an object to use service mechanism to
 196          * find a service implementation. This is the default behavior.
 197          *   </li>
 198          *   <li>
 199          * {@code false} instruct an object to skip service mechanism and
 200          * use the default implementation for that service.
 201          *   </li>
 202          * </ul>
 203          */
 204     public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
 205 
 206 
 207     //System Properties corresponding to ACCESS_EXTERNAL_* properties
 208     public static final String SP_ACCESS_EXTERNAL_STYLESHEET = "javax.xml.accessExternalStylesheet";
 209     public static final String SP_ACCESS_EXTERNAL_DTD = "javax.xml.accessExternalDTD";
 210 
 211     //all access keyword
 212     public static final String ACCESS_EXTERNAL_ALL = "all";
 213 
 214     /**
 215      * Default value when FEATURE_SECURE_PROCESSING (FSP) is set to true
 216      */
 217     public static final String EXTERNAL_ACCESS_DEFAULT_FSP = "";
 218 
 219     /**
 220      * FEATURE_SECURE_PROCESSING (FSP) is false by default
 221      */
 222     public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
 223 
 224     public static final String XML_SECURITY_PROPERTY_MANAGER =
 225             ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager";
 226 
 227     /**
 228      * Feature enableExtensionFunctions
 229      */
 230     public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
 231             ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
 232     public static final String SP_ORACLE_ENABLE_EXTENSION_FUNCTION = "javax.xml.enableExtensionFunctions";
 233 
 234     /**
 235      * Values for a feature
 236      */
 237     public static final String FEATURE_TRUE = "true";
 238     public static final String FEATURE_FALSE = "false";
 239 
 240     /**
 241      * Check if we're in jdk8 or above
 242      */
 243     public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
 244 
 245     /*
 246      * Check the version of the current JDK against that specified in the
 247      * parameter
 248      *
 249      * There is a proposal to change the java version string to:
 250      * MAJOR.MINOR.FU.CPU.PSU-BUILDNUMBER_BUGIDNUMBER_OPTIONAL
 251      * This method would work with both the current format and that proposed
 252      *
 253      * @param compareTo a JDK version to be compared to
 254      * @return true if the current version is the same or above that represented
 255      * by the parameter
 256      */
 257     public static boolean isJavaVersionAtLeast(int compareTo) {
 258         String javaVersion = SecuritySupport.getSystemProperty("java.version");
 259         String versions[] = javaVersion.split("\\.", 3);
 260         if (Integer.parseInt(versions[0]) >= compareTo ||
 261             Integer.parseInt(versions[1]) >= compareTo) {
 262             return true;
 263         }
 264         return false;
 265     }
 266 } // class Constants