public RootParamNode getRootParamNode() { checkAndParse(); if (!rootParamsNodeIsGenerated) { rootParamNode = ParamNode.convert(data); rootParamsNodeIsGenerated = true; } return rootParamNode; }
public Map<String, String> allSimple() { checkAndParse(); Map<String, String> result = new HashMap<String, String>(); for (String key : data.keySet()) { result.put(key, data.get(key)[0]); } return result; }
public String get(String key) { if (!_contains(key)) { checkAndParse(); } if (data.containsKey(key)) { return data.get(key)[0]; } return null; }
public Map<String, String[]> sub(String prefix) { checkAndParse(); Map<String, String[]> result = new HashMap<String, String[]>(); for (String key : data.keySet()) { if (key.startsWith(prefix + ".")) { result.put(key.substring(prefix.length() + 1), data.get(key)); } } return result; }
@SuppressWarnings("unchecked") public <T> T get(String key, Class<T> type) { try { checkAndParse(); // TODO: This is used by the test, but this is not the most convenient. return (T) Binder.bind(getRootParamNode(), key, type, type, null); } catch (Exception e) { Validation.addError(key, "validation.invalid"); return null; } }
public String urlEncode() { checkAndParse(); String encoding = Http.Response.current().encoding; StringBuilder ue = new StringBuilder(); for (String key : data.keySet()) { if (key.equals("body")) { continue; } String[] values = data.get(key); for (String value : values) { try { ue.append(URLEncoder.encode(key, encoding)) .append("=") .append(URLEncoder.encode(value, encoding)) .append("&"); } catch (Exception e) { Logger.error(e, "Error (encoding ?)"); } } } return ue.toString(); }
public Map<String, String[]> all() { checkAndParse(); return data; }
public String[] getAll(String key) { if (!_contains(key)) { checkAndParse(); } return data.get(key); }
public void remove(String key) { checkAndParse(); data.remove(key); // make sure rootsParamsNode is regenerated if needed rootParamsNodeIsGenerated = false; }
public void put(String key, String[] values) { checkAndParse(); data.put(key, values); // make sure rootsParamsNode is regenerated if needed rootParamsNodeIsGenerated = false; }