1 16 17 package org.springframework.mock.web.portlet; 18 19 import java.io.BufferedReader ; 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.InputStreamReader ; 24 import java.io.Reader ; 25 import java.io.UnsupportedEncodingException ; 26 27 import javax.portlet.ActionRequest; 28 import javax.portlet.PortalContext; 29 import javax.portlet.PortletContext; 30 31 38 public class MockActionRequest extends MockPortletRequest implements ActionRequest { 39 40 private String characterEncoding; 41 42 private byte[] content; 43 44 private String contentType; 45 46 47 53 public MockActionRequest() { 54 super(); 55 } 56 57 62 public MockActionRequest(PortletContext portletContext) { 63 super(portletContext); 64 } 65 66 71 public MockActionRequest(PortalContext portalContext, PortletContext portletContext) { 72 super(portalContext, portletContext); 73 } 74 75 76 public void setContent(byte[] content) { 77 this.content = content; 78 } 79 80 public InputStream getPortletInputStream() throws IOException { 81 if (this.content != null) { 82 return new ByteArrayInputStream (this.content); 83 } 84 else { 85 return null; 86 } 87 } 88 89 public void setCharacterEncoding(String characterEncoding) { 90 this.characterEncoding = characterEncoding; 91 } 92 93 public BufferedReader getReader() throws UnsupportedEncodingException { 94 if (this.content != null) { 95 InputStream sourceStream = new ByteArrayInputStream (this.content); 96 Reader sourceReader = (this.characterEncoding != null) ? 97 new InputStreamReader (sourceStream, this.characterEncoding) : new InputStreamReader (sourceStream); 98 return new BufferedReader (sourceReader); 99 } 100 else { 101 return null; 102 } 103 } 104 105 public String getCharacterEncoding() { 106 return characterEncoding; 107 } 108 109 public void setContentType(String contentType) { 110 this.contentType = contentType; 111 } 112 113 public String getContentType() { 114 return contentType; 115 } 116 117 public int getContentLength() { 118 return (this.content != null ? content.length : -1); 119 } 120 121 } 122 | Popular Tags |