001: /**
002: * $Id: PEAUtil.java,v 1.2 2003/12/19 22:46:36 jtb Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wsrp.consumer.cli;
014:
015: import java.util.Map;
016: import java.util.Set;
017: import java.util.Iterator;
018: import java.util.Locale;
019: import java.util.ResourceBundle;
020: import java.util.PropertyResourceBundle;
021: import java.util.StringTokenizer;
022: import java.text.MessageFormat;
023:
024: import java.io.Reader;
025: import java.io.BufferedReader;
026: import java.io.IOException;
027:
028: class PEAUtil {
029:
030: public static final String RESOURCE_BASE = "wsrpPEA";
031: public static ResourceBundle rb = PropertyResourceBundle.getBundle(
032: RESOURCE_BASE, Locale.getDefault());
033:
034: public static final int CONTEXT_LINE_NUM = 5;
035:
036: public static void setLocale(java.util.Locale locale) {
037: //
038: // load resource bundle based on locale
039: //
040: rb = PropertyResourceBundle.getBundle(RESOURCE_BASE, locale);
041: }
042:
043: public static String getLocalizedString(String key) {
044: return rb.getString(key);
045: }
046:
047: public static String getLocalizedString(String key, Object[] objs) {
048:
049: if (objs != null && objs.length > 0) {
050: MessageFormat mf = new MessageFormat("");
051: mf.setLocale(rb.getLocale());
052: mf.applyPattern(rb.getString(key));
053: return mf.format(objs);
054: } else {
055: return rb.getString(key);
056: }
057: }
058:
059: public static void debug(String key) {
060:
061: debug(key, null);
062: }
063:
064: public static void debug(String key, Object[] tokens) {
065:
066: String msg = getLocalizedString(key, tokens);
067: Object[] toks = { msg };
068: System.err.println(getLocalizedString("msgDebug", toks));
069: }
070:
071: public static void warning(String key) {
072:
073: warning(key, null);
074: }
075:
076: public static void warning(String key, Object[] tokens) {
077:
078: String msg = getLocalizedString(key, tokens);
079: Object[] toks = { msg };
080: System.err.println(getLocalizedString("msgWarning", toks));
081: }
082:
083: public static void error(String key) {
084:
085: error(key, null);
086: }
087:
088: public static void error(String key, Object[] tokens) {
089:
090: String msg = getLocalizedString(key, tokens);
091: Object[] toks = { msg };
092: System.err.println(getLocalizedString("msgError", toks));
093: }
094:
095: public static String getLines(Reader reader, int linenum) {
096: StringBuffer buf = new StringBuffer();
097: String line = null;
098: BufferedReader br = new BufferedReader(reader);
099:
100: try {
101: int i = 1;
102: int beg = linenum - CONTEXT_LINE_NUM;
103: int end = linenum + CONTEXT_LINE_NUM;
104: buf.append("\n");
105: while ((line = br.readLine()) != null) {
106: if (i == linenum) {
107: buf.append("(*)").append(line).append("\n");
108: } else if (i >= beg && i <= end) {
109: buf.append(" ").append(line).append("\n");
110: }
111: ++i;
112: }
113: buf.append("\n");
114: } catch (IOException ioe) {
115: return "";
116: }
117: return buf.toString();
118: }
119: }
|