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