manveen 02/05/04 07:40:09 Added: webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources EnvEntryForm.java SetUpEnvEntryAction.java Log: Added classes that display /edit an environment entry. Revision Changes Path 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/EnvEntryForm.java Index: EnvEntryForm.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/EnvEntryForm.java,v 1.1 2002/05/04 14:40:09 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/05/04 14:40:09 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.webapp.admin.resources; import java.util.List; import java.util.ArrayList; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.webapp.admin.LabelValueBean; /** * Form bean for the individual environment entry page. * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/05/04 14:40:09 $ * @since 4.1 */ public final class EnvEntryForm extends BaseForm { // ----------------------------------------------------- Instance Variables // ------------------------------------------------------------- Properties /** * The name of the associated entry. */ private String name = null; public String getName() { return (this.name); } public void setName(String name) { this.name = name; } /** * The type of the associated entry. */ private String entryType = null; public String getEntryType() { return (this.entryType); } public void setEntryType(String entryType) { this.entryType = entryType; } /** * The value of the associated entry. */ private String value = null; public String getValue() { return (this.value); } public void setValue(String value) { this.value = value; } /** * The description of the associated entry. */ private String description = null; public String getDescription() { return (this.description); } public void setDescription(String description) { this.description = description; } /** * Precomputed list of entry type labels and values. */ private static List typeVals = new ArrayList(); static { typeVals.add(new LabelValueBean("java.lang.Boolean", "java.lang.Boolean")); typeVals.add(new LabelValueBean("java.lang.Byte", "java.lang.Byte")); typeVals.add(new LabelValueBean("java.lang.Character", "java.lang.Character")); typeVals.add(new LabelValueBean("java.lang.Double", "java.lang.Double")); typeVals.add(new LabelValueBean("java.lang.Float", "java.lang.Float")); typeVals.add(new LabelValueBean("java.lang.Integer", "java.lang.Integer")); typeVals.add(new LabelValueBean("java.lang.Long", "java.lang.Long")); typeVals.add(new LabelValueBean("java.lang.Short", "java.lang.Short")); typeVals.add(new LabelValueBean("java.lang.String", "java.lang.String")); } /** * Return the typeVals. */ public List getTypeVals() { return this.typeVals; } /** * Set the typeVals. */ public void setTypeVals(List typeVals) { this.typeVals = typeVals; } // --------------------------------------------------------- Public Methods /** * Reset all properties to their default values. * * @param mapping The mapping used to select this instance * @param request The servlet request we are processing */ public void reset(ActionMapping mapping, HttpServletRequest request) { super.reset(mapping, request); name = null; entryType = null; value = null; description = null; } /** * Validate the properties that have been set from this HTTP request, * and return an <code>ActionErrors</code> object that encapsulates any * validation errors that have been found. If no errors are found, return * <code>null</code> or an <code>ActionErrors</code> object with no * recorded error messages. * * @param mapping The mapping used to select this instance * @param request The servlet request we are processing */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); String submit = request.getParameter("submit"); if (submit != null) { // name is a required field if ((name == null) || (name.length() < 1)) { errors.add("name", new ActionError("resources.error.name.required")); } // value is a required field if ((value == null) || (value.length() < 1)) { errors.add("value", new ActionError("resources.error.value.required")); } // Quotes not allowed in name if ((name != null) && (name.indexOf('"') >= 0)) { errors.add("name", new ActionError("users.error.quotes")); } // Quotes not allowed in value if ((value != null) && (value.indexOf('"') > 0)) { errors.add("value", new ActionError("users.error.quotes")); } // Quotes not allowed in description if ((description != null) && (description.indexOf('"') > 0)) { errors.add("description", new ActionError("users.error.quotes")); } } return (errors); } } 1.1 jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SetUpEnvEntryAction.java Index: SetUpEnvEntryAction.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/webapps/admin/WEB-INF/classes/org/apache/webapp/admin/resources/SetUpEnvEntryAction.java,v 1.1 2002/05/04 14:40:09 manveen Exp $ * $Revision: 1.1 $ * $Date: 2002/05/04 14:40:09 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-EnvEntry documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.webapp.admin.resources; import java.io.IOException; import java.net.URLDecoder; import java.util.Iterator; import java.util.Locale; import javax.management.Attribute; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.QueryExp; import javax.management.Query; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.JMException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanOperationInfo; import javax.management.MBeanInfo; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.Action; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.util.MessageResources; import org.apache.webapp.admin.ApplicationServlet; /** * <p>Implementation of <strong>Action</strong> that sets up and stashes * a <code>EnvEntryForm</code> bean in request scope. The form bean will have * a null <code>objectName</code> property if this form represents a EnvEntry * being added, or a non-null value for an existing EnvEntry.</p> * * @author Manveen Kaur * @version $Revision: 1.1 $ $Date: 2002/05/04 14:40:09 $ * @since 4.1 */ public final class SetUpEnvEntryAction extends Action { // ----------------------------------------------------- Instance Variables /** * The MBeanServer we will be interacting with. */ private MBeanServer mserver = null; /** * The MessageResources we will be retrieving messages from. */ private MessageResources resources = null; // --------------------------------------------------------- Public Methods /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Look up the components we will be using as needed if (mserver == null) { mserver = ((ApplicationServlet) getServlet()).getServer(); } if (resources == null) { resources = getServlet().getResources(); } HttpSession session = request.getSession(); Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY); // Set up the form bean based on the creating or editing state String objectName = request.getParameter("objectName"); EnvEntryForm envEntryForm = new EnvEntryForm(); if (objectName == null) { envEntryForm.setNodeLabel (resources.getMessage(locale, "resources.actions.env.create")); envEntryForm.setObjectName(null); } else { envEntryForm.setNodeLabel (resources.getMessage(locale, "resources.actions.env.edit")); envEntryForm.setObjectName(objectName); String attribute = null; try { ObjectName oname = new ObjectName(objectName); attribute = "name"; envEntryForm.setName ((String) mserver.getAttribute(oname, attribute)); attribute = "type"; envEntryForm.setEntryType ((String) mserver.getAttribute(oname, attribute)); attribute = "value"; envEntryForm.setValue ((String) mserver.getAttribute(oname, attribute)); attribute = "description"; envEntryForm.setDescription ((String) mserver.getAttribute(oname, attribute)); } catch (Exception e) { getServlet().log (resources.getMessage(locale, "users.error.attribute.get", attribute), e); response.sendError (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, resources.getMessage (locale, "users.error.attribute.get", attribute)); return (null); } } // Stash the form bean and forward to the display page saveToken(request); request.setAttribute("envEntryForm", envEntryForm); return (mapping.findForward("EnvEntry")); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>