incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwald...@apache.org
Subject svn commit: r482451 [4/5] - in /incubator/adffaces/branches/jwaldman-portal/trinidad: trinidad-api/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/config/ trinidad-api/src/main/java/org/apache/myfaces/trinidad/context/ trinidad-api/src/main/jav...
Date Tue, 05 Dec 2006 02:02:55 GMT
Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileImpl.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileImpl.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileImpl.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,454 @@
+/*
+ * Copyright  2002-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.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.BufferedInputStream;
+import java.io.EOFException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
+/**
+ * UploadedFileImpl defines a single file that has been uploaded
+ * to the server.
+ * 
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/webapp/UploadedFileImpl.java#0 $) $Date: 10-nov-2005.18:49:03 $
+ * @author The Oracle ADF Faces Team
+ */
+public class UploadedFileImpl implements UploadedFile, Serializable
+{
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 1592383482116327497L;
+  
+  UploadedFileImpl()
+  {
+  }
+
+  /**
+   * Returns the filename reported from the client.
+   */
+  public String getFilename()
+  {
+    return _filename;
+  }
+
+  /**
+   * Returns the MIME type of the file.
+   */
+  public String getContentType()
+  {
+    return _contentType;
+  }
+
+  /**
+   * Returns the total length (in bytes) of the file.
+   */
+  public long getLength()
+  {
+    return _length;
+  }
+
+  public Object getOpaqueData()
+  {
+    return null;
+  }
+
+  /**
+   * Returns an InputStream that can be used to read the file.
+   * This method can be called repeatedly.
+   */
+  public InputStream getInputStream() throws IOException
+  {
+    if (_buffers != null)
+    {
+      return new BufferIS(_buffers, _sizeOfLastBuffer);
+    }
+    else if (_file != null)
+    {
+      return new BufferedInputStream(new FileInputStream(_file));
+    }
+
+    return null;
+  }
+
+  /**
+   * Writes the entire contents of the file to an OutputStream.
+   */
+  private void _writeFile(OutputStream out) throws IOException
+  {
+    if (_buffers != null)
+    {
+      int size = _buffers.size();
+      for (int i = 0; i < size; i++)
+      {
+        byte[] buffer = _buffers.get(i);
+        int bytes;
+        if (i == (size - 1))
+          bytes = _sizeOfLastBuffer;
+        else
+          bytes = buffer.length;
+
+        out.write(buffer, 0, bytes);
+      }
+    }
+    else if (_file != null)
+    {
+      FileInputStream in = new FileInputStream(_file);
+      try
+      {
+        byte[] buffer = new byte[_DISK_BUFFER_SIZE];
+        while (true)
+        {
+          int bytes = in.read(buffer);
+          if (bytes < 0)
+            break;
+          out.write(buffer, 0, bytes);
+        }
+      }
+      finally
+      {
+        in.close();
+      }
+    }
+  }
+
+  /**
+   * Disposes of all resources used to store this file.
+   */ 
+  public void dispose()
+  {
+    _length = 0;
+    _buffers = null;
+    if (_file != null)
+    {
+      _file.delete();
+      _file = null;
+    }
+  }
+  
+  /**
+   * Loads the file from a MultipartFormItem.
+   */
+  public void loadFile(
+    UploadedFile      file,
+    long              remainingMemory,
+    long              remainingDiskSpace,
+    String            directory) throws IOException
+  {
+    _filename    = file.getFilename();
+    _contentType = file.getContentType();
+    
+    InputStream in = file.getInputStream();
+
+    // First step: try to read it into memory.  Instead of trying
+    // to build up one big buffer, we create a list of buffers
+    // that are each at most 4K.  This is vastly faster to create
+    // and insignificantly slower to read.
+    while (_length < remainingMemory)
+    {
+      // Read another block of buffered memory.  We'll read up to 4K
+      // at a time, but no more than the remaining amount of memory plus
+      // one byte.  Why plus one?  Well, we want to know when we've
+      // exceeded the memory size - not just reached it.
+      int size = Math.min(((int) (remainingMemory - _length)) + 1,
+                          _MEMORY_BUFFER_SIZE);
+      byte[] buffer = new byte[size];
+      int bytes = _fillBuffer(in, buffer, size);
+
+      _sizeOfLastBuffer = bytes;
+      _length           = _length + bytes;
+
+      if (_buffers == null)
+        _buffers = new ArrayList<byte[]>();
+      _buffers.add(buffer);
+      
+      // If we're done, bail right here.
+      if (bytes < size)
+        return;
+    }
+
+    // If we didn't have enough space to read the file into memory,
+    // and we also don't have enough space available on disk, then
+    // punt right here and now.
+    if (_length > remainingDiskSpace)
+    {
+      _buffers = null;
+      _length  = 0;
+      throw new EOFException("Per-request disk space limits exceeded.");
+    }
+
+    OutputStream out = _createOutputStream(directory);
+      
+    try
+    {
+      // First, copy the file from memory to the file
+      if (_length > 0)
+      {
+        _writeFile(out);
+      }
+      
+      // Free the buffers, since we're
+      _buffers = null;
+      
+      // Now, write directly to the file.
+      while (_length < remainingDiskSpace)
+      {
+        byte[] buffer = new byte[_DISK_BUFFER_SIZE];
+        int bytes = _fillBuffer(in, buffer, _DISK_BUFFER_SIZE);
+        out.write(buffer, 0, bytes);
+        _length = _length + bytes;
+
+        if (bytes < _DISK_BUFFER_SIZE)
+          break;
+      }
+    }
+    finally
+    {
+      out.close();
+
+      // If we read too much - then drop the file, and bail.
+      if (_length > remainingDiskSpace)
+      {
+        _file.delete();
+        _file = null;
+        _length = 0;
+
+        throw new EOFException("Per-request disk space limits exceeded.");
+      }
+    }
+  }
+  
+  @Override
+  public int hashCode()
+  {
+    if (_filename == null)
+      return 0;
+    return _filename.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    // UploadedFiles are only equal to themselves.
+    return (this == o);
+  }
+
+  //
+  // Create the OutputStream.
+  //
+  private OutputStream _createOutputStream(String directory) throws IOException
+  {
+    File tempDir;
+    if (directory == null)
+      tempDir = null;
+    else
+      tempDir = new File(directory);
+
+    // Create our temporary file.
+    _file = File.createTempFile("uix", null, tempDir);
+
+    // Even though we're supposed to clean up these files ourselves,
+    // make sure they get deleted even if an exception terminates
+    // our code.
+    _file.deleteOnExit();
+
+    // No need for additional buffering of the output - we always
+    // buffer the writes - so _don't_ add a BufferedOutputStream.
+    return new FileOutputStream(_file);
+  }
+
+
+  //
+  // If true, we're either in memory (or empty);  if false,
+  // we're on disk.
+  //
+  boolean __isInMemory()
+  {
+    return (_buffers != null);
+  }
+
+  //
+  // Fill a byte buffer from an InputStream.
+  //
+  private int _fillBuffer(
+    InputStream in,
+    byte[]      buffer,
+    int         size) throws IOException
+  {
+    int offset = 0;
+
+    // Read until the buffer is full, or the InputStream runs out.
+    do
+    {
+      int bytes = in.read(buffer, offset, size - offset);
+      if (bytes < 0)
+        break;
+      
+      offset = offset + bytes;
+    }
+    while (offset < size);
+
+    return offset;
+  }
+
+
+  //
+  // InputStream implementation that reads from an in-memory buffer.
+  //
+  static private class BufferIS extends InputStream
+  {
+    public BufferIS(List<byte[]> bufferList, int sizeOfLastBuffer)
+    {
+      _bufferList = bufferList;
+      _sizeOfLastBuffer = sizeOfLastBuffer;
+    }
+
+    // Read a single byte.
+    @Override
+    public int read()
+    {
+      int bufferIndex = _bufferIndex;
+      if (bufferIndex < 0)
+        return -1;
+
+      byte[] buffer = _getBuffer(bufferIndex);
+      byte currByte = buffer[_bufferPos];
+
+      int bufferSize = _getBufferSize(buffer, bufferIndex);
+      _advanceTo(_bufferPos + 1, bufferSize);
+     
+      return currByte & 0xff; 
+    }
+    
+    // Read into a buffer.
+    @Override
+    public int read(byte b[], int off, int len)
+    {
+      int bufferIndex = _bufferIndex;
+      if (bufferIndex < 0)
+        return -1;
+
+      byte[] buffer = _getBuffer(bufferIndex);
+      int bufferSize = _getBufferSize(buffer, bufferIndex);
+      
+      // Read as many bytes are available in the current buffer block,
+      // up to "len" bytes.  If "len" is larger, then in theory
+      // we could loop and read multiple blocks, but that'd complicate
+      // our logic here without actually simplifying the developer's
+      // logic any (they can't assume an InputStream behaves that way).
+      int bufferPos = _bufferPos;
+      int bytes = Math.min(len, bufferSize - bufferPos);
+      System.arraycopy(buffer, bufferPos, b, off, bytes);
+      _advanceTo(bufferPos + bytes, bufferSize);
+     
+      return bytes;
+    }
+
+    //
+    // Returns the number of bytes that will be made avaialable
+    // in the next call to read(byte[], int, int);
+    //
+    @Override
+    public int available()
+    {
+      int bufferIndex = _bufferIndex;
+      if (bufferIndex < 0)
+        return 0;
+
+      byte[] buffer = _getBuffer(bufferIndex);
+      int bufferSize = _getBufferSize(buffer, bufferIndex);
+
+      return bufferSize - _bufferPos;
+    }
+
+    // Advance the current buffer to a certain position.
+    private void _advanceTo(int pos, int bufferSize)
+    {
+      if (pos >= bufferSize)
+      {
+        _bufferPos = 0;
+        _bufferIndex = _bufferIndex + 1;
+        if (_bufferIndex >= _bufferList.size())
+          _bufferIndex = -1;
+      }
+      else
+      {
+        _bufferPos = pos;
+      }
+    }
+
+    // Return the size of a given buffer. (The last buffer
+    // may not be completely full.)
+    private int _getBufferSize(byte[] buffer, int bufferIndex)
+    {
+      if (bufferIndex == _bufferList.size() - 1)
+        return _sizeOfLastBuffer;
+      
+      return buffer.length;
+    }
+
+    // Return a buffer.
+    private byte[] _getBuffer(int bufferIndex)
+    {
+      return _bufferList.get(bufferIndex);
+    }
+
+    // ArrayList of all the buffers
+    private List<byte[]> _bufferList;
+    // The number of bytes in the last buffer (which may not be full)
+    private int  _sizeOfLastBuffer;
+
+    // Current index into _bufferList
+    private int  _bufferIndex;
+
+    // Current position in _bufferList[_bufferIndex]
+    private int  _bufferPos;
+  }
+
+
+  private String     _filename;
+  private String     _contentType;
+
+  // Total length fo the content, whether in memory or on disk
+  transient private long       _length;
+
+  // File where the content is stored (or null if the content
+  // is in memory)
+  transient private File       _file;
+
+  // ArrayList of all the in-memory buffers (or null if it's in
+  // a File)
+  transient private ArrayList<byte[]> _buffers;
+  // The number of bytes in the last buffer (which may not be full)
+  transient private int        _sizeOfLastBuffer;
+
+  // Buffer sizes.  The memory buffer size can be very small
+  // because of our list-of-small-buffers technique;  for disk I/O,
+  // use a larger buffer.
+  static private final int _MEMORY_BUFFER_SIZE = 2048;
+  static private final int _DISK_BUFFER_SIZE   = 8192;
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFileProcessorImpl.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,154 @@
+/*
+ * Copyright  2002-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.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.faces.context.ExternalContext;
+import javax.servlet.ServletRequest;
+
+import org.apache.myfaces.trinidad.model.UploadedFile;
+import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
+
+public class UploadedFileProcessorImpl implements UploadedFileProcessor
+{
+  public UploadedFileProcessorImpl()
+  {
+  }
+
+  public void init(ExternalContext context)
+  {
+    //
+    // Get MaxMemory and TempDir properties from servlet init params
+    //
+    if (_maxMemory == -1)
+    {
+      String maxMemory = context.getInitParameter(
+                                 MAX_MEMORY_PARAM_NAME);
+      if (maxMemory != null)
+      {
+        try
+        {
+          _maxMemory = Integer.parseInt(maxMemory);
+        }
+        catch (NumberFormatException nfe)
+        {
+          _maxMemory = _DEFAULT_MAX_MEMORY;
+        }
+      }
+      else
+      {
+        _maxMemory = _DEFAULT_MAX_MEMORY;
+      }
+    }
+      
+    if (_maxDiskSpace == -1)
+    {
+      String maxDiskSpace = context.getInitParameter(
+                                                  MAX_DISK_SPACE_PARAM_NAME);
+      if (maxDiskSpace != null)
+      {
+        try
+        {
+          _maxDiskSpace = Integer.parseInt(maxDiskSpace);
+        }
+        catch (NumberFormatException nfe)
+        {
+          _maxMemory = _DEFAULT_MAX_DISK_SPACE;
+        }
+      }
+      else
+      {
+        _maxDiskSpace = _DEFAULT_MAX_DISK_SPACE;
+      }
+    }
+    
+    if (_tempDir == null)
+    {
+      _tempDir = context.getInitParameter(TEMP_DIR_PARAM_NAME);
+      // Use the webapp temporary directory if the temporary directory
+      // has not been explicitly set.
+      if (_tempDir == null)
+      {
+        File tempDirFile = (File)
+          context.getApplicationMap().get("javax.servlet.context.tempdir");
+        if (tempDirFile != null)
+          _tempDir = tempDirFile.getAbsolutePath();
+      }
+    }
+  }
+
+  public UploadedFile processFile(ExternalContext ec,
+                                  UploadedFile tempFile)
+    throws IOException
+  {
+    RequestInfo info = _getRequestInfo(ec);
+
+    // Process one new file, loading only as much as can fit
+    // in the remaining memory and disk space.
+    UploadedFileImpl file = new UploadedFileImpl();
+    file.loadFile(tempFile,
+                  _maxMemory - info.totalBytesInMemory,
+                  _maxDiskSpace - info.totalBytesOnDisk,
+                  _tempDir);
+
+    // Keep a tally of how much we've stored in memory and on disk.
+    long length = file.getLength();
+    if (file.__isInMemory())
+    {
+      info.totalBytesInMemory += length;
+    }
+    else
+    {
+      info.totalBytesOnDisk += length;
+    }
+
+    return file;
+  }
+
+  private RequestInfo _getRequestInfo(ExternalContext ec)
+  {
+    @SuppressWarnings("unchecked")      
+    RequestInfo info = (RequestInfo) ec.getRequestMap().get(_REQUEST_INFO_KEY);
+    
+    if (info == null)
+    {
+      info = new RequestInfo();
+      ec.getRequestMap().put(_REQUEST_INFO_KEY, info);
+    }
+    
+    return info;
+  }
+
+
+  static private class RequestInfo
+  {
+    public long totalBytesInMemory;
+    public long totalBytesOnDisk;
+  }
+
+  private long   _maxMemory = -1;
+  private long   _maxDiskSpace = -1;
+  private String _tempDir = null;
+
+  private static final long _DEFAULT_MAX_MEMORY = 102400;
+  private static final long _DEFAULT_MAX_DISK_SPACE = 2048000;
+
+  private static final String _REQUEST_INFO_KEY = UploadedFileProcessorImpl.class.getName()+
+    ".UploadedFilesInfo";
+
+}

Added: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFiles.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFiles.java?view=auto&rev=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFiles.java (added)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/config/upload/UploadedFiles.java Mon Dec  4 18:02:50 2006
@@ -0,0 +1,252 @@
+/*
+ * Copyright  2002-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.apache.myfaces.trinidadinternal.config.upload;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.portlet.PortletRequest;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
+import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
+
+/**
+ * UploadedFiles defines the set of files that have been uploaded
+ * to the server.
+ * 
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/webapp/UploadedFiles.java#0 $) $Date: 10-nov-2005.18:49:05 $
+ * @author The Oracle ADF Faces Team
+ */
+final public class UploadedFiles
+{
+  /**
+   * Returns the map of uploaded files for the current request.
+   */
+  @SuppressWarnings("unchecked")
+  static public UploadedFiles getUploadedFiles(FacesContext context)
+  {
+    Map<String, Object> requestMap = 
+      context.getExternalContext().getRequestMap();
+    return (UploadedFiles) requestMap.get(_UPLOADED_FILES_KEY);
+  }
+
+  /**
+   * Store the character encoding for the current request.
+   */
+  static public void setCharacterEncoding(
+    ExternalContext externalContext,
+    String         encoding)
+  {
+    UploadedFiles files = (UploadedFiles)
+      externalContext.getRequestMap().get(_UPLOADED_FILES_KEY);
+    _setCharacterEncoding(files, encoding);
+  }
+  
+  static public void setCharacterEncoding(
+      HttpServletRequest req,
+      String encoding)
+  {
+    UploadedFiles files = (UploadedFiles)
+      req.getAttribute(_UPLOADED_FILES_KEY);
+    _setCharacterEncoding(files, encoding);
+  }
+  
+  static public void setCharacterEncoding(
+      PortletRequest req,
+      String encoding)
+  {
+    UploadedFiles files = (UploadedFiles)
+      req.getAttribute(_UPLOADED_FILES_KEY);
+    _setCharacterEncoding(files, encoding);
+  }
+
+  static private void _setCharacterEncoding(UploadedFiles files, String encoding)
+  {
+    if(files != null)
+    {
+      files._characterEncoding = encoding;
+    }
+  }
+
+  /**
+   * Returns a single uploaded file.
+   * @param name the name under which the file is stored.  In HTML forms,
+   *   this will be derived from the "name" set on the &lt;input&gt; tag.
+   */
+  public UploadedFile getUploadedFile(String name)
+  {
+    UploadedFile file = _map.get(name);
+    if (file == null)
+      return null;
+
+    return new FixFilename(file, _characterEncoding);
+  }
+
+
+  /**
+   * Returns an Iterator of the names of all uploaded files.
+   */
+  public Iterator<String> getUploadedNames()
+  {
+    return _map.keySet().iterator();
+  }
+
+  /**
+   * Dispose of all UploadedFiles.  This will happen automatically
+   * when the current request ends, so clients do not need to
+   * call this method.  However, if a developer is finished with
+   * processing files, this will free up resources earlier.
+   */
+  public void dispose()
+  {
+    Iterator<UploadedFile> iterator = _map.values().iterator();
+    while (iterator.hasNext())
+    {
+      UploadedFile file = iterator.next();
+      file.dispose();
+    }
+
+    _map.clear();
+
+    _totalMemory    = 0;
+    _totalDiskSpace = 0;
+  }
+
+  /**
+   * Creates an UploadedFiles.
+   */
+  @SuppressWarnings("unchecked")
+  UploadedFiles(ExternalContext externalContext)
+  {
+    externalContext.getRequestMap().put(_UPLOADED_FILES_KEY, this);
+    _map = new HashMap<String, UploadedFile>();
+  }
+
+  /**
+   * Store a single UploadedFile.
+   */
+  void __put(String name, UploadedFile file)
+  {
+    _map.put(name, file); 
+  }
+
+
+  /**
+   * Return the tally of total memory used.
+   */
+  public long getTotalMemory()
+  {
+    return _totalMemory;
+  }
+
+
+  /**
+   * Return the tally of total disk space used.
+   */
+  public long getTotalDiskSpace()
+  {
+    return _totalDiskSpace;
+  }
+
+
+
+  private long   _totalMemory;
+  private long   _totalDiskSpace;
+  private String _characterEncoding;
+  private final Map<String, UploadedFile> _map;
+
+  private static final String _UPLOADED_FILES_KEY = 
+    "org.apache.myfaces.trinidadinternal.webapp.UploadedFiles";
+
+  static public class FixFilename implements UploadedFile, Serializable
+  {
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -8586594511769079566L;
+    
+    public FixFilename()
+    {
+      // For serialization
+    }
+
+    public FixFilename(UploadedFile file, String encoding)
+    {
+      _file = file;
+      _encoding = encoding;
+    }
+    
+    public String getFilename()
+    {
+      String filename = _file.getFilename();
+      if (_encoding == null)
+        return filename;
+
+      try
+      {
+        return CaboHttpUtils.decodeRequestParameter(filename,
+                                                    _encoding,
+                                                    null);
+      }
+      catch (UnsupportedEncodingException uee)
+      {
+        // Should never happen, since the encoding should have
+        // already been vetted in UploadedRequestWrapper
+        assert false;
+        return filename;
+      }
+    }
+
+    public String getContentType()
+    {
+      return _file.getContentType();
+    }
+
+    public long getLength()
+    {
+      return _file.getLength();
+    }
+
+    public Object getOpaqueData()
+    {
+      return _file.getOpaqueData();
+    }
+
+    public InputStream getInputStream() throws IOException
+    {
+      return _file.getInputStream();
+    }
+
+
+    public void dispose()
+    {
+      _file.dispose();
+    }
+
+    private UploadedFile _file;
+    private String       _encoding;
+  }
+}

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/FacesContextFactoryImpl.java Mon Dec  4 18:02:50 2006
@@ -16,7 +16,6 @@
 package org.apache.myfaces.trinidadinternal.context;
 
 import java.io.IOException;
-
 import java.util.Iterator;
 
 import javax.faces.application.Application;
@@ -30,8 +29,9 @@
 import javax.faces.lifecycle.Lifecycle;
 import javax.faces.render.RenderKit;
 
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.config.GlobalConfigurator;
 import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl;
 
 /**
  * Internal class that optimizes retrieval of the RenderKit by caching it
@@ -46,19 +46,46 @@
   public FacesContextFactoryImpl(FacesContextFactory factory)
   {
     _factory = factory;
+    _config = GlobalConfigurator.getInstance();
   }
 
   @Override
+  @SuppressWarnings ("unchecked")
   public FacesContext getFacesContext(
       Object context,
       Object request,
       Object response, 
       Lifecycle lifecycle)
   {
-    return new CacheRenderKit(_factory.getFacesContext(context,
-                                                       request,
-                                                       response,
-                                                       lifecycle));
+    FacesContext fc = _factory.getFacesContext(context, request, response, lifecycle);
+    ExternalContext ec = fc.getExternalContext();
+    if(!_config.isInitialized())
+    {
+      _config.init(ec);
+    }
+    
+    //The global configurator will make sure other configurators are run only once
+    if(!GlobalConfiguratorImpl.isRequestBegun(ec))
+    {
+      _config.beginRequest(ec);
+      ec.getApplicationMap().put(_CONFIG_IN_CONTEXT, Boolean.TRUE);
+    }
+    
+    return new CacheRenderKit(fc);
+  }
+  
+  /**
+   * Sets the configurator up to execute an endRequest when it is destroyed
+   * 
+   * @param fc
+   */
+  static void endRequestIfNecessary(FacesContext fc)
+  {
+    ExternalContext ec = fc.getExternalContext();
+    if(Boolean.TRUE.equals(ec.getApplicationMap().remove(_CONFIG_IN_CONTEXT)))
+    {
+      ec.getApplicationMap().put(_READY_FOR_CLEANUP, Boolean.TRUE);      
+    }
   }
 
   static public class CacheRenderKit extends FacesContext
@@ -66,7 +93,10 @@
     public CacheRenderKit(FacesContext base)
     {
       _base = base;
-      _external = new OverrideDispatch(base.getExternalContext());
+      
+      //SMO: TODO: is this still needed?
+      ExternalContext external = GlobalConfigurator.getInstance().getExternalContext(base.getExternalContext());
+      _external = new OverrideDispatch(external);
       setCurrentInstance(this);
     }
 
@@ -193,12 +223,6 @@
     }
 
     @Override
-    public void release()
-    {
-      _base.release();
-    }
-
-    @Override
     public void renderResponse()
     {
       _base.renderResponse();
@@ -210,6 +234,22 @@
       _base.responseComplete();
     }
 
+    @Override
+    public void release()
+    {
+      //=- Scott O'Bryan -=
+      // JSR-301 should allow us to call the cleanup.  So this and all logic
+      // pertaining to creation and cleanup of the configurator per request
+      // could probably go away.
+      ExternalContext ec = getExternalContext();
+      if(Boolean.TRUE.equals(ec.getApplicationMap().remove(_READY_FOR_CLEANUP)))
+      {
+        GlobalConfigurator.getInstance().endRequest(ec);      
+      }
+      
+      _base.release();
+    }
+    
     private final FacesContext    _base;
     private final ExternalContext _external;
     private String    _renderKitId;
@@ -245,11 +285,8 @@
     private final ExternalContext _decorated;
   }
 
+  static private final String _CONFIG_IN_CONTEXT = FacesContextFactoryImpl.class.getName()+".CONFIG_IN_CONTEXT";
+  static private final String _READY_FOR_CLEANUP = FacesContextFactoryImpl.class.getName()+".CONFIG_READY_FOR_CLEANUP";
   private final FacesContextFactory _factory;
-
-  // 2006-08-02; -= Simon Lessard =-
-  // There's nothing logged in this class at this time.
-  @SuppressWarnings("unused")
-  static private final TrinidadLogger _LOG =
-    TrinidadLogger.createTrinidadLogger(FacesContextFactoryImpl.class);
+  private final GlobalConfigurator _config;
 }

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextFactoryImpl.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextFactoryImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextFactoryImpl.java Mon Dec  4 18:02:50 2006
@@ -17,6 +17,7 @@
 
 import java.util.List;
 
+import javax.faces.context.ExternalContext;
 import javax.servlet.ServletContext;
 
 import org.apache.myfaces.trinidad.context.RequestContext;
@@ -26,7 +27,7 @@
 
 import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
 
-import org.apache.myfaces.trinidadinternal.webapp.ConfigParser;
+import org.apache.myfaces.trinidadinternal.config.ConfigParser;
 
 /**
  * @author The Oracle ADF Faces Team
@@ -38,25 +39,24 @@
   }
 
   @Override
-  public RequestContext createContext(Object context,
-                                       Object request)
+  public RequestContext createContext(ExternalContext externalContext)
   {
-    RequestContextImpl impl =  new RequestContextImpl(_getBean(context));
-    impl.init(request);
+    RequestContextImpl impl =  new RequestContextImpl(_getBean(externalContext));
+    impl.init(externalContext);
     impl.__setPageResolver(_pageResolver);
     impl.__setPageFlowScopeProvider(_pageFlowScopeProvider);
     return impl;
   }
 
-  private RequestContextBean _getBean(Object context)
+  private RequestContextBean _getBean(ExternalContext externalContext)
   {
     if (_bean == null)
     {
       synchronized (this)
       {
-        if (context instanceof ServletContext)
+        if(externalContext != null)
         {
-          _bean = ConfigParser.parseConfigFile((ServletContext) context);
+          _bean = ConfigParser.parseConfigFile(externalContext);
         }
         else
         {
@@ -83,7 +83,7 @@
         {
           _pageFlowScopeProvider = PageFlowScopeProviderImpl.sharedInstance();
         }
-      }
+      }      
     }
 
     return _bean;

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/RequestContextImpl.java Mon Dec  4 18:02:50 2006
@@ -27,6 +27,7 @@
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
 import javax.servlet.http.HttpServletRequest;
@@ -88,7 +89,7 @@
     _partialTargets = new HashSet<String>();
   }
 
-  public void init(Object request)
+  public void init(ExternalContext request)
   {
     attach();
   }

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/context/TrinidadPhaseListener.java Mon Dec  4 18:02:50 2006
@@ -18,14 +18,12 @@
 import java.util.Map;
 
 import javax.faces.context.FacesContext;
-
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
 
 import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.context.RequestContextFactory;
-
 import org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl;
 
 /**
@@ -36,6 +34,11 @@
  */
 public class TrinidadPhaseListener implements PhaseListener
 {
+  /**
+   * 
+   */
+  private static final long serialVersionUID = -1249678874100309402L;
+
   static public final String CACHED_REQUEST_CONTEXT =
     "org.apache.myfaces.trinidadinternal.context.CachedRequestContext";
 
@@ -61,11 +64,12 @@
   @SuppressWarnings("unchecked")
   public void afterPhase(PhaseEvent event)
   {
+    FacesContext context = event.getFacesContext();
+
     if (event.getPhaseId() == PhaseId.RESTORE_VIEW)
     {
       // Store off the current ViewRoot so we can check for a full page
       // render in response to a partial event.
-      FacesContext context = event.getFacesContext();
       context.getExternalContext().getRequestMap().put(INITIAL_VIEW_ROOT_KEY,
                                                        context.getViewRoot());
     }
@@ -81,7 +85,9 @@
         (event.getFacesContext().getResponseComplete()))
     {
       _releaseContextIfNecessary(event.getFacesContext());
+      FacesContextFactoryImpl.endRequestIfNecessary(context);
     }
+        
   }
 
   @SuppressWarnings("unchecked")
@@ -128,6 +134,7 @@
   @SuppressWarnings("unchecked")
   static private void _createContextIfNecessary(FacesContext fContext)
   {
+    
     Map<String, Object> requestMap = fContext.getExternalContext().getRequestMap();
     Boolean createdContext = (Boolean)
       requestMap.get(_CREATED_CONTEXT_KEY);
@@ -159,9 +166,7 @@
           }
 
           assert(factory != null);
-          context = factory.createContext(
-                             fContext.getExternalContext().getContext(),
-                             fContext.getExternalContext().getRequest());
+          context = factory.createContext(fContext.getExternalContext());
           requestMap.put(CACHED_REQUEST_CONTEXT, context);
         }
       }
@@ -181,9 +186,8 @@
       if (context != null)
         context.release();
     }
-
   }
-
+  
   static public final String INITIAL_VIEW_ROOT_KEY =
     "org.apache.myfaces.trinidadinternal.InitialViewRoot";
 
@@ -192,5 +196,6 @@
 
   static private final String _POSTBACK_KEY =
     "org.apache.myfaces.trinidadinternal.context.AdfFacesPhaseListener.POSTBACK";
+  
     
 }

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java Mon Dec  4 18:02:50 2006
@@ -18,7 +18,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -26,8 +25,8 @@
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.ViewHandler;
-import javax.faces.component.UIComponent;
 import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIData;
 import javax.faces.component.UIForm;
 import javax.faces.component.UIGraphic;
@@ -43,45 +42,38 @@
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseStream;
 import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
 import javax.faces.render.RenderKit;
 import javax.faces.render.RenderKitFactory;
+import javax.faces.render.Renderer;
 import javax.faces.render.ResponseStateManager;
-
 import javax.servlet.ServletResponse;
 
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-
-import org.apache.myfaces.trinidad.context.RequestContext;
 import org.apache.myfaces.trinidad.context.Agent;
-
+import org.apache.myfaces.trinidad.context.PartialPageContext;
+import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 import org.apache.myfaces.trinidad.render.DialogRenderKitService;
 import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
-
+import org.apache.myfaces.trinidad.render.RenderUtils;
+import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
+import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
+import org.apache.myfaces.trinidadinternal.config.dispatch.DispatchResponseConfiguratorImpl;
 import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
-
-import org.apache.myfaces.trinidadinternal.io.DebugResponseWriter;
 import org.apache.myfaces.trinidadinternal.io.DebugHtmlResponseWriter;
+import org.apache.myfaces.trinidadinternal.io.DebugResponseWriter;
 import org.apache.myfaces.trinidadinternal.io.HtmlResponseWriter;
 import org.apache.myfaces.trinidadinternal.io.IndentingResponseWriter;
 import org.apache.myfaces.trinidadinternal.io.XhtmlResponseWriter;
-
-import org.apache.myfaces.trinidad.context.RenderingContext;
 import org.apache.myfaces.trinidadinternal.renderkit.RenderKitBase;
-import org.apache.myfaces.trinidad.render.RenderUtils;
-import org.apache.myfaces.trinidad.context.PartialPageContext;
 import org.apache.myfaces.trinidadinternal.renderkit.core.ppr.PartialPageContextImpl;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PartialPageUtils;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlRenderer;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlUtils;
+import org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlCommandButtonRenderer;
 import org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlCommandLinkRenderer;
 import org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlFormRenderer;
-
-import org.apache.myfaces.trinidadinternal.agent.TrinidadAgent;
-import org.apache.myfaces.trinidadinternal.agent.AgentUtil;
-import org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlCommandButtonRenderer;
 import org.apache.myfaces.trinidadinternal.share.util.CaboHttpUtils;
-import org.apache.myfaces.trinidadinternal.webapp.DispatchServletResponse;
 
 /**
  * RenderKit based on UIX.
@@ -514,7 +506,7 @@
       if (contentTypeList == null)
       {
         // default to content type captured by ServletFilter
-        contentTypeList = DispatchServletResponse.getContentType(fContext);
+        contentTypeList = DispatchResponseConfiguratorImpl.getContentType(fContext);
       }
 
       String[] acceptedTypes = (contentTypeList == null)

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java Mon Dec  4 18:02:50 2006
@@ -23,7 +23,7 @@
 import org.apache.myfaces.trinidad.component.core.input.CoreInputFile;
 
 import org.apache.myfaces.trinidad.context.RenderingContext;
-import org.apache.myfaces.trinidadinternal.webapp.UploadedFiles;
+import org.apache.myfaces.trinidadinternal.config.upload.UploadedFiles;
 
 /**
  */

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/util/MultipartFormHandler.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/util/MultipartFormHandler.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/util/MultipartFormHandler.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/share/util/MultipartFormHandler.java Mon Dec  4 18:02:50 2006
@@ -23,9 +23,9 @@
 
 import java.util.StringTokenizer;
 
-import javax.servlet.ServletRequest;
-
+import javax.faces.context.ExternalContext;
 
+import org.apache.myfaces.trinidad.util.ExternalContextUtils;
 
 /**
  * MultipartFormHandler - parses an incoming file upload post.
@@ -42,6 +42,7 @@
  * <p>
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/share/util/MultipartFormHandler.java#1 $) $Date: 11-nov-2005.14:59:39 $
  * @author The Oracle ADF Faces Team
+ * @author Scott O'Bryan
  */
 public class MultipartFormHandler
 {
@@ -49,28 +50,30 @@
   /**
    * Returns true if the servlet request is a multipart request.
    */
-  static public boolean isMultipartRequest(ServletRequest request)
+  static public boolean isMultipartRequest(final ExternalContext externalContext)
   {
-    String contentType = request.getContentType();
+    final String contentType =   ExternalContextUtils.getContentType(externalContext);
+    
     if (contentType == null)
+    {
       return false;
+    }
 
-    return (contentType.startsWith(_MULTIPART_REQUEST_TYPE) &&
-            (request.getAttribute(_HANDLED) == null));
+    return contentType.startsWith(_MULTIPART_REQUEST_TYPE) && externalContext.getRequestMap().get(_HANDLED) == null;
   }
 
   /**
    * Create a MultipartFormHandler for the given servlet request.
    */
-  public MultipartFormHandler(ServletRequest request)
-    throws IOException
+  public MultipartFormHandler(final ExternalContext externalContext) throws IOException
   {
-    this(request.getContentType(), request.getInputStream());
+    
+    this(ExternalContextUtils.getContentType(externalContext), ExternalContextUtils.getRequestInputStream(externalContext));
 
     // make sure that we don't try to decode this multi part request at a
     // later time; ie: if we do a forward.
-    request.setAttribute(_HANDLED, Boolean.TRUE);
-    _contentStreamSize = request.getContentLength();
+    externalContext.getRequestMap().put(_HANDLED, Boolean.TRUE);
+    _contentStreamSize = ExternalContextUtils.getContentLength(externalContext);
   }
 
   /**
@@ -81,20 +84,18 @@
    *             must define the multipart boundary value.
    * @param in The InputStream which provides the multipart/form-data content
    */
-  public MultipartFormHandler(String type, InputStream in)
-    throws IOException
+  public MultipartFormHandler(final String type, final InputStream in) throws IOException
   {
     if (!type.startsWith(_MULTIPART_REQUEST_TYPE))
+    {
       throw new IllegalStateException("Content is not multipart form data");
+    }
 
     _boundary = _parseBoundary(type);
-
     _in = in;
-
     _skipBoundary();
   }
 
-
   /**
    * Gets the character enocoding.
    */
@@ -103,7 +104,6 @@
     return _characterEncoding;
   }
 
-
   /**
    * Sets the character encoding.  If left to default,
    * Strings will be decoded for ISO-8859-1.  Clients
@@ -111,8 +111,7 @@
    * expect another part of their processing to decode
    * the strings for them.
    */
-  public void setCharacterEncoding(String characterEncoding)
-    throws UnsupportedEncodingException
+  public void setCharacterEncoding(final String characterEncoding) throws UnsupportedEncodingException
   {
     CaboHttpUtils.validateEncoding(characterEncoding);
     _characterEncoding = characterEncoding;
@@ -137,7 +136,6 @@
     return _contentStreamSize;
   }
 
-
   /**
    * Sets the maximum number of bytes that MultipartFormItem.writeFile()
    * will be allowed to write.  This value may be set immediately
@@ -150,7 +148,7 @@
    * to 128MB.
    * @see org.apache.myfaces.trinidadinternal.share.util.MultipartFormItem#writeFile
    */
-  public void setMaximumAllowedBytes(long maxAllowedBytes)
+  public void setMaximumAllowedBytes(final long maxAllowedBytes)
   {
     _maxAllowedBytes = Math.max(0L, maxAllowedBytes);
   }
@@ -168,22 +166,27 @@
    * Returns the next MultipartStreamItem from the request, or null if no
    * more are present.
    */
-  public MultipartFormItem getNextPart()
-    throws IOException
+  public MultipartFormItem getNextPart() throws IOException
   {
-    MultipartFormItemImpl previous = _currentItem;
+    final MultipartFormItemImpl previous = _currentItem;
     if (previous != null)
+    {
       previous.finish();
+    }
 
     //The first line is content-disposition
-    String dispositionText = _readLine(false);
+    final String dispositionText = _readLine(false);
     if (dispositionText == null)
+    {
       return null;
-    Disposition disposition = new Disposition(dispositionText);
+    }
+    final Disposition disposition = new Disposition(dispositionText);
 
-    String contentTypeText = _readLine(false);
+    final String contentTypeText = _readLine(false);
     if (contentTypeText == null)
+    {
       return null;
+    }
     String contentType = _parseContentType(contentTypeText);
 
     if (contentType == null)
@@ -193,10 +196,12 @@
     else
     {
       //Eat empty line
-      String emptyLine = _readLine(true);
+      final String emptyLine = _readLine(true);
       if (emptyLine.length() > 0)
+      {
         // =-=AEW Better exception?
         throw new IOException();
+      }
     }
 
     // Create the MultipartFormItem using the previously created
@@ -205,13 +210,11 @@
     return _currentItem;
   }
 
-
   //Reads a line and makes sure it is a boundary.  Throws an exception
   //if the line is not a boundary
-  private void _skipBoundary()
-    throws IOException
+  private void _skipBoundary() throws IOException
   {
-    String line = _readLine(true);
+    final String line = _readLine(true);
 
     //A boundary must be a boundary, otherwise the stream is corrupt
     if (!line.startsWith(_boundary))
@@ -221,30 +224,28 @@
     }
   }
 
-
   //Reads a line from the stream.  If required is true then throws an
   //Exception if the line cannot be read.
-  private String _readLine(boolean required)
-    throws IOException
+  private String _readLine(final boolean required) throws IOException
   {
     return _readLine(required, false, true);
   }
 
   //Reads a line from the stream.  If required is true then throws an
   //Exception if the line cannot be read.
-  private String _readLine(boolean required,
-                           boolean decodeEncoding,
-                           boolean stripNewLines)
-    throws IOException
+  private String _readLine(final boolean required, final boolean decodeEncoding, final boolean stripNewLines)
+  throws IOException
   {
-    byte[] data  = _lineBuffer;
-    int    bytes = _readLine(data, 0, data.length);
+    final byte[] data = _lineBuffer;
+    final int bytes = _readLine(data, 0, data.length);
 
     String line = null;
     if (bytes < 0)
     {
       if (required)
+      {
         throw new EOFException();
+      }
     }
     else
     {
@@ -255,14 +256,12 @@
 
   // This is a replacement for ServletInputStream.readLine().  We use
   // this utility method instead as we don't always have a ServletInputStream.
-  private int _readLine(
-    byte[]      buffer,
-    int         offset,
-    int         length
-    ) throws IOException
+  private int _readLine(final byte[] buffer, int offset, final int length) throws IOException
   {
     if (length <= 0)
+    {
       return 0;
+    }
 
     int count = 0;
     int c;
@@ -274,24 +273,26 @@
     // be of doubtful value.
     while ((c = _in.read()) != -1)
     {
-      buffer[offset++] = (byte)c;
+      buffer[offset++] = (byte) c;
       count++;
 
       // Found a newline;  we're done.
       if (c == '\n')
+      {
         break;
+      }
 
       // Out of space; we're done too.
       // Read one character less so that we can account for CR
-      if (count == length-1)
+      if (count == length - 1)
       {
         // If we've found a CR, then we're not quite done;  we'd
         // better read over the next character (which might be a LF);
         // othewise, the LF gets processed as a bonus newline.
         if (c == '\r')
         {
-          int nextchar = _in.read();
-          buffer[offset++] = (byte)nextchar;
+          final int nextchar = _in.read();
+          buffer[offset++] = (byte) nextchar;
           count++;
         }
 
@@ -300,28 +301,28 @@
     }
 
     _totalBytesRead += count;
-    return (count > 0) ? count : -1;
+    return count > 0 ? count : -1;
   }
 
-  private String _dataToString(
-    byte[]  data,
-    int     start,
-    int     bytes,
-    boolean decodeEncoding,
-    boolean stripNewLines)
+  private String _dataToString(final byte[] data, final int start, int bytes, final boolean decodeEncoding,
+      boolean stripNewLines)
   {
     if (bytes > 0)
     {
       int i = 0;
 
       // Strip off up to the last two CR/LF's automatically
-      while ((i < 2) && (bytes > 0))
+      while (i < 2 && bytes > 0)
       {
-        byte lastChar = data[start + bytes - 1];
-        if ((lastChar == '\r') || (lastChar == '\n'))
+        final byte lastChar = data[start + bytes - 1];
+        if (lastChar == '\r' || lastChar == '\n')
+        {
           bytes--;
+        }
         else
+        {
           break;
+        }
 
         i++;
       }
@@ -329,7 +330,7 @@
       // If we *don't* want to strip new lines, but we just did,
       // then put back a '\n' (doing it this way means that
       // we force any combo of CR/LF/etc. into '\n', which is our intention.)
-      if (!stripNewLines && (i > 0))
+      if (!stripNewLines && i > 0)
       {
         bytes++;
         data[start + bytes - 1] = '\n';
@@ -343,13 +344,13 @@
       // platform byte converter.  Whereas we explicitly want
       // to do _no_ byte conversion whatsoever, which is what
       // this constructor does.
-      if (decodeEncoding && (_characterEncoding != null))
+      if (decodeEncoding && _characterEncoding != null)
       {
         try
         {
           return new String(data, start, bytes, _characterEncoding);
         }
-        catch (UnsupportedEncodingException uee)
+        catch (final UnsupportedEncodingException uee)
         {
           // Shouldn't happen - we trap unsupported encodings
           // in setCharacterEncoding()... but fall through anyway
@@ -362,7 +363,7 @@
         {
           return new String(data, start, bytes, "ISO-8859-1");
         }
-        catch (UnsupportedEncodingException uee)
+        catch (final UnsupportedEncodingException uee)
         {
           // Shouldn't happen - we trap unsupported encodings
           // in setCharacterEncoding()... but fall through anyway
@@ -375,22 +376,20 @@
   }
 
   // Parse out the boundary text from the content type
-  static private String _parseBoundary(String contentType)
+  static private String _parseBoundary(final String contentType)
   {
-    int boundaryStart = contentType.indexOf(_BOUNDARY_PARAMETER);
+    final int boundaryStart = contentType.indexOf(_BOUNDARY_PARAMETER);
     if (boundaryStart < 0)
+    {
       return null;
+    }
 
     // Boundary always starts with "--"
-    return "--" +
-           contentType.substring(boundaryStart +
-                                 _BOUNDARY_PARAMETER.length());
+    return "--" + contentType.substring(boundaryStart + _BOUNDARY_PARAMETER.length());
   }
 
-
   //Reads the ContentType string out of a line of the incoming request
-  private String _parseContentType(String line)
-    throws IOException
+  private String _parseContentType(String line) throws IOException
   {
     String contentType = null;
 
@@ -398,7 +397,7 @@
 
     if (line.startsWith(_CONTENT_TYPE_PARAMETER))
     {
-      int start = line.indexOf(" ");
+      final int start = line.indexOf(" ");
 
       if (start == -1)
       {
@@ -419,29 +418,25 @@
     return contentType;
   }
 
-
-
   // Implementation of MultipartFormItem
-  private class MultipartFormItemImpl
-    implements MultipartFormItem
+  private class MultipartFormItemImpl implements MultipartFormItem
   {
-    MultipartFormItemImpl(
-      Disposition disposition,
-      String contentType) throws IOException
+    MultipartFormItemImpl(final Disposition disposition, final String contentType) throws IOException
     {
       _disposition = disposition;
       _contentType = contentType;
 
       // This is a parameter
       if (disposition.getFilename() == null)
+      {
         _parameterValue = _readParameter();
+      }
 
     }
 
     public void finish() throws IOException
     {
-      if ((_parameterValue == null) &&
-          !_finished)
+      if (_parameterValue == null && !_finished)
       {
         if (_inputStream == null)
         {
@@ -476,54 +471,58 @@
       return _contentType;
     }
 
-    public long writeFile(OutputStream out)
-      throws IOException
+    public long writeFile(final OutputStream out) throws IOException
     {
       // This isn't a file!
       if (_parameterValue != null)
+      {
         // =-=AEW Better exception?  We could just write
         // the value out to their output stream instead
         // of complaining, but this is probably not what
         // they really want.
         throw new IOException("Item is not a file");
-
+      }
 
       // The file's already been written, or at least
       // skipped over.
       if (_finished)
+      {
         // =-=AEW Better exception?
         throw new IOException("Item has already been read past.");
+      }
 
       if (_inputStream != null)
+      {
         // =-=AEW Better exception?
         throw new IOException("Input stream has already been requested.");
+      }
 
-      long   totalBytesWritten = 0;
+      long totalBytesWritten = 0;
 
       // ServletInputStream.readLine() has the annoying habit of adding a \r\n
       // to the end of the last line.
       // Since we want a byte-for-byte transfer, don't write the \r\n from the
       // end of a line until we have verified that we have another line.
-      boolean addCRLF     = false;
-      int  numbuf  = 0;
-      byte[] buffer     = __getStreamBuffer();
-      int    bufferSize = buffer.length;
-      while((numbuf = _readLine(buffer, 0, bufferSize)) != -1)
+      boolean addCRLF = false;
+      int numbuf = 0;
+      final byte[] buffer = __getStreamBuffer();
+      final int bufferSize = buffer.length;
+      while ((numbuf = _readLine(buffer, 0, bufferSize)) != -1)
       {
         // Check for boundary
-        if(numbuf > 2 && buffer[0] == '-' && buffer[1] == '-')   // quick pre-check
+        if (numbuf > 2 && buffer[0] == '-' && buffer[1] == '-') // quick pre-check
         {
-          String line = _dataToString(buffer, 0, numbuf, false, true);
-          if(line.startsWith(_boundary))
+          final String line = _dataToString(buffer, 0, numbuf, false, true);
+          if (line.startsWith(_boundary))
           {
-              break;
+            break;
           }
         }
 
         // Are we supposed to write \r\n from the last iteration?
-        if(addCRLF)
+        if (addCRLF)
         {
-          if(out != null)
+          if (out != null)
           {
             out.write('\r');
             out.write('\n');
@@ -532,69 +531,75 @@
           addCRLF = false;
         }
         // Postpone any ending \r\n until the next iteration
-        if(numbuf >= 2 &&
-           buffer[numbuf - 2] == '\r' &&
-           buffer[numbuf - 1] == '\n')
+        if (numbuf >= 2 && buffer[numbuf - 2] == '\r' && buffer[numbuf - 1] == '\n')
         {
-            numbuf -= 2;    // skip the last 2 chars
-            addCRLF = true;     // make a note to write them on the next iteration
+          numbuf -= 2; // skip the last 2 chars
+          addCRLF = true; // make a note to write them on the next iteration
         }
-        if(out != null)
+        if (out != null)
         {
           totalBytesWritten += numbuf;
           if (totalBytesWritten <= _maxAllowedBytes)
+          {
             out.write(buffer, 0, numbuf);
+          }
         }
       }
-      
+
       _finished = true;
 
       if (totalBytesWritten >= _maxAllowedBytes)
-        throw new EOFException("Uploaded file of length " + totalBytesWritten +
-                               " bytes exceeded maximum allowed length ("
-                               + _maxAllowedBytes + " bytes)");
+      {
+        throw new EOFException("Uploaded file of length " + totalBytesWritten
+            + " bytes exceeded maximum allowed length (" + _maxAllowedBytes + " bytes)");
+      }
       return totalBytesWritten;
     }
 
-    public InputStream getInputStream()
-      throws IOException
+    public InputStream getInputStream() throws IOException
     {
       if (_parameterValue != null)
+      {
         // =-=AEW Better exception?  We could just give
         // them a StringInputStream, but this probably
         // isn't what they want
         throw new IOException("Item is not a file");
+      }
 
       if (_finished)
+      {
         // =-=AEW Better exception?
         throw new IOException("Item has already been read past.");
+      }
 
       if (_inputStream != null)
+      {
         // =-=AEW Better exception?
         throw new IOException("Input stream has already been requested.");
+      }
 
       _inputStream = new MultipartInputStream();
       return _inputStream;
     }
 
-    private String _readParameter()
-      throws IOException
+    private String _readParameter() throws IOException
     {
       // Create the buffer.  It's no use reusing the buffer,
       // since the String object sent out will end up "owning"
       // the storage of the StringBuffer
-      StringBuffer buffer = new StringBuffer(200);
-      for (String line = _readLine(false, true, false);
-           (line != null) && !line.startsWith(_boundary);
-           line = _readLine(false, true, false))
+      final StringBuffer buffer = new StringBuffer(200);
+      for (String line = _readLine(false, true, false); line != null
+      && !line.startsWith(_boundary); line = _readLine(false, true, false))
       {
         buffer.append(line);
       }
 
       // Trim the final newline
-      int length = buffer.length();
+      final int length = buffer.length();
       if (buffer.charAt(length - 1) == '\n')
+      {
         buffer.deleteCharAt(length - 1);
+      }
 
       // =-=AEW Trim the buffer before toString()'ing?  The
       // usual time/space tradeoff.
@@ -603,35 +608,36 @@
 
     private MultipartInputStream _inputStream;
 
-    private Disposition _disposition;
+    private Disposition          _disposition;
 
-    private String _contentType;
+    private String               _contentType;
 
-    private String _parameterValue;
+    private String               _parameterValue;
 
     // For a file item, has the file been read?
-    private boolean _finished;
-
+    private boolean              _finished;
 
     private class MultipartInputStream extends InputStream
     {
-      MultipartInputStream()
-        throws IOException
+      MultipartInputStream() throws IOException
       {
         // This isn't a file!
         if (_parameterValue != null)
+        {
           // =-=AEW Better exception?  We could just write
           // the value out to their output stream instead
           // of complaining, but this is probably not what
           // they really want.
           throw new IOException("Item is not a file");
-
+        }
 
         // The file's already been written, or at least
         // skipped over.
         if (_finished)
+        {
           // =-=AEW Better exception?
           throw new IOException("Item has already been read past.");
+        }
 
         _begin = 0;
         _end = 0;
@@ -650,7 +656,7 @@
             ;
           }
         }
-        catch (IOException e)
+        catch (final IOException e)
         {
           // Don't care...
           ;
@@ -659,8 +665,7 @@
 
       //Fills up the _buffer parameter with
       //Returns false on EOF
-      private void readLine()
-        throws IOException
+      private void readLine() throws IOException
       {
         if (_finished)
         {
@@ -674,39 +679,36 @@
           _addCRLF = false;
         }
 
-        int  bufferSize = _buffer.length;
-        int  numbuf  = _readLine(_buffer, _end, (bufferSize-_end));
+        final int bufferSize = _buffer.length;
+        int numbuf = _readLine(_buffer, _end, (bufferSize - _end));
         if (numbuf < 0)
         {
           _finished = true;
           return;
         }
-        
-        if(numbuf > 2 && _buffer[_end] == '-' && _buffer[_end+1] == '-')   // quick pre-check
+
+        if (numbuf > 2 && _buffer[_end] == '-' && _buffer[_end + 1] == '-') // quick pre-check
         {
           // Check for boundary
-          String line = _dataToString(_buffer, _end, numbuf, false, true);
-          if(line.startsWith(_boundary))
+          final String line = _dataToString(_buffer, _end, numbuf, false, true);
+          if (line.startsWith(_boundary))
           {
-            _finished = true; 
+            _finished = true;
             return;
           }
-        } 
-        
-        if(numbuf >= 2 &&
-           _buffer[_end+numbuf - 2] == '\r' &&
-           _buffer[_end+numbuf - 1] == '\n')
+        }
+
+        if (numbuf >= 2 && _buffer[_end + numbuf - 2] == '\r' && _buffer[_end + numbuf - 1] == '\n')
         {
           // Postpone any ending \r\n until the next iteration
-          numbuf -= 2;     // skip the last 2 chars
+          numbuf -= 2; // skip the last 2 chars
           _addCRLF = true; // make a note to write them on the next iteration
         }
         _end += numbuf;
       }
 
       @Override
-      public int read(byte[] buffer, int offset, int length)
-        throws IOException
+      public int read(final byte[] buffer, final int offset, final int length) throws IOException
       {
         int bytes = -1; // default to EOF
 
@@ -721,15 +723,15 @@
           {
             readLine();
           }
-          if(!_finished)
+          if (!_finished)
           {
             cachedBytes = _end - _begin;
-  
-            bytes = (length > cachedBytes) ? cachedBytes : length;
-  
+
+            bytes = length > cachedBytes ? cachedBytes : length;
+
             System.arraycopy(_buffer, _begin, buffer, offset, bytes);
             _begin += bytes;
-  
+
             //If we've written all the data out of the array, then reset
             //to the beginning of the array
             if (_begin == _end)
@@ -742,17 +744,15 @@
       }
 
       @Override
-      public int read(byte[] buffer)
-        throws IOException
+      public int read(final byte[] buffer) throws IOException
       {
         return read(buffer, 0, buffer.length);
       }
 
       @Override
-      public int read()
-        throws IOException
+      public int read() throws IOException
       {
-        byte[] temp = new byte[1];
+        final byte[] temp = new byte[1];
         int value;
 
         value = read(temp, 0, 1);
@@ -767,28 +767,29 @@
     }
 
     //Where data begins in the buffer
-    private int _begin;
+    private int     _begin;
+
     //Where date ends in the buffer
-    private int _end;
+    private int     _end;
 
     //Data read from the servlet
-    private byte[] _buffer;
+    private byte[]  _buffer;
 
     //If true then no more bytes can be read
     private boolean _addCRLF;
   }
 
-
   private class Disposition
   {
-    Disposition(String line)
-      throws IOException // =-=AEW Better exception?
+    Disposition(final String line) throws IOException // =-=AEW Better exception?
     {
       // =-=AEW This could be more efficient
-      StringTokenizer tokenizer = new StringTokenizer(line, ";");
+      final StringTokenizer tokenizer = new StringTokenizer(line, ";");
 
       if (!tokenizer.hasMoreTokens())
+      {
         throw new IOException();
+      }
 
       // The first token has to be "content-disposition: something"
       String disposition = tokenizer.nextToken().toLowerCase();
@@ -798,17 +799,18 @@
       }
 
       // Get everything after content-disposition, lose the white space...
-      disposition = disposition.substring(
-                     _CONTENT_DISPOSITION_PARAMETER.length()).trim();
+      disposition = disposition.substring(_CONTENT_DISPOSITION_PARAMETER.length()).trim();
 
       // ... and then make sure it's form-data.
       if (!disposition.equals(_FORM_DATA_DISPOSITION))
+      {
         throw new IOException();
+      }
 
       String filenameBuffer = null;
       while (tokenizer.hasMoreTokens())
       {
-        String keyValue = tokenizer.nextToken().trim();
+        final String keyValue = tokenizer.nextToken().trim();
         if (_name == null)
         {
           _name = _extractName(keyValue);
@@ -816,15 +818,21 @@
         else
         {
           if (filenameBuffer == null)
+          {
             filenameBuffer = keyValue;
           // Don't quit on the first semicolon - keep appending
+          }
           else
+          {
             filenameBuffer = filenameBuffer + ";" + keyValue;
+          }
         }
       }
 
       if (filenameBuffer != null)
+      {
         _filename = _extractFilename(filenameBuffer);
+      }
     }
 
     public final String getName()
@@ -837,21 +845,19 @@
       return _filename;
     }
 
-    private String _extractName(String keyValue)
+    private String _extractName(final String keyValue)
     {
       return _extractValue(keyValue, _NAME_PARAMETER);
     }
 
-    private String _extractFilename(String keyValue)
+    private String _extractFilename(final String keyValue)
     {
       String fileName = _extractValue(keyValue, _FILENAME_PARAMETER);
       try
       {
-        fileName = CaboHttpUtils.decodeRequestParameter(fileName,
-                                                        getCharacterEncoding(),
-                                                        null);
+        fileName = CaboHttpUtils.decodeRequestParameter(fileName, getCharacterEncoding(), null);
       }
-      catch (UnsupportedEncodingException uee)
+      catch (final UnsupportedEncodingException uee)
       {
         // Must never happen, because we always check the validity
         // of the encoding before it gets set
@@ -861,8 +867,7 @@
       // Strip off anything that corresponds to a path.
       if (fileName != null)
       {
-        int index =
-          Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
+        final int index = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
 
         if (index != -1)
         {
@@ -873,20 +878,22 @@
       return fileName;
     }
 
-    private String _extractValue(
-      String keyValue,
-      String param)
+    private String _extractValue(final String keyValue, final String param)
     {
-      int length = param.length();
+      final int length = param.length();
       if (keyValue.regionMatches(true, 0, param, 0, length))
       {
         // Remove the leading and trailing quotes
         int start = length;
         if (keyValue.charAt(start) == '"')
+        {
           start++;
+        }
         int end = keyValue.length();
         if (keyValue.charAt(end - 1) == '"')
+        {
           end--;
+        }
         return keyValue.substring(start, end);
       }
 
@@ -894,57 +901,61 @@
     }
 
     private String _name;
+
     private String _filename;
   }
 
   byte[] __getStreamBuffer()
   {
     if (_streamBuffer == null)
+    {
       _streamBuffer = new byte[_STREAM_BUFFER_SIZE];
+    }
     return _streamBuffer;
   }
 
+  private static final String   _MULTIPART_REQUEST_TYPE        = "multipart/form-data";
 
-  private static final String _MULTIPART_REQUEST_TYPE = "multipart/form-data";
-
-  private static final String _DEFAULT_CONTENT_TYPE =
-      "application/octet-stream";
+  private static final String   _DEFAULT_CONTENT_TYPE          = "application/octet-stream";
 
   //Parameter of the content type used to identify the boundary string
-  private static final String _BOUNDARY_PARAMETER = "boundary=";
+  private static final String   _BOUNDARY_PARAMETER            = "boundary=";
+
+  private static final String   _NAME_PARAMETER                = "name=";
 
-  private static final String _NAME_PARAMETER = "name=";
+  private static final String   _FILENAME_PARAMETER            = "filename=";
 
-  private static final String _FILENAME_PARAMETER = "filename=";
+  private static final String   _CONTENT_TYPE_PARAMETER        = "content-type";
 
-  private static final String _CONTENT_TYPE_PARAMETER = "content-type";
+  private static final String   _CONTENT_DISPOSITION_PARAMETER = "content-disposition:";
 
-  private static final String _CONTENT_DISPOSITION_PARAMETER =
-    "content-disposition:";
+  private static final String   _FORM_DATA_DISPOSITION         = "form-data";
 
-  private static final String _FORM_DATA_DISPOSITION =
-    "form-data";
+  private static final String   _HANDLED                       = "org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler.handled";
 
-  private static final String _HANDLED =
-    "org.apache.myfaces.trinidadinternal.share.util.MultipartFormHandler.handled";
+  private static final int      _STREAM_BUFFER_SIZE            = 65000;
 
-  private static final int _STREAM_BUFFER_SIZE = 65000;
-  private static final int _LINE_BUFFER_SIZE = 8000;
+  private static final int      _LINE_BUFFER_SIZE              = 8000;
 
   // Use one buffer for each of file streaming and line reading.
   // Not multithread
   // safe, but this class explicitly _can't_ multithread anyway.
-  private byte[]             _lineBuffer   = new byte[_LINE_BUFFER_SIZE];
-  private byte[]             _streamBuffer;
+  private final byte[]                _lineBuffer                    = new byte[_LINE_BUFFER_SIZE];
+
+  private byte[]                _streamBuffer;
+
+  private InputStream           _in;
+
+  private String                _boundary;
+
+  private MultipartFormItemImpl _currentItem;
+
+  private String                _characterEncoding;
 
-  private InputStream        _in;
-  private String             _boundary;
+  private long                  _maxAllowedBytes               = 1L << 27;
 
-  private MultipartFormItemImpl  _currentItem;
-  private String                 _characterEncoding;
+  private int                   _totalBytesRead;
 
-  private long _maxAllowedBytes = 1L << 27;
-  private int _totalBytesRead;
-  private int _contentStreamSize = -1;
+  private int                   _contentStreamSize             = -1;
 }
 

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/skin/SkinUtils.java Mon Dec  4 18:02:50 2006
@@ -29,9 +29,9 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 
-import javax.servlet.ServletContext;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.myfaces.trinidad.skin.SkinFactory;
@@ -102,7 +102,7 @@
    * @param context ServletContext, used to get the trinidad-skins.xml file.
    */
   static public void registerSkinExtensions(
-    ServletContext context)
+    ExternalContext context)
   {
 
     SkinFactory skinFactory = SkinFactory.getFactory();
@@ -292,7 +292,7 @@
    * @param skinFactory
    */
   private static void _registerSkinExtensions(
-    ServletContext context,
+    ExternalContext context,
     SkinFactory skinFactory)
   {
     if (context == null)
@@ -525,7 +525,7 @@
    * @return List of SkinNodes (skin elements) found in trinidad-skins.xml
    */
   private static SkinsNode _getWebInfSkinsNode(
-    ServletContext context)
+    ExternalContext context)
   {
     InputStream in = context.getResourceAsStream(_CONFIG_FILE);
     if (in != null)

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/ConfigParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/ConfigParser.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/ConfigParser.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/ConfigParser.java Mon Dec  4 18:02:50 2006
@@ -1,263 +0,0 @@
-/*
- * 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.apache.myfaces.trinidadinternal.webapp;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import javax.servlet.ServletContext;
-
-import org.apache.myfaces.trinidad.logging.TrinidadLogger;
-import org.apache.myfaces.trinidad.bean.PropertyKey;
-import org.apache.myfaces.trinidad.webapp.UploadedFileProcessor;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParserFactory;
-
-import javax.faces.el.ValueBinding;
-
-import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
-
-import org.apache.myfaces.trinidadinternal.context.RequestContextBean;
-import org.apache.myfaces.trinidadinternal.util.nls.LocaleUtils;
-
-
-
-/**
- *
- */
-public class ConfigParser
-{
-  /**
-   *
-   */
-  static public RequestContextBean parseConfigFile(
-    ServletContext context)
-  {
-    RequestContextBean bean = new RequestContextBean();
-
-    InputStream in = context.getResourceAsStream(_CONFIG_FILE);
-    if (in != null)
-    {
-      try
-      {
-        InputSource input = new InputSource();
-        input.setByteStream(in);
-        input.setPublicId(_CONFIG_FILE);
-
-        SAXParserFactory factory = SAXParserFactory.newInstance();
-        factory.setNamespaceAware(true);
-        XMLReader reader = factory.newSAXParser().getXMLReader();
-
-        reader.setContentHandler(new Handler(bean,context));
-        reader.parse(input);
-      }
-      catch (IOException ioe)
-      {
-        _LOG.warning(ioe);
-      }
-      catch (ParserConfigurationException pce)
-      {
-        _LOG.warning(pce);
-      }
-      catch (SAXException saxe)
-      {
-        _LOG.warning(saxe);
-      }
-      finally
-      {
-        try
-        {
-          in.close();
-        }
-        catch (IOException ioe)
-        {
-          // Ignore
-          ;
-        }
-      }
-    }
-
-    String className = (String)
-      bean.getProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY);
-    if (className != null)
-    {
-      className = className.trim();
-
-      try
-      {
-        Class<?> clazz = ClassLoaderUtils.loadClass(className);
-        bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
-                         clazz.newInstance());
-      }
-      catch (Exception e)
-      {
-        _LOG.severe("Could not instantiate UploadedFileProcessor", e);
-        bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
-                         new UploadedFileProcessorImpl());
-      }
-    }
-    else
-    {
-      bean.setProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY,
-                       new UploadedFileProcessorImpl());
-    }
-
-    UploadedFileProcessor ufp = (UploadedFileProcessor)
-      bean.getProperty(RequestContextBean.UPLOADED_FILE_PROCESSOR_KEY);
-
-    ufp.init(context);
-
-    if (_LOG.isInfo())
-    {
-      Object debug = bean.getProperty(RequestContextBean.DEBUG_OUTPUT_KEY);
-      if (Boolean.TRUE.equals(debug))
-        _LOG.info("Trinidad is running in debug mode. "+
-                  "Do not use in a production environment. See:"+_CONFIG_FILE);
-    }
-    return bean;
-  }
-
-  static private class Handler extends DefaultHandler
-  {
-    public Handler(RequestContextBean bean,ServletContext context)
-    {
-      _context = context;
-      _bean = bean;
-    }
-
-    @Override
-    public void startElement(String uri,
-                             String localName,
-                             String qName,
-                             Attributes atts)
-    {
-      _currentText = "";
-    }
-
-    @Override
-    public void characters(char[] ch, int start, int length)
-    {
-      if (_currentText != null)
-        _currentText = _currentText + new String(ch, start, length);
-    }
-
-    @Override
-    public void endElement(String uri,
-                           String localName,
-                           String qName)
-    {
-      if ((_currentText != null) && !"".equals(_currentText))
-      {
-        PropertyKey key = _bean.getType().findKey(localName);
-        if (key == null)
-        {
-          if (_LOG.isWarning())
-            _LOG.warning("Element {0} is not understood", qName);
-        }
-        else
-        {
-          if (_currentText.startsWith("#{") &&
-              _currentText.endsWith("}"))
-          {
-            if (!key.getSupportsBinding())
-            {
-              if (_LOG.isWarning())
-                _LOG.warning("Element {0} does not support EL expressions.",
-                             qName);
-            }
-            else
-            {
-              ValueBinding binding =
-                LazyValueBinding.createValueBinding(_currentText);
-              _bean.setValueBinding(key, binding);
-            }
-          }
-          else
-          {
-            Object value;
-
-            if (key.getType() == Character.class)
-            {
-              value = _currentText.charAt(0);
-            }
-            else if (key.getType() == Integer.class)
-            {
-              value = _getIntegerValue(_currentText, qName);
-            }
-            else if (key.getType() == Boolean.class)
-            {
-              value = ("true".equalsIgnoreCase(_currentText)
-                       ? Boolean.TRUE : Boolean.FALSE);
-            }
-            else if (key.getType() == TimeZone.class)
-            {
-              value = TimeZone.getTimeZone(_currentText);
-            }
-            else if (key.getType() == Locale.class)
-            {
-              value = LocaleUtils.getLocaleForIANAString(_currentText);
-            }
-            else
-            {
-              value = _currentText;
-            }
-            if (key == RequestContextBean.REMOTE_DEVICE_REPOSITORY_URI){
-                _context.setAttribute("remote-device-repository-uri",value);
-            }
-            _bean.setProperty(key, value);
-          }
-        }
-      }
-
-      _currentText = null;
-    }
-
-  private static Integer _getIntegerValue(String text, String qName)
-  {
-    Integer value = null;
-    try
-    {
-      value = Integer.valueOf(text);
-    }
-    catch (NumberFormatException nfe)
-    {
-      if (_LOG.isWarning())
-      {
-        _LOG.warning("Element {0} only accepts integer values",
-                     qName);
-      }
-    }
-    return value;
-  }
-
-
-    private RequestContextBean _bean;
-    private String              _currentText;
-    private ServletContext _context;
-  }
-
-  static private final String _CONFIG_FILE = "/WEB-INF/trinidad-config.xml";
-  static private final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(ConfigParser.class);
-}

Modified: incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/DispatchServletResponse.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/DispatchServletResponse.java?view=diff&rev=482451&r1=482450&r2=482451
==============================================================================
--- incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/DispatchServletResponse.java (original)
+++ incubator/adffaces/branches/jwaldman-portal/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/webapp/DispatchServletResponse.java Mon Dec  4 18:02:50 2006
@@ -1,86 +0,0 @@
-/*
- * 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.apache.myfaces.trinidadinternal.webapp;
-
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-
-@SuppressWarnings("deprecation")
-public class DispatchServletResponse extends HttpServletResponseWrapper
-{
-  public DispatchServletResponse(
-    HttpServletResponse delegate,
-    HttpServletRequest  request)
-  {
-    super(delegate);
-    _request = request;
-  }
-
-  @Override
-  public void setContentType(
-    String contentTypeAndCharset)
-  {
-    if(contentTypeAndCharset != null)
-    {
-      Matcher matcher = _CONTENT_TYPE_PATTERN.matcher(contentTypeAndCharset);
-      if (matcher.matches())
-      {
-        String contentType = matcher.group(1);
-        String charset = (matcher.groupCount() > 1) ? matcher.group(2) : null; 
-        
-        // capture the content type on the request
-        _request.setAttribute(_CONTENT_TYPE_KEY, contentType);
-  
-        // TODO: use Agent APIs when available
-        if ("application/xhtml+xml".equals(contentType))
-        {
-          String userAgent = _request.getHeader("User-agent");
-          if (userAgent.indexOf("compatible; MSIE") != -1)
-          {
-            // IE must serve XHTML as text/html
-            contentTypeAndCharset = "text/html";
-  
-            if (charset != null)
-              contentTypeAndCharset += ";charset=" + charset;
-          }
-        }
-      }
-    }
-    super.setContentType(contentTypeAndCharset);
-  }
-  
-  @SuppressWarnings("unchecked")
-  static public String getContentType(
-    FacesContext context)
-  {
-    Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
-    return (String) requestMap.get(_CONTENT_TYPE_KEY);
-  }
-  
-  private final HttpServletRequest _request;
- 
-  static private final String _CONTENT_TYPE_KEY = 
-                                  "org.apache.myfaces.trinidadinternal.CONTENT_TYPE";
-                                  
-  static private final Pattern _CONTENT_TYPE_PATTERN = 
-                                  Pattern.compile("([^;]+)(?:;charset=(.*))?");
-}



Mime
View raw message