1 32 33 package com.knowgate.http.portlets; 34 35 import java.util.Hashtable ; 36 import java.util.Enumeration ; 37 import java.util.Properties ; 38 import java.util.Map ; 39 import java.util.Locale ; 40 import java.util.Locale ; 41 42 import java.io.IOException ; 43 import java.io.PrintWriter ; 44 import java.io.OutputStream ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.UnsupportedEncodingException ; 47 48 import javax.portlet.PortletURL; 49 import javax.portlet.RenderResponse; 50 51 import javax.servlet.http.HttpServletResponse ; 52 53 import com.knowgate.misc.Gadgets; 54 55 60 61 public class StringBufferRenderResponse implements RenderResponse { 62 63 private Properties oProps; 64 private ByteArrayOutputStream oBuf; 65 private PrintWriter oWrt; 66 private int iBufSize; 67 private String sEncoding; 68 69 public StringBufferRenderResponse (String encoding) { 70 sEncoding = encoding; 71 iBufSize = 4000; 72 oProps = new Properties (); 73 oBuf = new ByteArrayOutputStream (iBufSize); 74 oWrt = new PrintWriter (oBuf); 75 } 76 77 public void setProperty(String key, String value) { 78 oProps.setProperty (key, value); 79 } 80 81 public void addProperty(String key, String value) { 82 String sProp = oProps.getProperty(key); 83 84 if (sProp==null) 85 oProps.setProperty (key, value); 86 else { 87 oProps.remove(key); 88 oProps.setProperty(key, sProp + ";" + value); 89 } 90 } 91 92 public String encodeURL (String path) { 93 return Gadgets.URLEncode(path); 94 } 95 96 public String getContentType () { 97 throw new UnsupportedOperationException ("getContentType() not implemented HipergateRenderRequest"); 98 } 99 100 public PortletURL createRenderURL () { 101 throw new UnsupportedOperationException ("createRenderURL() not implemented HipergateRenderRequest"); 102 } 103 104 public PortletURL createActionURL () { 105 throw new UnsupportedOperationException ("createActionURL() not implemented HipergateRenderRequest"); 106 } 107 108 public String getNamespace () { 109 throw new UnsupportedOperationException ("getNamespace() not implemented HipergateRenderRequest"); 110 } 111 112 public void setTitle(String title) { 113 throw new UnsupportedOperationException ("setTitle() not implemented HipergateRenderRequest"); 114 } 115 116 public void setContentType(String type) { 117 throw new UnsupportedOperationException ("setContentType() not implemented HipergateRenderRequest"); 118 } 119 120 public String getCharacterEncoding() { 121 return sEncoding; 122 } 123 124 public PrintWriter getWriter() throws IOException { 125 return oWrt; 126 } 127 128 public Locale getLocale() { 129 throw new UnsupportedOperationException ("getLocale() not implemented HipergateRenderRequest"); 130 } 131 132 public void setBufferSize(int size) { 133 throw new UnsupportedOperationException ("setBufferSize() not implemented HipergateRenderRequest"); 134 } 135 136 public int getBufferSize() { 137 return iBufSize; 138 } 139 140 public void setCharacterEncoding(String encoding) { 141 sEncoding = encoding; 142 } 143 144 public void flushBuffer() throws IOException { 145 oWrt.flush(); 146 } 147 148 public void resetBuffer() { 149 oBuf.reset(); 150 } 151 152 public boolean isCommitted() { 153 throw new UnsupportedOperationException ("isCommitted() not implemented HipergateRenderRequest"); 154 } 155 156 public void reset() { 157 oBuf.reset(); 158 } 159 160 public OutputStream getPortletOutputStream() throws IOException { 161 return oBuf; 162 } 163 164 public String toString() { 165 String sRetVal; 166 167 try { 168 sRetVal = new String (oBuf.toByteArray(), sEncoding); 169 } 170 catch (UnsupportedEncodingException uee) { 171 sRetVal = new String (oBuf.toByteArray()); 172 } 173 174 return sRetVal; 175 } } 177 | Popular Tags |