src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java
author jwilhelm
Thu, 12 Sep 2019 03:21:11 +0200
changeset 58094 0f6c749acd15
parent 52902 e3398b2e1ab0
permissions -rw-r--r--
Added tag jdk-14+14 for changeset cddef3bde924
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     1
/*
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     4
 *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    10
 *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    15
 * accompanied this code).
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    16
 *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    20
 *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    23
 * questions.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    24
 */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    25
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    26
package jdk.xml.internal;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    27
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    28
import javax.xml.XMLConstants;
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    29
import static jdk.xml.internal.JdkXmlUtils.OVERRIDE_PARSER;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    30
import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG;
44802
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    31
import static jdk.xml.internal.JdkXmlUtils.RESET_SYMBOL_TABLE;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    32
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    33
/**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    34
 * This class manages JDK's XML Features. Previously added features and properties
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    35
 * may be gradually moved to this class.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    36
 */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    37
public class JdkXmlFeatures {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    38
    public static final String ORACLE_JAXP_PROPERTY_PREFIX =
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    39
        "http://www.oracle.com/xml/jaxp/properties/";
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    40
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    41
    public static final String XML_FEATURE_MANAGER =
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    42
            ORACLE_JAXP_PROPERTY_PREFIX + "XmlFeatureManager";
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    43
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    44
    public static final String ORACLE_FEATURE_SERVICE_MECHANISM =
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    45
            "http://www.oracle.com/feature/use-service-mechanism";
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    46
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    47
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    48
     * Feature enableExtensionFunctions
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    49
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    50
    public static final String ORACLE_ENABLE_EXTENSION_FUNCTION =
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    51
            ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions";
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    52
    public static final String SP_ENABLE_EXTENSION_FUNCTION =
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    53
            "javax.xml.enableExtensionFunctions";
40755
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
    54
    // This is the correct name by the spec
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
    55
    public static final String SP_ENABLE_EXTENSION_FUNCTION_SPEC =
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
    56
            "jdk.xml.enableExtensionFunctions";
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    57
    public static final String CATALOG_FEATURES = "javax.xml.catalog.catalogFeatures";
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    58
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    59
    public final static String PROPERTY_USE_CATALOG = XMLConstants.USE_CATALOG;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    60
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    61
    public static enum XmlFeature {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    62
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    63
         * Feature enableExtensionFunctions
40755
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
    64
         * FSP: extension function is enforced by FSP. When FSP is on, extension
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    65
         * function is disabled.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    66
         */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    67
        ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION_SPEC,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    68
                ORACLE_ENABLE_EXTENSION_FUNCTION, SP_ENABLE_EXTENSION_FUNCTION,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    69
                true, false, true, true),
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    70
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    71
         * The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    72
         * FSP: USE_CATALOG is not enforced by FSP.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    73
         */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    74
        USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    75
                null, null,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    76
                true, false, true, false),
44802
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    77
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    78
        /**
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    79
         * Feature resetSymbolTable
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    80
         * FSP: RESET_SYMBOL_TABLE_FEATURE is not enforced by FSP.
89a545213cad 8176168: Performance drop due to SAXParser SymbolTable reset
aefimov
parents: 40755
diff changeset
    81
         */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    82
        RESET_SYMBOL_TABLE_FEATURE(RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    83
                null, null,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    84
                false, false, true, false),
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    85
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    86
        /**
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    87
         * Feature overrideDefaultParser
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    88
         * FSP: not enforced by FSP.
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    89
         */
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    90
        JDK_OVERRIDE_PARSER(OVERRIDE_PARSER, OVERRIDE_PARSER,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    91
                ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    92
                false, false, true, false);
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    93
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    94
        private final String name;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    95
        private final String nameSP;
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    96
        private final String nameOld;
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
    97
        private final String nameOldSP;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    98
        private final boolean valueDefault;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
    99
        private final boolean valueEnforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   100
        private final boolean hasSystem;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   101
        private final boolean enforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   102
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   103
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   104
         * Constructs an XmlFeature instance.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   105
         * @param name the name of the feature
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   106
         * @param nameSP the name of the System Property
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   107
         * @param nameOld the name of the corresponding legacy property
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   108
         * @param nameOldSP the system property of the legacy property
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   109
         * @param value the value of the feature
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   110
         * @param hasSystem a flag to indicate whether the feature is supported
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   111
         * @param enforced a flag indicating whether the feature is
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   112
         * FSP (Feature_Secure_Processing) enforced
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   113
         * with a System property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   114
         */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   115
        XmlFeature(String name, String nameSP, String nameOld, String nameOldSP,
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   116
                boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   117
            this.name = name;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   118
            this.nameSP = nameSP;
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   119
            this.nameOld = nameOld;
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   120
            this.nameOldSP = nameOldSP;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   121
            this.valueDefault = value;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   122
            this.valueEnforced = valueEnforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   123
            this.hasSystem = hasSystem;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   124
            this.enforced = enforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   125
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   126
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   127
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   128
         * Checks whether the specified property is equal to the current property.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   129
         * @param propertyName the name of a property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   130
         * @return true if the specified property is the current property, false
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   131
         * otherwise
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   132
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   133
        boolean equalsPropertyName(String propertyName) {
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   134
            return name.equals(propertyName) ||
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   135
                    (nameOld != null && nameOld.equals(propertyName));
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   136
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   137
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   138
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   139
         * Returns the name of the property.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   140
         *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   141
         * @return the name of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   142
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   143
        public String apiProperty() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   144
            return name;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   145
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   146
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   147
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   148
         * Returns the name of the corresponding System Property.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   149
         *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   150
         * @return the name of the System Property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   151
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   152
        String systemProperty() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   153
            return nameSP;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   154
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   155
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   156
        /**
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   157
         * Returns the name of the legacy System Property.
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   158
         *
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   159
         * @return the name of the legacy System Property
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   160
         */
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   161
        String systemPropertyOld() {
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   162
            return nameOldSP;
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   163
        }
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   164
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   165
        /**
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   166
         * Returns the default value of the property.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   167
         * @return the default value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   168
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   169
        public boolean defaultValue() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   170
            return valueDefault;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   171
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   172
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   173
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   174
         * Returns the FSP-enforced value.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   175
         * @return the FSP-enforced value
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   176
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   177
        public boolean enforcedValue() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   178
            return valueEnforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   179
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   180
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   181
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   182
         * Checks whether System property is supported for the feature.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   183
         * @return true it is supported, false otherwise
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   184
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   185
        boolean hasSystemProperty() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   186
            return hasSystem;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   187
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   188
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   189
        /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   190
         * Checks whether the property is enforced by FSP
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   191
         * @return true it is, false otherwise
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   192
         */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   193
        boolean enforced() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   194
            return enforced;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   195
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   196
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   197
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   198
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   199
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   200
     * States of the settings of a property, in the order: default value, value
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   201
     * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   202
     * properties, and jaxp api properties
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   203
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   204
    public static enum State {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   205
        //this order reflects the overriding order
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   206
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   207
        DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"),
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   208
        JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"),
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   209
        APIPROPERTY("property");
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   210
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   211
        final String literal;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   212
        State(String literal) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   213
            this.literal = literal;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   214
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   215
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   216
        String literal() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   217
            return literal;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   218
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   219
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   220
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   221
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   222
     * Values of the features
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   223
     */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   224
    private final boolean[] featureValues;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   225
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   226
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   227
     * States of the settings for each property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   228
     */
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   229
    private final State[] states;
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   230
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   231
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   232
     * Flag indicating if secure processing is set
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   233
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   234
    boolean secureProcessing;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   235
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   236
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   237
     * Instantiate JdkXmlFeatures and initialize the fields
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   238
     * @param secureProcessing
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   239
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   240
    public JdkXmlFeatures(boolean secureProcessing) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   241
        featureValues = new boolean[XmlFeature.values().length];
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   242
        states = new State[XmlFeature.values().length];
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   243
        this.secureProcessing = secureProcessing;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   244
        for (XmlFeature f : XmlFeature.values()) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   245
            if (secureProcessing && f.enforced()) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   246
                featureValues[f.ordinal()] = f.enforcedValue();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   247
                states[f.ordinal()] = State.FSP;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   248
            } else {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   249
                featureValues[f.ordinal()] = f.defaultValue();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   250
                states[f.ordinal()] = State.DEFAULT;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   251
            }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   252
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   253
        //read system properties or jaxp.properties
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   254
        readSystemProperties();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   255
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   256
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   257
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   258
     * Updates the JdkXmlFeatures instance by reading the system properties again.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   259
     * This will become necessary in case the system properties are set after
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   260
     * the instance has been created.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   261
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   262
    public void update() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   263
        readSystemProperties();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   264
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   265
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   266
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   267
     * Set feature by property name and state
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   268
     * @param propertyName property name
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   269
     * @param state the state of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   270
     * @param value the value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   271
     * @return true if the property is managed by the JdkXmlFeatures instance;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   272
     *         false otherwise.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   273
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   274
    public boolean setFeature(String propertyName, State state, Object value) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   275
        int index = getIndex(propertyName);
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   276
        if (index > -1) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   277
            setFeature(index, state, value);
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   278
            return true;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   279
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   280
        return false;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   281
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   282
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   283
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   284
     * Set the value for a specific feature.
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   285
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   286
     * @param feature the feature
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   287
     * @param state the state of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   288
     * @param value the value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   289
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   290
    public void setFeature(XmlFeature feature, State state, boolean value) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   291
        setFeature(feature.ordinal(), state, value);
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   292
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   293
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   294
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   295
     * Return the value of the specified property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   296
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   297
     * @param feature the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   298
     * @return the value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   299
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   300
    public boolean getFeature(XmlFeature feature) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   301
        return featureValues[feature.ordinal()];
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   302
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   303
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   304
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   305
     * Return the value of a feature by its index (the Feature's ordinal)
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   306
     * @param index the index of a feature
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   307
     * @return value of a feature
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   308
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   309
    public boolean getFeature(int index) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   310
        return featureValues[index];
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   311
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   312
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   313
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   314
     * Set the value of a property by its index
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   315
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   316
     * @param index the index of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   317
     * @param state the state of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   318
     * @param value the value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   319
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   320
    public void setFeature(int index, State state, Object value) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   321
        boolean temp;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   322
        if (Boolean.class.isAssignableFrom(value.getClass())) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   323
            temp = (Boolean)value;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   324
        } else {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   325
            temp = Boolean.parseBoolean((String) value);
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   326
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   327
        setFeature(index, state, temp);
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   328
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   329
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   330
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   331
     * Set the value of a property by its index
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   332
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   333
     * @param index the index of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   334
     * @param state the state of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   335
     * @param value the value of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   336
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   337
    public void setFeature(int index, State state, boolean value) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   338
        //only update if it shall override
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   339
        if (state.compareTo(states[index]) >= 0) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   340
            featureValues[index] = value;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   341
            states[index] = state;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   342
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   343
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   344
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   345
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   346
     * Get the index by property name
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   347
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   348
     * @param propertyName property name
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   349
     * @return the index of the property if found; return -1 if not
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   350
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   351
    public int getIndex(String propertyName) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   352
        for (XmlFeature feature : XmlFeature.values()) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   353
            if (feature.equalsPropertyName(propertyName)) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   354
                //internally, ordinal is used as index
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   355
                return feature.ordinal();
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   356
            }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   357
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   358
        return -1;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   359
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   360
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   361
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   362
     * Read from system properties, or those in jaxp.properties
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   363
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   364
    private void readSystemProperties() {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   365
        for (XmlFeature feature : XmlFeature.values()) {
40755
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
   366
            if (!getSystemProperty(feature, feature.systemProperty())) {
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
   367
                //if system property is not found, try the older form if any
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   368
                String oldName = feature.systemPropertyOld();
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   369
                if (oldName != null) {
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   370
                    getSystemProperty(feature, oldName);
40755
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
   371
                }
26f6264ee481 8161454: Fails to Load external Java method from inside of a XSL stylesheet if SecurityManager is present
joehw
parents: 39907
diff changeset
   372
            }
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   373
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   374
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   375
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   376
    /**
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   377
     * Read from system properties, or those in jaxp.properties
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   378
     *
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   379
     * @param property the type of the property
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   380
     * @param sysPropertyName the name of system property
48577
8dff65f1d611 8186080: Transform XML interfaces
joehw
parents: 47216
diff changeset
   381
     * @return true if the system property is found, false otherwise
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   382
     */
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   383
    private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   384
        try {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   385
            String value = SecuritySupport.getSystemProperty(sysPropertyName);
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 48577
diff changeset
   386
            if (value != null && !value.isEmpty()) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   387
                setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   388
                return true;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   389
            }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   390
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   391
            value = SecuritySupport.readJAXPProperty(sysPropertyName);
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 48577
diff changeset
   392
            if (value != null && !value.isEmpty()) {
39907
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   393
                setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value));
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   394
                return true;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   395
            }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   396
        } catch (NumberFormatException e) {
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   397
            //invalid setting
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   398
            throw new NumberFormatException("Invalid setting for system property: " + feature.systemProperty());
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   399
        }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   400
        return false;
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   401
    }
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   402
db51759e3695 8158084: Catalog API: JAXP XML Processor Support
joehw
parents:
diff changeset
   403
}