KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > xml > SimpleSyslogTextFormatter_Helper


1 package com.protomatter.syslog.xml;
2
3 /**
4  * {{{ The Protomatter Software License, Version 1.0
5  * derived from The Apache Software License, Version 1.1
6  *
7  * Copyright (c) 1998-2002 Nate Sammons. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed for the
24  * Protomatter Software Project
25  * (http://protomatter.sourceforge.net/)."
26  * Alternately, this acknowledgment may appear in the software itself,
27  * if and wherever such third-party acknowledgments normally appear.
28  *
29  * 4. The names "Protomatter" and "Protomatter Software Project" must
30  * not be used to endorse or promote products derived from this
31  * software without prior written permission. For written
32  * permission, please contact support@protomatter.com.
33  *
34  * 5. Products derived from this software may not be called "Protomatter",
35  * nor may "Protomatter" appear in their name, without prior written
36  * permission of the Protomatter Software Project
37  * (support@protomatter.com).
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE PROTOMATTER SOFTWARE PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE. }}}
51  */

52
53 import java.io.PrintWriter JavaDoc;
54 import java.util.*;
55 import java.text.*;
56 import java.net.*;
57 import java.io.*;
58 import java.lang.reflect.*;
59
60 import org.jdom.*;
61
62 import com.protomatter.xml.*;
63 import com.protomatter.syslog.*;
64
65 /**
66  * XML configuration helper for <tt>SimpleSyslogTextFormatter</tt>.
67  */

68 public class SimpleSyslogTextFormatter_Helper
69 implements XMLConfigHelper
70 {
71   /**
72    * Configure this text formatter given the XML element.
73    * The <tt>&lt;Format&gt;</tt> element should look like this:<P>
74    *
75    * <TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 WIDTH="90%">
76    * <TR><TD>
77    * <PRE><B>
78    *
79    * &lt;Format class="com.protomatter.syslog.SimpleSyslogTextFormatter" &gt;
80    *
81    * &lt;showCaller&gt;<i>true|false</i>&lt;/showCaller&gt;
82    * &lt;showChannel&gt;<i>true|false</i>&lt;/showChannel&gt;
83    * &lt;showThreadName&gt;<i>true|false</i>&lt;/showThreadName&gt;
84    * &lt;showHostName&gt;<i>true|false</i>&lt;/showHostName&gt;
85    * &lt;dateFormat&gt;<i>DateFormat</i>&lt;/dateFormat&gt;
86    * &lt;dateFormatTimeZone&gt;<i>TimeZoneName</i>&lt;/dateFormatTimeZone&gt;
87    * &lt;dateFormatCacheTime&gt;<i>CacheTimeout</i>&lt;/dateFormatCacheTime&gt;
88    *
89    * &lt;classWidth&gt;<i>field-width</i>&lt;/classWidth&gt;
90    * &lt;channelWidth&gt;<i>field-width</i>&lt;/channelWidth&gt;
91    * &lt;threadWidth&gt;<i>field-width</i>&lt;/threadWidth&gt;
92    * &lt;hostWidth&gt;<i>field-width</i>&lt;/hostWidth&gt;
93    *
94    * &lt;/Format&gt;
95    * </B></PRE>
96    * </TD></TR></TABLE><P>
97    *
98    * <TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 WIDTH="90%">
99    * <TR CLASS="TableHeadingColor">
100    * <TD COLSPAN=3><B>Element</B></TD>
101    * </TR>
102    * <TR CLASS="TableHeadingColor">
103    * <TD><B>name</B></TD>
104    * <TD><B>value</B></TD>
105    * <TD><B>required</B></TD>
106    * </TR>
107    *
108    * <TR CLASS="TableRowColor">
109    * <TD VALIGN=TOP><TT>showCaller</TT></TD>
110    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the caller
111    * name should appear in the log.
112    * </TD>
113    * <TD VALIGN=TOP>no (default is <tt>true</tt>)</TD>
114    * </TR>
115    *
116    * <TR CLASS="TableRowColor">
117    * <TD VALIGN=TOP><TT>showChannel</TT></TD>
118    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the channel
119    * name should appear in the log.
120    * </TD>
121    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
122    * </TR>
123    *
124    * <TR CLASS="TableRowColor">
125    * <TD VALIGN=TOP><TT>showThreadName</TT></TD>
126    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the thread
127    * name should appear in the log.
128    * </TD>
129    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
130    * </TR>
131    *
132    * <TR CLASS="TableRowColor">
133    * <TD VALIGN=TOP><TT>showHostName</TT></TD>
134    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the host name
135    * name should appear in the log.
136    * </TD>
137    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
138    * </TR>
139    *
140    * <TR CLASS="TableRowColor">
141    * <TD VALIGN=TOP><TT>dateFormat</TT></TD>
142    * <TD>A date format that can be understood by the
143    * <tt>java.text.SimpleDateFormat</tt> format class.
144    * </TD>
145    * <TD VALIGN=TOP>no (default is "<tt>HH:mm:ss MM/dd</tt>")</TD>
146    * </TR>
147    *
148    * <TR CLASS="TableRowColor">
149    * <TD VALIGN=TOP><TT>dateFormatTimeZone</TT></TD>
150    * <TD>The name of the timezone to use for formatting timestamps.
151    * </TD>
152    * <TD VALIGN=TOP>no (default is the current time zone)</TD>
153    * </TR>
154    *
155    * <TR CLASS="TableRowColor">
156    * <TD VALIGN=TOP><TT>dateFormatCacheTime</TT></TD>
157    * <TD>How long (in milliseconds) to cache a created timestamp formatting object
158    * </TD>
159    * <TD VALIGN=TOP>no (default is <tt>1000</tt>)</TD>
160    * </TR>
161    *
162    * <TR CLASS="TableRowColor">
163    * <TD VALIGN=TOP><TT>classWidth</TT></TD>
164    * <TD>Field width in characters for the class section.
165    * </TD>
166    * <TD VALIGN=TOP>no (default is <tt>20</tt>)</TD>
167    * </TR>
168    *
169    * <TR CLASS="TableRowColor">
170    * <TD VALIGN=TOP><TT>channelWidth</TT></TD>
171    * <TD>Field width in characters for the channel section.
172    * </TD>
173    * <TD VALIGN=TOP>no (default is <tt>15</tt>)</TD>
174    * </TR>
175    *
176    * <TR CLASS="TableRowColor">
177    * <TD VALIGN=TOP><TT>hostWidth</TT></TD>
178    * <TD>Field width in characters for the host name section.
179    * </TD>
180    * <TD VALIGN=TOP>no (default is <tt>15</tt>)</TD>
181    * </TR>
182    *
183    * <TR CLASS="TableRowColor">
184    * <TD VALIGN=TOP><TT>threadWidth</TT></TD>
185    * <TD>Field width in characters for the thread name section.
186    * </TD>
187    * <TD VALIGN=TOP>no (default is <tt>15</tt>)</TD>
188    * </TR>
189    *
190    * </TABLE><P>
191    */

192   public void configure(Object JavaDoc o, Element e)
193   throws SyslogInitException
194   {
195     SimpleSyslogTextFormatter format = (SimpleSyslogTextFormatter)o;
196
197     String JavaDoc tmp = e.getChildTextTrim("showChannel", e.getNamespace());
198     if (tmp != null)
199         format.setShowChannel("true".equalsIgnoreCase(tmp));
200
201     tmp = e.getChildTextTrim("showCaller", e.getNamespace());
202     if (tmp != null)
203         format.setShowCaller("true".equalsIgnoreCase(tmp));
204
205     tmp = e.getChildTextTrim("showThreadName", e.getNamespace());
206     if (tmp != null)
207         format.setShowThreadName("true".equalsIgnoreCase(tmp));
208
209     tmp = e.getChildTextTrim("showHostName", e.getNamespace());
210     if (tmp != null)
211         format.setShowHostName("true".equalsIgnoreCase(tmp));
212
213     tmp = e.getChildTextTrim("dateFormat", e.getNamespace());
214     if (tmp != null)
215       format.setDateFormat(tmp);
216
217     tmp = e.getChildTextTrim("dateFormatTimeZone", e.getNamespace());
218     if (tmp != null)
219       format.setDateFormatTimezone(TimeZone.getTimeZone(tmp));
220
221     tmp = e.getChildTextTrim("dateFormatCacheTime", e.getNamespace());
222     if (tmp != null)
223       format.setDateFormatCacheTime(Integer.parseInt(tmp));
224
225     tmp = e.getChildTextTrim("classWidth", e.getNamespace());
226     if (tmp != null)
227       format.setClassWidth(Integer.parseInt(tmp));
228
229     tmp = e.getChildTextTrim("channelWidth", e.getNamespace());
230     if (tmp != null)
231       format.setChannelWidth(Integer.parseInt(tmp));
232
233     tmp = e.getChildTextTrim("hostWidth", e.getNamespace());
234     if (tmp != null)
235       format.setHostWidth(Integer.parseInt(tmp));
236
237     tmp = e.getChildTextTrim("threadWidth", e.getNamespace());
238     if (tmp != null)
239       format.setThreadWidth(Integer.parseInt(tmp));
240
241   }
242
243   public Element getConfiguration(Object JavaDoc o, Element element)
244   {
245     SimpleSyslogTextFormatter format = (SimpleSyslogTextFormatter)o;
246
247     Element sc = new Element("showChannel");
248     sc.setText(String.valueOf(format.getShowChannel()));
249     element.getChildren().add(sc);
250
251     Element st = new Element("showThreadName");
252     st.setText(String.valueOf(format.getShowThreadName()));
253     element.getChildren().add(st);
254
255     Element sh = new Element("showHostName");
256     sh.setText(String.valueOf(format.getShowHostName()));
257     element.getChildren().add(sh);
258
259     Element df = new Element("dateFormat");
260     df.setText(String.valueOf(format.getDateFormat()));
261     element.getChildren().add(df);
262
263     Element dfc = new Element("dateFormatCacheTime");
264     dfc.setText(String.valueOf(format.getDateFormatCacheTime()));
265     element.getChildren().add(dfc);
266
267     Element tz = new Element("dateFormatTimeZone");
268     tz.setText(String.valueOf(format.getDateFormatTimezone().getID()));
269     element.getChildren().add(tz);
270
271     Element cw = new Element("classWidth");
272     cw.setText(String.valueOf(format.getClassWidth()));
273     element.getChildren().add(cw);
274
275     Element chw = new Element("channelWidth");
276     chw.setText(String.valueOf(format.getChannelWidth()));
277     element.getChildren().add(chw);
278
279     Element tw = new Element("threadWidth");
280     tw.setText(String.valueOf(format.getThreadWidth()));
281     element.getChildren().add(tw);
282
283     Element hw = new Element("hostWidth");
284     hw.setText(String.valueOf(format.getHostWidth()));
285     element.getChildren().add(hw);
286
287     return element;
288   }
289 }
290
Popular Tags