001: /**
002: * Copyright 2004-2005 jManage.org
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */package org.jmanage.webui.forms;
016:
017: import org.apache.struts.action.ActionErrors;
018: import org.apache.struts.action.ActionMapping;
019: import org.apache.struts.action.ActionError;
020: import org.apache.commons.validator.GenericValidator;
021: import org.jmanage.core.util.ErrorCodes;
022: import org.jmanage.webui.util.RequestParams;
023:
024: import javax.servlet.http.HttpServletRequest;
025:
026: /**
027: *
028: * date: Jul 21, 2004
029: * @author Rakesh Kalra, Shashank Bellary
030: */
031: public class MBeanConfigForm extends BaseForm {
032: //TODO: Usage of DynaForm should clean up this.
033: private String[] name;
034: private String objectName;
035: private boolean applicationCluster;
036:
037: public final ActionErrors validate(ActionMapping mapping,
038: HttpServletRequest request) {
039: if (request.getParameter(RequestParams.MULTI_MBEAN_CONFIG) != null) {
040: boolean validValue = false, invalidValue = false, nullValue = false;
041: final String[] objectNames = request
042: .getParameterValues("name");
043: for (int mbeanCtr = 0; mbeanCtr < objectNames.length; mbeanCtr++) {
044: final String configName = request
045: .getParameter(objectNames[mbeanCtr]);
046: if (GenericValidator.isBlankOrNull(configName)) {
047: nullValue = true;
048: } else {
049: if (configName.indexOf("/") != -1) {
050: invalidValue = true;
051: } else {
052: validValue = true;
053: }
054: }
055: }
056: ActionErrors errors = new ActionErrors();
057: if (invalidValue) {
058: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
059: ErrorCodes.INVALID_CHAR_APP_NAME));
060: return errors;
061: } else if (nullValue && !validValue) {
062: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
063: "errors.required", "application name"));
064: return errors;
065: }
066: return null;
067: } else {
068: final String configName = request.getParameter("name");
069: ActionErrors errors = new ActionErrors();
070: if (GenericValidator.isBlankOrNull(configName)) {
071: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
072: "errors.required", "application name"));
073: return errors;
074: } else if (configName.indexOf("/") != -1) {
075: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
076: ErrorCodes.INVALID_CHAR_APP_NAME));
077: return errors;
078: } else {
079: return null;
080: }
081: }
082: }
083:
084: public String[] getName() {
085: return name;
086: }
087:
088: public void setName(String[] name) {
089: this .name = name;
090: }
091:
092: public String getObjectName() {
093: return objectName;
094: }
095:
096: public void setObjectName(String objectName) {
097: this .objectName = objectName;
098: }
099:
100: public boolean isApplicationCluster() {
101: return applicationCluster;
102: }
103:
104: public void setApplicationCluster(boolean applicationCluster) {
105: this.applicationCluster = applicationCluster;
106: }
107: }
|