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.custom.redirectTracker;
20  
21  import javax.faces.context.ExternalContext;
22  import javax.faces.context.FacesContext;
23  import java.io.IOException;
24  import java.io.InputStream;
25  import java.util.Map;
26  import java.util.Locale;
27  import java.util.Iterator;
28  import java.util.Set;
29  import java.net.URL;
30  import java.net.MalformedURLException;
31  import java.security.Principal;
32  
33  /**
34   * wraps a external context
35   */
36  public class RedirectTrackerExternalContextWrapper extends ExternalContext
37  {
38      private final ExternalContext original;
39  
40      public RedirectTrackerExternalContextWrapper(ExternalContext original)
41      {
42          this.original = original;
43      }
44  
45      public void dispatch(String s)
46          throws IOException
47      {
48          original.dispatch(s);
49      }
50  
51      public String encodeActionURL(String s)
52      {
53          return original.encodeActionURL(s);
54      }
55  
56      public String encodeNamespace(String s)
57      {
58          return original.encodeNamespace(s);
59      }
60  
61      public String encodeResourceURL(String s)
62      {
63          return original.encodeResourceURL(s);
64      }
65  
66      public Map getApplicationMap()
67      {
68          return original.getApplicationMap();
69      }
70  
71      public String getAuthType()
72      {
73          return original.getAuthType();
74      }
75  
76      public Object getContext()
77      {
78          return original.getContext();
79      }
80  
81      public String getInitParameter(String s)
82      {
83          return original.getInitParameter(s);
84      }
85  
86      public Map getInitParameterMap()
87      {
88          return original.getInitParameterMap();
89      }
90  
91      public String getRemoteUser()
92      {
93          return original.getRemoteUser();
94      }
95  
96      public Object getRequest()
97      {
98          return original.getRequest();
99      }
100 
101     public String getRequestContextPath()
102     {
103         return original.getRequestContextPath();
104     }
105 
106     public Map getRequestCookieMap()
107     {
108         return original.getRequestCookieMap();
109     }
110 
111     public Map getRequestHeaderMap()
112     {
113         return original.getRequestHeaderMap();
114     }
115 
116     public Map getRequestHeaderValuesMap()
117     {
118         return original.getRequestHeaderValuesMap();
119     }
120 
121     public Locale getRequestLocale()
122     {
123         return original.getRequestLocale();
124     }
125 
126     public Iterator getRequestLocales()
127     {
128         return original.getRequestLocales();
129     }
130 
131     public Map getRequestMap()
132     {
133         return original.getRequestMap();
134     }
135 
136     public Map getRequestParameterMap()
137     {
138         return original.getRequestParameterMap();
139     }
140 
141     public Iterator getRequestParameterNames()
142     {
143         return original.getRequestParameterNames();
144     }
145 
146     public Map getRequestParameterValuesMap()
147     {
148         return original.getRequestParameterValuesMap();
149     }
150 
151     public String getRequestPathInfo()
152     {
153         return original.getRequestPathInfo();
154     }
155 
156     public String getRequestServletPath()
157     {
158         return original.getRequestServletPath();
159     }
160 
161     public URL getResource(String s)
162         throws MalformedURLException
163     {
164         return original.getResource(s);
165     }
166 
167     public InputStream getResourceAsStream(String s)
168     {
169         return original.getResourceAsStream(s);
170     }
171 
172     public Set getResourcePaths(String s)
173     {
174         return original.getResourcePaths(s);
175     }
176 
177     public Object getResponse()
178     {
179         return original.getResponse();
180     }
181 
182     public Object getSession(boolean b)
183     {
184         return original.getSession(b);
185     }
186 
187     public Map getSessionMap()
188     {
189         return original.getSessionMap();
190     }
191 
192     public Principal getUserPrincipal()
193     {
194         return original.getUserPrincipal();
195     }
196 
197     public boolean isUserInRole(String s)
198     {
199         return original.isUserInRole(s);
200     }
201 
202     public void log(String s)
203     {
204         original.log(s);
205     }
206 
207     public void log(String s, Throwable throwable)
208     {
209         original.log(s, throwable);
210     }
211 
212     public void redirect(String url) throws IOException
213     {
214         FacesContext facesContext = FacesContext.getCurrentInstance();
215 
216         RedirectTrackerManager manager = RedirectTrackerManager.getInstance(facesContext);
217         if (manager != null)
218         {
219             url = manager.trackRedirect(facesContext, url);
220         }
221 
222         original.redirect(url);
223     }
224 
225     public ExternalContext getWrappedExternalContext()
226     {
227         return original;
228     }
229 }