You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2005/05/20 10:13:04 UTC

svn commit: r171077 [3/4] - in /incubator/jackrabbit/trunk/contrib/jcrtaglib: ./ src/ src/examples/ src/examples/web/ src/examples/web/WEB-INF/ src/examples/web/WEB-INF/classes/ src/examples/web/WEB-INF/lib/ src/examples/web/WEB-INF/repository/ src/examples/web/WEB-INF/src/ src/examples/web/WEB-INF/taglib/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jackrabbit/ src/java/org/apache/jackrabbit/taglib/ src/java/org/apache/jackrabbit/taglib/bean/ src/java/org/apache/jackrabbit/taglib/comparator/ src/java/org/apache/jackrabbit/taglib/filter/ src/java/org/apache/jackrabbit/taglib/size/ src/java/org/apache/jackrabbit/taglib/template/ src/java/org/apache/jackrabbit/taglib/traverser/ src/java/org/apache/jackrabbit/taglib/utils/ src/test/ src/test/org/ src/test/org/apache/ src/test/org/apache/jackrabbit/ src/test/org/apache/jackrabbit/taglib/ src/test/org/apache/jackrabbit/taglib/test/ xdocs/ xdocs/examples/

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SizeTag.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SizeTag.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SizeTag.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SizeTag.java Fri May 20 01:13:01 2005
@@ -0,0 +1,381 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.taglib.filter.ItemFilter;
+import org.apache.jackrabbit.taglib.size.SizeCalculator;
+import org.apache.jackrabbit.taglib.traverser.Traverser;
+import org.apache.jackrabbit.taglib.utils.JCRTagConstants;
+import org.apache.jackrabbit.taglib.utils.JCRTagUtils;
+import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
+import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
+
+/**
+ * Estimates the cumulative size of the nodes returned by the given
+ * <code>Traverser</code> and displays the value.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class SizeTag extends TagSupport
+{
+    /** logger */
+    private static Log log = LogFactory.getLog(SizeTag.class);
+
+    /** tag name */
+    public static String TAG_NAME = "size";
+
+    /** number format */
+    private static NumberFormat NF;
+
+    // Default Format
+    static
+    {
+        NF = new DecimalFormat("###,##0.0");
+        NF.setMaximumFractionDigits(2);
+    }
+
+    /**
+     * Name of the scoped variable where the jcr session is stored. If not set
+     * then JCRTagConstants.KEY_SESSION is used.
+     */
+    private String session;
+
+    /**
+     * JSTL expression or full path. <br>
+     * e.g. /mynode <br>
+     * or ${mynode}
+     */
+    private String node;
+
+    /**
+     * Traverser ID.
+     */
+    private String traverserID;
+
+    /**
+     * Expression that affects Traverser behaviour
+     */
+    private String traverserParam;
+
+    /**
+     * Traverse depth
+     */
+    private int traverserDepth = 0;
+
+    /**
+     * NodePredicate ID.
+     */
+    private String filterID;
+
+    /**
+     * Expression used by the NodePredicate to evaluate nodes. The evaluation
+     * must return a Boolean instance.
+     */
+    private String filterExp;
+
+    /**
+     * Storage calculator ID.
+     */
+    private String calculatorID;
+
+    /**
+     * Unit.
+     */
+    private int unit;
+
+    /**
+     * Decimal format pattern
+     */
+    private String format;
+
+    /**
+     * Constructor
+     */
+    public SizeTag()
+    {
+        super();
+        this.init();
+    }
+
+    /**
+     * Sets the filter expression
+     * 
+     * @param filterExp
+     */
+    public void setFilterExp(String filterExp)
+    {
+        this.filterExp = filterExp;
+    }
+
+    /**
+     * Sets the filter ID
+     * 
+     * @param filterID
+     */
+    public void setFilterID(String filterID)
+    {
+        this.filterID = filterID;
+    }
+
+    /**
+     * Sets the node
+     * 
+     * @param node
+     */
+    public void setNode(String node)
+    {
+        this.node = node;
+    }
+
+    /**
+     * Sets the session
+     * 
+     * @param session
+     */
+    public void setSession(String session)
+    {
+        this.session = session;
+    }
+
+    /**
+     * Sets the traverser depth
+     * 
+     * @param traverseDepth
+     */
+    public void setTraverserDepth(int traverseDepth)
+    {
+        this.traverserDepth = traverseDepth;
+    }
+
+    /**
+     * Sets the traverser ID
+     * 
+     * @param traverseID
+     */
+    public void setTraverserID(String traverseID)
+    {
+        this.traverserID = traverseID;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void release()
+    {
+        super.release();
+        this.init();
+    }
+
+    /**
+     * init
+     *  
+     */
+    private void init()
+    {
+        this.filterExp = null;
+        this.filterID = (String) JCRTagUtils
+                .lookup(JCRTagConstants.JNDI_DEFAULT_ITEM_FILTER);
+
+        this.node = "/";
+
+        this.session = "${" + JCRTagConstants.KEY_SESSION + "}";
+
+        this.traverserDepth = 1;
+        this.traverserID = (String) JCRTagUtils
+                .lookup(JCRTagConstants.JNDI_DEFAULT_TRAVERSER);
+
+        this.calculatorID = (String) JCRTagUtils
+                .lookup(JCRTagConstants.JNDI_DEFAULT_SIZE_CALCULATOR);
+
+        this.unit = SizeCalculator.BYTES;
+
+        this.format = null;
+
+    }
+
+    /**
+     * Sets the traverser parameter
+     * 
+     * @param traverserExp
+     */
+    public void setTraverserParam(String traverserExp)
+    {
+        this.traverserParam = traverserExp;
+    }
+
+    /**
+     * gets the traverser parameter evaluation
+     * 
+     * @return @throws
+     *         JspException
+     */
+    private Object getTraverserParam() throws JspException
+    {
+        Object o = null;
+        try
+        {
+            o = ExpressionUtil.evalNotNull(TAG_NAME, "traverserParam",
+                    this.traverserParam, Object.class, this, this.pageContext);
+        } catch (NullAttributeException e)
+        {
+        }
+        return o;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public int doEndTag() throws JspException
+    {
+        try
+        {
+            // get a session
+            Session s = JCRTagUtils.getSession(TAG_NAME, this.session, this,
+                    this.pageContext);
+
+            // get the node
+            Node jcrNode = (Node) JCRTagUtils.getItem(TAG_NAME, this.node,
+                    this, this.pageContext, s);
+
+            // Configure traverse strategy
+            Traverser traverser = (Traverser) JCRTagUtils
+                    .getBean(this.traverserID);
+            traverser.setDepth(this.traverserDepth);
+            traverser.setNode(jcrNode);
+            traverser.setParameter(this.getTraverserParam());
+
+            // Filter
+            if (this.filterExp != null)
+            {
+                ItemFilter predicate = (ItemFilter) JCRTagUtils
+                        .getBean(this.filterID);
+                predicate.setExpression(this.filterExp);
+                traverser.setFilter(predicate);
+            }
+            // Traverse nodes
+            traverser.traverse();
+
+            // Estimate size
+            SizeCalculator calculator = (SizeCalculator) JCRTagUtils
+                    .getBean(this.calculatorID);
+            calculator.setUnit(this.unit);
+
+            double size = 0;
+            Iterator iter = traverser.getNodes().iterator();
+            while (iter.hasNext())
+            {
+                Node n = (Node) iter.next();
+                size = size + calculator.getSize(n);
+            }
+
+            // Write the size
+            pageContext.getOut().write(this.getNumberFormat().format(size));
+
+        } catch (PathNotFoundException e)
+        {
+            String msg = JCRTagUtils.getMessage(e);
+            log.warn(msg, e);
+            throw new JspTagException(msg);
+        } catch (RepositoryException e)
+        {
+            String msg = JCRTagUtils.getMessage(e);
+            log.error(msg, e);
+            throw new JspTagException(msg);
+        } catch (IOException e)
+        {
+            String msg = JCRTagUtils.getMessage(e);
+            log.error(msg, e);
+            throw new JspTagException(msg);
+        }
+        return EVAL_PAGE;
+    }
+
+    /**
+     * Sets the unit ( bytes | kb | mb | gb )
+     * 
+     * @param unit
+     * @throws JspTagException
+     */
+    public void setUnit(String unit) throws JspTagException
+    {
+        if (unit.equalsIgnoreCase("bytes"))
+        {
+            this.unit = SizeCalculator.BYTES;
+        } else if (unit.equalsIgnoreCase("kb"))
+        {
+            this.unit = SizeCalculator.KILOBYTES;
+        } else if (unit.equalsIgnoreCase("mb"))
+        {
+            this.unit = SizeCalculator.MEGABYTES;
+        } else if (unit.equalsIgnoreCase("gb"))
+        {
+            this.unit = SizeCalculator.GIGABYTES;
+        } else
+        {
+            throw new JspTagException("No such unit. " + unit);
+        }
+    }
+
+    /**
+     * Sets the storage calculator ID
+     * 
+     * @param calculatorID
+     */
+    public void setCalculatorID(String calculatorID)
+    {
+        this.calculatorID = calculatorID;
+    }
+
+    /**
+     * Sets the format pattern
+     * 
+     * @param format
+     */
+    public void setFormat(String format)
+    {
+        this.format = format;
+    }
+
+    /**
+     * @return the number format
+     */
+    private NumberFormat getNumberFormat()
+    {
+        if (this.format == null)
+        {
+            return NF;
+        } else
+        {
+            return new DecimalFormat(this.format);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SizeTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/VersionsTag.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/VersionsTag.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/VersionsTag.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/VersionsTag.java Fri May 20 01:13:01 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+import javax.servlet.jsp.JspException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Iterates over the versions of the given node
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class VersionsTag extends NodesTag
+{
+    /** logger */
+    private static Log log = LogFactory.getLog(VersionsTag.class);
+
+    /** tag name */
+    public static String TAG_NAME = "versions";
+
+    /**
+     * Override superclass getNode.
+     * @return the baseVersion of the given Node
+     */
+    protected Node getNode() throws JspException, RepositoryException
+    {
+        Node node = super.getNode() ;
+        Version version = node.getBaseVersion() ;
+        return version ;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/VersionsTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/BeanFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/BeanFactory.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/BeanFactory.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/BeanFactory.java Fri May 20 01:13:01 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.bean;
+
+/**
+ * BeanFactory implementation are responsible of creating bean instances.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface BeanFactory
+{
+    /** gets a bean for the given ID */
+    Object getBean(String id);
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/BeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SimpleBeanFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SimpleBeanFactory.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SimpleBeanFactory.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SimpleBeanFactory.java Fri May 20 01:13:01 2005
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.bean;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Bean creation based on class name.<br>
+ * It creates a new instance on each call.<br>
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class SimpleBeanFactory implements BeanFactory
+{
+    private static Log log = LogFactory.getLog(SimpleBeanFactory.class);
+
+    /**
+     * @param id
+     * @return a new instance of the given class name
+     */
+    public Object getBean(String id)
+    {
+        try
+        {
+            ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+            Class beanClass = Class.forName(id);
+            Object bean = beanClass.newInstance();
+            return bean;
+        } catch (Exception e)
+        {
+            log.error("Unable to create an instance of " + id, e);
+            return null;
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SimpleBeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SpringBeanFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SpringBeanFactory.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SpringBeanFactory.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SpringBeanFactory.java Fri May 20 01:13:01 2005
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.bean;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * BeanFactory backed by the Spring Framework
+ */
+public class SpringBeanFactory implements BeanFactory
+{
+    /** Logger */
+    private static Log log = LogFactory.getLog(SpringBeanFactory.class);
+
+    /** Bean registration */
+    private String config = "jcrtaglib-beans.xml";
+
+    /** Spring Factory instance */
+    org.springframework.beans.factory.BeanFactory factory;
+
+    /**
+     * 
+     */
+    public SpringBeanFactory()
+    {
+        super();
+    }
+
+    /**
+     * Init the factory
+     */
+    private void init()
+    {
+        ClassPathResource res = new ClassPathResource(this.config);
+        if (!res.exists())
+        {
+            log.error("Unable to init Spring bean Factory. Config file not found at "
+                    + res.getFilename() + ".");
+            return;
+        }
+        factory = new XmlBeanFactory(res);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public Object getBean(String id)
+    {
+        if (factory == null)
+        {
+            init();
+        }
+        return factory.getBean(id);
+    }
+
+    /**
+     * Sets the spring bean config file 
+     * @param config
+     */
+    public void setConfig(String config)
+    {
+        this.config = config;
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/SpringBeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains BeanFactory interface and implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/bean/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/ItemComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/ItemComparator.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/ItemComparator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/ItemComparator.java Fri May 20 01:13:01 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.comparator;
+
+import java.util.Comparator;
+
+/**
+ * An ItemComparator implementation is responsible of handling comparison of any
+ * Node or Item based on a given expression.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface ItemComparator extends Comparator
+{
+    /**
+     * Expression to evaluate
+     */
+    public void setExpression(String exp);
+
+    /**
+     * Sort order
+     */
+    public void setAscending(boolean asc);
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/ItemComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/JEXLItemComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/JEXLItemComparator.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/JEXLItemComparator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/JEXLItemComparator.java Fri May 20 01:13:01 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.comparator;
+
+import javax.jcr.Item;
+
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.JexlHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * It compares any javax.jcr.Item based on a JEXL valid expression wich returns
+ * a comparable instance. The javax.jcr.Item is added to the JEXLContext with
+ * the name of "item". A valid JEXL expression would be "item.name".
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class JEXLItemComparator implements ItemComparator
+{
+    private static Log log = LogFactory.getLog(JEXLItemComparator.class);
+
+    /** Context */
+    JexlContext jc = JexlHelper.createContext();
+
+    /** Expression to evaluate */
+    private Expression expression;
+
+    /** Sort order */
+    private boolean ascending;
+
+    public int compare(Object o1, Object o2)
+    {
+        // Cast nodes
+        Item i1 = (Item) o1;
+        Item i2 = (Item) o2;
+        try
+        {
+            Comparable c1 = this.evaluate(i1);
+            Comparable c2 = this.evaluate(i2);
+            if (this.ascending)
+            {
+                return c1.compareTo(c2);
+            } else
+            {
+                return c2.compareTo(c1);
+            }
+        } catch (Exception e)
+        {
+            log.error("Unable to evaluate expression. " + e.getMessage(), e);
+            return 0;
+        }
+    }
+
+    /**
+     * Expression to evaluate
+     */
+    public void setExpression(String exp)
+    {
+        try
+        {
+            this.expression = ExpressionFactory.createExpression(exp);
+        } catch (Exception e)
+        {
+            log.error("Unable to create expression from String " + exp + ". "
+                    + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Sort order
+     */
+    public void setAscending(boolean asc)
+    {
+        this.ascending = asc;
+    }
+
+    /**
+     * Evaluate the expression for the given node
+     * 
+     * @param node
+     * @return @throws
+     *         Exception
+     */
+    private Comparable evaluate(Item item) throws Exception
+    {
+        // Clear the context
+        jc.getVars().clear();
+
+        // Add nodes to the context
+        jc.getVars().put("item", item);
+
+        // Evaluate
+        return (Comparable) expression.evaluate(jc);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/JEXLItemComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains ItemComparator interface and implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/comparator/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/ItemFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/ItemFilter.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/ItemFilter.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/ItemFilter.java Fri May 20 01:13:01 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.filter;
+
+import org.apache.commons.collections.Predicate;
+
+/**
+ * An ItemPredicate implementation is responsible of evaluating whether the
+ * given javax.jcr.Item should be included based on the given expression
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface ItemFilter extends Predicate
+{
+
+    /**
+     * Filter expression
+     * 
+     * @param exp
+     */
+    void setExpression(String exp);
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/ItemFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/JEXLItemFilter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/JEXLItemFilter.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/JEXLItemFilter.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/JEXLItemFilter.java Fri May 20 01:13:01 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.filter;
+
+import javax.jcr.Item;
+
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.JexlHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * It evaluates any javax.jcr.Item based on a JEXL valid expression which
+ * returns a Boolean instance. The javax.jcr.Item is added to the JEXLContext
+ * with the name of "item". A valid JEXL expression would be
+ * "item.name.equals('MyNodeName')".
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class JEXLItemFilter implements ItemFilter
+{
+    private static Log log = LogFactory.getLog(JEXLItemFilter.class);
+
+    /** Contex */
+    JexlContext jc = JexlHelper.createContext();
+
+    private Expression expression;
+
+    /**
+     * Set the expression to evaluate
+     */
+    public void setExpression(String exp)
+    {
+        try
+        {
+            this.expression = ExpressionFactory.createExpression(exp);
+        } catch (Exception e)
+        {
+            log.error("Unable to create expression. " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Evaluate a node. <br>
+     */
+    public boolean evaluate(Object o)
+    {
+        // Evaluate
+        try
+        {
+            Item item = (Item) o;
+
+            // Clear the context
+            jc.getVars().clear();
+
+            // Add nodes to the context
+            jc.getVars().put("item", item);
+
+            // Evaluate
+            return ((Boolean) this.expression.evaluate(jc)).booleanValue();
+        } catch (Exception e)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.debug("Unable to evalute " + e.getMessage(), e);
+            }
+            return false;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/JEXLItemFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains ItemFilter interface and implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/filter/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains the tag classes that provide access to the JCR implementation.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/AbstractSizeCalculator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/AbstractSizeCalculator.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/AbstractSizeCalculator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/AbstractSizeCalculator.java Fri May 20 01:13:01 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.size;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Superclass of SizeCalculator 
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce</a>
+ */
+public abstract class AbstractSizeCalculator implements SizeCalculator
+{
+    /** Logger */
+    private static Log log = LogFactory.getLog(AbstractSizeCalculator.class);
+
+    /** Unit */
+    protected int unit = SizeCalculator.BITS;
+
+    /**
+     * Unit conversion
+     * @param bits
+     * @param unit
+     * @return
+     */
+    protected double convert(long size, int unit) {
+        switch (unit)
+        {
+            case SizeCalculator.BITS:
+                return size ;
+            case SizeCalculator.BYTES:
+                return size / 8d ;
+            case SizeCalculator.KILOBYTES:
+                return size / 8192d ;
+            case SizeCalculator.MEGABYTES:
+                return size / 8388608d ;
+            case SizeCalculator.GIGABYTES:
+                return size / 8589934592d ;
+            default:
+                String msg = "No such unit." + unit ;
+                log.error(msg);
+            	throw new IllegalArgumentException(msg) ;
+        }
+    }
+
+    /** @inheritDoc */
+    public void setUnit(int unit)
+    {
+        this.unit = unit;
+    }
+    
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/AbstractSizeCalculator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SimpleSizeCalculator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SimpleSizeCalculator.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SimpleSizeCalculator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SimpleSizeCalculator.java Fri May 20 01:13:01 2005
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.size;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * SizeCalculator for testing purposes.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class SimpleSizeCalculator extends AbstractSizeCalculator
+{
+    /** Logger */
+    private static Log log = LogFactory.getLog(SimpleSizeCalculator.class);
+
+    /**
+     * Constructor
+     */
+    public SimpleSizeCalculator()
+    {
+        super();
+    }
+    
+    /** @inheritDoc */
+    public double getSize(Node node)
+    {
+        double size = 0;
+        try
+        {
+            PropertyIterator iter = node.getProperties();
+            while (iter.hasNext())
+            {
+                Property prop = iter.nextProperty();
+                size = size + this.getSize(prop);
+            }
+        } catch (RepositoryException e)
+        {
+            log.error("Unable to get properties from node. " + e.getMessage(),
+                    e);
+        }
+        return size;
+    }
+
+    /** @inheritDoc */
+    public double getSize(Property property)
+    {
+        long bits = 0;
+        try
+        {
+            switch (property.getType())
+            {
+            case PropertyType.BINARY:
+                bits = this.getBinarySize(property) ;
+                break;
+            case PropertyType.BOOLEAN:
+                if (property.getDefinition().isMultiple()) {
+                    bits = property.getValues().length * 1 ;
+                } else {
+                    bits = 1 ;
+                }
+                break;
+            case PropertyType.DOUBLE:
+            case PropertyType.DATE:
+            case PropertyType.LONG:
+                if (property.getDefinition().isMultiple()) {
+                    bits = property.getValues().length * 64 ;
+                } else {
+                    bits = 64 ;
+                }
+                break;
+            default:
+                bits = this.getStringSize(property);
+                break;
+            }
+        } catch (RepositoryException e)
+        {
+            log.error("Unable to get values from property. " + e.getMessage(),
+                    e);
+        }
+        return this.convert(bits, this.unit);
+    }
+
+    /**
+     * @param property
+     * @return the size in bits of a binary property
+     * @throws ValueFormatException
+     * @throws RepositoryException
+     */
+    private long getBinarySize(Property prop) throws ValueFormatException, RepositoryException {
+        if (prop.getDefinition().isMultiple()) {
+            long[] sizes = prop.getLengths() ;
+            long size = 0 ;
+            for (int i = 0; i < sizes.length; i++)
+            {
+                size = size + sizes[i];
+            }
+            return size * 8 ;
+        } else {
+            return prop.getLength() * 8;
+        }
+    }
+    
+    /**
+     * @param prop
+     * @return size in bits
+     * @throws ValueFormatException
+     * @throws RepositoryException
+     */
+    private long getStringSize(Property prop) throws ValueFormatException, RepositoryException {
+        if (prop.getDefinition().isMultiple()) {
+            long[] sizes = prop.getLengths() ;
+            long size = 0 ;
+            for (int i = 0; i < sizes.length; i++)
+            {
+                size = size + sizes[i] * 16 ;
+            }
+            return size;
+        } else {
+            return prop.getLength() * 16 ;
+        }
+    }
+    
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SimpleSizeCalculator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SizeCalculator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SizeCalculator.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SizeCalculator.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SizeCalculator.java Fri May 20 01:13:01 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.size;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+/**
+ * StorageCalculator implementations are responsible of calculating the size
+ * that uses a given Node or Property.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface SizeCalculator
+{
+    int BITS = 0;
+    
+    int BYTES = 1;
+
+    int KILOBYTES = 2;
+
+    int MEGABYTES = 3;
+
+    int GIGABYTES = 4;
+
+    /**
+     * Sets the unit
+     * 
+     * @param unit
+     */
+    void setUnit(int unit);
+
+    /**
+     * Calculate the size of the given node.
+     * 
+     * @param node
+     * @return size
+     */
+    double getSize(Node node);
+
+    /**
+     * Calculate the size of the given property.
+     * 
+     * @param property
+     * @return size
+     */
+    double getSize(Property property);
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/SizeCalculator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains SizeCalculator interface and implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/size/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/SimpleTemplateEngine.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/SimpleTemplateEngine.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/SimpleTemplateEngine.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/SimpleTemplateEngine.java Fri May 20 01:13:01 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.template;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Template for testing purposes.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class SimpleTemplateEngine implements TemplateEngine
+{
+    private static Log log = LogFactory.getLog(SimpleTemplateEngine.class);
+
+    public void setTemplate(String id)
+    {
+        // Nothing to do
+    }
+
+    public void write(PageContext ctx, Item item)
+    {
+        try
+        {
+            if (item instanceof Node)
+            {
+                ctx.getOut().write(item.getName());
+            } else if (item instanceof Property)
+            {
+                Property prop = (Property) item;
+                if (prop.getDefinition().isMultiple())
+                {
+                    ctx.getOut().write("Multiple: " + prop.getValues().length); 
+                } else {
+                    String value = prop.getValue().getString();
+                    ctx.getOut().write(value);
+                }
+            } else
+            {
+                throw new IllegalArgumentException("Unsupported item. "
+                        + item.getClass().getName());
+            }
+        } catch (Exception e)
+        {
+            log.error(e);
+        }
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/SimpleTemplateEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/TemplateEngine.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/TemplateEngine.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/TemplateEngine.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/TemplateEngine.java Fri May 20 01:13:01 2005
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.template;
+
+import javax.jcr.Item;
+import javax.servlet.jsp.PageContext;
+
+/**
+ * TemplateEngine implementations write nodes and properties with the given
+ * template.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface TemplateEngine
+{
+    /**
+     * Template ID
+     * 
+     * @param id
+     */
+    void setTemplate(String id);
+
+    /**
+     * Write the given node
+     * 
+     * @param page
+     *            context
+     * @param item
+     */
+    void write(PageContext ctx, Item item);
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/TemplateEngine.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,5 @@
+<body>
+Contains TemplateEngine interface and implementations.
+Implementations for Velocity and other template engines
+will be added.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/template/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AbstractTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AbstractTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AbstractTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AbstractTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.Predicate;
+
+/**
+ * Abstract Traverser
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public abstract class AbstractTraverser implements Traverser
+{
+    /**
+     * Traverse root
+     */
+    protected Node node;
+
+    /**
+     * Container of traversed nodes
+     */
+    protected Collection nodes = new ArrayList();
+
+    /**
+     * Max depth from the relative root node
+     */
+    protected int depth = 0;
+
+    /**
+     * Per Children order
+     */
+    protected Comparator order;
+
+    /**
+     * Predicate (filter)
+     */
+    protected Predicate filter;
+
+    /**
+     * Parameter that affects the <code>Traverser<code> behaviour
+     */
+    protected Object parameter;
+
+    /**
+     * Constructor
+     */
+    public AbstractTraverser()
+    {
+        super();
+    }
+
+    /**
+     * @return travesed nodes
+     */
+    public Collection getNodes()
+    {
+        return nodes ;
+    }
+
+    /**
+     * Visit node
+     * 
+     * @param node
+     */
+    protected void visit(Node node)
+    {
+        if (this.filter== null || this.filter.evaluate(node))
+        {
+            this.nodes.add(node);
+        } 
+    }
+
+    public int getDepth()
+    {
+        return depth;
+    }
+
+    public void setDepth(int depth)
+    {
+        this.depth = depth;
+    }
+
+    public Node getNode()
+    {
+        return node;
+    }
+
+    public void setNode(Node node)
+    {
+        this.node = node;
+    }
+
+    public void setFilter(Predicate predicate)
+    {
+        this.filter = predicate;
+    }
+
+    public void setOrder(Comparator comparator)
+    {
+        this.order = comparator;
+    }
+
+    /**
+     * Get the children for the given node. <br>
+     * Filtered and sorted if necesary.
+     * 
+     * @param node
+     * @return @throws
+     *         DepthExceededException
+     */
+    protected Iterator getChildren(Node node) throws DepthExceededException,
+            RepositoryException
+    {
+        // Check depth
+        if (node.getDepth() - this.node.getDepth() >= this.depth )
+            throw new DepthExceededException();
+
+        Iterator children = node.getNodes();
+
+        // Sort
+        if (this.order != null)
+        {
+            List l = IteratorUtils.toList(children);
+            Collections.sort(l, this.order);
+            children = l.iterator();
+        }
+
+        return children;
+    }
+
+    public void traverse() throws RepositoryException
+    {
+        this.nodes.clear();
+        this.internalTraverse();
+    }
+
+    protected abstract void internalTraverse() throws RepositoryException;
+
+    public void setParameter(Object parameter)
+    {
+        this.parameter = parameter;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AbstractTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AncestorsTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AncestorsTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AncestorsTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AncestorsTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * This Traverser collect the parent nodes.<br>
+ * It may be useful for building the breadcrumb.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class AncestorsTraverser extends AbstractTraverser
+{
+    /**
+     * Visit the ancestors recursively
+     * 
+     * @param myNode
+     * @throws RepositoryException
+     */
+    private void ancestor(Node myNode) throws RepositoryException
+    {
+        if (myNode.getDepth() > this.node.getDepth() - this.depth
+                && myNode.getDepth() > 0)
+        {
+            this.ancestor(myNode.getParent());
+        }
+        this.nodes.add(myNode);
+    }
+
+    protected void internalTraverse() throws RepositoryException
+    {
+        this.ancestor(super.node);
+    }
+
+    /** Parameters are ignored */
+    public void setParameter(Object parameter)
+    {
+        // Any parameter is ignored.
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/AncestorsTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/DepthExceededException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/DepthExceededException.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/DepthExceededException.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/DepthExceededException.java Fri May 20 01:13:01 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+/**
+ * Depth exceeded
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce</a>
+ */
+class DepthExceededException extends Exception 
+{
+
+    /**
+     * Comment for <code>serialVersionUID</code>
+     */
+    private static final long serialVersionUID = 3834024770894443576L;
+    
+    /**
+     * 
+     */
+    public DepthExceededException()
+    {
+        super();
+    }
+    /**
+     * @param message
+     */
+    public DepthExceededException(String message)
+    {
+        super(message);
+    }
+    /**
+     * @param message
+     * @param cause
+     */
+    public DepthExceededException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+    /**
+     * @param cause
+     */
+    public DepthExceededException(Throwable cause)
+    {
+        super(cause);
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/DepthExceededException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodeTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodeTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodeTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodeTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.Iterator;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <p>
+ * ExpandedNodeTraverser collects only the children of the ancestors in the path from
+ * the root node to the target node.
+ * </p>
+ * <p>
+ * The parameter must be a Node instance or a String with the path to the target
+ * Node.
+ * </p>
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class ExpandedNodeTraverser extends AbstractTraverser
+{
+    private static Log log = LogFactory.getLog(ExpandedNodeTraverser.class);
+
+    /**
+     * Preorder strategy recusively only for parent Nodes.
+     * 
+     * @param node
+     * @throws RepositoryException
+     */
+    private void preorder(Node myNode) throws RepositoryException
+    {
+        visit(myNode);
+
+        if (!this.isAncestor(myNode) && !this.getTarget().isSame(myNode))
+        {
+            return;
+        }
+
+        try
+        {
+            Iterator iter = this.getChildren(myNode);
+            while (iter.hasNext())
+            {
+                this.preorder((Node) iter.next());
+            }
+        } catch (DepthExceededException e)
+        {
+            log.error("Depth should never be exceeded in this traverser.", e);
+        }
+    }
+
+    /**
+     *  
+     */
+    protected void internalTraverse() throws RepositoryException
+    {
+        // Override depth.
+        this.depth = Integer.MAX_VALUE;
+        this.preorder(node);
+    }
+
+    /**
+     * Validates the parameter. <br>
+     * It only accepts the target Node. <br>
+     * The path (String) or a Node instance;
+     * 
+     * @throws IllegalArgumentException
+     */
+    public void setParameter(Object param)
+    {
+        if (param == null
+                || (!(param instanceof String) && !(param instanceof Node)))
+        {
+            throw new IllegalArgumentException(
+                    "The parameter is not a Node. Class: " + param);
+        }
+
+        if (param instanceof String)
+        {
+            try
+            {
+                Node node = this.node.getSession().getRootNode().getNode(
+                        (String) param);
+                this.parameter = node;
+            } catch (PathNotFoundException e)
+            {
+                throw new IllegalArgumentException("No node in " + parameter);
+            } catch (RepositoryException e)
+            {
+                log.error("Unable to get node" + e.getMessage(), e);
+            }
+        } else
+        {
+            this.parameter = param;
+        }
+
+    }
+
+    private Node getTarget()
+    {
+        return (Node) this.parameter;
+    }
+
+    private boolean isAncestor(Node ancestor) throws ItemNotFoundException,
+            AccessDeniedException, RepositoryException
+    {
+        if (ancestor.getDepth() >= this.getTarget().getDepth())
+        {
+            return false;
+        }
+        return this.getTarget().getAncestor(ancestor.getDepth()).isSame(
+                ancestor);
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodeTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodesTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodesTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodesTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodesTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This Traverser collects the children of the ancestors in the path from the
+ * root node to any of the target nodes. <br>
+ * The parameter must be a Collection or Iterator containing the target nodes.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class ExpandedNodesTraverser extends AbstractTraverser
+{
+
+    private static Log log = LogFactory.getLog(ExpandedNodesTraverser.class);
+
+    /**
+     * Preorder strategy recusively only for parent Nodes.
+     * 
+     * @param node
+     * @throws RepositoryException
+     */
+    private void preorder(Node myNode) throws RepositoryException
+    {
+        visit(myNode);
+
+        
+        if (!this.isAncestor(myNode) && !this.getTarget().contains(myNode))
+        {
+            return;
+        }
+
+        try
+        {
+            Iterator iter = this.getChildren(myNode);
+            while (iter.hasNext())
+            {
+                this.preorder((Node) iter.next());
+            }
+        } catch (DepthExceededException e)
+        {
+            log.error("Depth should never be exceeded in this traverser.", e);
+        }
+    }
+
+    /**
+     * @inheritDoc
+     */
+    protected void internalTraverse() throws RepositoryException
+    {
+        // Override depth.
+        this.depth = Integer.MAX_VALUE;
+        this.preorder(node);
+    }
+
+    /**
+     * Sets the parameter. <br>
+     * It only accepts Collection or Iterator instances.<br>
+     * The path (String) or a Node instance;
+     * 
+     * @throws IllegalArgumentException
+     */
+    public void setParameter(Object param)
+    {
+
+        if (param == null
+                || (!(param instanceof Collection) && !(param instanceof Iterator)))
+        {
+            throw new IllegalArgumentException(
+                    "The parameter is not a Collection or Iterator. " + param);
+        }
+        if (param instanceof Collection)
+        {
+            this.parameter = (Collection) param;
+        } else if (param instanceof Iterator)
+        {
+            this.parameter = IteratorUtils.toList((Iterator) param);
+        }
+    }
+
+    /**
+     * Checks if the node is ancestor of any af the target nodes
+     * 
+     * @param ancestor
+     * @return @throws
+     *         RepositoryException
+     * @throws AccessDeniedException
+     * @throws ItemNotFoundException
+     */
+    private boolean isAncestor(Node ancestor) throws ItemNotFoundException,
+            AccessDeniedException, RepositoryException
+    {
+        Iterator iter = this.getTarget().iterator();
+        while (iter.hasNext())
+        {
+            Node target = (Node) iter.next();
+            if (this.isAncestor(ancestor, target))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Checks if the node is ancestor of the given target node.
+     * 
+     * @param ancestor
+     * @param target
+     * @return @throws
+     *         RepositoryException
+     * @throws AccessDeniedException
+     * @throws ItemNotFoundException
+     */
+    private boolean isAncestor(Node ancestor, Node target)
+            throws ItemNotFoundException, AccessDeniedException,
+            RepositoryException
+    {
+        if (ancestor.getDepth() >= target.getDepth())
+        {
+            return false;
+        }
+        return target.getAncestor(ancestor.getDepth()).isSame(ancestor);
+    }
+
+    /**
+     * Get the collection of target nodes.
+     * 
+     * @return
+     */
+    private Collection getTarget()
+    {
+        return (Collection) this.parameter;
+    }
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/ExpandedNodesTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/LevelByLevelTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/LevelByLevelTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/LevelByLevelTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/LevelByLevelTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Level by level traverse strategy 
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class LevelByLevelTraverser extends AbstractTraverser
+{
+    private Map levels = new HashMap() ;
+    
+
+    /**
+     * Traverse the node children tree
+     * 
+     * @throws RepositoryException
+     */
+    protected void internalTraverse() throws RepositoryException
+    {
+        throw new UnsupportedOperationException();
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/LevelByLevelTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PostorderTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PostorderTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PostorderTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PostorderTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.IteratorUtils;
+
+/**
+ * Postorder traverse strategy
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public class PostorderTraverser extends AbstractTraverser
+{
+
+    /**
+     * Postorder traversal
+     * 
+     * @param node
+     * @throws RepositoryException
+     */
+    private void postorder(Node node) throws RepositoryException
+    {
+        try
+        {
+            Object[] nodes = IteratorUtils.toArray(this.getChildren(node)) ;
+            CollectionUtils.reverseArray(nodes);
+            Iterator iter = IteratorUtils.arrayIterator(nodes);
+            while (iter.hasNext())
+            {
+                this.postorder((Node) iter.next());
+            }
+        } catch (DepthExceededException e)
+        {
+            // Do nothing
+        }
+        visit(node);
+    }
+
+    /**
+     * Traverse the node children tree
+     * 
+     * @throws RepositoryException
+     */
+    protected void internalTraverse() throws RepositoryException
+    {
+        this.postorder(this.node);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PostorderTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PreorderTraverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PreorderTraverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PreorderTraverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PreorderTraverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Preorder traverse strategy 
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce</a>
+ */
+public class PreorderTraverser extends AbstractTraverser
+{
+    
+    /**
+     * Preorder traversal
+     * 
+     * @param node
+     * @throws RepositoryException
+     */
+    private void preorder(Node node) throws RepositoryException
+    {
+        visit(node);
+        try
+        {
+            Iterator iter = this.getChildren(node);
+            while (iter.hasNext())
+            {
+                this.preorder((Node) iter.next());
+            }
+        } catch (DepthExceededException e)
+        {
+            // Do nothing
+        }
+    }
+    
+    /**
+     * Traverse the node children tree
+     * @throws RepositoryException
+     */
+    protected void internalTraverse() throws RepositoryException
+    {
+        this.preorder(this.node);
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/PreorderTraverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/Traverser.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/Traverser.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/Traverser.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/Traverser.java Fri May 20 01:13:01 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.traverser;
+
+import java.util.Collection;
+import java.util.Comparator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.collections.Predicate;
+
+/**
+ * Traverser implementations are responsible of collecting nodes from the root
+ * node base on custom strategies.
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface Traverser
+{
+
+    /**
+     * Parameter that optionally affect the Traverser behaviour. <br>
+     * 
+     * @param expression
+     */
+    public void setParameter(Object parameter);
+
+    /**
+     * Set a node filter
+     * 
+     * @param node
+     */
+    public void setFilter(Predicate predicate);
+
+    /**
+     * Set the comparator to order the nodes
+     * 
+     * @param node
+     */
+    public void setOrder(Comparator comparator);
+
+    /**
+     * Set the node to traverse from
+     * 
+     * @param node
+     */
+    public void setNode(Node node);
+
+    /**
+     * Set the depth
+     * 
+     * @param depth
+     */
+    public void setDepth(int depth);
+
+    /**
+     * Perform traverse
+     */
+    public void traverse() throws RepositoryException;
+
+    /**
+     * Get the nodes
+     * 
+     * @return
+     */
+    public Collection getNodes();
+
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/Traverser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/package.html?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/package.html Fri May 20 01:13:01 2005
@@ -0,0 +1,3 @@
+<body>
+Contains Traverser interface and implementations.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/traverser/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/utils/JCRTagConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/utils/JCRTagConstants.java?rev=171077&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/utils/JCRTagConstants.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/utils/JCRTagConstants.java Fri May 20 01:13:01 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.
+ */
+package org.apache.jackrabbit.taglib.utils;
+
+/**
+ * JCR Taglib Constants
+ * 
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+public interface JCRTagConstants
+{
+    public static String JNDI_DEFAULT_REPOSITORY = "jcr/repositoryFactory";
+
+    public static String JNDI_BEAN_FACTORY = "jcr/beanFactory";
+
+    
+    public static String JNDI_ANON_USER = "jcr/login/anonuser";
+
+    public static String JNDI_ANON_PWD = "jcr/login/anonpwd";
+
+    // Bean factory Defaults 
+    public static String JNDI_DEFAULT_TEMPLATE_ENGINE = "jcr/template/engine/default";
+    
+    public static String JNDI_DEFAULT_TRAVERSER = "jcr/traverser/default";
+
+    public static String JNDI_DEFAULT_ITEM_FILTER = "jcr/filter/default";
+    
+    public static String JNDI_DEFAULT_ITEM_COMPARATOR = "jcr/comparator/default";
+
+    public static String JNDI_DEFAULT_SIZE_CALCULATOR = "jcr/size/default";
+    
+    public static String JNDI_DEFAULT_SIZE_FORMAT = "jcr/size/format/default";
+    
+    // Default keys
+    public static String KEY_SESSION = "jcrsession";
+    
+    public static String KEY_CD = "jcrcd";    
+    
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/utils/JCRTagConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native