Changes to MGC class library and some missing unit test files for inner class
[IRC.git] / Robust / src / ClassLibrary / MGC / gnu / Formatter.java
1 /* Formatter.java --
2    A class for formatting log messages by localizing message texts
3    and performing substitution of parameters
4    Copyright (C) 2002, 2004 Free Software Foundation, Inc.
5
6 This file is part of GNU Classpath.
7
8 GNU Classpath is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU Classpath is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Classpath; see the file COPYING.  If not, write to the
20 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301 USA.
22
23 Linking this library statically or dynamically with other modules is
24 making a combined work based on this library.  Thus, the terms and
25 conditions of the GNU General Public License cover the whole
26 combination.
27
28 As a special exception, the copyright holders of this library give you
29 permission to link this library with independent modules to produce an
30 executable, regardless of the license terms of these independent
31 modules, and to copy and distribute the resulting executable under
32 terms of your choice, provided that you also meet, for each linked
33 independent module, the terms and conditions of the license of that
34 module.  An independent module is a module which is not derived from
35 or based on this library.  If you modify this library, you may extend
36 this exception to your version of the library, but you are not
37 obligated to do so.  If you do not wish to do so, delete this
38 exception statement from your version. */
39
40
41 package java.util.logging;
42
43 /**
44  * A <code>Formatter</code> supports handlers by localizing
45  * message texts and by subsituting parameter values for their
46  * placeholders.
47  *
48  * @author Sascha Brawer (brawer@acm.org)
49  */
50 public abstract class Formatter
51 {
52   /**
53    * Constructs a new Formatter.
54    */
55   protected Formatter()
56   {
57   }
58
59
60   /**
61    * Formats a LogRecord into a string.  Usually called by handlers
62    * which need a string for a log record, for example to append
63    * a record to a log file or to transmit a record over the network.
64    *
65    * @param record the log record for which a string form is requested.
66    */
67   public abstract String format(LogRecord record);
68
69
70   /**
71    * Returns a string that handlers are supposed to emit before
72    * the first log record.  The base implementation returns an
73    * empty string, but subclasses such as {@link XMLFormatter}
74    * override this method in order to provide a suitable header.
75    *
76    * @return a string for the header.
77    *
78    * @param handler the handler which will prepend the returned
79    *     string in front of the first log record.  This method
80    *     may inspect certain properties of the handler, for
81    *     example its encoding, in order to construct the header.
82    */
83   public String getHead(Handler handler)
84   {
85     return "";
86   }
87
88
89   /**
90    * Returns a string that handlers are supposed to emit after
91    * the last log record.  The base implementation returns an
92    * empty string, but subclasses such as {@link XMLFormatter}
93    * override this method in order to provide a suitable tail.
94    *
95    * @return a string for the header.
96    *
97    * @param handler the handler which will append the returned
98    *     string after the last log record.  This method
99    *     may inspect certain properties of the handler
100    *     in order to construct the tail.
101    */
102   public String getTail(Handler handler)
103   {
104     return "";
105   }
106
107
108   /**
109    * Formats the message part of a log record.
110    *
111    * <p>First, the Formatter localizes the record message to the
112    * default locale by looking up the message in the record's
113    * localization resource bundle.  If this step fails because there
114    * is no resource bundle associated with the record, or because the
115    * record message is not a key in the bundle, the raw message is
116    * used instead.
117    *
118    * <p>Second, the Formatter substitutes appropriate strings for
119    * the message parameters. If the record returns a non-empty
120    * array for <code>getParameters()</code> and the localized
121    * message string contains the character sequence "{0", the
122    * formatter uses <code>java.text.MessageFormat</code> to format
123    * the message.  Otherwise, no parameter substitution is performed.
124    *
125    * @param record the log record to be localized and formatted.
126    *
127    * @return the localized message text where parameters have been
128    *         substituted by suitable strings.
129    *
130    * @throws NullPointerException if <code>record</code>
131    *         is <code>null</code>.
132    */
133   /*public String formatMessage(LogRecord record)
134   {
135     String          msg;
136     ResourceBundle  bundle;
137     Object[]        params;
138
139     /* This will throw a NullPointerExceptionif record is null. */
140     /*msg = record.getMessage();
141     if (msg == null)
142       msg = "";
143
144     /* Try to localize the message. */
145     /*bundle = record.getResourceBundle();
146     if (bundle != null)
147     {
148       try
149       {
150         msg = bundle.getString(msg);
151       }
152       catch (java.util.MissingResourceException _)
153       {
154       }
155     }
156
157     /* Format the message if there are parameters. */
158     /*params = record.getParameters();
159     if ((params != null)
160         && (params.length > 0)
161         && (msg.indexOf("{0") >= 0))
162     {
163       msg = MessageFormat.format(msg, params);
164     }
165
166     return msg;
167   }*/
168 }