KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > xml > SimpleSyslogMailSubjectFormatter_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.*;
54 import java.net.*;
55 import java.util.*;
56 import java.text.*;
57
58 import com.protomatter.xml.*;
59 import com.protomatter.syslog.*;
60 import org.jdom.*;
61
62 /**
63  * XML configuration helper for <tt>SimpleSyslogMailSubjectFormatter</tt>.
64  */

65 public class SimpleSyslogMailSubjectFormatter_Helper
66 extends BasicLogger_Helper
67 {
68   /**
69    * Configure this text formatter given the XML element.
70    * The <tt>&lt;SubjectFormat&gt;</tt> element should look like this:<P>
71    *
72    * <TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 WIDTH="90%">
73    * <TR><TD>
74    * <PRE><B>
75    *
76    * &lt;SubjectFormat class="com.protomatter.syslog.SimpleSyslogMailSubjectFormatter" &gt;
77    *
78    * &lt;showCaller&gt;<i>true|false</i>&lt;/showCaller&gt;
79    * &lt;showChannel&gt;<i>true|false</i>&lt;/showChannel&gt;
80    * &lt;showThreadName&gt;<i>true|false</i>&lt;/showThreadName&gt;
81    * &lt;showHostName&gt;<i>true|false</i>&lt;/showHostName&gt;
82    *
83    * &lt;/SubjectFormat&gt;
84    * </B></PRE>
85    * </TD></TR></TABLE><P>
86    *
87    * <TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 WIDTH="90%">
88    * <TR CLASS="TableHeadingColor">
89    * <TD COLSPAN=3><B>Element</B></TD>
90    * </TR>
91    * <TR CLASS="TableHeadingColor">
92    * <TD><B>name</B></TD>
93    * <TD><B>value</B></TD>
94    * <TD><B>required</B></TD>
95    * </TR>
96    *
97    * <TR CLASS="TableRowColor">
98    * <TD VALIGN=TOP><TT>showCaller</TT></TD>
99    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the caller
100    * name should appear in the log.
101    * </TD>
102    * <TD VALIGN=TOP>no (default is <tt>true</tt>)</TD>
103    * </TR>
104    *
105    * <TR CLASS="TableRowColor">
106    * <TD VALIGN=TOP><TT>showChannel</TT></TD>
107    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the channel
108    * name should appear in the log.
109    * </TD>
110    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
111    * </TR>
112    *
113    * <TR CLASS="TableRowColor">
114    * <TD VALIGN=TOP><TT>showThreadName</TT></TD>
115    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the thread
116    * name should appear in the log.
117    * </TD>
118    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
119    * </TR>
120    *
121    * <TR CLASS="TableRowColor">
122    * <TD VALIGN=TOP><TT>showHostName</TT></TD>
123    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the host name
124    * name should appear in the log.
125    * </TD>
126    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
127    * </TR>
128    *
129    * </TABLE><P>
130    *
131    */

132   public void configure(Object JavaDoc o, Element e)
133   throws SyslogInitException
134   {
135     super.configure(o, e);
136     SimpleSyslogMailSubjectFormatter format = (SimpleSyslogMailSubjectFormatter)o;
137
138     String JavaDoc tmp = e.getChildTextTrim("showCaller", e.getNamespace());
139     if (tmp != null)
140         format.setShowCaller("true".equalsIgnoreCase(tmp));
141
142     tmp = e.getChildTextTrim("showChannel", e.getNamespace());
143     if (tmp != null)
144         format.setShowChannel("true".equalsIgnoreCase(tmp));
145
146     tmp = e.getChildTextTrim("showThreadName", e.getNamespace());
147     if (tmp != null)
148         format.setShowThreadName("true".equalsIgnoreCase(tmp));
149
150     tmp = e.getChildTextTrim("showHostName", e.getNamespace());
151     if (tmp != null)
152         format.setShowHostName("true".equalsIgnoreCase(tmp));
153   }
154
155   public Element getConfiguration(Object JavaDoc o, Element element)
156   {
157     Element e = super.getConfiguration(o, element);
158     SimpleSyslogMailSubjectFormatter format = (SimpleSyslogMailSubjectFormatter)o;
159
160     element.getChildren().add((new Element("showCaller")).
161       setText(String.valueOf(format.getShowCaller())));
162     element.getChildren().add((new Element("showChannel")).
163       setText(String.valueOf(format.getShowChannel())));
164     element.getChildren().add((new Element("showThreadName")).
165       setText(String.valueOf(format.getShowThreadName())));
166     element.getChildren().add((new Element("showHostName")).
167       setText(String.valueOf(format.getShowHostName())));
168     return element;
169   }
170 }
171
Popular Tags