001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: XSLMessages.java 468641 2006-10-28 06:54:42Z minchau $
020     */
021    package org.apache.xalan.res;
022    
023    import java.util.ListResourceBundle;
024    
025    import org.apache.xpath.res.XPATHMessages;
026    
027    /**
028     * Sets things up for issuing error messages.  This class is misnamed, and
029     * should be called XalanMessages, or some such.
030     * @xsl.usage internal
031     */
032    public class XSLMessages extends XPATHMessages
033    {
034    
035      /** The language specific resource object for Xalan messages.  */
036      private static ListResourceBundle XSLTBundle = null;
037    
038      /** The class name of the Xalan error message string table.    */
039      private static final String XSLT_ERROR_RESOURCES =
040        "org.apache.xalan.res.XSLTErrorResources";
041    
042      /**
043       * Creates a message from the specified key and replacement
044       * arguments, localized to the given locale.
045       *
046       * @param msgKey    The key for the message text.
047       * @param args      The arguments to be used as replacement text
048       *                  in the message created.
049       *
050       * @return The formatted message string.
051       */
052      public static final String createMessage(String msgKey, Object args[])  //throws Exception
053      {
054        if (XSLTBundle == null)
055          XSLTBundle = loadResourceBundle(XSLT_ERROR_RESOURCES);
056        
057        if (XSLTBundle != null)
058        {
059          return createMsg(XSLTBundle, msgKey, args);
060        }
061        else
062          return "Could not load any resource bundles.";
063      }
064      
065      /**
066       * Creates a message from the specified key and replacement
067       * arguments, localized to the given locale.
068       *
069       * @param msgKey    The key for the message text.
070       * @param args      The arguments to be used as replacement text
071       *                  in the message created.
072       *
073       * @return The formatted warning string.
074       */
075      public static final String createWarning(String msgKey, Object args[])  //throws Exception
076      {
077        if (XSLTBundle == null)
078          XSLTBundle = loadResourceBundle(XSLT_ERROR_RESOURCES);
079    
080        if (XSLTBundle != null)
081        {
082          return createMsg(XSLTBundle, msgKey, args);
083        }
084        else
085          return "Could not load any resource bundles.";
086      }
087    }