KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > log > LogForm


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.log;
14
15 import java.io.File JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.util.Locale JavaDoc;
18
19 import org.w3c.dom.Document JavaDoc;
20
21 import com.tonbeller.wcf.component.Component;
22 import com.tonbeller.wcf.controller.RequestContext;
23 import com.tonbeller.wcf.form.FormComponent;
24 import com.tonbeller.wcf.format.FormatException;
25 import com.tonbeller.wcf.utils.SoftException;
26
27 /**
28  * Logging administration form
29  */

30 public class LogForm extends FormComponent {
31
32   LogHandler logHandler;
33   String JavaDoc logDir;
34
35   // Properties
36
String JavaDoc logConf = LogHandler.getDefault();
37   String JavaDoc logVersion;
38
39   /**
40    * Constructor
41    * @param id
42    * @param doc
43    * @param logHdl
44    * @throws IOException
45    */

46   public LogForm(String JavaDoc id, Component parent, Document JavaDoc doc, String JavaDoc logDir) throws Exception JavaDoc {
47     super(id, parent, doc);
48     
49     this.logDir = logDir;
50   }
51
52   /**
53    * @see com.tonbeller.wcf.component.Component#initialize(com.tonbeller.wcf.controller.RequestContext)
54    */

55   public void initialize(RequestContext context) throws Exception JavaDoc {
56     try {
57       String JavaDoc ctxname = context.getRequest().getContextPath();
58       if(ctxname.startsWith("/"))
59         ctxname = ctxname.substring(1);
60       
61       this.logHandler = createLogHandler(logDir, context.getLocale(), ctxname);
62       this.logVersion = logHandler.version();
63     } catch(IOException JavaDoc e) {
64       throw new SoftException(e);
65     }
66
67     // jetzt erst die NodeHandler intialisieren
68
super.initialize(context);
69   }
70   
71   /**
72    * Method createLogHandler.
73    * @param context
74    * @return LogHandler
75    */

76   protected LogHandler createLogHandler(String JavaDoc logDir, Locale JavaDoc locale, String JavaDoc ctxname) throws IOException JavaDoc {
77     return new LogHandler(logDir, locale, ctxname);
78   }
79   
80   /**
81    * Method getLogHandler.
82    * @return LogHandler
83    */

84   public LogHandler getLogHandler() {
85     return logHandler;
86   }
87
88   /**
89    * Returns the logConf.
90    * @return String
91    */

92   public String JavaDoc getLogConf() {
93     return logConf;
94   }
95
96   /**
97    * Sets the logConf.
98    * @param logConf The logConf to set
99    */

100   public void setLogConf(String JavaDoc logConf) {
101     this.logConf = logConf;
102     try {
103       logHandler.applyConfig(logConf);
104     } catch(Exception JavaDoc e) {
105       String JavaDoc msg = e.getMessage();
106       if(msg == null)
107         msg = e.toString();
108       throw new FormatException(msg);
109     }
110   }
111
112   /**
113    * Returns the logVersion.
114    * @return String
115    */

116   public String JavaDoc getLogVersion() {
117     return logVersion;
118   }
119
120   /**
121    * Returns the logFile.
122    * @return String
123    */

124   public String JavaDoc getLogFile() {
125     return logHandler.getLogFile().getAbsolutePath();
126   }
127
128   /**
129    * Sets the logFile.
130    * @param logFile The logFile to set
131    */

132   public void setLogFile(String JavaDoc logFile) {
133     logHandler.setLogFile(new File JavaDoc(logFile));
134   }
135
136   /**
137    * Returns the logLevel.
138    * @return String
139    */

140   public String JavaDoc getLogLevel() {
141     return logHandler.getRootLoggerLevel();
142   }
143
144 }
145
Popular Tags