View | Details | Raw Unified | Return to bug 53737
Collapse All | Expand All

(-)java/org/apache/jasper/JspC.java (-41 / +23 lines)
Lines 30-46 Link Here
30
import java.io.PrintWriter;
30
import java.io.PrintWriter;
31
import java.io.Reader;
31
import java.io.Reader;
32
import java.io.Writer;
32
import java.io.Writer;
33
import java.net.MalformedURLException;
34
import java.net.URL;
33
import java.net.URL;
35
import java.net.URLClassLoader;
34
import java.net.URLClassLoader;
36
import java.util.ArrayList;
35
import java.util.ArrayList;
36
import java.util.Arrays;
37
import java.util.HashMap;
37
import java.util.HashMap;
38
import java.util.HashSet;
38
import java.util.HashSet;
39
import java.util.Iterator;
39
import java.util.Iterator;
40
import java.util.LinkedList;
40
import java.util.List;
41
import java.util.List;
41
import java.util.Map;
42
import java.util.Map;
42
import java.util.Set;
43
import java.util.Set;
43
import java.util.Stack;
44
import java.util.StringTokenizer;
44
import java.util.StringTokenizer;
45
import java.util.Vector;
45
import java.util.Vector;
46
46
Lines 1217-1253 Link Here
1217
    }
1217
    }
1218
1218
1219
    /**
1219
    /**
1220
     * Locate all jsp files in the webapp. Used if no explicit
1220
     * Locate all jsp files in the webapp, including those from web-fragments.
1221
     * jsps are specified.
1221
     * Used if no explicit jsps are specified.
1222
     */
1222
     */
1223
    public void scanFiles( File base ) throws JasperException {
1223
    public void scanFiles() {
1224
        Stack<String> dirs = new Stack<>();
1224
        if (extensions == null) {
1225
        dirs.push(base.toString());
1225
            extensions = Arrays.asList("jsp", "jspx");
1226
1227
        // Make sure default extensions are always included
1228
        if ((getExtensions() == null) || (getExtensions().size() < 2)) {
1229
            addExtension("jsp");
1230
            addExtension("jspx");
1231
        }
1226
        }
1232
1227
        LinkedList<String> dirs = new LinkedList<>();
1233
        while (!dirs.isEmpty()) {
1228
        dirs.add("/");
1234
            String s = dirs.pop();
1229
        for (String dir = dirs.poll(); dir != null; dir = dirs.poll()) {
1235
            File f = new File(s);
1230
            for (String file : context.getResourcePaths(dir)) {
1236
            if (f.exists() && f.isDirectory()) {
1231
                if (file.endsWith("/")) {
1237
                String[] files = f.list();
1232
                    dirs.add(file);
1238
                String ext;
1233
                } else {
1239
                for (int i = 0; (files != null) && i < files.length; i++) {
1234
                    String ext = file.substring(file.lastIndexOf('.') + 1);
1240
                    File f2 = new File(s, files[i]);
1235
                    if (extensions.contains(ext) || jspConfig.isJspPage(file)) {
1241
                    if (f2.isDirectory()) {
1236
                        pages.add(file.substring(1));
1242
                        dirs.push(f2.getPath());
1243
                    } else {
1244
                        String path = f2.getPath();
1245
                        String uri = path.substring(uriRoot.length());
1246
                        ext = files[i].substring(files[i].lastIndexOf('.') +1);
1247
                        if (getExtensions().contains(ext) ||
1248
                            jspConfig.isJspPage(uri)) {
1249
                            pages.add(path);
1250
                        }
1251
                    }
1237
                    }
1252
                }
1238
                }
1253
            }
1239
            }
Lines 1296-1302 Link Here
1296
1282
1297
            // No explicit pages, we'll process all .jsp in the webapp
1283
            // No explicit pages, we'll process all .jsp in the webapp
1298
            if (pages.size() == 0) {
1284
            if (pages.size() == 0) {
1299
                scanFiles(uriRootF);
1285
                scanFiles();
1300
            }
1286
            }
1301
1287
1302
            initWebXml();
1288
            initWebXml();
Lines 1414-1428 Link Here
1414
        }
1400
        }
1415
    }
1401
    }
1416
1402
1417
    protected void initServletContext() {
1403
    protected void initServletContext() throws IOException, JasperException {
1418
        try {
1404
        // TODO: should we use the Ant Project's log?
1419
            context =new JspCServletContext
1405
        PrintWriter log = new PrintWriter(System.out);
1420
                (new PrintWriter(System.out),
1406
        URL resourceBase = new File(uriRoot).getCanonicalFile().toURI().toURL();
1421
                 new URL("file:" + uriRoot.replace('\\','/') + '/'));
1407
        context = new JspCServletContext(log, resourceBase);
1422
            tldLocationsCache = TldLocationsCache.getInstance(context);
1423
        } catch (MalformedURLException me) {
1424
            System.out.println("**" + me);
1425
        }
1426
        rctxt = new JspRuntimeContext(context, this);
1408
        rctxt = new JspRuntimeContext(context, this);
1427
        jspConfig = new JspConfig(context);
1409
        jspConfig = new JspConfig(context);
1428
        tagPluginManager = new TagPluginManager(context);
1410
        tagPluginManager = new TagPluginManager(context);
(-)java/org/apache/jasper/compiler/JspConfig.java (-247 / +116 lines)
Lines 17-30 Link Here
17
17
18
package org.apache.jasper.compiler;
18
package org.apache.jasper.compiler;
19
19
20
import java.util.Iterator;
20
import java.util.ArrayList;
21
import java.util.Collection;
22
import java.util.List;
21
import java.util.Vector;
23
import java.util.Vector;
22
24
23
import javax.servlet.ServletContext;
25
import javax.servlet.ServletContext;
26
import javax.servlet.descriptor.JspConfigDescriptor;
27
import javax.servlet.descriptor.JspPropertyGroupDescriptor;
24
28
25
import org.apache.jasper.JasperException;
26
import org.apache.jasper.xmlparser.ParserUtils;
27
import org.apache.jasper.xmlparser.TreeNode;
28
import org.apache.juli.logging.Log;
29
import org.apache.juli.logging.Log;
29
import org.apache.juli.logging.LogFactory;
30
import org.apache.juli.logging.LogFactory;
30
31
Lines 41-249 Link Here
41
    // Logger
42
    // Logger
42
    private final Log log = LogFactory.getLog(JspConfig.class);
43
    private final Log log = LogFactory.getLog(JspConfig.class);
43
44
44
    private Vector<JspPropertyGroup> jspProperties = null;
45
    private final JspProperty defaultJspProperty;
45
    private final ServletContext ctxt;
46
    private final List<JspPropertyGroup> jspProperties;
46
    private volatile boolean initialized = false;
47
47
48
    private static final String defaultIsXml = null;    // unspecified
49
    private String defaultIsELIgnored = null;           // unspecified
50
    private static final String defaultIsScriptingInvalid = null;
51
    private String defaultDeferedSyntaxAllowedAsLiteral = null;
52
    private static final String defaultTrimDirectiveWhitespaces = null;
53
    private static final String defaultDefaultContentType = null;
54
    private static final String defaultBuffer = null;
55
    private static final String defaultErrorOnUndeclaredNamespace = "false";
56
    private JspProperty defaultJspProperty;
57
58
    public JspConfig(ServletContext ctxt) {
48
    public JspConfig(ServletContext ctxt) {
59
        this.ctxt = ctxt;
49
        // set up default behaviour based on effective Servlet specification version
60
    }
50
        int major = ctxt.getEffectiveMajorVersion();
51
        int minor = ctxt.getEffectiveMinorVersion();
61
52
62
    private double getVersion(TreeNode webApp) {
53
        if (major < 2 || major == 2 && minor < 4) {
63
        String v = webApp.findAttribute("version");
54
            // < 2.4 : elIgnored, deferedSyntaxAllowedAsLiteral, and no jsp-config
64
        if (v != null) {
55
            defaultJspProperty = new JspProperty("true", "true");
65
            try {
56
            jspProperties = null;
66
                return Double.parseDouble(v);
57
            return;
67
            } catch (NumberFormatException e) {
58
        } else if (major == 2 && minor == 4) {
68
            }
59
            // 2.4 : deferedSyntaxAllowedAsLiteral
60
            defaultJspProperty = new JspProperty(null, "true");
61
        } else {
62
            defaultJspProperty = new JspProperty(null, null);
69
        }
63
        }
70
        return 2.3;
64
        jspProperties = processJspConfig(ctxt);
71
    }
65
    }
72
66
73
    private void processWebDotXml() throws JasperException {
67
    private List<JspPropertyGroup> processJspConfig(ServletContext ctxt) {
68
        JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
69
        if (jspConfig == null) {
70
            // no jsp-config for this application
71
            return null;
72
        }
74
73
75
        WebXml webXml = null;
74
        Collection<JspPropertyGroupDescriptor> jspPropertyGroups = jspConfig.getJspPropertyGroups();
75
        List<JspPropertyGroup> jspProperties = new ArrayList<>();
76
        for (JspPropertyGroupDescriptor jspPropertyGroup : jspPropertyGroups) {
76
77
77
        try {
78
            Collection<String> urlPatterns = jspPropertyGroup.getUrlPatterns();
78
            webXml = new WebXml(ctxt);
79
            if (urlPatterns.isEmpty()) {
79
80
                continue;
80
            TreeNode webApp = null;
81
            if (webXml.getInputSource() != null) {
82
                ParserUtils pu = new ParserUtils();
83
                webApp = pu.parseXMLDocument(webXml.getSystemId(),
84
                        webXml.getInputSource());
85
            }
81
            }
86
82
87
            if (webApp == null
83
            JspProperty property = new JspProperty(jspPropertyGroup.getIsXml(),
88
                    || getVersion(webApp) < 2.4) {
84
                    jspPropertyGroup.getElIgnored(),
89
                defaultIsELIgnored = "true";
85
                    jspPropertyGroup.getScriptingInvalid(),
90
                defaultDeferedSyntaxAllowedAsLiteral = "true";
86
                    jspPropertyGroup.getPageEncoding(),
91
                return;
87
                    new Vector<>(jspPropertyGroup.getIncludePreludes()),
92
            }
88
                    new Vector<>(jspPropertyGroup.getIncludeCodas()),
93
            if (getVersion(webApp) < 2.5) {
89
                    jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral(),
94
                defaultDeferedSyntaxAllowedAsLiteral = "true";
90
                    jspPropertyGroup.getTrimDirectiveWhitespaces(),
95
            }
91
                    jspPropertyGroup.getDefaultContentType(),
96
            TreeNode jspConfig = webApp.findChild("jsp-config");
92
                    jspPropertyGroup.getBuffer(),
97
            if (jspConfig == null) {
93
                    jspPropertyGroup.getErrorOnUndeclaredNamespace());
98
                return;
99
            }
100
94
101
            jspProperties = new Vector<>();
95
            // Add one JspPropertyGroup for each URL Pattern.  This makes
102
            Iterator<TreeNode> jspPropertyList =
96
            // the matching logic easier.
103
                jspConfig.findChildren("jsp-property-group");
97
            for (String urlPattern : urlPatterns) {
104
            while (jspPropertyList.hasNext()) {
98
                String path = null;
99
                String extension = null;
105
100
106
                TreeNode element = jspPropertyList.next();
101
                if (urlPattern.indexOf('*') < 0) {
107
                Iterator<TreeNode> list = element.findChildren();
102
                    // Exact match
108
103
                    path = urlPattern;
109
                Vector<String> urlPatterns = new Vector<>();
104
                } else {
110
                String pageEncoding = null;
105
                    int i = urlPattern.lastIndexOf('/');
111
                String scriptingInvalid = null;
106
                    String file;
112
                String elIgnored = null;
107
                    if (i >= 0) {
113
                String isXml = null;
108
                        path = urlPattern.substring(0, i + 1);
114
                Vector<String> includePrelude = new Vector<>();
109
                        file = urlPattern.substring(i + 1);
115
                Vector<String> includeCoda = new Vector<>();
116
                String deferredSyntaxAllowedAsLiteral = null;
117
                String trimDirectiveWhitespaces = null;
118
                String defaultContentType = null;
119
                String buffer = null;
120
                String errorOnUndeclaredNamespace = null;
121
122
                while (list.hasNext()) {
123
124
                    element = list.next();
125
                    String tname = element.getName();
126
127
                    if ("url-pattern".equals(tname))
128
                        urlPatterns.addElement( element.getBody() );
129
                    else if ("page-encoding".equals(tname))
130
                        pageEncoding = element.getBody();
131
                    else if ("is-xml".equals(tname))
132
                        isXml = element.getBody();
133
                    else if ("el-ignored".equals(tname))
134
                        elIgnored = element.getBody();
135
                    else if ("scripting-invalid".equals(tname))
136
                        scriptingInvalid = element.getBody();
137
                    else if ("include-prelude".equals(tname))
138
                        includePrelude.addElement(element.getBody());
139
                    else if ("include-coda".equals(tname))
140
                        includeCoda.addElement(element.getBody());
141
                    else if ("deferred-syntax-allowed-as-literal".equals(tname))
142
                        deferredSyntaxAllowedAsLiteral = element.getBody();
143
                    else if ("trim-directive-whitespaces".equals(tname))
144
                        trimDirectiveWhitespaces = element.getBody();
145
                    else if ("default-content-type".equals(tname))
146
                        defaultContentType = element.getBody();
147
                    else if ("buffer".equals(tname))
148
                        buffer = element.getBody();
149
                    else if ("error-on-undeclared-namespace".equals(tname))
150
                        errorOnUndeclaredNamespace = element.getBody();
151
                }
152
153
                if (urlPatterns.size() == 0) {
154
                    continue;
155
                }
156
157
                // Add one JspPropertyGroup for each URL Pattern.  This makes
158
                // the matching logic easier.
159
                for( int p = 0; p < urlPatterns.size(); p++ ) {
160
                    String urlPattern = urlPatterns.elementAt( p );
161
                    String path = null;
162
                    String extension = null;
163
164
                    if (urlPattern.indexOf('*') < 0) {
165
                        // Exact match
166
                        path = urlPattern;
167
                    } else {
110
                    } else {
168
                        int i = urlPattern.lastIndexOf('/');
111
                        file = urlPattern;
169
                        String file;
112
                    }
170
                        if (i >= 0) {
171
                            path = urlPattern.substring(0,i+1);
172
                            file = urlPattern.substring(i+1);
173
                        } else {
174
                            file = urlPattern;
175
                        }
176
113
177
                        // pattern must be "*", or of the form "*.jsp"
114
                    // pattern must be "*", or of the form "*.jsp"
178
                        if (file.equals("*")) {
115
                    if (file.equals("*")) {
179
                            extension = "*";
116
                        extension = "*";
180
                        } else if (file.startsWith("*.")) {
117
                    } else if (file.startsWith("*.")) {
181
                            extension = file.substring(file.indexOf('.')+1);
118
                        extension = file.substring(file.indexOf('.') + 1);
182
                        }
119
                    }
183
120
184
                        // The url patterns are reconstructed as the following:
121
                    // The url patterns are reconstructed as the following:
185
                        // path != null, extension == null:  / or /foo/bar.ext
122
                    // path != null, extension == null:  / or /foo/bar.ext
186
                        // path == null, extension != null:  *.ext
123
                    // path == null, extension != null:  *.ext
187
                        // path != null, extension == "*":   /foo/*
124
                    // path != null, extension == "*":   /foo/*
188
                        boolean isStar = "*".equals(extension);
125
                    boolean isStar = "*".equals(extension);
189
                        if ((path == null && (extension == null || isStar))
126
                    if ((path == null && (extension == null || isStar))
190
                                || (path != null && !isStar)) {
127
                            || (path != null && !isStar)) {
191
                            if (log.isWarnEnabled()) {
128
                        if (log.isWarnEnabled()) {
192
                                log.warn(Localizer.getMessage(
129
                            log.warn(Localizer.getMessage(
193
                                        "jsp.warning.bad.urlpattern.propertygroup",
130
                                    "jsp.warning.bad.urlpattern.propertygroup",
194
                                        urlPattern));
131
                                    urlPattern));
195
                            }
196
                            continue;
197
                        }
132
                        }
133
                        continue;
198
                    }
134
                    }
135
                }
199
136
200
                    JspProperty property = new JspProperty(isXml,
137
                JspPropertyGroup propertyGroup =
201
                            elIgnored,
202
                            scriptingInvalid,
203
                            pageEncoding,
204
                            includePrelude,
205
                            includeCoda,
206
                            deferredSyntaxAllowedAsLiteral,
207
                            trimDirectiveWhitespaces,
208
                            defaultContentType,
209
                            buffer,
210
                            errorOnUndeclaredNamespace);
211
                    JspPropertyGroup propertyGroup =
212
                        new JspPropertyGroup(path, extension, property);
138
                        new JspPropertyGroup(path, extension, property);
213
139
214
                    jspProperties.addElement(propertyGroup);
140
                jspProperties.add(propertyGroup);
215
                }
216
            }
141
            }
217
        } catch (Exception ex) {
218
            throw new JasperException(ex);
219
        } finally {
220
            if (webXml != null) {
221
                webXml.close();
222
            }
223
        }
142
        }
143
        return jspProperties;
224
    }
144
    }
225
145
226
    private void init() throws JasperException {
227
228
        if (!initialized) {
229
            synchronized (this) {
230
                if (!initialized) {
231
                    processWebDotXml();
232
                    defaultJspProperty = new JspProperty(defaultIsXml,
233
                            defaultIsELIgnored,
234
                            defaultIsScriptingInvalid,
235
                            null, null, null,
236
                            defaultDeferedSyntaxAllowedAsLiteral,
237
                            defaultTrimDirectiveWhitespaces,
238
                            defaultDefaultContentType,
239
                            defaultBuffer,
240
                            defaultErrorOnUndeclaredNamespace);
241
                    initialized = true;
242
                }
243
            }
244
        }
245
    }
246
247
    /**
146
    /**
248
     * Select the property group that has more restrictive url-pattern.
147
     * Select the property group that has more restrictive url-pattern.
249
     * In case of tie, select the first.
148
     * In case of tie, select the first.
Lines 268-277 Link Here
268
            // Both specifies a *.ext, keep the first one
167
            // Both specifies a *.ext, keep the first one
269
            return prev;
168
            return prev;
270
        }
169
        }
271
        if (prevPath == null && currPath != null) {
170
        if (prevPath == null) {
272
            return curr;
171
            return curr;
273
        }
172
        }
274
        if (prevPath != null && currPath == null) {
173
        if (currPath == null) {
275
            return prev;
174
            return prev;
276
        }
175
        }
277
        if (prevPath.length() >= currPath.length()) {
176
        if (prevPath.length() >= currPath.length()) {
Lines 286-295 Link Here
286
     * @param uri the resource supplied.
185
     * @param uri the resource supplied.
287
     * @return a JspProperty indicating the best match, or some default.
186
     * @return a JspProperty indicating the best match, or some default.
288
     */
187
     */
289
    public JspProperty findJspProperty(String uri) throws JasperException {
188
    public JspProperty findJspProperty(String uri) {
290
189
291
        init();
292
293
        // JSP Configuration settings do not apply to tag files
190
        // JSP Configuration settings do not apply to tag files
294
        if (jspProperties == null || uri.endsWith(".tag")
191
        if (jspProperties == null || uri.endsWith(".tag")
295
                || uri.endsWith(".tagx")) {
192
                || uri.endsWith(".tagx")) {
Lines 320-329 Link Here
320
        JspPropertyGroup bufferMatch = null;
217
        JspPropertyGroup bufferMatch = null;
321
        JspPropertyGroup errorOnUndeclaredNamespaceMatch = null;
218
        JspPropertyGroup errorOnUndeclaredNamespaceMatch = null;
322
219
323
        Iterator<JspPropertyGroup> iter = jspProperties.iterator();
220
        for (JspPropertyGroup jpg : jspProperties) {
324
        while (iter.hasNext()) {
325
221
326
            JspPropertyGroup jpg = iter.next();
327
            JspProperty jp = jpg.getJspProperty();
222
            JspProperty jp = jpg.getJspProperty();
328
223
329
            // (arrays will be the same length)
224
            // (arrays will be the same length)
Lines 339-345 Link Here
339
            } else {
234
            } else {
340
                // Matching patterns *.ext or /p/*
235
                // Matching patterns *.ext or /p/*
341
                if (path != null && uriPath != null &&
236
                if (path != null && uriPath != null &&
342
                        ! uriPath.startsWith(path)) {
237
                        !uriPath.startsWith(path)) {
343
                    // not matched
238
                    // not matched
344
                    continue;
239
                    continue;
345
                }
240
                }
Lines 368-457 Link Here
368
            }
263
            }
369
            if (jp.isScriptingInvalid() != null) {
264
            if (jp.isScriptingInvalid() != null) {
370
                scriptingInvalidMatch =
265
                scriptingInvalidMatch =
371
                    selectProperty(scriptingInvalidMatch, jpg);
266
                        selectProperty(scriptingInvalidMatch, jpg);
372
            }
267
            }
373
            if (jp.getPageEncoding() != null) {
268
            if (jp.getPageEncoding() != null) {
374
                pageEncodingMatch = selectProperty(pageEncodingMatch, jpg);
269
                pageEncodingMatch = selectProperty(pageEncodingMatch, jpg);
375
            }
270
            }
376
            if (jp.isDeferedSyntaxAllowedAsLiteral() != null) {
271
            if (jp.isDeferedSyntaxAllowedAsLiteral() != null) {
377
                deferedSyntaxAllowedAsLiteralMatch =
272
                deferedSyntaxAllowedAsLiteralMatch =
378
                    selectProperty(deferedSyntaxAllowedAsLiteralMatch, jpg);
273
                        selectProperty(deferedSyntaxAllowedAsLiteralMatch, jpg);
379
            }
274
            }
380
            if (jp.isTrimDirectiveWhitespaces() != null) {
275
            if (jp.isTrimDirectiveWhitespaces() != null) {
381
                trimDirectiveWhitespacesMatch =
276
                trimDirectiveWhitespacesMatch =
382
                    selectProperty(trimDirectiveWhitespacesMatch, jpg);
277
                        selectProperty(trimDirectiveWhitespacesMatch, jpg);
383
            }
278
            }
384
            if (jp.getDefaultContentType() != null) {
279
            if (jp.getDefaultContentType() != null) {
385
                defaultContentTypeMatch =
280
                defaultContentTypeMatch =
386
                    selectProperty(defaultContentTypeMatch, jpg);
281
                        selectProperty(defaultContentTypeMatch, jpg);
387
            }
282
            }
388
            if (jp.getBuffer() != null) {
283
            if (jp.getBuffer() != null) {
389
                bufferMatch = selectProperty(bufferMatch, jpg);
284
                bufferMatch = selectProperty(bufferMatch, jpg);
390
            }
285
            }
391
            if (jp.isErrorOnUndeclaredNamespace() != null) {
286
            if (jp.isErrorOnUndeclaredNamespace() != null) {
392
                errorOnUndeclaredNamespaceMatch =
287
                errorOnUndeclaredNamespaceMatch =
393
                    selectProperty(errorOnUndeclaredNamespaceMatch, jpg);
288
                        selectProperty(errorOnUndeclaredNamespaceMatch, jpg);
394
            }
289
            }
395
        }
290
        }
396
291
397
292
398
        String isXml = defaultIsXml;
293
        String isXml = defaultProperty(isXmlMatch).isXml();
399
        String isELIgnored = defaultIsELIgnored;
294
        String isELIgnored = defaultProperty(elIgnoredMatch).isELIgnored();
400
        String isScriptingInvalid = defaultIsScriptingInvalid;
295
        String isScriptingInvalid = defaultProperty(scriptingInvalidMatch).isScriptingInvalid();
401
        String pageEncoding = null;
296
        String pageEncoding = defaultProperty(pageEncodingMatch).getPageEncoding();
402
        String isDeferedSyntaxAllowedAsLiteral =
297
        String isDeferedSyntaxAllowedAsLiteral = defaultProperty(defaultContentTypeMatch).isDeferedSyntaxAllowedAsLiteral();
403
            defaultDeferedSyntaxAllowedAsLiteral;
298
        String isTrimDirectiveWhitespaces = defaultProperty(trimDirectiveWhitespacesMatch).isTrimDirectiveWhitespaces();
404
        String isTrimDirectiveWhitespaces = defaultTrimDirectiveWhitespaces;
299
        String defaultContentType = defaultProperty(defaultContentTypeMatch).getDefaultContentType();
405
        String defaultContentType = defaultDefaultContentType;
300
        String buffer = defaultProperty(bufferMatch).getBuffer();
406
        String buffer = defaultBuffer;
301
        String errorOnUndeclaredNamespace = defaultProperty(errorOnUndeclaredNamespaceMatch).isErrorOnUndeclaredNamespace();
407
        String errorOnUndelcaredNamespace = defaultErrorOnUndeclaredNamespace;
408
302
409
        if (isXmlMatch != null) {
410
            isXml = isXmlMatch.getJspProperty().isXml();
411
        }
412
        if (elIgnoredMatch != null) {
413
            isELIgnored = elIgnoredMatch.getJspProperty().isELIgnored();
414
        }
415
        if (scriptingInvalidMatch != null) {
416
            isScriptingInvalid =
417
                scriptingInvalidMatch.getJspProperty().isScriptingInvalid();
418
        }
419
        if (pageEncodingMatch != null) {
420
            pageEncoding = pageEncodingMatch.getJspProperty().getPageEncoding();
421
        }
422
        if (deferedSyntaxAllowedAsLiteralMatch != null) {
423
            isDeferedSyntaxAllowedAsLiteral =
424
                deferedSyntaxAllowedAsLiteralMatch.getJspProperty().isDeferedSyntaxAllowedAsLiteral();
425
        }
426
        if (trimDirectiveWhitespacesMatch != null) {
427
            isTrimDirectiveWhitespaces =
428
                trimDirectiveWhitespacesMatch.getJspProperty().isTrimDirectiveWhitespaces();
429
        }
430
        if (defaultContentTypeMatch != null) {
431
            defaultContentType =
432
                defaultContentTypeMatch.getJspProperty().getDefaultContentType();
433
        }
434
        if (bufferMatch != null) {
435
            buffer = bufferMatch.getJspProperty().getBuffer();
436
        }
437
        if (errorOnUndeclaredNamespaceMatch != null) {
438
            errorOnUndelcaredNamespace =
439
                errorOnUndeclaredNamespaceMatch.getJspProperty().isErrorOnUndeclaredNamespace();
440
        }
441
442
        return new JspProperty(isXml, isELIgnored, isScriptingInvalid,
303
        return new JspProperty(isXml, isELIgnored, isScriptingInvalid,
443
                pageEncoding, includePreludes, includeCodas,
304
                pageEncoding, includePreludes, includeCodas,
444
                isDeferedSyntaxAllowedAsLiteral, isTrimDirectiveWhitespaces,
305
                isDeferedSyntaxAllowedAsLiteral, isTrimDirectiveWhitespaces,
445
                defaultContentType, buffer, errorOnUndelcaredNamespace);
306
                defaultContentType, buffer, errorOnUndeclaredNamespace);
446
    }
307
    }
447
308
309
    private JspProperty defaultProperty(JspPropertyGroup match) {
310
        if (match == null) {
311
            return defaultJspProperty;
312
        } else {
313
            return match.getJspProperty();
314
        }
315
    }
316
448
    /**
317
    /**
449
     * To find out if an uri matches an url pattern in jsp config.  If so,
318
     * To find out if an uri matches an url pattern in jsp config.  If so,
450
     * then the uri is a JSP page.  This is used primarily for jspc.
319
     * then the uri is a JSP page.  This is used primarily for jspc.
451
     */
320
     */
452
    public boolean isJspPage(String uri) throws JasperException {
321
    public boolean isJspPage(String uri) {
453
322
454
        init();
455
        if (jspProperties == null) {
323
        if (jspProperties == null) {
456
            return false;
324
            return false;
457
        }
325
        }
Lines 467-477 Link Here
467
            uriExtension = uri.substring(index+1);
335
            uriExtension = uri.substring(index+1);
468
        }
336
        }
469
337
470
        Iterator<JspPropertyGroup> iter = jspProperties.iterator();
338
        for (JspPropertyGroup jpg : jspProperties) {
471
        while (iter.hasNext()) {
472
339
473
            JspPropertyGroup jpg = iter.next();
474
475
            String extension = jpg.getExtension();
340
            String extension = jpg.getExtension();
476
            String path = jpg.getPath();
341
            String path = jpg.getPath();
477
342
Lines 530-535 Link Here
530
        private final String buffer;
395
        private final String buffer;
531
        private final String errorOnUndeclaredNamespace;
396
        private final String errorOnUndeclaredNamespace;
532
397
398
        private JspProperty(String elIgnored, String deferedSyntaxAllowedAsLiteral) {
399
            this(null, elIgnored, null, null, null, null, deferedSyntaxAllowedAsLiteral, null, null, null, null);
400
        }
401
533
        public JspProperty(String isXml, String elIgnored,
402
        public JspProperty(String isXml, String elIgnored,
534
                String scriptingInvalid, String pageEncoding,
403
                String scriptingInvalid, String pageEncoding,
535
                Vector<String> includePrelude, Vector<String> includeCoda,
404
                Vector<String> includePrelude, Vector<String> includeCoda,
(-)java/org/apache/jasper/compiler/TldLocationsCache.java (-46 / +25 lines)
Lines 27-32 Link Here
27
import java.util.Set;
27
import java.util.Set;
28
28
29
import javax.servlet.ServletContext;
29
import javax.servlet.ServletContext;
30
import javax.servlet.descriptor.JspConfigDescriptor;
31
import javax.servlet.descriptor.TaglibDescriptor;
30
32
31
import org.apache.jasper.JasperException;
33
import org.apache.jasper.JasperException;
32
import org.apache.jasper.util.ExceptionUtils;
34
import org.apache.jasper.util.ExceptionUtils;
Lines 235-294 Link Here
235
    /*
237
    /*
236
     * Populates taglib map described in web.xml.
238
     * Populates taglib map described in web.xml.
237
     *
239
     *
238
     * This is not kept in sync with o.a.c.startup.TldConfig as the Jasper only
240
     * This is not kept in sync with o.a.c.startup.TldConfig as a) Jasper only
239
     * needs the URI to TLD mappings from scan web.xml whereas TldConfig needs
241
     * needs the URI to TLD mappings and b) Jasper can obtain the information
240
     * to scan the actual TLD files.
242
     * from the ServletContext.
241
     */
243
     */
242
    private void tldScanWebXml() throws Exception {
244
    private void tldScanWebXml() throws Exception {
243
245
244
        WebXml webXml = null;
246
        JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
245
        try {
247
        if (jspConfig == null) {
246
            webXml = new WebXml(ctxt);
248
            // no jsp-config for this application
247
            if (webXml.getInputSource() == null) {
249
            return;
248
                return;
250
        }
249
            }
250
251
251
            // Parse the web application deployment descriptor
252
        for (TaglibDescriptor taglib : jspConfig.getTaglibs()) {
252
            TreeNode webtld = null;
253
            webtld = new ParserUtils().parseXMLDocument(webXml.getSystemId(),
254
                    webXml.getInputSource());
255
253
256
            // Allow taglib to be an element of the root or jsp-config (JSP2.0)
254
            String tagUri = taglib.getTaglibURI();
257
            TreeNode jspConfig = webtld.findChild("jsp-config");
255
            String tagLoc = taglib.getTaglibLocation();
258
            if (jspConfig != null) {
259
                webtld = jspConfig;
260
            }
261
            Iterator<TreeNode> taglibs = webtld.findChildren("taglib");
262
            while (taglibs.hasNext()) {
263
256
264
                // Parse the next <taglib> element
257
            // Save this location if appropriate
265
                TreeNode taglib = taglibs.next();
258
            if (tagLoc == null) {
266
                String tagUri = null;
259
                continue;
267
                String tagLoc = null;
268
                TreeNode child = taglib.findChild("taglib-uri");
269
                if (child != null)
270
                    tagUri = child.getBody();
271
                child = taglib.findChild("taglib-location");
272
                if (child != null)
273
                    tagLoc = child.getBody();
274
275
                // Save this location if appropriate
276
                if (tagLoc == null)
277
                    continue;
278
                if (uriType(tagLoc) == NOROOT_REL_URI)
279
                    tagLoc = "/WEB-INF/" + tagLoc;
280
                TldLocation location;
281
                if (tagLoc.endsWith(JAR_EXT)) {
282
                    location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString());
283
                } else {
284
                    location = new TldLocation(tagLoc);
285
                }
286
                mappings.put(tagUri, location);
287
            }
260
            }
288
        } finally {
261
            if (uriType(tagLoc) == NOROOT_REL_URI) {
289
            if (webXml != null) {
262
                tagLoc = "/WEB-INF/" + tagLoc;
290
                webXml.close();
291
            }
263
            }
264
            TldLocation location;
265
            if (tagLoc.endsWith(JAR_EXT)) {
266
                location = new TldLocation("META-INF/taglib.tld", ctxt.getResource(tagLoc).toString());
267
            } else {
268
                location = new TldLocation(tagLoc);
269
            }
270
            mappings.put(tagUri, location);
292
        }
271
        }
293
    }
272
    }
294
273
(-)java/org/apache/jasper/compiler/WebXml.java (+3 lines)
Lines 39-45 Link Here
39
 * annotations with the main web.xml
39
 * annotations with the main web.xml
40
 *
40
 *
41
 * Clients *must* ensure that they call {@link #close()} to clean up resources.
41
 * Clients *must* ensure that they call {@link #close()} to clean up resources.
42
 *
43
 * @deprecated  Unused - will be removed in Tomcat 8.0.x
42
 */
44
 */
45
@Deprecated
43
public class WebXml {
46
public class WebXml {
44
    private static final String FILE_PROTOCOL = "file:";
47
    private static final String FILE_PROTOCOL = "file:";
45
    private static final String WEB_XML = "/WEB-INF/web.xml";
48
    private static final String WEB_XML = "/WEB-INF/web.xml";
(-)java/org/apache/jasper/servlet/JspCServletContext.java (-4 / +386 lines)
Lines 19-36 Link Here
19
19
20
20
21
import java.io.File;
21
import java.io.File;
22
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.InputStream;
23
import java.io.PrintWriter;
24
import java.io.PrintWriter;
24
import java.net.MalformedURLException;
25
import java.net.MalformedURLException;
26
import java.net.URISyntaxException;
25
import java.net.URL;
27
import java.net.URL;
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Collections;
26
import java.util.EnumSet;
31
import java.util.EnumSet;
27
import java.util.Enumeration;
32
import java.util.Enumeration;
28
import java.util.EventListener;
33
import java.util.EventListener;
29
import java.util.HashSet;
34
import java.util.HashSet;
30
import java.util.Hashtable;
35
import java.util.Hashtable;
36
import java.util.Iterator;
37
import java.util.List;
31
import java.util.Map;
38
import java.util.Map;
32
import java.util.Set;
39
import java.util.Set;
33
import java.util.Vector;
40
import java.util.Vector;
41
import java.util.jar.JarEntry;
42
import java.util.jar.JarFile;
34
43
35
import javax.servlet.Filter;
44
import javax.servlet.Filter;
36
import javax.servlet.FilterRegistration;
45
import javax.servlet.FilterRegistration;
Lines 43-50 Link Here
43
import javax.servlet.SessionCookieConfig;
52
import javax.servlet.SessionCookieConfig;
44
import javax.servlet.SessionTrackingMode;
53
import javax.servlet.SessionTrackingMode;
45
import javax.servlet.descriptor.JspConfigDescriptor;
54
import javax.servlet.descriptor.JspConfigDescriptor;
55
import javax.servlet.descriptor.JspPropertyGroupDescriptor;
56
import javax.servlet.descriptor.TaglibDescriptor;
46
57
58
import org.apache.jasper.JasperException;
47
import org.apache.jasper.util.ExceptionUtils;
59
import org.apache.jasper.util.ExceptionUtils;
60
import org.apache.jasper.xmlparser.ParserUtils;
61
import org.apache.jasper.xmlparser.TreeNode;
48
62
49
63
50
/**
64
/**
Lines 56-61 Link Here
56
70
57
public class JspCServletContext implements ServletContext {
71
public class JspCServletContext implements ServletContext {
58
72
73
    private static final String JSP_CONFIG = "jsp-config";
59
74
60
    // ----------------------------------------------------- Instance Variables
75
    // ----------------------------------------------------- Instance Variables
61
76
Lines 78-88 Link Here
78
    private final URL myResourceBaseURL;
93
    private final URL myResourceBaseURL;
79
94
80
95
96
81
    /**
97
    /**
82
     * Web application class loader.
98
     * Web application class loader.
83
     */
99
     */
84
    private ClassLoader loader;
100
    private ClassLoader loader;
85
101
102
    private final int effectiveMajorVersion;
103
    private final int effectiveMinorVersion;
104
    private final JspConfigDescriptor jspConfigDescriptor;
86
105
87
    // ----------------------------------------------------------- Constructors
106
    // ----------------------------------------------------------- Constructors
88
107
Lines 92-106 Link Here
92
     * @param aLogWriter PrintWriter which is used for <code>log()</code> calls
111
     * @param aLogWriter PrintWriter which is used for <code>log()</code> calls
93
     * @param aResourceBaseURL Resource base URL
112
     * @param aResourceBaseURL Resource base URL
94
     */
113
     */
95
    public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL) {
114
    public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL) throws IOException, JasperException {
96
115
97
        myAttributes = new Hashtable<>();
116
        myAttributes = new Hashtable<>();
98
        myLogWriter = aLogWriter;
117
        myLogWriter = aLogWriter;
99
        myResourceBaseURL = aResourceBaseURL;
118
        myResourceBaseURL = aResourceBaseURL;
100
119
120
        TreeNode mergedWebApp = loadAndMerge();
121
122
        // set effective version for this application
123
        Version version = Version.fromString(mergedWebApp.findAttribute("version"));
124
        effectiveMajorVersion = version.getMajor();
125
        effectiveMinorVersion = version.getMinor();
126
127
        jspConfigDescriptor = new JspCJspConfigDescriptor(mergedWebApp, version);
101
    }
128
    }
102
129
130
    private TreeNode loadAndMerge() throws IOException, JasperException {
131
        ParserUtils pu = new ParserUtils();
132
        TreeNode root = load(pu);
133
        mergeFragments(pu, root);
134
        return root;
135
    }
103
136
137
    private TreeNode load(ParserUtils pu) throws JasperException, IOException {
138
        URL webUrl = getResource("/WEB-INF/web.xml");
139
        if (webUrl == null) {
140
            // No web.xml in the application, use a empty one as default to support Servlet 3.0 applications.
141
            // This avoids inconsistency between compilation triggered by JspServlet which would use the
142
            // container's specification level and JspC which would default to Servlet 2.3 behaviour (including
143
            // unanticipated consequences such as disabling EL evaluation).
144
            webUrl = JspCServletContext.class.getResource("web.xml");
145
        }
146
        try (InputStream is = webUrl.openStream()) {
147
            return pu.parseXMLDocument(webUrl.toExternalForm(), is);
148
        }
149
    }
150
151
    private void mergeFragments(ParserUtils pu, TreeNode root) throws IOException, JasperException {
152
        Set<String> libs = getResourcePaths("/WEB-INF/lib/");
153
        if (libs == null) {
154
            return;
155
        }
156
157
        // HACK: just iterate all jars as fragment ordering does not matter for merging jsp-config entries
158
        for (String lib : libs) {
159
            try {
160
                URL url = getResource(lib);
161
                try (JarFile jarFile = new JarFile(new File(url.toURI()))) {
162
                    JarEntry entry = jarFile.getJarEntry("META-INF/web-fragment.xml");
163
                    if (entry == null) {
164
                        continue;
165
                    }
166
167
                    try (InputStream is = jarFile.getInputStream(entry)) {
168
                        TreeNode fragment = pu.parseXMLDocument(url.toExternalForm(), is);
169
                        merge(root, fragment);
170
                    }
171
                }
172
            } catch (URISyntaxException e) {
173
                throw new JasperException(e);
174
            }
175
        }
176
    }
177
178
    private void merge(TreeNode root, TreeNode fragment) {
179
        TreeNode childConfig = fragment.findChild(JSP_CONFIG);
180
        if (childConfig == null) {
181
            return;
182
    }
183
        TreeNode rootConfig = root.findChild(JSP_CONFIG);
184
        Iterator<TreeNode> children = childConfig.findChildren();
185
        while (children.hasNext()) {
186
            TreeNode node = children.next();
187
            if (rootConfig == null) {
188
                // automatically adds to parent
189
                rootConfig = new TreeNode(JSP_CONFIG, root);
190
            }
191
            rootConfig.addChild(node);
192
        }
193
    }
194
104
    // --------------------------------------------------------- Public Methods
195
    // --------------------------------------------------------- Public Methods
105
196
106
197
Lines 628-640 Link Here
628
719
629
    @Override
720
    @Override
630
    public int getEffectiveMajorVersion() {
721
    public int getEffectiveMajorVersion() {
631
        return 3;
722
        return effectiveMajorVersion;
632
    }
723
    }
633
724
634
725
635
    @Override
726
    @Override
636
    public int getEffectiveMinorVersion() {
727
    public int getEffectiveMinorVersion() {
637
        return 0;
728
        return effectiveMinorVersion;
638
    }
729
    }
639
730
640
731
Lines 646-652 Link Here
646
737
647
    @Override
738
    @Override
648
    public JspConfigDescriptor getJspConfigDescriptor() {
739
    public JspConfigDescriptor getJspConfigDescriptor() {
649
        return null;
740
        return jspConfigDescriptor;
650
    }
741
    }
651
742
652
743
Lines 660-663 Link Here
660
    public String getVirtualServerName() {
751
    public String getVirtualServerName() {
661
        return null;
752
        return null;
662
    }
753
    }
754
755
    private static enum Version {
756
        VERSION_2_3(2, 3),
757
        VERSION_2_4(2, 4),
758
        VERSION_2_5(2, 5),
759
        VERSION_3_0(3, 0),
760
        VERSION_3_1(3, 1);
761
        private final int major;
762
        private final int minor;
763
        private Version(int major, int minor) {
764
            this.major = major;
765
            this.minor = minor;
766
        }
767
768
        private int getMajor() {
769
            return major;
770
        }
771
772
        private int getMinor() {
773
            return minor;
774
        }
775
776
        private static Version fromString(String version) {
777
            if (version == null) {
778
                return VERSION_2_3;
779
            }
780
            switch (version) {
781
                case "2.4":
782
                    return VERSION_2_4;
783
                case "2.5":
784
                    return VERSION_2_5;
785
                case "3.0":
786
                    return VERSION_3_0;
787
                case "3.1":
788
                    return VERSION_3_1;
789
                default:
790
                    return VERSION_2_3;
791
            }
792
        }
793
    }
794
795
    private static class JspCJspConfigDescriptor implements JspConfigDescriptor {
796
        private final Collection<TaglibDescriptor> taglibs;
797
        private final Collection<JspPropertyGroupDescriptor> jspPropertyGroups;
798
799
        private JspCJspConfigDescriptor(TreeNode webapp, Version version) {
800
            // In Servlet 2.3, <taglib> elements were under the root and there were no property groups
801
            if (version == Version.VERSION_2_3) {
802
                taglibs = taglibDescriptors(webapp);
803
                jspPropertyGroups = Collections.emptyList();
804
                return;
805
            }
806
807
            // In later versions, JSP configuration is under the <jsp-config> element
808
            TreeNode jspConfig = webapp.findChild(JSP_CONFIG);
809
            if (jspConfig == null) {
810
                taglibs = Collections.emptyList();
811
                jspPropertyGroups = Collections.emptyList();
812
                return;
813
            }
814
            taglibs = taglibDescriptors(jspConfig);
815
            jspPropertyGroups = propertyGroups(jspConfig);
816
        }
817
818
        private Collection<TaglibDescriptor> taglibDescriptors(TreeNode parent) {
819
            Collection<TaglibDescriptor> descriptors = new ArrayList<>();
820
            Iterator<TreeNode> taglibs = parent.findChildren("taglib");
821
            while (taglibs.hasNext()) {
822
                TreeNode taglib = taglibs.next();
823
                final String tagUri = optionalChild(taglib, "taglib-uri");
824
                final String tagLoc = optionalChild(taglib, "taglib-location");
825
                descriptors.add(new JspCTaglibDescriptor(tagUri, tagLoc));
826
            }
827
            return Collections.unmodifiableCollection(descriptors);
828
        }
829
830
        private Collection<JspPropertyGroupDescriptor> propertyGroups(TreeNode parent) {
831
            List<JspPropertyGroupDescriptor> descriptors = new ArrayList<>();
832
            Iterator<TreeNode> groups = parent.findChildren("jsp-property-group");
833
            while (groups.hasNext()) {
834
                TreeNode group = groups.next();
835
                String buffer = null;
836
                String defaultContentType = null;
837
                String deferedSyntaxAllowedAsLiteral = null;
838
                String elIgnored = null;
839
                String errorOnUndeclaredNamespace = null;
840
                List<String> includeCodas = new ArrayList<>();
841
                List<String> includePreludes = new ArrayList<>();
842
                String isXml = null;
843
                String pageEncoding = null;
844
                String scriptingInvalid = null;
845
                String trimDirectiveWhitespaces = null;
846
                List<String> urlPatterns = new ArrayList<>();
847
                Iterator<TreeNode> child = group.findChildren();
848
                while (child.hasNext()) {
849
                    TreeNode node = child.next();
850
                    String body = node.getBody();
851
                    switch (node.getName()) {
852
                        case "buffer":
853
                            buffer = body;
854
                            break;
855
                        case "default-content-type":
856
                            defaultContentType = body;
857
                            break;
858
                        case "deferred-syntax-allowed-as-literal":
859
                            deferedSyntaxAllowedAsLiteral = body;
860
                            break;
861
                        case "el-ignored":
862
                            elIgnored = body;
863
                            break;
864
                        case "error-on-undeclared-namespace":
865
                            errorOnUndeclaredNamespace = body;
866
                            break;
867
                        case "include-coda":
868
                            includeCodas.add(body);
869
                            break;
870
                        case "include-prelude":
871
                            includePreludes.add(body);
872
                            break;
873
                        case "is-xml":
874
                            isXml = body;
875
                            break;
876
                        case "page-encoding":
877
                            pageEncoding = body;
878
                            break;
879
                        case "scripting-invalid":
880
                            scriptingInvalid = body;
881
                            break;
882
                        case "trim-directive-whitespaces":
883
                            buffer = body;
884
                            break;
885
                        case "url-pattern":
886
                            urlPatterns.add(body);
887
                            break;
888
                    }
889
                }
890
                descriptors.add(new JspCPropertyGroupDescriptor(
891
                        buffer,
892
                        defaultContentType,
893
                        deferedSyntaxAllowedAsLiteral,
894
                        elIgnored,
895
                        errorOnUndeclaredNamespace,
896
                        Collections.unmodifiableCollection(includeCodas),
897
                        Collections.unmodifiableCollection(includePreludes),
898
                        isXml,
899
                        pageEncoding,
900
                        scriptingInvalid,
901
                        trimDirectiveWhitespaces,
902
                        Collections.unmodifiableCollection(urlPatterns)));
903
            }
904
            return Collections.unmodifiableList(descriptors);
905
        }
906
907
        private static String optionalChild(TreeNode parent, String name) {
908
            TreeNode child = parent.findChild(name);
909
            return child == null ? null : child.getBody();
910
        }
911
912
        @Override
913
        public Collection<TaglibDescriptor> getTaglibs() {
914
            return taglibs;
915
        }
916
917
        @Override
918
        public Collection<JspPropertyGroupDescriptor> getJspPropertyGroups() {
919
            return jspPropertyGroups;
920
        }
921
922
        // TODO: share with org.apache.catalina.core.ApplicationTaglibDescriptor
923
        private static class JspCTaglibDescriptor implements TaglibDescriptor {
924
            private final String tagUri;
925
            private final String tagLoc;
926
927
            public JspCTaglibDescriptor(String tagUri, String tagLoc) {
928
                this.tagUri = tagUri;
929
                this.tagLoc = tagLoc;
930
            }
931
932
            @Override
933
            public String getTaglibURI() {
934
                return tagUri;
935
            }
936
937
            @Override
938
            public String getTaglibLocation() {
939
                return tagLoc;
940
            }
941
        }
942
943
        // TODO: share with org.apache.catalina.core.ApplicationJspPropertyGroupDescriptor
944
        private static class JspCPropertyGroupDescriptor implements JspPropertyGroupDescriptor {
945
            private final String buffer;
946
            private final String defaultContentType;
947
            private final String deferedSyntaxAllowedAsLiteral;
948
            private final String elIgnored;
949
            private final String errorOnUndeclaredNamespace;
950
            private final Collection<String> includeCodas;
951
            private final Collection<String> includePreludes;
952
            private final String isXml;
953
            private final String pageEncoding;
954
            private final String scriptingInvalid;
955
            private final String trimDirectiveWhitespaces;
956
            private final Collection<String> urlPatterns;
957
958
            private JspCPropertyGroupDescriptor(String buffer,
959
                                                String defaultContentType,
960
                                                String deferedSyntaxAllowedAsLiteral,
961
                                                String elIgnored,
962
                                                String errorOnUndeclaredNamespace,
963
                                                Collection<String> includeCodas,
964
                                                Collection<String> includePreludes,
965
                                                String isXml,
966
                                                String pageEncoding,
967
                                                String scriptingInvalid,
968
                                                String trimDirectiveWhitespaces,
969
                                                Collection<String> urlPatterns) {
970
                this.buffer = buffer;
971
                this.defaultContentType = defaultContentType;
972
                this.deferedSyntaxAllowedAsLiteral = deferedSyntaxAllowedAsLiteral;
973
                this.elIgnored = elIgnored;
974
                this.errorOnUndeclaredNamespace = errorOnUndeclaredNamespace;
975
                this.includeCodas = includeCodas;
976
                this.includePreludes = includePreludes;
977
                this.isXml = isXml;
978
                this.pageEncoding = pageEncoding;
979
                this.scriptingInvalid = scriptingInvalid;
980
                this.trimDirectiveWhitespaces = trimDirectiveWhitespaces;
981
                this.urlPatterns = urlPatterns;
982
            }
983
984
            @Override
985
            public Collection<String> getUrlPatterns() {
986
                return urlPatterns;
987
            }
988
989
            @Override
990
            public String getElIgnored() {
991
                return elIgnored;
992
            }
993
994
            @Override
995
            public String getPageEncoding() {
996
                return pageEncoding;
997
            }
998
999
            @Override
1000
            public String getScriptingInvalid() {
1001
                return scriptingInvalid;
1002
            }
1003
1004
            @Override
1005
            public String getIsXml() {
1006
                return isXml;
1007
            }
1008
1009
            @Override
1010
            public Collection<String> getIncludePreludes() {
1011
                return includePreludes;
1012
            }
1013
1014
            @Override
1015
            public Collection<String> getIncludeCodas() {
1016
                return includeCodas;
1017
            }
1018
1019
            @Override
1020
            public String getDeferredSyntaxAllowedAsLiteral() {
1021
                return deferedSyntaxAllowedAsLiteral;
1022
            }
1023
1024
            @Override
1025
            public String getTrimDirectiveWhitespaces() {
1026
                return trimDirectiveWhitespaces;
1027
            }
1028
1029
            @Override
1030
            public String getDefaultContentType() {
1031
                return defaultContentType;
1032
            }
1033
1034
            @Override
1035
            public String getBuffer() {
1036
                return buffer;
1037
            }
1038
1039
            @Override
1040
            public String getErrorOnUndeclaredNamespace() {
1041
                return errorOnUndeclaredNamespace;
1042
            }
1043
        }
1044
    }
663
}
1045
}
(-)java/org/apache/jasper/servlet/web.xml (+26 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!--
3
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
4
  ~ contributor license agreements.  See the NOTICE file distributed with
5
  ~ this work for additional information regarding copyright ownership.
6
  ~ The ASF licenses this file to You under the Apache License, Version 2.0
7
  ~ (the "License"); you may not use this file except in compliance with
8
  ~ 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, software
13
  ~ distributed under the License is distributed on an "AS IS" BASIS,
14
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
  ~ See the License for the specific language governing permissions and
16
  ~ limitations under the License.
17
  -->
18
<!--
19
  Default web.xml used by Jasper if one is not provided in the application.
20
-->
21
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
22
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
24
         version="3.1">
25
</web-app>
26
native
(-)test/org/apache/jasper/servlet/TestJspCServletContext.java (+98 lines)
Line 0 Link Here
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
package org.apache.jasper.servlet;
18
19
import java.io.File;
20
import java.util.Collection;
21
import java.util.Iterator;
22
23
import javax.servlet.descriptor.JspConfigDescriptor;
24
import javax.servlet.descriptor.JspPropertyGroupDescriptor;
25
26
import org.junit.Assert;
27
import org.junit.Test;
28
29
public class TestJspCServletContext {
30
31
    @Test
32
    public void testWebapp() throws Exception {
33
        File appDir = new File("test/webapp");
34
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
35
        Assert.assertEquals(3, context.getEffectiveMajorVersion());
36
        Assert.assertEquals(1, context.getEffectiveMinorVersion());
37
        JspConfigDescriptor jspConfigDescriptor = context.getJspConfigDescriptor();
38
        Assert.assertTrue(jspConfigDescriptor.getTaglibs().isEmpty());
39
        Collection<JspPropertyGroupDescriptor> propertyGroups = jspConfigDescriptor.getJspPropertyGroups();
40
        Assert.assertEquals(1, propertyGroups.size());
41
        JspPropertyGroupDescriptor groupDescriptor = propertyGroups.iterator().next();
42
        Assert.assertEquals("text/plain", groupDescriptor.getDefaultContentType());
43
        Collection<String> urlPatterns = groupDescriptor.getUrlPatterns();
44
        Assert.assertEquals(2, urlPatterns.size());
45
        Iterator<String> iterator = urlPatterns.iterator();
46
        Assert.assertEquals("/bug49nnn/bug49726a.jsp", iterator.next());
47
        Assert.assertEquals("/bug49nnn/bug49726b.jsp", iterator.next());
48
    }
49
50
    @Test
51
    public void testWebapp_2_3() throws Exception {
52
        File appDir = new File("test/webapp-2.3");
53
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
54
        Assert.assertEquals(2, context.getEffectiveMajorVersion());
55
        Assert.assertEquals(3, context.getEffectiveMinorVersion());
56
    }
57
58
    @Test
59
    public void testWebapp_2_4() throws Exception {
60
        File appDir = new File("test/webapp-2.4");
61
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
62
        Assert.assertEquals(2, context.getEffectiveMajorVersion());
63
        Assert.assertEquals(4, context.getEffectiveMinorVersion());
64
    }
65
66
    @Test
67
    public void testWebapp_2_5() throws Exception {
68
        File appDir = new File("test/webapp-2.5");
69
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
70
        Assert.assertEquals(2, context.getEffectiveMajorVersion());
71
        Assert.assertEquals(5, context.getEffectiveMinorVersion());
72
    }
73
74
    @Test
75
    public void testWebapp_3_0() throws Exception {
76
        File appDir = new File("test/webapp-3.0");
77
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
78
        Assert.assertEquals(3, context.getEffectiveMajorVersion());
79
        Assert.assertEquals(0, context.getEffectiveMinorVersion());
80
    }
81
82
    @Test
83
    public void testWebapp_3_1() throws Exception {
84
        File appDir = new File("test/webapp-3.1");
85
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
86
        Assert.assertEquals(3, context.getEffectiveMajorVersion());
87
        Assert.assertEquals(1, context.getEffectiveMinorVersion());
88
    }
89
90
    @Test
91
    public void testWebresources() throws Exception {
92
        File appDir = new File("test/webresources/dir1");
93
        JspCServletContext context = new JspCServletContext(null, appDir.toURI().toURL());
94
        Assert.assertEquals(3, context.getEffectiveMajorVersion());
95
        Assert.assertEquals(1, context.getEffectiveMinorVersion());
96
    }
97
}
98
native

Return to bug 53737