
com.adobe.forms.common.submitutils.ParameterMap Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.adobe.forms.common.submitutils;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
/**
* Created with IntelliJ IDEA.
* User: syr
* Date: 1/20/14
* Time: 12:53 PM
* To change this template use File | Settings | File Templates.
*/
public class ParameterMap extends TreeMap implements RequestParameterMap {
private Map stringParameterMap;
public RequestParameter[] getValues(String name) {
return get(name);
}
public RequestParameter getValue(String name) {
RequestParameter[] params = get(name);
return (params != null && params.length > 0) ? params[0] : null;
}
public String getStringValue(final String name) {
final RequestParameter param = getValue(name);
return (param != null) ? param.getString() : null;
}
public String[] getStringValues(final String name) {
return toStringArray(getValues(name));
}
public Map getStringParameterMap() {
if (this.stringParameterMap == null) {
LinkedHashMap pm = new LinkedHashMap();
for (Map.Entry ppmEntry : entrySet()) {
pm.put(ppmEntry.getKey(), toStringArray(ppmEntry.getValue()));
}
this.stringParameterMap = Collections.unmodifiableMap(pm);
}
return stringParameterMap;
}
private static String[] toStringArray(final RequestParameter[] params) {
if (params == null) {
return null;
}
final String[] ps = new String[params.length];
for (int i = 0; i < params.length; i++) {
ps[i] = params[i].getString();
}
return ps;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy