Package org.kohsuke.stapler.jelly.groovy
Class JellyBuilder
- java.lang.Object
-
- groovy.lang.GroovyObjectSupport
-
- org.kohsuke.stapler.jelly.groovy.JellyBuilder
-
- All Implemented Interfaces:
groovy.lang.GroovyObject
public final class JellyBuilder extends groovy.lang.GroovyObjectSupportDrive Jelly scripts from Groovy markup.- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description JellyBuilder(org.apache.commons.jelly.JellyContext context, org.apache.commons.jelly.XMLOutput output)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadjunct(String name)Includes the specified adjunct.protected voiddoInvokeMethod(groovy.xml.QName name, Object args)JellyBuildergetBuilder()org.apache.commons.jelly.JellyContextgetContext()ObjectgetMy()Gets the "it" object.org.apache.commons.jelly.XMLOutputgetOutput()ObjectgetProperty(String property)Allows values fromJellyContextto be read like global variables.org.kohsuke.stapler.StaplerRequestgetRequest()org.kohsuke.stapler.StaplerResponsegetResponse()StringgetRootURL()Gets the absolute URL to the top of the webapp.javax.servlet.ServletContextgetServletContext()voidimg(Object base, String localName)Generates an<IMG>tag to the resource.voidinclude(Class clazz, String view)Includes another view.voidinclude(Object it, String view)Includes another view.Namespacejelly(Class t)Loads a jelly tag library.ObjectmethodMissing(String name, Object args)<T extends TypedTagLibrary>
Tnamespace(Class<T> type)Namespacenamespace(String nsUri)Namespacenamespace(String nsUri, String prefix)This is used to allow QName to be used for the invocation.voidraw(Object o)Generates HTML fragment from string.org.dom4j.ElementredirectToDom(groovy.lang.Closure c)Captures the XML fragment generated by the given closure into dom4j DOM tree and return the root element.Stringres(Object base, String localName)Yields a URL to the given resource.voidset(String var, Object value)Sets the value toJellyContext(typically as a pre-cursor to calling into Jelly tags.)org.apache.commons.jelly.XMLOutputsetOutput(org.apache.commons.jelly.XMLOutput newValue)Objecttaglib(Class type)Loads a Groovy tag lib instance.voidtext(Object o)Writes PCDATA.Objectwith(org.apache.commons.jelly.XMLOutput out, groovy.lang.Closure c)Executes the closure with the specifiedXMLOutput.
-
-
-
Method Detail
-
namespace
public Namespace namespace(String nsUri, String prefix)
This is used to allow QName to be used for the invocation.
-
namespace
public <T extends TypedTagLibrary> T namespace(Class<T> type)
-
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:
IOExceptionorg.apache.commons.jelly.JellyException
-
include
public void include(Class clazz, String view) throws IOException, org.apache.commons.jelly.JellyException
Includes another view.- Throws:
IOExceptionorg.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 specifiedXMLOutput.
-
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 fromJellyContextto be read like global variables. These includes 'request', 'response', etc.- Specified by:
getPropertyin interfacegroovy.lang.GroovyObject- Overrides:
getPropertyin classgroovy.lang.GroovyObjectSupport- See Also:
JellyClassTearOff
-
set
public void set(String var, Object value)
Sets the value toJellyContext(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
GroovyClosureScriptso 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.
-
adjunct
public void adjunct(String name) throws IOException, SAXException
Includes the specified adjunct. This method is useful for including adjunct dynamically on demand.- Throws:
IOExceptionSAXException
-
jelly
public Namespace jelly(Class t)
Loads a jelly tag library.- Parameters:
t- If this is a subtype ofTagLibrary, then that tag library is loaded and bound to theNamespaceobject, 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()
-
getBuilder
public JellyBuilder getBuilder()
-
getRootURL
public String getRootURL()
Gets the absolute URL to the top of the webapp.- See Also:
HttpServletRequest.getContextPath()
-
img
public void img(Object base, String localName) throws SAXException
Generates an<IMG>tag to the resource.- Throws:
SAXException
-
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.
-
-