001: /*
002: * Copyright 1999-2005 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: XMLErrorResources.java,v 1.10 2005/06/29 19:30:33 jycli Exp $
018: */
019: package org.apache.xml.res;
020:
021: import java.util.ListResourceBundle;
022: import java.util.Locale;
023: import java.util.MissingResourceException;
024: import java.util.ResourceBundle;
025:
026: /**
027: * Set up error messages.
028: * We build a two dimensional array of message keys and
029: * message strings. In order to add a new message here,
030: * you need to first add a String constant. And you need
031: * to enter key, value pair as part of the contents
032: * array. You also need to update MAX_CODE for error strings
033: * and MAX_WARNING for warnings ( Needed for only information
034: * purpose )
035: */
036: public class XMLErrorResources extends ListResourceBundle {
037:
038: /*
039: * This file contains error and warning messages related to Xalan Error
040: * Handling.
041: *
042: * General notes to translators:
043: *
044: * 1) Xalan (or more properly, Xalan-interpretive) and XSLTC are names of
045: * components.
046: * XSLT is an acronym for "XML Stylesheet Language: Transformations".
047: * XSLTC is an acronym for XSLT Compiler.
048: *
049: * 2) A stylesheet is a description of how to transform an input XML document
050: * into a resultant XML document (or HTML document or text). The
051: * stylesheet itself is described in the form of an XML document.
052: *
053: * 3) A template is a component of a stylesheet that is used to match a
054: * particular portion of an input document and specifies the form of the
055: * corresponding portion of the output document.
056: *
057: * 4) An element is a mark-up tag in an XML document; an attribute is a
058: * modifier on the tag. For example, in <elem attr='val' attr2='val2'>
059: * "elem" is an element name, "attr" and "attr2" are attribute names with
060: * the values "val" and "val2", respectively.
061: *
062: * 5) A namespace declaration is a special attribute that is used to associate
063: * a prefix with a URI (the namespace). The meanings of element names and
064: * attribute names that use that prefix are defined with respect to that
065: * namespace.
066: *
067: * 6) "Translet" is an invented term that describes the class file that
068: * results from compiling an XML stylesheet into a Java class.
069: *
070: * 7) XPath is a specification that describes a notation for identifying
071: * nodes in a tree-structured representation of an XML document. An
072: * instance of that notation is referred to as an XPath expression.
073: *
074: */
075:
076: /*
077: * Message keys
078: */
079: public static final String ER_FUNCTION_NOT_SUPPORTED = "ER_FUNCTION_NOT_SUPPORTED";
080: public static final String ER_CANNOT_OVERWRITE_CAUSE = "ER_CANNOT_OVERWRITE_CAUSE";
081: public static final String ER_NO_DEFAULT_IMPL = "ER_NO_DEFAULT_IMPL";
082: public static final String ER_CHUNKEDINTARRAY_NOT_SUPPORTED = "ER_CHUNKEDINTARRAY_NOT_SUPPORTED";
083: public static final String ER_OFFSET_BIGGER_THAN_SLOT = "ER_OFFSET_BIGGER_THAN_SLOT";
084: public static final String ER_COROUTINE_NOT_AVAIL = "ER_COROUTINE_NOT_AVAIL";
085: public static final String ER_COROUTINE_CO_EXIT = "ER_COROUTINE_CO_EXIT";
086: public static final String ER_COJOINROUTINESET_FAILED = "ER_COJOINROUTINESET_FAILED";
087: public static final String ER_COROUTINE_PARAM = "ER_COROUTINE_PARAM";
088: public static final String ER_PARSER_DOTERMINATE_ANSWERS = "ER_PARSER_DOTERMINATE_ANSWERS";
089: public static final String ER_NO_PARSE_CALL_WHILE_PARSING = "ER_NO_PARSE_CALL_WHILE_PARSING";
090: public static final String ER_TYPED_ITERATOR_AXIS_NOT_IMPLEMENTED = "ER_TYPED_ITERATOR_AXIS_NOT_IMPLEMENTED";
091: public static final String ER_ITERATOR_AXIS_NOT_IMPLEMENTED = "ER_ITERATOR_AXIS_NOT_IMPLEMENTED";
092: public static final String ER_ITERATOR_CLONE_NOT_SUPPORTED = "ER_ITERATOR_CLONE_NOT_SUPPORTED";
093: public static final String ER_UNKNOWN_AXIS_TYPE = "ER_UNKNOWN_AXIS_TYPE";
094: public static final String ER_AXIS_NOT_SUPPORTED = "ER_AXIS_NOT_SUPPORTED";
095: public static final String ER_NO_DTMIDS_AVAIL = "ER_NO_DTMIDS_AVAIL";
096: public static final String ER_NOT_SUPPORTED = "ER_NOT_SUPPORTED";
097: public static final String ER_NODE_NON_NULL = "ER_NODE_NON_NULL";
098: public static final String ER_COULD_NOT_RESOLVE_NODE = "ER_COULD_NOT_RESOLVE_NODE";
099: public static final String ER_STARTPARSE_WHILE_PARSING = "ER_STARTPARSE_WHILE_PARSING";
100: public static final String ER_STARTPARSE_NEEDS_SAXPARSER = "ER_STARTPARSE_NEEDS_SAXPARSER";
101: public static final String ER_COULD_NOT_INIT_PARSER = "ER_COULD_NOT_INIT_PARSER";
102: public static final String ER_EXCEPTION_CREATING_POOL = "ER_EXCEPTION_CREATING_POOL";
103: public static final String ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE = "ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE";
104: public static final String ER_SCHEME_REQUIRED = "ER_SCHEME_REQUIRED";
105: public static final String ER_NO_SCHEME_IN_URI = "ER_NO_SCHEME_IN_URI";
106: public static final String ER_NO_SCHEME_INURI = "ER_NO_SCHEME_INURI";
107: public static final String ER_PATH_INVALID_CHAR = "ER_PATH_INVALID_CHAR";
108: public static final String ER_SCHEME_FROM_NULL_STRING = "ER_SCHEME_FROM_NULL_STRING";
109: public static final String ER_SCHEME_NOT_CONFORMANT = "ER_SCHEME_NOT_CONFORMANT";
110: public static final String ER_HOST_ADDRESS_NOT_WELLFORMED = "ER_HOST_ADDRESS_NOT_WELLFORMED";
111: public static final String ER_PORT_WHEN_HOST_NULL = "ER_PORT_WHEN_HOST_NULL";
112: public static final String ER_INVALID_PORT = "ER_INVALID_PORT";
113: public static final String ER_FRAG_FOR_GENERIC_URI = "ER_FRAG_FOR_GENERIC_URI";
114: public static final String ER_FRAG_WHEN_PATH_NULL = "ER_FRAG_WHEN_PATH_NULL";
115: public static final String ER_FRAG_INVALID_CHAR = "ER_FRAG_INVALID_CHAR";
116: public static final String ER_PARSER_IN_USE = "ER_PARSER_IN_USE";
117: public static final String ER_CANNOT_CHANGE_WHILE_PARSING = "ER_CANNOT_CHANGE_WHILE_PARSING";
118: public static final String ER_SELF_CAUSATION_NOT_PERMITTED = "ER_SELF_CAUSATION_NOT_PERMITTED";
119: public static final String ER_NO_USERINFO_IF_NO_HOST = "ER_NO_USERINFO_IF_NO_HOST";
120: public static final String ER_NO_PORT_IF_NO_HOST = "ER_NO_PORT_IF_NO_HOST";
121: public static final String ER_NO_QUERY_STRING_IN_PATH = "ER_NO_QUERY_STRING_IN_PATH";
122: public static final String ER_NO_FRAGMENT_STRING_IN_PATH = "ER_NO_FRAGMENT_STRING_IN_PATH";
123: public static final String ER_CANNOT_INIT_URI_EMPTY_PARMS = "ER_CANNOT_INIT_URI_EMPTY_PARMS";
124: public static final String ER_METHOD_NOT_SUPPORTED = "ER_METHOD_NOT_SUPPORTED";
125: public static final String ER_INCRSAXSRCFILTER_NOT_RESTARTABLE = "ER_INCRSAXSRCFILTER_NOT_RESTARTABLE";
126: public static final String ER_XMLRDR_NOT_BEFORE_STARTPARSE = "ER_XMLRDR_NOT_BEFORE_STARTPARSE";
127: public static final String ER_AXIS_TRAVERSER_NOT_SUPPORTED = "ER_AXIS_TRAVERSER_NOT_SUPPORTED";
128: public static final String ER_ERRORHANDLER_CREATED_WITH_NULL_PRINTWRITER = "ER_ERRORHANDLER_CREATED_WITH_NULL_PRINTWRITER";
129: public static final String ER_SYSTEMID_UNKNOWN = "ER_SYSTEMID_UNKNOWN";
130: public static final String ER_LOCATION_UNKNOWN = "ER_LOCATION_UNKNOWN";
131: public static final String ER_PREFIX_MUST_RESOLVE = "ER_PREFIX_MUST_RESOLVE";
132: public static final String ER_CREATEDOCUMENT_NOT_SUPPORTED = "ER_CREATEDOCUMENT_NOT_SUPPORTED";
133: public static final String ER_CHILD_HAS_NO_OWNER_DOCUMENT = "ER_CHILD_HAS_NO_OWNER_DOCUMENT";
134: public static final String ER_CHILD_HAS_NO_OWNER_DOCUMENT_ELEMENT = "ER_CHILD_HAS_NO_OWNER_DOCUMENT_ELEMENT";
135: public static final String ER_CANT_OUTPUT_TEXT_BEFORE_DOC = "ER_CANT_OUTPUT_TEXT_BEFORE_DOC";
136: public static final String ER_CANT_HAVE_MORE_THAN_ONE_ROOT = "ER_CANT_HAVE_MORE_THAN_ONE_ROOT";
137: public static final String ER_ARG_LOCALNAME_NULL = "ER_ARG_LOCALNAME_NULL";
138: public static final String ER_ARG_LOCALNAME_INVALID = "ER_ARG_LOCALNAME_INVALID";
139: public static final String ER_ARG_PREFIX_INVALID = "ER_ARG_PREFIX_INVALID";
140: public static final String ER_NAME_CANT_START_WITH_COLON = "ER_NAME_CANT_START_WITH_COLON";
141:
142: /*
143: * Now fill in the message text.
144: * Then fill in the message text for that message code in the
145: * array. Use the new error code as the index into the array.
146: */
147:
148: // Error messages...
149: /**
150: * Get the lookup table for error messages
151: *
152: * @return The association list.
153: */
154: public Object[][] getContents() {
155: return new Object[][] {
156:
157: /** Error message ID that has a null message, but takes in a single object. */
158: { "ER0000", "{0}" },
159:
160: { ER_FUNCTION_NOT_SUPPORTED, "Function not supported!" },
161:
162: { ER_CANNOT_OVERWRITE_CAUSE, "Cannot overwrite cause" },
163:
164: { ER_NO_DEFAULT_IMPL,
165: "No default implementation found " },
166:
167: { ER_CHUNKEDINTARRAY_NOT_SUPPORTED,
168: "ChunkedIntArray({0}) not currently supported" },
169:
170: { ER_OFFSET_BIGGER_THAN_SLOT, "Offset bigger than slot" },
171:
172: { ER_COROUTINE_NOT_AVAIL,
173: "Coroutine not available, id={0}" },
174:
175: { ER_COROUTINE_CO_EXIT,
176: "CoroutineManager received co_exit() request" },
177:
178: { ER_COJOINROUTINESET_FAILED,
179: "co_joinCoroutineSet() failed" },
180:
181: { ER_COROUTINE_PARAM, "Coroutine parameter error ({0})" },
182:
183: { ER_PARSER_DOTERMINATE_ANSWERS,
184: "\nUNEXPECTED: Parser doTerminate answers {0}" },
185:
186: { ER_NO_PARSE_CALL_WHILE_PARSING,
187: "parse may not be called while parsing" },
188:
189: { ER_TYPED_ITERATOR_AXIS_NOT_IMPLEMENTED,
190: "Error: typed iterator for axis {0} not implemented" },
191:
192: { ER_ITERATOR_AXIS_NOT_IMPLEMENTED,
193: "Error: iterator for axis {0} not implemented " },
194:
195: { ER_ITERATOR_CLONE_NOT_SUPPORTED,
196: "Iterator clone not supported" },
197:
198: { ER_UNKNOWN_AXIS_TYPE,
199: "Unknown axis traversal type: {0}" },
200:
201: { ER_AXIS_NOT_SUPPORTED,
202: "Axis traverser not supported: {0}" },
203:
204: { ER_NO_DTMIDS_AVAIL, "No more DTM IDs are available" },
205:
206: { ER_NOT_SUPPORTED, "Not supported: {0}" },
207:
208: { ER_NODE_NON_NULL,
209: "Node must be non-null for getDTMHandleFromNode" },
210:
211: { ER_COULD_NOT_RESOLVE_NODE,
212: "Could not resolve the node to a handle" },
213:
214: { ER_STARTPARSE_WHILE_PARSING,
215: "startParse may not be called while parsing" },
216:
217: { ER_STARTPARSE_NEEDS_SAXPARSER,
218: "startParse needs a non-null SAXParser" },
219:
220: { ER_COULD_NOT_INIT_PARSER,
221: "could not initialize parser with" },
222:
223: { ER_EXCEPTION_CREATING_POOL,
224: "exception creating new instance for pool" },
225:
226: { ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE,
227: "Path contains invalid escape sequence" },
228:
229: { ER_SCHEME_REQUIRED, "Scheme is required!" },
230:
231: { ER_NO_SCHEME_IN_URI, "No scheme found in URI: {0}" },
232:
233: { ER_NO_SCHEME_INURI, "No scheme found in URI" },
234:
235: { ER_PATH_INVALID_CHAR,
236: "Path contains invalid character: {0}" },
237:
238: { ER_SCHEME_FROM_NULL_STRING,
239: "Cannot set scheme from null string" },
240:
241: { ER_SCHEME_NOT_CONFORMANT,
242: "The scheme is not conformant." },
243:
244: { ER_HOST_ADDRESS_NOT_WELLFORMED,
245: "Host is not a well formed address" },
246:
247: { ER_PORT_WHEN_HOST_NULL,
248: "Port cannot be set when host is null" },
249:
250: { ER_INVALID_PORT, "Invalid port number" },
251:
252: { ER_FRAG_FOR_GENERIC_URI,
253: "Fragment can only be set for a generic URI" },
254:
255: { ER_FRAG_WHEN_PATH_NULL,
256: "Fragment cannot be set when path is null" },
257:
258: { ER_FRAG_INVALID_CHAR,
259: "Fragment contains invalid character" },
260:
261: { ER_PARSER_IN_USE, "Parser is already in use" },
262:
263: { ER_CANNOT_CHANGE_WHILE_PARSING,
264: "Cannot change {0} {1} while parsing" },
265:
266: { ER_SELF_CAUSATION_NOT_PERMITTED,
267: "Self-causation not permitted" },
268:
269: { ER_NO_USERINFO_IF_NO_HOST,
270: "Userinfo may not be specified if host is not specified" },
271:
272: { ER_NO_PORT_IF_NO_HOST,
273: "Port may not be specified if host is not specified" },
274:
275: { ER_NO_QUERY_STRING_IN_PATH,
276: "Query string cannot be specified in path and query string" },
277:
278: { ER_NO_FRAGMENT_STRING_IN_PATH,
279: "Fragment cannot be specified in both the path and fragment" },
280:
281: { ER_CANNOT_INIT_URI_EMPTY_PARMS,
282: "Cannot initialize URI with empty parameters" },
283:
284: { ER_METHOD_NOT_SUPPORTED, "Method not yet supported " },
285:
286: { ER_INCRSAXSRCFILTER_NOT_RESTARTABLE,
287: "IncrementalSAXSource_Filter not currently restartable" },
288:
289: { ER_XMLRDR_NOT_BEFORE_STARTPARSE,
290: "XMLReader not before startParse request" },
291:
292: { ER_AXIS_TRAVERSER_NOT_SUPPORTED,
293: "Axis traverser not supported: {0}" },
294:
295: { ER_ERRORHANDLER_CREATED_WITH_NULL_PRINTWRITER,
296: "ListingErrorHandler created with null PrintWriter!" },
297:
298: { ER_SYSTEMID_UNKNOWN, "SystemId Unknown" },
299:
300: { ER_LOCATION_UNKNOWN, "Location of error unknown" },
301:
302: { ER_PREFIX_MUST_RESOLVE,
303: "Prefix must resolve to a namespace: {0}" },
304:
305: { ER_CREATEDOCUMENT_NOT_SUPPORTED,
306: "createDocument() not supported in XPathContext!" },
307:
308: { ER_CHILD_HAS_NO_OWNER_DOCUMENT,
309: "Attribute child does not have an owner document!" },
310:
311: { ER_CHILD_HAS_NO_OWNER_DOCUMENT_ELEMENT,
312: "Attribute child does not have an owner document element!" },
313:
314: { ER_CANT_OUTPUT_TEXT_BEFORE_DOC,
315: "Warning: can't output text before document element! Ignoring..." },
316:
317: { ER_CANT_HAVE_MORE_THAN_ONE_ROOT,
318: "Can't have more than one root on a DOM!" },
319:
320: { ER_ARG_LOCALNAME_NULL, "Argument 'localName' is null" },
321:
322: // Note to translators: A QNAME has the syntactic form [NCName:]NCName
323: // The localname is the portion after the optional colon; the message indicates
324: // that there is a problem with that part of the QNAME.
325: { ER_ARG_LOCALNAME_INVALID,
326: "Localname in QNAME should be a valid NCName" },
327:
328: // Note to translators: A QNAME has the syntactic form [NCName:]NCName
329: // The prefix is the portion before the optional colon; the message indicates
330: // that there is a problem with that part of the QNAME.
331: { ER_ARG_PREFIX_INVALID,
332: "Prefix in QNAME should be a valid NCName" },
333:
334: { ER_NAME_CANT_START_WITH_COLON,
335: "Name cannot start with a colon" },
336:
337: { "BAD_CODE",
338: "Parameter to createMessage was out of bounds" },
339: { "FORMAT_FAILED",
340: "Exception thrown during messageFormat call" },
341: { "line", "Line #" }, { "column", "Column #" }
342:
343: };
344: }
345:
346: /**
347: * Return a named ResourceBundle for a particular locale. This method mimics the behavior
348: * of ResourceBundle.getBundle().
349: *
350: * @param className the name of the class that implements the resource bundle.
351: * @return the ResourceBundle
352: * @throws MissingResourceException
353: */
354: public static final XMLErrorResources loadResourceBundle(
355: String className) throws MissingResourceException {
356:
357: Locale locale = Locale.getDefault();
358: String suffix = getResourceSuffix(locale);
359:
360: try {
361:
362: // first try with the given locale
363: return (XMLErrorResources) ResourceBundle.getBundle(
364: className + suffix, locale);
365: } catch (MissingResourceException e) {
366: try // try to fall back to en_US if we can't load
367: {
368:
369: // Since we can't find the localized property file,
370: // fall back to en_US.
371: return (XMLErrorResources) ResourceBundle.getBundle(
372: className, new Locale("en", "US"));
373: } catch (MissingResourceException e2) {
374:
375: // Now we are really in trouble.
376: // very bad, definitely very bad...not going to get very far
377: throw new MissingResourceException(
378: "Could not load any resource bundles.",
379: className, "");
380: }
381: }
382: }
383:
384: /**
385: * Return the resource file suffic for the indicated locale
386: * For most locales, this will be based the language code. However
387: * for Chinese, we do distinguish between Taiwan and PRC
388: *
389: * @param locale the locale
390: * @return an String suffix which canbe appended to a resource name
391: */
392: private static final String getResourceSuffix(Locale locale) {
393:
394: String suffix = "_" + locale.getLanguage();
395: String country = locale.getCountry();
396:
397: if (country.equals("TW"))
398: suffix += "_" + country;
399:
400: return suffix;
401: }
402:
403: }
|