You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2001/03/21 11:10:16 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/util/logger XByteBuffer.java XHttpServletRequestFacade.java XHttpServletResponseFacade.java XMLTestCaseGenerator.java XResponseHeader.java XServletInputStreamFacade.java XServletOutputStreamFacade.java XServletWriterFacade.java

juergen     01/03/21 02:10:15

  Added:       src/share/org/apache/slide/util/logger XByteBuffer.java
                        XHttpServletRequestFacade.java
                        XHttpServletResponseFacade.java
                        XMLTestCaseGenerator.java XResponseHeader.java
                        XServletInputStreamFacade.java
                        XServletOutputStreamFacade.java
                        XServletWriterFacade.java
  Log:
  Added request/response facades to enable logging and generation of test cases.
  
  Revision  Changes    Path
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XByteBuffer.java
  
  Index: XByteBuffer.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.io.*;
  import org.apache.slide.common.Domain;
  
  /**
   * Un-synchronized byte buffer. We have methods to write and read from the
   * buffer, and helpers can convert various data formats.
   *
   * The idea is to minimize the number of buffers and the amount of copy from
   * layer to layer. It's _not_ premature optimization - it's the way things
   * should work.
   *
   * The Request and Response will use several buffers, same for the protocol
   * adapters.
   *
   * Note that the Buffer owns his byte[], while the Chunk is just a light
   * cursor.
   *
   *
   * @author Costin Manolache
   */
  
  
  public class XByteBuffer {
      // everything happens inside one thread !!!
          
      protected static final int DEFAULT_BUFFER_SIZE = 8*1024;
      int defaultBufferSize = DEFAULT_BUFFER_SIZE;
      int bytesWritten = 0;
  
      /** The buffers
       */
      private byte buf[];
      private byte buf2[];
  
      /**
       * The index one greater than the index of the last valid byte in
       * the buffer.
       */
      public int count = 0;
      // count==-1 for end of stream
      
  
      public XByteBuffer() {
          buf = new byte[defaultBufferSize];
      }
  
      public void write(int b) throws IOException {
          if (count >= buf.length) {
              resize();
          }
          buf[count++] = (byte)b;
          bytesWritten++;
      }
  
      public void write(byte b[], int off, int len) throws IOException {
          int avail = buf.length - count;
          Domain.debug("ENTER: XByteBuffer:write(len="+len+") avail="+avail);
  
          if ( len > avail ) {
              int newLength = buf.length;
              do {
                  newLength = newLength + newLength / 2;
              } while ( newLength <= count + len );
              resize( newLength );
          }
  
          if ( len > 0 ) {
              System.arraycopy(b, off, buf, count, len);
              count += len;
              bytesWritten += len;
          }
          Domain.debug("LEAVE: XByteBuffer:write(len="+len+") bytesWritten="+bytesWritten);
          return;
      }
  
      /**
       * enlarge the buffer.
       * @pre   buf != null
       */
      private void resize() {
          resize( buf.length + buf.length / 2 );
      }
  
      /**
       * enlarge the buffer.
       * @pre   buf != null
       */
      private void resize( int neededSize ) {
          Domain.debug("XByteBuffer:resize( neededSize="+neededSize+")");
          buf2 = new byte[neededSize];
          System.arraycopy( buf, 0, buf2, 0, buf.length );
          buf = buf2;
          buf2 = null;
      }
  
      public boolean isContentWritten() {
      return bytesWritten!=0;
      }
      
      public void setBufferSize(int size) {
      if( size > buf.length ) {
          buf=new byte[size];
      }
      }
  
      public int getBufferSize() {
      return buf.length;
      }
  
  
      // -------------------- Utils
  
      public byte[] getBuffer() {
          return buf;
      }
  
      public String getBufferContent() {
          return new String( buf ).substring( 0, bytesWritten );
  //hak       return new String( buf );
      }
  
      public int getNumberOfBytesWritten() {
          return bytesWritten;
      }
      
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XHttpServletRequestFacade.java
  
  Index: XHttpServletRequestFacade.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/XHttpServletRequestFacade.java,v 1.1 2001/03/21 10:10:09 juergen Exp $
   * $Revision: 1.1 $
   * $Date: 2001/03/21 10:10:09 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.slide.util.logger;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpSession;
  import javax.servlet.ServletInputStream;
  import javax.servlet.RequestDispatcher;
  
  import java.io.InputStream;
  import java.io.BufferedInputStream;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import java.util.Enumeration;
  import java.util.Locale;
  import java.security.Principal;
  
  import org.apache.slide.util.logger.XServletInputStreamFacade;
  
  import org.apache.slide.common.Domain;
  
  /**
   * This class supports additional set-methods and a re-readable
   * inputstream to the interface javax.servlet.http.HttpServletRequest.
   *
   * @author    Hardy.Kiefer@softwareag.com
   *
   * @version   0.1
   *
   * @invariant (inputStream != null)
   *
   * @see       javax.servlet.http.HttpServletRequest
   *
   */
  public class XHttpServletRequestFacade implements HttpServletRequest {
          
              
      public static final String DEFAULT_CHAR_ENCODING = "8859_1";
  
      /**
       * the HttpServletRequest to re-read.
       *
       * @invariant (req != null)
       *
       * @see javax.servlet.http.HttpServletRequest
       */
      private HttpServletRequest request;
  
          
      /**
       * the inputstream to re-read.
       *
       * @see java.io.BufferedInputStream
       */
      private XServletInputStreamFacade inStreamFacade = null;
              
      /**
       * buffered reader which uses the input stream
       *
       * @see java.io.BufferedReader
       */
      private BufferedReader reader = null;
          
      /**
       * true - if inputstream can read using a reader; false otherwise.
       */
      private boolean usingReader = false;
  
      /**
       * true - if inputstream can read using a stream; false otherwise.
       */
      private boolean usingStream = false;
          
          
      /**
       * This constructor creates an re-readable HttpServletRequest.
       *
       * @pre        (req != null)
       * @post
       *
       * @param      req   HttpServletRequest
       *
       * @exception
       *
       * @time
       * @space
       *
       * @see
       */
      public XHttpServletRequestFacade (HttpServletRequest request)  {
          Domain.debug("Create XHttpServletRequestFacade");
          this.request = request;
      }
  
      /**
       * Returns the value of the named attribute as an Object,
       * or null if no attribute of the given name exists.
       *
       * @param      name   the named attribute
       *
       * @return     Returns the value of the named attribute as an Object
       */
      public Object getAttribute(String name) {
          return request.getAttribute(name);
      }
  
      /**
       * Returns an Enumeration containing the names of the attributes
       * available to this request.
       *
       * @param      name   the named attribute
       *
       * @return     Returns an Enumeration containing the names of the attributes
       */
      public Enumeration getAttributeNames() {
          return request.getAttributeNames();
      }
  
      /**
       * Stores an attribute in this request.
       *
       * @param      attribute name
       * @param      attribute value
       *
       * @return     none
       */
      public void setAttribute(String name, Object value) {
          request.setAttribute(name, value);
      }
  
      /**
       * Removes an attribute from this request.
       *
       * @param      attribute name
       *
       * @return     none
       */
      public void removeAttribute(String name) {
          request.removeAttribute(name);
      }
  
      /**
       * Returns the name of the character encoding used in the body of this request.
       *
       * @param      none
       *
       * @return     Returns the name of the character encoding
       */
      public String getCharacterEncoding() {
          return request.getCharacterEncoding();
      }
  
      /**
       * Returns the length, in bytes, of the request body
       * and made available by the input stream, or -1 if the length is not known.
       *
       * @param      none
       *
       * @return     Returns the length
       */
      public int getContentLength() {
          return request.getContentLength();
      }
  
      /**
       * Returns the MIME type of the body of the request,
       * or null if the type is not known.
       *
       * @param      none
       *
       * @return     Returns the MIME type
       */
      public String getContentType() {
          return request.getContentType();
      }
  
      /**
       * Returns an array containing all of the Cookie objects
       * the client sent with this request.
       *
       * @param      none
       *
       * @return     Returns the Cookie objects
       */
      public Cookie[] getCookies() {
          return request.getCookies();
      }
  
      /**
       * Returns the value of the specified request header
       * as a long value that represents a Date object.
       *
       * @param      name
       *
       * @return     Returns a long value representing the date
       */
      public long getDateHeader(String name) {
          return request.getDateHeader(name);
      }
  
      /**
       * Returns the value of the specified request header as a String.
       *
       * @param      name
       *
       * @return     Returns the header
       */
      public String getHeader(String name) {
          return request.getHeader(name);
      }
  
      /**
       * Returns all the values of the specified request header as an Enumeration of String objects.
       *
       * @param      name
       *
       * @return     Returns an enumeration of all the header names
       */
      public Enumeration getHeaders(String name) {
          return request.getHeaders(name);
      }
  
      /**
       * Returns an enumeration of all the header names this request contains.
       *
       * @param      none
       *
       * @return     Returns an enumeration of all the header names
       */
      public Enumeration getHeaderNames() {
          return request.getHeaderNames();
      }
  
      /**
       * Retrieves the body of the request as binary data using a ServletInputStream.
       *
       * @param      none
       *
       * @return     Returns the body of the request
       */
      public ServletInputStream getInputStream() throws IOException {
          Domain.debug("ENTER: XHttpServletRequestFacade:getInputStream()");
          if (usingReader) {
              throw new IllegalStateException("getReader() method has been called on this request");
          }
          usingStream = true;
          
          if ( inStreamFacade == null ) {
              inStreamFacade = new XServletInputStreamFacade( request.getInputStream());
          }
              
          Domain.debug("LEAVE: XHttpServletRequestFacade:getInputStream()");
          return (  inStreamFacade );
      }
  
          
      /**
       *  Reads the next byte of data from the input stream.
       *
       * @param      none
       *
       * @return     the next byte of data, or -1 if the end of the stream is reached
       */
      public int doRead() throws IOException {
          return inStreamFacade.read();
      }
  
      /**
       *  Reads up to len bytes of data from the input stream into an array of bytes.
       *
       * @param      b - the buffer into which the data is read.
       * @param      off - the start offset in array b at which the data is written.
       * @param      len - the maximum number of bytes to read.
       *
       * @return     the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
       */
      public int doRead( byte b[], int off, int len ) throws IOException {
          return inStreamFacade.read( b, off, len );
      }
  
          
      /**
       * Returns the value of the specified request header as an int.
       *
       * @param      parameter name
       *
       * @return     Returns the value
       */
      /** Adapter: Tomcat Request doesn't deal with header to int conversion.
       */
      public int getIntHeader(String name)
      throws  NumberFormatException
      {
      String value=request.getHeader( name );
      if( value==null) return -1;
      int valueInt=Integer.parseInt(value);
      return valueInt;
      }
  
      /**
       * Returns the name of the HTTP method with which
       * this request was made, for example, GET, POST, or PUT.
       *
       * @param      none
       *
       * @return     Returns the method name
       */
      public String getMethod() {
          return request.getMethod();
      }
  
      /**
       * Returns the value of a request parameter as a String,
       * or null if the parameter does not exist.
       *
       * @param      parameter name
       *
       * @return     Returns the value
       */
      /** Adapter: Request doesn't deal with this servlet convention
       */
      public String getParameter(String name) {
          return request.getParameter( name );
      }
  
      /**
       * Returns an array of String objects containing all of the values
       * the given request parameter has, or null if the parameter does not exist.
       *
       * @param      parameter name
       *
       * @return     Returns parameter values
       */
      public String[] getParameterValues(String name) {
          return request.getParameterValues(name);
      }
  
      /**
       * Returns an Enumeration of String objects containing
       * the names of the parameters contained in this request.
       *
       * @param      none
       *
       * @return     Returns an Enumeration of String objects
       */
      /** Adapter: Request doesn't deal with this servlet convention
       */
      public Enumeration getParameterNames() {
          return request.getParameterNames();
      }
      
      /**
       * Returns any extra path information associated with the
       * URL the client sent when it made this request.
       *
       * @param      none
       *
       * @return     Returns any extra path information
       */
      public String getPathInfo() {
          return request.getPathInfo();
      }
  
      /**
       * Returns any extra path information after the servlet
       * name but before the query string, and translates it to a real path.
       *
       * @param      none
       *
       * @return     Returns any extra path information after the servlet name
       */
      public String getPathTranslated() {
          return request.getPathTranslated();
      }
  
      /**
       * Returns the name and version of the protocol the request
       * uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
       *
       * @param      none
       *
       * @return     Returns the name and version of the protocol
       */
      public String getProtocol() {
          return request.getProtocol();
      }
  
      /**
       * Returns the query string that is contained in the request URL after the path.
       *
       * @param      none
       *
       * @return     Returns the query string
       */
      public String getQueryString() {
          return request.getQueryString();
      }
  
  
      /**
       * Returns the login of the user making this request,
       * if the user has been authenticated, or null if the user has not been authenticated.
       *
       * @param      none
       *
       * @return     Returns the login of the user making this request
       */
      public String getRemoteUser() {
          return request.getRemoteUser();
      }
  
      /**
       * Returns the name of the scheme used to make this request,
       * for example, http, https, or ftp.
       *
       * @param      none
       *
       * @return     Returns the name of the scheme
       */
      public String getScheme() {
          return request.getScheme();
      }
  
      /**
       * Returns the host name of the server that received the request.
       *
       * @param      none
       *
       * @return     Returns the host name of the server
       */
      public String getServerName() {
          return request.getServerName();
      }
  
      /**
       * Returns the port number on which this request was received.
       *
       * @param      none
       *
       * @return     Returns the port number
       */
      public int getServerPort() {
          return request.getServerPort();
      }
  
      /**
       * Retrieves the body of the request as character data using a BufferedReader.
       *
       * @param      none
       *
       * @return     Returns a BufferedReader
       */
      public BufferedReader getReader() throws IOException {
          Domain.debug("ENTER: XHttpServletRequestFacade:getReader()");
          if (usingStream) {
              throw new IllegalStateException("getInputStream() method has been called on this request");
          }
          usingReader = true;
  
          if ( inStreamFacade == null ) {
              inStreamFacade = new XServletInputStreamFacade( request.getInputStream());
          }
  
          if( reader != null ) {
              Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - reader != null");
              return reader; // method already called
          }
  
          String encoding = request.getCharacterEncoding();
          if (encoding == null) {
              encoding = DEFAULT_CHAR_ENCODING;
          }
      
          InputStreamReader r = new InputStreamReader(inStreamFacade, encoding);
          reader= new BufferedReader(r);
          Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - new BufferedReader");
          return reader;
      }
  
      /**
       * Returns the Internet Protocol (IP) address of the client that sent the request
       *
       * @param      none
       *
       * @return     Returns IP address
       */
      public String getRemoteAddr() {
          return request.getRemoteAddr();
      }
  
      /**
       * Returns the fully qualified name of the client
       * that sent the request, or the IP address of the client
       * if the name cannot be determined.
       *
       * @param      none
       *
       * @return     Returns client name
       */
      public String getRemoteHost() {
          return request.getRemoteHost();
      }
  
      /**
       * Returns the part of this request's URL from the
       * protocol name up to the query string in the first line of the HTTP request.
       *
       * @param      none
       *
       * @return     Returns the part of this request's URL
       */
      public String getRequestURI() {
          return request.getRequestURI();
      }
  
      /**
       * Returns a RequestDispatcher object that acts as a wrapper
       * for the resource located at the given path.
       *
       * @param      path
       *
       * @return     Returns  RequestDispatcher
       */
      public RequestDispatcher getRequestDispatcher(String path) {
          return request.getRequestDispatcher(path);
      }
  
      /**
       * Returns the preferred Locale that the client will accept content in,
       * based on the Accept-Language header.
       *
       * @param      none
       *
       * @return     Returns the preferred Locale
       */
  
      /** Adapter: first elelment
       */
      public Locale getLocale() {
      return (Locale)getLocales().nextElement();
      }
  
      /**
       * Returns an Enumeration of Locale objects indicating,
       * in decreasing order starting with the preferred locale,
       * the locales that are acceptable to the client based on the Accept-Language header.
       *
       * @param      none
       *
       * @return     Returns an Enumeration of Locale objects
       */
      /** Delegate to RequestUtil
       */
      public Enumeration getLocales() {
          return request.getLocales();
      }
          
      /**
       * Returns the portion of the request URI that indicates
       * the context of the request.
       *
       * @param      none
       *
       * @return     Returns the URI
       */
      /** Delegate to Context
       */
      public String getContextPath() {
          return request.getContextPath();
      }
  
      /**
       * Returns the part of this request's URL that calls the servlet.
       *
       * @param      none
       *
       * @return     Returns the part of this request's URL that calls the servlet
       */
      public String getServletPath() {
          return request.getServletPath();
      }
  
      /**
       * Deprecated. As of Version 2.1 of the Java Servlet API,
       * use ServletContext.getRealPath(java.lang.String) instead.
       *
       * @deprecated
       *
       * @param      parameter name
       *
       * @return     Returns the value
       */
      public String getRealPath(String name) {
          return request.getRealPath(name);
      }
      
      // -------------------- Security --------------------
          
          
      /**
       * Returns the name of the authentication scheme
       * used to protect the servlet, for example,
       * "BASIC" or "SSL," or null if the servlet was not protected.
       *
       * @param      none
       *
       * @return     Returns the name of the authentication scheme
       */
      public String getAuthType() {
          return request.getAuthType();
      }
  
      /**
       * Returns a boolean indicating whether this request was made
       * using a secure channel, such as HTTPS.
       *
       * @param      none
       *
       * @return     Returns a boolean
       */
      public boolean isSecure() {
          return request.isSecure();
      }
  
      /**
       * Returns a boolean indicating whether the authenticated
       * user is included in the specified logical "role".
       *
       * @param      role - a String specifying the name of the role
       *
       * @return     Returns a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated
       */
      public boolean isUserInRole(String role) {
          return request.isUserInRole(role);
      }
  
      /**
       * Returns a java.security.Principal object containing the
       * name of the current authenticated user.
       *
       * @param      none
       *
       * @return     Returns a java.security.Principal object
       */
      public Principal getUserPrincipal() {
          return request.getUserPrincipal();
      }
      
      // -------------------- Session --------------------
  
      /**
       * Returns the current session associated with this request,
       * or if the request does not have a session, creates one.
       *
       * @param      none
       *
       * @return     Returns the current session
       */
      public HttpSession getSession() {
          return request.getSession(true);
      }
  
      /**
       * Returns the current HttpSession associated with this request
       * or, if if there is no current session and create is true, returns a new session.
       *
       * @param      true - to create a new session for this request if necessary;
       *             false  to return null if there's no current session
       *
       * @return     Returns the HttpSession associated with this request or null
       *             if create is false and the request has no valid session
       */
      public HttpSession getSession(boolean create) {
          return request.getSession( create );
      }
  
      /**
       * Returns the session ID specified by the client.
       *
       * @param      none
       *
       * @return     Returns the session ID
       */
      public String getRequestedSessionId() {
          return request.getRequestedSessionId();
      }
      
      /**
       * Checks whether the requested session ID is still valid.
       *
       * @param      none
       *
       * @return     Returns true if this request has an id for a valid session in the current session context; false otherwise
       */
      public boolean isRequestedSessionIdValid() {
      // so here we just assume that if we have a session it's,
      // all good, else not.
      HttpSession session = (HttpSession)request.getSession(false);
      return (session != null);
      }
  
      /**
       * Checks whether the requested session ID came in as a cookie.
       *
       * @param      none
       *
       * @return     Returns true if the session ID came in as a cookie; otherwise, false
       */
      public boolean isRequestedSessionIdFromCookie() {
          return request.isRequestedSessionIdFromCookie();
      }
  
      /**
       * Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead
       *
       * @param      none
       * @deprecated
       *
       * @return
       */
      public boolean isRequestedSessionIdFromUrl() {
          return isRequestedSessionIdFromURL();
      }
  
      /**
       * Checks whether the requested session ID came in as part of the request URL.
       *
       * @param      none
       *
       * @return     true if the session ID came in as part of a URL; otherwise, false
       */
      public boolean isRequestedSessionIdFromURL() {
          return request.isRequestedSessionIdFromURL();
      }
      
      /**
       * Returns the content of the buffered input stream.
       *
       * @return      copy of input stream as string.
       */
      public String getRequestBody() throws IOException {
          if ( usingStream ){
              Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingStream");
              return inStreamFacade.getBufferContent();
          } else if ( usingReader ) {
              Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingReader");
              return reader.toString();
          } else {
              Domain.debug("XHttpServletRequestFacade:getRequestBody() - nor Reader nor Stream - do nothing");
              return "";
          }
      }
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XHttpServletResponseFacade.java
  
  Index: XHttpServletResponseFacade.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/XHttpServletResponseFacade.java,v 1.1 2001/03/21 10:10:09 juergen Exp $
   * $Revision: 1.1 $
   * $Date: 2001/03/21 10:10:09 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.io.Writer;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.io.BufferedOutputStream;
  import java.io.IOException;
  // import java.net.*;
  import java.util.Locale;
  import java.util.Enumeration;
  import java.util.Vector;
  // import java.lang.IllegalArgumentException;
  import javax.servlet.http.Cookie;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.slide.common.Domain;
  
  /**
   * This class supports additional set-methods and a re-readable
   * inputstream to the interface javax.servlet.http.HttpServletResponse.
   *
   * @author    Hardy.Kiefer@softwareag.com
   *
   * @version   0.1
   *
   * @invariant (inputStream != null)
   *
   * @see       javax.servlet.http.HttpServletResponse
   *
   */
  public class XHttpServletResponseFacade  implements HttpServletResponse
  {
  
      
      public static final String DEFAULT_CHAR_ENCODING = "8859_1";
  
      
      // default implementation will just append everything here
      StringBuffer body=null;
  
      /**
       * the HttpServletResponse to re-read.
       *
       * @invariant (response != null)
       *
       * @see javax.servlet.http.HttpServletResponse
       */
      private HttpServletResponse response;
  
      protected HttpServletRequest request;
      
      public void setRequest(HttpServletRequest request) {
      this.request = request;
      }
  
      public HttpServletRequest getRequest() {
      return request;
      }
      
      /**
       * true - if outputstream can write using a stream; false otherwise.
       */
      private boolean usingStream = false;
      
      /**
       * true - if outputstream can write using a writer; false otherwise.
       */
      private boolean usingWriter = false;
  
      /**
       * output stream used for building the writer.
       *
       * @see javax.servlet.ServletOutputStream
       */
      XServletOutputStreamFacade osFacade = null;
      
      /**
       * writer which uses the output stream.
       *
       * @see java.io.PrintWriter
       */
      PrintWriter writer = null;
  
      /**
       * response headers
       */
      Vector responseHeaders = new Vector();
      public Enumeration getResponseHeaders() {
          return responseHeaders.elements();
      }
      
      
      /**
       * This constructor creates an re-writable HttpServletRes�pmse.
       *
       * @pre        (response != null)
       * @post
       *
       * @param      response   HttpServletResponse
       *
       * @exception
       *
       * @time
       * @space
       *
       * @see
       */
      public XHttpServletResponseFacade(HttpServletResponse response) {
          Domain.debug("Create XHttpServletResponseFacade");
          this.response = response;
      }
  
  
      // -------------------- Public methods --------------------
  
      /**
       * Adds the specified cookie to the response.
       *
       * @param      cookie - the Cookie to return to the client
       *
       * @return     none
       */
      public void addCookie(javax.servlet.http.Cookie cookie) {
          responseHeaders.add(
              new XResponseHeader(
                  "Cookie",
                  cookie.getName() + " " +
                  cookie.getValue() + " " +
                  cookie.getDomain()
                  )
              );
          response.addCookie(cookie);
      }
  
      /**
       * Returns a boolean indicating whether the named response header has already been set.
       *
       * @param      name - the header name
       *
       * @return     true if the named response header has already been set; false otherwise
       */
      public boolean containsHeader(String name) {
          return response.containsHeader(name);
      }
  
      /**
       * Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
       *
       * @param      url - the url to be encoded.
       *
       * @return     the encoded URL if encoding is needed; the unchanged URL otherwise.
       */
      public String encodeRedirectURL(String location) {
          return response.encodeRedirectURL(location);
      }
  
      /**
       * Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead
       *
       * @param      url - the url to be encoded.
       *
       * @return     the encoded URL if encoding is needed; the unchanged URL otherwise.
       * @deprecated
       */
      public String encodeRedirectUrl(String location) {
          return encodeRedirectURL(location);
      }
  
      /**
       * Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.
       *
       * @param      url - the url to be encoded.
       *
       * @return     the encoded URL if encoding is needed; the unchanged URL otherwise.
       */
      public String encodeURL(String url) {
          return response.encodeUrl(url);
      }
  
      /**
       * Deprecated. As of version 2.1, use encodeURL(String url) instead.
       *
       * @param      url - the url to be encoded.
       *
       * @return     the encoded URL if encoding is needed; the unchanged URL otherwise.
       *
       * @deprecated
       */
      public String encodeUrl(String url) {
      return encodeURL(url);
      }
  
      /**
       * Returns the name of the charset used for the MIME body sent in this response.
       *
       * @return     a String specifying the name of the charset, for example, ISO-8859-1
       */
      public String getCharacterEncoding() {
          return response.getCharacterEncoding();
      }
  
      /**
       * Returns a ServletOutputStream suitable for writing binary data in the response.
       *
       * @return     a ServletOutputStream for writing binary data
       */
      public ServletOutputStream getOutputStream()
          throws IOException {
          Domain.debug("ENTER: XHttpServletResponseFacade:getOutputStream()");
          if ( usingWriter ) {
              throw new IllegalStateException("Writer is already being used for this response");
          }
          usingStream = true;
  
          if( osFacade == null ) {
              osFacade = new XServletOutputStreamFacade(
                  response.getOutputStream(),
                  response.getCharacterEncoding());
          }
              
          Domain.debug("LEAVE: XHttpServletResponseFacade:getOutputStream()");
          return osFacade;
      }
  
      /**
       * Returns a PrintWriter object that can send character text to the client.
       *
       * @return     a PrintWriter object that can return character data to the client
       */
      public PrintWriter getWriter() throws IOException {
          Domain.debug("ENTER: XHttpServletResponseFacade:getWriter()");
          if (usingStream) {
              throw new IllegalStateException("OutputStream is already being used for this response");
          }
          usingWriter= true ;
  
        if( writer == null ) {
            writer = new XServletWriterFacade( response.getWriter() );
        }
  
          Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter()");
          return writer;
      }
  
      public PrintWriter getWriter(ServletOutputStream outs) throws IOException {
          Domain.debug("ENTER: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
          if(writer!=null) return writer;
          // it already did all the checkings
      
          //hak started = true;
          usingWriter = true;
      
          //  writer = new XServletWriterFacade( getConverter(outs), this);
          Domain.debug("LEAVE: XHttpServletResponseFacade:getWriter(ServletOutputStream)");
          return writer;
      }
  
      public Writer getConverter( ServletOutputStream outs ) throws IOException {
          String encoding = getCharacterEncoding();
          OutputStreamWriter osWriter;
          if (encoding == null) {
              // use default platform encoding - is this correct ?
              osWriter = new OutputStreamWriter(outs);
          } else {
              try {
                  osWriter = new OutputStreamWriter(outs, encoding);
              } catch (java.io.UnsupportedEncodingException ex) {
                  // XXX log it
                  System.out.println("Unsuported encoding: " + encoding );
                  return new OutputStreamWriter(outs);
              }
          }
          return osWriter;
      }
  
      /**
       * Sends an error response to the client using the specified status.
       *
       * @param      sc - the error status code.
       */
      public void sendError(int sc) throws IOException {
          sendError(sc, "No detailed message");
      }
  
      /**
       * Sends an error response to the client using the specified status code and descriptive message.
       *
       * @param      sc - the error status code
       *            msg - the descriptive message
       */
      public void sendError(int sc, String msg) throws IOException {
          response.sendError(sc, msg);
      }
  
      /**
       * Sends a temporary redirect response to the client using the specified redirect location URL.
       *
       * @param      location - the redirect location URL
       */
      public void sendRedirect(String location)
          throws IOException, IllegalArgumentException {
          response.sendRedirect(location);
      }
  
      private int contentLength = 0;
      /**
       * Sets the content type of the response being sent to the client.
       *
       * @param      len - an integer specifying the length of the content being returned to the client; sets the Content-Length header
       */
      public void setContentLength(int len) {
          contentLength = len;
          response.setContentLength(len);
      }
  
      public int getContentLength() {
          return contentLength;
      }
  
      
      private String contentType;
      /**
       * Sets the content type of the response being sent to the client.
       *
       * @param      type - a String specifying the MIME type of the content
       */
      public void setContentType(String type) {
          contentType = type;
          response.setContentType(type);
      }
  
      public String getContentType() {
          return contentType;
      }
  
      /**
       * Sets a response header with the given name and date-value.
       *
       * @param      name - the name of the header to set
       *            value - the assigned date value
       */
      public void setDateHeader(String name, long date) {
          responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
          response.setDateHeader(name, date);
      }
  
      /**
       * Adds a response header with the given name and date-value.
       *
       * @param      name - the name of the header to set
       *            value - the additional date value
       */
      public void addDateHeader(String name, long date) {
          responseHeaders.add(new XResponseHeader(name, String.valueOf(date)));
          response.addDateHeader(name, date);
      }
  
      /**
       * Sets a response header with the given name and value.
       *
       * @param      name - the name of the header
       *            value - the header value
       */
      public void setHeader(String name, String value) {
          responseHeaders.add(new XResponseHeader(name, value));
          response.setHeader(name, value);
      }
  
      /**
       * Adds a response header with the given name and value.
       *
       * @param      name - the name of the header
       *            value - the header value
       */
      public void addHeader(String name, String value) {
          responseHeaders.add(new XResponseHeader(name, value));
          response.addHeader(name, value);
      }
  
      /**
       * Sets a response header with the given name and integer value.
       *
       * @param      name - the name of the header
       *            value - the assigned integer value
       */
      public void setIntHeader(String name, int value) {
          responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
          response.setHeader(name, Integer.toString(value));
      }
  
      /**
       * Adds a response header with the given name and integer value.
       *
       * @param      name - the name of the header
       *            value - the assigned integer value
       */
      public void addIntHeader(String name, int value) {
          responseHeaders.add(new XResponseHeader(name, String.valueOf(value)));
          response.addHeader(name, Integer.toString(value));
      }
  
      /**
       * Sets the status code for this response.
       *
       * @param      sc - the status code
       */
      public void setStatus(int sc) {
          status = sc;
          response.setStatus(sc);
      }
  
      private int bufferSize = 0;
      /**
       * Sets the preferred buffer size for the body of the response.
       *
       * @param      size - the preferred buffer size
       */
      public void setBufferSize(int size) throws IllegalStateException {
          bufferSize = size;
          response.setBufferSize(size);
      }
  
      /**
       * Returns the actual buffer size used for the response.
       *
       * @return      the actual buffer size used
       */
      public int getBufferSize() {
          return response.getBufferSize();
      }
  
      /**
       * Clears any data that exists in the buffer as well as the status code and headers.
       */
      public void reset() throws IllegalStateException {
          response.reset();
      }
  
      /**
       * Returns a boolean indicating if the response has been committed.
       *
       * @return      a boolean indicating if the response has been committed
       */
      public boolean isCommitted() {
          return response.isCommitted();
      }
  
      /**
       * Forces any content in the buffer to be written to the client.
       */
      public void flushBuffer() throws IOException {
          response.flushBuffer();
      }
  
      /**
       * Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.
       *
       * @param      loc - the locale of the response
       */
      public void setLocale(Locale loc) {
          response.setLocale(loc);
      }
  
      /**
       * Returns the locale assigned to the response.
       *
       * @return      the locale assigned to the response.
       */
      public Locale getLocale() {
          return response.getLocale();
      }
  
      /**
       *
       * @deprecated
       */
      private int status = -1;
      private String msg = "";
      public void setStatus(int sc, String msg) {
          status = sc;
          msg = msg;
          response.setStatus(sc);
      }
      public int getStatus() {
          return status;
      }
      public String getMessage() {
          return msg;
      }
  
      /**
       * Returns the content of the buffered output stream.
       *
       * @return      copy of outputstream as string.
       */
      public String getResponseBody() throws IOException {
          if ( usingStream ) {
              Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingStream");
              return osFacade.getOutputBuffer();
          } else if ( usingWriter ) {
              Domain.debug("XHttpServletResponseFacade:getResponseBody() - usingWriter");
              return (( XServletWriterFacade )writer).getOutputBuffer();
          } else {
              Domain.debug("XHttpServletResponseFacade:getResponseBody() - nor writer nor stream - osFacade = " + osFacade + " writer = " + writer);
              return "";
          }
      }
  
  
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XMLTestCaseGenerator.java
  
  Index: XMLTestCaseGenerator.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.util.Enumeration;
  import java.io.StringReader;
  import java.io.IOException;
  
  import org.apache.slide.webdav.common.WebdavStatus;
  
  import org.jdom.Element;
  import org.jdom.JDOMException;
  import org.jdom.input.SAXBuilder;
  import org.jdom.output.XMLOutputter;
  
  
   
  /**
   * This class writes the header, the command and the body of an HTML request
   * or response in an XML structure.
   *
   * @author Hardy Kiefer, Software AG, Germany
   */
  
  
  public class XMLTestCaseGenerator {
      
      /**
       * constants
       */
      private static final String           CRLF = System.getProperty("line.separator");
      private static final String XML_MASK_BEGIN = "<![CDATA[";
      private static final String   XML_MASK_END = "]]>";
      private static final String SEPARATOR_LINE = "CRLF+<! --------------------------- END OF COMMAND ------------------------ >+CRLF";
  
      
      private XHttpServletRequestFacade request;
      private XHttpServletResponseFacade response;
      
      
          
      /*
       * Name of the thread
       */
      private String threadName;
      
      public void setThreadName( String threadName ) {
          this.threadName = threadName;
      }
      public String getThreadName() {
          return threadName;
      }
      
      
      /*
       * Constructs an XMLTestCaseGenerator object.
       */
      public XMLTestCaseGenerator( XHttpServletRequestFacade request, XHttpServletResponseFacade response){
          this.request = request;
          this.response = response;
      }
      
      /*
       * this method writes the data as XML.
       */
      public String toString() {
  //hak       String result = new String( printXMLheader() + printXMLbody() + SEPARATOR_LINE);
          String result = new String( printXMLbody());
          try {
              Element elem = (new SAXBuilder(false).build(new StringReader(result)).getRootElement());
              result = new XMLOutputter(" ", true).outputString(elem);
          }
          catch (JDOMException e) {
              e.printStackTrace();
          }
          catch (IOException e) {
              e.printStackTrace();
          }
          return result;
      }
  
      /*
       * this method prints the XML test attribute.
       */
      private String printXMLbody() {
          String result;
          result = printXMLstep();
          return result;
      }
      /*
       * this method prints the XML step attribute.
       */
      private String printXMLstep() {
          String result = new String("<step executeIn=\"" + getThreadName() + "\">");
          result = result + printXMLrequest();
          result = result + printXMLresponse();
          result = result + "</step>";
          return result;
      }
      /*
       * this method prints the XML request attribute.
       */
      private String printXMLrequest() {
          String result = new String("<request>");
          result = result + printXMLrequestCommand();
          result = result + printXMLrequestHeaders();
          result = result + printXMLrequestBody();
          result = result + "</request>";
          return result;
      }
                                    
      /*
       * this method prints the XML request attribute.
       */
      private String printXMLresponse() {
          String result = new String("<response>");
          result = result + printXMLresponseCommand();
          result = result + printXMLresponseHeaders();
          result = result + printXMLresponseBody();
          result = result + "</response>";
          return result;
      }
                                    
      /*
       * this method prints the XML request command attribute.
       */
      private String printXMLrequestCommand() {
          String result = new String("<command>");
          result = result + request.getMethod() + " " + request.getRequestURI() + " " + getProtocol();
          result = result + "</command>";
          return result;
      }
                                    
      /*
       * this method prints the XML request header attributes.
       */
      private String printXMLrequestHeaders() {
          String result = new String();
          Enumeration e = request.getHeaderNames();
          if ( e != null ) {
              while ( e.hasMoreElements() ) {
                  String headerName = (String)e.nextElement();
                  String headerValue = request.getHeader(headerName);
                  result = result + "<header>" + headerName + ": " + headerValue + "</header>";
              }
          }
          return result;
      }
                                    
      /*
       * this method prints the XML request body attribute.
       */
      private String printXMLrequestBody(){
          String result = new String("<body>");
          result = result + XML_MASK_BEGIN;
          try {
              result = result + request.getRequestBody();
          }
          catch (IOException e) {
              e.printStackTrace();
          }
          result = result + XML_MASK_END;
          result = result + "</body>";
          return result;
      }
  
      /*
       * this method prints the XML response command attribute.
       */
      private String printXMLresponseCommand() {
          String result = new String("<command>");
          result = result + getProtocol() + " " +
              response.getStatus() + " " +
              WebdavStatus.getStatusText(response.getStatus());
          result = result + "</command>";
          return result;
      }
          
      /*
       * Returns the protocol without a trailing CRLF
       */
      private String getProtocol() {
          String result = request.getProtocol();
          while (result.endsWith("\n")) {
              result = result.substring(0, result.length()-"\n".length()-1);
          }
          return result;
      }
                                    
      /*
       * this method prints the XML response header attributes.
       */
      private String printXMLresponseHeaders() {
          XResponseHeader respHeader;
          String result = new String();
          Enumeration e = response.getResponseHeaders();
          if ( e != null ) {
              while ( e.hasMoreElements() ) {
                  result = result + "<header>";
                  result = result + ((XResponseHeader)e.nextElement()).toString();
                  result = result + "</header>";
              }
          }
          return result;
      }
                                    
      /*
       * this method prints the XML response body attribute.
       */
      private String printXMLresponseBody() {
          String result = new String("<body>");
          result = result + XML_MASK_BEGIN;
          try {
              result = result + response.getResponseBody();
          } catch ( IOException e ) {
              e.printStackTrace();
          }
          result = result + XML_MASK_END;
          result = result + "</body>";
          return result;
      }
  
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XResponseHeader.java
  
  Index: XResponseHeader.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  
  /**
   * This class represents a header of a http servlet response and its value .
   *
   * @author Hardy Kiefer, Software AG, Germany
   */
  
  
  public class XResponseHeader {
  
      private String name;
      public String getName() {
          return name;
      }
      
      private String value;
      public String getValue() {
          return value;
      }
      
  
      public XResponseHeader( String name, String value ) {
          this.name = name;
          this.value = value;
      }
  
      public String toString() {
          return getName() + ": " + getValue();
      }
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XServletInputStreamFacade.java
  
  Index: XServletInputStreamFacade.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/util/logger/XServletInputStreamFacade.java,v 1.1 2001/03/21 10:10:14 juergen Exp $
   * $Revision: 1.1 $
   * $Date: 2001/03/21 10:10:14 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.io.IOException;
  import javax.servlet.ServletInputStream;
  import org.apache.slide.common.Domain;
  
  /**
   * This class is to buffer an ServletInputStream.
   *
   * @author Hardy.Kiefer@softwareag.com
   */
  public class XServletInputStreamFacade extends ServletInputStream {
  
      private static final char CRLF = (System.getProperty("line.separator")).charAt(0);
      
      private ServletInputStream in;
      private XByteBuffer byteBuf;
  
      public XServletInputStreamFacade( ServletInputStream in ) {
          if ( Domain.isInitialized()) Domain.debug("Create XServletInputStreamFacade");
          this.in = in;
          byteBuf = new XByteBuffer();
      }
      
      
      
      public int read() throws IOException {
          if ( Domain.isInitialized())Domain.debug("ENTER: XServletInputStreamFacade:read()");
          int result = in.read();
          byteBuf.write(result);
          if ( Domain.isInitialized())Domain.debug("LEAVE: XServletInputStreamFacade:read() result = " + result );
          return result;
      }
  
      public int read(byte[] b) throws IOException {
          if ( Domain.isInitialized()) Domain.debug("ENTER: XServletInputStreamFacade:read(byte[] b)");
          int result = in.read(b);
          byteBuf.write( b, 0, result );
          if ( Domain.isInitialized()) Domain.debug("LEAVE: XServletInputStreamFacade:read(byte[] b) result = " + result );
          return result;
      }
  
      public int read(byte[] b, int off, int len) throws IOException {
          if ( Domain.isInitialized()) Domain.debug("ENTER: XServletInputStreamFacade:read(byte[] b, off="+off+" len="+len+" )");
          int result = in.read(b, off, len);
          byteBuf.write( b, off, result );
          if ( Domain.isInitialized()) Domain.debug("LEAVE: XServletInputStreamFacade:read(byte[] b, off="+off+" len="+len+" ) result = " + result );
          return result;
      }
  
      /**
       * See the general contract of the <code>skip</code>
       * method of <code>InputStream</code>.
       *
       * @param      n   the number of bytes to be skipped.
       * @return     the actual number of bytes skipped.
       * @exception  IOException  if an I/O error occurs.
       */
      public long skip(long n) throws IOException {
          return in.skip(n);
      }
  
      /**
       * Returns the number of bytes that can be read from this input
       * stream without blocking.
       * <p>
       * The <code>available</code> method of
       * <code>BufferedInputStream</code> returns the sum of the the number
       * of bytes remaining to be read in the buffer
       * (<code>count&nbsp;- pos</code>)
       * and the result of calling the <code>available</code> method of the
       * underlying input stream.
       *
       * @return     the number of bytes that can be read from this input
       *             stream without blocking.
       * @exception  IOException  if an I/O error occurs.
       * @see        java.io.FilterInputStream#in
       */
      public synchronized int available() throws IOException {
          return in.available();
      }
  
      /**
       * See the general contract of the <code>mark</code>
       * method of <code>InputStream</code>.
       *
       * @param   readlimit   the maximum limit of bytes that can be read before
       *                      the mark position becomes invalid.
       * @see     java.io.BufferedInputStream#reset()
       */
      public synchronized void mark(int readlimit) {
          in.mark(readlimit);
      }
  
      /**
       * See the general contract of the <code>reset</code>
       * method of <code>InputStream</code>.
       * <p>
       * If <code>markpos</code> is <code>-1</code>
       * (no mark has been set or the mark has been
       * invalidated), an <code>IOException</code>
       * is thrown. Otherwise, <code>pos</code> is
       * set equal to <code>markpos</code>.
       *
       * @exception  IOException  if this stream has not been marked or
       *               if the mark has been invalidated.
       * @see        java.io.BufferedInputStream#mark(int)
       */
      public synchronized void reset() throws IOException {
          in.reset();
      }
  
      /**
       * Tests if this input stream supports the <code>mark</code>
       * and <code>reset</code> methods. The <code>markSupported</code>
       * method of <code>BufferedInputStream</code> returns
       * <code>true</code>.
       *
       * @return  a <code>boolean</code> indicating if this stream type supports
       *          the <code>mark</code> and <code>reset</code> methods.
       * @see     java.io.InputStream#mark(int)
       * @see     java.io.InputStream#reset()
       */
      public boolean markSupported() {
          return in.markSupported();
      }
  
      /**
       * Closes this input stream and releases any system resources
       * associated with the stream.
       *
       * @exception  IOException  if an I/O error occurs.
       */
      public void close() throws IOException {
          in.close();
      }
  
      /**
       * Get content of the read input stream saved in the buffer.
       **/
      public String getBufferContent() {
          return byteBuf.getBufferContent();
      }
  
      /**
       * Get number of bytes read from the input stream saved in the buffer.
       **/
      public int getNumberOfBytesWritten() {
          return byteBuf.getNumberOfBytesWritten();
      }
      
  }
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XServletOutputStreamFacade.java
  
  Index: XServletOutputStreamFacade.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.io.PrintStream;
  import java.io.IOException;
  import javax.servlet.ServletOutputStream;
  
  import org.apache.slide.common.Domain;
  
  /**
   *
   */
  public class XServletOutputStreamFacade extends ServletOutputStream {
  
      
      public static final String DEFAULT_CHAR_ENCODING = "8859_1";
      public static final byte[] bCRLF = (System.getProperty("line.separator")).getBytes();
  
      ServletOutputStream prStream;
      //PrintStream prStream;
      XByteBuffer bb;
      
      /** Encoding - first time print() is used.
      IMPORTANT: print() is _bad_, if you want to write Strings and mix
      bytes you'd better use a real writer ( it's faster ).
      But _don't_ use the servlet writer - since you'll not be able to write
      bytes.
      */
      String enc;
      
      protected XServletOutputStreamFacade( ServletOutputStream soStream, String enc) {
          Domain.debug("Create XServletOutputStreamFacade");
  //      this.prStream = new PrintStream( soStream, true );
  //      if ( DEFAULT_CHAR_ENCODING.equals(enc) ) {
  //          this.enc = null;
  //      } else {
  //          this.enc = enc;
  //      }
          this.prStream = soStream;
          bb = new XByteBuffer();
      }
  
      // -------------------- Write methods --------------------
      
      public void write(int i) throws IOException {
          Domain.debug("XServletOutputStreamFacade:write(int)");
          bb.write(i);
          prStream.write(i);
      }
  
      public void write(byte[] b) throws IOException {
          Domain.debug("XServletOutputStreamFacade:write(byte[])");
          write(b,0,b.length);
          prStream.write(b,0,b.length);
      }
      
      public void write(byte[] b, int off, int len) throws IOException {
          Domain.debug("XServletOutputStreamFacade:write(byte[] b, int off, int len)");
          bb.write( b, off, len );
          prStream.write(b, off, len);
      }
  
      // -------------------- Servlet Output Stream methods --------------------
      
      /** Alternate implementation for print, using String.getBytes(enc).
      It seems to be a bit faster for small strings, but it's 10..20% slower
      for larger texts ( nor very large - 5..10k )
  
      That seems to be mostly because of byte b[] - the writer has an
      internal ( and fixed ) buffer.
  
      Please use getWriter() if you want to send strings.
      */
      public void print(String s) throws IOException {
          Domain.debug("XServletOutputStreamFacade:print(" + s + " )");
          if (s==null) {
              s="null";
          }
          byte b[]=null;
          if( enc==null) {
              b=s.getBytes();
          } else {
              try {
                  b=s.getBytes( enc );
              } catch (java.io.UnsupportedEncodingException ex) {
                  b=s.getBytes();
              enc=null;
              }
          }
          write( b );
          prStream.print( s );
      }
      
      public void println() throws IOException {
          Domain.debug("XServletOutputStreamFacade:println()");
          write(bCRLF);
          prStream.println();
      }
  
      public void println(String s) throws IOException {
          Domain.debug("XServletOutputStreamFacade:println(" + s + " )");
          if (s==null) {
              s="null";
          }
          byte b[]=null;
          if( enc==null) {
              b=s.getBytes();
          } else {
              try {
                  b=s.getBytes( enc );
              } catch (java.io.UnsupportedEncodingException ex) {
                  b=s.getBytes();
              enc=null;
              }
          }
          write(b);
          write(bCRLF);
          prStream.println(s);
      }
  
      /** Will send the buffer to the client.
       */
      public void flush() throws IOException {
          Domain.debug("XServletOutputStreamFacade:flush()");
          prStream.flush();
      }
  
      public void close() throws IOException {
          Domain.debug("XServletOutputStreamFacade:close()");
          prStream.close();
      }
  
      /**
       * Returns the content of the byte buffer as string.
       *
       * @return      content of the byte buffer as string.
       */
      public String getOutputBuffer() throws IOException {
          return bb.getBufferContent();
      }
  
      
  }
  
  
  
  
  1.1                  jakarta-slide/src/share/org/apache/slide/util/logger/XServletWriterFacade.java
  
  Index: XServletWriterFacade.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.slide.util.logger;
  
  import java.io.*;
  import javax.servlet.ServletOutputStream;
  
  import org.apache.slide.util.logger.XHttpServletRequestFacade;
  import org.apache.slide.util.logger.XHttpServletResponseFacade;
  
  /**
   *  Facade to the PrintWriter returned by Response.
   *  This will grow to include more support for JSPs ( and other templating
   *  systems ) buffering requirements, provide support for accounting
   *  and will allow more control over char-to-byte conversion ( if it proves
   *  that we spend too much time in that area ).
   *
   *  This will also help us control the multi-buffering ( since all writers have
   *  8k or more of un-recyclable buffers).
   *
   * @author Costin Manolache [costin@eng.sun.com]
   */
  public class XServletWriterFacade extends PrintWriter {
      
      protected static final int DEFAULT_BUFFER_SIZE = 8*1024;
      int defaultBufferSize = DEFAULT_BUFFER_SIZE;
      int bytesWritten = 0;
  
      /** The buffer
       */
      public StringBuffer buffer;
  
      public XServletWriterFacade( Writer w ) {
          super( w );
  //      buf = new byte[defaultBufferSize];
          buffer = new StringBuffer();
      }
  
      // -------------------- Write methods --------------------
  
      public void flush() {
      super.flush();
      }
  
      public void print( String str ) {
          buffer = buffer.append(str);
          super.print( str );
     }
  
      public void println( String str ) {
          buffer = buffer.append(str + "\n");
          super.println( str );
     }
  
      public void write( char buf[], int offset, int count ) {
          buffer = buffer.append( buf, offset, count );
          super.write( buf, offset, count );
      }
  
      public void write( String str ) {
          buffer = buffer.append(str);
          super.write( str );
      }
  
      public String getOutputBuffer() {
          return buffer.toString();
      }
  
  }