org.kohsuke.stapler.jelly.groovy
Class JellyBuilder

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by org.kohsuke.stapler.jelly.groovy.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 Summary
JellyBuilder(org.apache.commons.jelly.JellyContext context, org.apache.commons.jelly.XMLOutput output)
           
 
Method Summary
 void adjunct(java.lang.String name)
          Includes the specified adjunct.
protected  void doInvokeMethod(groovy.xml.QName name, java.lang.Object args)
           
 JellyBuilder getBuilder()
           
 org.apache.commons.jelly.JellyContext getContext()
           
 java.lang.Object getMy()
          Gets the "it" object.
 org.apache.commons.jelly.XMLOutput getOutput()
           
 java.lang.Object getProperty(java.lang.String property)
          Allows values from JellyContext to be read like global variables.
 StaplerRequest getRequest()
           
 StaplerResponse getResponse()
           
 java.lang.String getRootURL()
          Gets the absolute URL to the top of the webapp.
 javax.servlet.ServletContext getServletContext()
           
 void img(java.lang.Object base, java.lang.String localName)
          Generates an <IMG> tag to the resource.
 void include(java.lang.Class clazz, java.lang.String view)
          Includes another view.
 void include(java.lang.Object it, java.lang.String view)
          Includes another view.
 Namespace jelly(java.lang.Class t)
          Loads a jelly tag library.
 java.lang.Object methodMissing(java.lang.String name, java.lang.Object args)
           
<T extends TypedTagLibrary>
T
namespace(java.lang.Class<T> type)
           
 Namespace namespace(java.lang.String nsUri)
           
 Namespace namespace(java.lang.String nsUri, java.lang.String prefix)
          This is used to allow QName to be used for the invocation.
 void raw(java.lang.Object o)
          Generates HTML fragment from string.
 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.
 java.lang.String res(java.lang.Object base, java.lang.String localName)
          Yields a URL to the given resource.
 void set(java.lang.String var, java.lang.Object value)
          Sets the value to JellyContext (typically as a pre-cursor to calling into Jelly tags.)
 org.apache.commons.jelly.XMLOutput setOutput(org.apache.commons.jelly.XMLOutput newValue)
           
 java.lang.Object taglib(java.lang.Class type)
          Loads a Groovy tag lib instance.
 void text(java.lang.Object o)
          Writes PCDATA.
 java.lang.Object with(org.apache.commons.jelly.XMLOutput out, groovy.lang.Closure c)
          Executes the closure with the specified XMLOutput.
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, invokeMethod, setMetaClass, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JellyBuilder

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

namespace

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


namespace

public Namespace namespace(java.lang.String nsUri)

namespace

public <T extends TypedTagLibrary> T namespace(java.lang.Class<T> type)

getOutput

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

getContext

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

include

public void include(java.lang.Object it,
                    java.lang.String view)
             throws java.io.IOException,
                    org.apache.commons.jelly.JellyException
Includes another view.

Throws:
java.io.IOException
org.apache.commons.jelly.JellyException

include

public void include(java.lang.Class clazz,
                    java.lang.String view)
             throws java.io.IOException,
                    org.apache.commons.jelly.JellyException
Includes another view.

Throws:
java.io.IOException
org.apache.commons.jelly.JellyException

methodMissing

public java.lang.Object methodMissing(java.lang.String name,
                                      java.lang.Object args)

doInvokeMethod

protected void doInvokeMethod(groovy.xml.QName name,
                              java.lang.Object args)

setOutput

public org.apache.commons.jelly.XMLOutput setOutput(org.apache.commons.jelly.XMLOutput newValue)

with

public java.lang.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 java.lang.Object getProperty(java.lang.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(java.lang.String var,
                java.lang.Object value)
Sets the value to JellyContext (typically as a pre-cursor to calling into Jelly tags.)


getMy

public java.lang.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(java.lang.Object o)
          throws org.xml.sax.SAXException
Writes PCDATA.

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

Throws:
org.xml.sax.SAXException
See Also:
raw(Object)

raw

public void raw(java.lang.Object o)
         throws org.xml.sax.SAXException
Generates HTML fragment from string.

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

Throws:
org.xml.sax.SAXException
See Also:
text(Object)

taglib

public java.lang.Object taglib(java.lang.Class type)
                        throws java.lang.IllegalAccessException,
                               java.lang.InstantiationException,
                               java.io.IOException,
                               org.xml.sax.SAXException
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 instanciates the class (if not done so already for this request), and return it.

Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException
org.xml.sax.SAXException

adjunct

public void adjunct(java.lang.String name)
             throws java.io.IOException,
                    org.xml.sax.SAXException
Includes the specified adjunct. This method is useful for including adjunct dynamically on demand.

Throws:
java.io.IOException
org.xml.sax.SAXException

jelly

public Namespace jelly(java.lang.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 StaplerRequest getRequest()

getResponse

public StaplerResponse getResponse()

getBuilder

public JellyBuilder getBuilder()

getRootURL

public java.lang.String getRootURL()
Gets the absolute URL to the top of the webapp.

See Also:
HttpServletRequest.getContextPath()

img

public void img(java.lang.Object base,
                java.lang.String localName)
         throws org.xml.sax.SAXException
Generates an <IMG> tag to the resource.

Throws:
org.xml.sax.SAXException

res

public java.lang.String res(java.lang.Object base,
                            java.lang.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.


Copyright © 2012. All Rights Reserved.