KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > xml > FileLog_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>FileLog</tt>.
64  */

65 public class FileLog_Helper
66 extends BasicLogger_Helper
67 {
68   /**
69    * Configure this logger given the XML element.
70    * The <tt>&lt;Logger&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;Logger class="com.protomatter.syslog.FileLog" &gt;
77    *
78    * <font color="#888888">&lt;!--
79    * Config params from {@link BasicLogger_Helper#configure(Object,Element) BasicLogger_Helper} can
80    * get inserted here.
81    * --&gt;</font>
82    *
83    * &lt;fileName&gt;<i>FileName</i>&lt;/fileName&gt;
84    * &lt;append&gt;<i>true|false</i>&lt;/append&gt;
85    * &lt;autoFlush&gt;<i>true|false</i>&lt;/autoFlush&gt;
86    *
87    * &lt;/Logger&gt;
88    * </B></PRE>
89    * </TD></TR></TABLE><P>
90    *
91    * <TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 WIDTH="90%">
92    * <TR CLASS="TableHeadingColor">
93    * <TD COLSPAN=3><B>Element</B></TD>
94    * </TR>
95    * <TR CLASS="TableHeadingColor">
96    * <TD><B>name</B></TD>
97    * <TD><B>value</B></TD>
98    * <TD><B>required</B></TD>
99    * </TR>
100    *
101    * <TR CLASS="TableRowColor">
102    * <TD VALIGN=TOP><TT>fileName</TT></TD>
103    * <TD>The filename to write log entries to.
104    * </TD>
105    * <TD VALIGN=TOP>yes</TD>
106    * </TR>
107    *
108    * <TR CLASS="TableRowColor">
109    * <TD VALIGN=TOP><TT>append</TT></TD>
110    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the file
111    * should be appended to (or overwritten).
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>autoFlush</TT></TD>
118    * <TD><tt>true</tt> or <tt>false</tt> -- decide if we should
119    * flush the output buffer all the time or not. If this is
120    * set to <tt>false</tt> (the default), logging will be fast,
121    * but if set to <tt>true</tt> it will always be up-to-date.
122    * </TD>
123    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
124    * </TR>
125    *
126    * </TABLE><P>
127    *
128    */

129    public void configure(Object JavaDoc o, Element e)
130    throws SyslogInitException
131    {
132      super.configure(o, e);
133
134      FileLog log = (FileLog)o;
135
136      String JavaDoc tmp = e.getChildTextTrim("fileName", e.getNamespace());
137      if (tmp != null)
138      {
139        log.setFile(new File(tmp));
140      }
141      else
142      {
143        throw new IllegalArgumentException JavaDoc(
144          MessageFormat.format(Syslog.getResourceString(MessageConstants.XML_MUST_SPECIFY_PARAM_MESSAGE),
145          new Object JavaDoc[] { "fileName" } ));
146      }
147
148      tmp = e.getChildTextTrim("append", e.getNamespace());
149      if (tmp != null)
150        log.setAppend("true".equalsIgnoreCase(tmp.trim()));
151
152      tmp = e.getChildTextTrim("autoFlush", e.getNamespace());
153      if (tmp != null)
154        log.setAutoFlush("true".equalsIgnoreCase(tmp.trim()));
155    }
156
157   public Element getConfiguration(Object JavaDoc o, Element element)
158   {
159     Element e = super.getConfiguration(o, element);
160
161     FileLog log = (FileLog)o;
162
163     Element file = new Element("fileName");
164     file.setText(log.getFile().getPath());
165     e.getChildren().add(file);
166
167     Element append = new Element("append");
168     append.setText(String.valueOf(log.getAppend()));
169     e.getChildren().add(append);
170
171     Element af = new Element("autoFlush");
172     af.setText(String.valueOf(log.getAutoFlush()));
173     e.getChildren().add(af);
174
175     return e;
176   }
177 }
178
Popular Tags