KickJava   Java API By Example, From Geeks To Geeks.

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


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: EditCatalinaAccessLoggerAction.java,v 1.8 2005/04/19 13:01:41 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.logging;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.CatalinaObjectName;
41 import org.objectweb.jonas.jmx.JonasManagementRepr;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
44 import org.objectweb.jonas.webapp.jonasadmin.service.container.WebAppItem;
45
46 /**
47  * @author Michel-Ange ANTON
48  * @author Adriana Danes
49  */

50
51 public class EditCatalinaAccessLoggerAction extends BaseLoggerAction {
52
53 // --------------------------------------------------------- Public Methods
54

55     public ActionForward executeAction(ActionMapping pMapping, ActionForm pForm
56         , HttpServletRequest JavaDoc pRequest, HttpServletResponse JavaDoc pResponse)
57         throws IOException JavaDoc, ServletException JavaDoc {
58
59         // Parameters
60
String JavaDoc sAction = pRequest.getParameter("action");
61         if (sAction == null) {
62             sAction = "edit";
63         }
64         String JavaDoc sObjectName = pRequest.getParameter("select");
65         // Form used
66
CatalinaAccessLogValveForm oForm = null;
67         if (("create".equals(sAction) == true) || (sObjectName != null)) {
68             oForm = new CatalinaAccessLogValveForm();
69             m_Session.setAttribute("catalinaAccessLoggerForm", oForm);
70             oForm.reset(pMapping, pRequest);
71             oForm.setObjectName(sObjectName);
72         } else {
73             oForm = (CatalinaAccessLogValveForm) m_Session.getAttribute("catalinaAccessLoggerForm");
74         }
75         oForm.setAction(sAction);
76         // Polulate
77
try {
78             if (oForm.getObjectName() != null) {
79                 // Get the access logger
80
ObjectName JavaDoc on = new ObjectName JavaDoc(oForm.getObjectName());
81                 String JavaDoc loggerContainerType = null; // needed for mgmt tree node name
82
String JavaDoc loggerContainerName = null; // needed for mgmt tree node name
83
// Populate
84
oForm.setObjectName(on.toString());
85                 oForm.setDirectory(getStringAttribute(on, "directory"));
86                 oForm.setPattern(getStringAttribute(on, "pattern"));
87                 oForm.setPrefix(getStringAttribute(on, "prefix"));
88                 oForm.setResolveHosts(getBooleanAttribute(on, "resolveHosts"));
89                 oForm.setRotatable(getBooleanAttribute(on, "rotatable"));
90                 oForm.setSuffix(getStringAttribute(on, "suffix"));
91                 ObjectName JavaDoc onContainer = (ObjectName JavaDoc) JonasManagementRepr.getAttribute(on, "containerName");
92                 if (onContainer.getKeyProperty("j2eeType") != null) {
93                     if (onContainer.getKeyProperty("j2eeType").equals("WebModule")) {
94                         // The container is a Web application (Context element in Tomcat)
95
oForm.setContainerType(m_Resources.getMessage("label.loggers.container.context"));
96                         String JavaDoc webContainerName = WebAppItem.extractLabelPathContext(onContainer.getKeyProperty("name"));
97                         oForm.setContainerName(webContainerName);
98                         oForm.setContainerObjectName(onContainer.toString());
99                         loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_CONTEXT;
100                         loggerContainerName = on.getKeyProperty("path");
101                     }
102                 } else if (onContainer.getKeyProperty("type") != null) {
103                     if (onContainer.getKeyProperty("type").equals("Engine")) {
104                         oForm.setContainerType(m_Resources.getMessage("label.loggers.container.engine"));
105                         oForm.setContainerName(m_Resources.getMessage("label.loggers.container.engine.name"));
106                         loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_ENGINE;
107                         loggerContainerName = oForm.getContainerName();
108                     } else if (onContainer.getKeyProperty("type").equals("Host")) {
109                         oForm.setContainerType(m_Resources.getMessage("label.loggers.container.host"));
110                         oForm.setContainerName(onContainer.getKeyProperty("host"));
111                         loggerContainerType = LoggerItem.LOGGER_CATALINA_ACCESS_HOST;
112                         loggerContainerName = on.getKeyProperty("host");
113                     }
114                 }
115                 // Force the node selected in tree
116
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
117                     + WhereAreYou.NODE_SEPARATOR
118                     + "logging"
119                     + WhereAreYou.NODE_SEPARATOR
120                     + loggerContainerType
121                     + WhereAreYou.NODE_SEPARATOR
122                     + loggerContainerName, true);
123             } else {
124                 oForm.setCatalinaDomainName(m_WhereAreYou.getCurrentCatalinaDomainName());
125                 ObjectName JavaDoc hostsOn = CatalinaObjectName.catalinaHosts(m_WhereAreYou.getCurrentCatalinaDomainName());
126                 Iterator JavaDoc hosts = JonasAdminJmx.getListMbean(hostsOn).iterator();
127                 ArrayList JavaDoc hostNames = new ArrayList JavaDoc();
128                 for (; hosts.hasNext();) {
129                     hostNames.add(((ObjectName JavaDoc) hosts.next()).getKeyProperty("host"));
130                 }
131                 String JavaDoc[] allNames = new String JavaDoc[hostNames.size() + 1];
132                 allNames[0] = "no name required for Engine";
133                 for (int i=1; i < allNames.length; i++) {
134                     allNames[i] = (String JavaDoc) hostNames.get(i-1);
135                 }
136                 oForm.setContainerNames(allNames);
137             }
138         } catch (Throwable JavaDoc t) {
139             addGlobalError(t);
140             saveErrors(pRequest, m_Errors);
141             return (pMapping.findForward("Global Error"));
142         }
143         // Forward to the jsp.
144
return (pMapping.findForward("Catalina Access Logger"));
145     }
146
147 }
148
Popular Tags