You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by wg...@apache.org on 2005/01/17 01:31:00 UTC

svn commit: r125378 - in jakarta/velocity/trunk: docs src/java/org/apache/velocity/anakia src/java/org/apache/velocity/test test/anakia/compare test/anakia/xdocs test/anakia/xdocs/stylesheets xdocs

Author: wglass
Date: Sun Jan 16 16:30:59 2005
New Revision: 125378

URL: http://svn.apache.org/viewcvs?view=rev&rev=125378
Log:
added ability to create new references from additional xml files.  Many thanks to Peter Ryan for requesting the feature and writing the patch.
Added:
   jakarta/velocity/trunk/test/anakia/compare/index.context.html
   jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/customContext.xml
   jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site_contexts.vsl
Modified:
   jakarta/velocity/trunk/docs/anakia.html
   jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java
   jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java
   jakarta/velocity/trunk/test/anakia/compare/index.html
   jakarta/velocity/trunk/test/anakia/xdocs/index.xml
   jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl
   jakarta/velocity/trunk/xdocs/anakia.xml

Modified: jakarta/velocity/trunk/docs/anakia.html
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/docs/anakia.html?view=diff&rev=125378&p1=jakarta/velocity/trunk/docs/anakia.html&r1=125377&p2=jakarta/velocity/trunk/docs/anakia.html&r2=125378
==============================================================================
--- jakarta/velocity/trunk/docs/anakia.html	(original)
+++ jakarta/velocity/trunk/docs/anakia.html	Sun Jan 16 16:30:59 2005
@@ -1,8 +1,24 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
+<!--
+Copyright 1999-2004 The Apache Software Foundation
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+
 <!-- Content Stylesheet for Site -->
 
-        
+
 <!-- start the processing -->
     <!-- ====================================================================== -->
     <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
@@ -14,17 +30,17 @@
 
                                                     <meta name="author" value="Jon S. Stevens">
             <meta name="email" value="jon@latchkey.com">
-            
-           
-            
-            
-            
-            
-            
+
+
+
+
+
+
+
             <title>Velocity - Anakia</title>
         </head>
 
-        <body bgcolor="#ffffff" text="#000000" link="#525D76">        
+        <body bgcolor="#ffffff" text="#000000" link="#525D76">
             <table border="0" width="100%" cellspacing="0">
                 <!-- TOP IMAGE -->
                 <tr>
@@ -40,11 +56,11 @@
                 <tr><td colspan="2">
                     <hr noshade="" size="1"/>
                 </td></tr>
-                
+
                 <tr>
                     <!-- LEFT SIDE NAVIGATION -->
                     <td width="20%" valign="top" nowrap="true">
-                    
+
     <!-- ============================================================ -->
 
                 <p><strong>About</strong></p>
@@ -146,6 +162,7 @@
         </font>
       </td></tr>
       <tr><td>
+        <p>
         <blockquote>
                                     <p>
     Essentially an XML transformation tool, Anakia uses <a href="http://www.jdom.org">JDOM</a> and <a href="http://jakarta.apache.org/velocity">Velocity</a> to transform
@@ -155,15 +172,15 @@
     files.
 </p>
                                                 <p>
-   The basic model that AnakiaTask uses is pretty straightforward : 
+   The basic model that AnakiaTask uses is pretty straightforward :
    <ol>
    <li>Parse your XML into a JDOM Document:<br />
 <pre>SAXBuilder builder;
 Document root = null;
 
-try 
+try
 {
-    builder = new SAXBuilder( 
+    builder = new SAXBuilder(
         "org.apache.xerces.parsers.SAXParser" );
     root = builder.build( file );
 }
@@ -195,9 +212,9 @@
     Anakia -- intended to replace Stylebook, which was originally used
     to generate simple, static web sites in which all pages had the same
     look and feel -- is great for documentation/project web sites, such
-    as the sites on <a href="http://www.apache.org/">www.apache.org</a> 
-    and <a href="http://jakarta.apache.org">jakarta.apache.org</a>. As it 
-    is more targeted to a specific purpose, it does not provide some of 
+    as the sites on <a href="http://www.apache.org/">www.apache.org</a>
+    and <a href="http://jakarta.apache.org">jakarta.apache.org</a>. As it
+    is more targeted to a specific purpose, it does not provide some of
     XSL's "extra" functionality.
 </p>
                                                 <p>
@@ -208,17 +225,18 @@
                                                 <p>
     Anakia creates a Context, which contains a JDOM Document object of
     the .xml page, as well as an (optional) JDOM Document object of your
-    project.xml page. The .vsl page is executed (using Velocity) with
-    the Context. You can then navigate your .xml file and pull
-    information out of it by simply executing methods on the JDOM
-    Document object.
+    project.xml page. In addition to the project.xml based context, additional
+    xml contexts can be added through context nested elements. The
+    .vsl page is executed (using Velocity) with the Context. You can then
+    navigate your .xml file and pull information out of it by simply executing
+    methods on the JDOM Document object.
 </p>
                                                 <p>
     Anakia is being used to create the documentation for not only this
-    website, but also for the Jakarta Project's website as well as 
-    many of the projects that live under the Jakarta Project. This 
-    process is 
-    <a href="http://jakarta.apache.org/site/jakarta-site2.html">documented</a> 
+    website, but also for the Jakarta Project's website as well as
+    many of the projects that live under the Jakarta Project. This
+    process is
+    <a href="http://jakarta.apache.org/site/jakarta-site2.html">documented</a>
     on the site. You are welcome to use this for your own needs as well.
 </p>
                             </blockquote>
@@ -233,6 +251,7 @@
         </font>
       </td></tr>
       <tr><td>
+        <p>
         <blockquote>
                                     <p>
     Before reviewing the jakarta-velocity/examples/anakia directory,
@@ -249,7 +268,7 @@
                                                 <p>
     The jakarta-velocity/examples/anakia/xdocs/ directory has all of the
     .xml source code. The xdocs/stylesheets directory contains the .vsl
-    file, in which most of the magic happens. Understanding <a href="user-guide.html">Velocity Template Language</a> and 
+    file, in which most of the magic happens. Understanding <a href="user-guide.html">Velocity Template Language</a> and
     <a href="http://www.jdom.org/">JDOM</a> is
     necessary to understand how the .vsl file works.
 </p>
@@ -265,6 +284,7 @@
         </font>
       </td></tr>
       <tr><td>
+        <p>
         <blockquote>
                                     <p>
     Anakia is an Ant task that executes from an Ant build file. The
@@ -373,12 +393,12 @@
 </td>
                                 <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
     <font color="#000000" size="-1" face="arial,helvetica,sanserif">
-                
+
             This is the extension that is appended to the end of your
             .xml file. For example, with an extension of ".html",
             index.xml would be converted into index.html. By default,
             the extension is .html.
-            
+
             </font>
 </td>
             </tr>
@@ -393,7 +413,7 @@
                 This is the path (relative to Velocity's
             template.loader.1.template.path) to the
             VelocityStyleTemplate to process. This file is the
-            equivalent to the .xsl file in Ant's style task. 
+            equivalent to the .xsl file in Ant's style task.
             </font>
 </td>
             </tr>
@@ -412,7 +432,7 @@
             this file. <strong>It is an optional task argument.</strong>
             If you look at the Anakia example in the
             jakarta-velocity/examples/anakia directory, you can see the
-            project.xml file being used in the .vsl file. 
+            project.xml file being used in the .vsl file.
             </font>
 </td>
             </tr>
@@ -506,18 +526,14 @@
                                                 <table border="0" cellspacing="0" cellpadding="2" width="100%">
       <tr><td bgcolor="#525D76">
         <font color="#ffffff" face="arial,helvetica,sanserif">
-          <a name="Context Objects"><strong>Context Objects</strong></a>
+          <a name="Predefined Context Objects"><strong>Predefined Context Objects</strong></a>
         </font>
       </td></tr>
       <tr><td>
+        <p>
         <blockquote>
                                     <p>
     The Anakia Ant task places several objects into the Context for you.
-    Right now, you do not have control over what is placed into the
-    Context. Eventually, we hope to have a way to give you control over
-    this. However, that does not prevent Anakia from being extremely
-    useful for you today. :-) The objects that are available to you in
-    your .vsl template are:
 </p>
                                                 <table>
                         <tr>
@@ -556,7 +572,7 @@
     <font color="#000000" size="-1" face="arial,helvetica,sanserif">
                 This contains the JDOM root Element to your project.xml
             document. If you have not specified a project.xml document,
-            then this variable will not be in the context. 
+            then this variable will not be in the context.
             </font>
 </td>
             </tr>
@@ -572,7 +588,7 @@
             $string that is passed into it and it will return the
             converted String. This is good for dealing with CDATA. The
             entities that are converted are: " -&gt; &amp;quot; | &lt;
-            -&gt; &amp;lt; | &gt; -&gt; &amp;gt; | &amp; - &gt; &amp;amp; 
+            -&gt; &amp;lt; | &gt; -&gt; &amp;gt; | &amp; - &gt; &amp;amp;
             </font>
 </td>
             </tr>
@@ -626,7 +642,7 @@
             not the actual &lt;td&gt; &lt;/td&gt;. NOTE: this object is
             obsoleted as simply specifying $element.content will produce the
             desired output.
-            
+
             </font>
 </td>
             </tr>
@@ -660,7 +676,7 @@
 </td>
                                 <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
     <font color="#000000" size="-1" face="arial,helvetica,sanserif">
-                
+
                The W3C XPath Specification <a href="http://www.w3.org/TR/xpath/">http://www.w3.org/TR/xpath/
                </a> refers to NodeSets repeatedly, but this implementation
                simply uses java.util.List to hold all Nodes. A 'Node' is any
@@ -671,7 +687,7 @@
                for backward compatibility only. You can use
                $element.selectNodes("document/properties/@title") to achieve
                the same effect with a more intuitive syntax.
-            
+
             </font>
 </td>
             </tr>
@@ -683,17 +699,17 @@
 </td>
                                 <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
     <font color="#000000" size="-1" face="arial,helvetica,sanserif">
-                
+
                 This is a new java.util.Date object. Useful for putting
                 the current date/time into a page.
-            
+
             </font>
 </td>
             </tr>
             </table>
                                                 <p>
     All node lists returned from Anakia objects through $element.selectNodes,
-    $element.content, and $element.children, as well as through obsoleted 
+    $element.content, and $element.children, as well as through obsoleted
     $treeWalk.allElements and $xpath.applyTo have two special features:
     <ul>
         <li>they support the selectNodes method just as a single element does
@@ -711,13 +727,136 @@
                                                 <table border="0" cellspacing="0" cellpadding="2" width="100%">
       <tr><td bgcolor="#525D76">
         <font color="#ffffff" face="arial,helvetica,sanserif">
+          <a name="Customizing the Anakia Context"><strong>Customizing the Anakia Context</strong></a>
+        </font>
+      </td></tr>
+      <tr><td>
+        <p>
+        <blockquote>
+                                    <p>
+    The Anakia context can be customized by using one or more context nested
+    elements.
+</p>
+                                                    <div align="left">
+    <table cellspacing="4" cellpadding="0" border="0">
+    <tr>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    <tr>
+      <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#ffffff"><pre>
+&lt;anakia ...&gt;
+    &lt;context name=&quot;customContext&quot; file=&quot;./customContext.xml&quot;/&gt;
+&lt;/anakia&gt;
+</pre></td>
+      <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    <tr>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    </table>
+    </div>
+                                                <p>
+    The context file must be an xml file and is an instance of a JDOM
+    root element similar to $project. There are two attributes for the context:
+</p>
+                                                <table>
+                        <tr>
+                        <th bgcolor="#039acc" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+                Name
+            </font>
+</th>
+                                <th bgcolor="#039acc" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+                Description
+            </font>
+</th>
+            </tr>
+                                <tr>
+                        <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+                name
+            </font>
+</td>
+                                <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+
+            This sets the name of the context within the velocity context.
+            It cannot be one of the predefined context objects.
+
+            </font>
+</td>
+            </tr>
+                                <tr>
+                        <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+                file
+            </font>
+</td>
+                                <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
+    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
+
+            The location of the custom file relative to the anakia basedir.
+            This must be an XML file.
+
+            </font>
+</td>
+            </tr>
+            </table>
+                                                <p>
+    Within the velocity template the context can be accessed using the standard
+    velocity template language.
+</p>
+                                                    <div align="left">
+    <table cellspacing="4" cellpadding="0" border="0">
+    <tr>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    <tr>
+      <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#ffffff"><pre>
+#set ($customMenus = $xpath.applyTo(&quot;body/menu&quot;,$customContext))
+#foreach($customMenu in $customMenus)
+    &lt;strong&gt;$customMenu.getAttributeValue(&quot;name&quot;)&lt;/strong&gt;
+    &lt;ul&gt;
+    #foreach ($customItem in $customMenu.getChildren() )
+        #set ($name = $customItem.getAttributeValue(&quot;name&quot;))
+        &lt;li&gt;#projectanchor($name $customItem.getAttributeValue(&quot;href&quot;))&lt;/li&gt;
+        #end
+    &lt;/ul&gt;
+#end</pre></td>
+      <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    <tr>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+      <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
+    </tr>
+    </table>
+    </div>
+                            </blockquote>
+        </p>
+      </td></tr>
+      <tr><td><br/></td></tr>
+    </table>
+                                                <table border="0" cellspacing="0" cellpadding="2" width="100%">
+      <tr><td bgcolor="#525D76">
+        <font color="#ffffff" face="arial,helvetica,sanserif">
           <a name="Credits"><strong>Credits</strong></a>
         </font>
       </td></tr>
       <tr><td>
+        <p>
         <blockquote>
                                     <p>
-    Anakia was originally conceptualized and implemented by 
+    Anakia was originally conceptualized and implemented by
         <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>.
 </p>
                                                 <p>
@@ -732,7 +871,8 @@
     Further help and assistance was provided by Jason van Zyl and Geir
     Magnusson Jr. XPath support was added by Bob McWhirter. The more
     intuitive syntax achieved through selectNodes() and self-rendering
-    elements and node lists was added by Attila Szegedi.
+    elements and node lists was added by Attila Szegedi. The custom context
+    nested element was added by Peter Ryan.
 </p>
                             </blockquote>
         </p>
@@ -748,7 +888,7 @@
                 </td></tr>
                 <tr><td colspan="2">
                     <div align="center"><font color="#525D76" size="-1"><em>
-                    Copyright &#169; 1999-2004, Apache Software Foundation
+                    Copyright &#169; 1999-2005, The Apache Software Foundation
                     </em></font></div>
                 </td></tr>
             </table>

Modified: jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java?view=diff&rev=125378&p1=jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java&r1=125377&p2=jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java&r2=125378
==============================================================================
--- jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java	(original)
+++ jakarta/velocity/trunk/src/java/org/apache/velocity/anakia/AnakiaTask.java	Sun Jan 16 16:30:59 2005
@@ -23,6 +23,9 @@
 import java.io.Writer;
 
 import java.util.StringTokenizer;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
 
 import org.apache.commons.collections.ExtendedProperties;
 
@@ -63,20 +66,17 @@
 public class AnakiaTask extends MatchingTask
 {
     /** <code>{@link SAXBuilder}</code> instance to use */
-    private SAXBuilder builder;
+    SAXBuilder builder;
 
     /** the destination directory */
     private File destDir = null;
     
     /** the base directory */
-    private File baseDir = null;
+    File baseDir = null;
 
     /** the style= attribute */
     private String style = null;
     
-    /** the File to the style file */
-    private File styleFile = null;
-    
     /** last modified of the style sheet */
     private long styleSheetLastModified = 0;
 
@@ -104,6 +104,9 @@
     /** the VelocityEngine instance to use */
     private VelocityEngine ve = new VelocityEngine();
 
+    /** the Velocity subcontexts */
+    private List contexts = new LinkedList();
+
     /**
      * Constructor creates the SAXBuilder.
      */
@@ -208,7 +211,6 @@
     {
         DirectoryScanner scanner;
         String[]         list;
-        String[]         dirs;
 
         if (baseDir == null)
         {
@@ -299,15 +301,15 @@
         list = scanner.getIncludedFiles();
         for (int i = 0;i < list.length; ++i)
         {
-            process( baseDir, list[i], destDir, projectDocument );
+            process(list[i], projectDocument );        
         }
+        
     }    
     
     /**
      * Process an XML file using Velocity
      */
-    private void process(File baseDir, String xmlFile, File destDir, 
-                         Document projectDocument)
+    private void process(String xmlFile, Document projectDocument)
         throws BuildException
     {
         File   outFile=null;
@@ -326,7 +328,8 @@
             if (lastModifiedCheck == false || 
                     (inFile.lastModified() > outFile.lastModified() ||
                     styleSheetLastModified > outFile.lastModified() ||
-                    projectFileLastModified > outFile.lastModified()))
+                    projectFileLastModified > outFile.lastModified() ||
+                    userContextsModifed(outFile.lastModified())))
             {
                 ensureDirectoryFor( outFile );
 
@@ -363,18 +366,35 @@
                 context.put ("escape", new Escape() );
                 context.put ("date", new java.util.Date() );
 
-                // only put this into the context if it exists.
+                /**
+                 * only put this into the context if it exists.
+                 */
                 if (projectDocument != null)
                 {
                     context.put ("project", projectDocument.getRootElement());
                 }
                 
-                // Process the VSL template with the context and write out
-                // the result as the outFile.
+                /**
+                 *  Add the user subcontexts to the to context
+                 */ 
+                for (Iterator iter = contexts.iterator(); iter.hasNext();) 
+                {
+                    Context subContext = (Context) iter.next();
+                    context.put(subContext.getName(), subContext
+                            .getContextDocument().getRootElement());
+                }
+                
+                /**
+                 * Process the VSL template with the context and write out
+                 * the result as the outFile.
+                 */
                 writer = new BufferedWriter(new OutputStreamWriter(
                                             new FileOutputStream(outFile),
                                                 encoding));
-                // get the template to process
+
+                /**
+                 * get the template to process
+                 */
                 Template template = ve.getTemplate(style);
                 template.merge(context, writer);
 
@@ -407,11 +427,9 @@
             {
                 e.printStackTrace();
             }
-//            log("Failed to process " + inFile, Project.MSG_INFO);
         }
         catch (Throwable e)
         {
-//            log("Failed to process " + inFile, Project.MSG_INFO);
             if (outFile != null)
             {
                 outFile.delete();
@@ -456,10 +474,8 @@
         {
             return StringUtils.chop(sb.toString(), 1);
         }
-        else
-        {
-            return ".";
-        }
+
+        return ".";
     }
     
     /**
@@ -477,4 +493,112 @@
             }
         }
     }
+
+
+    /**
+     * Check to see if user context is modified.
+     */
+    private boolean userContextsModifed(long lastModified) 
+    {
+        for (Iterator iter = contexts.iterator(); iter.hasNext();) {
+            AnakiaTask.Context ctx = (AnakiaTask.Context) iter.next();
+            if(ctx.getLastModified() > lastModified) 
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * Create a new context.
+     */
+    public Context createContext() 
+    {
+        Context context = new Context();
+        contexts.add(context);
+        return context;        
+    }
+        
+    
+    /**
+     * A context implementation that loads all values from an XML file.
+     */
+    public class Context 
+    {
+        
+        private String name;
+        private Document contextDoc;
+        private File contextFile;
+        
+        /**
+         * Public constructor.
+         */
+        public Context() 
+        {
+        }
+        
+        /**
+         * Get the name of the context.
+         */
+        public String getName() 
+        {
+            return name;
+        }
+
+        /**
+         * Set the name of the context. 
+         * 
+         * @throws IllegalArgumentException if a reserved word is used as a 
+         * name, specifically any of "relativePath", "treeWalk", "xpath",
+         * "escape", "date", or "project"
+         */
+        public void setName(String name) 
+        {
+            if (name.equals("relativePath") || 
+                    name.equals("treeWalk") || 
+                    name.equals("xpath") || 
+                    name.equals("escape") || 
+                    name.equals("date") ||
+                    name.equals("project")) {
+                    
+                    throw new IllegalArgumentException("Context name '" + name
+                            + "' is reserved by Anakia");
+                }
+            
+            this.name = name;
+        }
+    
+        /**
+         * Build the context based on a file path.
+         */
+        public void setFile(String file) 
+        {
+            contextFile = new File(baseDir, file);
+            
+            try 
+            {
+                contextDoc = builder.build(contextFile);
+            } catch (Exception e) {
+                throw new BuildException(e);
+            }
+        }
+    
+        /**
+         * Retrieve the time the source file was last modified.
+         */
+        public long getLastModified() 
+        {
+            return contextFile.lastModified();
+        }
+        
+        /**
+         * Retrieve the context document object.
+         */
+        public Document getContextDocument() 
+        {
+            return contextDoc;
+        }
+    }
+
 }    

Modified: jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java?view=diff&rev=125378&p1=jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java&r1=125377&p2=jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java&r2=125378
==============================================================================
--- jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java	(original)
+++ jakarta/velocity/trunk/src/java/org/apache/velocity/test/AnakiaTestCase.java	Sun Jan 16 16:30:59 2005
@@ -22,13 +22,15 @@
  * first running Anakia and then running this test.
  *
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: AnakiaTestCase.java,v 1.8 2004/03/19 17:13:38 dlr Exp $
+ * @version $Id$
  */
 public class AnakiaTestCase extends BaseTestCase
 {
     private static final String COMPARE_DIR = "../test/anakia/compare";
     private static final String RESULTS_DIR = "../test/anakia/results";
-    private static final String FILE_EXT = ".html";
+
+    private static final String FILE_EXT = "html";
+    private static final String CONTEXT_FILE_EXT = "context.html";
 
     /**
      * Creates a new instance.
@@ -55,10 +57,22 @@
         {
             assureResultsDirectoryExists(RESULTS_DIR);
             
+            /**
             if (!isMatch(RESULTS_DIR,COMPARE_DIR,"index",FILE_EXT,FILE_EXT))
             {
                 fail("Output is incorrect!");
             }
+            **/
+            
+            if (!isMatch(
+                    RESULTS_DIR,
+                    COMPARE_DIR,
+                    "index",
+                    CONTEXT_FILE_EXT,
+                    CONTEXT_FILE_EXT))
+                    {
+                    fail("Custom Context Output is incorrect");
+                    }            
             else
             {
                 System.out.println ("Passed!");

Added: jakarta/velocity/trunk/test/anakia/compare/index.context.html
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/compare/index.context.html?view=auto&rev=125378
==============================================================================
--- (empty file)
+++ jakarta/velocity/trunk/test/anakia/compare/index.context.html	Sun Jan 16 16:30:59 2005
@@ -0,0 +1,65 @@
+<!-- Content Stylesheet for Site -->
+
+        
+<!-- start the processing -->
+    <!-- ====================================================================== -->
+    <!-- Main Page Section -->
+    <!-- ====================================================================== -->
+    <html>
+        <head>
+            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
+                        <meta name="author" value="$au.getText()">
+            <meta name="email" value="$em.getValue()">
+            <title>The Jakarta Project</title>
+        </head>
+
+        <body bgcolor="#ffffff" text="#000000" link="#525D76">        
+            <table border="1">
+                <tr>
+                <td>
+                            <strong>Home</strong>
+        <ul>
+                    <li>    <a href="./index.html">Front Page</a>
+</li>
+                </ul>
+            <strong>About</strong>
+        <ul>
+                    <li>    <a href="./about/index.html">About</a>
+</li>
+                </ul>
+        
+            	<strong>Other Context</strong>
+    	<ul>
+    	    		<li>    <a href="./index.html">Front Page OC</a>
+</li>
+    	    	</ul>
+        	<strong>Other About</strong>
+    	<ul>
+    	    		<li>    <a href="./about/index.html">About OC</a>
+</li>
+    	    	</ul>
+                    </td>
+                <td>
+                                                                                                        <p> This is an example template that gets processed. </p>
+                                                                                                <img src="./images/velocity.gif" width="329" height="105" align="">
+                                                                                                <table border="1">
+                <tr>
+                    <td> It even has a table in it! </td>
+                </tr>
+            </table>
+                                                                                                <h3>And an h3 tag</h3>
+                                                                                                                                    <p> here is another section </p>
+                                                                                                                                    <p>
+                <a href="./about/index.html">A link to a sub page</a>
+            </p>
+                                                                            </td>
+                </tr>
+            </table>
+        </body>
+    </html>
+<!-- end the processing -->
+
+
+
+
+

Modified: jakarta/velocity/trunk/test/anakia/compare/index.html
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/compare/index.html?view=diff&rev=125378&p1=jakarta/velocity/trunk/test/anakia/compare/index.html&r1=125377&p2=jakarta/velocity/trunk/test/anakia/compare/index.html&r2=125378
==============================================================================
--- jakarta/velocity/trunk/test/anakia/compare/index.html	(original)
+++ jakarta/velocity/trunk/test/anakia/compare/index.html	Sun Jan 16 16:30:59 2005
@@ -9,17 +9,10 @@
         <head>
             <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
 
-                        
-<!--
-                                    
             
             
-                        
--->
-
-
-                        <meta name="author" value="Jon S. Stevens">
-            <meta name="email" value="jon@latchkey.com">
+                        <meta name="author" value="$au.getText()">
+            <meta name="email" value="$em.getValue()">
 
             <title>The Jakarta Project</title>
         </head>
@@ -28,7 +21,7 @@
             <table border="1">
                 <tr>
                 <td>
-                    
+                
             <strong>Home</strong>
         <ul>
                     <li>    <a href="./index.html">Front Page</a>
@@ -42,20 +35,19 @@
                     </td>
                 <td>
                 
-                                                                                        <p>
-This is an example template that gets processed.
-</p>
+                
+                                                                                        <p> This is an example template that gets processed. </p>
                                                                                                 <img src="./images/velocity.gif" width="329" height="105" align="">
                                                                                                 <table border="1">
-<tr>
-    <td>
-        It even has a table in it!
-    </td>
-</tr>
-</table>
+                <tr>
+                    <td> It even has a table in it! </td>
+                </tr>
+            </table>
                                                                                                 <h3>And an h3 tag</h3>
                                                                                                                                     <p> here is another section </p>
-                                                                                                                                    <p><a href="./about/index.html">A link to a sub page</a></p>
+                                                                                                                                    <p>
+                <a href="./about/index.html">A link to a sub page</a>
+            </p>
                                                                             </td>
                 </tr>
             </table>

Modified: jakarta/velocity/trunk/test/anakia/xdocs/index.xml
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/xdocs/index.xml?view=diff&rev=125378&p1=jakarta/velocity/trunk/test/anakia/xdocs/index.xml&r1=125377&p2=jakarta/velocity/trunk/test/anakia/xdocs/index.xml&r2=125378
==============================================================================
--- jakarta/velocity/trunk/test/anakia/xdocs/index.xml	(original)
+++ jakarta/velocity/trunk/test/anakia/xdocs/index.xml	Sun Jan 16 16:30:59 2005
@@ -1,46 +1,27 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <document>
-
-  <properties>
-    <author email="jon@latchkey.com">Jon S. Stevens</author>
-    <title>The Jakarta Project</title>
-  </properties>
-
-<body>
-
-  <section name="Section 1">
-
-<p>
-This is an example template that gets processed.
-</p>
-
-<img src="/images/velocity.gif" width="329" height="105"/>
-
-<table border="1">
-<tr>
-    <td>
-        It even has a table in it!
-    </td>
-</tr>
-</table>
-
-<h3>And an h3 tag</h3>
-
-  </section>
-
-
-    <section name="Section 2">
-
-    <p> here is another section </p>
-    
-    </section>
-
-    <section name="section 3">
-    
-    <p><a href="./about/index.html">A link to a sub page</a></p>
-
-    </section>
-
-</body>
+    <properties>
+        <author email="jon@latchkey.com">Jon S. Stevens</author>
+        <title>The Jakarta Project</title>
+    </properties>
+    <body>
+        <section name="Section 1">
+            <p> This is an example template that gets processed. </p>
+            <img src="/images/velocity.gif" width="329" height="105"/>
+            <table border="1">
+                <tr>
+                    <td> It even has a table in it! </td>
+                </tr>
+            </table>
+            <h3>And an h3 tag</h3>
+        </section>
+        <section name="Section 2">
+            <p> here is another section </p>
+        </section>
+        <section name="section 3">
+            <p>
+                <a href="./about/index.html">A link to a sub page</a>
+            </p>
+        </section>
+    </body>
 </document>

Added: jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/customContext.xml
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/customContext.xml?view=auto&rev=125378
==============================================================================
--- (empty file)
+++ jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/customContext.xml	Sun Jan 16 16:30:59 2005
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project name="Jakarta Site" href="http://jakarta.apache.org/">
+    <body>
+        <menu name="Other Context">
+            <item name="Front Page OC" href="/index.html"/>
+        </menu>
+        <menu name="Other About">
+            <item name="About OC" href="/about/index.html"/>
+        </menu>
+    </body>
+</project>
\ No newline at end of file

Modified: jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl?view=diff&rev=125378&p1=jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl&r1=125377&p2=jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl&r2=125378
==============================================================================
--- jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl	(original)
+++ jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site.vsl	Sun Jan 16 16:30:59 2005
@@ -16,7 +16,6 @@
 ## This is where the macro's live
 
 #macro ( makeProject )
-    ##set ($menus = $project.getChild("body").getChildren("menu"))
     #set ($menus = $xpath.applyTo("body/menu", $project))
 
     #foreach ( $menu in $menus )
@@ -61,23 +60,6 @@
 
             ##set ($au = $root.getChild("properties").getChild("author").getText())
             ##set ($em = $root.getChild("properties").getChild("author").getAttributeValue("email"))
-
-<!--
-            ## For some reason, we can't .getText() and .getValue() directly in the
-            ## set directive, but rather have to wait a moment, and do it in the
-            ## metaauthor directive.
-
-            #set ($au = $xpath.applyTo("properties/author", $root).get(0))
-            #set ($em = $xpath.applyTo("properties/author/@email", $root).get(0))
-
-            ## This should work, but doesn't
-
-            ##set ($au = $xpath.applyTo("properties/author", $root).get(0).getText())
-            ##set ($em = $xpath.applyTo("properties/author/@email", $root).get(0).getValue())
-
--->
-
-
             #metaauthor ( $au.getText() $em.getValue() )
 
             <title>$root.getChild("properties").getChild("title").getText()</title>

Added: jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site_contexts.vsl
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site_contexts.vsl?view=auto&rev=125378
==============================================================================
--- (empty file)
+++ jakarta/velocity/trunk/test/anakia/xdocs/stylesheets/site_contexts.vsl	Sun Jan 16 16:30:59 2005
@@ -0,0 +1,96 @@
+<!-- Content Stylesheet for Site -->
+
+    ## Defined variables
+    #set ($bodybg = "#ffffff")
+    #set ($bodyfg = "#000000")
+    #set ($bodylink = "#525D76")
+    #set ($bannerbg = "#525D76")
+    #set ($bannerfg = "#ffffff")
+    #set ($tablethbg = "#039acc")
+    #set ($tabletdbg = "#a0ddf0")
+    
+<!-- start the processing -->
+#document()
+<!-- end the processing -->
+
+## This is where the macro's live
+
+#macro ( makeProject )
+    #set ($menus = $xpath.applyTo("body/menu", $project))
+    #foreach ( $menu in $menus )
+        <strong>$menu.getAttributeValue("name")</strong>
+        <ul>
+        #foreach ( $item in $menu.getChildren() )
+            #set ($name = $item.getAttributeValue("name"))
+            <li>#projectanchor($name $item.getAttributeValue("href"))</li>
+        #end
+        </ul>
+    #end
+    
+    #set ($customMenus = $xpath.applyTo("body/menu",$customContext))
+    #foreach($customMenu in $customMenus)
+    	<strong>$customMenu.getAttributeValue("name")</strong>
+    	<ul>
+    	#foreach ($customItem in $customMenu.getChildren() )
+    		#set ($name = $customItem.getAttributeValue("name"))
+    		<li>#projectanchor($name $customItem.getAttributeValue("href"))</li>
+    	#end
+    	</ul>
+    #end    
+#end
+
+#macro ( image $value )
+#if ($value.getAttributeValue("width"))
+#set ($width=$value.getAttributeValue("width"))
+#end
+#if ($value.getAttributeValue("height"))
+#set ($height=$value.getAttributeValue("height"))
+#end
+#if ($value.getAttributeValue("align"))
+#set ($align=$value.getAttributeValue("align"))
+#end
+<img src="$relativePath$value.getAttributeValue("src")" width="$!width" height="$!height" align="$!align">
+#end
+
+#macro ( projectanchor $name $value )
+    <a href="$relativePath$value">$name</a>
+#end
+#macro ( metaauthor $author $email )
+            <meta name="author" value="$author">
+            <meta name="email" value="$email">
+#end
+
+#macro (document)
+    <!-- ====================================================================== -->
+    <!-- Main Page Section -->
+    <!-- ====================================================================== -->
+    <html>
+        <head>
+            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
+            #metaauthor ( $au.getText() $em.getValue() )
+            <title>$root.getChild("properties").getChild("title").getText()</title>
+        </head>
+
+        <body bgcolor="$bodybg" text="$bodyfg" link="$bodylink">        
+            <table border="1">
+                <tr>
+                <td>
+                #makeProject()
+                </td>
+                <td>
+                #set ($allSections = $xpath.applyTo("body/section", $root))
+                #foreach ( $section in $allSections )
+                    #foreach ( $item in $section.getChildren() )                
+                        #if ($item.getName().equals("img"))
+                            #image ($item)
+                        #else
+                            $xmlout.outputString($item)
+                        #end
+                    #end
+                #end
+                </td>
+                </tr>
+            </table>
+        </body>
+    </html>
+#end
\ No newline at end of file

Modified: jakarta/velocity/trunk/xdocs/anakia.xml
Url: http://svn.apache.org/viewcvs/jakarta/velocity/trunk/xdocs/anakia.xml?view=diff&rev=125378&p1=jakarta/velocity/trunk/xdocs/anakia.xml&r1=125377&p2=jakarta/velocity/trunk/xdocs/anakia.xml&r2=125378
==============================================================================
--- jakarta/velocity/trunk/xdocs/anakia.xml	(original)
+++ jakarta/velocity/trunk/xdocs/anakia.xml	Sun Jan 16 16:30:59 2005
@@ -74,10 +74,11 @@
 <p>
     Anakia creates a Context, which contains a JDOM Document object of
     the .xml page, as well as an (optional) JDOM Document object of your
-    project.xml page. The .vsl page is executed (using Velocity) with
-    the Context. You can then navigate your .xml file and pull
-    information out of it by simply executing methods on the JDOM
-    Document object.
+    project.xml page. In addition to the project.xml based context, additional
+    xml contexts can be added through context nested elements. The 
+    .vsl page is executed (using Velocity) with the Context. You can then 
+    navigate your .xml file and pull information out of it by simply executing
+    methods on the JDOM Document object.
 </p>
 <p>
     Anakia is being used to create the documentation for not only this
@@ -245,16 +246,10 @@
     </table>
 </section>
 
-<section name="Context Objects">
+<section name="Predefined Context Objects">
 <p>
     The Anakia Ant task places several objects into the Context for you.
-    Right now, you do not have control over what is placed into the
-    Context. Eventually, we hope to have a way to give you control over
-    this. However, that does not prevent Anakia from being extremely
-    useful for you today. :-) The objects that are available to you in
-    your .vsl template are:
 </p>
-
     <table border="0">
         <tr>
         <th>Name</th>
@@ -363,6 +358,57 @@
 
 </section>
 
+<section name="Customizing the Anakia Context">
+<p>
+    The Anakia context can be customized by using one or more context nested 
+    elements.
+</p>
+<source><![CDATA[
+<anakia ...>
+    <context name="customContext" file="./customContext.xml"/>
+</anakia>
+]]></source>
+<p>
+    The context file must be an xml file and is an instance of a JDOM
+    root element similar to $project. There are two attributes for the context:
+</p>
+<table border="0">
+    <tr>
+        <th>Name</th>
+        <th>Description</th>
+    </tr>
+    <tr>
+        <td>name</td>
+        <td>
+            This sets the name of the context within the velocity context.
+            It cannot be one of the predefined context objects.
+        </td>
+    </tr>
+    <tr>
+        <td>file</td>
+        <td>
+            The location of the custom file relative to the anakia basedir.
+            This must be an XML file.
+        </td>
+    </tr>
+</table>
+<p>
+    Within the velocity template the context can be accessed using the standard
+    velocity template language.
+</p>
+<source><![CDATA[
+#set ($customMenus = $xpath.applyTo("body/menu",$customContext))
+#foreach($customMenu in $customMenus)
+    <strong>$customMenu.getAttributeValue("name")</strong>
+    <ul>
+    #foreach ($customItem in $customMenu.getChildren() )
+        #set ($name = $customItem.getAttributeValue("name"))
+        <li>#projectanchor($name $customItem.getAttributeValue("href"))</li>
+        #end
+    </ul>
+#end]]></source>
+</section>
+
 <section name="Credits">
 <p>
     Anakia was originally conceptualized and implemented by 
@@ -381,8 +427,10 @@
     Further help and assistance was provided by Jason van Zyl and Geir
     Magnusson Jr. XPath support was added by Bob McWhirter. The more
     intuitive syntax achieved through selectNodes() and self-rendering
-    elements and node lists was added by Attila Szegedi.
+    elements and node lists was added by Attila Szegedi. The custom context
+    nested element was added by Peter Ryan.
 </p>
+
 </section>
 
 </body>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org