You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2012/12/07 12:03:39 UTC
svn commit: r1418276 - in /lenya/branches/BRANCH_2_1_X/src/modules/news:
config/cocoon-xconf/Paginator.xconf pagesheets/ pagesheets/news.xml
sitemap.xmap xslt/collection2xhtml.xsl xslt/createPaginationLinks.xsl
xslt/flatten.xsl xslt/sort.xsl
Author: andreas
Date: Fri Dec 7 11:03:37 2012
New Revision: 1418276
URL: http://svn.apache.org/viewvc?rev=1418276&view=rev
Log:
Issue 54250: Add pagination functionality to news module. Thanks to Leonardo Miceli for the patch.
Added:
lenya/branches/BRANCH_2_1_X/src/modules/news/config/cocoon-xconf/Paginator.xconf
lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/
lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/news.xml
lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/createPaginationLinks.xsl
Modified:
lenya/branches/BRANCH_2_1_X/src/modules/news/sitemap.xmap
lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/collection2xhtml.xsl
lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/flatten.xsl
lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/sort.xsl
Added: lenya/branches/BRANCH_2_1_X/src/modules/news/config/cocoon-xconf/Paginator.xconf
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/config/cocoon-xconf/Paginator.xconf?rev=1418276&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/config/cocoon-xconf/Paginator.xconf (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/config/cocoon-xconf/Paginator.xconf Fri Dec 7 11:03:37 2012
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<xconf xpath="/cocoon" unless="component[@role='org.apache.cocoon.transformation.pagination.Paginator']">
+
+ <!-- ======================= Paginator =========================== -->
+ <component
+ class="org.apache.cocoon.transformation.pagination.Paginator"
+ role="org.apache.cocoon.transformation.pagination.Paginator"
+ logger="core.paginator"/>
+
+</xconf>
Added: lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/news.xml
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/news.xml?rev=1418276&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/news.xml (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/pagesheets/news.xml Fri Dec 7 11:03:37 2012
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<pagesheet xmlns="http://apache.org/cocoon/paginate/1.0">
+ <rules>
+ <count type="element" name="document" num="3" />
+ </rules>
+</pagesheet>
\ No newline at end of file
Modified: lenya/branches/BRANCH_2_1_X/src/modules/news/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/sitemap.xmap?rev=1418276&r1=1418275&r2=1418276&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/sitemap.xmap (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/sitemap.xmap Fri Dec 7 11:03:37 2012
@@ -31,6 +31,10 @@
<encoding>UTF-8</encoding>
</map:serializer>
</map:serializers>
+ <map:transformers default="xslt">
+ <map:transformer logger="sitemap.transformer.paginator"
+ name="paginator" src="org.apache.cocoon.transformation.pagination.Paginator"/>
+ </map:transformers>
</map:components>
@@ -67,6 +71,21 @@
<map:parameter name="area" value="{3}"/>
<map:parameter name="format" value="{1}"/>
</map:transform>
+
+ <map:select type="request-parameter">
+ <map:parameter name="parameter-name" value="page"/>
+ <!-- comparing against the same request-param to check for existence
+ as C2.1 does not allow to do it -->
+ <map:when test="{request-param:page}">
+ <map:transform src="pagesheets/news.xml" type="paginator">
+ <map:parameter name="page" value="{request-param:page}"/>
+ </map:transform>
+ <map:transform src="fallback://lenya/modules/news/xslt/createPaginationLinks.xsl"/>
+ </map:when>
+ <map:otherwise>
+ </map:otherwise>
+ </map:select>
+
<map:transform type="include"/>
<map:transform src="fallback://lenya/modules/news/xslt/flatten.xsl"/>
<map:transform src="fallback://lenya/modules/news/xslt/sort.xsl"/>
Modified: lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/collection2xhtml.xsl
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/collection2xhtml.xsl?rev=1418276&r1=1418275&r2=1418276&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/collection2xhtml.xsl (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/collection2xhtml.xsl Fri Dec 7 11:03:37 2012
@@ -61,6 +61,7 @@
</xsl:if>
<xsl:apply-templates select="col:document"/>
+ <xsl:apply-templates select="col:page"/>
</div>
</body>
</html>
@@ -93,14 +94,21 @@
<xsl:template match="xhtml:p" mode="excerpt">
- <xsl:copy>
+ <p xmlns="http://www.w3.org/1999/xhtml">
<xsl:copy-of select="@*"/>
<xsl:variable name="content" select="."/>
<xsl:value-of select="substring($content, 1, $maxChars)"/>
<xsl:if test="string-length($content) > $maxChars">
<xsl:text>…</xsl:text>
</xsl:if>
- </xsl:copy>
+ </p>
+ </xsl:template>
+
+
+ <xsl:template match="col:page">
+ <div id="pagination">
+ <xsl:apply-templates/>
+ </div>
</xsl:template>
Added: lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/createPaginationLinks.xsl
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/createPaginationLinks.xsl?rev=1418276&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/createPaginationLinks.xsl (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/createPaginationLinks.xsl Fri Dec 7 11:03:37 2012
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:meta="http://apache.org/lenya/meta/1.0/"
+ xmlns:doc="http://apache.org/lenya/metadata/document/1.0"
+ xmlns:page="http://apache.org/cocoon/paginate/1.0"
+ xmlns:col="http://apache.org/cocoon/lenya/collection/1.0"
+ exclude-result-prefixes="page"
+ >
+
+ <xsl:template match="page:page">
+
+ <col:page id="pagination">
+ <!-- create 'previous' link -->
+ <xsl:if test="@current > 1">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="@current-uri" />
+ <xsl:text>?page=</xsl:text>
+ <xsl:value-of select="number(@current)-1" />
+ </xsl:attribute>
+ <xsl:text><</xsl:text>
+ </a>
+ </xsl:if>
+ <!-- show current page of total pages -->
+ <span id="current"><xsl:value-of select="@current"/></span>
+ <span><xsl:text> of </xsl:text></span>
+ <span id="total"><xsl:value-of select="@total"/></span>
+ <!-- create 'next' link -->
+ <xsl:if test="@current < @total">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="@current-uri" />
+ <xsl:text>?page=</xsl:text>
+ <xsl:value-of select="number(@current)+1" />
+ </xsl:attribute>
+ <xsl:text>></xsl:text>
+ </a>
+ </xsl:if>
+ </col:page>
+ </xsl:template>
+
+ <xsl:template match="@*|node()">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+
+
+</xsl:stylesheet>
Modified: lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/flatten.xsl
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/flatten.xsl?rev=1418276&r1=1418275&r2=1418276&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/flatten.xsl (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/flatten.xsl Fri Dec 7 11:03:37 2012
@@ -30,6 +30,12 @@
</xsl:template>
+ <xsl:template match="col:page">
+ <xsl:copy>
+ <xsl:apply-templates/>
+ </xsl:copy>
+ </xsl:template>
+
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
Modified: lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/sort.xsl
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/sort.xsl?rev=1418276&r1=1418275&r2=1418276&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/sort.xsl (original)
+++ lenya/branches/BRANCH_2_1_X/src/modules/news/xslt/sort.xsl Fri Dec 7 11:03:37 2012
@@ -31,6 +31,7 @@
<xsl:apply-templates select="col:document">
<xsl:sort select="dc:date" order="descending"/>
</xsl:apply-templates>
+ <xsl:apply-templates select="col:page" />
</xsl:copy>
</xsl:template>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org