001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057: package org.apache.xerces.utils;
058:
059: import java.util.Locale;
060: import java.util.ResourceBundle;
061: import java.util.ListResourceBundle;
062:
063: /**
064: * ImplementationMessages provides messages internal to the parser implementation
065: *
066: * @version
067: */
068: public class ImplementationMessages implements XMLMessageProvider {
069: /**
070: * The domain of messages concerning the Xerces implementation.
071: */
072: public static final String XERCES_IMPLEMENTATION_DOMAIN = "http://www.apache.org/xml/xerces.html";
073:
074: /**
075: *
076: */
077: public void setLocale(Locale locale) {
078: fLocale = locale;
079: }
080:
081: /**
082: *
083: */
084: public Locale getLocale() {
085: return fLocale;
086: }
087:
088: /**
089: * Creates a message from the specified key and replacement
090: * arguments, localized to the given locale.
091: *
092: * @param locale The requested locale of the message to be
093: * created.
094: * @param key The key for the message text.
095: * @param args The arguments to be used as replacement text
096: * in the message created.
097: */
098: public String createMessage(Locale locale, int majorCode,
099: int minorCode, Object args[]) {
100: boolean throwex = false;
101: if (fResourceBundle == null || locale != fLocale) {
102: if (locale != null)
103: fResourceBundle = ListResourceBundle.getBundle(
104: "org.apache.xerces.msg.ImplementationMessages",
105: locale);
106: if (fResourceBundle == null)
107: fResourceBundle = ListResourceBundle
108: .getBundle("org.apache.xerces.msg.ImplementationMessages");
109: }
110: if (majorCode < 0 || majorCode >= fgMessageKeys.length - 1) {
111: majorCode = BAD_MAJORCODE;
112: throwex = true;
113: }
114: String msgKey = fgMessageKeys[majorCode];
115: String msg = fResourceBundle.getString(msgKey);
116: if (args != null) {
117: try {
118: msg = java.text.MessageFormat.format(msg, args);
119: } catch (Exception e) {
120: msg = fResourceBundle
121: .getString(fgMessageKeys[FORMAT_FAILED]);
122: msg += " " + fResourceBundle.getString(msgKey);
123: }
124: }
125: if (throwex) {
126: throw new RuntimeException(msg);
127: }
128: return msg;
129: }
130:
131: //
132: //
133: //
134: private Locale fLocale = null;
135: private ResourceBundle fResourceBundle = null;
136: //
137: //
138: //
139: public static final int BAD_MAJORCODE = 0, // majorCode parameter to createMessage was out of bounds
140: ENC4 = 1, // "Invalid UTF-8 code. (byte: 0x{0})"
141: ENC5 = 2, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1})"
142: ENC6 = 3, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2})"
143: ENC7 = 4, // "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2} 0x{3})"
144: IO0 = 5, // "File, \"{0}\", not found."
145: VAL_BST = 6, // "Invalid ContentSpecNode.NODE_XXX value for binary op CMNode."
146: VAL_CMSI = 7, // "Invalid CMStateSet bit index."
147: VAL_CST = 8, // "Unknown ContentSpecNode.NODE_XXX value."
148: VAL_LST = 9, // "Invalid ContentSpecNode.NODE_XXX value for leaf CMNode."
149: VAL_NIICM = 10, // "Only * unary ops should be in the internal content model tree."
150: VAL_NPCD = 11, // "PCData found in non-mixed model content."
151: VAL_UST = 12, // "Invalid ContentSpecNode.NODE_XXX value for unary op CMNode."
152: VAL_WCGHI = 13, // "Input to whatCanGoHere() is inconsistent."
153: INT_DCN = 14, // "Internal Error: dataChunk == NULL"
154: INT_PCN = 15, // "Internal Error: fPreviousChunk == NULL"
155: FATAL_ERROR = 16, // "Stopping after fatal error: {0}"
156:
157: //
158: // KEEP THIS AT THE END
159: //
160: FORMAT_FAILED = 17; // "Internal Error while formatting error message "
161:
162: //
163: // Table of error code to error key strings.
164: //
165: private static final String[] fgMessageKeys = { "BadMajorCode", // 0, "The majorCode parameter to createMessage was out of bounds."
166: "ENC4", // 1, "Invalid UTF-8 code. (byte: 0x{0})"
167: "ENC5", // 2, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1})"
168: "ENC6", // 3, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2})"
169: "ENC7", // 4, "Invalid UTF-8 code. (bytes: 0x{0} 0x{1} 0x{2} 0x{3})"
170: "FileNotFound", // 5, "File, \"{0}\", not found."
171: "VAL_BST", // 6, "Invalid ContentSpecNode.NODE_XXX value for binary op CMNode."
172: "VAL_CMSI", // 7, "Invalid CMStateSet bit index."
173: "VAL_CST", // 8, "Unknown ContentSpecNode.NODE_XXX value."
174: "VAL_LST", // 9, "Invalid ContentSpecNode.NODE_XXX value for leaf CMNode."
175: "VAL_NIICM", // 10, "Only * unary ops should be in the internal content model tree."
176: "VAL_NPCD", // 11, "PCData found in non-mixed model content."
177: "VAL_UST", // 12, "Invalid ContentSpecNode.NODE_XXX value for unary op CMNode."
178: "VAL_WCGHI", // 13, "Input to whatCanGoHere() is inconsistent."
179: "INT_DCN", // 14, "Internal Error: dataChunk == NULL"
180: "INT_PCN", // 15, "Internal Error: fPreviousChunk == NULL"
181: "FatalError", // 16, "Stopping after fatal error: {0}"
182:
183: //
184: // KEEP THIS AT THE END
185: //
186: "FormatFailed", // 17, "An internal error occurred while formatting the following message:"
187: null };
188: }
|