View Javadoc
1   /*
2    * #%L
3    * wcm.io
4    * %%
5    * Copyright (C) 2019 wcm.io
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package io.wcm.wcm.ui.granite.pathfield.impl.util;
21  
22  import java.io.IOException;
23  import java.util.Enumeration;
24  
25  import javax.el.ELContext;
26  import javax.servlet.Servlet;
27  import javax.servlet.ServletConfig;
28  import javax.servlet.ServletContext;
29  import javax.servlet.ServletException;
30  import javax.servlet.ServletRequest;
31  import javax.servlet.ServletResponse;
32  import javax.servlet.http.HttpSession;
33  import javax.servlet.jsp.JspWriter;
34  import javax.servlet.jsp.PageContext;
35  import javax.servlet.jsp.el.ExpressionEvaluator;
36  import javax.servlet.jsp.el.VariableResolver;
37  
38  import org.apache.sling.api.SlingHttpServletRequest;
39  import org.apache.sling.api.SlingHttpServletResponse;
40  
41  /**
42   * Workaround because {@link com.adobe.granite.ui.components.ComponentHelper} supports
43   * no direct pass-in of SlingHttpServletRequest.
44   */
45  @SuppressWarnings("deprecation")
46  public final class DummyPageContext extends PageContext {
47  
48    private final SlingHttpServletRequest slingRequest;
49    private final SlingHttpServletResponse slingResponse;
50    private final JspWriter jspWriter;
51  
52    /**
53     * @param slingRequest Request
54     * @param slingResponse Response
55     */
56    public DummyPageContext(SlingHttpServletRequest slingRequest, SlingHttpServletResponse slingResponse) {
57      this.slingRequest = slingRequest;
58      this.slingResponse = slingResponse;
59      try {
60        this.jspWriter = new JspWriterWrapper(slingResponse.getWriter());
61      }
62      catch (IOException ex) {
63        throw new IllegalArgumentException("Unable to get output writer.", ex);
64      }
65    }
66  
67    @Override
68    public ServletRequest getRequest() {
69      return slingRequest;
70    }
71  
72    @Override
73    public ServletResponse getResponse() {
74      return slingResponse;
75    }
76  
77    @Override
78    public JspWriter getOut() {
79      return jspWriter;
80    }
81  
82  
83    // --- unsupported methods ---
84  
85    @Override
86    public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize,
87        boolean autoFlush) throws IOException, IllegalStateException, IllegalArgumentException {
88      throw new UnsupportedOperationException();
89    }
90  
91    @Override
92    public void release() {
93      throw new UnsupportedOperationException();
94    }
95  
96    @Override
97    public HttpSession getSession() {
98      throw new UnsupportedOperationException();
99    }
100 
101   @Override
102   public Object getPage() {
103     throw new UnsupportedOperationException();
104   }
105 
106   @Override
107   public Exception getException() {
108     throw new UnsupportedOperationException();
109   }
110 
111   @Override
112   public ServletConfig getServletConfig() {
113     throw new UnsupportedOperationException();
114   }
115 
116   @Override
117   public ServletContext getServletContext() {
118     throw new UnsupportedOperationException();
119   }
120 
121   @Override
122   public void forward(String relativeUrlPath) throws ServletException, IOException {
123     throw new UnsupportedOperationException();
124   }
125 
126   @Override
127   public void include(String relativeUrlPath) throws ServletException, IOException {
128     throw new UnsupportedOperationException();
129   }
130 
131   @Override
132   public void include(String relativeUrlPath, boolean flush) throws ServletException, IOException {
133     throw new UnsupportedOperationException();
134   }
135 
136   @Override
137   public void handlePageException(Exception e) throws ServletException, IOException {
138     throw new UnsupportedOperationException();
139   }
140 
141   @Override
142   public void handlePageException(Throwable t) throws ServletException, IOException {
143     throw new UnsupportedOperationException();
144   }
145 
146   @Override
147   public void setAttribute(String name, Object value) {
148     throw new UnsupportedOperationException();
149   }
150 
151   @Override
152   public void setAttribute(String name, Object value, int scope) {
153     throw new UnsupportedOperationException();
154   }
155 
156   @Override
157   public Object getAttribute(String name) {
158     throw new UnsupportedOperationException();
159   }
160 
161   @Override
162   public Object getAttribute(String name, int scope) {
163     throw new UnsupportedOperationException();
164   }
165 
166   @Override
167   public Object findAttribute(String name) {
168     throw new UnsupportedOperationException();
169   }
170 
171   @Override
172   public void removeAttribute(String name) {
173     throw new UnsupportedOperationException();
174   }
175 
176   @Override
177   public void removeAttribute(String name, int scope) {
178     throw new UnsupportedOperationException();
179   }
180 
181   @Override
182   public int getAttributesScope(String name) {
183     throw new UnsupportedOperationException();
184   }
185 
186   @Override
187   public Enumeration<String> getAttributeNamesInScope(int scope) {
188     throw new UnsupportedOperationException();
189   }
190 
191   @Override
192   public ExpressionEvaluator getExpressionEvaluator() {
193     throw new UnsupportedOperationException();
194   }
195 
196   @Override
197   public VariableResolver getVariableResolver() {
198     throw new UnsupportedOperationException();
199   }
200 
201   @Override
202   public ELContext getELContext() {
203     throw new UnsupportedOperationException();
204   }
205 
206 }