< prev index next >

src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java

Print this page




  25 
  26 package jdk.xml.internal;
  27 
  28 import javax.xml.XMLConstants;
  29 import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG;
  30 
  31 /**
  32  * This class manages JDK's XML Features. Previously added features and properties
  33  * may be gradually moved to this class.
  34  */
  35 public class JdkXmlFeatures {
  36     public static final String ORACLE_JAXP_PROPERTY_PREFIX =
  37         "http://www.oracle.com/xml/jaxp/properties/";
  38     /**
  39      * Feature enableExtensionFunctions
  40      */
  41     public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
  42             ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
  43     public static final String SP_ENABLE_EXTENSION_FUNCTION =
  44             "javax.xml.enableExtensionFunctions";



  45     public static final String CATALOG_FEATURES = "javax.xml.catalog.catalogFeatures";
  46 
  47     public final static String PROPERTY_USE_CATALOG = XMLConstants.USE_CATALOG;
  48 
  49     public static enum XmlFeature {
  50         /**
  51          * Feature enableExtensionFunctions
  52          * FSP: extension function is enforced by FSP. When FSP is on, entension
  53          * function is disabled.
  54          */
  55         ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION,
  56                 SP_ENABLE_EXTENSION_FUNCTION, true, false, true, true),
  57         /**
  58          * The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
  59          * FSP: USE_CATALOG is not enforced by FSP.
  60          */
  61         USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG, true, false, true, false);
  62 
  63         private final String name;
  64         private final String nameSP;
  65         private final boolean valueDefault;
  66         private final boolean valueEnforced;
  67         private final boolean hasSystem;
  68         private final boolean enforced;
  69 
  70         /**
  71          * Constructs an XmlFeature instance.
  72          * @param name the name of the feature
  73          * @param nameSP the name of the System Property
  74          * @param value the value of the feature
  75          * @param hasSystem a flag to indicate whether the feature is supported
  76          * @param enforced a flag indicating whether the feature is


 132 
 133         /**
 134          * Checks whether System property is supported for the feature.
 135          * @return true it is supported, false otherwise
 136          */
 137         boolean hasSystemProperty() {
 138             return hasSystem;
 139         }
 140 
 141         /**
 142          * Checks whether the property is enforced by FSP
 143          * @return true it is, false otherwise
 144          */
 145         boolean enforced() {
 146             return enforced;
 147         }
 148 
 149     }
 150 
 151     /**
























 152      * States of the settings of a property, in the order: default value, value
 153      * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
 154      * properties, and jaxp api properties
 155      */
 156     public static enum State {
 157         //this order reflects the overriding order
 158 
 159         DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
 160         JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
 161         APIPROPERTY("property");
 162 
 163         final String literal;
 164         State(String literal) {
 165             this.literal = literal;
 166         }
 167 
 168         String literal() {
 169             return literal;
 170         }
 171     }


 299      *
 300      * @param propertyName property name
 301      * @return the index of the property if found; return -1 if not
 302      */
 303     public int getIndex(String propertyName) {
 304         for (XmlFeature feature : XmlFeature.values()) {
 305             if (feature.equalsPropertyName(propertyName)) {
 306                 //internally, ordinal is used as index
 307                 return feature.ordinal();
 308             }
 309         }
 310         return -1;
 311     }
 312 
 313     /**
 314      * Read from system properties, or those in jaxp.properties
 315      */
 316     private void readSystemProperties() {
 317         for (XmlFeature feature : XmlFeature.values()) {
 318             getSystemProperty(feature, feature.systemProperty());









 319         }
 320     }
 321 
 322     /**
 323      * Read from system properties, or those in jaxp.properties
 324      *
 325      * @param property the type of the property
 326      * @param sysPropertyName the name of system property
 327      */
 328     private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
 329         try {
 330             String value = SecuritySupport.getSystemProperty(sysPropertyName);
 331             if (value != null && !value.equals("")) {
 332                 setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
 333                 return true;
 334             }
 335 
 336             value = SecuritySupport.readJAXPProperty(sysPropertyName);
 337             if (value != null && !value.equals("")) {
 338                 setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value));


  25 
  26 package jdk.xml.internal;
  27 
  28 import javax.xml.XMLConstants;
  29 import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG;
  30 
  31 /**
  32  * This class manages JDK's XML Features. Previously added features and properties
  33  * may be gradually moved to this class.
  34  */
  35 public class JdkXmlFeatures {
  36     public static final String ORACLE_JAXP_PROPERTY_PREFIX =
  37         "http://www.oracle.com/xml/jaxp/properties/";
  38     /**
  39      * Feature enableExtensionFunctions
  40      */
  41     public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
  42             ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
  43     public static final String SP_ENABLE_EXTENSION_FUNCTION =
  44             "javax.xml.enableExtensionFunctions";
  45     // This is the correct name by the spec
  46     public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
  47             "jdk.xml.enableExtensionFunctions";
  48     public static final String CATALOG_FEATURES = "javax.xml.catalog.catalogFeatures";
  49 
  50     public final static String PROPERTY_USE_CATALOG = XMLConstants.USE_CATALOG;
  51 
  52     public static enum XmlFeature {
  53         /**
  54          * Feature enableExtensionFunctions
  55          * FSP: extension function is enforced by FSP. When FSP is on, extension
  56          * function is disabled.
  57          */
  58         ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION,
  59                 SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, false, true, true),
  60         /**
  61          * The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
  62          * FSP: USE_CATALOG is not enforced by FSP.
  63          */
  64         USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG, true, false, true, false);
  65 
  66         private final String name;
  67         private final String nameSP;
  68         private final boolean valueDefault;
  69         private final boolean valueEnforced;
  70         private final boolean hasSystem;
  71         private final boolean enforced;
  72 
  73         /**
  74          * Constructs an XmlFeature instance.
  75          * @param name the name of the feature
  76          * @param nameSP the name of the System Property
  77          * @param value the value of the feature
  78          * @param hasSystem a flag to indicate whether the feature is supported
  79          * @param enforced a flag indicating whether the feature is


 135 
 136         /**
 137          * Checks whether System property is supported for the feature.
 138          * @return true it is supported, false otherwise
 139          */
 140         boolean hasSystemProperty() {
 141             return hasSystem;
 142         }
 143 
 144         /**
 145          * Checks whether the property is enforced by FSP
 146          * @return true it is, false otherwise
 147          */
 148         boolean enforced() {
 149             return enforced;
 150         }
 151 
 152     }
 153 
 154     /**
 155      * Maps old property names with the new ones. This map is used to keep track of
 156      * name changes so that old or incorrect names continue to be supported for compatibility.
 157      */
 158     public static enum NameMap {
 159 
 160         ENABLE_EXTENSION_FUNCTION(SP_ENABLE_EXTENSION_FUNCTION_SPEC, SP_ENABLE_EXTENSION_FUNCTION);
 161 
 162         final String newName;
 163         final String oldName;
 164 
 165         NameMap(String newName, String oldName) {
 166             this.newName = newName;
 167             this.oldName = oldName;
 168         }
 169 
 170         String getOldName(String newName) {
 171             if (newName.equals(this.newName)) {
 172                 return oldName;
 173             }
 174             return null;
 175         }
 176     }
 177 
 178     /**
 179      * States of the settings of a property, in the order: default value, value
 180      * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
 181      * properties, and jaxp api properties
 182      */
 183     public static enum State {
 184         //this order reflects the overriding order
 185 
 186         DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
 187         JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
 188         APIPROPERTY("property");
 189 
 190         final String literal;
 191         State(String literal) {
 192             this.literal = literal;
 193         }
 194 
 195         String literal() {
 196             return literal;
 197         }
 198     }


 326      *
 327      * @param propertyName property name
 328      * @return the index of the property if found; return -1 if not
 329      */
 330     public int getIndex(String propertyName) {
 331         for (XmlFeature feature : XmlFeature.values()) {
 332             if (feature.equalsPropertyName(propertyName)) {
 333                 //internally, ordinal is used as index
 334                 return feature.ordinal();
 335             }
 336         }
 337         return -1;
 338     }
 339 
 340     /**
 341      * Read from system properties, or those in jaxp.properties
 342      */
 343     private void readSystemProperties() {
 344         for (XmlFeature feature : XmlFeature.values()) {
 345             getSystemProperty(feature, feature.systemProperty());
 346             if (!getSystemProperty(feature, feature.systemProperty())) {
 347                 //if system property is not found, try the older form if any
 348                 for (NameMap nameMap : NameMap.values()) {
 349                     String oldName = nameMap.getOldName(feature.systemProperty());
 350                     if (oldName != null) {
 351                         getSystemProperty(feature, oldName);
 352                     }
 353                 }
 354             }
 355         }
 356     }
 357 
 358     /**
 359      * Read from system properties, or those in jaxp.properties
 360      *
 361      * @param property the type of the property
 362      * @param sysPropertyName the name of system property
 363      */
 364     private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
 365         try {
 366             String value = SecuritySupport.getSystemProperty(sysPropertyName);
 367             if (value != null && !value.equals("")) {
 368                 setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
 369                 return true;
 370             }
 371 
 372             value = SecuritySupport.readJAXPProperty(sysPropertyName);
 373             if (value != null && !value.equals("")) {
 374                 setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value));
< prev index next >