org.apache.jasper.tagplugins.jstl.Util Java Examples

The following examples show how to use org.apache.jasper.tagplugins.jstl.Util. 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: Remove.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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 #2
Source File: Remove.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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 vote down vote up
@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: Out.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public static boolean output(JspWriter out, Object input, String value,
        String defaultValue, boolean escapeXml) throws IOException {
    if (input instanceof Reader) {
        char[] buffer = new char[8096];
        int read = 0;
        while (read != -1) {
            read = ((Reader) input).read(buffer);
            if (read != -1) {
                if (escapeXml) {
                    String escaped = Util.escapeXml(buffer, read);
                    if (escaped == null) {
                        out.write(buffer, 0, read);
                    } else {
                        out.print(escaped);
                    }
                } else {
                    out.write(buffer, 0, read);
                }
            }
        }
        return true;
    } else {
        String v = value != null ? value : defaultValue;
        if (v != null) {
            if(escapeXml){
                v = Util.escapeXml(v);
            }
            out.write(v);
            return true;
        } else {
            return false;
        }
    }
}
 
Example #5
Source File: Out.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static boolean output(JspWriter out, Object input, String value,
        String defaultValue, boolean escapeXml) throws IOException {
    if (input instanceof Reader) {
        char[] buffer = new char[8096];
        int read = 0;
        while (read != -1) {
            read = ((Reader) input).read(buffer);
            if (read != -1) {
                if (escapeXml) {
                    String escaped = Util.escapeXml(buffer, read);
                    if (escaped == null) {
                        out.write(buffer, 0, read);
                    } else {
                        out.print(escaped);
                    }
                } else {
                    out.write(buffer, 0, read);
                }
            }
        }
        return true;
    } else {
        String v = value != null ? value : defaultValue;
        if (v != null) {
            if(escapeXml){
                v = Util.escapeXml(v);
            }
            out.write(v);
            return true;
        } else {
            return false;
        }
    }
}
 
Example #6
Source File: Out.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static boolean output(JspWriter out, Object input, String value,
        String defaultValue, boolean escapeXml) throws IOException {
    if (input instanceof Reader) {
        char[] buffer = new char[8096];
        int read = 0;
        while (read != -1) {
            read = ((Reader) input).read(buffer);
            if (read != -1) {
                if (escapeXml) {
                    String escaped = Util.escapeXml(buffer, read);
                    if (escaped == null) {
                        out.write(buffer, 0, read);
                    } else {
                        out.print(escaped);
                    }
                } else {
                    out.write(buffer, 0, read);
                }
            }
        }
        return true;
    } else {
        String v = value != null ? value : defaultValue;
        if (v != null) {
            if(escapeXml){
                v = Util.escapeXml(v);
            }
            out.write(v);
            return true;
        } else {
            return false;
        }
    }
}
 
Example #7
Source File: Url.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@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 #8
Source File: Url.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@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 #9
Source File: Url.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@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("}");
    }
}