View Javadoc

    1   /*
    2    * $Id: StrutsBodyContent.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts2.views.jsp.ui;
    22
    23  import java.io.IOException;
    24  import java.io.Reader;
    25  import java.io.StringReader;
    26  import java.io.Writer;
    27
    28  import javax.servlet.jsp.JspWriter;
    29  import javax.servlet.jsp.tagext.BodyContent;
    30
    31
    32  /***
    33   * StrutsBodyContent
    34   */
    35  public class StrutsBodyContent extends BodyContent {
    36
    37      private StringBuffer buffer = new StringBuffer();
    38
    39
    40      public StrutsBodyContent(JspWriter jspWriter) {
    41          super(jspWriter);
    42      }
    43
    44
    45      public Reader getReader() {
    46          return new StringReader(buffer.toString());
    47      }
    48
    49      public int getRemaining() {
    50          return 0;
    51      }
    52
    53      public String getString() {
    54          return buffer.toString();
    55      }
    56
    57      public void clear() throws IOException {
    58          buffer = new StringBuffer();
    59      }
    60
    61      public void clearBuffer() throws IOException {
    62          clear();
    63      }
    64
    65      public void close() throws IOException {
    66          buffer = null;
    67      }
    68
    69      public void newLine() throws IOException {
    70          buffer.append("\n");
    71      }
    72
    73      public void print(boolean b) throws IOException {
    74          buffer.append(b);
    75      }
    76
    77      public void print(char c) throws IOException {
    78          buffer.append(c);
    79      }
    80
    81      public void print(int i) throws IOException {
    82          buffer.append(i);
    83      }
    84
    85      public void print(long l) throws IOException {
    86          buffer.append(l);
    87      }
    88
    89      public void print(float v) throws IOException {
    90          buffer.append(v);
    91      }
    92
    93      public void print(double v) throws IOException {
    94          buffer.append(v);
    95      }
    96
    97      public void print(char[] chars) throws IOException {
    98          buffer.append(chars);
    99      }
    100
    101     public void print(String s) throws IOException {
    102         buffer.append(s);
    103     }
    104
    105     public void print(Object o) throws IOException {
    106         buffer.append(o);
    107     }
    108
    109     public void println() throws IOException {
    110         newLine();
    111     }
    112
    113     public void println(boolean b) throws IOException {
    114         print(b);
    115         newLine();
    116     }
    117
    118     public void println(char c) throws IOException {
    119         print(c);
    120         newLine();
    121     }
    122
    123     public void println(int i) throws IOException {
    124         print(i);
    125         newLine();
    126     }
    127
    128     public void println(long l) throws IOException {
    129         print(l);
    130         newLine();
    131     }
    132
    133     public void println(float v) throws IOException {
    134         print(v);
    135         newLine();
    136     }
    137
    138     public void println(double v) throws IOException {
    139         print(v);
    140         newLine();
    141     }
    142
    143     public void println(char[] chars) throws IOException {
    144         print(chars);
    145         newLine();
    146     }
    147
    148     public void println(String s) throws IOException {
    149         print(s);
    150         newLine();
    151     }
    152
    153     public void println(Object o) throws IOException {
    154         print(o);
    155         newLine();
    156     }
    157
    158     /***
    159      * Write a portion of an array of characters.
    160      *
    161      * @param cbuf Array of characters
    162      * @param off  Offset from which to start writing characters
    163      * @param len  Number of characters to write
    164      * @throws IOException If an I/O error occurs
    165      */
    166     public void write(char[] cbuf, int off, int len) throws IOException {
    167         buffer.append(cbuf, off, len);
    168     }
    169
    170     public void writeOut(Writer writer) throws IOException {
    171         writer.write(buffer.toString());
    172     }
    173 }