Coverage Report - org.apache.commons.workflow.web.IncludeResponse23
 
Classes in this File Line Coverage Branch Coverage Complexity
IncludeResponse23
0%
0/46
0%
0/16
1.812
 
 1  
 /*
 2  
  * Copyright 1999-2001,2004 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 
 17  
 package org.apache.commons.workflow.web;
 18  
 
 19  
 
 20  
 import java.io.ByteArrayOutputStream;
 21  
 import java.io.CharArrayWriter;
 22  
 import java.io.IOException;
 23  
 import java.io.PrintWriter;
 24  
 import javax.servlet.ServletOutputStream;
 25  
 import javax.servlet.ServletResponse;
 26  
 import javax.servlet.ServletResponseWrapper;
 27  
 
 28  
 
 29  
 /**
 30  
  * <p>Implementation of <code>HttpServletResponseWrapper</code> for use in
 31  
  * <code>IncludeStep23</code>.  It buffers the response characters up into
 32  
  * a memory-resident buffer that can be converted into a String by calling
 33  
  * <code>getContent()</code>.</p>
 34  
  *
 35  
  * @version $Revision: 155475 $ $Date: 2005-02-26 13:31:11 +0000 (Sat, 26 Feb 2005) $
 36  
  * @author Craig R. McClanahan
 37  
  */
 38  
 
 39  
 public class IncludeResponse23 extends ServletResponseWrapper {
 40  
 
 41  
 
 42  
     // ----------------------------------------------------------- Constructors
 43  
 
 44  
 
 45  
     /**
 46  
      * Construct a new response wrapper according to the specified parameters.
 47  
      *
 48  
      * @param response The servlet response we are wrapping
 49  
      */
 50  
     public IncludeResponse23(ServletResponse response) {
 51  
 
 52  0
         super(response);
 53  
 
 54  0
     }
 55  
 
 56  
 
 57  
     // ----------------------------------------------------- Instance Variables
 58  
 
 59  
 
 60  
     /**
 61  
      * Accumulator for output that is generated via
 62  
      * <code>getOutputStream()</code>.
 63  
      */
 64  0
     protected ByteArrayOutputStream baos = null;
 65  
 
 66  
 
 67  
     /**
 68  
      * Accumulator for output that is generated via
 69  
      * <code>getWriter()</code>.
 70  
      */
 71  0
     protected CharArrayWriter caw = null;
 72  
 
 73  
 
 74  
     // --------------------------------------------------------- Public Methods
 75  
 
 76  
 
 77  
     /**
 78  
      * Swallow any attempt to flush the response buffer.
 79  
      */
 80  
     public void flushBuffer() throws IOException {
 81  
 
 82  
         ; // No action is required
 83  
 
 84  0
     }
 85  
 
 86  
 
 87  
     /**
 88  
      * Return the character encoding for the included response (if any).
 89  
      */
 90  
     public String getCharacterEncoding() {
 91  
 
 92  0
         return (null); // FIXME - getCharacterEncoding()
 93  
 
 94  
     }
 95  
 
 96  
 
 97  
     /**
 98  
      * Return the response data written to this response as a String.
 99  
      *
 100  
      * @exception IOException if a conversion error occurs
 101  
      */
 102  
     public String getContent() throws IOException {
 103  
 
 104  0
         String encoding = getCharacterEncoding();
 105  0
         if (baos != null) {
 106  0
             if (encoding == null)
 107  0
                 return (baos.toString());
 108  
             else
 109  0
                 return (baos.toString(encoding));
 110  0
         } else if (caw != null) {
 111  0
             return (caw.toString());
 112  
         } else {
 113  0
             return ("");
 114  
         }
 115  
 
 116  
     }
 117  
 
 118  
 
 119  
     /**
 120  
      * Return a ServletOutputStream that can be used to accumulate the response
 121  
      * data for the included resource.
 122  
      *
 123  
      * @exception IOException if an I/O error occurs
 124  
      */
 125  
     public ServletOutputStream getOutputStream() throws IOException {
 126  
 
 127  0
         if (caw != null)
 128  0
             throw new IllegalStateException("getWriter() already called");
 129  0
         baos = new ByteArrayOutputStream();
 130  
         //        return (new IncludeOutputStream23(this));
 131  0
         return (null); // FIXME - getOutputStream()
 132  
 
 133  
     }
 134  
 
 135  
 
 136  
     /**
 137  
      * Return a PrintWriter that can be used to accumulate the response data
 138  
      * for the included resource.
 139  
      *
 140  
      * @exception IOException if an I/O error occurs
 141  
      */
 142  
     public PrintWriter getWriter() throws IOException {
 143  
 
 144  0
         if (baos != null)
 145  0
             throw new IllegalStateException
 146  
                 ("getOutputStream() already called");
 147  0
         caw = new CharArrayWriter();
 148  
         //        return (new IncludeWriter23(this));
 149  0
         return (null); // FIXME - getWriter()
 150  
 
 151  
     }
 152  
 
 153  
 
 154  
     /**
 155  
      * Reset the response buffer and all headers.
 156  
      */
 157  
     public void reset() {
 158  
 
 159  0
         resetBuffer();
 160  
 
 161  0
     }
 162  
 
 163  
 
 164  
     /**
 165  
      * Reset the response buffer to contain no data.
 166  
      */
 167  
     public void resetBuffer() {
 168  
 
 169  0
         if (baos != null)
 170  0
             baos.reset();
 171  0
         else if (caw != null)
 172  0
             caw.reset();
 173  
 
 174  0
     }
 175  
 
 176  
 
 177  
     /**
 178  
      * Set the content type (and possibly the character encoding) of the
 179  
      * response data.
 180  
      *
 181  
      * @param contentType The new content type
 182  
      */
 183  
     public void setContentType(String contentType) {
 184  
 
 185  
         ; // FIXME - setContentType()
 186  
 
 187  0
     }
 188  
 
 189  
 
 190  
     // -------------------------------------------------------- Package Methods
 191  
 
 192  
 
 193  
     /**
 194  
      * Write a sequence of bytes to our accumulator.
 195  
      *
 196  
      * @param b The byte array
 197  
      */
 198  
     void write(byte b[]) {
 199  
 
 200  0
         baos.write(b, 0, b.length);
 201  
 
 202  0
     }
 203  
 
 204  
 
 205  
     /**
 206  
      * Write a sequence of bytes to our accumulator.
 207  
      *
 208  
      * @param b The byte array
 209  
      * @param off Starting offset
 210  
      * @param len Number of bytes to be written
 211  
      */
 212  
     void write(byte b[], int off, int len) {
 213  
 
 214  0
         baos.write(b, off, len);
 215  
 
 216  0
     }
 217  
 
 218  
 
 219  
     /**
 220  
      * Write a sequence of characters to our accumulator.
 221  
      *
 222  
      * @param c The character array
 223  
      */
 224  
     void write(char c[]) {
 225  
 
 226  0
         caw.write(c, 0, c.length);
 227  
 
 228  0
     }
 229  
 
 230  
 
 231  
     /**
 232  
      * Write a sequence of characters to our accumulator.
 233  
      *
 234  
      * @param c The character array
 235  
      * @param off Starting offset
 236  
      * @param len Number of bytes to be written
 237  
      */
 238  
     void write(char c[], int off, int len) {
 239  
 
 240  0
         caw.write(c, off, len);
 241  
 
 242  0
     }
 243  
 
 244  
 
 245  
     /**
 246  
      * Write a single byte or character (based on which accumulator has
 247  
      * been created) to our accumulator.
 248  
      *
 249  
      * @param value The byte or character to be written
 250  
      */
 251  
     void write(int value) {
 252  
 
 253  0
         if (baos != null)
 254  0
             baos.write(value);
 255  
         else
 256  0
             caw.write(value);
 257  
 
 258  0
     }
 259  
 
 260  
 
 261  
     /**
 262  
      * Write a sequence of characters to our accumulator.
 263  
      *
 264  
      * @param s The character string
 265  
      */
 266  
     void write(String s) {
 267  
 
 268  0
         caw.write(s, 0, s.length());
 269  
 
 270  0
     }
 271  
 
 272  
 
 273  
     /**
 274  
      * Write a sequence of characters to our accumulator.
 275  
      *
 276  
      * @param s The character string
 277  
      * @param off Starting offset
 278  
      * @param len Number of characters to write
 279  
      */
 280  
     void write(String s, int off, int len) {
 281  
 
 282  0
         caw.write(s, off, len);
 283  
 
 284  0
     }
 285  
 
 286  
 
 287  
 }