1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.util;
21
22 import javax.faces.FacesException;
23 import javax.faces.FacesWrapper;
24 import javax.faces.component.StateHolder;
25 import javax.faces.context.FacesContext;
26 import javax.servlet.http.Part;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.lang.reflect.InvocationTargetException;
30 import java.lang.reflect.Method;
31 import java.util.Collection;
32
33 public class HttpPartWrapper implements Part, FacesWrapper<Part>, StateHolder {
34 private Part delegate;
35
36 public HttpPartWrapper() {
37 }
38
39 public HttpPartWrapper(final Part delegate) {
40 this.delegate = delegate;
41 }
42
43 @Override
44 public void delete() throws IOException {
45 getWrapped().delete();
46 }
47
48 @Override
49 public String getContentType() {
50 return getWrapped().getContentType();
51 }
52
53 @Override
54 public String getHeader(final String headerName) {
55 return getWrapped().getHeader(headerName);
56 }
57
58 @Override
59 public Collection<String> getHeaderNames() {
60 return getWrapped().getHeaderNames();
61 }
62
63 @Override
64 public Collection<String> getHeaders(final String headerName) {
65 return getWrapped().getHeaders(headerName);
66 }
67
68 @Override
69 public InputStream getInputStream() throws IOException {
70 return getWrapped().getInputStream();
71 }
72
73 @Override
74 public String getName() {
75 return getWrapped().getName();
76 }
77
78 @Override
79 public long getSize() {
80 return getWrapped().getSize();
81 }
82
83 @Override
84 public void write(final String fileName) throws IOException {
85 getWrapped().write(fileName);
86 }
87
88 public String getSubmittedFileName() {
89 final Part wrapped = getWrapped();
90 try {
91 final Method m = wrapped.getClass().getMethod("getSubmittedFileName");
92 return (String) m.invoke(wrapped);
93 } catch (final NoSuchMethodException ex) {
94 throw new FacesException(ex);
95 } catch (final SecurityException ex) {
96 throw new FacesException(ex);
97 } catch (final IllegalAccessException ex) {
98 throw new FacesException(ex);
99 } catch (final IllegalArgumentException ex) {
100 throw new FacesException(ex);
101 } catch (final InvocationTargetException ex) {
102 throw new FacesException(ex);
103 }
104 }
105
106 @Override
107 public Object saveState(final FacesContext context) {
108 return null;
109 }
110
111 @Override
112 public void restoreState(final FacesContext context, final Object state) {
113 }
114
115 @Override
116 public boolean isTransient() {
117 return true;
118 }
119
120 @Override
121 public void setTransient(final boolean newTransientValue) {
122 }
123
124 @Override
125 public Part getWrapped() {
126 return delegate;
127 }
128
129 }