1 57 package org.enhydra.apache.xerces.utils; 58 59 import java.util.ListResourceBundle ; 60 import java.util.Locale ; 61 import java.util.ResourceBundle ; 62 63 68 public class ImplementationMessages implements XMLMessageProvider { 69 72 public static final String XERCES_IMPLEMENTATION_DOMAIN = "http://www.apache.org/xml/xerces.html"; 73 74 77 public void setLocale(Locale locale) { 78 fLocale = locale; 79 } 80 83 public Locale getLocale() { 84 return fLocale; 85 } 86 87 97 public String createMessage(Locale locale, int majorCode, int minorCode, Object args[]) { 98 boolean throwex = false; 99 if (fResourceBundle == null || locale != fLocale) { 100 if (locale != null) 101 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.ImplementationMessages", locale); 102 if (fResourceBundle == null) 103 fResourceBundle = ListResourceBundle.getBundle("org.enhydra.apache.xerces.msg.ImplementationMessages"); 104 } 105 if (majorCode < 0 || majorCode >= fgMessageKeys.length - 1) { 106 majorCode = BAD_MAJORCODE; 107 throwex = true; 108 } 109 String msgKey = fgMessageKeys[majorCode]; 110 String msg = fResourceBundle.getString(msgKey); 111 if (args != null) { 112 try { 113 msg = java.text.MessageFormat.format(msg, args); 114 } catch (Exception e) { 115 msg = fResourceBundle.getString(fgMessageKeys[FORMAT_FAILED]); 116 msg += " " + fResourceBundle.getString(msgKey); 117 } 118 } 119 if (throwex) { 120 throw new RuntimeException (msg); 121 } 122 return msg; 123 } 124 private Locale fLocale = null; 128 private ResourceBundle fResourceBundle = null; 129 public static final int 133 BAD_MAJORCODE = 0, ENC4 = 1, ENC5 = 2, ENC6 = 3, ENC7 = 4, IO0 = 5, VAL_BST = 6, VAL_CMSI = 7, VAL_CST = 8, VAL_LST = 9, VAL_NIICM = 10, VAL_NPCD = 11, VAL_UST = 12, VAL_WCGHI = 13, INT_DCN = 14, INT_PCN = 15, FATAL_ERROR = 16, 151 FORMAT_FAILED = 17; 156 private static final String [] fgMessageKeys = { 160 "BadMajorCode", "ENC4", "ENC5", "ENC6", "ENC7", "FileNotFound", "VAL_BST", "VAL_CMSI", "VAL_CST", "VAL_LST", "VAL_NIICM", "VAL_NPCD", "VAL_UST", "VAL_WCGHI", "INT_DCN", "INT_PCN", "FatalError", 178 "FormatFailed", null 183 }; 184 } 185 | Popular Tags |