001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 8, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.jfreereport.wizard.messages;
018:
019: import java.util.Collections;
020: import java.util.HashMap;
021: import java.util.Locale;
022: import java.util.Map;
023: import java.util.MissingResourceException;
024: import java.util.ResourceBundle;
025: import org.pentaho.messages.MessageUtil;
026: import org.pentaho.messages.util.LocaleHelper;
027:
028: /**
029: * @author James Dixon
030: *
031: * TODO To change the template for this generated type comment go to
032: * Window - Preferences - Java - Code Style - Code Templates
033: */
034: public class Messages {
035: private static final String BUNDLE_NAME = "org.pentaho.jfreereport.wizard.messages.messages";//$NON-NLS-1$
036: private static final Map locales = Collections
037: .synchronizedMap(new HashMap());
038:
039: protected static Map getLocales() {
040: return locales;
041: }
042:
043: public static ResourceBundle getBundle() {
044: Locale locale = LocaleHelper.getLocale();
045: ResourceBundle bundle = (ResourceBundle) locales.get(locale);
046: if (bundle == null) {
047: bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
048: locales.put(locale, bundle);
049: }
050: return bundle;
051: }
052:
053: public static String getEncodedString(String rawValue) {
054: StringBuffer value = new StringBuffer();
055: for (int n = 0; n < rawValue.length(); n++) {
056: int charValue = rawValue.charAt(n);
057: if (charValue >= 0x80) {
058: value.append("&#x"); //$NON-NLS-1$
059: value.append(Integer.toString(charValue, 0x10));
060: value.append(";"); //$NON-NLS-1$
061: } else {
062: value.append((char) charValue);
063: }
064: }
065: return value.toString();
066:
067: }
068:
069: public static String getString(String key) {
070: try {
071: return getBundle().getString(key);
072: } catch (MissingResourceException e) {
073: return '!' + key + '!';
074: }
075: }
076:
077: public static String getString(String key, String param1) {
078: return MessageUtil.getString(getBundle(), key, param1);
079: }
080:
081: public static String getString(String key, String param1,
082: String param2) {
083: return MessageUtil.getString(getBundle(), key, param1, param2);
084: }
085:
086: public static String getString(String key, String param1,
087: String param2, String param3) {
088: return MessageUtil.getString(getBundle(), key, param1, param2,
089: param3);
090: }
091:
092: public static String getErrorString(String key) {
093: return MessageUtil.formatErrorMessage(key, getString(key));
094: }
095:
096: public static String getErrorString(String key, String param1) {
097: return MessageUtil.getErrorString(getBundle(), key, param1);
098: }
099:
100: public static String getErrorString(String key, String param1,
101: String param2) {
102: return MessageUtil.getErrorString(getBundle(), key, param1,
103: param2);
104: }
105:
106: public static String getErrorString(String key, String param1,
107: String param2, String param3) {
108: return MessageUtil.getErrorString(getBundle(), key, param1,
109: param2, param3);
110: }
111:
112: }
|