/** * Writes all parameters into the given {@link javax.script.ScriptContext} * * @param ctx the context to be filled with the internally stored name value pairs */ public void applyTo(ScriptContext ctx) { for (Entry<String, Object> e : entrySet()) { ctx.setAttribute(e.getKey(), e.getValue(), ScriptContext.ENGINE_SCOPE); } }
/** * Sents the given context as POST to the designated server. * * @param params the data to POST * @param charset the charset to use when encoding the post data * @return the outcall itself for fluent method calls * @throws IOException in case of any IO error */ public Outcall postData(Context params, Charset charset) throws IOException { connection.setRequestMethod(REQUEST_METHOD_POST); connection.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_FORM_URLENCODED); this.charset = charset; OutputStreamWriter writer = new OutputStreamWriter(getOutput(), charset.name()); StringBuilder sb = new StringBuilder(); boolean first = true; for (Map.Entry<String, Object> entry : params.entrySet()) { if (!first) { sb.append("&"); } first = false; sb.append(URLEncoder.encode(entry.getKey(), charset.name())); sb.append("="); sb.append(URLEncoder.encode(NLS.toMachineString(entry.getValue()), charset.name())); } writer.write(sb.toString()); writer.flush(); return this; }
protected void prepareValues(Context ctx, StringBuilder fields, StringBuilder values, List<Object> valueList) { for (Map.Entry<String, Object> entry : ctx.entrySet()) { if (entry.getValue() != null) { if (fields.length() > 0) { fields.append(", "); values.append(", "); } if (!SANE_COLUMN_NAME.matcher(entry.getKey()).matches()) { throw Exceptions.handle() .to(Databases.LOG) .withSystemErrorMessage("Cannot use '%s' as column name for an insert. " + "Only characters, digits and '_' is allowed!", entry.getKey()) .handle(); } fields.append(entry.getKey()); values.append("?"); valueList.add(Databases.convertValue(entry.getValue())); } } }