Search in sources :

Example 1 with TagPluginContext

use of org.apache.jasper.compiler.tagplugin.TagPluginContext in project tomcat by apache.

the class TagPluginManager method invokePlugin.

/**
     * Invoke tag plugin for the given custom tag, if a plugin exists for
     * the custom tag's tag handler.
     * <p/>
     * The given custom tag node will be manipulated by the plugin.
     */
private void invokePlugin(Node.CustomTag n, PageInfo pageInfo) {
    TagPlugin tagPlugin = tagPlugins.get(n.getTagHandlerClass().getName());
    if (tagPlugin == null) {
        return;
    }
    TagPluginContext tagPluginContext = new TagPluginContextImpl(n, pageInfo);
    n.setTagPluginContext(tagPluginContext);
    tagPlugin.doTag(tagPluginContext);
}
Also used : TagPluginContext(org.apache.jasper.compiler.tagplugin.TagPluginContext) TagPlugin(org.apache.jasper.compiler.tagplugin.TagPlugin)

Example 2 with TagPluginContext

use of org.apache.jasper.compiler.tagplugin.TagPluginContext in project tomcat by apache.

the class Param method doTag.

@Override
public void doTag(TagPluginContext ctxt) {
    //don't support the body content
    //define names of all the temp variables
    String nameName = ctxt.getTemporaryVariableName();
    String valueName = ctxt.getTemporaryVariableName();
    String urlName = ctxt.getTemporaryVariableName();
    String encName = ctxt.getTemporaryVariableName();
    String index = ctxt.getTemporaryVariableName();
    //if the param tag has no parents, throw a exception
    TagPluginContext parent = ctxt.getParentContext();
    if (parent == null) {
        ctxt.generateJavaSource(" throw new JspTagException" + "(\"&lt;param&gt; outside &lt;import&gt; or &lt;urlEncode&gt;\");");
        return;
    }
    //get the url string before adding this param
    ctxt.generateJavaSource("String " + urlName + " = " + "(String)pageContext.getAttribute(\"url_without_param\");");
    //get the value of "name"
    ctxt.generateJavaSource("String " + nameName + " = ");
    ctxt.generateAttribute("name");
    ctxt.generateJavaSource(";");
    //if the "name" is null then do nothing.
    //else add such string "name=value" to the url.
    //and the url should be encoded
    ctxt.generateJavaSource("if(" + nameName + " != null && !" + nameName + ".equals(\"\")){");
    ctxt.generateJavaSource("    String " + valueName + " = ");
    ctxt.generateAttribute("value");
    ctxt.generateJavaSource(";");
    ctxt.generateJavaSource("    if(" + valueName + " == null) " + valueName + " = \"\";");
    ctxt.generateJavaSource("    String " + encName + " = pageContext.getResponse().getCharacterEncoding();");
    ctxt.generateJavaSource("    " + nameName + " = java.net.URLEncoder.encode(" + nameName + ", " + encName + ");");
    ctxt.generateJavaSource("    " + valueName + " = java.net.URLEncoder.encode(" + valueName + ", " + encName + ");");
    ctxt.generateJavaSource("    int " + index + ";");
    ctxt.generateJavaSource("    " + index + " = " + urlName + ".indexOf(\'?\');");
    //if the current param is the first one, add a "?" ahead of it
    //else add a "&" ahead of it
    ctxt.generateJavaSource("    if(" + index + " == -1){");
    ctxt.generateJavaSource("        " + urlName + " = " + urlName + " + \"?\" + " + nameName + " + \"=\" + " + valueName + ";");
    ctxt.generateJavaSource("    }else{");
    ctxt.generateJavaSource("        " + urlName + " = " + urlName + " + \"&\" + " + nameName + " + \"=\" + " + valueName + ";");
    ctxt.generateJavaSource("    }");
    ctxt.generateJavaSource("    pageContext.setAttribute(\"url_without_param\"," + urlName + ");");
    ctxt.generateJavaSource("}");
}
Also used : TagPluginContext(org.apache.jasper.compiler.tagplugin.TagPluginContext)

Example 3 with TagPluginContext

use of org.apache.jasper.compiler.tagplugin.TagPluginContext in project tomcat by apache.

the class When method doTag.

@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>
}
Also used : TagPluginContext(org.apache.jasper.compiler.tagplugin.TagPluginContext)

Aggregations

TagPluginContext (org.apache.jasper.compiler.tagplugin.TagPluginContext)3 TagPlugin (org.apache.jasper.compiler.tagplugin.TagPlugin)1