Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/cd.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/cd.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/cd.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/cd.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,28 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Nodes Tag with default traverser

+ + + +

Current directory stored in the page Context

+

Depth = 1

+ + +
+
+
+ +

Depth = 2

+ + +
+
+
+ +

Current directory stored in the request

+ +
+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/cd.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/comparators.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/comparators.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/comparators.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/comparators.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,37 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Nodes Tag with default traverser

+Sorted by "item.name" + + + +

Descending

+ + + + + + + + + + + +
PathName
+ +

Ascending

+ + + + + + + + + + + +
PathName
+ + +
\ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/comparators.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/count.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/count.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/count.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/count.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,18 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Count Tag with default traverser

+ + +Child nodes of "/": + +

Depth = 0

+
+ +

Depth = 1

+
+ +

Depth = 2

+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/count.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/filters.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/filters.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/filters.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/filters.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,22 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Nodes Tag with default traverser

+Filtered by "item.name.equals('TestA')" + + + +

Depth = 2

+ + + + + + + + + + + +
PathName
+ +
\ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/filters.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/ifPresent.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/ifPresent.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/ifPresent.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/ifPresent.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,28 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

IfPresent tag

+ + + + + /TestA is present
+
+ + + /john is not present
+
+ + + Root is present
+
+ + + Property 'jcr:primaryType' is present in Root
+
+ + + Root is not present
+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/ifPresent.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/index.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/index.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/index.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/index.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,59 @@ + + + + + +

JCR taglib

+ +

Basic usage

+
    +
  1. + SessionTag.
    + jrc:session sets the boundaries of a JCR session. + It creates a Session and stores it in a page scope variable. +
  2. +
  3. + CdTag.
    + jrc:cd sets the current working directory. +
  4. +
  5. NodesTag
    + jrc:nodes iterates over all the traversed nodes from the given node. +
  6. +
  7. PropertiesTag
    + jcr:properties iterates over the properties of the given node. +
  8. +
  9. OutTag
    + jcr:out displays Node and property values through + the given template engine and template. +
  10. +
  11. SetTag
    + jcr:set stores the given node or property in a + page context scoped variable. +
  12. +
  13. CountTag
    + jcr:counts counts the nodes returned by the given + Traverser and writes the value. +
  14. +
  15. SizeTag
    + jcr:size Estimates the cumulative size of the nodes returned by the given + Traverser and writes the value. +
  16. +
  17. QueryTag
    + jcr:query Iterates over the query result nodes. +
  18. +
  19. IfPresentTag
    + jcr:ifPresent Conditional tag which evaluates a node existence. +
  20. +
  21. versionsTag
    + jcr:versions Iterates over the versions of the given node +
  22. +
+ +

Advanced usage

+
    +
  1. Test traversers
  2. +
  3. Test filters
  4. +
  5. Test comparators
  6. +
+ + \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/index.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/nodes.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/nodes.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/nodes.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/nodes.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,23 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Nodes Tag with default traverser

+ +

Depth = 0

+ + + +
+
+ +

Depth = 1

+ +
+
+ +

Depth = 2

+ +
+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/nodes.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/out.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/out.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/out.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/out.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,28 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Out

+ + + + + + + + + + + + + + + + + + + +
NodePropertyNode: Template engine outputProperty: Template engine output
+ + + +
+
\ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/out.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/properties.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/properties.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/properties.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/properties.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,35 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Properties

+ + + Session:
+ + + + + + + + + + + + + + + + + +
PathNameTypeValue
+ + + +   + + + + +   +
+
Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/properties.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/query.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/query.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/query.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/query.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,22 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Query tag

+ +<% + String q = "SELECT * FROM nt:base WHERE jcr:path LIKE '/TestA/%'" ; +%> + + + +

SQL: <%=q%>

+ + Node:
+
+ +

XPATH: //*

+ + Node:
+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/query.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/session.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/session.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/session.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/session.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,7 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> + +

Session

+ + +Hello session + Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/session.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/set.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/set.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/set.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/set.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,11 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Set

+ + + + node:
+ + Node type: + +
\ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/set.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/size.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/size.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/size.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/size.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,34 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Size Tag with default traverser

+ + + +

Size of root node:

+ bytes
+ +
+
+ +

Size of testA node

+ bytes
+ +
+
+ +

Size of A-L2 node

+ bytes
+ +
+
+ +

Size of testA node with depth=1

+ bytes
+ +

Size of testB node

+ bytes
+ +
+
+ +
Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/size.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/traversers.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/traversers.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/traversers.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/traversers.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,80 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Traversers

+ + + +

Preorder traverser

+ +
+
+ +

Postorder traverser

+ +
+
+ +

AncestorTraverser (breadcrumb) from node "Apples/Apple1/Nice apple1"

+ + / + +
+ +

ExpandedNodeTraverser (navigator) to node "Apples/Apple1"

+

Depth is ignored in this Traverser implementation

+ + + +    + + /
+
+
+ +

+ ExpandedNodesTraverser (navigator with multiple expanded nodes)
+ to node "/Apples/Apple1" and
+ to node "/Oranges" +

+

Depth is ignored in this Traverser implementation

+ + + + +<% + java.util.Collection c = new java.util.ArrayList() ; + c.add(pageContext.getAttribute("apple1")); + c.add(pageContext.getAttribute("oranges")); + pageContext.setAttribute("target", c); +%> + + +    + + /
+
+ + +
Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/traversers.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/versions.jsp URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/versions.jsp?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/versions.jsp (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/versions.jsp Fri May 20 01:13:01 2005 @@ -0,0 +1,12 @@ +<%@taglib uri="/taglib/jcr" prefix="jcr" %> +<%@taglib uri="/taglib/c" prefix="c" %> +

Versions

+ + + + +
+
+ +
+ Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/examples/web/versions.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CdTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CdTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CdTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CdTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,110 @@ +/* + * 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.Item; +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.servlet.jsp.JspException; + +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; + +/** + * Changes the current directory. Nested tags must read the paths relative to + * this node.
+ * + * @author Edgar Poce + */ +public class CdTag extends SetTag +{ + + /** + * Constructor + */ + public CdTag() + { + super(); + this.init(); + } + + /** + * Init + */ + private void init() + { + this.var = JCRTagConstants.KEY_CD; + } + + /** + * @inheritDoc + */ + public int doEndTag() throws JspException + { + // Restore the previous attribute + pageContext.removeAttribute(this.var, this.scope); + return super.doEndTag(); + } + + /** + * @inheritDoc + */ + public int doStartTag() throws JspException + { + super.doStartTag(); + return EVAL_BODY_INCLUDE; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + + /** + * Sets the node + * + * @param node + */ + public void setNode(String node) + { + this.item = node; + } + + /** + * Retrieve and validate the Item. It must be a Node instance. + * + * @return curren working node + * @throws JspException + * @throws RepositoryException + */ + protected Item getItem() throws JspException, RepositoryException + { + Item item = super.getItem(); + + // Validate + if (!(item instanceof Node)) + { + throw new JspException("The referenced item is not a Node instance"); + } + + return item; + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CdTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CountTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CountTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CountTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CountTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,276 @@ +/* + * 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 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.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; + +/** + *

+ * Counts the nodes returned by the given Traverser and writes + * the value. + *

+ * + * @author Edgar Poce + */ +public class CountTag extends TagSupport +{ + private static Log log = LogFactory.getLog(CountTag.class); + + public static String TAG_NAME = "count"; + + /** + * 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.
+ * e.g. /mynode
+ * 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; + + /** + * Constructor + */ + public CountTag() + { + 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; + } + + /** + * Set 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; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.jsp.tagext.Tag#release() + */ + 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); + + } + + /** + * Sets the traverser parameter. The paremeter is Traverser specific. + * + * @param traverserParam + */ + public void setTraverserParam(String traverserParam) + { + this.traverserParam = traverserParam; + } + + /** + * Gets the traverser instance + * + * @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; + } + + /* + * (non-Javadoc) + * + * @see javax.servlet.jsp.tagext.Tag#doEndTag() + */ + 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(); + // Retrieve Nodes + pageContext.getOut().write( + String.valueOf(traverser.getNodes().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; + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/CountTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/IfPresentTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/IfPresentTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/IfPresentTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/IfPresentTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,177 @@ +/* + * 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.Item; +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.jstl.core.ConditionalTagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; + +/** + * Conditional tag that evaluates the existence of the given node. + * + * @author Edgar Poce + */ +public class IfPresentTag extends ConditionalTagSupport +{ + /** Logger */ + private static Log log = LogFactory.getLog(IfPresentTag.class); + + /** Tag Name */ + public static String TAG_NAME = "set"; + + /** + * Session + */ + private String session; + + /** + * expression or full path. + */ + private String item; + + /** + * Property. + */ + private String property; + + /** + * Expected evaluation result (true | false) + */ + private boolean value = true; + + /** + * Constructor + */ + public IfPresentTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + protected boolean condition() throws JspTagException + { + boolean present = false; + + try + { + Session jcrSession = JCRTagUtils.getSession(TAG_NAME, this.session, + this, this.pageContext); + try + { + Item i = JCRTagUtils.getItem(TAG_NAME, this.item, this, + this.pageContext, jcrSession); + + // If the property is set + if (this.property != null) + { + Node n = (Node) i; + i = n.getProperty(this.property); + } + + present = true; + } catch (PathNotFoundException e) + { + // Do nothing + } + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } catch (JspException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } + + return (present == this.value); + } + + /** + * @inheritDoc + */ + protected void init() + { + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + this.item = null; + this.value = true; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + + /** + * Sets the item + * + * @param item + */ + public void setItem(String item) + { + this.item = item; + } + + /** + * Sets the session + * + * @param session + */ + public void setSession(String session) + { + this.session = session; + } + + /** + * Sets the value + * + * @param value + */ + public void setValue(boolean value) + { + this.value = value; + } + + /** + * Sets the property. This value can be set only when the item is a node. + * + * @param property + */ + public void setProperty(String property) + { + this.property = property; + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/IfPresentTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/NodesTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/NodesTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/NodesTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/NodesTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,369 @@ +/* + * 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.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.jstl.core.LoopTagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.comparator.ItemComparator; +import org.apache.jackrabbit.taglib.filter.ItemFilter; +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; + +/** + * Iterates through the traversed nodes from the given node + * + * @author Edgar Poce + */ +public class NodesTag extends LoopTagSupport +{ + private static Log log = LogFactory.getLog(NodesTag.class); + + public static String TAG_NAME = "nodes"; + + /** + * Name of the scoped variable where the jcr session is stored. + */ + private String session; + + /** + * JSTL expression referencing a node or or full path.
+ * e.g. /mynode
+ * or ${mynode} + */ + private String node; + + /** + * NodeComparator ID + */ + private String sortID; + + /** + * Expression used by the NodeComparator to evaluate nodes.
+ * The evaluation must return a Comparable instance.
+ */ + private String sortExp; + + /** + * Sort order
+ * true / false + */ + private boolean ascending = true; + + /** + * Traverser ID. + */ + private String traverserID; + + /** + * Parameter 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; + + /** + * Children Nodes + */ + private Iterator nodes; + + /** + * + */ + public NodesTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + protected boolean hasNext() throws JspTagException + { + return nodes.hasNext(); + } + + /** + * @inheritDoc + */ + protected Object next() throws JspTagException + { + return nodes.next(); + } + + /** + * @inheritDoc + */ + protected void prepare() throws JspTagException + { + try + { + // get the node + Node jcrNode = this.getNode(); + + // Configure traverse strategy + Traverser traverser = (Traverser) JCRTagUtils + .getBean(this.traverserID); + traverser.setDepth(this.traverserDepth); + traverser.setNode(jcrNode); + traverser.setParameter(this.getTraverserParam()); + + // Sort + if (this.sortExp != null) + { + ItemComparator order = (ItemComparator) JCRTagUtils + .getBean(this.sortID); + order.setExpression(this.sortExp); + order.setAscending(this.ascending); + traverser.setOrder(order); + } + + // Filter + if (this.filterExp != null) + { + ItemFilter predicate = (ItemFilter) JCRTagUtils + .getBean(this.filterID); + predicate.setExpression(this.filterExp); + traverser.setFilter(predicate); + } + + // Traverse nodes + traverser.traverse(); + + // Retrieve Nodes + this.nodes = traverser.getNodes().iterator(); + + } 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 (JspException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } + } + + /** + * Sets the order ( ascending | descending ) + * + * @param ascending + */ + public void setAscending(boolean ascending) + { + this.ascending = ascending; + } + + /** + * 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 sort expression + * + * @param sortExp + */ + public void setSortExp(String sortExp) + { + this.sortExp = sortExp; + } + + /** + * Sets the sort ID + * + * @param sortJNDI + */ + public void setSortID(String sortJNDI) + { + this.sortID = sortJNDI; + } + + /** + * 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.ascending = true; + + this.filterExp = null; + this.filterID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_ITEM_FILTER); + + this.node = "/"; + this.nodes = null; + + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + + this.sortExp = null; + this.sortID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_ITEM_COMPARATOR); + + this.traverserDepth = 1; + this.traverserID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_TRAVERSER); + + } + + /** + * Sets the Traverer 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; + } + + /** + * Retrieves the node + * + * @return @throws + * JspException + * @throws RepositoryException + * @throws PathNotFoundException + */ + protected Node getNode() throws PathNotFoundException, JspException, + RepositoryException + { + // Get the session + Session jcrSession = JCRTagUtils.getSession(TAG_NAME, this.session, + this, this.pageContext); + + return (Node) JCRTagUtils.getItem(TAG_NAME, this.node, this, + this.pageContext, jcrSession); + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/NodesTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/OutTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/OutTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/OutTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/OutTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,197 @@ +/* + * 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.Item; +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.tagext.TagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.template.TemplateEngine; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; + +/** + * Displays Node and property values with the given template engine. + * + * @author Edgar Poce + */ +public class OutTag extends TagSupport +{ + private static Log log = LogFactory.getLog(OutTag.class); + + /** Tag Name */ + public static String TAG_NAME = "out"; + + /** + * Name of the scoped variable where the jcr session is stored. If not set + * then JCRTagConstants.KEY_SESSION is used. + */ + private String session; + + /** + * expression or full path. + */ + private String item; + + /** + * Property of the given node + */ + private String property; + + /** + * Template engine id + */ + private String templateEngineID; + + /** + * Template name + */ + private String template; + + /** + * Constructor + */ + public OutTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + public int doEndTag() throws JspException + { + try + { + // Get a session + Session s = JCRTagUtils.getSession(TAG_NAME, this.session, this, + this.pageContext); + + // Get the node + Item item = JCRTagUtils.getItem(TAG_NAME, this.item, this, + this.pageContext, s); + + // If the property is set + if (this.property != null) + { + Node n = (Node) item; + item = n.getProperty(this.property); + } + + // Get the template Engine + TemplateEngine engine = (TemplateEngine) JCRTagUtils + .getBean(this.templateEngineID); + engine.setTemplate(this.template); + engine.write(this.pageContext, item); + + } catch (PathNotFoundException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspException(msg, e); + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspException(msg, e); + } + return EVAL_PAGE; + } + + /** + * Sets the item + * + * @param item + */ + public void setItem(String item) + { + this.item = item; + } + + /** + * Sets the session + * + * @param session + */ + public void setSession(String session) + { + this.session = session; + } + + /** + * Init + * + */ + private void init() + { + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + + this.item = null; + + this.property = null; + + this.templateEngineID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_TEMPLATE_ENGINE); + this.template = null; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + + /** + * Sets the template + * + * @param template + */ + public void setTemplate(String template) + { + this.template = template; + } + + /** + * Sets the template engine ID + * + * @param templateEngine + */ + public void setTemplateEngineID(String templateEngine) + { + this.templateEngineID = templateEngine; + } + + /** + * Sets the property. This value can be set only when the item is a node. + * + * @param property + */ + public void setProperty(String property) + { + this.property = property; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/OutTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/PropertiesTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/PropertiesTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/PropertiesTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/PropertiesTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,275 @@ +/* + * 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.util.Collections; +import java.util.Iterator; +import java.util.List; + +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.jstl.core.LoopTagSupport; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.IteratorUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.comparator.ItemComparator; +import org.apache.jackrabbit.taglib.filter.ItemFilter; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; + +/** + * Iterates over the properties of the given node. + * + * @author Edgar Poce + */ +public class PropertiesTag extends LoopTagSupport +{ + /** logger */ + private static Log log = LogFactory.getLog(PropertiesTag.class); + + /** tag name */ + public static String TAG_NAME = "properties"; + + /** + * 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 or full path.
+ * e.g. /mynode
+ * or ${mynode} + */ + private String node; + + /** + * JNDI address where the ItemComparator is bound.
+ * e.g. myproperty + */ + private String sortID; + + /** + * Expression used by the ItemComparator
+ * The evaluation must return a Comparable instance.
+ */ + private String sortExp; + + /** + * Sort order
+ * true / false + */ + private boolean ascending = true; + + /** + * JNDI address where the NodePredicate is bound. + */ + private String filterID; + + /** + * Expression used by the NodePredicate to evaluate nodes. The evaluation + * must return a Boolean instance. + */ + private String filterExp; + + /** + * Properties + */ + private Iterator properties; + + /** + * Constructor + */ + public PropertiesTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + protected boolean hasNext() throws JspTagException + { + return this.properties.hasNext(); + } + + /** + * @inheritDoc + */ + protected Object next() throws JspTagException + { + return this.properties.next(); + } + + /** + * @inheritDoc + */ + protected void prepare() throws JspTagException + { + try + { + // get a session + Session jcrSession = JCRTagUtils.getSession(TAG_NAME, this.session, this, + this.pageContext); + + // get the node + Node node = (Node) JCRTagUtils.getItem(TAG_NAME, this.node, this, + this.pageContext, jcrSession); + + // Get the properties + List props = IteratorUtils.toList(node.getProperties()); + + // Sort + if (this.sortExp != null) + { + ItemComparator order = (ItemComparator) JCRTagUtils + .getBean(this.sortID); + order.setExpression(this.sortExp); + order.setAscending(this.ascending); + Collections.sort(props, order); + } + + // Filter + if (this.filterExp != null) + { + ItemFilter predicate = (ItemFilter) JCRTagUtils + .getBean(this.filterID); + predicate.setExpression(this.filterExp); + CollectionUtils.filter(props, predicate); + } + + // get iterator + this.properties = props.iterator(); + } catch (PathNotFoundException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } catch (JspException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } + } + + /** + * Set the order ( ascending | descending) + * @param ascending + */ + public void setAscending(boolean ascending) + { + this.ascending = ascending; + } + + /** + * 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 sort expression + * @param sortExp + */ + public void setSortExp(String sortExp) + { + this.sortExp = sortExp; + } + + /** + * Sets the sortID + * @param sortID + */ + public void setSortID(String sortID) + { + this.sortID = sortID; + } + + /** + * init + * + */ + private void init() + { + this.ascending = true; + + this.filterExp = null; + this.filterID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_ITEM_FILTER); + + this.node = "/"; + + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + + this.sortExp = null; + this.sortID = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_DEFAULT_ITEM_COMPARATOR); + + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/PropertiesTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/QueryTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/QueryTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/QueryTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/QueryTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,211 @@ +/* + * 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.util.Iterator; + +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.query.Query; +import javax.jcr.query.QueryResult; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspTagException; +import javax.servlet.jsp.jstl.core.LoopTagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; +import org.apache.taglibs.standard.tag.el.core.ExpressionUtil; + +/** + *

+ * Iterates over the nodes returned by the given query. + *

+ * + * @author Edgar Poce + */ +public class QueryTag extends LoopTagSupport +{ + /** logger */ + private static Log log = LogFactory.getLog(QueryTag.class); + + /** tag name */ + public static String TAG_NAME = "query"; + + /** + * Name of the scoped variable where the jcr session is stored. If not set + * then JCRTagConstants.KEY_SESSION is used. + */ + private String session; + + /** + * Query + */ + private String stmt; + + /** + * Query type ( SQL | XPATH ) + */ + private String lang; + + /** + * Children Nodes + */ + private Iterator nodes; + + /** + * Constructor + */ + public QueryTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + protected boolean hasNext() throws JspTagException + { + return nodes.hasNext(); + } + + /** + * @inheritDoc + */ + protected Object next() throws JspTagException + { + return nodes.next(); + } + + /** + * @inheritDoc + */ + protected void prepare() throws JspTagException + { + try + { + // get a session + Session s = JCRTagUtils.getSession(TAG_NAME, this.session, this, + this.pageContext); + + Query q = s.getWorkspace().getQueryManager().createQuery( + this.getStmt(), this.getLang()); + + QueryResult qr = q.execute(); + + this.nodes = qr.getNodes(); + + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspTagException(msg); + } catch (JspException e) + { + String msg = JCRTagUtils.getMessage(e); + log.warn(msg); + throw new JspTagException(msg); + } + } + + /** + * Sets the session + * + * @param session + */ + public void setSession(String session) + { + this.session = session; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + + /** + * init + * + */ + private void init() + { + this.nodes = null; + + this.stmt = null; + + this.lang = "xpath"; + + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + + } + + /** + * @return the query + * @throws JspException + */ + private String getStmt() throws JspException + { + return (String) ExpressionUtil.evalNotNull(TAG_NAME, "query", + this.stmt, String.class, this, this.pageContext); + } + + /** + * Sets the query + * + * @param query + */ + public void setStmt(String query) + { + this.stmt = query; + } + + /** + * Gets the query type + * + * @return @throws + * JspTagException + */ + private String getLang() throws JspTagException + { + if (this.lang.equalsIgnoreCase("xpath")) + { + return Query.XPATH; + } else if (this.lang.equalsIgnoreCase("sql")) + { + return Query.SQL; + } else + { + throw new JspTagException("No such Query type. " + this.lang); + } + } + + /** + * Sets the query type + * + * @param type + */ + public void setLang(String language) + { + this.lang = language; + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/QueryTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SessionTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SessionTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SessionTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SessionTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,298 @@ +/* + * 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.security.Principal; + +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; + +/** + *

+ * Creates a session stores it in a page scope variable. + *

+ * + * @author Edgar Poce + */ +public class SessionTag extends TagSupport +{ + /** logger */ + private static Log log = LogFactory.getLog(SessionTag.class); + + /** + * Session instance + */ + private Session session; + + /** + * Name of the jndi address of a repository other than the default. + */ + private String repositoryJNDI = JCRTagConstants.JNDI_DEFAULT_REPOSITORY;; + + /** + * Workspace name. + */ + private String workspace; + + /** + * Name of the target page context variable where the session will be + * stored. + */ + private String var; + + /** + * Name of the user for loggin in.
+ * If no user is set then the request.getUserPrincipal is used.
+ * If no user is logged in the default user is used (See config options). + */ + private String user; + + /** + * User's password.
+ * Password used for creating a new JCR Session. + */ + private String password; + + /** + * previous session. (nested sessions) + */ + private Object previousSession; + + /** + * Constructor and initialization + */ + public SessionTag() + { + super(); + this.init(); + } + + /** + * Init + */ + private void init() + { + if (log.isDebugEnabled()) + { + log.debug("Cleaning state"); + } + this.password = null; + this.repositoryJNDI = JCRTagConstants.JNDI_DEFAULT_REPOSITORY; + this.var = JCRTagConstants.KEY_SESSION; + this.user = null; + this.workspace = null; + this.session = null; + } + + /** + * Sets the password + * + * @param pwd + */ + public void setPassword(String pwd) + { + this.password = pwd; + } + + /** + * Sets the repository JNDI address + * + * @param repository + */ + public void setRepositoryJNDI(String repository) + { + this.repositoryJNDI = repository; + } + + /** + * Sets the variable where the Session will be stored + * + * @param target + */ + public void setVar(String target) + { + this.var = target; + } + + /** + * Sets the user + * + * @param user + */ + public void setUser(String user) + { + this.user = user; + } + + /** + * Sets the workspace + * + * @param workspace + */ + public void setWorkspace(String workspace) + { + this.workspace = workspace; + } + + /** + * @inheritDoc + */ + public int doEndTag() throws JspException + { + // Restore the previous session (if any) + if (this.previousSession != null) + { + pageContext.setAttribute(this.var, this.previousSession); + this.previousSession=null ; + } else { + this.pageContext.removeAttribute(this.var, PageContext.PAGE_SCOPE); + } + + // Logout + session.logout(); + + if (log.isDebugEnabled()) + { + log.debug("logged out"); + } + + // Return + return EVAL_PAGE; + } + + /** + * @inheritDoc + */ + public int doStartTag() throws JspException + { + this.previousSession = pageContext.getAttribute(this.var); + + // Get the repository + Repository repo = (Repository) JCRTagUtils.lookup(this.repositoryJNDI); + + // Get the session + try + { + if (this.workspace == null) + { + session = repo.login(this.getCredentials()); + } else + { + session = repo.login(this.getCredentials(), this.workspace); + } + if (log.isDebugEnabled()) + { + log.debug("logged in"); + } + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspException(msg, e); + } + + // Store the session in the page scope + pageContext.setAttribute(this.var, session); + + // Return + return EVAL_BODY_INCLUDE; + } + + /** + *

+ * Create credentials + *

+ *
    + *
  1. Try to create credentials for the given user (user and pwd)
  2. + *
  3. Try to create credentials for the logged user (logged user and no + * pwd)
  4. + *
  5. Try to create credentials for anonymous user (JNDI config)
  6. + *
+ * + * @return @throws + * JspException + */ + private SimpleCredentials getCredentials() throws JspException + { + // Session credentials + SimpleCredentials cred = null; + + // Try to create credentials for the given user + if (this.user != null) + { + if (this.password == null) + { + cred = new SimpleCredentials(this.user, "".toCharArray()); + } else + { + cred = new SimpleCredentials(this.user, this.password + .toCharArray()); + } + } + + // Try to create credentials for the logged user + if (cred == null) + { + Principal p = ((HttpServletRequest) this.pageContext.getRequest()) + .getUserPrincipal(); + if (p != null) + { + cred = new SimpleCredentials(p.getName(), "".toCharArray()); + } + } + + // Try to create credentials for anonymous user + if (cred == null) + { + String usr = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_ANON_USER); + + String pwd = (String) JCRTagUtils + .lookup(JCRTagConstants.JNDI_ANON_PWD); + + if (usr == null || pwd == null) + { + log.error("Configure user name and password " + + "for anonymous user properly"); + } + cred = new SimpleCredentials(usr, pwd.toCharArray()); + } + + return cred; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SessionTag.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SetTag.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SetTag.java?rev=171077&view=auto ============================================================================== --- incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SetTag.java (added) +++ incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SetTag.java Fri May 20 01:13:01 2005 @@ -0,0 +1,201 @@ +/* + * 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.Item; +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.PageContext; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.taglib.utils.JCRTagConstants; +import org.apache.jackrabbit.taglib.utils.JCRTagUtils; +import org.apache.taglibs.standard.tag.common.core.Util; + +/** + * Stores the given node or property in a scoped variable. + * + * @author Edgar Poce + */ +public class SetTag extends TagSupport +{ + /** logger */ + private static Log log = LogFactory.getLog(SetTag.class); + + /** Tag Name */ + public static String TAG_NAME = "set"; + + /** + * Name of the scoped variable where the jcr session will be stored. If not set + * then JCRTagConstants.KEY_SESSION is used. + */ + protected String session; + + /** + * Item + */ + protected String item; + + /** + * Property + */ + private String property; + + /** + * Scoped variable where the jcr Item will be stored + */ + protected String var; + + /** + * Scope + */ + protected int scope; + + /** + * Constructor + */ + public SetTag() + { + super(); + this.init(); + } + + /** + * @inheritDoc + */ + public int doEndTag() throws JspException + { + return EVAL_PAGE; + } + + /** + * Sets the item + * + * @param item + */ + public void setItem(String item) + { + this.item = item; + } + + /** + * Sets the session + * + * @param session + */ + public void setSession(String session) + { + this.session = session; + } + + /** + * init + */ + private void init() + { + this.session = "${" + JCRTagConstants.KEY_SESSION + "}"; + this.item = null; + this.scope = PageContext.PAGE_SCOPE; + } + + /** + * @inheritDoc + */ + public void release() + { + super.release(); + this.init(); + } + + /** + * Sets the variable name where the Item will be stored. + * + * @param var + */ + public void setVar(String var) + { + this.var = var; + } + + /** + * @inheritDoc + */ + public int doStartTag() throws JspException + { + try + { + Item i = this.getItem(); + // If the property is set + if (this.property != null) + { + Node n = (Node) i; + i = n.getProperty(this.property); + } + this.pageContext.setAttribute(this.var, i, this.scope); + } catch (RepositoryException e) + { + String msg = JCRTagUtils.getMessage(e); + log.error(msg, e); + throw new JspException(msg, e); + } + return SKIP_BODY; + } + + /** + * Gets the item + * + * @return @throws + * JspException + * @throws RepositoryException + */ + protected Item getItem() throws JspException, RepositoryException + { + // Get a session + Session session = JCRTagUtils.getSession(TAG_NAME, this.session, this, + this.pageContext); + + // Get the item + Item item = JCRTagUtils.getItem(TAG_NAME, this.item, this, + this.pageContext, session); + + return item; + } + + /** + * Sets the property. This can be set only when the item is a node. + * + * @param property + */ + public void setProperty(String property) + { + this.property = property; + } + + /** + * Sets the scope + * + * @param scope + */ + public void setScope(String scope) + { + this.scope = Util.getScope(scope); + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/contrib/jcrtaglib/src/java/org/apache/jackrabbit/taglib/SetTag.java ------------------------------------------------------------------------------ svn:eol-style = native