001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: ArchiveConfigAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.webapp.jonasadmin.xml;
025:
026: import java.io.IOException;
027: import java.util.HashMap;
028: import java.util.TreeMap;
029:
030: import javax.management.ObjectName;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.apache.struts.action.ActionMessage;
039: import org.objectweb.jonas.jmx.JonasManagementRepr;
040: import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx;
041: import org.objectweb.jonas.webapp.jonasadmin.deploy.BaseDeployAction;
042: import org.w3c.dom.Document;
043:
044: /**
045: * Action to extract the XML parsed into a Document object from the archive and
046: * forward to the form view JSP configuration page.
047: *
048: * @author Patrick Smith
049: * @author Gregory Lapouchnian
050: */
051: public class ArchiveConfigAction extends BaseDeployAction {
052:
053: /**
054: * Executes the struts action.
055: * @param p_Mapping the struts action mapping.
056: * @param p_Form the struts action form.
057: * @param p_Request the HttpServletRequest.
058: * @param p_Response the HttpServletResponse.
059: * @throws IOException
060: * @throws ServletException
061: * @return the action forward to forward to.
062: */
063: public ActionForward executeAction(ActionMapping p_Mapping,
064: ActionForm p_Form, HttpServletRequest p_Request,
065: HttpServletResponse p_Response) throws IOException,
066: ServletException {
067:
068: String sForward = "Archive Config";
069:
070: ArchiveConfigForm oForm = (ArchiveConfigForm) p_Form;
071:
072: String serverName = m_WhereAreYou.getCurrentJonasServerName();
073:
074: // find out which XML file within the archive is being requested
075: if (p_Request.getParameter("file") != null
076: && p_Request.getParameter("file").length() > 0) {
077: oForm.setPathName(p_Request.getParameter("file"));
078: }
079: // make sure that the user selected the archive and file names
080: if (oForm.getArchiveName() == null
081: || oForm.getPathName() == null) {
082: m_Errors.add("error.config.noselect", new ActionMessage(
083: "error.config.noselect"));
084: saveErrors(p_Request, m_Errors);
085:
086: // Forward back to the selection JSP
087: return (p_Mapping.findForward("Archive Config Select"));
088: }
089:
090: // retrieve the XML document
091: ObjectName on = JonasAdminJmx
092: .getRarConfigObjectName(serverName);
093: Object[] params = new Object[] { oForm.getArchiveName(),
094: oForm.getPathName() };
095: String[] sig = new String[] { "java.lang.String",
096: "java.lang.String" };
097:
098: Document document;
099: try {
100: document = (Document) JonasManagementRepr.invoke(on,
101: "extractDocument", params, sig, serverName);
102: oForm.setDocument(document);
103: } catch (Exception e) {
104: m_Errors.add("error.archiveconfig.load.fail",
105: new ActionMessage("error.archiveconfig.load.fail",
106: oForm.getPathName()));
107: saveErrors(p_Request, m_Errors);
108:
109: // forward back to the selection JSP
110: return (p_Mapping.findForward("Archive Config Select"));
111: }
112:
113: // reset the values, not to reuse anything from the previous document
114: oForm.setValuesMap(new TreeMap());
115: oForm.setMapping(new HashMap());
116:
117: // specify the two types of xml files that can be configured, these are
118: // used as parameters to <html:link> when switching from file to file
119: oForm.setValues("raXmlFileName", "META-INF/ra.xml");
120: oForm.setValues("jonasRaXmlFileName", "META-INF/jonas-ra.xml");
121:
122: // save the contents of the document to the form
123: oForm.setValues("fileName", oForm.getArchiveName());
124: oForm.setValues("pathName", oForm.getPathName());
125: oForm.setIsDomain(isDomain());
126:
127: // Forward to the jsp.
128: return (p_Mapping.findForward(sForward));
129: }
130: }
|