/*
* 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.conf.impl;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.jsp.el.Expression;
import javax.servlet.jsp.el.ExpressionEvaluator;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.conf.impl.ConfigImpl;
import de.odysseus.calyxo.base.util.ListOrderedMap;
import de.odysseus.calyxo.forms.conf.FieldConfig;
import de.odysseus.calyxo.forms.conf.InputConfig;
import de.odysseus.calyxo.forms.conf.MessageConfig;
/**
* Input configuration implementation.
*
* @author Christoph Beck
*/
public class InputConfigImpl extends ConfigImpl implements InputConfig {
private String name;
private boolean array;
private String relax;
private String ignore;
private MessageConfig message;
private Map fieldConfigs = ListOrderedMap.decorate(new HashMap());
private Expression relaxExpression;
private Expression ignoreExpression;
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getElementName()
*/
protected String _getElementName() {
return "input";
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_addChildren(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Elements)
*/
protected void _addChildren(Elements list) {
super._addChildren(list);
list.add(getFieldConfigs());
list.add(getMessageConfig());
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_putAttributes(de.odysseus.calyxo.base.conf.impl.ConfigImpl.Attributes)
*/
protected void _putAttributes(Attributes map) {
super._putAttributes(map);
map.put("name", name);
map.put("array", String.valueOf(array));
map.put("relax", relax);
map.put("ignore", ignore);
}
/**
* Answer array <code>{ "relax", "ignore" }</code>.
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_getDynamicAttributes()
*/
protected String[] _getDynamicAttributes() {
return new String[]{ "relax", "ignore" };
}
/**
* Validate relax and ignore expressions.
* @see de.odysseus.calyxo.base.conf.impl.ConfigImpl#_evaluate(de.odysseus.calyxo.base.ModuleContext)
*/
protected void _evaluate(ModuleContext context) throws ConfigException {
super._evaluate(context);
ExpressionEvaluator evaluator = context.getExpressionEvaluator();
if (relax != null) {
StringBuffer s = new StringBuffer();
s.append("${");
s.append(relax);
s.append("}");
try {
relaxExpression = evaluator.parseExpression(s.toString(), Boolean.class, this);
} catch (Exception e) {
throw new ConfigException("Parse error in '" + relax + "'", e);
}
}
if (ignore != null) {
StringBuffer s = new StringBuffer();
s.append("${");
s.append(ignore);
s.append("}");
try {
ignoreExpression = evaluator.parseExpression(s.toString(), Boolean.class, this);
} catch (Exception e) {
throw new ConfigException("Parse error in '" + ignore + "'", e);
}
}
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.InputConfig#getName()
*/
public String getName() {
return name;
}
/**
* Set input parameter name
*/
public void setName(String string) {
name = string;
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.InputConfig#isArray()
*/
public boolean isArray() {
return array;
}
/**
* Set array flag
*/
public void setArray(boolean value) {
array = value;
}
/**
* Add field element
*/
public void add(FieldConfigImpl value) throws ConfigException {
if (fieldConfigs.containsKey(value.getProperty())) {
throw new ConfigException("Duplicate field '" + value.getProperty() + "' in " + toInlineString());
}
fieldConfigs.put(value.getProperty(), value);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.InputConfig#getFieldConfig(java.lang.String)
*/
public FieldConfig getFieldConfig(String property) {
return (FieldConfigImpl)fieldConfigs.get(property);
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.InputConfig#getFieldConfigs()
*/
public Iterator getFieldConfigs() {
return fieldConfigs.values().iterator();
}
/*
* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.InputConfig#getMessageConfig()
*/
public MessageConfig getMessageConfig() {
return message;
}
/**
* Set message element
*/
public void setMessageConfig(MessageConfig value) {
message = value;
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.FieldConfig#getRelax()
*/
public String getRelax() {
return relax;
}
/**
* Set the relax expression
*/
public void setRelax(String relax) {
this.relax = relax;
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.FieldConfig#getParsedRelaxExpression()
*/
public Expression getParsedRelaxExpression() {
return relaxExpression;
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.FieldConfig#getIgnore()
*/
public String getIgnore() {
return ignore;
}
/**
* Set the ignore expression
*/
public void setIgnore(String ignore) {
this.ignore = ignore;
}
/* (non-Javadoc)
* @see de.odysseus.calyxo.forms.conf.FieldConfig#getParsedIgnoreExpression()
*/
public Expression getParsedIgnoreExpression() {
return ignoreExpression;
}
}