View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared.renderkit.html.util;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import java.lang.reflect.InvocationTargetException;
24  import java.lang.reflect.Method;
25  import java.util.Collection;
26  import javax.faces.FacesException;
27  import javax.faces.FacesWrapper;
28  import javax.faces.component.StateHolder;
29  import javax.faces.context.FacesContext;
30  import javax.servlet.http.Part;
31  
32  public class HttpPartWrapper implements Part, FacesWrapper<Part>, StateHolder
33  {
34      private Part delegate;
35  
36      public HttpPartWrapper()
37      {
38      }
39      
40      public HttpPartWrapper(Part delegate)
41      {
42          this.delegate = delegate;
43      }
44  
45      public void delete() throws IOException
46      {
47          getWrapped().delete();
48      }
49  
50      public String getContentType()
51      {
52          return getWrapped().getContentType();
53      }
54  
55      public String getHeader(String headerName)
56      {
57          return getWrapped().getHeader(headerName);
58      }
59  
60      public Collection<String> getHeaderNames()
61      {
62          return getWrapped().getHeaderNames();
63      }
64  
65      public Collection<String> getHeaders(String headerName)
66      {
67          return getWrapped().getHeaders(headerName);
68      }
69  
70      public InputStream getInputStream() throws IOException
71      {
72          return getWrapped().getInputStream();
73      }
74  
75      public String getName()
76      {
77          return getWrapped().getName();
78      }
79  
80      public long getSize()
81      {
82          return getWrapped().getSize();
83      }
84  
85      public void write(String fileName) throws IOException
86      {
87          getWrapped().write(fileName);
88      }
89      
90      public String getSubmittedFileName()
91      {
92          Part wrapped = getWrapped();
93          try
94          {
95              Method m = wrapped.getClass().getMethod("getSubmittedFileName");
96              return (String) m.invoke(wrapped);
97          }
98          catch (NoSuchMethodException ex)
99          {
100             throw new FacesException(ex);
101         }
102         catch (SecurityException ex)
103         {
104             throw new FacesException(ex);
105         } 
106         catch (IllegalAccessException ex)
107         {
108             throw new FacesException(ex);
109         } 
110         catch (IllegalArgumentException ex)
111         {
112             throw new FacesException(ex);
113         }
114         catch (InvocationTargetException ex)
115         {
116             throw new FacesException(ex);
117         }
118     }
119 
120     public Object saveState(FacesContext context)
121     {
122         return null;
123     }
124 
125     public void restoreState(FacesContext context, Object state)
126     {
127     }
128 
129     public boolean isTransient()
130     {
131         return true;
132     }
133 
134     public void setTransient(boolean newTransientValue)
135     {
136     }
137 
138     public Part getWrapped()
139     {
140         return delegate;
141     }
142     
143 }