commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/xdocs tutorial.xml
Date Mon, 30 Sep 2002 07:31:57 GMT
jstrachan    2002/09/30 00:31:56

  Modified:    jelly/xdocs tutorial.xml
  Log:
  Added Otto's new addtions to the tutorials
  
  Revision  Changes    Path
  1.2       +137 -9    jakarta-commons-sandbox/jelly/xdocs/tutorial.xml
  
  Index: tutorial.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/xdocs/tutorial.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- tutorial.xml	20 Sep 2002 13:44:38 -0000	1.1
  +++ tutorial.xml	30 Sep 2002 07:31:56 -0000	1.2
  @@ -3,13 +3,13 @@
   <document>
   
    <properties>
  -  <title>Jelly Tutorials</title>
  +  <title>Jelly Tutorial</title>
     <author email="vonwao@yahoo.com">Otto von Wachter</author>
    </properties>
   
   <body>
   
  -<section name="Jelly Tutorials">
  +<section name="Jelly Tutorial">
   
   <p>
   The best way to get acquainted with Jelly, and get an idea what it can be
  @@ -19,11 +19,12 @@
   </p>
   
   <p>
  -Before going any further it might be worth checking out the <a href="gettingstarted.html">Getting
Started</a> guide.
  +Before going any further it might be worth checking out the 
  +<a href="gettingstarted.html">Getting Started</a> guide.
   </p>
   
   <p>
  -The goal of the tutorials is to guide you through running some of the Jelly
  +The goal of the tutorial is to guide you through running some of the Jelly
   demos and give you some ideas of other potential uses of Jelly (and
   hopefully make your first experience with Jelly enjoyable and fun).
   </p>
  @@ -50,17 +51,26 @@
   </p>
   <ul>
   <li>
  -<a href="#jellyswing">JellySwing Demo</a>
  +<a href="#jellyswing">JellySwing</a>
  +</li>
  +<li>
  +<a href="#embeddingjelly">Embedding Jelly</a>
  +</li>
  +<li>
  +<a href="#jsl">Transforming XML with JSL</a>
  +</li>
  +<li>
  +<a href="#html">Parsing HTML</a>
   </li>
   </ul>
   <br/>
   
   <a name="jellyswing"/>
  -<section name="JellySwing Demo">
  +<section name="JellySwing">
   
   
   <p>
  -This demo shows how you can use Jelly (using the <a href="tags.html#jelly:jellyswing">JellySwing</a>
library) to build the UI for a Swing java program.
  +The JellySwing demo shows how you can use Jelly (using the <a href="tags.html#jelly:jellyswing">JellySwing</a>
library) to build the UI for a Swing java program.
   </p>
   
   <p>
  @@ -127,9 +137,36 @@
   Jelly, can be written in java and added by this method.
   </p>
   
  -</section>
   
  -<section name="Other Ideas for JellySwing">
  +<subsection name="Jelly Runner">
  +
  +<p>
  +The Jelly Runner is a JellySwing interface that lets you run other Jelly scripts. Just
select a file in the file dialod and click the Run Script button
  +</p>
  +
  +<p>
  +To start the JellyRunner type "maven jelly:runner" (View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/swing/run.jelly?rev=HEAD">demo
source</a>).
  +</p>
  +
  +</subsection>
  +
  +<subsection name="Homepage Builder (JellySwing Edition)">
  +
  +<p>
  +This is a good chance to use the Jelly Runner. Find HomepageBuilder.jelly, which is located
in /src/test/org/apache/commons/jelly/demos/ (View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/demos/HomepageBuilder.jelly?rev=HEAD">demo
source</a>).
  +</p>
  +
  +<p>
  +As you can see, the HomepageBuilder is a (mini) fully-functional swing application, and
it's entirely written in Jelly!  This example uses Jelly on two levels: 1) For the actual
application/UI and 2) As a templating engine to build homepages.This shows how you can use
different taglibs together to build sophisticated applications.
  +</p>
  +
  +<p>
  +See the section on Embedding Jelly to find out more about the Homepage Builder demo. This
is also a good way to compare a Java implementation (HomepageBuilder.java) with a Jelly implementation
(HomepageBuilder.jelly). 
  +</p>
  +
  +</subsection>
  +
  +<subsection name="Other Ideas for JellySwing">
   
   <ul>
   <li>
  @@ -145,6 +182,97 @@
   can be downloaded from a web server at runtime. In some applications, this would provide
a lot of flexibility.
   </li>
   </ul>
  +
  +</subsection>
  +
  +</section>
  +
  +<a name="embeddingjelly"/>
  +<section name="Embedding Jelly">
  +
  +<p>
  +There are cases where you may want to execute Jelly scripts from within a java program
(as opposed to doing it from Maven or the command line). This tutorial presents a simple example
of a program that does this.
  +</p>
  +
  +<p>
  +This example is a "Home Page Builder". When you run the program, it will open a window
where you can choose a template, and specify a few paramters. Then you simply click on "build
page" and voila, your home page is generated by Jelly.
  +</p>
  +
  +<p>
  +To run the demo type "maven demo:embed" (View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/demos/HomepageBuilder.java?rev=HEAD">demo
source</a>).
  +</p>
  +
  +<p>
  +The code that actually runs Jelly is the following. 
  +</p>
  +
  +<pre>
  +	OutputStream output = new FileOutputStream("demopage.html");
  +	JellyContext context = new JellyContext();
  +        context.setVariable("name",nameField.getText());
  +        
  +        //...set other context variables
  +	
  +	XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
  +	context.runScript("src/test/org/apache/commons/jelly/demos/"+template), xmlOutput);
  +        xmlOutput.flush();
  +</pre>
  +
  +<p>
  +As you can see, it's pretty straighforward to call a Jelly script programatically. First
you need a context to run the script in. You can think of the context as the "environment"
in which the script runs. The script can use and modify variables in the context however it
wishes. Then you need an XML output stream where the output of the script will be sent. In
some cases, like this one, the XML output is the essential product of the script. In other
cases, it may just be a "byproduct" of running the script, used for logging, etc. This is
the case when you are running a maven build, for example.
  +</p>
  +
  +<p>
  +After you have explored this demo and its implementation, you may want to look at this
same example implemented using the JellySwing library, above (if you haven't already done
so).
  +</p>
  +
  +</section>
  +
  +<a name="jsl"/>
  +
  +<section name="Transforming XML With JSL">
  +
  +<p>
  +With the <A HREF="tags.html#jelly:jsl">JSL tag library</A>, you can transform
XML documents in an XSLT-like manner.
  +</p>
  +
  +<p>
  +To run the demo type "maven demo:jsl" (View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/example.jelly?rev=HEAD">demo
source</a>).
  +</p>
  +
  +<p>
  +If you look at the documentation (link above), you'll see that the JSL taglib consists
of a mere four tags, but these provide the main functionality needed (many of the standar
XSLT tags are already part of other Jelly taglibs, such as forEach and choose). Additionally,
much of the power of XSLT comes with using XPath expressions, which are natively suported
by Jelly.
  +</p>
  +
  +<p>
  +There are many good books and tutorials on XSLT, and since the concepts are the same, I
won't waste Jelly documentation space and time on this subject. 
  +</p>
  +
  +
  +</section>
  +
  +<a name="html"/>
  +<section name="Parsing HTML">
  +
  +<p>
  +This demo demonstrates the use the handy parse tag in the <A HREF="tags.html#jelly:html">HTML
tag library</A>
  +</p>
  +
  +<p>
  +To run the demo type "maven demo:html" (View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/html/example.jelly?rev=HEAD">demo
source</a>).
  +</p>
  +
  +<p>
  +As you can see in the demo script, parsing an HTML file is simple: 
  +</p>
  +
  +<pre>
  +	&lt;html:parse var="doc" html="index.html"/&gt;	
  +</pre>
  +
  +<p>
  +Once you have parsed the document you can treat it the same way as a parsed XML document,
i.e. applying JSL transformations, querying the document with XPath expressions, and so on.
  +</p>
   
   </section>
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message