jaxp/src/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12458 d601e4bba306
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: OutputPropertiesFactory.java,v 1.2.4.1 2005/09/15 08:15:21 suresh_emailid Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.serializer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
    25
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.io.BufferedInputStream;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.security.AccessController;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import java.security.PrivilegedAction;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import java.util.Enumeration;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import java.util.Properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import javax.xml.transform.OutputKeys;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.serializer.utils.Utils;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * This class is a factory to generate a set of default properties
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * of key/value pairs that are used to create a serializer through the
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * factory {@link SerializerFactory SerilizerFactory}.
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * The properties generated by this factory
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * may be modified to non-default values before the SerializerFactory is used to
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * create a Serializer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * The given output types supported are "xml", "text", and "html".
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * These type strings can be obtained from the
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * {@link Method Method} class in this package.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * Other constants defined in this class are the non-standard property keys
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * that can be used to set non-standard property values on a java.util.Properties object
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * that is used to create or configure a serializer. Here are the non-standard keys:
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * <ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * <li> <b>S_KEY_INDENT_AMOUNT </b> -
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * The non-standard property key to use to set the indentation amount.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * The "indent" key needs to have a value of "yes", and this
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * properties value is a the number of whitespaces to indent by per
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * indentation level.
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * <li> <b>S_KEY_CONTENT_HANDLER </b> -
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * This non-standard property key is used to set the name of the fully qualified
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * Java class that implements the ContentHandler interface.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * The output of the serializer will be SAX events sent to this an
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * object of this class.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * <li> <b>S_KEY_ENTITIES </b> -
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * This non-standard property key is used to specify the name of the property file
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * that specifies character to entity reference mappings. A line in such a
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * file is has the name of the entity and the numeric (base 10) value
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * of the corresponding character, like this one: <br> quot=34 <br>
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * <li> <b>S_USE_URL_ESCAPING </b> -
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 * This non-standard property key is used to set a value of "yes" if the href values for HTML serialization should
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
 *  use %xx escaping.
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
 * <li> <b>S_OMIT_META_TAG </b> -
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
 * This non-standard property key is used to set a value of "yes" if the META tag should be omitted where it would
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
 *  otherwise be supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
 * </ul>
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
 * @see SerializerFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
 * @see Method
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
 * @see Serializer
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
public final class OutputPropertiesFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    /** S_BUILTIN_EXTENSIONS_URL is a mnemonic for the XML Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     *(http://xml.apache.org/xalan) predefined to signify Xalan's
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     * built-in XSLT Extensions. When used in stylesheets, this is often
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * bound to the "xalan:" prefix.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    private static final String
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
      S_BUILTIN_EXTENSIONS_URL = "http://xml.apache.org/xalan";
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * The old built-in extension url. It is still supported for
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     * backward compatibility.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    private static final String
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
      S_BUILTIN_OLD_EXTENSIONS_URL = "http://xml.apache.org/xslt";
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    //*  PUBLIC CONSTANTS
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     * This is not a public API.
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
     * This is the built-in extensions namespace,
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
     * reexpressed in {namespaceURI} syntax
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
     * suitable for prepending to a localname to produce a "universal
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * name".
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    public static final String S_BUILTIN_EXTENSIONS_UNIVERSAL =
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        "{" + S_BUILTIN_EXTENSIONS_URL + "}";
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    // Some special Xalan keys.
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * The non-standard property key to use to set the
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     * number of whitepaces to indent by, per indentation level,
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * if indent="yes".
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    public static final String S_KEY_INDENT_AMOUNT =
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "indent-amount";
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * The non-standard property key to use to set the
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     * number of whitepaces to indent by, per indentation level,
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     * if indent="yes".
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    public static final String S_KEY_LINE_SEPARATOR =
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "line-separator";
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    /** This non-standard property key is used to set the name of the fully qualified
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     * Java class that implements the ContentHandler interface.
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * Fully qualified name of class with a default constructor that
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     *  implements the ContentHandler interface, where the result tree events
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     *  will be sent to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    public static final String S_KEY_CONTENT_HANDLER =
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "content-handler";
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
     * This non-standard property key is used to specify the name of the property file
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * that specifies character to entity reference mappings.
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    public static final String S_KEY_ENTITIES =
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "entities";
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     * This non-standard property key is used to set a value of "yes" if the href values for HTML serialization should
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     *  use %xx escaping. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
    public static final String S_USE_URL_ESCAPING =
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "use-url-escaping";
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * This non-standard property key is used to set a value of "yes" if the META tag should be omitted where it would
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     *  otherwise be supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    public static final String S_OMIT_META_TAG =
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        S_BUILTIN_EXTENSIONS_UNIVERSAL + "omit-meta-tag";
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * The old built-in extension namespace, this is not a public API.
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    public static final String S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL =
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        "{" + S_BUILTIN_OLD_EXTENSIONS_URL + "}";
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * This is not a public API, it is only public because it is used
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     * by outside of this package,
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * it is the length of the old built-in extension namespace.
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN =
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   179
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   180
     * This non-standard, Oracle-impl only property key is used as if OutputKeys.STANDALONE is specified but
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   181
     * without writing it out in the declaration; It can be used to reverse the change by Xalan patch 1495.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   182
     * Since Xalan patch 1495 can cause incompatible behavior, this property is add for application to neutralize
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   183
     * the effect of Xalan patch 1495
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   184
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   185
        /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   186
         * <p>Is Standalone</p>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   187
         *
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   188
         * <ul>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   189
         *   <li>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   190
         *     <code>yes</code> to indicate the output is intended to be used as standalone
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   191
         *   </li>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   192
         *   <li>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   193
         *     <code>no</code> has no effect.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   194
         *   </li>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   195
         * </ul>
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   196
         */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   197
    public static final String ORACLE_IS_STANDALONE = "http://www.oracle.com/xml/is-standalone";
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   198
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    //*  PRIVATE CONSTANTS
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
    private static final String S_XSLT_PREFIX = "xslt.output.";
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    private static final int S_XSLT_PREFIX_LEN = S_XSLT_PREFIX.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
    private static final String S_XALAN_PREFIX = "org.apache.xslt.";
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    private static final int S_XALAN_PREFIX_LEN = S_XALAN_PREFIX.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
    /** Synchronization object for lazy initialization of the above tables. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    private static Integer m_synch_object = new Integer(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    /** the directory in which the various method property files are located */
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    private static final String PROP_DIR = "com/sun/org/apache/xml/internal/serializer/";
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    /** property file for default XML properties */
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    private static final String PROP_FILE_XML = "output_xml.properties";
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    /** property file for default TEXT properties */
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    private static final String PROP_FILE_TEXT = "output_text.properties";
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    /** property file for default HTML properties */
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    private static final String PROP_FILE_HTML = "output_html.properties";
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
    /** property file for default UNKNOWN (Either XML or HTML, to be determined later) properties */
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    private static final String PROP_FILE_UNKNOWN = "output_unknown.properties";
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    //*  PRIVATE STATIC FIELDS
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
    //************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    /** The default properties of all output files. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    private static Properties m_xml_properties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    /** The default properties when method="html". */
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
    private static Properties m_html_properties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    /** The default properties when method="text". */
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    private static Properties m_text_properties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    /** The properties when method="" for the "unknown" wrapper */
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    private static Properties m_unknown_properties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
    private static final Class
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        ACCESS_CONTROLLER_CLASS = findAccessControllerClass();
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    private static Class findAccessControllerClass() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
            // This Class was introduced in JDK 1.2. With the re-architecture of
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            // security mechanism ( starting in JDK 1.2 ), we have option of
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
            // giving privileges to certain part of code using doPrivileged block.
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
            // In JDK1.1.X applications won't be having security manager and if
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
            // there is security manager ( in applets ), code need to be signed
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            // and trusted for having access to resources.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            return Class.forName("java.security.AccessController");
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        catch (Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            //User may be using older JDK ( JDK <1.2 ). Allow him/her to use it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
            // But don't try to use doPrivileged
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
     * Creates an empty OutputProperties with the property key/value defaults specified by
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
     * a property file.  The method argument is used to construct a string of
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
     * the form output_[method].properties (for instance, output_html.properties).
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
     * The output_xml.properties file is always used as the base.
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
     * <p>Anything other than 'text', 'xml', and 'html', will
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
     * use the output_xml.properties file.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
     * @param   method non-null reference to method name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
     * @return Properties object that holds the defaults for the given method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    static public final Properties getDefaultMethodProperties(String method)
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        String fileName = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        Properties defaultProperties = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        // According to this article : Double-check locking does not work
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        // http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            synchronized (m_synch_object)
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                if (null == m_xml_properties) // double check
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
                    fileName = PROP_FILE_XML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                    m_xml_properties = loadPropertiesFile(fileName, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
            if (method.equals(Method.XML))
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                defaultProperties = m_xml_properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            else if (method.equals(Method.HTML))
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                if (null == m_html_properties) // double check
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                    fileName = PROP_FILE_HTML;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
                    m_html_properties =
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                        loadPropertiesFile(fileName, m_xml_properties);
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
                defaultProperties = m_html_properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
            else if (method.equals(Method.TEXT))
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
                if (null == m_text_properties) // double check
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
                    fileName = PROP_FILE_TEXT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
                    m_text_properties =
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
                        loadPropertiesFile(fileName, m_xml_properties);
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
                    if (null
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
                        == m_text_properties.getProperty(OutputKeys.ENCODING))
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
                    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                        String mimeEncoding = Encodings.getMimeEncoding(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
                        m_text_properties.put(
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
                            OutputKeys.ENCODING,
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                            mimeEncoding);
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                defaultProperties = m_text_properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
            else if (method.equals(com.sun.org.apache.xml.internal.serializer.Method.UNKNOWN))
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                if (null == m_unknown_properties) // double check
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                    fileName = PROP_FILE_UNKNOWN;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                    m_unknown_properties =
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                        loadPropertiesFile(fileName, m_xml_properties);
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                defaultProperties = m_unknown_properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                // TODO: Calculate res file from name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                defaultProperties = m_xml_properties;
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
        catch (IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
            throw new WrappedRuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                    MsgKey.ER_COULD_NOT_LOAD_METHOD_PROPERTY,
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
                    new Object[] { fileName, method }),
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
                ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        // wrap these cached defaultProperties in a new Property object just so
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
        // that the caller of this method can't modify the default values
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
        return new Properties(defaultProperties);
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
     * Load the properties file from a resource stream.  If a
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
     * key name such as "org.apache.xslt.xxx", fix up the start of
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     * string to be a curly namespace.  If a key name starts with
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
     * "xslt.output.xxx", clip off "xslt.output.".  If a key name *or* a
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * key value is discovered, check for \u003a in the text, and
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * fix it up to be ":", since earlier versions of the JDK do not
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     * handle the escape sequence (at least in key names).
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
     * @param resourceName non-null reference to resource name.
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
     * @param defaults Default properties, which may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    static private Properties loadPropertiesFile(
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
        final String resourceName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
        Properties defaults)
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
        throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        // This static method should eventually be moved to a thread-specific class
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        // so that we can cache the ContextClassLoader and bottleneck all properties file
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        // loading throughout Xalan.
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
        Properties props = new Properties(defaults);
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
        InputStream is = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
        BufferedInputStream bis = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
            if (ACCESS_CONTROLLER_CLASS != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
                is = (InputStream) AccessController
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
                    .doPrivileged(new PrivilegedAction() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
                        public Object run()
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
                            return OutputPropertiesFactory.class
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
                                .getResourceAsStream(resourceName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
                    });
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
                // User may be using older JDK ( JDK < 1.2 )
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
                is = OutputPropertiesFactory.class
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
                    .getResourceAsStream(resourceName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
            bis = new BufferedInputStream(is);
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
            props.load(bis);
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        catch (IOException ioe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
            if (defaults == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
                throw ioe;
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                throw new WrappedRuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                    Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
                        MsgKey.ER_COULD_NOT_LOAD_RESOURCE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
                        new Object[] { resourceName }),
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
                    ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
                //"Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ", ioe);
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
        catch (SecurityException se)
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
            // Repeat IOException handling for sandbox/applet case -sc
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            if (defaults == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
                throw se;
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
                throw new WrappedRuntimeException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
                    Utils.messages.createMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
                        MsgKey.ER_COULD_NOT_LOAD_RESOURCE,
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
                        new Object[] { resourceName }),
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
                    se);
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                //"Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the defaults ", se);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        finally
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
            if (bis != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
                bis.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
            if (is != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
                is.close();
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
        // Note that we're working at the HashTable level here,
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
        // and not at the Properties level!  This is important
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
        // because we don't want to modify the default properties.
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
        // NB: If fixupPropertyString ends up changing the property
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        // name or value, we need to remove the old key and re-add
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
        // with the new key and value.  However, then our Enumeration
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        // could lose its place in the HashTable.  So, we first
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        // clone the HashTable and enumerate over that since the
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        // clone will not change.  When we migrate to Collections,
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        // this code should be revisited and cleaned up to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        // an Iterator which may (or may not) alleviate the need for
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        // the clone.  Many thanks to Padraig O'hIceadha
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        // <padraig@gradient.ie> for finding this problem.  Bugzilla 2000.
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
        Enumeration keys = ((Properties) props.clone()).keys();
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
        while (keys.hasMoreElements())
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            String key = (String) keys.nextElement();
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
            // Now check if the given key was specified as a
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
            // System property. If so, the system property
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            // overides the default value in the propery file.
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
            String value = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
            {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   475
                value = SecuritySupport.getSystemProperty(key);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
            catch (SecurityException se)
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
                // No-op for sandbox/applet case, leave null -sc
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
            if (value == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
                value = (String) props.get(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
            String newKey = fixupPropertyString(key, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
            String newValue = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
            try
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
            {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12458
diff changeset
   488
                newValue = SecuritySupport.getSystemProperty(newKey);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
            catch (SecurityException se)
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
                // No-op for sandbox/applet case, leave null -sc
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
            if (newValue == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
                newValue = fixupPropertyString(value, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
            else
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
                newValue = fixupPropertyString(newValue, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
            if (key != newKey || value != newValue)
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
                props.remove(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
                props.put(newKey, newValue);
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
        return props;
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
     * Fix up a string in an output properties file according to
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
     * the rules of {@link #loadPropertiesFile}.
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
     * @param s non-null reference to string that may need to be fixed up.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
     * @return A new string if fixup occured, otherwise the s argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
    static private String fixupPropertyString(String s, boolean doClipping)
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
        int index;
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
        if (doClipping && s.startsWith(S_XSLT_PREFIX))
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
            s = s.substring(S_XSLT_PREFIX_LEN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
        if (s.startsWith(S_XALAN_PREFIX))
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
            s =
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
                S_BUILTIN_EXTENSIONS_UNIVERSAL
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
                    + s.substring(S_XALAN_PREFIX_LEN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
        if ((index = s.indexOf("\\u003a")) > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
            String temp = s.substring(index + 6);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
            s = s.substring(0, index) + ":" + temp;
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
        return s;
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
}