/*
* 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 java.text.ParseException;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
/**
* Converter interface.
* A converter can parse a string to an object value and format it back
* to a string.
* Implementors must have an empty constructor. Additionally to the
* methods required for a validation engine they have to implement the
* {@link #parse(HttpServletRequest, String)} and
* {@link #format(HttpServletRequest, Object)} methods.
*
* @author Christoph Beck
* @author Oliver Stuhr
*/
public interface Converter extends ValidatorBase {
/**
* Static "do-nothing" converter instance
*/
public static final Converter IDENTITY = new Converter() {
public String format(HttpServletRequest request, Object value) {
return value == null ? null : value.toString();
}
public Object parse(HttpServletRequest request, String value) {
return value;
}
public void localize(Locale locale) {
}
public boolean isSharable() {
return true;
}
};
/**
* Formats the given value to a string.
* @return formatted string
*/
public String format(HttpServletRequest request, Object value);
/**
* Parses the given string to an object.
* @return converted value
*/
public Object parse(HttpServletRequest request, String value) throws ParseException;
}
|