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