KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > logging > CatalinaAccessLogValveForm


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: CatalinaAccessLogValveForm.java,v 1.5 2005/04/21 08:59:54 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.logging;
27
28 import java.util.List JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32
33 import org.apache.struts.action.ActionMessage;
34 import org.apache.struts.action.ActionErrors;
35 import org.apache.struts.action.ActionMapping;
36 import org.objectweb.jonas.jmx.CatalinaObjectName;
37 import org.objectweb.jonas.jmx.JonasManagementRepr;
38 import org.objectweb.jonas.webapp.jonasadmin.Jlists;
39
40 /**
41  * @author Michel-Ange ANTON
42  * @author Adriana Danes
43  */

44
45 public final class CatalinaAccessLogValveForm extends CatalinaValveForm {
46
47 // ----------------------------------------------------- Properties Variables
48

49     /**
50      * directory in which log files will be placed
51      */

52     private String JavaDoc directory = null;
53     /**
54      * A formatting layout
55      */

56     private String JavaDoc pattern = null;
57     /**
58      * prefix added to the start of each log file's name
59      */

60     private String JavaDoc prefix = null;
61     /**
62      * suffix added to the end of each log file's name
63      */

64     private String JavaDoc suffix = null;
65     /**
66      * Deafult true. Flag to determine if log rotation should occure.
67      */

68     private boolean rotatable = true;
69     /**
70      * Set to true to convert the IP address of the remote host into the corresponding host name via a DNS lookup.
71      * Set to false to skip this lookup, and report the remote IP address instead.
72      */

73     private boolean resolveHosts = false;
74     /**
75      *
76      */

77     private List JavaDoc booleanValues = Jlists.getBooleanValues();
78     /**
79      * Domain name used to construct Catalina MBean ObjectNames (JOnAS server name in general)
80      */

81     private String JavaDoc catalinaDomainName = null;
82
83 // --------------------------------------------------------- Public Methods
84

85     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
86         super.reset(mapping, request);
87         directory = "logs";
88         prefix = "access_log.";
89         suffix = ".txt";
90         pattern = "%h %l %u %t \"%r\" %s %b";
91         resolveHosts = false;
92         rotatable = true;
93         String JavaDoc[] containerTypes = {"Engine", "Host"};
94         setContainerTypes(containerTypes);
95     }
96
97     public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
98         ActionErrors oErrors = new ActionErrors();
99         // prefix
100
if ((prefix == null) || (prefix.length() < 1)) {
101             oErrors.add("pattern", new ActionMessage("error.logger.catalina.access.prefix.required"));
102         }
103         // default is a 0 length string
104
if ((suffix == null) || (suffix.length() < 1)) {
105             suffix = "";
106         }
107         // pattern
108
if ((pattern == null) || (pattern.length() < 1)) {
109             oErrors.add("pattern", new ActionMessage("error.logger.catalina.access.pattern.required"));
110         }
111         // Test the provided Engine or Host names only in case we are in a "create" action
112
if (getAction().equals("edit")) {
113             return oErrors;
114         }
115         if (getContainerType().equals("Engine")) {
116             // Test if no access valve set already on the Engine
117
ObjectName JavaDoc onEngine = CatalinaObjectName.catalinaEngine(catalinaDomainName);
118             ObjectName JavaDoc[] valveOns = (ObjectName JavaDoc[]) JonasManagementRepr.getAttribute(onEngine, "valveObjectNames");
119             for (int i = 0; i < valveOns.length; i++) {
120                 ObjectName JavaDoc valveOn = valveOns[i];
121                 if (valveOn != null) { // can be null because bug in Tomacat (after a remove)
122
String JavaDoc valveName = valveOn.getKeyProperty("name");
123                     if (valveName.equals("AccessLogValve")) {
124                         // we already have an AccessLogValve associated to the Engine
125
oErrors.add("", new ActionMessage("error.logger.catalina.access.log.engine.alreadypresent"));
126                         break;
127                     }
128                 }
129             }
130         }
131         if (getContainerType().equals("Host")) {
132             // Test if no access valve set already on the choosen host
133
ObjectName JavaDoc onHost = CatalinaObjectName.catalinaHost(catalinaDomainName, getContainerName());
134             if (!JonasManagementRepr.isRegistered(onHost)) {
135                 oErrors.add("", new ActionMessage("error.logger.catalina.access.log.nohost"));
136             } else {
137                 ObjectName JavaDoc[] valveOns = (ObjectName JavaDoc[]) JonasManagementRepr.getAttribute(onHost, "valveObjectNames");
138                 for (int i = 0; i < valveOns.length; i++) {
139                     ObjectName JavaDoc valveOn = valveOns[i];
140                     if (valveOn != null) { // can be null because bug in Tomacat (after a remove)
141
String JavaDoc valveName = valveOn.getKeyProperty("name");
142                         if (valveName.equals("AccessLogValve")) {
143                         // we already have an AccessLogValve associated to the Host
144
oErrors.add("", new ActionMessage("error.logger.catalina.access.log.host.alreadypresent"));
145                         break;
146                         }
147                     }
148                 }
149             }
150         }
151         return oErrors;
152     }
153
154 // ------------------------------------------------------------- Properties Methods
155

156     public List JavaDoc getBooleanValues() {
157         return booleanValues;
158     }
159
160     public void setBooleanValues(List JavaDoc booleanValues) {
161         this.booleanValues = booleanValues;
162     }
163
164     public String JavaDoc getDirectory() {
165         return this.directory;
166     }
167
168     public void setDirectory(String JavaDoc directory) {
169         this.directory = directory;
170     }
171
172     public String JavaDoc getPattern() {
173         return this.pattern;
174     }
175
176     public void setPattern(String JavaDoc pattern) {
177         this.pattern = pattern;
178     }
179
180     public String JavaDoc getPrefix() {
181         return this.prefix;
182     }
183
184     public void setPrefix(String JavaDoc prefix) {
185         this.prefix = prefix;
186     }
187
188     public String JavaDoc getSuffix() {
189         return this.suffix;
190     }
191
192     public void setSuffix(String JavaDoc suffix) {
193         this.suffix = suffix;
194     }
195
196     public boolean isResolveHosts() {
197         return this.resolveHosts;
198     }
199
200     public void setResolveHosts(boolean resolveHosts) {
201         this.resolveHosts = resolveHosts;
202     }
203
204     public boolean isRotatable() {
205         return this.rotatable;
206     }
207
208     public void setRotatable(boolean rotatable) {
209         this.rotatable = rotatable;
210     }
211
212     /**
213      * @return Returns the catalinaDomainName.
214      */

215     public String JavaDoc getCatalinaDomainName() {
216         return catalinaDomainName;
217     }
218
219
220     /**
221      * @param catalinaDomainName The catalinaDomainName to set.
222      */

223     public void setCatalinaDomainName(String JavaDoc catalinaDomainName) {
224         this.catalinaDomainName = catalinaDomainName;
225     }
226
227 }
228
Popular Tags