Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Jelly Executable XML

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Jelly: Executable XML


dIon Gillard
Multitask Consulting Pty. Ltd.

dIon Gillard — Jelly: Executable XML Page 1


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 2


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

What Is Jelly?
ƒ Java and XML based scripting engine
ƒ Executes XML and produces XML, HTML, etc.
ƒ Front end to other XML tools such as Ant
ƒ Borrows heavily from JSP and JSTL
ƒ Comes with many tag libraries for common tasks
ƒ Uses Jexl for expression support
ƒ Extensible via Java or Jelly tag libraries

dIon Gillard — Jelly: Executable XML Page 3


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Jelly Architecture

XMLParser

Context

Tags Script

XMLOutput

TagLibrary

dIon Gillard — Jelly: Executable XML Page 4


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Key classes
ƒ XMLParser
¾ Takes XML document and creates a script
ƒ Context
¾ Variables available to the Jelly script at run time
ƒ Script
¾ Executable 'code' made up of text and tags
ƒ TagLibrary
¾ Group of tags with a registered name

dIon Gillard — Jelly: Executable XML Page 5


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 6


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

A Jelly Script

<?xml version="1.0" ?>

<j:jelly xmlns:j="jelly:core">

Hello World!

</j:jelly>

Demo: aJellyScript-1.jelly, aJellyScript-2.jelly, aJellyScript-3.jelly

dIon Gillard — Jelly: Executable XML Page 7


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Jelly Script – Details


ƒ It's an XML Document
ƒ Namespaces used to refer to tag libraries
ƒ Text is passed straight through
ƒ Trimming? (Sample 1)
ƒ Encoding? (Sample 2)
ƒ jelly:core where is that defined?

dIon Gillard — Jelly: Executable XML Page 8


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Jelly Script – variables


<?xml version="1.0" ?>
<jelly xmlns="jelly:core" trim="no">
Properties
------------
<forEach var="iter"
items="${systemScope}">${iter.key} =
${iter.value}
</forEach>
</jelly>

Demo: aJellyScript-4.jelly

dIon Gillard — Jelly: Executable XML Page 9


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Jelly Script – variables (Continued)


ƒ Default namespace
ƒ forEach from core tag library
ƒ systemScope predefined variable
ƒ Accessing iterators and objects
ƒ Text output formatting

dIon Gillard — Jelly: Executable XML Page 10


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 11


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core TagLibrary
ƒ Jelly was originally one big jar with all the tag
libraries included
ƒ Too many dependencies were difficult to track
ƒ Split into core and ant, antlr, avalon, bean,
beanshell, betwixt, bsf, define, dynabean,
email, fmt, html, http, interaction, jetty, jface,
jms, jmx, jsl, junit, log, ojb, quartz, soap, sql,
swing, swt, threads, util, validate, velocity,
xml, xmlunit

dIon Gillard — Jelly: Executable XML Page 12


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core TagLibrary vs. Others


ƒ These were the tags that will most always be used
ƒ We will not cover all tag libraries during the session
ƒ If you become familiar with core, the
documentation and a bit of reading between the
lines will allow you to easily understand the others

dIon Gillard — Jelly: Executable XML Page 13


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – set
ƒ <j:set var=”name” value=”${expr}”/>
¾ Or <j:set var=”name”>${stringExpr}</j:set>
ƒ Assignment operator
ƒ Not like Ant properties
ƒ value can be any jexl expression

dIon Gillard — Jelly: Executable XML Page 14


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – set Example


<?xml version="1.0" ?>
<jelly xmlns="jelly:core" trim="yes">
Properties
------------
<forEach var="iter" items="${systemScope}">
<set var="name" value="${iter.key}"/>
<set var="value" value="${iter.value}"/>
${name} = "${value}"
</forEach>
</jelly>

Demo: core1.jelly

dIon Gillard — Jelly: Executable XML Page 15


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – if
ƒ <if test=”${booleanExpr}”>
ƒ ...more tags...
ƒ </if>
ƒ Evaluates its body if the expression is true
ƒ No else tag!
ƒ operators supported >, >=, <, <=, !

dIon Gillard — Jelly: Executable XML Page 16


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – if Example
<?xml version="1.0" ?>
<jelly xmlns="jelly:core" trim="no">

<forEach var="iter" items="${systemScope}">


<set var="name" value="${iter.key}"/>
<if test="${name == 'user.name'}">
Hi ${iter.value}!
</if>
</forEach>
</jelly>

Demo: core2.jelly, core3.jelly

dIon Gillard — Jelly: Executable XML Page 17


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – forEach
ƒ You've seen it in action
ƒ The 'for loop' for jelly
<forEach var=”item” items=”${expr}”
indexVar=”counter” begin=”number”
end=”number” step=”number”>
...statements...
</forEach>

dIon Gillard — Jelly: Executable XML Page 18


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – new
ƒ Create a new object
ƒ <new var=”name” className=”fullName” />
ƒ The class must be available to Jelly either in
the current thread's context class loader, or
on the classpath
ƒ This is very different to Ant's <property/>
ƒ Arguments can be passed to the constructor
using <arg>
Demo: core4.jelly

dIon Gillard — Jelly: Executable XML Page 19


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – new Example


<?xml version="1.0" ?>
<jelly xmlns="jelly:core" trim="no">

<new var="myList"
className="java.util.ArrayList" />
Size is ${size(myList)}

</jelly>

Demo: core5.jelly

dIon Gillard — Jelly: Executable XML Page 20


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – invoke and catch


ƒ Invoke a method on an object
ƒ Can take nested <arg>s like new
<invoke var=”result” method=”name”
on=”object”/>
ƒ Exception handling?
<catch var=”e”>
...
</catch>

dIon Gillard — Jelly: Executable XML Page 21


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – invoke Example


<new var="myList1"
className="java.util.ArrayList"/>
<expr value="${myList1.add('Hello')}"/>
<invoke var="dontCare" method="add"
on="${myList1}">
<arg value="World"/>
</invoke>
Size of list 1 is ${size(myList1)}
list 1 is ${myList1}

Demo: core6.jelly

dIon Gillard — Jelly: Executable XML Page 22


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – switch
ƒ Switch, case, default from Java
<switch on=”${expr}”>
<case value=”${otherExpr}”>
...
</case>
<default>
...
</default>
</switch>

Demo: core8.jelly

dIon Gillard — Jelly: Executable XML Page 23


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – switch Example


<set var="lookingFor" value="dion" />
<switch on="${systemScope['user.name']}">
<case value="${lookingFor}">
Gotcha
</case>
<default>
Imposter!
</default>
</switch>

dIon Gillard — Jelly: Executable XML Page 24


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – choose
ƒ Similar to switch, but not necessarily on a
single value
<choose>
<when test=”${booleanExpr}”>
...
</when>
<otherwise></otherwise>
</choose>

Demo: core9.jelly, core10.jelly

dIon Gillard — Jelly: Executable XML Page 25


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – choose Example


<set var="lookingFor" value="dion" />
<choose>
<when test="${systemScope['user.name'] ==
lookingFor}">
Gotcha
</when>
<otherwise>
Imposter!
</otherwise>
</choose>

dIon Gillard — Jelly: Executable XML Page 26


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – while
ƒ While loop for Jelly
ƒ <while test=”${booleanExpr}”>...</while>

<set var="start" value="5" />


<while test="${start != 10}">
start is ${start}
<set var="start" value="${start + 1}"/>
</while>

Demo: core11.jelly

dIon Gillard — Jelly: Executable XML Page 27


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – break
ƒ Breaks out of while or forEach
ƒ <break test=”${booleanExpr}”>...</while>

<set var="start" value="5" />


<while test="${true}">
start is ${start}
<set var="start" value="${start + 1}"/>
<break test=”${start == 10}”/>
</while>

Demo: core12.jelly

dIon Gillard — Jelly: Executable XML Page 28


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – thread
ƒ Creates a new thread and runs its body on that
thread
ƒ Output can be to XMLOutput, file, or inherited
ƒ All the usual threading issues apply
ƒ Script finishes when the threads are completed

dIon Gillard — Jelly: Executable XML Page 29


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – thread Example


<set var="start" value="5" />
<thread>
<while test="${start != 10}">
start is ${start}
<set var="start" value="${start + 1}"/>
</while>
<new var="end" className="java.util.Date"/>
Thread ended at ${end}
</thread>
<new var="now" className="java.util.Date"/>
Done ${now}

Demo: core13.jelly

dIon Gillard — Jelly: Executable XML Page 30


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – useBean
ƒ Create a bean of the given class
ƒ Convert XML attributes into bean properties
and call the setters
ƒ Make it available as a variable
ƒ <useBean var=”name” class=”fullName”
property1=”value” property2=”value”/>

dIon Gillard — Jelly: Executable XML Page 31


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – useBean Example


<new var="dimension"
className="java.awt.Dimension">
<arg type="int" value="320"/>
<arg type="int" value="240"/>
</new>

<useBean var="frame"
class="javax.swing.JFrame" title="My Frame" />
${frame.setSize(dimension)}
<setProperties object="${frame}"
visible="true"/>

Demo: core14.jelly

dIon Gillard — Jelly: Executable XML Page 32


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – useList
ƒ Create a new list and populate it from the given
items
ƒ <useList var=”name” items=”${expr}”/>

<useList var="myList"
items="${systemScope.keySet()}" />
list is '${myList}'

Demo: core15.jelly

dIon Gillard — Jelly: Executable XML Page 33


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – include and import


ƒ Import or Include a script into the current
one using a URI or file
ƒ Include inherits values from the parent, and
can export back if required
ƒ Import by default doesn't inherit and can't export
ƒ <import inherit=”true/false” file=”${name}”
uri=”${name}”>
ƒ <include export=”true/false” ...>
Demo: importInclude.jelly

dIon Gillard — Jelly: Executable XML Page 34


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core - file
ƒ Write the tag body to a file, or variable
<file name=”${fileName}”
omitXmlDeclaration=”${bool}”
outputMode=”XML/HTML” prettyPrint=”${bool}”
encoding=”${value}” var=”alternateVariable”
escapeText=”${bool}”>
...
</file>

Demo: core16.jelly

dIon Gillard — Jelly: Executable XML Page 35


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – file Example

<file name="${systemScope['user.home']}
/temp.jelly" omitXmlDeclaration="true">
When you hear the air attack warning...
</file>

dIon Gillard — Jelly: Executable XML Page 36


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – remove, expr, scope


ƒ Remove
¾ Removes a variable from the current scope
¾ <remove var=”name”/>
ƒ Expr
¾ Evaluates an expression
¾ <expr value=”${someExpression}”/>
ƒ Scope
¾ Sets up a new scope that won't affect current variables

Demo: scope.jelly

dIon Gillard — Jelly: Executable XML Page 37


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Core – jelly and whitespace


ƒ <jelly>...</jelly>
¾Runs it's body
ƒ <whitespace trim=”${bool}”>
...</whitespace>
¾Container to allow fine grained control over
whitespace

dIon Gillard — Jelly: Executable XML Page 38


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 39


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Other TagLibraries
ƒ Ant – allows ant tasks to be invoked from Jelly
ƒ Antlr – Generate code from antlr grammars
ƒ Avalon – An Avalon-based service to run scripts
ƒ Bean – map tags to beans like Ant does
ƒ BeanShell – runs beanshell scripts
ƒ Betwixt – turn beans into XML and XML into beans

dIon Gillard — Jelly: Executable XML Page 40


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Other TagLibraries (Continued)


ƒ BSF – run any BSF capable scripting language
from Jelly
ƒ Define – define new tag libraries and tags via
jelly tags
ƒ DynaBean – tags to define, create and
manipulate dyna beans
ƒ Email – send emails
ƒ Fmt – jstl format tag library

dIon Gillard — Jelly: Executable XML Page 41


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Other TagLibraries (Continued)


ƒ Html – parse possibly badly formatted HTML
as XML
ƒ Http – perform common HTTP protocol actions
ƒ Interaction – prompt the user and get replies
ƒ Jetty – manipulate a jetty instance, process
requests via Jelly
ƒ JMS – work with messages
ƒ JSL – simplified stylesheet processing using objects

dIon Gillard — Jelly: Executable XML Page 42


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Other TagLibraries (Continued)


ƒ Junit – write unit tests as jelly scripts
ƒ Log – wrapper for commons logging
ƒ Ojb – store objects in OJB
ƒ Quartz – cron like scheduling via scripts
ƒ Soap – Invoke a web service
ƒ SQL – JSTL. Create transactions, run queries,
process result sets, update data
ƒ Swing – build UI via tags

dIon Gillard — Jelly: Executable XML Page 43


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Other TagLibraries (Continued)


ƒ Swt – build eclipse style UI via tags
ƒ Threads – coordinate across threads
ƒ Util – miscellaneous extras
ƒ Validate – validate XML docs
ƒ Velocity – run velocity templates in Jelly
ƒ Xml – parse, sort, use xpath for if, transform and
loop through XML docs
ƒ Xmlunit – unit test XML document content

dIon Gillard — Jelly: Executable XML Page 44


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Ant Tag Library


ƒ Any ant task typedef can be used except
those that rely on build.xml
ƒ Use xmlns:ant=”jelly:ant”
ƒ Place the commons-jelly-tags-ant-XXX.jar in
the classpath, along with commons-grant.jar,
ant.jar and ant-optional.jar
ƒ Tags provided: ant, fileScanner, setProperty

dIon Gillard — Jelly: Executable XML Page 45


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Ant Tag Library (Continued)


<fileScanner var="scripts">
<fileset dir="C:/source/css/css2003">
<include name="*.jelly"/>
</fileset>
</fileScanner>

<j:forEach var="script"
items="${scripts.iterator()}" trim="yes">
<echo>script is ${script}</echo>
</j:forEach>

Demo: ant1.jelly

dIon Gillard — Jelly: Executable XML Page 46


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Ant Tag Library – setProperty


ƒ Sets a property on an Ant task if the value is not
null.
<ant:javadoc....>
<!-- allow custom doclets -->
<j:if test="${context.getVariable('maven.javadoc.
doclet') != null}">
<ant:setProperty name="doclet"
value="${maven.javadoc.doclet}" />
</j:if>
</ant:javadoc>

dIon Gillard — Jelly: Executable XML Page 47


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib
ƒ Parse
¾ <x:parse var=”name”
xml=”${uriFileReaderOrInputStream}”/>
¾ ${name} is now a Dom4J Document
¾ xmlns:x="jelly:xml"
¾ Need taglib jar available
ƒ Other Sessions:
¾ Bonnie B. Ricca “XSLT 2.0: Not Your Mothers XSLT”

dIon Gillard — Jelly: Executable XML Page 48


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib – parse Example


<x:parse var="doc">
<document>
<properties><title>Doc Title</title></properties>
<body>
<section>Hello World</section>
</body>
</document>
</x:parse>
Title was '<x:expr select="$doc/document/properties/title"/>'
Section was '<x:expr select="$doc/document/body/section"/>'
Demo: xml1.jelly, xml2.jelly

dIon Gillard — Jelly: Executable XML Page 49


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib – if Example


<x:if select="$doc/document/body/section[@name =
'fred']">
found section fred
</x:if>

ƒ Allows logic to use xpath queries on an XML


document to drive processing

Demo: xml3.jelly

dIon Gillard — Jelly: Executable XML Page 50


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib – forEach Example


<x:forEach var="name" select="$doc/document/body/section/@name"
trim="no">
Section name is ${name.text}
</x:forEach>

ƒ Loop through XML documents processing


nodes as needed.
ƒ Similar to forEach, except nodeset comes
from xpath
Demo: xml5.jelly

dIon Gillard — Jelly: Executable XML Page 51


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib – sort Example


<x:set var="sections" select="$doc/document/body/section" />
<x:sort list="${sections}" sort="./@name" descending="false" />
<j:forEach var="name" items="${sections}">
Section name is ${name.text}
</j:forEach>

ƒ Data can be easily sorted before output

Demo: xml4.jelly, xml6.jelly

dIon Gillard — Jelly: Executable XML Page 52


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

XML Taglib – set Example


<x:set var="name"
select="string($doc/document/body/section/@name)"/>
Name is ${name}

ƒ Variables can be set based on the result of an


xpath expression

Demo: xml4.jelly, xml7.jelly

dIon Gillard — Jelly: Executable XML Page 53


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

SQL Taglib
ƒ Allows processing of SQL queries
ƒ Transformation into XML/HTML easily
ƒ Based on the JSTL taglib
ƒ Tags provided
¾ Transaction, driver, query, update, resultSet, row,
dataSource

dIon Gillard — Jelly: Executable XML Page 54


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

SQL Taglib – Example


<sql:setDataSource
url="jdbc:db2:SAMPLE"
driver="COM.ibm.db2...."
user="db2admin"
password="db2admin"/>

<sql:query var="results">
select * from ${databaseTable}
</sql:query>

Demo: sql1.jelly

dIon Gillard — Jelly: Executable XML Page 55


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

SQL Taglib – Example (Continued)


<j:forEach items="${results.rowsByIndex}"
var="row">
<j:forEach var="columnName"
items="${results.columnNames}" indexVar="i">
${columnName} = ${row[i]}
</j:forEach>

</j:forEach>

Demo: sql2.jelly, sql3.jelly, sql4.jelly

dIon Gillard — Jelly: Executable XML Page 56


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Util Taglib
ƒ Miscellaneous utility tags
ƒ <util:available file=”${fileName}”
uri=”relativePath”>...</util:available>
ƒ <util:loadText var=”name” file=”${fileName}”
uri=”relativePath” />
ƒ <util:tokenize var=”name”
delim=”${char}”>${stringContent}</util:tokenize>

Demo: util1.jelly

dIon Gillard — Jelly: Executable XML Page 57


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Util Taglib (Continued)

ƒ <util:file var=”name” name=”${fileName}”/>


ƒ <util:properties var=”name”
file=”${fileName}” uri=”relativePath” />
ƒ <util:replace var=”name” oldChar=”\”
newChar=”/” value=”${someString}”/>

dIon Gillard — Jelly: Executable XML Page 58


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

User Interfaces
ƒ Jelly comes with both a Swing and SWT tag library
ƒ This allows the UI to be specified in XML
ƒ It's not XUL

Demo: swing/ maven demo:swing, swt/ maven demo

dIon Gillard — Jelly: Executable XML Page 59


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 60


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Scripting Languages
ƒ XML is often unwieldy
ƒ Code can be far more compact and
expressive, but is difficult to generate
ƒ As a scripting language itself, Jelly is unusual
in that it lets you load and run scripts for
other languages within a script

dIon Gillard — Jelly: Executable XML Page 61


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Scripting – BeanShell
ƒ BeanShell tag library
ƒ Need bean shell jars
ƒ Use xmlns:bsh="jelly:beanshell"
<bsh:script>
Properties sysprops =
System.getProperties();
System.out.println("-testsysprop =
" + sysprops.get("testsysprop"));
</bsh:script>

dIon Gillard — Jelly: Executable XML Page 62


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Scripting – BSF
ƒ Ex-IBM Bean Scripting Framework
ƒ Need BSF jars
ƒ Use xmlns:javascript="jelly:javascript”
ƒ Provides Jython, Pnuts, JavaScript
ƒ Registers Jelly Context with BSF Manager
ƒ Expressions are passed through to BSF to manage

dIon Gillard — Jelly: Executable XML Page 63


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Scripting – BSF (Continued)

ƒ JavaScript samples are currently broken in Jelly


<j:jelly xmlns="jelly:javascript" xmlns:j="jelly:core"
trim="no">
<script>
var result = 0
for (var i = 0; i != 10; i++) {
result += i;
}
</script>

dIon Gillard — Jelly: Executable XML Page 64


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Agenda
ƒ What is Jelly?
ƒ Anatomy of a Jelly script
ƒ Jelly 'Core' Tag Library
ƒ Other supplied tag libraries
ƒ Scripting languages in Jelly
ƒ Embedding Jelly

dIon Gillard — Jelly: Executable XML Page 65


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Embedding Jelly
ƒ Where is the output to go?
ƒ What variables do you want available to the script?
ƒ Set up XMLOutput
ƒ Run the script
ƒ What do you want to do with the output?

dIon Gillard — Jelly: Executable XML Page 66


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Embedding Jelly – Sample


OutputStream output = new FileOutputStream("output.xml");
JellyContext context = new JellyContext();
// populate it
context.setVariable("bean1", myApp.getData());
// create XMLOutput
XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
// run the script specified
context.runScript(scriptFileName, xmlOutput);
xmlOutput.flush();
output.close();

dIon Gillard — Jelly: Executable XML Page 67


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Embedding Jelly – Misc


ƒ Need Jelly Core as a minimum dependency
ƒ Other taglibs as required
ƒ Running scripts gives users more control
ƒ They will do things you didn't plan on
ƒ Jelly is good at swallowing exceptions :-(
ƒ What do you do with the output
ƒ How do you tell the user of script results, etc.

dIon Gillard — Jelly: Executable XML Page 68


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Summary
ƒ XML based scripting
ƒ Large tag library support
ƒ Based on JSTL / JSP
ƒ XML can be intermixed with Java and tags
to produce output

dIon Gillard — Jelly: Executable XML Page 69


Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.

Resources
ƒ http://jakarta.apache.org/commons/jelly/
ƒ http://jakarta.apache.org/commons/jexl/
ƒ http://cocoon.apache.org/
ƒ http://maven.apache.org/
ƒ dion@multitask.com.au

dIon Gillard — Jelly: Executable XML Page 70

You might also like