1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.apache.jsp;
20
21 import java.io.IOException;
22 import java.net.URL;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Set;
27
28 import javax.servlet.ServletContext;
29 import javax.servlet.ServletException;
30
31 import org.apache.jasper.servlet.JasperInitializer;
32 import org.apache.jasper.servlet.TldPreScanned;
33 import org.apache.jasper.servlet.TldScanner;
34 import org.xml.sax.SAXException;
35
36 /**
37 * JettyJasperInitializer
38 *
39 */
40 public class JettyJasperInitializer extends JasperInitializer
41 {
42
43 /**
44 * NullTldScanner
45 *
46 * Does nothing. Used when we can tell that all jsps have been precompiled, in which case
47 * the tlds are not needed.
48 */
49 private final class NullTldScanner extends TldScanner
50 {
51 /**
52 * @param context
53 * @param namespaceAware
54 * @param validation
55 * @param blockExternal
56 */
57 private NullTldScanner(ServletContext context, boolean namespaceAware, boolean validation, boolean blockExternal)
58 {
59 super(context, namespaceAware, validation, blockExternal);
60 }
61
62 /**
63 * @see org.apache.jasper.servlet.TldScanner#scan()
64 */
65 @Override
66 public void scan() throws IOException, SAXException
67 {
68 return; //do nothing
69 }
70
71 /**
72 * @see org.apache.jasper.servlet.TldScanner#getListeners()
73 */
74 @Override
75 public List<String> getListeners()
76 {
77 return Collections.emptyList();
78 }
79
80 /**
81 * @see org.apache.jasper.servlet.TldScanner#scanJars()
82 */
83 @Override
84 public void scanJars()
85 {
86 return; //do nothing
87 }
88 }
89
90 /**
91 * Make a TldScanner, and prefeed it the tlds that have already been discovered in jar files
92 * by the MetaInfConfiguration.
93 *
94 * @see org.apache.jasper.servlet.JasperInitializer#prepareScanner(javax.servlet.ServletContext, boolean, boolean, boolean)
95 */
96 @Override
97 public TldScanner newTldScanner(ServletContext context, boolean namespaceAware, boolean validate, boolean blockExternal)
98 {
99 String tmp = context.getInitParameter("org.eclipse.jetty.jsp.precompiled");
100 if (tmp!=null && !tmp.equals("") && Boolean.valueOf(tmp))
101 {
102 return new NullTldScanner(context, namespaceAware, validate, blockExternal);
103 }
104
105 Collection<URL> tldUrls = (Collection<URL>)context.getAttribute("org.eclipse.jetty.tlds");
106 if (tldUrls != null && !tldUrls.isEmpty())
107 {
108 return new TldPreScanned(context,namespaceAware,validate,blockExternal,tldUrls);
109 }
110 return super.newTldScanner(context, namespaceAware, validate, blockExternal);
111 }
112
113
114 }