FormInput.java :  » Web-Framework » calyxo » de » odysseus » calyxo » forms » Java Open Source

Java Open Source » Web Framework » calyxo 
calyxo » de » odysseus » calyxo » forms » FormInput.java
/*
 * Copyright 2004, 2005, 2006 Odysseus Software GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package de.odysseus.calyxo.forms;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.el.VariableResolver;


/**
 * Form input interface.
 * A form input can validate its parameter from a
 * {@link de.odysseus.calyxo.forms.FormInputValues} object and
 * format its mapped property from a
 * {@link de.odysseus.calyxo.forms.FormData} object.
 * <p/>
 * The property, the input get mapped to, could depend on input values,
 * so it is not part of this interface. Rather, it appears in the
 * input validation result.
 * 
 * @see de.odysseus.calyxo.forms.FormInputResult
 * @author Christoph Beck
 */
public interface FormInput {
  /**
   * Get the input parameter name
   */
  public String getName();

  /**
   * True iff this input represents an array parameter
   */
  public boolean isArray();

  /**
   * Validate.
   * @param request the request we process
   * @param params the input parameters
   * @param resolver variable resolver used to evaluate expressions
   * @return input validation result
   */
  public FormInputResult validate(HttpServletRequest request, FormInputValues params, VariableResolver resolver);

  /**
   * Format property.
   * @param request the request we process
   * @param bean form data
   * @return if this is an array input, an array of strings; a string else
   * @throws Exception if form data access failes
   */
  public Object format(HttpServletRequest request, FormData bean) throws Exception;

  /**
   * Format indexed property.
   * @param request the request we process
   * @param bean form data
   * @param index index used to access property
   * @param notAvailableResult returned if the property value is not available for the specified index
   * @return formatted string
   * @throws Exception if form data access failes
   */
  public String format(HttpServletRequest request, FormData bean, int index, String notAvailableResult) throws Exception;  

  /**
   * Answer true iff the input should be treated "relaxed" if invalid.
   * This information may be used to suppress error messages for an input.
   * 
   * @param variables the variable resolver
   * @return true iff the input should be treated "relaxed" if invalid.
   */
  public boolean isRelaxed(VariableResolver variables);

  /**
   * Answer true iff the input should be "ignored".
   * For an ignored input, no validation is done at all.
   * 
   * @param variables the variable resolver
   * @return true iff the input should be treated "ignored" if invalid.
   */
  public boolean isIgnored(VariableResolver variables);
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.