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

(-)java/org/apache/jasper/runtime/JspApplicationContextImpl.java (-20 / +2 lines)
Lines 19-45 Link Here
19
import java.security.AccessController;
19
import java.security.AccessController;
20
import java.security.PrivilegedAction;
20
import java.security.PrivilegedAction;
21
import java.util.ArrayList;
21
import java.util.ArrayList;
22
import java.util.Iterator;
23
import java.util.List;
22
import java.util.List;
24
23
25
import javax.el.ArrayELResolver;
26
import javax.el.BeanELResolver;
27
import javax.el.CompositeELResolver;
24
import javax.el.CompositeELResolver;
28
import javax.el.ELContextEvent;
25
import javax.el.ELContextEvent;
29
import javax.el.ELContextListener;
26
import javax.el.ELContextListener;
30
import javax.el.ELResolver;
27
import javax.el.ELResolver;
31
import javax.el.ExpressionFactory;
28
import javax.el.ExpressionFactory;
32
import javax.el.ListELResolver;
33
import javax.el.MapELResolver;
34
import javax.el.ResourceBundleELResolver;
35
import javax.servlet.ServletContext;
29
import javax.servlet.ServletContext;
36
import javax.servlet.jsp.JspApplicationContext;
30
import javax.servlet.jsp.JspApplicationContext;
37
import javax.servlet.jsp.JspContext;
31
import javax.servlet.jsp.JspContext;
38
import javax.servlet.jsp.el.ImplicitObjectELResolver;
39
import javax.servlet.jsp.el.ScopedAttributeELResolver;
40
32
41
import org.apache.jasper.Constants;
33
import org.apache.jasper.Constants;
42
import org.apache.jasper.el.ELContextImpl;
34
import org.apache.jasper.el.ELContextImpl;
35
import org.apache.jasper.el.JasperELResolver;
43
36
44
/**
37
/**
45
 * Implementation of JspApplicationContext
38
 * Implementation of JspApplicationContext
Lines 119-136 Link Here
119
    private ELResolver createELResolver() {
112
    private ELResolver createELResolver() {
120
        this.instantiated = true;
113
        this.instantiated = true;
121
        if (this.resolver == null) {
114
        if (this.resolver == null) {
122
            CompositeELResolver r = new CompositeELResolver();
115
            CompositeELResolver r = new JasperELResolver(this.resolvers);
123
            r.add(new ImplicitObjectELResolver());
124
            for (Iterator<ELResolver> itr = this.resolvers.iterator();
125
                    itr.hasNext();) {
126
                r.add(itr.next());
127
            }
128
            r.add(new MapELResolver());
129
            r.add(new ResourceBundleELResolver());
130
            r.add(new ListELResolver());
131
            r.add(new ArrayELResolver());    
132
            r.add(new BeanELResolver());
133
            r.add(new ScopedAttributeELResolver());
134
            this.resolver = r;
116
            this.resolver = r;
135
        }
117
        }
136
        return this.resolver;
118
        return this.resolver;
(-)java/org/apache/jasper/el/JasperELResolver.java (+143 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
18
package org.apache.jasper.el;
19
20
import java.util.List;
21
22
import javax.el.ArrayELResolver;
23
import javax.el.BeanELResolver;
24
import javax.el.CompositeELResolver;
25
import javax.el.ELContext;
26
import javax.el.ELException;
27
import javax.el.ELResolver;
28
import javax.el.ListELResolver;
29
import javax.el.MapELResolver;
30
import javax.el.PropertyNotFoundException;
31
import javax.el.ResourceBundleELResolver;
32
import javax.servlet.jsp.el.ImplicitObjectELResolver;
33
import javax.servlet.jsp.el.ScopedAttributeELResolver;
34
35
import org.apache.el.lang.ELSupport;
36
37
/*
38
 * Jasper-specific CompositeELResolver that optimizes certain functions to avoid unnecessary resolver calls.
39
 */
40
public class JasperELResolver extends CompositeELResolver {
41
    
42
    private int size;
43
    private ELResolver[] resolvers;
44
    private int appResolversSize;
45
46
    public JasperELResolver(List<ELResolver> appResolvers) { 
47
        appResolversSize = appResolvers.size();
48
        resolvers = new ELResolver[7 /* 7 standard EL resolvers */ + appResolversSize];
49
        size = resolvers.length;
50
        
51
        int index = 0;
52
        resolvers[index++] = new ImplicitObjectELResolver();
53
        for (ELResolver appResolver : appResolvers) {
54
            resolvers[index++] = appResolver;
55
        }
56
        resolvers[index++] = new MapELResolver();
57
        resolvers[index++] = new ResourceBundleELResolver();
58
        resolvers[index++] = new ListELResolver();
59
        resolvers[index++] = new ArrayELResolver();    
60
        resolvers[index++] = new BeanELResolver();
61
        resolvers[index++] = new ScopedAttributeELResolver();
62
    }
63
64
    @Override
65
    public synchronized void add(ELResolver elResolver) {
66
        super.add(elResolver);
67
        
68
        ELResolver[] nr = new ELResolver[size + 1];
69
        System.arraycopy(resolvers, 0, nr, 0, size);
70
        nr[size] = elResolver;
71
        
72
        resolvers = nr;
73
        size ++;
74
    }
75
76
    @Override
77
    public Object getValue(ELContext context, Object base, Object property)
78
        throws NullPointerException, PropertyNotFoundException, ELException {        
79
        context.setPropertyResolved(false);
80
                
81
        int start;
82
        Object result = null;
83
        
84
        if (base == null) {
85
            // call implicit and app resolvers
86
            int index = 1 /* implicit */ + appResolversSize;
87
            for (int i = 0; i < index; i++) {
88
                result = resolvers[i].getValue(context, base, property);
89
                if (context.isPropertyResolved()) {
90
                    return result;
91
                }
92
            }
93
            // skip collection-based resolvers (map, resource, list, array, and bean)
94
            start = index + 5;
95
        } else {
96
            // skip implicit resolver only
97
            start = 1;
98
        }
99
        
100
        for (int i = start; i < size; i++) {
101
            result = resolvers[i].getValue(context, base, property);
102
            if (context.isPropertyResolved()) {
103
                return result;
104
            }
105
        }
106
107
        return null;
108
    }
109
    
110
    @Override
111
    public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
112
        String targetMethod = ELSupport.coerceToString(method);
113
        if (targetMethod.length() == 0) {
114
            throw new ELException(new NoSuchMethodException());
115
        }
116
117
        context.setPropertyResolved(false);
118
        
119
        Object result = null;
120
        
121
        // skip implicit and call app resolvers
122
        int index = 1 /* implicit */ + appResolversSize;
123
        for (int i = 1; i < index; i++) {
124
            result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
125
            if (context.isPropertyResolved()) {
126
                return result;
127
            }
128
        }
129
        
130
        // skip map, resource, list, and array resolvers
131
        index += 4; 
132
        // call bean and the rest of resolvers
133
        for (int i = index; i < size; i++) {
134
            result = resolvers[i].invoke(context, base, targetMethod, paramTypes, params);
135
            if (context.isPropertyResolved()) {
136
                return result;
137
            }
138
        }
139
        
140
        return null;
141
    }
142
    
143
}
0
  + text/plain
144
  + text/plain
1
  + Date Revision
145
  + Date Revision
2
  + native
146
  + native

Return to bug 53896