jon 00/11/25 22:52:22
Modified: src/java/org/apache/velocity/anakia AnakiaTask.java
XPathTool.java
Added: src/java/org/apache/velocity/anakia TreeWalker.java
Log:
lots of changes and functionality. added TreeWalker and documentation to XPathTool
Revision Changes Path
1.9 +6 -7
jakarta-velocity/src/java/org/apache/velocity/anakia/AnakiaTask.java
Index: AnakiaTask.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/anakia/AnakiaTask.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AnakiaTask.java 2000/11/25 20:44:08 1.8
+++ AnakiaTask.java 2000/11/26 06:52:22 1.9
@@ -81,14 +81,12 @@
class instead to do your transformations. It works very
similar in concept to Ant's <style> task.
<p>
- This class is still a work in progress, so more documentation
- will be following soon.
- <p>
- The name Anakia is just a cool name that I liked so I used
- it for this project.
+ You can find more documentation about this class on the
+ Velocity
+ <a href="http://jakarta.apache.org/velocity/anakia.html">Website</a>.
@author <a href="[EMAIL PROTECTED]">Jon S. Stevens</a>
- @version $Id: AnakiaTask.java,v 1.8 2000/11/25 20:44:08 jon Exp $
+ @version $Id: AnakiaTask.java,v 1.9 2000/11/26 06:52:22 jon Exp $
*/
public class AnakiaTask extends MatchingTask
{
@@ -303,8 +301,9 @@
context.put ("root", root.getRootElement());
context.put ("xmlout", new XMLOutputter());
context.put ("relativePath", getRelativePath(xmlFile));
+ context.put ("treeWalk", new TreeWalker());
context.put ("xpath", new XPathTool() );
-
+
// only put this into the context if it exists.
if (projectDocument != null)
context.put ("project", projectDocument.getRootElement());
1.4 +15 -9
jakarta-velocity/src/java/org/apache/velocity/anakia/XPathTool.java
Index: XPathTool.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/anakia/XPathTool.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XPathTool.java 2000/11/24 01:25:52 1.3
+++ XPathTool.java 2000/11/26 06:52:22 1.4
@@ -66,13 +66,24 @@
import org.jdom.Element;
/**
- This class adds an entrypoint into XPath funcitonlaity,
+ This class adds an entrypoint into XPath functionality,
for Anakia.
-
+ <p>
All methods take a string XPath specification, along with
a context, and produces a resulting NodeSet (java.util.List).
-
- @author <a href="[EMAIL PROTECTED]">bob mcwhirter</a>
+ <p>
+ To use it in Velocity, do this:
+ <p>
+ <code>
+ #set $authors = $xpath.applyTo("document/author", $root)
+ #foreach ($author in $authors)
+ $author.getValue() // At time of writting this could be wrong; what is NodeSet?
+ #end
+ </code>
+
+ @author <a href="[EMAIL PROTECTED]">bob mcwhirter</a>
+ @author <a href="[EMAIL PROTECTED]">Jon S. Stevens</a>
+ @version $Id: XPathTool.java,v 1.4 2000/11/26 06:52:22 jon Exp $
*/
public class XPathTool
@@ -98,7 +109,6 @@
Document doc)
{
XPath xpath = new XPath( xpathSpec );
-
return xpath.applyTo( doc );
}
@@ -114,7 +124,6 @@
Element elem)
{
XPath xpath = new XPath(xpathSpec);
-
return xpath.applyTo( elem );
}
@@ -130,9 +139,6 @@
List nodeSet)
{
XPath xpath = new XPath(xpathSpec);
-
return xpath.applyTo( nodeSet );
}
-
-
}
1.1
jakarta-velocity/src/java/org/apache/velocity/anakia/TreeWalker.java
Index: TreeWalker.java
===================================================================
package org.apache.velocity.anakia;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// JDK Stuff
import java.util.*;
// JDOM Stuff
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
/**
This class allows you to walk a tree of JDOM Element objects.
It first walks the tree itself starting at the Element passed
into allElements() and stores each node of the tree
in a Vector which allElements() returns as a result of its
execution. You can then use a #foreach in Velocity to walk
over the Vector and visit each Element node.
@author <a href="[EMAIL PROTECTED]">Jon S. Stevens</a>
@version $Id: TreeWalker.java,v 1.1 2000/11/26 06:52:22 jon Exp $
*/
public class TreeWalker
{
/** the cache of Element objects */
private Vector theElements = null;
/**
Empty constructor
*/
public TreeWalker()
{
// Left blank
}
/**
Creates a new Vector and walks the Element tree.
@param Element the starting Element node
@return Vector a vector of Element nodes
*/
public Vector allElements(Element e)
{
theElements = new Vector();
treeWalk (e);
return this.theElements;
}
/**
A recursive method to walk the Element tree.
@param Element the current Element
*/
private final void treeWalk(Element e)
{
for (Iterator i=e.getChildren().iterator(); i.hasNext(); )
{
Element child = (Element)i.next();
theElements.add(child);
treeWalk(child);
}
}
}