jelly: executable xml
TRANSCRIPT
![Page 1: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/1.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 1
Jelly: Executable XMLdIon GillardMultitask Consulting Pty. Ltd.
![Page 2: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/2.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 2
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 3: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/3.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 3
What Is Jelly?Java and XML based scripting engineExecutes XML and produces XML, HTML, etc.Front end to other XML tools such as AntBorrows heavily from JSP and JSTLComes with many tag libraries for common tasksUses Jexl for expression supportExtensible via Java or Jelly tag libraries
![Page 4: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/4.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 4
Jelly Architecture
Context
ScriptTags
XMLParser
TagLibrary
XMLOutput
![Page 5: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/5.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 5
Key classesXMLParser
Takes XML document and creates a script
ContextVariables available to the Jelly script at run time
ScriptExecutable 'code' made up of text and tags
TagLibraryGroup of tags with a registered name
![Page 6: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/6.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 6
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 7: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/7.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 7
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
![Page 8: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/8.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 8
Jelly Script – DetailsIt's an XML DocumentNamespaces used to refer to tag librariesText is passed straight throughTrimming? (Sample 1)Encoding? (Sample 2)jelly:core where is that defined?
![Page 9: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/9.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 9
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
![Page 10: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/10.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 10
Jelly Script – variables (Continued)
Default namespaceforEach from core tag librarysystemScope predefined variableAccessing iterators and objectsText output formatting
![Page 11: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/11.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 11
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 12: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/12.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 12
Core TagLibraryJelly was originally one big jar with all the tag libraries includedToo 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
![Page 13: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/13.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 13
Core TagLibrary vs. OthersThese 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
![Page 14: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/14.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 14
Core – set
<j:set var=”name” value=”${expr}”/>Or <j:set var=”name”>${stringExpr}</j:set>
Assignment operatorNot like Ant propertiesvalue can be any jexl expression
![Page 15: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/15.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 15
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
![Page 16: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/16.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 16
Core – if<if test=”${booleanExpr}”>...more tags...
</if>Evaluates its body if the expression is trueNo else tag!operators supported >, >=, <, <=, !
![Page 17: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/17.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 17
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
![Page 18: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/18.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 18
Core – forEachYou've seen it in actionThe 'for loop' for jelly
<forEach var=”item” items=”${expr}”indexVar=”counter” begin=”number”end=”number” step=”number”>...statements...
</forEach>
![Page 19: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/19.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 19
Core – newCreate 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 classpathThis is very different to Ant's <property/>Arguments can be passed to the constructor using <arg>
Demo: core4.jelly
![Page 20: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/20.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 20
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
![Page 21: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/21.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 21
Core – invoke and catchInvoke a method on an objectCan take nested <arg>s like new
<invoke var=”result” method=”name”on=”object”/>
Exception handling? <catch var=”e”>...
</catch>
![Page 22: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/22.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 22
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
![Page 23: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/23.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 23
Core – switchSwitch, case, default from Java
<switch on=”${expr}”>
<case value=”${otherExpr}”>
...
</case>
<default>
...
</default>
</switch>
Demo: core8.jelly
![Page 24: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/24.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 24
Core – switch Example<set var="lookingFor" value="dion" /><switch on="${systemScope['user.name']}"><case value="${lookingFor}">Gotcha
</case><default>Imposter!
</default></switch>
![Page 25: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/25.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 25
Core – chooseSimilar to switch, but not necessarily on a single value
<choose>
<when test=”${booleanExpr}”>
...
</when>
<otherwise></otherwise>
</choose>
Demo: core9.jelly, core10.jelly
![Page 26: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/26.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 26
Core – choose Example<set var="lookingFor" value="dion" /><choose>
<when test="${systemScope['user.name'] == lookingFor}">
Gotcha</when><otherwise>
Imposter!</otherwise>
</choose>
![Page 27: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/27.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 27
Core – whileWhile 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
![Page 28: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/28.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 28
Core – breakBreaks 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
![Page 29: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/29.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 29
Core – threadCreates a new thread and runs its body on that threadOutput can be to XMLOutput, file, or inheritedAll the usual threading issues applyScript finishes when the threads are completed
![Page 30: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/30.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 30
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
![Page 31: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/31.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 31
Core – useBeanCreate a bean of the given classConvert XML attributes into bean properties and call the settersMake it available as a variable
<useBean var=”name” class=”fullName”property1=”value” property2=”value”/>
![Page 32: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/32.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 32
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
![Page 33: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/33.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 33
Core – useListCreate 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
![Page 34: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/34.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 34
Core – include and importImport or Include a script into the current one using a URI or fileInclude inherits values from the parent, and can export back if requiredImport by default doesn't inherit and can't export
<import inherit=”true/false” file=”${name}”uri=”${name}”><include export=”true/false” ...>
Demo: importInclude.jelly
![Page 35: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/35.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 35
Core - fileWrite 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
![Page 36: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/36.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 36
Core – file Example
<file name="${systemScope['user.home']}/temp.jelly" omitXmlDeclaration="true">When you hear the air attack warning...
</file>
![Page 37: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/37.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 37
Core – remove, expr, scopeRemove
Removes a variable from the current scope<remove var=”name”/>
Expr Evaluates an expression<expr value=”${someExpression}”/>
ScopeSets up a new scope that won't affect current variables
Demo: scope.jelly
![Page 38: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/38.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 38
Core – jelly and whitespace<jelly>...</jelly>
Runs it's body
<whitespace trim=”${bool}”> ...</whitespace>
Container to allow fine grained control over whitespace
![Page 39: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/39.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 39
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 40: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/40.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 40
Other TagLibrariesAnt – allows ant tasks to be invoked from JellyAntlr – Generate code from antlr grammarsAvalon – An Avalon-based service to run scriptsBean – map tags to beans like Ant doesBeanShell – runs beanshell scriptsBetwixt – turn beans into XML and XML into beans
![Page 41: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/41.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 41
Other TagLibraries (Continued)
BSF – run any BSF capable scripting language from JellyDefine – define new tag libraries and tags via jelly tagsDynaBean – tags to define, create and manipulate dyna beansEmail – send emailsFmt – jstl format tag library
![Page 42: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/42.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 42
Other TagLibraries (Continued)
Html – parse possibly badly formatted HTML as XMLHttp – perform common HTTP protocol actions Interaction – prompt the user and get replies
Jetty – manipulate a jetty instance, process requests via JellyJMS – work with messagesJSL – simplified stylesheet processing using objects
![Page 43: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/43.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 43
Other TagLibraries (Continued)
Junit – write unit tests as jelly scriptsLog – wrapper for commons loggingOjb – store objects in OJBQuartz – cron like scheduling via scriptsSoap – Invoke a web service
SQL – JSTL. Create transactions, run queries, process result sets, update dataSwing – build UI via tags
![Page 44: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/44.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 44
Other TagLibraries (Continued)
Swt – build eclipse style UI via tagsThreads – coordinate across threadsUtil – miscellaneous extrasValidate – validate XML docsVelocity – run velocity templates in Jelly
Xml – parse, sort, use xpath for if, transform and loop through XML docsXmlunit – unit test XML document content
![Page 45: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/45.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 45
Ant Tag LibraryAny ant task typedef can be used except those that rely on build.xmlUse 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.jarTags provided: ant, fileScanner, setProperty
![Page 46: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/46.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 46
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
![Page 47: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/47.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 47
Ant Tag Library – setPropertySets 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>
![Page 48: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/48.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 48
XML TaglibParse
<x:parse var=”name”xml=”${uriFileReaderOrInputStream}”/>${name} is now a Dom4J Documentxmlns:x="jelly:xml"Need taglib jar available
Other Sessions:Bonnie B. Ricca “XSLT 2.0: Not Your Mothers XSLT”
![Page 49: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/49.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 49
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
![Page 50: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/50.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 50
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
![Page 51: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/51.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 51
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
![Page 52: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/52.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 52
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
![Page 53: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/53.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 53
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
![Page 54: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/54.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 54
SQL TaglibAllows processing of SQL queriesTransformation into XML/HTML easilyBased on the JSTL taglibTags provided
Transaction, driver, query, update, resultSet, row, dataSource
![Page 55: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/55.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 55
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
![Page 56: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/56.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 56
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
![Page 57: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/57.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 57
Util TaglibMiscellaneous 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
![Page 58: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/58.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 58
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}”/>
![Page 59: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/59.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 59
User InterfacesJelly comes with both a Swing and SWT tag libraryThis allows the UI to be specified in XMLIt's not XUL
Demo: swing/ maven demo:swing, swt/ maven demo
![Page 60: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/60.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 60
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 61: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/61.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 61
Scripting LanguagesXML is often unwieldyCode can be far more compact and expressive, but is difficult to generateAs a scripting language itself, Jelly is unusual in that it lets you load and run scripts for other languages within a script
![Page 62: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/62.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 62
Scripting – BeanShellBeanShell tag libraryNeed bean shell jarsUse xmlns:bsh="jelly:beanshell"<bsh:script>
Properties sysprops = System.getProperties();
System.out.println("-testsysprop = " + sysprops.get("testsysprop"));</bsh:script>
![Page 63: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/63.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 63
Scripting – BSFEx-IBM Bean Scripting FrameworkNeed BSF jarsUse xmlns:javascript="jelly:javascript”Provides Jython, Pnuts, JavaScriptRegisters Jelly Context with BSF ManagerExpressions are passed through to BSF to manage
![Page 64: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/64.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 64
Scripting – BSF (Continued)
JavaScript samples are currently broken in Jelly<j:jelly xmlns="jelly:javascript" xmlns:j="jelly:core"
trim="no"><script>var result = 0for (var i = 0; i != 10; i++) {
result += i; }
</script>
![Page 65: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/65.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 65
AgendaWhat is Jelly?Anatomy of a Jelly scriptJelly 'Core' Tag LibraryOther supplied tag librariesScripting languages in JellyEmbedding Jelly
![Page 66: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/66.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 66
Embedding JellyWhere is the output to go?What variables do you want available to the script?Set up XMLOutputRun the scriptWhat do you want to do with the output?
![Page 67: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/67.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 67
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();
![Page 68: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/68.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 68
Embedding Jelly – Misc
Need Jelly Core as a minimum dependencyOther taglibs as requiredRunning scripts gives users more controlThey will do things you didn't plan onJelly is good at swallowing exceptions :-(What do you do with the outputHow do you tell the user of script results, etc.
![Page 69: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/69.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 69
SummaryXML based scriptingLarge tag library supportBased on JSTL / JSPXML can be intermixed with Java and tags to produce output
![Page 70: Jelly: Executable XML](https://reader037.vdocuments.net/reader037/viewer/2022110220/586a3b5f1a28abfc718b9458/html5/thumbnails/70.jpg)
Colorado Software Summit: October 26 – 31, 2003 © Copyright 2003, Multitask Consulting Pty. Ltd.
dIon Gillard — Jelly: Executable XML Page 70
Resourceshttp://jakarta.apache.org/commons/jelly/http://jakarta.apache.org/commons/jexl/http://cocoon.apache.org/http://maven.apache.org/[email protected]