[jboss-cvs] jboss-seam/src/mail/org/jboss/seam/mail/ui/context ...

Peter Muir peter at bleepbleep.org.uk
Thu Apr 5 11:08:26 EDT 2007


  User: pmuir   
  Date: 07/04/05 11:08:26

  Modified:    src/mail/org/jboss/seam/mail/ui/context   
                        MailFacesContextImpl.java
                        MailExternalContextImpl.java
  Added:       src/mail/org/jboss/seam/mail/ui/context   
                        MailResponseWriter.java
  Log:
  JBSEAM-1133 & JBSEAM-1134
  
  Revision  Changes    Path
  1.3       +8 -6      jboss-seam/src/mail/org/jboss/seam/mail/ui/context/MailFacesContextImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MailFacesContextImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/context/MailFacesContextImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- MailFacesContextImpl.java	10 Feb 2007 20:44:19 -0000	1.2
  +++ MailFacesContextImpl.java	5 Apr 2007 15:08:25 -0000	1.3
  @@ -19,16 +19,18 @@
      private FacesContext delegate;
      private ExternalContext externalContext;
      
  +   private ResponseWriter responseWriter;
  +   
      public MailFacesContextImpl(FacesContext delegate)
      {
  -      this.delegate = delegate;
  -      externalContext = new MailExternalContextImpl(delegate.getExternalContext());
  +      this(delegate, null);
      }
      
  -   public MailFacesContextImpl(FacesContext delegate, String urlBase)
  +   public MailFacesContextImpl(FacesContext facesContext, String urlBase)
      {
  -      this.delegate = delegate;
  +      this.delegate = facesContext;
         externalContext = new MailExternalContextImpl(delegate.getExternalContext(), urlBase);
  +      responseWriter = new MailResponseWriter(delegate.getResponseWriter(), delegate.getResponseWriter().getContentType());
      }
   
      @Override
  @@ -100,7 +102,7 @@
      @Override
      public ResponseWriter getResponseWriter()
      {
  -      return delegate.getResponseWriter();
  +      return responseWriter;
      }
   
      @Override
  @@ -136,7 +138,7 @@
      @Override
      public void setResponseWriter(ResponseWriter responseWriter)
      {
  -      delegate.setResponseWriter(responseWriter);
  +      this.responseWriter = responseWriter;
      }
   
      @Override
  
  
  
  1.2       +1 -1      jboss-seam/src/mail/org/jboss/seam/mail/ui/context/MailExternalContextImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MailExternalContextImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/mail/org/jboss/seam/mail/ui/context/MailExternalContextImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- MailExternalContextImpl.java	10 Feb 2007 16:32:29 -0000	1.1
  +++ MailExternalContextImpl.java	5 Apr 2007 15:08:25 -0000	1.2
  @@ -21,7 +21,7 @@
      private String urlBase;
      
      public MailExternalContextImpl(ExternalContext delegate) {
  -      this.delegate = delegate;
  +      this(delegate, null);
      }
      
      public MailExternalContextImpl(ExternalContext delegate, String urlBase) {
  
  
  
  1.1      date: 2007/04/05 15:08:25;  author: pmuir;  state: Exp;jboss-seam/src/mail/org/jboss/seam/mail/ui/context/MailResponseWriter.java
  
  Index: MailResponseWriter.java
  ===================================================================
  /*
   * Copyright 2004-2006 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   * License for the specific language governing permissions and limitations under
   * the License.
   */
  package org.jboss.seam.mail.ui.context;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import javax.faces.FacesException;
  import javax.faces.component.UIComponent;
  import javax.faces.context.ResponseWriter;
  
  /**
   * The ResponseWriter for mail objects needs to support unencoded plain text
   * output.
   */
  public class MailResponseWriter extends ResponseWriter
  {
     
     public static String TEXT_PLAIN_CONTENT_TYPE = "text/plain";
     
     public static String HTML_PLAIN_CONTENT_TYPE = "text/html";
     
     private String contentType;
     
     private ResponseWriter delegate;
  
     public MailResponseWriter(ResponseWriter responseWriter, String contentType)
              throws FacesException
     {
        this.delegate = responseWriter;
        this.contentType = contentType;
     }
  
     @Override
     public String getContentType()
     {
        if (contentType == null)
        {
           return delegate.getContentType();
        }
        else
        {
           return contentType;
        }
     }
  
     @Override
     public String getCharacterEncoding()
     {
        return delegate.getCharacterEncoding();
     }
  
     @Override
     public void flush() throws IOException
     {
        delegate.flush();
     }
  
     @Override
     public void startDocument() throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.startDocument();
        }
     }
  
     @Override
     public void endDocument() throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.endDocument();
        }
     }
  
     @Override
     public void startElement(String name, UIComponent component) throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.startElement(name, component);
        }
     }
  
     @Override
     public void endElement(String name) throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.endElement(name);
        }
     }
  
     @Override
     public void writeAttribute(String name, Object value, String property)
              throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.writeAttribute(name, value, property);
        }
        
     }
  
     @Override
     public void writeURIAttribute(String name, Object value, String componentPropertyName)
              throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write tags/attributes to plaintext!
        }
        else
        {
           delegate.writeURIAttribute(name, value, componentPropertyName);
        }
       
     }
  
     @Override
     public void writeComment(Object comment) throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           // Do nothing, can't write comments to plaintext!
        }
        else
        {
           delegate.writeComment(comment);
        }
     }
  
     @Override
     public void writeText(Object value, String componentPropertyName) throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           if (value == null)
           {
              throw new NullPointerException("Text must not be null.");
           }
           String strValue = value.toString();
           write(strValue);
        }
        else
        {
           delegate.writeText(value, componentPropertyName);
        }
     }
  
     @Override
     public void writeText(char cbuf[], int off, int len) throws IOException
     {
        if (cbuf == null)
        {
           throw new NullPointerException("cbuf name must not be null");
        }
        if (cbuf.length < off + len)
        {
           throw new IndexOutOfBoundsException((off + len) + " > " + cbuf.length);
        }
        String strValue = new String(cbuf, off, len);
        write(strValue);
     }
  
     @Override
     public ResponseWriter cloneWithWriter(Writer writer)
     {
        return cloneWithWriter(writer, null);
     }
     
     public MailResponseWriter cloneWithWriter(Writer writer, String contentType)
     {
        MailResponseWriter newWriter = new MailResponseWriter(delegate.cloneWithWriter(writer), contentType);
        return newWriter;
     }
  
     // Writer methods
  
     @Override
     public void close() throws IOException
     {
        delegate.close();
     }
  
     @Override
     public void write(char cbuf[], int off, int len) throws IOException
     {
        String strValue = new String(cbuf, off, len);
        write(strValue);
     }
  
     @Override
     public void write(int c) throws IOException
     {
        delegate.write(c);
     }
  
     @Override
     public void write(char cbuf[]) throws IOException
     {
        String strValue = new String(cbuf);
        write(strValue);
     }
  
     @Override
     public void write(String str) throws IOException
     {
        if (TEXT_PLAIN_CONTENT_TYPE.equals(getContentType()))
        {
           delegate.write(str);
        }
        else
        {
           delegate.write(str);
        }
     }
  
     @Override
     public void write(String str, int off, int len) throws IOException
     {
        String strValue = str.substring(off, off + len);
        write(strValue);
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list