Author: markt
Date: Thu Aug  6 18:17:35 2015
New Revision: 1694548

URL: http://svn.apache.org/r1694548
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58178
Fix the second part of this bug - El and imports for tag files.

Added:
    tomcat/trunk/test/webapp/WEB-INF/tags/bug58178b.tag
    tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp   (with props)
Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
    tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java
    tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java
    tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag
    tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp

Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Generator.java?rev=1694548&r1=1694547&r2=1694548&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/Generator.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/Generator.java Thu Aug  6 
18:17:35 2015
@@ -3631,13 +3631,14 @@ class Generator {
         out.printin("public final class ");
         out.println(className);
         out.printil("    extends javax.servlet.jsp.tagext.SimpleTagSupport");
-        out.printin("    implements 
org.apache.jasper.runtime.JspSourceDependent");
+        out.printin("    implements 
org.apache.jasper.runtime.JspSourceDependent,");
+        out.println();
+        out.printin("                 
org.apache.jasper.runtime.JspSourceImports");
         if (tagInfo.hasDynamicAttributes()) {
             out.println(",");
             out.printin("               
javax.servlet.jsp.tagext.DynamicAttributes");
         }
         out.println(" {");
-        out.println();
         out.pushIndent();
 
         /*
@@ -3906,9 +3907,9 @@ class Generator {
             out.println(");");
         }
         if (aliasSeen) {
-            out.printil("this.jspContext = new 
org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, 
_jspx_at_end, aliasMap);");
+            out.printil("this.jspContext = new 
org.apache.jasper.runtime.JspContextWrapper(this, ctx, _jspx_nested, 
_jspx_at_begin, _jspx_at_end, aliasMap);");
         } else {
-            out.printil("this.jspContext = new 
org.apache.jasper.runtime.JspContextWrapper(ctx, _jspx_nested, _jspx_at_begin, 
_jspx_at_end, null);");
+            out.printil("this.jspContext = new 
org.apache.jasper.runtime.JspContextWrapper(this, ctx, _jspx_nested, 
_jspx_at_begin, _jspx_at_end, null);");
         }
         out.popIndent();
         out.printil("}");

Modified: tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java?rev=1694548&r1=1694547&r2=1694548&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/runtime/JspContextWrapper.java Thu Aug  
6 18:17:35 2015
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import javax.el.ELContext;
 import javax.el.ELResolver;
@@ -47,6 +48,7 @@ import javax.servlet.jsp.el.ELException;
 import javax.servlet.jsp.el.ExpressionEvaluator;
 import javax.servlet.jsp.el.VariableResolver;
 import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.tagext.JspTag;
 import javax.servlet.jsp.tagext.VariableInfo;
 
 import org.apache.jasper.compiler.Localizer;
@@ -66,6 +68,8 @@ import org.apache.jasper.compiler.Locali
 @SuppressWarnings("deprecation") // Have to support old JSP EL API
 public class JspContextWrapper extends PageContext implements VariableResolver 
{
 
+    private final JspTag jspTag;
+
     // Invoking JSP context
     private final PageContext invokingJspCtxt;
 
@@ -90,9 +94,10 @@ public class JspContextWrapper extends P
 
     private final PageContext rootJspCtxt;
 
-    public JspContextWrapper(JspContext jspContext,
+    public JspContextWrapper(JspTag jspTag, JspContext jspContext,
             ArrayList<String> nestedVars, ArrayList<String> atBeginVars,
             ArrayList<String> atEndVars, Map<String,String> aliases) {
+        this.jspTag = jspTag;
         this.invokingJspCtxt = (PageContext) jspContext;
         if (jspContext instanceof JspContextWrapper) {
             rootJspCtxt = ((JspContextWrapper)jspContext).rootJspCtxt;
@@ -502,7 +507,7 @@ public class JspContextWrapper extends P
     @Override
     public ELContext getELContext() {
         if (elContext == null) {
-            elContext = new ELContextWrapper(rootJspCtxt.getELContext(), this);
+            elContext = new ELContextWrapper(rootJspCtxt.getELContext(), 
jspTag, this);
         }
         return elContext;
     }
@@ -511,10 +516,13 @@ public class JspContextWrapper extends P
     static class ELContextWrapper extends ELContext {
 
         private final ELContext wrapped;
+        private final JspTag jspTag;
         private final PageContext pageContext;
+        private ImportHandler importHandler;
 
-        private ELContextWrapper(ELContext wrapped, PageContext pageContext) {
+        private ELContextWrapper(ELContext wrapped, JspTag jspTag, PageContext 
pageContext) {
             this.wrapped = wrapped;
+            this.jspTag = jspTag;
             this.pageContext = pageContext;
         }
 
@@ -552,7 +560,25 @@ public class JspContextWrapper extends P
 
         @Override
         public ImportHandler getImportHandler() {
-            return wrapped.getImportHandler();
+            if (importHandler == null) {
+                importHandler = new ImportHandler();
+                if (jspTag instanceof JspSourceImports) {
+                    Set<String> packageImports = ((JspSourceImports) 
jspTag).getPackageImports();
+                    if (packageImports != null) {
+                        for (String packageImport : packageImports) {
+                            importHandler.importPackage(packageImport);
+                        }
+                    }
+                    Set<String> classImports = ((JspSourceImports) 
jspTag).getClassImports();
+                    if (classImports != null) {
+                        for (String classImport : classImports) {
+                            importHandler.importClass(classImport);
+                        }
+                    }
+                }
+
+            }
+            return importHandler;
         }
 
         @Override

Modified: tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java?rev=1694548&r1=1694547&r2=1694548&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java 
(original)
+++ tomcat/trunk/test/org/apache/jasper/runtime/TestJspContextWrapper.java Thu 
Aug  6 18:17:35 2015
@@ -1,12 +1,33 @@
+/*
+ * 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;
 
+import java.math.BigDecimal;
+import java.util.Collections;
+
+import javax.servlet.DispatcherType;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.catalina.startup.TomcatBaseTest;
-import org.apache.tomcat.util.buf.ByteChunk;
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
 public class TestJspContextWrapper extends TomcatBaseTest {
 
     @Test
@@ -24,7 +45,25 @@ public class TestJspContextWrapper exten
         Assert.assertTrue(result, result.contains("PASS"));
     }
 
-    public void testELTagFileImports() {
+    @Test
+    public void testELTagFileImports() throws Exception {
+        getTomcatInstanceTestWebapp(false, true);
+
+        ByteChunk out = new ByteChunk();
+
+        int rc = getUrl("http://localhost:"; + getPort() + 
"/test/bug5nnnn/bug58178b.jsp", out, null);
+
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+
+        String result = out.toString();
 
+        Assert.assertTrue(result, result.contains("00-" + 
DispatcherType.ASYNC));
+        // No obvious status fields for javax.servlet.http
+        // Could hack something with HttpUtils...
+        // No obvious status fields for javax.servlet.jsp
+        // Wild card (package) import
+        Assert.assertTrue(result, result.contains("01-" + 
BigDecimal.ROUND_UP));
+        // Class import
+        Assert.assertTrue(result, result.contains("02-" + 
Collections.EMPTY_LIST.size()));
     }
 }

Modified: tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag?rev=1694548&r1=1694547&r2=1694548&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag (original)
+++ tomcat/trunk/test/webapp/WEB-INF/tags/bug58178.tag Thu Aug  6 18:17:35 2015
@@ -1,9 +1,25 @@
+<%--
+ 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.
+--%>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"; %>
 
 <c:catch var="error">
   <jsp:doBody/>
 </c:catch>
-   
+
 <c:if test="${error != null}">
   <p>PASS<br/>
   Error detected<br/>

Added: tomcat/trunk/test/webapp/WEB-INF/tags/bug58178b.tag
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/tags/bug58178b.tag?rev=1694548&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/WEB-INF/tags/bug58178b.tag (added)
+++ tomcat/trunk/test/webapp/WEB-INF/tags/bug58178b.tag Thu Aug  6 18:17:35 2015
@@ -0,0 +1,20 @@
+<%--
+ 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.
+--%>
+<%@tag import="java.math.*, java.util.Collections" %>
+<p>00-${DispatcherType.ASYNC}</p>
+<p>01-${BigDecimal.ROUND_UP}</p>
+<p>02-${Collections.EMPTY_LIST.stream().count()}</p>
\ No newline at end of file

Modified: tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp?rev=1694548&r1=1694547&r2=1694548&view=diff
==============================================================================
--- tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp (original)
+++ tomcat/trunk/test/webapp/bug5nnnn/bug58178.jsp Thu Aug  6 18:17:35 2015
@@ -1,3 +1,19 @@
+<%--
+  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.
+--%>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %>
 <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"; %>

Added: tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp?rev=1694548&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp (added)
+++ tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp Thu Aug  6 18:17:35 2015
@@ -0,0 +1,21 @@
+<%--
+  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.
+--%>
+<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
+<html>
+<body>
+<tags:bug58178b />
+</html>
\ No newline at end of file

Propchange: tomcat/trunk/test/webapp/bug5nnnn/bug58178b.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to