ASF Bugzilla – Attachment 25750 Details for
Bug 27717
<x:forEach> very slow in JSTL 1.1
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Supporting variable resolver
JSTLVariableResolver.java (text/plain), 6.36 KB, created by
Jeremy Boynes
on 2010-07-11 01:19:20 UTC
(
hide
)
Description:
Supporting variable resolver
Filename:
MIME Type:
Creator:
Jeremy Boynes
Created:
2010-07-11 01:19:20 UTC
Size:
6.36 KB
patch
obsolete
>/* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You under the Apache License, Version 2.0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > * See the License for the specific language governing permissions and > * limitations under the License. > */ >package org.apache.taglibs.standard.tag.common.xml; > >import javax.servlet.http.Cookie; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.jsp.PageContext; >import javax.xml.XMLConstants; >import javax.xml.namespace.NamespaceContext; >import javax.xml.namespace.QName; >import javax.xml.xpath.XPathVariableResolver; >import java.util.HashMap; >import java.util.Iterator; >import java.util.Map; > >/** > */ >public class JSTLVariableResolver implements XPathVariableResolver, NamespaceContext { > > private static enum Scope { > JSP, > PARAM, > HEADER, > COOKIE, > INITPARAM, > PAGE, > REQUEST, > SESSION, > APPLICATION > } > > // Namespace URIs for JSTL implicit variables > private static final String PARAM_NS_URL = "http://java.sun.com/jstl/xpath/param"; > private static final String HEADER_NS_URL = "http://java.sun.com/jstl/xpath/header"; > private static final String COOKIE_NS_URL = "http://java.sun.com/jstl/xpath/cookie"; > private static final String INITPARAM_NS_URL = "http://java.sun.com/jstl/xpath/initParam"; > private static final String PAGE_NS_URL = "http://java.sun.com/jstl/xpath/page"; > private static final String REQUEST_NS_URL = "http://java.sun.com/jstl/xpath/request"; > private static final String SESSION_NS_URL = "http://java.sun.com/jstl/xpath/session"; > private static final String APP_NS_URL = "http://java.sun.com/jstl/xpath/app"; > > // Prefixes for JSTL implicit variables > private static final String PARAM_PREFIX = "param"; > private static final String HEADER_PREFIX = "header"; > private static final String COOKIE_PREFIX = "cookie"; > private static final String INITPARAM_PREFIX = "initParam"; > private static final String PAGE_PREFIX = "pageScope"; > private static final String REQUEST_PREFIX = "requestScope"; > private static final String SESSION_PREFIX = "sessionScope"; > private static final String APP_PREFIX = "applicationScope"; > > // map prefixes to namespaces > private static final Map<String, String> NAMESPACES; > > static { > NAMESPACES = new HashMap<String, String>(8); > NAMESPACES.put(XMLConstants.DEFAULT_NS_PREFIX, XMLConstants.NULL_NS_URI); > NAMESPACES.put(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI); > NAMESPACES.put(XMLConstants.XMLNS_ATTRIBUTE, XMLConstants.XMLNS_ATTRIBUTE_NS_URI); > NAMESPACES.put(PARAM_PREFIX, PARAM_NS_URL); > NAMESPACES.put(HEADER_PREFIX, HEADER_NS_URL); > NAMESPACES.put(COOKIE_PREFIX, COOKIE_NS_URL); > NAMESPACES.put(INITPARAM_PREFIX, INITPARAM_NS_URL); > NAMESPACES.put(PAGE_PREFIX, PAGE_NS_URL); > NAMESPACES.put(REQUEST_PREFIX, REQUEST_NS_URL); > NAMESPACES.put(SESSION_PREFIX, SESSION_NS_URL); > NAMESPACES.put(APP_PREFIX, APP_NS_URL); > } > > // map namespaces to scopes > private static final Map<String, Scope> SCOPES; > > static { > SCOPES = new HashMap<String, Scope>(8); > SCOPES.put(XMLConstants.NULL_NS_URI, Scope.JSP); > SCOPES.put(PARAM_NS_URL, Scope.PARAM); > SCOPES.put(HEADER_NS_URL, Scope.HEADER); > SCOPES.put(COOKIE_NS_URL, Scope.COOKIE); > SCOPES.put(INITPARAM_NS_URL, Scope.INITPARAM); > SCOPES.put(PAGE_NS_URL, Scope.PAGE); > SCOPES.put(REQUEST_NS_URL, Scope.REQUEST); > SCOPES.put(SESSION_NS_URL, Scope.SESSION); > SCOPES.put(APP_NS_URL, Scope.APPLICATION); > } > > > private PageContext pageContext; > > public void setPageContext(PageContext pageContext) { > this.pageContext = pageContext; > } > > public Object resolveVariable(QName variableName) { > String name = variableName.getLocalPart(); > Scope scope = SCOPES.get(variableName.getNamespaceURI()); > if (scope == null) { > return null; > } > switch (scope) { > case JSP: > return pageContext.findAttribute(name); > case PARAM: > return pageContext.getRequest().getParameter(name); > case HEADER: > return ((HttpServletRequest) pageContext.getRequest()).getHeader(name); > case COOKIE: > Cookie[] cookies = ((HttpServletRequest) pageContext.getRequest()).getCookies(); > if (cookies != null) { > for (Cookie cookie : cookies) { > if (cookie.getName().equals(name)) { > return cookie.getValue(); > } > } > } > return null; > case INITPARAM: > return pageContext.getServletContext().getInitParameter(name); > case PAGE: > return pageContext.getAttribute(name, PageContext.PAGE_SCOPE); > case REQUEST: > return pageContext.getAttribute(name, PageContext.REQUEST_SCOPE); > case SESSION: > return pageContext.getAttribute(name, PageContext.SESSION_SCOPE); > case APPLICATION: > return pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE); > default: > throw new AssertionError(); > } > } > > public String getNamespaceURI(String prefix) { > if (prefix == null) { > throw new IllegalArgumentException("prefix is null"); > } > String uri = NAMESPACES.get(prefix); > if (uri != null) { > return uri; > } > return XMLConstants.NULL_NS_URI; > } > > public String getPrefix(String namespaceURI) { > throw new UnsupportedOperationException(); > } > > public Iterator getPrefixes(String namespaceURI) { > throw new UnsupportedOperationException(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 27717
:
12261
|
12262
|
12263
|
12264
|
25749
|
25750
|
26445
|
26448
|
26452