Java Code Examples for org.apache.jasper.compiler.tagplugin.TagPluginContext#isAttributeSpecified()
The following examples show how to use
org.apache.jasper.compiler.tagplugin.TagPluginContext#isAttributeSpecified() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: If.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { String condV = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("boolean " + condV + "="); ctxt.generateAttribute("test"); ctxt.generateJavaSource(";"); if (ctxt.isAttributeSpecified("var")) { String scope = "PageContext.PAGE_SCOPE"; if (ctxt.isAttributeSpecified("scope")) { String scopeStr = ctxt.getConstantAttribute("scope"); if ("request".equals(scopeStr)) { scope = "PageContext.REQUEST_SCOPE"; } else if ("session".equals(scopeStr)) { scope = "PageContext.SESSION_SCOPE"; } else if ("application".equals(scopeStr)) { scope = "PageContext.APPLICATION_SCOPE"; } } ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", new Boolean(" + condV + ")," + scope + ");"); } ctxt.generateJavaSource("if (" + condV + "){"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 2
Source File: Remove.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { //scope flag boolean hasScope = ctxt.isAttributeSpecified("scope"); //the value of the "var" String strVar = ctxt.getConstantAttribute("var"); //remove attribute from certain scope. //default scope is "page". if(hasScope){ int iScope = Util.getScope(ctxt.getConstantAttribute("scope")); ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");"); }else{ ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\");"); } }
Example 3
Source File: Remove.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { //scope flag boolean hasScope = ctxt.isAttributeSpecified("scope"); //the value of the "var" String strVar = ctxt.getConstantAttribute("var"); //remove attribute from certain scope. //default scope is "page". if(hasScope){ int iScope = Util.getScope(ctxt.getConstantAttribute("scope")); ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");"); }else{ ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\");"); } }
Example 4
Source File: If.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { String condV = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("boolean " + condV + "="); ctxt.generateAttribute("test"); ctxt.generateJavaSource(";"); if (ctxt.isAttributeSpecified("var")) { String scope = "PageContext.PAGE_SCOPE"; if (ctxt.isAttributeSpecified("scope")) { String scopeStr = ctxt.getConstantAttribute("scope"); if ("request".equals(scopeStr)) { scope = "PageContext.REQUEST_SCOPE"; } else if ("session".equals(scopeStr)) { scope = "PageContext.SESSION_SCOPE"; } else if ("application".equals(scopeStr)) { scope = "PageContext.APPLICATION_SCOPE"; } } ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", new Boolean(" + condV + ")," + scope + ");"); } ctxt.generateJavaSource("if (" + condV + "){"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 5
Source File: If.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { String condV = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("boolean " + condV + "="); ctxt.generateAttribute("test"); ctxt.generateJavaSource(";"); if (ctxt.isAttributeSpecified("var")) { String scope = "PageContext.PAGE_SCOPE"; if (ctxt.isAttributeSpecified("scope")) { String scopeStr = ctxt.getConstantAttribute("scope"); if ("request".equals(scopeStr)) { scope = "PageContext.REQUEST_SCOPE"; } else if ("session".equals(scopeStr)) { scope = "PageContext.SESSION_SCOPE"; } else if ("application".equals(scopeStr)) { scope = "PageContext.APPLICATION_SCOPE"; } } ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", new Boolean(" + condV + ")," + scope + ");"); } ctxt.generateJavaSource("if (" + condV + "){"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 6
Source File: Remove.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void doTag(TagPluginContext ctxt) { //scope flag boolean hasScope = ctxt.isAttributeSpecified("scope"); //the value of the "var" String strVar = ctxt.getConstantAttribute("var"); //remove attribute from certain scope. //default scope is "page". if(hasScope){ int iScope = Util.getScope(ctxt.getConstantAttribute("scope")); ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\"," + iScope + ");"); }else{ ctxt.generateJavaSource("pageContext.removeAttribute(\"" + strVar + "\");"); } }
Example 7
Source File: Redirect.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //flag for the existence of the "context" boolean hasContext = ctxt.isAttributeSpecified("context"); //names of the temp variables String urlName = ctxt.getTemporaryVariableName(); String contextName = ctxt.getTemporaryVariableName(); String baseUrlName = ctxt.getTemporaryVariableName(); String resultName = ctxt.getTemporaryVariableName(); String responseName = ctxt.getTemporaryVariableName(); //get context ctxt.generateJavaSource("String " + contextName + " = null;"); if(hasContext){ ctxt.generateJavaSource(contextName + " = "); ctxt.generateAttribute("context"); ctxt.generateJavaSource(";"); } //get the url ctxt.generateJavaSource("String " + urlName + " = "); ctxt.generateAttribute("url"); ctxt.generateJavaSource(";"); //get the raw url according to "url" and "context" ctxt.generateJavaSource("String " + baseUrlName + " = " + "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + urlName + ", " + contextName + ", pageContext);"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"url_without_param\", " + baseUrlName + ");"); //add params ctxt.generateBody(); ctxt.generateJavaSource("String " + resultName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");"); ctxt.generateJavaSource("pageContext.removeAttribute" + "(\"url_without_param\");"); //get the response object ctxt.generateJavaSource("HttpServletResponse " + responseName + " = " + "((HttpServletResponse) pageContext.getResponse());"); //if the url is relative, encode it ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){"); ctxt.generateJavaSource(" " + resultName + " = " + responseName + ".encodeRedirectURL(" + resultName + ");"); ctxt.generateJavaSource("}"); //do redirect ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" " + responseName + ".sendRedirect(" + resultName + ");"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); }
Example 8
Source File: ForTokens.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { boolean hasVar, hasVarStatus, hasBegin, hasEnd, hasStep; //init the flags hasVar = ctxt.isAttributeSpecified("var"); hasVarStatus = ctxt.isAttributeSpecified("varStatus"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); if(hasVarStatus){ ctxt.dontUseTagPlugin(); return; } //define all the temp variables' names String itemsName = ctxt.getTemporaryVariableName(); String delimsName = ctxt.getTemporaryVariableName(); String stName = ctxt.getTemporaryVariableName(); String beginName = ctxt.getTemporaryVariableName(); String endName = ctxt.getTemporaryVariableName(); String stepName = ctxt.getTemporaryVariableName(); String index = ctxt.getTemporaryVariableName(); String temp = ctxt.getTemporaryVariableName(); String tokensCountName = ctxt.getTemporaryVariableName(); //get the value of the "items" attribute ctxt.generateJavaSource("String " + itemsName + " = (String)"); ctxt.generateAttribute("items"); ctxt.generateJavaSource(";"); //get the value of the "delim" attribute ctxt.generateJavaSource("String " + delimsName + " = (String)"); ctxt.generateAttribute("delims"); ctxt.generateJavaSource(";"); //new a StringTokenizer Object according to the "items" and the "delim" ctxt.generateJavaSource("java.util.StringTokenizer " + stName + " = " + "new java.util.StringTokenizer(" + itemsName + ", " + delimsName + ");"); //if "begin" specified, move the token to the "begin" place //and record the begin index. default begin place is 0. ctxt.generateJavaSource("int " + tokensCountName + " = " + stName + ".countTokens();"); if(hasBegin){ ctxt.generateJavaSource("int " + beginName + " = " ); ctxt.generateAttribute("begin"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("for(int " + index + " = 0; " + index + " < " + beginName + " && " + stName + ".hasMoreTokens(); " + index + "++, " + stName + ".nextToken()){}"); }else{ ctxt.generateJavaSource("int " + beginName + " = 0;"); } //when "end" is specified, if the "end" is more than the last index, //record the end place as the last index, otherwise, record it as "end"; //default end place is the last index if(hasEnd){ ctxt.generateJavaSource("int " + endName + " = 0;" ); ctxt.generateJavaSource("if((" + tokensCountName + " - 1) < "); ctxt.generateAttribute("end"); ctxt.generateJavaSource("){"); ctxt.generateJavaSource(" " + endName + " = " + tokensCountName + " - 1;"); ctxt.generateJavaSource("}else{"); ctxt.generateJavaSource(" " + endName + " = "); ctxt.generateAttribute("end"); ctxt.generateJavaSource(";}"); }else{ ctxt.generateJavaSource("int " + endName + " = " + tokensCountName + " - 1;"); } //get the step value from "step" if specified. //default step value is 1. if(hasStep){ ctxt.generateJavaSource("int " + stepName + " = " ); ctxt.generateAttribute("step"); ctxt.generateJavaSource(";"); }else{ ctxt.generateJavaSource("int " + stepName + " = 1;"); } //the loop ctxt.generateJavaSource("for(int " + index + " = " + beginName + "; " + index + " <= " + endName + "; " + index + "++){"); ctxt.generateJavaSource(" String " + temp + " = " + stName + ".nextToken();"); ctxt.generateJavaSource(" if(((" + index + " - " + beginName + ") % " + stepName + ") == 0){"); //if var specified, put the current token into the attribute "var" defines. if(hasVar){ String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource(" pageContext.setAttribute(\"" + strVar + "\", " + temp + ");"); } ctxt.generateBody(); ctxt.generateJavaSource(" }"); ctxt.generateJavaSource("}"); }
Example 9
Source File: Out.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //these two data member are to indicate //whether the corresponding attribute is specified boolean hasDefault=false, hasEscapeXml=false; hasDefault = ctxt.isAttributeSpecified("default"); hasEscapeXml = ctxt.isAttributeSpecified("escapeXml"); //strValName, strEscapeXmlName & strDefName are two variables' name //standing for value, escapeXml and default attribute String strObjectName = ctxt.getTemporaryVariableName(); String strValName = ctxt.getTemporaryVariableName(); String strDefName = ctxt.getTemporaryVariableName(); String strEscapeXmlName = ctxt.getTemporaryVariableName(); String strSkipBodyName = ctxt.getTemporaryVariableName(); //according to the tag file, the value attribute is mandatory. ctxt.generateImport("java.io.Reader"); ctxt.generateJavaSource("Object " + strObjectName + "="); ctxt.generateAttribute("value"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("String " + strValName + "=null;"); ctxt.generateJavaSource("if(!(" + strObjectName + " instanceof Reader) && "+ strObjectName + " != null){"); ctxt.generateJavaSource( strValName + " = " + strObjectName + ".toString();"); ctxt.generateJavaSource("}"); //initiate the strDefName with null. //if the default has been specified, then assign the value to it; ctxt.generateJavaSource("String " + strDefName + " = null;"); if(hasDefault){ ctxt.generateJavaSource("if("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(" != null){"); ctxt.generateJavaSource(strDefName + " = ("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(").toString();"); ctxt.generateJavaSource("}"); } //initiate the strEscapeXmlName with true; //if the escapeXml is specified, assign the value to it; ctxt.generateJavaSource("boolean " + strEscapeXmlName + " = true;"); if(hasEscapeXml){ ctxt.generateJavaSource(strEscapeXmlName + " = "); ctxt.generateAttribute("escapeXml"); ctxt.generateJavaSource(";"); } //main part. ctxt.generateJavaSource( "boolean " + strSkipBodyName + " = " + "org.apache.jasper.tagplugins.jstl.core.Out.output(out, " + strObjectName + ", " + strValName + ", " + strDefName + ", " + strEscapeXmlName + ");"); ctxt.generateJavaSource("if(!" + strSkipBodyName + ") {"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 10
Source File: ForEach.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { String index = null; boolean hasVarStatus = ctxt.isAttributeSpecified("varStatus"); if (hasVarStatus) { ctxt.dontUseTagPlugin(); return; } hasVar = ctxt.isAttributeSpecified("var"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); boolean hasItems = ctxt.isAttributeSpecified("items"); if (hasItems) { doCollection(ctxt); return; } // We must have a begin and end attributes index = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("for (int " + index + " = "); ctxt.generateAttribute("begin"); ctxt.generateJavaSource("; " + index + " <= "); ctxt.generateAttribute("end"); if (hasStep) { ctxt.generateJavaSource("; " + index + "+="); ctxt.generateAttribute("step"); ctxt.generateJavaSource(") {"); } else { ctxt.generateJavaSource("; " + index + "++) {"); } // If var is specified and the body contains an EL, then sycn // the var attribute if (hasVar /* && ctxt.hasEL() */) { ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", String.valueOf(" + index + "));"); } ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 11
Source File: ForTokens.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { boolean hasVar, hasVarStatus, hasBegin, hasEnd, hasStep; //init the flags hasVar = ctxt.isAttributeSpecified("var"); hasVarStatus = ctxt.isAttributeSpecified("varStatus"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); if(hasVarStatus){ ctxt.dontUseTagPlugin(); return; } //define all the temp variables' names String itemsName = ctxt.getTemporaryVariableName(); String delimsName = ctxt.getTemporaryVariableName(); String stName = ctxt.getTemporaryVariableName(); String beginName = ctxt.getTemporaryVariableName(); String endName = ctxt.getTemporaryVariableName(); String stepName = ctxt.getTemporaryVariableName(); String index = ctxt.getTemporaryVariableName(); String temp = ctxt.getTemporaryVariableName(); String tokensCountName = ctxt.getTemporaryVariableName(); //get the value of the "items" attribute ctxt.generateJavaSource("String " + itemsName + " = (String)"); ctxt.generateAttribute("items"); ctxt.generateJavaSource(";"); //get the value of the "delim" attribute ctxt.generateJavaSource("String " + delimsName + " = (String)"); ctxt.generateAttribute("delims"); ctxt.generateJavaSource(";"); //new a StringTokenizer Object according to the "items" and the "delim" ctxt.generateJavaSource("java.util.StringTokenizer " + stName + " = " + "new java.util.StringTokenizer(" + itemsName + ", " + delimsName + ");"); //if "begin" specified, move the token to the "begin" place //and record the begin index. default begin place is 0. ctxt.generateJavaSource("int " + tokensCountName + " = " + stName + ".countTokens();"); if(hasBegin){ ctxt.generateJavaSource("int " + beginName + " = " ); ctxt.generateAttribute("begin"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("for(int " + index + " = 0; " + index + " < " + beginName + " && " + stName + ".hasMoreTokens(); " + index + "++, " + stName + ".nextToken()){}"); }else{ ctxt.generateJavaSource("int " + beginName + " = 0;"); } //when "end" is specified, if the "end" is more than the last index, //record the end place as the last index, otherwise, record it as "end"; //default end place is the last index if(hasEnd){ ctxt.generateJavaSource("int " + endName + " = 0;" ); ctxt.generateJavaSource("if((" + tokensCountName + " - 1) < "); ctxt.generateAttribute("end"); ctxt.generateJavaSource("){"); ctxt.generateJavaSource(" " + endName + " = " + tokensCountName + " - 1;"); ctxt.generateJavaSource("}else{"); ctxt.generateJavaSource(" " + endName + " = "); ctxt.generateAttribute("end"); ctxt.generateJavaSource(";}"); }else{ ctxt.generateJavaSource("int " + endName + " = " + tokensCountName + " - 1;"); } //get the step value from "step" if specified. //default step value is 1. if(hasStep){ ctxt.generateJavaSource("int " + stepName + " = " ); ctxt.generateAttribute("step"); ctxt.generateJavaSource(";"); }else{ ctxt.generateJavaSource("int " + stepName + " = 1;"); } //the loop ctxt.generateJavaSource("for(int " + index + " = " + beginName + "; " + index + " <= " + endName + "; " + index + "++){"); ctxt.generateJavaSource(" String " + temp + " = " + stName + ".nextToken();"); ctxt.generateJavaSource(" if(((" + index + " - " + beginName + ") % " + stepName + ") == 0){"); //if var specified, put the current token into the attribute "var" defines. if(hasVar){ String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource(" pageContext.setAttribute(\"" + strVar + "\", " + temp + ");"); } ctxt.generateBody(); ctxt.generateJavaSource(" }"); ctxt.generateJavaSource("}"); }
Example 12
Source File: Out.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //these two data member are to indicate //whether the corresponding attribute is specified boolean hasDefault=false, hasEscapeXml=false; hasDefault = ctxt.isAttributeSpecified("default"); hasEscapeXml = ctxt.isAttributeSpecified("escapeXml"); //strValName, strEscapeXmlName & strDefName are two variables' name //standing for value, escapeXml and default attribute String strObjectName = ctxt.getTemporaryVariableName(); String strValName = ctxt.getTemporaryVariableName(); String strDefName = ctxt.getTemporaryVariableName(); String strEscapeXmlName = ctxt.getTemporaryVariableName(); String strSkipBodyName = ctxt.getTemporaryVariableName(); //according to the tag file, the value attribute is mandatory. ctxt.generateImport("java.io.Reader"); ctxt.generateJavaSource("Object " + strObjectName + "="); ctxt.generateAttribute("value"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("String " + strValName + "=null;"); ctxt.generateJavaSource("if(!(" + strObjectName + " instanceof Reader) && "+ strObjectName + " != null){"); ctxt.generateJavaSource( strValName + " = " + strObjectName + ".toString();"); ctxt.generateJavaSource("}"); //initiate the strDefName with null. //if the default has been specified, then assign the value to it; ctxt.generateJavaSource("String " + strDefName + " = null;"); if(hasDefault){ ctxt.generateJavaSource("if("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(" != null){"); ctxt.generateJavaSource(strDefName + " = ("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(").toString();"); ctxt.generateJavaSource("}"); } //initiate the strEscapeXmlName with true; //if the escapeXml is specified, assign the value to it; ctxt.generateJavaSource("boolean " + strEscapeXmlName + " = true;"); if(hasEscapeXml){ ctxt.generateJavaSource(strEscapeXmlName + " = "); ctxt.generateAttribute("escapeXml"); ctxt.generateJavaSource(";"); } //main part. ctxt.generateJavaSource( "boolean " + strSkipBodyName + " = " + "org.apache.jasper.tagplugins.jstl.core.Out.output(out, " + strObjectName + ", " + strValName + ", " + strDefName + ", " + strEscapeXmlName + ");"); ctxt.generateJavaSource("if(!" + strSkipBodyName + ") {"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 13
Source File: Redirect.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //flag for the existence of the "context" boolean hasContext = ctxt.isAttributeSpecified("context"); //names of the temp variables String urlName = ctxt.getTemporaryVariableName(); String contextName = ctxt.getTemporaryVariableName(); String baseUrlName = ctxt.getTemporaryVariableName(); String resultName = ctxt.getTemporaryVariableName(); String responseName = ctxt.getTemporaryVariableName(); //get context ctxt.generateJavaSource("String " + contextName + " = null;"); if(hasContext){ ctxt.generateJavaSource(contextName + " = "); ctxt.generateAttribute("context"); ctxt.generateJavaSource(";"); } //get the url ctxt.generateJavaSource("String " + urlName + " = "); ctxt.generateAttribute("url"); ctxt.generateJavaSource(";"); //get the raw url according to "url" and "context" ctxt.generateJavaSource("String " + baseUrlName + " = " + "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + urlName + ", " + contextName + ", pageContext);"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"url_without_param\", " + baseUrlName + ");"); //add params ctxt.generateBody(); ctxt.generateJavaSource("String " + resultName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");"); ctxt.generateJavaSource("pageContext.removeAttribute" + "(\"url_without_param\");"); //get the response object ctxt.generateJavaSource("HttpServletResponse " + responseName + " = " + "((HttpServletResponse) pageContext.getResponse());"); //if the url is relative, encode it ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){"); ctxt.generateJavaSource(" " + resultName + " = " + responseName + ".encodeRedirectURL(" + resultName + ");"); ctxt.generateJavaSource("}"); //do redirect ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" " + responseName + ".sendRedirect(" + resultName + ");"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); }
Example 14
Source File: Url.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //flags boolean hasVar, hasContext, hasScope; //init flags hasVar = ctxt.isAttributeSpecified("var"); hasContext = ctxt.isAttributeSpecified("context"); hasScope = ctxt.isAttributeSpecified("scope"); //define name of the temp variables String valueName = ctxt.getTemporaryVariableName(); String contextName = ctxt.getTemporaryVariableName(); String baseUrlName = ctxt.getTemporaryVariableName(); String resultName = ctxt.getTemporaryVariableName(); String responseName = ctxt.getTemporaryVariableName(); //get the scope String strScope = "page"; if(hasScope){ strScope = ctxt.getConstantAttribute("scope"); } int iScope = Util.getScope(strScope); //get the value ctxt.generateJavaSource("String " + valueName + " = "); ctxt.generateAttribute("value"); ctxt.generateJavaSource(";"); //get the context ctxt.generateJavaSource("String " + contextName + " = null;"); if(hasContext){ ctxt.generateJavaSource(contextName + " = "); ctxt.generateAttribute("context"); ctxt.generateJavaSource(";"); } //get the raw url ctxt.generateJavaSource("String " + baseUrlName + " = " + "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + valueName + ", " + contextName + ", pageContext);"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"url_without_param\", " + baseUrlName + ");"); //add params ctxt.generateBody(); ctxt.generateJavaSource("String " + resultName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");"); ctxt.generateJavaSource("pageContext.removeAttribute(\"url_without_param\");"); //if the url is relative, encode it ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){"); ctxt.generateJavaSource(" HttpServletResponse " + responseName + " = " + "((HttpServletResponse) pageContext.getResponse());"); ctxt.generateJavaSource(" " + resultName + " = " + responseName + ".encodeURL(" + resultName + ");"); ctxt.generateJavaSource("}"); //if "var" is specified, the url string store in the attribute var defines if(hasVar){ String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"" + strVar + "\", " + resultName + ", " + iScope + ");"); //if var is not specified, just print out the url string }else{ ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" pageContext.getOut().print(" + resultName + ");"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); } }
Example 15
Source File: ForEach.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { String index = null; boolean hasVarStatus = ctxt.isAttributeSpecified("varStatus"); if (hasVarStatus) { ctxt.dontUseTagPlugin(); return; } hasVar = ctxt.isAttributeSpecified("var"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); boolean hasItems = ctxt.isAttributeSpecified("items"); if (hasItems) { doCollection(ctxt); return; } // We must have a begin and end attributes index = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("for (int " + index + " = "); ctxt.generateAttribute("begin"); ctxt.generateJavaSource("; " + index + " <= "); ctxt.generateAttribute("end"); if (hasStep) { ctxt.generateJavaSource("; " + index + "+="); ctxt.generateAttribute("step"); ctxt.generateJavaSource(") {"); } else { ctxt.generateJavaSource("; " + index + "++) {"); } // If var is specified and the body contains an EL, then sycn // the var attribute if (hasVar /* && ctxt.hasEL() */) { ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", String.valueOf(" + index + "));"); } ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 16
Source File: ForTokens.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { boolean hasVar, hasVarStatus, hasBegin, hasEnd, hasStep; //init the flags hasVar = ctxt.isAttributeSpecified("var"); hasVarStatus = ctxt.isAttributeSpecified("varStatus"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); if(hasVarStatus){ ctxt.dontUseTagPlugin(); return; } //define all the temp variables' names String itemsName = ctxt.getTemporaryVariableName(); String delimsName = ctxt.getTemporaryVariableName(); String stName = ctxt.getTemporaryVariableName(); String beginName = ctxt.getTemporaryVariableName(); String endName = ctxt.getTemporaryVariableName(); String stepName = ctxt.getTemporaryVariableName(); String index = ctxt.getTemporaryVariableName(); String temp = ctxt.getTemporaryVariableName(); String tokensCountName = ctxt.getTemporaryVariableName(); //get the value of the "items" attribute ctxt.generateJavaSource("String " + itemsName + " = (String)"); ctxt.generateAttribute("items"); ctxt.generateJavaSource(";"); //get the value of the "delim" attribute ctxt.generateJavaSource("String " + delimsName + " = (String)"); ctxt.generateAttribute("delims"); ctxt.generateJavaSource(";"); //new a StringTokenizer Object according to the "items" and the "delim" ctxt.generateJavaSource("java.util.StringTokenizer " + stName + " = " + "new java.util.StringTokenizer(" + itemsName + ", " + delimsName + ");"); //if "begin" specified, move the token to the "begin" place //and record the begin index. default begin place is 0. ctxt.generateJavaSource("int " + tokensCountName + " = " + stName + ".countTokens();"); if(hasBegin){ ctxt.generateJavaSource("int " + beginName + " = " ); ctxt.generateAttribute("begin"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("for(int " + index + " = 0; " + index + " < " + beginName + " && " + stName + ".hasMoreTokens(); " + index + "++, " + stName + ".nextToken()){}"); }else{ ctxt.generateJavaSource("int " + beginName + " = 0;"); } //when "end" is specified, if the "end" is more than the last index, //record the end place as the last index, otherwise, record it as "end"; //default end place is the last index if(hasEnd){ ctxt.generateJavaSource("int " + endName + " = 0;" ); ctxt.generateJavaSource("if((" + tokensCountName + " - 1) < "); ctxt.generateAttribute("end"); ctxt.generateJavaSource("){"); ctxt.generateJavaSource(" " + endName + " = " + tokensCountName + " - 1;"); ctxt.generateJavaSource("}else{"); ctxt.generateJavaSource(" " + endName + " = "); ctxt.generateAttribute("end"); ctxt.generateJavaSource(";}"); }else{ ctxt.generateJavaSource("int " + endName + " = " + tokensCountName + " - 1;"); } //get the step value from "step" if specified. //default step value is 1. if(hasStep){ ctxt.generateJavaSource("int " + stepName + " = " ); ctxt.generateAttribute("step"); ctxt.generateJavaSource(";"); }else{ ctxt.generateJavaSource("int " + stepName + " = 1;"); } //the loop ctxt.generateJavaSource("for(int " + index + " = " + beginName + "; " + index + " <= " + endName + "; " + index + "++){"); ctxt.generateJavaSource(" String " + temp + " = " + stName + ".nextToken();"); ctxt.generateJavaSource(" if(((" + index + " - " + beginName + ") % " + stepName + ") == 0){"); //if var specified, put the current token into the attribute "var" defines. if(hasVar){ String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource(" pageContext.setAttribute(\"" + strVar + "\", " + temp + ");"); } ctxt.generateBody(); ctxt.generateJavaSource(" }"); ctxt.generateJavaSource("}"); }
Example 17
Source File: Out.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //these two data member are to indicate //whether the corresponding attribute is specified boolean hasDefault=false, hasEscapeXml=false; hasDefault = ctxt.isAttributeSpecified("default"); hasEscapeXml = ctxt.isAttributeSpecified("escapeXml"); //strValName, strEscapeXmlName & strDefName are two variables' name //standing for value, escapeXml and default attribute String strObjectName = ctxt.getTemporaryVariableName(); String strValName = ctxt.getTemporaryVariableName(); String strDefName = ctxt.getTemporaryVariableName(); String strEscapeXmlName = ctxt.getTemporaryVariableName(); String strSkipBodyName = ctxt.getTemporaryVariableName(); //according to the tag file, the value attribute is mandatory. ctxt.generateImport("java.io.Reader"); ctxt.generateJavaSource("Object " + strObjectName + "="); ctxt.generateAttribute("value"); ctxt.generateJavaSource(";"); ctxt.generateJavaSource("String " + strValName + "=null;"); ctxt.generateJavaSource("if(!(" + strObjectName + " instanceof Reader) && "+ strObjectName + " != null){"); ctxt.generateJavaSource( strValName + " = " + strObjectName + ".toString();"); ctxt.generateJavaSource("}"); //initiate the strDefName with null. //if the default has been specified, then assign the value to it; ctxt.generateJavaSource("String " + strDefName + " = null;"); if(hasDefault){ ctxt.generateJavaSource("if("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(" != null){"); ctxt.generateJavaSource(strDefName + " = ("); ctxt.generateAttribute("default"); ctxt.generateJavaSource(").toString();"); ctxt.generateJavaSource("}"); } //initiate the strEscapeXmlName with true; //if the escapeXml is specified, assign the value to it; ctxt.generateJavaSource("boolean " + strEscapeXmlName + " = true;"); if(hasEscapeXml){ ctxt.generateJavaSource(strEscapeXmlName + " = "); ctxt.generateAttribute("escapeXml"); ctxt.generateJavaSource(";"); } //main part. ctxt.generateJavaSource( "boolean " + strSkipBodyName + " = " + "org.apache.jasper.tagplugins.jstl.core.Out.output(out, " + strObjectName + ", " + strValName + ", " + strDefName + ", " + strEscapeXmlName + ");"); ctxt.generateJavaSource("if(!" + strSkipBodyName + ") {"); ctxt.generateBody(); ctxt.generateJavaSource("}"); }
Example 18
Source File: Redirect.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //flag for the existence of the "context" boolean hasContext = ctxt.isAttributeSpecified("context"); //names of the temp variables String urlName = ctxt.getTemporaryVariableName(); String contextName = ctxt.getTemporaryVariableName(); String baseUrlName = ctxt.getTemporaryVariableName(); String resultName = ctxt.getTemporaryVariableName(); String responseName = ctxt.getTemporaryVariableName(); //get context ctxt.generateJavaSource("String " + contextName + " = null;"); if(hasContext){ ctxt.generateJavaSource(contextName + " = "); ctxt.generateAttribute("context"); ctxt.generateJavaSource(";"); } //get the url ctxt.generateJavaSource("String " + urlName + " = "); ctxt.generateAttribute("url"); ctxt.generateJavaSource(";"); //get the raw url according to "url" and "context" ctxt.generateJavaSource("String " + baseUrlName + " = " + "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + urlName + ", " + contextName + ", pageContext);"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"url_without_param\", " + baseUrlName + ");"); //add params ctxt.generateBody(); ctxt.generateJavaSource("String " + resultName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");"); ctxt.generateJavaSource("pageContext.removeAttribute" + "(\"url_without_param\");"); //get the response object ctxt.generateJavaSource("HttpServletResponse " + responseName + " = " + "((HttpServletResponse) pageContext.getResponse());"); //if the url is relative, encode it ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){"); ctxt.generateJavaSource(" " + resultName + " = " + responseName + ".encodeRedirectURL(" + resultName + ");"); ctxt.generateJavaSource("}"); //do redirect ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" " + responseName + ".sendRedirect(" + resultName + ");"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); }
Example 19
Source File: Url.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { //flags boolean hasVar, hasContext, hasScope; //init flags hasVar = ctxt.isAttributeSpecified("var"); hasContext = ctxt.isAttributeSpecified("context"); hasScope = ctxt.isAttributeSpecified("scope"); //define name of the temp variables String valueName = ctxt.getTemporaryVariableName(); String contextName = ctxt.getTemporaryVariableName(); String baseUrlName = ctxt.getTemporaryVariableName(); String resultName = ctxt.getTemporaryVariableName(); String responseName = ctxt.getTemporaryVariableName(); //get the scope String strScope = "page"; if(hasScope){ strScope = ctxt.getConstantAttribute("scope"); } int iScope = Util.getScope(strScope); //get the value ctxt.generateJavaSource("String " + valueName + " = "); ctxt.generateAttribute("value"); ctxt.generateJavaSource(";"); //get the context ctxt.generateJavaSource("String " + contextName + " = null;"); if(hasContext){ ctxt.generateJavaSource(contextName + " = "); ctxt.generateAttribute("context"); ctxt.generateJavaSource(";"); } //get the raw url ctxt.generateJavaSource("String " + baseUrlName + " = " + "org.apache.jasper.tagplugins.jstl.Util.resolveUrl(" + valueName + ", " + contextName + ", pageContext);"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"url_without_param\", " + baseUrlName + ");"); //add params ctxt.generateBody(); ctxt.generateJavaSource("String " + resultName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");"); ctxt.generateJavaSource("pageContext.removeAttribute(\"url_without_param\");"); //if the url is relative, encode it ctxt.generateJavaSource("if(!org.apache.jasper.tagplugins.jstl.Util.isAbsoluteUrl(" + resultName + ")){"); ctxt.generateJavaSource(" HttpServletResponse " + responseName + " = " + "((HttpServletResponse) pageContext.getResponse());"); ctxt.generateJavaSource(" " + resultName + " = " + responseName + ".encodeURL(" + resultName + ");"); ctxt.generateJavaSource("}"); //if "var" is specified, the url string store in the attribute var defines if(hasVar){ String strVar = ctxt.getConstantAttribute("var"); ctxt.generateJavaSource("pageContext.setAttribute" + "(\"" + strVar + "\", " + resultName + ", " + iScope + ");"); //if var is not specified, just print out the url string }else{ ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" pageContext.getOut().print(" + resultName + ");"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); } }
Example 20
Source File: ForEach.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void doTag(TagPluginContext ctxt) { String index = null; boolean hasVarStatus = ctxt.isAttributeSpecified("varStatus"); if (hasVarStatus) { ctxt.dontUseTagPlugin(); return; } hasVar = ctxt.isAttributeSpecified("var"); hasBegin = ctxt.isAttributeSpecified("begin"); hasEnd = ctxt.isAttributeSpecified("end"); hasStep = ctxt.isAttributeSpecified("step"); boolean hasItems = ctxt.isAttributeSpecified("items"); if (hasItems) { doCollection(ctxt); return; } // We must have a begin and end attributes index = ctxt.getTemporaryVariableName(); ctxt.generateJavaSource("for (int " + index + " = "); ctxt.generateAttribute("begin"); ctxt.generateJavaSource("; " + index + " <= "); ctxt.generateAttribute("end"); if (hasStep) { ctxt.generateJavaSource("; " + index + "+="); ctxt.generateAttribute("step"); ctxt.generateJavaSource(") {"); } else { ctxt.generateJavaSource("; " + index + "++) {"); } // If var is specified and the body contains an EL, then sycn // the var attribute if (hasVar /* && ctxt.hasEL() */) { ctxt.generateJavaSource("_jspx_page_context.setAttribute("); ctxt.generateAttribute("var"); ctxt.generateJavaSource(", String.valueOf(" + index + "));"); } ctxt.generateBody(); ctxt.generateJavaSource("}"); }