View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.struts2.jasper.runtime;
19  
20  import org.apache.struts2.jasper.compiler.Localizer;
21  
22  import javax.servlet.ServletConfig;
23  import javax.servlet.ServletException;
24  import javax.servlet.http.HttpServlet;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  import javax.servlet.jsp.HttpJspPage;
28  import javax.servlet.jsp.JspFactory;
29  import java.io.IOException;
30  
31  /***
32   * This is the super class of all JSP-generated servlets.
33   *
34   * @author Anil K. Vijendran
35   */
36  public abstract class HttpJspBase
37          extends HttpServlet
38          implements HttpJspPage
39  
40  
41  {
42  
43      static {
44          if (JspFactory.getDefaultFactory() == null) {
45              JspFactoryImpl factory = new JspFactoryImpl();
46              if (System.getSecurityManager() != null) {
47                  String basePackage = "org.apache.struts2.jasper.";
48                  try {
49                      factory.getClass().getClassLoader().loadClass(basePackage +
50                              "runtime.JspFactoryImpl$PrivilegedGetPageContext");
51                      factory.getClass().getClassLoader().loadClass(basePackage +
52                              "runtime.JspFactoryImpl$PrivilegedReleasePageContext");
53                      factory.getClass().getClassLoader().loadClass(basePackage +
54                              "runtime.JspRuntimeLibrary");
55                      factory.getClass().getClassLoader().loadClass(basePackage +
56                              "runtime.JspRuntimeLibrary$PrivilegedIntrospectHelper");
57                      factory.getClass().getClassLoader().loadClass(basePackage +
58                              "runtime.ServletResponseWrapperInclude");
59                      factory.getClass().getClassLoader().loadClass(basePackage +
60                              "servlet.JspServletWrapper");
61                  } catch (ClassNotFoundException ex) {
62                      org.apache.commons.logging.LogFactory.getLog(HttpJspBase.class)
63                              .error("Jasper JspRuntimeContext preload of class failed: " +
64                                      ex.getMessage(), ex);
65                  }
66              }
67              JspFactory.setDefaultFactory(factory);
68          }
69      }
70  
71      protected HttpJspBase() {
72      }
73  
74      public final void init(ServletConfig config)
75              throws ServletException {
76          super.init(config);
77          jspInit();
78          _jspInit();
79      }
80  
81      public String getServletInfo() {
82          return Localizer.getMessage("jsp.engine.info");
83      }
84  
85      public final void destroy() {
86          jspDestroy();
87          _jspDestroy();
88      }
89  
90      /***
91       * Entry point into service.
92       */
93      public final void service(HttpServletRequest request, HttpServletResponse response)
94              throws ServletException, IOException {
95          _jspService(request, response);
96      }
97  
98      public void jspInit() {
99      }
100 
101     public void _jspInit() {
102     }
103 
104     public void jspDestroy() {
105     }
106 
107     protected void _jspDestroy() {
108     }
109 
110     public abstract void _jspService(HttpServletRequest request,
111                                      HttpServletResponse response)
112             throws ServletException, IOException;
113 }