Package com.helger.servlet.request
Class RequestParamMap
- java.lang.Object
-
- com.helger.servlet.request.RequestParamMap
-
- All Implemented Interfaces:
com.helger.commons.lang.IHasSize,IRequestParamMap
@NotThreadSafe public class RequestParamMap extends Object implements IRequestParamMap
This class represents a nested map that is build from request parameters. E.g. the parameterstruct[key]=valueresults in amap{struct=map{key=value}}.
If another parameterstruct[key2]=value2is added the resulting map looks like this:map{struct=map{key=value, key2=value2}}. Theses maps can indefinitely be nested.
Having onlystruct[key1][key2][key3]=valueresults inmap{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,setSeparators(char, char)andsetSeparators(String, String)offer the possibility to set different separator separators that are not special.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_CLOSEstatic StringDEFAULT_OPEN
-
Constructor Summary
Constructors Constructor Description RequestParamMap()RequestParamMap(Map<String,?> aMap)This constructor is private, because it does not call theput(String, Object)method which does the main string parsing!
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontains(String... aPath)booleancontainsKey(String sKey)Check if this map, contains the passed key.static IRequestParamMapcreate(Map<String,Object> aAttrCont)static IRequestParamMapcreateFromRequest(jakarta.servlet.http.HttpServletRequest aHttpRequest)booleanequals(Object o)com.helger.commons.collection.impl.ICommonsOrderedMap<String,RequestParamMapItem>getAsObjectMap()com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getAsValueMap()static com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getAsValueMap(Map<String,? extends RequestParamMapItem> aMap)com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getAsValueTrimmedMap()static com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getAsValueTrimmedMap(Map<String,? extends RequestParamMapItem> aMap)static StringgetCloseSeparator()static StringgetFieldName(String sBaseName)Deprecated.static StringgetFieldName(String sBaseName, int... aSuffixes)static StringgetFieldName(String sBaseName, String... aSuffixes)IRequestParamMapgetMap(String... aPath)Get a nested map for the specified path.RequestParamMapItemgetObject(String... aPath)static StringgetOpenSeparator()com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getValueMap(String... aPath)com.helger.commons.collection.impl.ICommonsOrderedMap<String,String>getValueTrimmedMap(String... aPath)inthashCode()booleanisEmpty()com.helger.commons.collection.impl.ICommonsOrderedSet<String>keySet()voidput(String sPath, Object aValue)static voidsetSeparators(char cOpen, char cClose)Set the separator chars to use.static voidsetSeparators(String sOpen, String sClose)Set the separators to use.static voidsetSeparatorsToDefault()intsize()StringtoString()com.helger.commons.collection.impl.ICommonsList<RequestParamMapItem>values()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.servlet.request.IRequestParamMap
getBigDecimal, getBigInteger, getBoolean, getDouble, getInt, getLong, getString, getStringTrimmed, isCheckBoxChecked
-
-
-
-
Field Detail
-
DEFAULT_OPEN
public static final String DEFAULT_OPEN
- See Also:
- Constant Field Values
-
DEFAULT_CLOSE
public static final String DEFAULT_CLOSE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RequestParamMap
public RequestParamMap()
-
RequestParamMap
public RequestParamMap(@Nonnull Map<String,?> aMap)
This constructor is private, because it does not call theput(String, Object)method which does the main string parsing!- Parameters:
aMap- The map to use. May not benull.
-
-
Method Detail
-
contains
public boolean contains(@Nonnull @Nonempty String... aPath)
- Specified by:
containsin interfaceIRequestParamMap
-
getObject
@Nullable public RequestParamMapItem getObject(@Nonnull @Nonempty String... aPath)
- Specified by:
getObjectin interfaceIRequestParamMap
-
getValueMap
@Nullable public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getValueMap(@Nonnull @Nonempty String... aPath)
- Specified by:
getValueMapin interfaceIRequestParamMap
-
getValueTrimmedMap
@Nullable public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getValueTrimmedMap(@Nonnull @Nonempty String... aPath)
- Specified by:
getValueTrimmedMapin interfaceIRequestParamMap
-
getMap
@Nullable @ReturnsMutableCopy public IRequestParamMap getMap(@Nonnull @Nonempty String... aPath)
Description copied from interface:IRequestParamMapGet a nested map for the specified path.- Specified by:
getMapin interfaceIRequestParamMap- Parameters:
aPath- The path to be resolved- Returns:
nullif the path could not be resolved.
-
containsKey
public boolean containsKey(@Nullable String sKey)
Description copied from interface:IRequestParamMapCheck if this map, contains the passed key. This will be true both for nested maps as well as for values.- Specified by:
containsKeyin interfaceIRequestParamMap- Parameters:
sKey- The key to check.- Returns:
trueif such a key is contained,falseif not
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacecom.helger.commons.lang.IHasSize
-
size
@Nonnegative public int size()
- Specified by:
sizein interfacecom.helger.commons.lang.IHasSize
-
keySet
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedSet<String> keySet()
- Specified by:
keySetin interfaceIRequestParamMap- Returns:
- A set of all contained key. Never
nullbut maybe empty.
-
values
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<RequestParamMapItem> values()
- Specified by:
valuesin interfaceIRequestParamMap- Returns:
- A collection of all values of this map. The type of the value is
usually either
String, file item (from upload) orMapfrom String to Object.
-
getAsObjectMap
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,RequestParamMapItem> getAsObjectMap()
- Specified by:
getAsObjectMapin interfaceIRequestParamMap- Returns:
- A copy of the contained map. For the value types see
IRequestParamMap.values()
-
getAsValueMap
@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAsValueMap(@Nonnull Map<String,? extends RequestParamMapItem> aMap)
-
getAsValueMap
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAsValueMap()
- Specified by:
getAsValueMapin interfaceIRequestParamMap- Returns:
- A key/value map, with enforced values. If this map contains a nested map, the nested maps are ignored!
-
getAsValueTrimmedMap
@Nonnull @ReturnsMutableCopy public static com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAsValueTrimmedMap(@Nonnull Map<String,? extends RequestParamMapItem> aMap)
-
getAsValueTrimmedMap
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsOrderedMap<String,String> getAsValueTrimmedMap()
- Specified by:
getAsValueTrimmedMapin interfaceIRequestParamMap- Returns:
- A key/value map, with enforced and trimmed values. If this map contains a nested map, the nested maps are ignored!
-
createFromRequest
@Nonnull public static IRequestParamMap createFromRequest(@Nonnull jakarta.servlet.http.HttpServletRequest aHttpRequest)
-
getFieldName
@Nonnull @Nonempty @Deprecated(forRemoval=false) public static String getFieldName(@Nonnull @Nonempty String sBaseName)
Deprecated.This method doesn't make sense but it should stay, so that it's easy to spot usage of this invalid method.- Parameters:
sBaseName- Base name- Returns:
- Base name as is.
-
getFieldName
@Nonnull @Nonempty public static String getFieldName(@Nonnull @Nonempty String sBaseName, @Nullable String... aSuffixes)
-
getFieldName
@Nonnull @Nonempty public static String getFieldName(@Nonnull @Nonempty String sBaseName, @Nullable int... aSuffixes)
-
setSeparatorsToDefault
public static void setSeparatorsToDefault()
-
setSeparators
public static void setSeparators(char cOpen, char cClose)Set the separator chars to use.- Parameters:
cOpen- Open charcClose- Close char - must be different from open char!
-
setSeparators
public static void setSeparators(@Nonnull @Nonempty String sOpen, @Nonnull @Nonempty String sClose)
Set the separators to use.- Parameters:
sOpen- Open string. May neither benullnor empty.sClose- Close string. May neither benullnor empty.
-
getOpenSeparator
@Nonnull @Nonempty public static String getOpenSeparator()
- Returns:
- The open char. By default this is "[". Never
nullnor empty. - See Also:
DEFAULT_OPEN
-
getCloseSeparator
@Nonnull @Nonempty public static String getCloseSeparator()
- Returns:
- The close char. By default this is "]". Never
nullnor empty. - See Also:
DEFAULT_CLOSE
-
-