Interface TagPluginContext


  • public interface TagPluginContext
    This interface allows the plugin author to make inquiries about the properties of the current tag, and to use Jasper resources to generate direct Java codes in place of tag handler invocations.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void dontUseTagPlugin()
      Abandon optimization for this tag handler, and instruct Jasper to generate the tag handler calls, as usual.
      void generateAttribute​(java.lang.String attribute)
      Generate codes to evaluate value of an attribute in the custom tag The codes is a Java expression.
      void generateBody()
      Generate codes for the body of the custom tag
      void generateDeclaration​(java.lang.String id, java.lang.String text)
      Generate a declaration in the of the generated class.
      void generateImport​(java.lang.String s)
      Generate an import statement
      void generateJavaSource​(java.lang.String s)
      Generate Java source code scriptlet
      default void generatePageTermination()
      Generate the code to terminate the current page.
      java.lang.String getConstantAttribute​(java.lang.String attribute)
      Returns the value of a constant attribute.
      TagPluginContext getParentContext()
      Get the PluginContext for the parent of this custom tag.
      default TagPluginContext getParentContext​(boolean crossTagHandlers)
      Get the PluginContext of the closest enclosing custom tag that has one, optionally looking beyond tags whose body is generated by the standard tag handler mechanism.
      java.lang.Object getPluginAttribute​(java.lang.String attr)
      Get the value of an attribute in the current tagplugin context.
      java.lang.String getTemporaryVariableName()
      Generates a unique temporary variable name for use in generated code.
      default boolean hasBody()
      Checks whether the current tag has a body.
      boolean isAttributeSpecified​(java.lang.String attribute)
      Checks whether the specified attribute is present in the current tag.
      boolean isConstantAttribute​(java.lang.String attribute)
      Checks whether the specified attribute has a translation-time constant value.
      boolean isScriptless()
      Checks whether the body of the current tag is scriptless.
      boolean isTagFile()
      Is the tag being used inside a tag file?
      void setPluginAttribute​(java.lang.String attr, java.lang.Object value)
      Associate the attribute with a value in the current tagplugin context.
    • Method Detail

      • isScriptless

        boolean isScriptless()
        Checks whether the body of the current tag is scriptless.
        Returns:
        true if the body of the tag is scriptless
      • hasBody

        default boolean hasBody()
        Checks whether the current tag has a body. A tag whose only children are jsp:attribute actions, or whose jsp:body is empty, has no body. A body that contains only whitespace is still a body.
        Returns:
        true if the tag has a body, false if the body is empty. The default implementation returns true, which is always safe for a plugin that uses the query to skip work that is only needed for a body.
      • isAttributeSpecified

        boolean isAttributeSpecified​(java.lang.String attribute)
        Checks whether the specified attribute is present in the current tag.
        Parameters:
        attribute - Name of the attribute
        Returns:
        true if the attribute is specified in the tag
      • getTemporaryVariableName

        java.lang.String getTemporaryVariableName()
        Generates a unique temporary variable name for use in generated code.
        Returns:
        A unique temporary variable name that the plugin can use
      • generateImport

        void generateImport​(java.lang.String s)
        Generate an import statement
        Parameters:
        s - Name of the import class, '*' allowed.
      • generateDeclaration

        void generateDeclaration​(java.lang.String id,
                                 java.lang.String text)
        Generate a declaration in the of the generated class. This can be used to declare an inner class, a method, or a class variable.
        Parameters:
        id - A unique ID identifying the declaration. It is not part of the declaration, and is used to ensure that the declaration will only appear once. If this method is invoked with the same id more than once in the translation unit, only the first declaration will be taken.
        text - The text of the declaration.
      • generateJavaSource

        void generateJavaSource​(java.lang.String s)
        Generate Java source code scriptlet
        Parameters:
        s - the scriptlet (raw Java source)
      • isConstantAttribute

        boolean isConstantAttribute​(java.lang.String attribute)
        Checks whether the specified attribute has a translation-time constant value.
        Parameters:
        attribute - The attribute name
        Returns:
        true if the attribute is specified and its value is a translation-time constant
      • getConstantAttribute

        java.lang.String getConstantAttribute​(java.lang.String attribute)
        Returns the value of a constant attribute.
        Parameters:
        attribute - The attribute name
        Returns:
        A string that is the value of a constant attribute. Undefined if the attribute is not a (translation-time) constant. null if the attribute is not specified
      • generateAttribute

        void generateAttribute​(java.lang.String attribute)
        Generate codes to evaluate value of an attribute in the custom tag The codes is a Java expression. NOTE: Currently cannot handle attributes that are fragments.
        Parameters:
        attribute - The specified attribute
      • generateBody

        void generateBody()
        Generate codes for the body of the custom tag
      • dontUseTagPlugin

        void dontUseTagPlugin()
        Abandon optimization for this tag handler, and instruct Jasper to generate the tag handler calls, as usual. Should be invoked if errors are detected, or when the tag body is deemed too complicated for optimization.
      • getParentContext

        TagPluginContext getParentContext()
        Get the PluginContext for the parent of this custom tag. NOTE: The operations available for PluginContext so obtained is limited to getPluginAttribute and setPluginAttribute, and queries (e.g. isScriptless()). There should be no calls to generate*().
        Returns:
        The pluginContext for the parent node. null if the parent is not a custom tag, if the parent custom tag has no plugin context, or if the tag associated with this context has abandoned the plugin, in which case the body is not generated inline and the scopes of the generated code are disconnected.
      • getParentContext

        default TagPluginContext getParentContext​(boolean crossTagHandlers)
        Get the PluginContext of the closest enclosing custom tag that has one, optionally looking beyond tags whose body is generated by the standard tag handler mechanism. The same restrictions as for getParentContext() apply to the context obtained.

        Tags that abandoned their plugin are not skipped. Their body is generated in a separate method of the generated servlet, so local variables of outer tags are out of scope inside it and the result must not be used to share such variables. It is suitable for finding a tag that must be told to abandon its plugin.

        Parameters:
        crossTagHandlers - true to continue past tags that abandoned their plugin
        Returns:
        the pluginContext of the closest enclosing tag with a plugin, or null if there is none
      • setPluginAttribute

        void setPluginAttribute​(java.lang.String attr,
                                java.lang.Object value)
        Associate the attribute with a value in the current tagplugin context. The plugin attributes can be used for communication among tags that must work together as a group. See <c:when> for an example.
        Parameters:
        attr - The attribute name
        value - The attribute value
      • getPluginAttribute

        java.lang.Object getPluginAttribute​(java.lang.String attr)
        Get the value of an attribute in the current tagplugin context.
        Parameters:
        attr - The attribute name
        Returns:
        the attribute value
      • isTagFile

        boolean isTagFile()
        Is the tag being used inside a tag file?
        Returns:
        true if inside a tag file
      • generatePageTermination

        default void generatePageTermination()
        Generate the code to terminate the current page.