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 [2/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/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" %>
+<h1>Nodes Tag with default traverser</h1>
+
+<jcr:session>
+
+<h3>Current directory stored in the page Context</h3>
+<h2>Depth = 1</h2>
+<jcr:cd node="/TestA">
+ <jcr:nodes node="A-L2" var="node" traverserDepth="1">
+ <c:out value="${node.path}"/><br>
+ </jcr:nodes>
+</jcr:cd>
+
+<h2>Depth = 2</h2>
+<jcr:cd node="/TestA">
+ <jcr:nodes node="A-L2" var="node" traverserDepth="2">
+ <c:out value="${node.path}"/><br>
+ </jcr:nodes>
+</jcr:cd>
+
+<h3>Current directory stored in the request</h3>
+<jcr:cd node="/TestA" scope="request">
+ <jcr:out item="A-L2"/><br>
+</jcr:cd>
+
+</jcr:session>
+
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" %>
+<h1>Nodes Tag with default traverser</h1>
+<font color="red">Sorted by "item.name"</font>
+
+<jcr:session>
+
+<h2>Descending</h2>
+<table border="1" cellpadding="5">
+<tr>
+ <TH>Path</TH>
+ <TH>Name</TH>
+</tr>
+<jcr:nodes node="/" var="node" traverserDepth="2" sortExp="item.name" ascending="false">
+<tr>
+ <TD><c:out value="${node.path}"/></TD>
+ <TD><c:out value="${node.name}"/></TD>
+</tr>
+</jcr:nodes>
+</table>
+
+<h2>Ascending</h2>
+<table border="1" cellpadding="5">
+<tr>
+ <TH>Path</TH>
+ <TH>Name</TH>
+</tr>
+<jcr:nodes node="/" var="node" traverserDepth="2" sortExp="item.name" ascending="true">
+<tr>
+ <TD><c:out value="${node.path}"/></TD>
+ <TD><c:out value="${node.name}"/></TD>
+</tr>
+</jcr:nodes>
+</table>
+
+
+</jcr:session>
\ 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" %>
+<h1>Count Tag with default traverser</h1>
+
+<jcr:session>
+Child nodes of "/":
+
+<h2>Depth = 0</h2>
+<jcr:count node="/" traverserDepth="0" /><br/>
+
+<h2>Depth = 1</h2>
+<jcr:count node="/" traverserDepth="1"/><br/>
+
+<h2>Depth = 2</h2>
+<jcr:count node="/" traverserDepth="2"/><br/>
+
+</jcr:session>
+
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" %>
+<h1>Nodes Tag with default traverser</h1>
+<font color="red">Filtered by "item.name.equals('TestA')"</font>
+
+<jcr:session>
+
+<h2>Depth = 2</h2>
+<table border="1" cellpadding="5">
+<tr>
+ <TH>Path</TH>
+ <TH>Name</TH>
+</tr>
+<jcr:nodes node="/" var="node" traverserDepth="2" filterExp="item.name.equals('TestA')">
+<tr>
+ <TD><c:out value="${node.path}"/></TD>
+ <TD><c:out value="${node.name}"/></TD>
+</tr>
+</jcr:nodes>
+</table>
+
+</jcr:session>
\ 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" %>
+<h1>IfPresent tag</h1>
+
+<jcr:session>
+
+<jcr:ifPresent item="/TestA">
+ /TestA is present<br>
+</jcr:ifPresent>
+
+<jcr:ifPresent item="/john" value="false">
+ /john is not present<br>
+</jcr:ifPresent>
+
+<jcr:ifPresent item="/">
+ Root is present<br>
+</jcr:ifPresent>
+
+<jcr:ifPresent item="/" property="jcr:primcaryType">
+ Property 'jcr:primaryType' is present in Root<br>
+</jcr:ifPresent>
+
+<jcr:ifPresent item="/" value="false">
+ Root is not present<br>
+</jcr:ifPresent>
+
+</jcr:session>
+
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 @@
+<html>
+<HEAD>
+</HEAD>
+<BODY>
+
+<h1>JCR taglib</h1>
+
+<h3>Basic usage</h3>
+<ol>
+ <LI>
+ <a href="session.jsp">SessionTag</a>. <br/>
+ jrc:session sets the boundaries of a JCR session.
+ It creates a Session and stores it in a page scope variable.
+ </LI>
+ <LI>
+ <a href="cd.jsp">CdTag</a>. <br/>
+ jrc:cd sets the current working directory.
+ </LI>
+ <LI><a href="nodes.jsp">NodesTag</a><br/>
+ jrc:nodes iterates over all the traversed nodes from the given node.
+ </LI>
+ <LI><a href="properties.jsp">PropertiesTag</a><br/>
+ jcr:properties iterates over the properties of the given node.
+ </LI>
+ <LI><a href="out.jsp">OutTag</a><br/>
+ jcr:out displays Node and property values through
+ the given template engine and template.
+ </LI>
+ <LI><a href="set.jsp">SetTag</a><br/>
+ jcr:set stores the given node or property in a
+ page context scoped variable.
+ </LI>
+ <LI><a href="count.jsp">CountTag</a><br/>
+ jcr:counts counts the nodes returned by the given
+ Traverser and writes the value.
+ </LI>
+ <LI><a href="size.jsp">SizeTag</a><br/>
+ jcr:size Estimates the cumulative size of the nodes returned by the given
+ Traverser and writes the value.
+ </LI>
+ <LI><a href="query.jsp">QueryTag</a><br/>
+ jcr:query Iterates over the query result nodes.
+ </LI>
+ <LI><a href="ifPresent.jsp">IfPresentTag</a><br/>
+ jcr:ifPresent Conditional tag which evaluates a node existence.
+ </LI>
+ <LI><a href="versions.jsp">versionsTag</a><br/>
+ jcr:versions Iterates over the versions of the given node
+ </LI>
+</ol>
+
+<h3>Advanced usage</h3>
+<ol>
+ <LI>Test <a href="traversers.jsp">traversers</a> </LI>
+ <LI>Test <a href="filters.jsp">filters</a> </LI>
+ <LI>Test <a href="comparators.jsp">comparators</a> </LI>
+</ol>
+</BODY>
+</html>
\ 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" %>
+<h1>Nodes Tag with default traverser</h1>
+
+<h2>Depth = 0</h2>
+<jcr:session>
+
+<jcr:nodes node="/" var="node" traverserDepth="0">
+ <c:out value="${node.path}"/><br>
+</jcr:nodes>
+
+<h2>Depth = 1</h2>
+<jcr:nodes node="/" var="node" traverserDepth="1">
+ <c:out value="${node.path}"/><br>
+</jcr:nodes>
+
+<h2>Depth = 2</h2>
+<jcr:nodes node="/" var="node" traverserDepth="2">
+ <c:out value="${node.path}"/><br>
+</jcr:nodes>
+
+</jcr:session>
+
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" %>
+<h1>Out</h1>
+
+<jcr:session>
+<table cellpadding="10" border="1" >
+ <tr>
+ <TH>Node</TH>
+ <TH>Property</TH>
+ <TH>Node: Template engine output</TH>
+ <TH>Property: Template engine output</TH>
+ </tr>
+ <jcr:nodes node="/TestB" var="node" traverserDepth="0">
+ <jcr:properties node="${node}" var="property">
+ <tr>
+ <TD><c:out value="${property.path}"/></TD>
+ <TD><c:out value="${property.name}"/></TD>
+ <TD>
+ <jcr:out item="${node}" />
+ </TD>
+ <TD>
+ <jcr:out item="${node}" property="jcr:primaryType" />
+ </TD>
+ </tr>
+ </jcr:properties>
+ </jcr:nodes>
+</table>
+</jcr:session>
\ 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" %>
+<h1>Properties</h1>
+
+<jcr:session>
+ Session: <c:out value="${session.userId}"/><br>
+<table cellpadding="10" border="1" >
+ <tr>
+ <TH>Path</TH>
+ <TH>Name</TH>
+ <TH>Type</TH>
+ <TH>Value</TH>
+ </tr>
+ <jcr:nodes node="/TestB" var="node">
+ <jcr:properties node="${node}" var="property" sortExp="item.name">
+ <tr>
+ <TD><c:out value="${property.path}"/></TD>
+ <TD><c:out value="${property.name}"/></TD>
+ <TD>
+ <c:if test="${!empty property.value}">
+ <c:out value="${property.value.type}"/>
+ </c:if>
+
+ </TD>
+ <TD>
+ <c:if test="${!empty property.value}">
+ <c:out value="${property.value.string}"/>
+ </c:if>
+
+ </TD>
+ </tr>
+ </jcr:properties>
+ </jcr:nodes>
+</table>
+</jcr:session>
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" %>
+<h1>Query tag</h1>
+
+<%
+ String q = "SELECT * FROM nt:base WHERE jcr:path LIKE '/TestA/%'" ;
+%>
+
+<jcr:session>
+
+<h3>SQL: <%=q%> </h3>
+<jcr:query stmt="<%= q %>" var="node" lang="sql">
+ Node: <c:out value="${node.path}"/><br>
+</jcr:query>
+
+<h3>XPATH: //* </h3>
+<jcr:query stmt="//*" var="node" lang="xpath">
+ Node: <c:out value="${node.path}"/><br>
+</jcr:query>
+
+</jcr:session>
+
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" %>
+
+<h1>Session</h1>
+
+<jcr:session>
+Hello session
+</jcr: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" %>
+<h1>Set</h1>
+
+<jcr:session>
+ <jcr:set item="/TestA" var="myA" scope="request"/>
+ node: <jcr:out item="${myA}" /><br/>
+ <jcr:set item="/TestA" property="jcr:primaryType" var="type" />
+ Node type: <c:out value="${type.string}" />
+
+</jcr:session>
\ 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" %>
+<h1>Size Tag with default traverser</h1>
+
+<jcr:session>
+
+ <h2>Size of root node: </h2>
+ <jcr:size node="/" traverserDepth="0" /> bytes <br/>
+ <jcr:properties node="/" var="prop">
+ <jcr:out item="${prop}"/> <br>
+ </jcr:properties>
+
+ <h2>Size of testA node</h2>
+ <jcr:size node="TestA" traverserDepth="0" /> bytes <br/>
+ <jcr:properties node="/TestA" var="prop">
+ <jcr:out item="${prop}"/><br>
+ </jcr:properties>
+
+ <h2>Size of A-L2 node</h2>
+ <jcr:size node="TestA/A-L2" traverserDepth="0" /> bytes <br/>
+ <jcr:properties node="/TestA/A-L2" var="prop">
+ <jcr:out item="${prop}"/><br>
+ </jcr:properties>
+
+ <h2>Size of testA node with depth=1</h2>
+ <jcr:size node="TestA" traverserDepth="1" /> bytes <br/>
+
+ <h2>Size of testB node</h2>
+ <jcr:size node="/TestB" traverserDepth="0" /> bytes <br/>
+ <jcr:properties node="TestB" var="prop">
+ <jcr:out item="${prop}"/><br>
+ </jcr:properties>
+
+</jcr:session>
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" %>
+<h1>Traversers</h1>
+
+<jcr:session>
+
+<h2>Preorder traverser</h2>
+<jcr:nodes
+ node="/"
+ var="node"
+ traverserID="org.apache.jackrabbit.taglib.traverser.PreorderTraverser"
+ traverserDepth="5">
+ <c:out value="${node.path}"/><br>
+</jcr:nodes>
+
+<h2>Postorder traverser</h2>
+<jcr:nodes
+ node="/"
+ var="node"
+ traverserID="org.apache.jackrabbit.taglib.traverser.PostorderTraverser"
+ traverserDepth="5">
+ <c:out value="${node.path}"/><br>
+</jcr:nodes>
+
+<h2>AncestorTraverser (breadcrumb) from node "Apples/Apple1/Nice apple1"</h2>
+<jcr:nodes
+ node="Apples/Apple1/Nice apple1"
+ var="node"
+ traverserID="org.apache.jackrabbit.taglib.traverser.AncestorsTraverser"
+ traverserDepth="5">
+ <c:out value="${node.name}"/> /
+</jcr:nodes>
+<br>
+
+<h2>ExpandedNodeTraverser (navigator) to node "Apples/Apple1"</h2>
+<p>Depth is ignored in this Traverser implementation</p>
+<jcr:nodes
+ node="/"
+ var="node"
+ traverserID="org.apache.jackrabbit.taglib.traverser.ExpandedNodeTraverser"
+ traverserParam="Apples/Apple1"
+ traverserDepth="5">
+
+ <c:forEach begin="0" end="${node.depth}">
+
+ </c:forEach>
+ / <c:out value="${node.name}"/><br/>
+</jcr:nodes>
+<br>
+
+<h2>
+ ExpandedNodesTraverser (navigator with multiple expanded nodes)<br>
+ to node "/Apples/Apple1" and <br>
+ to node "/Oranges"
+ </h2>
+<p>Depth is ignored in this Traverser implementation</p>
+
+<jcr:set item="Apples/Apple1" var="apple1" />
+<jcr:set item="Oranges" var="oranges" />
+
+<%
+ java.util.Collection c = new java.util.ArrayList() ;
+ c.add(pageContext.getAttribute("apple1"));
+ c.add(pageContext.getAttribute("oranges"));
+ pageContext.setAttribute("target", c);
+%>
+<jcr:nodes
+ node="/"
+ var="node"
+ traverserID="org.apache.jackrabbit.taglib.traverser.ExpandedNodesTraverser"
+ traverserParam="${target}"
+ traverserDepth="5">
+ <c:forEach begin="0" end="${node.depth}">
+
+ </c:forEach>
+ / <c:out value="${node.name}"/><br/>
+</jcr:nodes>
+
+
+</jcr:session>
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" %>
+<h1>Versions</h1>
+
+<jcr:session>
+
+<jcr:versions node="/TestA" var="node" traverserDepth="1">
+ <c:out value="${node.path}"/><br>
+</jcr:versions>
+
+</jcr:session>
+
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.<br>
+ *
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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;
+
+/**
+ * <p>
+ * Counts the nodes returned by the given <code>Traverser</code> and writes
+ * the value.
+ * </p>
+ *
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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. <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;
+
+ /**
+ * 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 <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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 <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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. <br>
+ * e.g. /mynode <br>
+ * or ${mynode}
+ */
+ private String node;
+
+ /**
+ * NodeComparator ID
+ */
+ private String sortID;
+
+ /**
+ * Expression used by the NodeComparator to evaluate nodes. <br>
+ * The evaluation must return a Comparable instance. <br>
+ */
+ private String sortExp;
+
+ /**
+ * Sort order <br>
+ * 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 <a href="mailto:edgarpoce@gmail.com">Edgar Poce</a>
+ */
+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 <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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. <br>
+ * e.g. /mynode <br>
+ * or ${mynode}
+ */
+ private String node;
+
+ /**
+ * JNDI address where the <code>ItemComparator</code> is bound. <br>
+ * e.g. myproperty
+ */
+ private String sortID;
+
+ /**
+ * Expression used by the <code>ItemComparator</code><br>
+ * The evaluation must return a Comparable instance. <br>
+ */
+ private String sortExp;
+
+ /**
+ * Sort order <br>
+ * 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;
+
+/**
+ * <p>
+ * Iterates over the nodes returned by the given query.
+ * </p>
+ *
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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;
+
+/**
+ * <p>
+ * Creates a session stores it in a page scope variable.
+ * </p>
+ *
+ * @author <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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. <br>
+ * If no user is set then the request.getUserPrincipal is used. <br>
+ * If no user is logged in the default user is used (See config options).
+ */
+ private String user;
+
+ /**
+ * User's password. <br>
+ * 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;
+ }
+
+ /**
+ * <p>
+ * Create credentials
+ * </p>
+ * <ol>
+ * <li>Try to create credentials for the given user (user and pwd)</li>
+ * <li>Try to create credentials for the logged user (logged user and no
+ * pwd)</li>
+ * <li>Try to create credentials for anonymous user (JNDI config)</li>
+ * </ol>
+ *
+ * @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 <a href="mailto:edgarpoce@gmail.com">Edgar Poce </a>
+ */
+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