Class JellyBuilder

  • All Implemented Interfaces:
    groovy.lang.GroovyObject

    public final class JellyBuilder
    extends groovy.lang.GroovyObjectSupport
    Drive Jelly scripts from Groovy markup.
    Author:
    Kohsuke Kawaguchi
    • Constructor Detail

      • JellyBuilder

        public JellyBuilder​(org.apache.commons.jelly.JellyContext context,
                            org.apache.commons.jelly.XMLOutput output)
    • Method Detail

      • namespace

        public Namespace namespace​(String nsUri,
                                   String prefix)
        This is used to allow QName to be used for the invocation.
      • getOutput

        public org.apache.commons.jelly.XMLOutput getOutput()
      • getContext

        public org.apache.commons.jelly.JellyContext getContext()
      • include

        public void include​(Object it,
                            String view)
                     throws IOException,
                            org.apache.commons.jelly.JellyException
        Includes another view.
        Throws:
        IOException
        org.apache.commons.jelly.JellyException
      • include

        public void include​(Class clazz,
                            String view)
                     throws IOException,
                            org.apache.commons.jelly.JellyException
        Includes another view.
        Throws:
        IOException
        org.apache.commons.jelly.JellyException
      • doInvokeMethod

        protected void doInvokeMethod​(groovy.xml.QName name,
                                      Object args)
      • setOutput

        public org.apache.commons.jelly.XMLOutput setOutput​(org.apache.commons.jelly.XMLOutput newValue)
      • with

        public Object with​(org.apache.commons.jelly.XMLOutput out,
                           groovy.lang.Closure c)
        Executes the closure with the specified XMLOutput.
      • redirectToDom

        public org.dom4j.Element redirectToDom​(groovy.lang.Closure c)
        Captures the XML fragment generated by the given closure into dom4j DOM tree and return the root element.
        Returns:
        null if nothing was generated.
      • getProperty

        public Object getProperty​(String property)
        Allows values from JellyContext to be read like global variables. These includes 'request', 'response', etc.
        Specified by:
        getProperty in interface groovy.lang.GroovyObject
        Overrides:
        getProperty in class groovy.lang.GroovyObjectSupport
        See Also:
        JellyClassTearOff
      • set

        public void set​(String var,
                        Object value)
        Sets the value to JellyContext (typically as a pre-cursor to calling into Jelly tags.)
      • getMy

        public Object getMy()
        Gets the "it" object. In Groovy "it" is reserved word with a specific meaning, so instead use "my" as the word.
      • text

        public void text​(Object o)
                  throws SAXException
        Writes PCDATA.

        Any HTML unsafe characters in the string representation of the given object is properly escaped.

        Throws:
        SAXException
        See Also:
        raw(Object)
      • raw

        public void raw​(Object o)
                 throws SAXException
        Generates HTML fragment from string.

        The string representation of the object is assumed to produce proper HTML. No further escaping is performed.

        Throws:
        SAXException
        See Also:
        text(Object)
      • taglib

        public Object taglib​(Class type)
        Loads a Groovy tag lib instance.

        A groovy tag library is really just a script class with bunch of method definitions, without any explicit class definition. Such a class is loaded as a subtype of GroovyClosureScript so that it can use this builder as the delegation target.

        This method instantiates the class (if not done so already for this request), and return it.

      • jelly

        public Namespace jelly​(Class t)
        Loads a jelly tag library.
        Parameters:
        t - If this is a subtype of TagLibrary, then that tag library is loaded and bound to the Namespace object, which you can later use to call tags. Otherwise, t has to have 'taglib' file in the resource and sibling "*.jelly" files will be treated as tag files.
      • getServletContext

        public javax.servlet.ServletContext getServletContext()
      • getRequest

        public org.kohsuke.stapler.StaplerRequest getRequest()
      • getResponse

        public org.kohsuke.stapler.StaplerResponse getResponse()
      • getRootURL

        public String getRootURL()
        Gets the absolute URL to the top of the webapp.
        See Also:
        HttpServletRequest.getContextPath()
      • res

        public String res​(Object base,
                          String localName)
        Yields a URL to the given resource.
        Parameters:
        base - The base class/object for which the 'localName' parameter is resolved from. If this is class, 'localName' is assumed to be a resource of this class. If it's other objects, 'localName' is assumed to be a resource of the class of this object.