/* * 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.jasper.runtime;
/** * Implementation of a JSP Context Wrapper. * * The JSP Context Wrapper is a JspContext created and maintained by a tag * handler implementation. It wraps the Invoking JSP Context, that is, the * JspContext instance passed to the tag handler by the invoking page via * setJspContext(). * * @author Kin-man Chung * @author Jan Luehe * @author Jacob Hookom
*/
@SuppressWarnings("deprecation") // Have to support old JSP EL API publicclass JspContextWrapper extends PageContext implements VariableResolver {
@Override public Object findAttribute(String name) {
if (name == null) { thrownew NullPointerException(Localizer
.getMessage("jsp.error.attribute.null_name"));
}
Object o = pageAttributes.get(name); if (o == null) {
o = rootJspCtxt.getAttribute(name, REQUEST_SCOPE); if (o == null) { if (getSession() != null) { try {
o = rootJspCtxt.getAttribute(name, SESSION_SCOPE);
} catch (IllegalStateException ise) { // Session has been invalidated. // Ignore and fall through to application scope.
}
} if (o == null) {
o = rootJspCtxt.getAttribute(name, APPLICATION_SCOPE);
}
}
}
@Override
@Deprecated public VariableResolver getVariableResolver() { returnthis;
}
@Override public BodyContent pushBody() { return invokingJspCtxt.pushBody();
}
@Override public JspWriter pushBody(Writer writer) { return invokingJspCtxt.pushBody(writer);
}
@Override public JspWriter popBody() { return invokingJspCtxt.popBody();
}
@Override
@Deprecated public ExpressionEvaluator getExpressionEvaluator() { return invokingJspCtxt.getExpressionEvaluator();
}
@Override publicvoid handlePageException(Exception ex) throws IOException,
ServletException { // Should never be called since handleException() called with a // Throwable in the generated servlet.
handlePageException((Throwable) ex);
}
/** * Synchronize variables at begin of tag file
*/ publicvoid syncBeginTagFile() {
saveNestedVariables();
}
/** * Synchronize variables before fragment invocation
*/ publicvoid syncBeforeInvoke() {
copyTagToPageScope(VariableInfo.NESTED);
copyTagToPageScope(VariableInfo.AT_BEGIN);
}
/** * Synchronize variables at end of tag file
*/ publicvoid syncEndTagFile() {
copyTagToPageScope(VariableInfo.AT_BEGIN);
copyTagToPageScope(VariableInfo.AT_END);
restoreNestedVariables();
}
/** * Copies the variables of the given scope from the virtual page scope of * this JSP context wrapper to the page scope of the invoking JSP context. * * @param scope * variable scope (one of NESTED, AT_BEGIN, or AT_END)
*/ privatevoid copyTagToPageScope(int scope) {
Iterator<String> iter = null;
switch (scope) { case VariableInfo.NESTED: if (nestedVars != null) {
iter = nestedVars.iterator();
} break; case VariableInfo.AT_BEGIN: if (atBeginVars != null) {
iter = atBeginVars.iterator();
} break; case VariableInfo.AT_END: if (atEndVars != null) {
iter = atEndVars.iterator();
} break;
}
/** * Saves the values of any NESTED variables that are present in the invoking * JSP context, so they can later be restored.
*/ privatevoid saveNestedVariables() { if (nestedVars != null) { for (String varName : nestedVars) {
varName = findAlias(varName);
Object obj = invokingJspCtxt.getAttribute(varName); if (obj != null) {
originalNestedVars.put(varName, obj);
}
}
}
}
/** * Restores the values of any NESTED variables in the invoking JSP context.
*/ privatevoid restoreNestedVariables() { if (nestedVars != null) { for (String varName : nestedVars) {
varName = findAlias(varName);
Object obj = originalNestedVars.get(varName); if (obj != null) {
invokingJspCtxt.setAttribute(varName, obj);
} else {
invokingJspCtxt.removeAttribute(varName, PAGE_SCOPE);
}
}
}
}
/** * Checks to see if the given variable name is used as an alias, and if so, * returns the variable name for which it is used as an alias. * * @param varName * The variable name to check * @return The variable name for which varName is used as an alias, or * varName if it is not being used as an alias
*/ private String findAlias(String varName) {
if (aliases == null) { return varName;
}
String alias = aliases.get(varName); if (alias == null) { return varName;
} return alias;
}
@Override public ELContext getELContext() { if (elContext == null) {
elContext = new ELContextWrapper(rootJspCtxt.getELContext(), jspTag, this);
JspFactory factory = JspFactory.getDefaultFactory();
JspApplicationContext jspAppCtxt = factory.getJspApplicationContext(servletContext); if (jspAppCtxt instanceof JspApplicationContextImpl) {
((JspApplicationContextImpl) jspAppCtxt).fireListeners(elContext);
}
} return elContext;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.