Author: markt Date: Thu Oct 25 11:57:13 2012 New Revision: 1402113 URL: http://svn.apache.org/viewvc?rev=1402113&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54012 Enable the tag plug-in for c:set to work in tag files. Based on a patch by Sheldon Shao.
Modified: tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java tomcat/trunk/java/org/apache/jasper/compiler/PageInfo.java tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java tomcat/trunk/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java tomcat/trunk/java/org/apache/jasper/tagplugins/jstl/core/Set.java Modified: tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java?rev=1402113&r1=1402112&r2=1402113&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java Thu Oct 25 11:57:13 2012 @@ -108,7 +108,7 @@ public abstract class Compiler { // Setup page info area pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), - errDispatcher), ctxt.getJspFile()); + errDispatcher), ctxt.getJspFile(), ctxt.isTagFile()); JspConfig jspConfig = options.getJspConfig(); JspConfig.JspProperty jspProperty = jspConfig.findJspProperty(ctxt Modified: tomcat/trunk/java/org/apache/jasper/compiler/PageInfo.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/PageInfo.java?rev=1402113&r1=1402112&r2=1402113&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/PageInfo.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/PageInfo.java Thu Oct 25 11:57:13 2012 @@ -99,8 +99,10 @@ class PageInfo { // JSP 2.2 private boolean errorOnUndeclaredNamepsace = false; - PageInfo(BeanRepository beanRepository, String jspFile) { + private boolean isTagFile = false; + PageInfo(BeanRepository beanRepository, String jspFile, boolean isTagFile) { + this.isTagFile = isTagFile; this.jspFile = jspFile; this.beanRepository = beanRepository; this.varInfoNames = new HashSet<>(); @@ -119,6 +121,10 @@ class PageInfo { imports.addAll(Constants.STANDARD_IMPORTS); } + public boolean isTagFile() { + return isTagFile; + } + /** * Check if the plugin ID has been previously declared. Make a not * that this Id is now declared. Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java?rev=1402113&r1=1402112&r2=1402113&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/TagPluginManager.java Thu Oct 25 11:57:13 2012 @@ -243,6 +243,11 @@ public class TagPluginManager { curNodes = node.getAtETag(); } + @Override + public boolean isTagFile() { + return pageInfo.isTagFile(); + } + private Node.JspAttribute getNodeAttribute(String attribute) { Node.JspAttribute[] attrs = node.getJspAttributes(); for (int i=0; attrs != null && i < attrs.length; i++) { Modified: tomcat/trunk/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java?rev=1402113&r1=1402112&r2=1402113&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java Thu Oct 25 11:57:13 2012 @@ -120,5 +120,10 @@ public interface TagPluginContext { * Get the value of an attribute in the current tagplugin context. */ Object getPluginAttribute(String attr); + + /** + * Is the tag being used inside a tag file? + */ + boolean isTagFile(); } Modified: tomcat/trunk/java/org/apache/jasper/tagplugins/jstl/core/Set.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/tagplugins/jstl/core/Set.java?rev=1402113&r1=1402112&r2=1402113&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/tagplugins/jstl/core/Set.java (original) +++ tomcat/trunk/java/org/apache/jasper/tagplugins/jstl/core/Set.java Thu Oct 25 11:57:13 2012 @@ -70,14 +70,20 @@ public class Set implements TagPlugin { //if the attribute var has been specified then assign the result to the var; if(hasVar){ + String jspCtxt = null; + if (ctxt.isTagFile()) { + jspCtxt = "this.getJspContext()"; + } else { + jspCtxt = "_jspx_page_context"; + } String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource("if(null != " + resultName + "){"); - ctxt.generateJavaSource(" pageContext.setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");"); + ctxt.generateJavaSource(" " + jspCtxt + ".setAttribute(\"" + strVar + "\"," + resultName + "," + iScope + ");"); ctxt.generateJavaSource("} else {"); if(hasScope){ - ctxt.generateJavaSource(" pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");"); + ctxt.generateJavaSource(" " + jspCtxt + ".removeAttribute(\"" + strVar + "\"," + iScope + ");"); }else{ - ctxt.generateJavaSource(" pageContext.removeAttribute(\"" + strVar + "\");"); + ctxt.generateJavaSource(" " + jspCtxt + ".removeAttribute(\"" + strVar + "\");"); } ctxt.generateJavaSource("}"); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org