org.efaps.ui.wicket.request.EFapsRequestParametersAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-webapp Show documentation
Show all versions of efaps-webapp Show documentation
eFaps WebApp provides a web interface as the User Interface for eFaps
which can be easily expanded and altered.
/*
* Copyright 2003 - 2011 The eFaps Team
*
* 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.
*
* Revision: $Rev: 8390 $
* Last Changed: $Date: 2012-12-18 00:07:32 -0500 (Tue, 18 Dec 2012) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.ui.wicket.request;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.wicket.request.IRequestParameters;
import org.apache.wicket.request.IWritableRequestParameters;
import org.apache.wicket.util.string.StringValue;
import org.efaps.db.Context;
import org.efaps.ui.wicket.util.ParameterUtil;
import org.efaps.util.EFapsException;
/**
* TODO comment!
*
* @author The eFaps Team
* @version $Id: EFapsRequestParametersAdapter.java 8390 2012-12-18 05:07:32Z [email protected] $
*/
public class EFapsRequestParametersAdapter
implements IWritableRequestParameters
{
private final Map> parameters = new HashMap>();
/**
* @param _queryParameters
* @param _postParameters
*/
public EFapsRequestParametersAdapter(final IRequestParameters... _parameters)
{
for (final IRequestParameters p : _parameters) {
for (final String name : p.getParameterNames()) {
this.parameters.put(name, p.getParameterValues(name));
}
}
}
@Override
public Set getParameterNames()
{
return Collections.unmodifiableSet(this.parameters.keySet());
}
@Override
public StringValue getParameterValue(final String _name)
{
final List values = this.parameters.get(_name);
return (values != null && !values.isEmpty()) ? values.get(0)
: StringValue.valueOf((String) null);
}
@Override
public List getParameterValues(final String _name)
{
final List values = this.parameters.get(_name);
return values != null ? Collections.unmodifiableList(values) : null;
}
@Override
public void setParameterValues(final String _name,
final List _value)
{
this.parameters.put(_name, _value);
try {
Context.getThreadContext().getParameters().put(_name, ParameterUtil.stringValues2Array(_value));
} catch (final EFapsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Sets value for given key.
*
* @param _key key for the value
* @param _value value
*/
public void setParameterValue(final String _key,
final String _value)
{
final List list = new ArrayList(1);
list.add(StringValue.valueOf(_value));
setParameterValues(_key, list);
}
/**
* Adds a value for given key.
*
* @param _key key for the value
* @param _value value
*/
public void addParameterValue(final String _key,
final String _value)
{
List list = this.parameters.get(_key);
if (list == null)
{
list = new ArrayList(1);
this.parameters.put(_key, list);
}
list.add(StringValue.valueOf(_value));
try {
Context.getThreadContext().getParameters().put(_key, ParameterUtil.stringValues2Array(list));
} catch (final EFapsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void reset()
{
this.parameters.clear();
}
}