01: package test;
02:
03: import javax.portlet.GenericPortlet;
04: import javax.portlet.RenderRequest;
05: import javax.portlet.ActionRequest;
06: import javax.portlet.ActionResponse;
07: import javax.portlet.RenderResponse;
08: import javax.portlet.PortletException;
09: import javax.portlet.PortletURL;
10: import javax.portlet.PortletRequestDispatcher;
11: import javax.portlet.PortletContext;
12: import javax.portlet.PortletConfig;
13:
14: import java.io.IOException;
15: import java.io.PrintWriter;
16: import java.io.InputStream;
17:
18: import java.util.Map;
19: import java.util.HashMap;
20: import java.util.Iterator;
21:
22: public class InputStreamPortlet extends GenericPortlet {
23:
24: public void processAction(ActionRequest request,
25: ActionResponse response) throws PortletException {
26:
27: int contentLength = request.getContentLength();
28: int len = 0;
29:
30: try {
31: InputStream sin = request.getPortletInputStream();
32: if (sin != null) {
33: while (sin.read() != -1) {
34: len++;
35: }
36: }
37: } catch (IOException e) {
38: throw new PortletException(
39: "HelloWorldPortlet.processAction exception", e);
40: }
41:
42: Map nav = new HashMap();
43: nav.put("contentLength", Integer.toString(contentLength));
44: nav.put("inputStreamLen", Integer.toString(len));
45: response.setRenderParameters(nav);
46:
47: }
48:
49: public void doView(RenderRequest request, RenderResponse response)
50: throws PortletException, IOException {
51:
52: response.setContentType(request.getResponseContentType());
53: PortletURL actionURL = response.createActionURL();
54: PrintWriter writer = response.getWriter();
55:
56: writer
57: .write("<form enctype=\"multipart/form-data\" method=\"post\" action=\""
58: + actionURL.toString());
59:
60: writer
61: .write("\"><TABLE WIDTH=\"100%\"><TR><TD ALIGN=\"RIGHT\" ALIGN=\"TOP\">Filename:</TD><TD ALIGN=\"LEFT\"><INPUT TYPE=\"FILE\" NAME=\"FILE1\"></TD></TR><TR><TD ALIGN=\"RIGHT\"> </TD><TD ALIGN=\"LEFT\"><INPUT TYPE=\"SUBMIT\" NAME=\"SUB1\" VALUE=\"Upload File\"></TD></TR></TABLE></form>");
62:
63: writer.write("Parameter passed from processAction:<P>");
64: Map params = request.getParameterMap();
65: Iterator names = params.keySet().iterator();
66: while (names.hasNext()) {
67: String name = (String) names.next();
68: String value = (String) params.get(name);
69: writer.write(" " + name + " :" + value);
70: writer.write("<P>");
71: }
72: writer.write("<P>");
73: }
74:
75: }
|