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  */
  36 public final class XalanConstants {
  37 
  38     //
  39     // Constants
  40     //
  41     //Xerces security manager
  42     public static final String SECURITY_MANAGER =
  43             "http://apache.org/xml/properties/security-manager";
  44 
  45     //
  46     // Implementation limits: API properties
  47     //
  48     /** Oracle JAXP property prefix ("http://www.oracle.com/xml/jaxp/properties/"). */
  49     public static final String ORACLE_JAXP_PROPERTY_PREFIX =
  50         "http://www.oracle.com/xml/jaxp/properties/";
  51     /**
  52      * JDK entity expansion limit; Note that the existing system property
  53      * "entityExpansionLimit" with no prefix is still observed
  54      */
  55     public static final String JDK_ENTITY_EXPANSION_LIMIT =
  56             ORACLE_JAXP_PROPERTY_PREFIX + "entityExpansionLimit";
  57 
  58     /**
  59      * JDK element attribute limit; Note that the existing system property
  60      * "elementAttributeLimit" with no prefix is still observed
  61      */
  62     public static final String JDK_ELEMENT_ATTRIBUTE_LIMIT =
  63             ORACLE_JAXP_PROPERTY_PREFIX + "elementAttributeLimit";
  64 
  65     /**
  66      * JDK maxOccur limit; Note that the existing system property
  67      * "maxOccurLimit" with no prefix is still observed
  68      */
  69     public static final String JDK_MAX_OCCUR_LIMIT =
  70             ORACLE_JAXP_PROPERTY_PREFIX + "maxOccurLimit";
  71 
  72     /**
  73      * JDK total entity size limit
  74      */
  75     public static final String JDK_TOTAL_ENTITY_SIZE_LIMIT =
  76             ORACLE_JAXP_PROPERTY_PREFIX + "totalEntitySizeLimit";
  77 
  78     /**
  79      * JDK maximum general entity size limit
  80      */
  81     public static final String JDK_GENERAL_ENTITY_SIZE_LIMIT =
  82             ORACLE_JAXP_PROPERTY_PREFIX + "maxGeneralEntitySizeLimit";
  83 
  84     /**
  85      * JDK node count limit in entities that limits the total number of nodes
  86      * in all of entity references.
  87      */
  88     public static final String JDK_ENTITY_REPLACEMENT_LIMIT =
  89             ORACLE_JAXP_PROPERTY_PREFIX + "entityReplacementLimit";
  90 
  91     /**
  92      * JDK maximum parameter entity size limit
  93      */
  94     public static final String JDK_PARAMETER_ENTITY_SIZE_LIMIT =
  95             ORACLE_JAXP_PROPERTY_PREFIX + "maxParameterEntitySizeLimit";
  96     /**
  97      * JDK maximum XML name limit
  98      */
  99     public static final String JDK_XML_NAME_LIMIT =
 100             ORACLE_JAXP_PROPERTY_PREFIX + "maxXMLNameLimit";
 101 
 102     /**
 103      * JDK maxElementDepth limit
 104      */
 105     public static final String JDK_MAX_ELEMENT_DEPTH =
 106             ORACLE_JAXP_PROPERTY_PREFIX + "maxElementDepth";
 107 
 108     /**
 109      * JDK property indicating whether the parser shall print out entity
 110      * count information
 111      * Value: a string "yes" means print, "no" or any other string means not.
 112      */
 113     public static final String JDK_ENTITY_COUNT_INFO =
 114             ORACLE_JAXP_PROPERTY_PREFIX + "getEntityCountInfo";
 115 
 116     //
 117     // Implementation limits: corresponding System Properties of the above
 118     // API properties
 119     //
 120     /**
 121      * JDK entity expansion limit; Note that the existing system property
 122      * "entityExpansionLimit" with no prefix is still observed
 123      */
 124     public static final String SP_ENTITY_EXPANSION_LIMIT = "jdk.xml.entityExpansionLimit";
 125 
 126     /**
 127      * JDK element attribute limit; Note that the existing system property
 128      * "elementAttributeLimit" with no prefix is still observed
 129      */
 130     public static final String SP_ELEMENT_ATTRIBUTE_LIMIT =  "jdk.xml.elementAttributeLimit";
 131 
 132     /**
 133      * JDK maxOccur limit; Note that the existing system property
 134      * "maxOccurLimit" with no prefix is still observed
 135      */
 136     public static final String SP_MAX_OCCUR_LIMIT = "jdk.xml.maxOccurLimit";
 137 
 138     /**
 139      * JDK total entity size limit
 140      */
 141     public static final String SP_TOTAL_ENTITY_SIZE_LIMIT = "jdk.xml.totalEntitySizeLimit";
 142 
 143     /**
 144      * JDK maximum general entity size limit
 145      */
 146     public static final String SP_GENERAL_ENTITY_SIZE_LIMIT = "jdk.xml.maxGeneralEntitySizeLimit";
 147 
 148     /**
 149      * JDK node count limit in entities that limits the total number of nodes
 150      * in all of entity references.
 151      */
 152     public static final String SP_ENTITY_REPLACEMENT_LIMIT = "jdk.xml.entityReplacementLimit";
 153 
 154     /**
 155      * JDK maximum parameter entity size limit
 156      */
 157     public static final String SP_PARAMETER_ENTITY_SIZE_LIMIT = "jdk.xml.maxParameterEntitySizeLimit";
 158     /**
 159      * JDK maximum XML name limit
 160      */
 161     public static final String SP_XML_NAME_LIMIT = "jdk.xml.maxXMLNameLimit";
 162 
 163     /**
 164      * JDK maxElementDepth limit
 165      */
 166     public static final String SP_MAX_ELEMENT_DEPTH = "jdk.xml.maxElementDepth";
 167 
 168     /**
 169      * JDK TransformerFactory and Transformer attribute that specifies a class
 170      * loader that will be used for extension functions class loading
 171      * Value: a "null", the default value, means that the default EF class loading
 172      * path will be used.
 173      * Instance of ClassLoader: the specified instance of ClassLoader will be used
 174      * for extension functions loading during translation process
 175      */
 176     public static final String JDK_EXTENSION_CLASSLOADER = "jdk.xml.transform.extensionClassLoader";
 177 
 178     //legacy System Properties
 179     public final static String ENTITY_EXPANSION_LIMIT = "entityExpansionLimit";
 180     public static final String ELEMENT_ATTRIBUTE_LIMIT = "elementAttributeLimit" ;
 181     public final static String MAX_OCCUR_LIMIT = "maxOccurLimit";
 182 
 183     /**
 184      * A string "yes" that can be used for properties such as getEntityCountInfo
 185      */
 186     public static final String JDK_YES = "yes";
 187 
 188     // Oracle Feature:
 189     /**
 190      * <p>Use Service Mechanism</p>
 191      *
 192      * <ul>
 193      *   <li>
 194          * {@code true} instruct an object to use service mechanism to
 195          * find a service implementation. This is the default behavior.
 196          *   </li>
 197          *   <li>
 198          * {@code false} instruct an object to skip service mechanism and
 199          * use the default implementation for that service.
 200          *   </li>
 201          * </ul>
 202          */
 203     public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
 204 
 205 
 206     //System Properties corresponding to ACCESS_EXTERNAL_* properties
 207     public static final String SP_ACCESS_EXTERNAL_STYLESHEET = "javax.xml.accessExternalStylesheet";
 208     public static final String SP_ACCESS_EXTERNAL_DTD = "javax.xml.accessExternalDTD";
 209 
 210     //all access keyword
 211     public static final String ACCESS_EXTERNAL_ALL = "all";
 212 
 213     /**
 214      * Default value when FEATURE_SECURE_PROCESSING (FSP) is set to true
 215      */
 216     public static final String EXTERNAL_ACCESS_DEFAULT_FSP = "";
 217 
 218     /**
 219      * FEATURE_SECURE_PROCESSING (FSP) is false by default
 220      */
 221     public static final String EXTERNAL_ACCESS_DEFAULT = ACCESS_EXTERNAL_ALL;
 222 
 223     public static final String XML_SECURITY_PROPERTY_MANAGER =
 224             ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager";
 225 
 226     /**
 227      * Feature enableExtensionFunctions
 228      */
 229     public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
 230             ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
 231     public static final String SP_ORACLE_ENABLE_EXTENSION_FUNCTION = "javax.xml.enableExtensionFunctions";
 232 
 233     /**
 234      * Values for a feature
 235      */
 236     public static final String FEATURE_TRUE = "true";
 237     public static final String FEATURE_FALSE = "false";
 238 
 239     /**
 240      * Check if we're in jdk8 or above
 241      */
 242     public static final boolean IS_JDK8_OR_ABOVE = isJavaVersionAtLeast(8);
 243 
 244     /*
 245      * Check the version of the current JDK against that specified in the
 246      * parameter
 247      *
 248      * There is a proposal to change the java version string to:
 249      * MAJOR.MINOR.FU.CPU.PSU-BUILDNUMBER_BUGIDNUMBER_OPTIONAL
 250      * This method would work with both the current format and that proposed
 251      *
 252      * @param compareTo a JDK version to be compared to
 253      * @return true if the current version is the same or above that represented
 254      * by the parameter
 255      */
 256     public static boolean isJavaVersionAtLeast(int compareTo) {
 257         String javaVersion = SecuritySupport.getSystemProperty("java.version");
 258         String versions[] = javaVersion.split("\\.", 3);
 259         if (Integer.parseInt(versions[0]) >= compareTo ||
 260             Integer.parseInt(versions[1]) >= compareTo) {
 261             return true;
 262         }
 263         return false;
 264     }
 265 } // class Constants