Java Code Examples for org.apache.jasper.compiler.tagplugin.TagPluginContext#dontUseTagPlugin()

The following examples show how to use org.apache.jasper.compiler.tagplugin.TagPluginContext#dontUseTagPlugin() . 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: When.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void doTag(TagPluginContext ctxt) {
    // Get the parent context to determine if this is the first <c:when>
    TagPluginContext parentContext = ctxt.getParentContext();
    if (parentContext == null) {
        ctxt.dontUseTagPlugin();
        return;
    }

    if ("true".equals(parentContext.getPluginAttribute("hasBeenHere"))) {
        ctxt.generateJavaSource("} else if(");
        // See comment below for the reason we generate the extra "}" here.
    }
    else {
        ctxt.generateJavaSource("if(");
        parentContext.setPluginAttribute("hasBeenHere", "true");
    }
    ctxt.generateAttribute("test");
    ctxt.generateJavaSource("){");
    ctxt.generateBody();

    // We don't generate the closing "}" for the "if" here because there
    // may be whitespaces in between <c:when>'s.  Instead we delay
    // generating it until the next <c:when> or <c:otherwise> or
    // <c:choose>
}
 
Example 2
Source File: When.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void doTag(TagPluginContext ctxt) {
    // Get the parent context to determine if this is the first <c:when>
    TagPluginContext parentContext = ctxt.getParentContext();
    if (parentContext == null) {
        ctxt.dontUseTagPlugin();
        return;
    }
    
    if ("true".equals(parentContext.getPluginAttribute("hasBeenHere"))) {
        ctxt.generateJavaSource("} else if(");
        // See comment below for the reason we generate the extra "}" here.
    }
    else {
        ctxt.generateJavaSource("if(");
        parentContext.setPluginAttribute("hasBeenHere", "true");
    }
    ctxt.generateAttribute("test");
    ctxt.generateJavaSource("){");
    ctxt.generateBody();
    
    // We don't generate the closing "}" for the "if" here because there
    // may be whitespaces in between <c:when>'s.  Instead we delay
    // generating it until the next <c:when> or <c:otherwise> or
    // <c:choose>
}
 
Example 3
Source File: When.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void doTag(TagPluginContext ctxt) {
    // Get the parent context to determine if this is the first <c:when>
    TagPluginContext parentContext = ctxt.getParentContext();
    if (parentContext == null) {
        ctxt.dontUseTagPlugin();
        return;
    }
    
    if ("true".equals(parentContext.getPluginAttribute("hasBeenHere"))) {
        ctxt.generateJavaSource("} else if(");
        // See comment below for the reason we generate the extra "}" here.
    }
    else {
        ctxt.generateJavaSource("if(");
        parentContext.setPluginAttribute("hasBeenHere", "true");
    }
    ctxt.generateAttribute("test");
    ctxt.generateJavaSource("){");
    ctxt.generateBody();
    
    // We don't generate the closing "}" for the "if" here because there
    // may be whitespaces in between <c:when>'s.  Instead we delay
    // generating it until the next <c:when> or <c:otherwise> or
    // <c:choose>
}
 
Example 4
Source File: ForTokens.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@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 5
Source File: ForEach.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@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 6
Source File: ForTokens.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@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 7
Source File: ForEach.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: ForTokens.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@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: ForEach.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@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("}");
}