/** * Parsing ctor * @param context How we lookup references * @param key The name of the variable that this was transfered as * @param type The type information from javascript * @param value The javascript variable converted to a string * @param has the data already been URL decoded? */ public InboundVariable(InboundContext context, String key, String type, String value, boolean urlDecoded) { this(context, key, type, new FormField(value), urlDecoded); }
public InputStream getInputStream() throws IOException { return formField.getInputStream(); }
/** * @return Returns the value. */ public String getValue() { return formField.getString(); }
if (formField.isFile()) InputStreamFactory inFactory = new SimpleInputStreamFactory(formField.getInputStream()); value = new FileTransfer(formField.getName(), formField.getMimeType(), formField.getFileSize(), inFactory); value = formField.getString();
return new FileTransfer(formField.getName(), formField.getMimeType(), formField.getFileSize(), inFactory); return formField.getInputStream(); return ImageIO.read(formField.getInputStream()); InputStream in = formField.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); CopyUtils.copy(in, out);
@Override public String toString() { if (formField == null) { return type + ProtocolConstants.INBOUND_TYPE_SEPARATOR + "null"; } return type + ProtocolConstants.INBOUND_TYPE_SEPARATOR + formField.toString(); }
@Override public int hashCode() { if (!dereferenced) { // dereference(); throw new IllegalStateException("hashCode() called before dereference()"); } int hash = 745; hash += (formField == null) ? 875 : formField.hashCode(); hash += (type == null) ? 346 : type.hashCode(); hash += (key == null) ? 768 : key.hashCode(); return hash; }
if (!this.formField.equals(that.formField))
public Object convertInbound(Class<?> paramType, InboundVariable data) throws ConversionException { if (data.isNull()) { return null; } if (data.getFormField().isFile()) { // Data from file uploads is not URL encoded return data.getValue(); } else { return data.urlDecode(); } }
/** * Parsing ctor * @param context How we lookup references * @param key The name of the variable that this was transfered as * @param type The type information from javascript * @param value The javascript variable converted to a string */ public InboundVariable(InboundContext context, String key, String type, String value) { this(context, key, type, new FormField(value)); }
if (formField != null) return formField.getString();
public void close() throws IOException { formField.getInputStream().close(); } };
/** * Sort out a single line in a POST request * @param line The line to parse * @param paramMap The map to add parsed parameters to */ private static void parsePostLine(String line, Map<String, FormField> paramMap) { if (line.length() == 0) { return; } int sep = line.indexOf(ProtocolConstants.INBOUND_DECL_SEPARATOR); if (sep == -1) { paramMap.put(line, null); } else { String key = line.substring(0, sep); String value = line.substring(sep + ProtocolConstants.INBOUND_DECL_SEPARATOR.length()); paramMap.put(key, new FormField(value)); } }
/** * Attempt to de-reference an inbound variable. * We try de-referencing as soon as possible (why? there is a good reason * for it, it fixes some bug, but I can't remember what right now) However * the referenced variable may not exist yet, so the de-referencing may * fail, requiring us to have another go later. * @throws ConversionException If cross-references don't add up */ public void dereference() throws ConversionException { int depth = 0; while (ProtocolConstants.TYPE_REFERENCE.equals(type)) { InboundVariable cd = context.getInboundVariable(formField.getString()); if (cd == null) { throw new ConversionException(getClass(), "Found reference to variable named '" + formField.getString() + "', but no variable of that name could be found."); } type = cd.type; formField = cd.getFormField(); key = cd.key; depth++; if (depth > 20) { throw new ConversionException(getClass(), "Max depth exceeded when dereferencing " + formField.getString()); } } dereferenced = true; }
convertedMap.put(key, new FormField(array[0]));
String value = entry.getValue().getString(); String line = key + ProtocolConstants.INBOUND_DECL_SEPARATOR + value;
paramMap.put(name, new FormField(req.getParameter(name)));