cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <>
Subject info on my recent contributions in the scratchpad
Date Fri, 22 Feb 2002 18:22:09 GMT
I uploaded (with much problems for your compiler, sorry about that) a
few new components that I found very useful:

1) ImageReader: this is a reader which is able to scale images depending
on parameters.

This is a sitemap fragment that works on it

       | Creates a thumbnail for the requested images, using a special
       | extension of the form .(*x*), for example .(10x20) or .(0x80).
       | When the 'zero' value is used, it indicates that this side
       | be resized according to original aspect ratio of the images.
       | for example, if an image is originally 200x100, asking for
       | gives a picture of 50x25, while asking for .(0x50) gives
       | Asking for 0x0 or negative numbers is not meaningful.
       | The parameter "expire-time" indicates how many (milliseconds)
       | image is expected to live. The higher you set this value, the
       | requests for images you'll get, since images will be cached by
       | or local browser caches and will avoid asking you again for
       | the image, which is a rather CPU and memory intense operation
       | if cocoon itself adds a caching layer on this). So, use a low
       | if your images change frequently, a higher value if they do
   <map:match pattern="**.jpg.(*x*)">
    <map:read type="image" src="{1}.jpg">
      <map:parameter name="width" value="{2}"/>
      <map:parameter name="height" value="{3}"/>
      <map:parameter name="expire-time" value="1000000"/>

I've found this *extremely* easy to use and useful for creating
thumbnails or normalizing the site of uploaded images (yes, this is part
of my long-time-due image gallery)

2) DirectoryZipArchiver

This is another read that is able to generate a zip archive of the
content of a particular directory

       | Produces a zipped archive containing all the files in the 
       | requested folder (if any).
   <map:match pattern="**/">
    <map:read type="archiver" src="{1}"/>

useful to generate archives without having to generate them on the disk
(not that this is very fast and light because doesn't store anything in
memory, so you can create archives or Gb without problems... I've tested
it up to 200Mb), useful to save space on your server disk.

3) Paginator

the paginator is a special filter transformer that 'paginates' your
input depending on a 'pagesheet' a sort of stylesheets for pages that
contains the paginating rules.

This is an example pagesheet

<?xml version="1.0"?>
<pagesheet xmlns="">
  <group name="tables" element="table" namespace="..."/>
  <group name="figures" element="figure" namespace="..."/>
 <rules page="1">
  <count type="element" name="section" namespace="..." num="3"/>
  <link type="unit" num="1"/>
  <link type="range" value="10"/>
  <count type="element" name="section" namespace="..." num="4"/>
  <link type="unit" num="1"/>

it might paginate one item at a time (using the item groups you can have
more than one groups of items, say figures and tables on a book) or
paginate couting elements in a particular namespace.

The above pagesheet says:

 1) there are two group items 'tables' and 'figures'
 2) on the first page, count '3' section elements and stop
 3) give a link to the next page
 4) give link to the +10 page
 5) on all the other page, count '4' sections elements
 6) and give a link to the next and previous page (if available)

So given a sitemap like this

   <map:match pattern="books/*(*)">
    <map:generate src="{1}.xml"/>
    <map:transform type="paginate" src="book.pagesheet">
      <map:parameter name="page" value="{2}"/>
    <map:serialize type="xml"/>

where books/book.xml is


if you asked for book/book(2) you would get

 <book xmlns:page="">
  <page:page current="2" total="3" current-uri="book(2)"
   <page:link type="prev" page="1" uri="book(1)/>
   <page:link type="next" page="3" uri="book(3)/>

that you can later XSLT-transform for your paginating needs.

Note that I used the 'resource(page)' URI scheme which I find very
elegant and straightforward.

Note also that all the logic to know if the page is the last one and all
those checks are done by the paginator so you can free your XSLT
stylesheets from that stinky logic.

NOTE: the paginator concept is very powerful but I didn't have time to
improve on it so I donated it instead of leaving it on my harddisk to
collect digital dust. In theory, the pagesheet semantics is powerful
enough (and there are stubs in the code for that!) to do pagination
based on counting the characters included in particular elements, so
that better forms of pagination can be done for textual documents.

Unfortunately, the code is *VERY* ugly and very badly
written, it is very likely that it looses some SAX events here and there
and you get weird NPE out of Xalan if you post-transformX-Mozilla-Status: 0009same time, I
think the concept is quite powerful, even if it is
somewhat inefficient since it filters out things instead of generating
them propertly

Anyway, use them and improve on them at wish.

Hope you'll find them useful.

Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<>                             Friedrich Nietzsche

To unsubscribe, e-mail:
For additional commands, email:

View raw message