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, 21 Oct 2002 12:02:56 GMT
jstrachan    2002/10/21 05:02:56

  Modified:    jelly/xdocs tutorial.xml
  Log:
  Applied Ted's latest patches for the tutorial
  
  Revision  Changes    Path
  1.4       +64 -13    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- tutorial.xml	18 Oct 2002 00:34:05 -0000	1.3
  +++ tutorial.xml	21 Oct 2002 12:02:55 -0000	1.4
  @@ -89,7 +89,7 @@
   
   <p>
   To run the swing demo type "maven demo:swing"
  -(View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/swing/example.jelly?rev=HEAD">demo
script</a>). You should see a window open with
  +(View the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/swing/example.jelly?rev=HEAD&amp;content-type=text/vnd.viewcvs-markup">demo
script</a>). You should see a window open with
   some swing components. You can test the actions by selecting a menu item or
   pressing the button. The actions in this demo simply output a message to the
   console. A more practical action could be to invoke a bean, call a script
  @@ -97,7 +97,7 @@
   </p>
   
   <p>
  -If you look at the jelly code for this demo (link to the code), you will see
  +If you look at the <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/swing/example.jelly?rev=HEAD&amp;content-type=text/vnd.viewcvs-markup">jelly
code for this demo</a>, you will see
   that building a UI is pretty simple. For example, a menu bar is simply:
   </p>
   
  @@ -141,11 +141,11 @@
   <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
  +The Jelly Runner is a JellySwing interface that lets you run other Jelly scripts. Just
select a file in the file dialog 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>).
  +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&amp;content-type=text/vnd.viewcvs-markup">demo
source</a>).
   </p>
   
   </subsection>
  @@ -153,7 +153,7 @@
   <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>).
  +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&amp;content-type=text/vnd.viewcvs-markup">demo
source</a>).
   </p>
   
   <p>
  @@ -195,7 +195,11 @@
   </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.
  +This example is another "Home Page Builder". Previously, we used JellySwing to create the
Home Page Builder. This time we will create the Swing controls in Java and only use Jelly
to output the HTML.
  +</p>
  +
  +<p>
  +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>
  @@ -209,9 +213,17 @@
   <pre>
       OutputStream output = new FileOutputStream("demopage.html");
       JellyContext context = new JellyContext();
  -        context.setVariable("name",nameField.getText());
   
  -        //...set other context variables
  +        context.setVariable("<b>name</b>",nameField.getText());
  +        context.setVariable("<b>background</b>",colorField.getText());
  +        context.setVariable("<b>url</b>",urlField.getText());
  +          // Set the hobby list
  +        Vector v = new Vector();
  +        Enumeration enum= listModel.elements();
  +        while (enum.hasMoreElements()) {
  +            v.add(enum.nextElement());
  +        }
  +        context.setVariable("<b>hobbies</b>", v);
   
       XMLOutput xmlOutput = XMLOutput.createXMLOutput(output);
       context.runScript("src/test/org/apache/commons/jelly/demos/"+template), xmlOutput);
  @@ -219,11 +231,36 @@
   </pre>
   
   <p>
  +The Jelly template looks like this:
  +</p>
  +
  +<pre>
  +&lt;?xml version="1.0"?&gt;
  +&lt;j:jelly trim="false" xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:html="jelly:html"&gt;
  +  &lt;html&gt;
  +    &lt;head&gt;
  +    &lt;title&gt;${<b>name</b>}'s Page&lt;/title&gt;
  +    &lt;/head&gt;
  +    &lt;body bgcolor="${<b>background</b>}" text="#FFFFFF"&gt;
  +    &lt;h1&gt;${<b>name</b>}'s Homepage&lt;/h1&gt;
  +    &lt;img src="${<b>url</b>}"/&gt;
  +    &lt;h2&gt;My Hobbies&lt;/h2&gt;
  +    &lt;ul&gt;
  +    &lt;j:forEach items="${<b>hobbies</b>}" var="i"&gt;
  +        &lt;li&gt;${i}&lt;/li&gt;
  +    &lt;/j:forEach&gt;
  +    &lt;/ul&gt;
  +    &lt;/body&gt;
  +  &lt;/html&gt;
  +&lt;/j:jelly&gt;
  +</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).
  +After you have explored this demo and its implementation, you may want to compare it with
the same example implemented using the JellySwing library, above (if you haven't already done
so).
   </p>
   
   </section>
  @@ -233,15 +270,29 @@
   <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.
  +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&amp;content-type=text/vnd.viewcvs-markup">demo
source</a>). The demo transforms the demo source into HTML and ouputs it to the command
line, like this:
   </p>
   
  +<pre>
  +&lt;html&gt;
  +&lt;body&gt;
  +&lt;h1&gt;Output&lt;/h1&gt;
  +&lt;small&gt;James Elson&lt;h2&gt;I am a title!&lt;/h2&gt;
  +&lt;small&gt;Twas a dark, rainy night...&lt;/small&gt;&lt;p&gt;dfjsdfjsdf&lt;/p&gt;&lt;p&gt;fdsfsdfhdsff
gyuf uysgf ds&lt;/p&gt;&lt;/small&gt;
  +&lt;/body&gt;
  +&lt;/html&gt;
  +</pre>
  +
   <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>).
  +Of course, this HTML could just as easly be going to a file or out to a browser in a HTTP
response.
   </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.
  +If you look at the <a href="tags.html#jelly:jsl">JSL tag library</a> documentation,
you'll see that the JSL taglib consists of a mere four tags: style, template, stylesheet,
and applyTemplates. Since many of the standard XSLT tags are already part of other Jelly taglibs,
such as forEach and choose, these are the only others we really need. Moreover, much of the
power of XSLT comes with using XPath expressions, which are natively supported by Jelly.
   </p>
   
   <p>
  @@ -259,7 +310,7 @@
   </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>).
  +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&amp;content-type=text/vnd.viewcvs-markup">demo
source</a>).
   </p>
   
   <p>
  
  
  

--
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