Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2006-2015 phloc systems
* http://www.phloc.com
* office[at]phloc[dot]com
*
* 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 com.phloc.web.servlet.request;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.phloc.commons.ValueEnforcer;
import com.phloc.commons.annotations.Nonempty;
import com.phloc.commons.annotations.ReturnsMutableCopy;
import com.phloc.commons.collections.ArrayHelper;
import com.phloc.commons.collections.ContainerHelper;
import com.phloc.commons.collections.attrs.AbstractReadonlyAttributeContainer;
import com.phloc.commons.collections.attrs.IReadonlyAttributeContainer;
import com.phloc.commons.hash.HashCodeGenerator;
import com.phloc.commons.lang.CGStringHelper;
import com.phloc.commons.lang.GenericReflection;
import com.phloc.commons.string.StringHelper;
import com.phloc.commons.string.ToStringGenerator;
/**
* This class represents a nested map that is build from request parameters.
* E.g. the parameter struct[key]=value results in a
* map{struct=map{key=value}}.
* If another parameter struct[key2]=value2 is added the resulting
* map looks like this: map{struct=map{key=value, key2=value2}}.
* Theses maps can indefinitely be nested.
* Having only struct[key1][key2][key3]=value results in
* map{struct=map{key1=map{key2=map{key3=value}}}}
*
* By default the separator chars are "[" and "]" but since this may be a
* problem with JS expressions, {@link #setSeparators(char, char)} and
* {@link #setSeparators(String, String)} offer the possibility to set different
* separator separators that are not special.
*
* @author Philip Helger
*/
@Immutable
public final class RequestParamMap implements IRequestParamMap
{
public static final String DEFAULT_OPEN = "[";
public static final String DEFAULT_CLOSE = "]";
private static final Logger s_aLogger = LoggerFactory.getLogger (RequestParamMap.class);
/** The index open separator */
private static String s_sOpen = DEFAULT_OPEN;
/** The index close separator */
private static String s_sClose = DEFAULT_CLOSE;
private final Map m_aMap;
public RequestParamMap ()
{
m_aMap = new HashMap ();
}
/**
* This constructor is private, because it does not call the
* {@link #put(String, Object)} method which does the main string parsing!
*
* @param aMap
* The map to use. May not be null.
*/
private RequestParamMap (@Nonnull final Map aMap)
{
m_aMap = ValueEnforcer.notNull (aMap, "Map");
}
private void _recursiveAddItem (@Nonnull final Map aMap,
@Nonnull final String sName,
@Nullable final Object aValue)
{
final int nIndex = sName.indexOf (s_sOpen);
if (nIndex == -1)
{
// Value level
aMap.put (sName, aValue);
}
else
{
// Get the name until the first "["
final String sPrefix = sName.substring (0, nIndex);
// Ensure that the respective map is present
final Object aPrefixValue = aMap.get (sPrefix);
Map aChildMap = GenericReflection.