19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one
39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file
49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information
59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file
69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the  "License");
79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License.
89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at
99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *     http://www.apache.org/licenses/LICENSE-2.0
119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software
139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and
169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License.
179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/*
199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: OutputPropertiesFactory.java 468654 2006-10-28 07:09:23Z minchau $
209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.serializer;
229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.BufferedInputStream;
249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.IOException;
259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.io.InputStream;
269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.security.AccessController;
279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.security.PrivilegedAction;
289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Enumeration;
299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport java.util.Properties;
309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport javax.xml.transform.OutputKeys;
329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.serializer.utils.MsgKey;
349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.serializer.utils.Utils;
359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.serializer.utils.WrappedRuntimeException;
369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/**
389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This class is a factory to generate a set of default properties
399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of key/value pairs that are used to create a serializer through the
409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * factory {@link SerializerFactory SerilizerFactory}.
419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The properties generated by this factory
429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * may be modified to non-default values before the SerializerFactory is used to
439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * create a Serializer.
449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>
459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The given output types supported are "xml", "text", and "html".
469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * These type strings can be obtained from the
479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * {@link Method Method} class in this package.
489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p>
499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Other constants defined in this class are the non-standard property keys
509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that can be used to set non-standard property values on a java.util.Properties object
519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that is used to create or configure a serializer. Here are the non-standard keys:
529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <ul>
539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li> <b>S_KEY_INDENT_AMOUNT </b> -
549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The non-standard property key to use to set the indentation amount.
559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The "indent" key needs to have a value of "yes", and this
569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * properties value is a the number of whitespaces to indent by per
579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * indentation level.
589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li> <b>S_KEY_CONTENT_HANDLER </b> -
609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This non-standard property key is used to set the name of the fully qualified
619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Java class that implements the ContentHandler interface.
629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The output of the serializer will be SAX events sent to this an
639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * object of this class.
649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li> <b>S_KEY_ENTITIES </b> -
669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This non-standard property key is used to specify the name of the property file
679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that specifies character to entity reference mappings. A line in such a
689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * file is has the name of the entity and the numeric (base 10) value
699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * of the corresponding character, like this one: <br> quot=34 <br>
709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li> <b>S_USE_URL_ESCAPING </b> -
729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This non-standard property key is used to set a value of "yes" if the href values for HTML serialization should
739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *  use %xx escaping.
749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <li> <b>S_OMIT_META_TAG </b> -
769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This non-standard property key is used to set a value of "yes" if the META tag should be omitted where it would
779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *  otherwise be supplied.
789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </ul>
799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson *
809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see SerializerFactory
819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see Method
829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see Serializer
839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */
849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic final class OutputPropertiesFactory
859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{
869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** S_BUILTIN_EXTENSIONS_URL is a mnemonic for the XML Namespace
879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *(http://xml.apache.org/xalan) predefined to signify Xalan's
889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * built-in XSLT Extensions. When used in stylesheets, this is often
899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * bound to the "xalan:" prefix.
909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String
929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      S_BUILTIN_EXTENSIONS_URL = "http://xml.apache.org/xalan";
939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The old built-in extension url. It is still supported for
969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * backward compatibility.
979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String
999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson      S_BUILTIN_OLD_EXTENSIONS_URL = "http://xml.apache.org/xslt";
1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //*  PUBLIC CONSTANTS
1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This is not a public API.
1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This is the built-in extensions namespace,
1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * reexpressed in {namespaceURI} syntax
1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * suitable for prepending to a localname to produce a "universal
1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * name".
1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_BUILTIN_EXTENSIONS_UNIVERSAL =
1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        "{" + S_BUILTIN_EXTENSIONS_URL + "}";
1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    // Some special Xalan keys.
1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The non-standard property key to use to set the
1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * number of whitepaces to indent by, per indentation level,
1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * if indent="yes".
1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_KEY_INDENT_AMOUNT =
1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "indent-amount";
1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The non-standard property key to use to set the
1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * characters to write out as at the end of a line,
1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * rather than the default ones from the runtime.
1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_KEY_LINE_SEPARATOR =
1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "line-separator";
1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** This non-standard property key is used to set the name of the fully qualified
1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Java class that implements the ContentHandler interface.
1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Fully qualified name of class with a default constructor that
1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  implements the ContentHandler interface, where the result tree events
1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  will be sent to.
1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_KEY_CONTENT_HANDLER =
1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "content-handler";
1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This non-standard property key is used to specify the name of the property file
1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * that specifies character to entity reference mappings.
1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_KEY_ENTITIES =
1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "entities";
1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This non-standard property key is used to set a value of "yes" if the href values for HTML serialization should
1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  use %xx escaping. */
1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_USE_URL_ESCAPING =
1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "use-url-escaping";
1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This non-standard property key is used to set a value of "yes" if the META tag should be omitted where it would
1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *  otherwise be supplied.
1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_OMIT_META_TAG =
1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_EXTENSIONS_UNIVERSAL + "omit-meta-tag";
1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The old built-in extension namespace, this is not a public API.
1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final String S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL =
1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        "{" + S_BUILTIN_OLD_EXTENSIONS_URL + "}";
1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * This is not a public API, it is only public because it is used
1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * by outside of this package,
1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * it is the length of the old built-in extension namespace.
1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    public static final int S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL_LEN =
1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        S_BUILTIN_OLD_EXTENSIONS_UNIVERSAL.length();
1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //*  PRIVATE CONSTANTS
1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String S_XSLT_PREFIX = "xslt.output.";
1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final int S_XSLT_PREFIX_LEN = S_XSLT_PREFIX.length();
1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String S_XALAN_PREFIX = "org.apache.xslt.";
1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final int S_XALAN_PREFIX_LEN = S_XALAN_PREFIX.length();
1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** Synchronization object for lazy initialization of the above tables. */
1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Integer m_synch_object = new Integer(1);
1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** the directory in which the various method property files are located */
1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String PROP_DIR = SerializerBase.PKG_PATH+'/';
1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** property file for default XML properties */
1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String PROP_FILE_XML = "output_xml.properties";
1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** property file for default TEXT properties */
1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String PROP_FILE_TEXT = "output_text.properties";
1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** property file for default HTML properties */
1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String PROP_FILE_HTML = "output_html.properties";
1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** property file for default UNKNOWN (Either XML or HTML, to be determined later) properties */
1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final String PROP_FILE_UNKNOWN = "output_unknown.properties";
1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //*  PRIVATE STATIC FIELDS
2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    //************************************************************
2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** The default properties of all output files. */
2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Properties m_xml_properties = null;
2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** The default properties when method="html". */
2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Properties m_html_properties = null;
2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** The default properties when method="text". */
2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Properties m_text_properties = null;
2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /** The properties when method="" for the "unknown" wrapper */
2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Properties m_unknown_properties = null;
2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static final Class
2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        ACCESS_CONTROLLER_CLASS = findAccessControllerClass();
2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    private static Class findAccessControllerClass() {
2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // This Class was introduced in JDK 1.2. With the re-architecture of
2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // security mechanism ( starting in JDK 1.2 ), we have option of
2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // giving privileges to certain part of code using doPrivileged block.
2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // In JDK1.1.X applications won't be having security manager and if
2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // there is security manager ( in applets ), code need to be signed
2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // and trusted for having access to resources.
2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            return Class.forName("java.security.AccessController");
2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (Exception e)
2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            //User may be using older JDK ( JDK <1.2 ). Allow him/her to use it.
2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // But don't try to use doPrivileged
2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return null;
2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Creates an empty OutputProperties with the property key/value defaults specified by
2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * a property file.  The method argument is used to construct a string of
2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * the form output_[method].properties (for instance, output_html.properties).
2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * The output_xml.properties file is always used as the base.
2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *
2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * <p>Anything other than 'text', 'xml', and 'html', will
2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * use the output_xml.properties file.</p>
2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *
2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @param   method non-null reference to method name.
2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *
2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @return Properties object that holds the defaults for the given method.
2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static public final Properties getDefaultMethodProperties(String method)
2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        String fileName = null;
2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        Properties defaultProperties = null;
2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // According to this article : Double-check locking does not work
2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html
2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            synchronized (m_synch_object)
2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                if (null == m_xml_properties) // double check
2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                {
2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    fileName = PROP_FILE_XML;
2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    m_xml_properties = loadPropertiesFile(fileName, null);
2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                }
2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (method.equals(Method.XML))
2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                defaultProperties = m_xml_properties;
2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else if (method.equals(Method.HTML))
2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                if (null == m_html_properties) // double check
2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                {
2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    fileName = PROP_FILE_HTML;
2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    m_html_properties =
2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        loadPropertiesFile(fileName, m_xml_properties);
2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                }
2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                defaultProperties = m_html_properties;
2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else if (method.equals(Method.TEXT))
2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                if (null == m_text_properties) // double check
2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                {
2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    fileName = PROP_FILE_TEXT;
2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    m_text_properties =
2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        loadPropertiesFile(fileName, m_xml_properties);
2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    if (null
2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        == m_text_properties.getProperty(OutputKeys.ENCODING))
2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    {
2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        String mimeEncoding = Encodings.getMimeEncoding(null);
2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        m_text_properties.put(
2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            OutputKeys.ENCODING,
2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            mimeEncoding);
2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    }
2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                }
3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                defaultProperties = m_text_properties;
3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else if (method.equals(Method.UNKNOWN))
3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                if (null == m_unknown_properties) // double check
3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                {
3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    fileName = PROP_FILE_UNKNOWN;
3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    m_unknown_properties =
3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        loadPropertiesFile(fileName, m_xml_properties);
3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                }
3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                defaultProperties = m_unknown_properties;
3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else
3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                // TODO: Calculate res file from name.
3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                defaultProperties = m_xml_properties;
3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (IOException ioe)
3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            throw new WrappedRuntimeException(
3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                Utils.messages.createMessage(
3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    MsgKey.ER_COULD_NOT_LOAD_METHOD_PROPERTY,
3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    new Object[] { fileName, method }),
3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                ioe);
3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // wrap these cached defaultProperties in a new Property object just so
3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // that the caller of this method can't modify the default values
3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return new Properties(defaultProperties);
3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Load the properties file from a resource stream.  If a
3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * key name such as "org.apache.xslt.xxx", fix up the start of
3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * string to be a curly namespace.  If a key name starts with
3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * "xslt.output.xxx", clip off "xslt.output.".  If a key name *or* a
3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * key value is discovered, check for \u003a in the text, and
3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * fix it up to be ":", since earlier versions of the JDK do not
3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * handle the escape sequence (at least in key names).
3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *
3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @param resourceName non-null reference to resource name.
3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @param defaults Default properties, which may be null.
3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static private Properties loadPropertiesFile(
3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        final String resourceName,
3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        Properties defaults)
3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        throws IOException
3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // This static method should eventually be moved to a thread-specific class
3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // so that we can cache the ContextClassLoader and bottleneck all properties file
3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // loading throughout Xalan.
3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        Properties props = new Properties(defaults);
3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        InputStream is = null;
3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        BufferedInputStream bis = null;
3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        try
3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (ACCESS_CONTROLLER_CLASS != null)
3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                is = (InputStream) AccessController
3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    .doPrivileged(new PrivilegedAction() {
3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        public Object run()
3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        {
3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                            return OutputPropertiesFactory.class
3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                                .getResourceAsStream(resourceName);
3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        }
3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    });
3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else
3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                // User may be using older JDK ( JDK < 1.2 )
3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                is = OutputPropertiesFactory.class
3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    .getResourceAsStream(resourceName);
3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            bis = new BufferedInputStream(is);
3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            props.load(bis);
3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (IOException ioe)
3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (defaults == null)
3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                throw ioe;
3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else
3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                throw new WrappedRuntimeException(
3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    Utils.messages.createMessage(
3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        MsgKey.ER_COULD_NOT_LOAD_RESOURCE,
3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        new Object[] { resourceName }),
3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    ioe);
3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                //"Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ", ioe);
3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        catch (SecurityException se)
4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // Repeat IOException handling for sandbox/applet case -sc
4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (defaults == null)
4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                throw se;
4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else
4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                throw new WrappedRuntimeException(
4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    Utils.messages.createMessage(
4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        MsgKey.ER_COULD_NOT_LOAD_RESOURCE,
4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                        new Object[] { resourceName }),
4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    se);
4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                //"Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the defaults ", se);
4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        finally
4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (bis != null)
4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                bis.close();
4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (is != null)
4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                is.close();
4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // Note that we're working at the HashTable level here,
4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // and not at the Properties level!  This is important
4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // because we don't want to modify the default properties.
4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // NB: If fixupPropertyString ends up changing the property
4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // name or value, we need to remove the old key and re-add
4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // with the new key and value.  However, then our Enumeration
4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // could lose its place in the HashTable.  So, we first
4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // clone the HashTable and enumerate over that since the
4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // clone will not change.  When we migrate to Collections,
4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // this code should be revisited and cleaned up to use
4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // an Iterator which may (or may not) alleviate the need for
4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // the clone.  Many thanks to Padraig O'hIceadha
4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        // <padraig@gradient.ie> for finding this problem.  Bugzilla 2000.
4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        Enumeration keys = ((Properties) props.clone()).keys();
4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        while (keys.hasMoreElements())
4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            String key = (String) keys.nextElement();
4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // Now check if the given key was specified as a
4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // System property. If so, the system property
4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            // overides the default value in the propery file.
4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            String value = null;
4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            try
4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                value = System.getProperty(key);
4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            catch (SecurityException se)
4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                // No-op for sandbox/applet case, leave null -sc
4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (value == null)
4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                value = (String) props.get(key);
4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            String newKey = fixupPropertyString(key, true);
4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            String newValue = null;
4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            try
4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                newValue = System.getProperty(newKey);
4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            catch (SecurityException se)
4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                // No-op for sandbox/applet case, leave null -sc
4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (newValue == null)
4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                newValue = fixupPropertyString(value, false);
4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            else
4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                newValue = fixupPropertyString(newValue, false);
4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            if (key != newKey || value != newValue)
4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            {
4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                props.remove(key);
4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                props.put(newKey, newValue);
4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            }
4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return props;
4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    /**
4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * Fix up a string in an output properties file according to
4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * the rules of {@link #loadPropertiesFile}.
4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     *
4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @param s non-null reference to string that may need to be fixed up.
4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     * @return A new string if fixup occured, otherwise the s argument.
4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson     */
4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    static private String fixupPropertyString(String s, boolean doClipping)
4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    {
4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        int index;
4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (doClipping && s.startsWith(S_XSLT_PREFIX))
4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            s = s.substring(S_XSLT_PREFIX_LEN);
5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if (s.startsWith(S_XALAN_PREFIX))
5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            s =
5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                S_BUILTIN_EXTENSIONS_UNIVERSAL
5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson                    + s.substring(S_XALAN_PREFIX_LEN);
5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        if ((index = s.indexOf("\\u003a")) > 0)
5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        {
5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            String temp = s.substring(index + 6);
5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson            s = s.substring(0, index) + ":" + temp;
5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        }
5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson        return s;
5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson    }
5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson
5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson}
517