cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/util ResizableContainer.java
Date Fri, 27 Jun 2003 20:10:43 GMT
stefano     2003/06/27 13:10:43

  Modified:    src/scratchpad/webapp/samples scratchpad-samples.xml
               src/webapp/samples samples.xml
  Added:       src/webapp/samples/paginator/content list.xml text.xml
               src/webapp/samples/paginator/stylesheets list2html.xsl
                        pagedlist2html.xsl
               src/webapp/samples/imagereader sitemap.xmap logo.jpg
               src/java/org/apache/cocoon/transformation/pagination
                        PageRules.java Paginator.java Pagesheet.java
                        Paginator.xconf ItemGroup.java
               src/webapp/samples/paginator sitemap.xmap README.txt
               src/webapp/samples/paginator/pagesheets pagesheet.dtd
                        text.pagesheet list.pagesheet
               src/java/org/apache/cocoon/reading ImageReader.java
               src/java/org/apache/cocoon/util ResizableContainer.java
  Removed:     src/scratchpad/webapp/samples/paginator/content text.xml
                        list.xml
               src/scratchpad/src/org/apache/cocoon/transformation/pagination
                        Pagesheet.java ItemGroup.java Paginator.xconf
                        PageRules.java Paginator.java
               src/scratchpad/webapp/samples/paginator/pagesheets
                        list.pagesheet pagesheet.dtd text.pagesheet
               src/scratchpad/webapp/samples/paginator/stylesheets
                        pagedlist2html.xsl list2html.xsl
               src/scratchpad/src/org/apache/cocoon/util
                        ResizableContainer.java
               src/scratchpad/webapp/samples/paginator README.txt
                        sitemap.xmap
               src/scratchpad/webapp/samples/imagereader logo.jpg
                        sitemap.xmap
               src/scratchpad/src/org/apache/cocoon/reading
                        ImageReader.java
  Log:
  moved the paginating transformer and the ImageReader from the scratchpad to the main trunk, as voted a while ago
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/webapp/samples/paginator/content/list.xml
  
  Index: list.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: list.xml,v 1.1 2003/06/27 20:10:41 stefano Exp $ -->
  
  <list>
    <item>This is item 1</item>
    <item>This is item 2</item>
    <item>This is item 3</item>
    <item>This is item 4</item>
    <item>This is item 5</item>
    <item>This is item 6</item>
    <item>This is item 7</item>
    <item>This is item 8</item>
    <item>This is item 9</item>
  </list>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/content/text.xml
  
  Index: text.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: text.xml,v 1.1 2003/06/27 20:10:41 stefano Exp $ -->
  
  <list>
    <item>This is the paragraph number one (44 chars).</item>
    <item>This is the paragraph number two, a bit longer (58 chars).</item>
    <item>This one is third (29 chars).</item>
    <item>4th (15 chars).</item>
    <item>5th (15 chars).</item>
    <item>This is the paragraph number six.</item>
    <item>This is the paragraph number seven.</item>
    <item>This is the paragraph number eight.</item>
    <item>This is the paragraph number nine which is longer (twice) then any other paragraph before.</item>
    <item>This is the paragraph number ten.</item>
    <item>This is the paragraph number eleven.</item>
  </list>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/stylesheets/list2html.xsl
  
  Index: list2html.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: list2html.xsl,v 1.1 2003/06/27 20:10:41 stefano Exp $ -->
  
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
    <xsl:template match="/">
     <html>
      <head>
       <title>Complete List</title>
      </head>
      <body bgcolor="white" alink="red" link="blue" vlink="blue">
       <h3>Complete List</h3>
       <xsl:apply-templates/>
      </body>
     </html>
    </xsl:template>
  
    <xsl:template match="list">
     <ul>
      <xsl:apply-templates/>
     </ul>
    </xsl:template>
  
    <xsl:template match="item">
     <li><xsl:apply-templates/></li>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/stylesheets/pagedlist2html.xsl
  
  Index: pagedlist2html.xsl
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: pagedlist2html.xsl,v 1.1 2003/06/27 20:10:41 stefano Exp $ -->
  
  <!DOCTYPE xsl:stylesheet [
   <!ENTITY laquo "&#xAB;" >
   <!ENTITY raquo "&#xBB;" >
   <!ENTITY nbsp "&#160;" >
  ]>
  
  <xsl:stylesheet version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:page="http://apache.org/cocoon/paginate/1.0"
  >
  
    <xsl:template match="/">
     <html>
      <head>
       <title>Paged List</title>
      </head>
      <body bgcolor="white" alink="red" link="blue" vlink="blue">
       <h3>Paged List</h3>
       <xsl:apply-templates/>
       <a href="{//page:page/@clean-uri}">single page version</a>
      </body>
     </html>
    </xsl:template>
  
    <xsl:template match="list">
     <ul>
      <xsl:apply-templates/>
     </ul>
    </xsl:template>
  
    <xsl:template match="item">
     <li><xsl:apply-templates/></li>
    </xsl:template>
  
    <xsl:template match="page:page">
     <xsl:if test="@total &gt; 1">
  
        <!-- page navigation table -->
        <table border="0">
         <tr>
  
          <!-- td prev -->
          <td align="right">&nbsp;
           <xsl:if test="page:link[@type='prev']">
            <xsl:variable name="previous" select="@current - 1"/>
             <a href="{page:link[@page = $previous]/@uri}">&laquo; prev</a>
           </xsl:if>
          </td>
  
          <!-- td current -->
          <td align="center">
            [page <xsl:value-of select="@current"/> of <xsl:value-of select="@total"/>]
          </td>
  
          <!-- td next -->
          <td align="left">
           <xsl:if test="page:link[@type='next']">
            <xsl:variable name="next" select="@current + 1"/>
            <a href="{page:link[@page = $next]/@uri}">next &raquo;</a>
           </xsl:if>
          &nbsp;</td>
  
         </tr>
        </table>
     </xsl:if>
    </xsl:template>
  </xsl:stylesheet>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/imagereader/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <!--
    CVS $Id: sitemap.xmap,v 1.1 2003/06/27 20:10:41 stefano Exp $
    
    Image Reader Sample
  -->
  
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
    <map:components>
      <map:generators default="file"/>
      <map:transformers default="xslt"/>
      <map:readers default="resource">
        <map:reader name="image" src="org.apache.cocoon.reading.ImageReader" logger="sitemap.reader.image" pool-max="32" pool-min="1" pool-grow="4"/>
      </map:readers>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
      <map:selectors default="browser"/>
    </map:components>
  
    <map:pipelines>
      <map:pipeline>
        <map:match pattern="">
          <map:redirect-to uri="image-100"/>
        </map:match>
   
        <map:match pattern="image-*">
          <map:read type="image" src="logo.jpg">
            <map:parameter name="width" value="{1}"/>
            <map:parameter name="height" value="{1}"/>
          </map:read>
        </map:match>
      </map:pipeline>
    </map:pipelines>
  </map:sitemap>
  
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/imagereader/logo.jpg
  
  	<<Binary file>>
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/transformation/pagination/PageRules.java
  
  Index: PageRules.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.transformation.pagination;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Container class for the immutable pagination rules for each page.
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:bhtek@yahoo.com">Boon Hian Tek</a>
   * @version CVS $Id: PageRules.java,v 1.1 2003/06/27 20:10:42 stefano Exp $
   */
  public class PageRules {
  
      public String elementName;
      public String elementURI;
      public int elementCount = 0;
      public int charCount = 0;
      public int unitLinks = 0;
      private List rangeLinks = new ArrayList();
  
      public boolean match(String element, String namespace) {
          boolean elementMatches = ((this.elementName!=null) &&
                                    this.elementName.equals(element));
  
          if (this.elementURI==null) {
              return elementMatches;
          } else {
              return elementMatches && this.elementURI.equals(namespace);
          }
      }
  
      public boolean match(String namespace) {
          return ((this.elementURI!=null) &&
                  (this.elementURI.equals(namespace)));
      }
  
      public Integer[] getRangeLinks() {
          return (Integer[]) this.rangeLinks.toArray(new Integer[this.rangeLinks.size()]);
      }
  
      public void addRangeLink(Integer rangeLink) {
          this.rangeLinks.add(rangeLink);
      }
  
      public void addRangeLink(int rangeLink) {
          this.addRangeLink(new Integer(rangeLink));
      }
  
      public void addRangeLink(String rangeLink) {
          this.addRangeLink(new Integer(rangeLink));
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/transformation/pagination/Paginator.java
  
  Index: Paginator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.transformation.pagination;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.caching.CacheableProcessingComponent;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.transformation.AbstractTransformer;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceException;
  import org.apache.excalibur.source.SourceValidity;
  import org.apache.excalibur.source.impl.validity.AggregatedValidity;
  import org.apache.excalibur.source.impl.validity.TimeStampValidity;
  import org.apache.excalibur.store.Store;
  import org.apache.excalibur.xml.sax.SAXParser;
  import org.xml.sax.Attributes;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.io.IOException;
  import java.io.Serializable;
  import java.util.Map;
  
  /**
   * A paginating transformer.
   *
   * @author     <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author     <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:bhtek@yahoo.com">Boon Hian Tek</a>
   * @version    CVS $Id: Paginator.java,v 1.1 2003/06/27 20:10:42 stefano Exp $
   */
  public class Paginator extends AbstractTransformer
    implements Composable, Disposable, CacheableProcessingComponent {
  
      public static final String PAGINATE_URI = "http://apache.org/cocoon/paginate/1.0";
      public static final String PAGINATE_PREFIX = "page";
      public static final String PAGINATE_PREFIX_TOKEN = PAGINATE_PREFIX+":";
  
      private ComponentManager manager;
      private SAXParser parser;
      private Store store;
      private Source inputSource;
      private int page;
      private int item;
      private String itemGroup;
      private String requestURI;
      private Request request;
      private Pagesheet pagesheet;
      private int level;
      private boolean prefixMapping;
  
      /**
       * Set the current <code>ComponentManager</code> instance used by this
       * <code>Composable</code>.
       *
       * @param  manager  Description of the Parameter
       */
      public void compose(ComponentManager manager) {
          try {
              this.manager = manager;
              getLogger().debug("Looking up "+SAXParser.ROLE);
              this.parser = (SAXParser) manager.lookup(SAXParser.ROLE);
              getLogger().debug("Looking up "+Store.ROLE+"/TransientStore");
              this.store = (Store) manager.lookup(Store.ROLE+"/TransientStore");
          } catch (Exception e) {
              getLogger().error("Could not find component", e);
          }
      }
  
      /**
       * Dispose this component.
       */
      public void dispose() {
          if (this.parser!=null) {
              this.manager.release((Component) this.parser);
          } else {
              this.parser = null;
          }
          if (this.store!=null) {
              this.manager.release(this.store);
          } else {
              this.store = null;
          }
      }
  
      /**
       * Setup the transformer.
       */
      public void setup(SourceResolver resolver, Map objectModel, String src,
                        Parameters par)
                          throws ProcessingException, SAXException,
                                 IOException {
  
          if (src==null) {
              throw new ProcessingException("I need the paginate instructions (pagesheet) to continue. Set the 'src' attribute.");
          }
  
          try {
              this.level = 0;
              this.prefixMapping = false;
              this.inputSource = resolver.resolveURI(src);
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("Using pagesheet: '"+
                                    this.inputSource.getURI()+"' in "+this+
                                    ", last modified: "+
                                    this.inputSource.getLastModified());
              }
              this.page = par.getParameterAsInteger("page", 1);
              this.item = par.getParameterAsInteger("item", 0);
              this.itemGroup = par.getParameter("item-group", "");
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("Paginating with [page = "+this.page+
                                    ", item = "+this.item+", item-group = "+
                                    this.itemGroup+"]");
              }
  
              this.request = ObjectModelHelper.getRequest(objectModel);
              this.requestURI = request.getRequestURI();
  
              // Get the pagesheet factory from the Store if available,
              // otherwise load it and put it into the store for further request
              if (store!=null) {
                  pagesheet = (Pagesheet) store.get(src);
              }
  
              // If not in the store or if pagesheet has changed, loads and stores it
              if ((pagesheet==null) ||
                  pagesheet.modifiedSince(inputSource.getLastModified())) {
                  pagesheet = new Pagesheet();
                  pagesheet.setLastModified(inputSource.getLastModified());
                  parser.parse(new InputSource(inputSource.getInputStream()),
                               pagesheet);
                  if (store!=null) {
                      store.store(src, pagesheet);
                  }
              }
  
              // Clone it in order to avoid concurrency collisions since the
              // implementation is not reentrant.
              this.pagesheet = (Pagesheet) this.pagesheet.clone();
          } catch (SourceException se) {
              throw new ProcessingException("Could not retrieve source '"+src+
                                            "'", se);
          }
      }
  
      /**
       * Generate the unique key. This key must be unique inside the space of
       * this component. This method must be invoked before the
       * generateValidity() method.
       *
       * @return The generated key or <code>null</code> if the component is
       *         currently not cacheable.
       */
      public Serializable getKey() {
          if (this.inputSource.getLastModified()!=0) {
              return this.inputSource.getURI()+page;
          } else {
              return null;
          }
      }
  
      /**
       * Generate the validity object. Before this method can be invoked the
       * generateKey() method must be invoked.
       *
       * @return The generated validity object or <code>null</code> if the
       *         component is currently not cacheable.
       */
      public SourceValidity getValidity() {
          if (this.inputSource.getLastModified()!=0) {
              AggregatedValidity validity = new AggregatedValidity();
  
              validity.add(new TimeStampValidity(page));
              validity.add(this.inputSource.getValidity());
              return validity;
          } else {
              return null;
          }
      }
  
      /**
       * Receive notification of the beginning of an element.
       *
       * @param uri The Namespace URI, or the empty string if the
       *            element has no Namespace URI or if Namespace processing is not being
       *            performed.
       * @param loc The local name (without prefix), or the empty
       *            string if Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty
       *            string if raw names are not available.
       * @param a The attributes attached to the element. If there
       *          are no attributes, it shall be an empty Attributes object.
       */
      public void startElement(String uri, String loc, String raw,
                               Attributes a) throws SAXException {
          if ( !prefixMapping) {
              super.startPrefixMapping(PAGINATE_PREFIX, PAGINATE_URI);
              this.prefixMapping = true;
          }
          level++;
          pagesheet.processStartElement(uri, loc);
          if (pagesheet.isInPage(page, item, itemGroup)) {
              int itemCount = pagesheet.itemCount(uri, loc);
  
              if (itemCount>0) {
                  String itemGroup = pagesheet.getItemGroupName(uri, loc);
                  AttributesImpl atts = new AttributesImpl(a);
  
                  atts.addAttribute(PAGINATE_URI, "item",
                                    PAGINATE_PREFIX_TOKEN+"item", "CDATA",
                                    String.valueOf(itemCount));
                  atts.addAttribute(PAGINATE_URI, "item-group",
                                    PAGINATE_PREFIX_TOKEN+"item-group",
                                    "CDATA", itemGroup);
                  super.startElement(uri, loc, raw, atts);
              } else {
                  super.startElement(uri, loc, raw, a);
              }
          }
      }
  
      /**
       * Receive notification of the end of an element.
       *
       * @param uri The Namespace URI, or the empty string if the
       *            element has no Namespace URI or if Namespace processing is not being
       *            performed.
       * @param loc The local name (without prefix), or the empty
       *            string if Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty
       *            string if raw names are not available.
       */
      public void endElement(String uri, String loc,
                             String raw) throws SAXException {
          level--;
  
          // Prevent infinite recursive loop.
          if (PAGINATE_URI.equals(uri)) {
              super.endElement(uri, loc, raw);
              return;
          }
  
          if (pagesheet.isInPage(page, item, itemGroup)) {
              if (level==0) {
                  if (item==0) {
                      int totalPages = pagesheet.getTotalPages();
                      PageRules rules = pagesheet.getPageRules(page);
  
                      Integer[] rangeLinks = rules.getRangeLinks();
                      int unitLinks = rules.unitLinks;
                      int currentPage = page;
  
                      // call add paginate
                      addPaginateTags(rangeLinks, unitLinks, currentPage,
                                      totalPages, requestURI, this);
  
                  } else {
                      int totalItems = pagesheet.getTotalItems(itemGroup);
                      AttributesImpl atts = new AttributesImpl();
  
                      atts.addAttribute(null, "current", "current", "CDATA",
                                        String.valueOf(item));
                      atts.addAttribute(null, "total", "total", "CDATA",
                                        String.valueOf(totalItems));
                      atts.addAttribute(null, "current-uri", "current-uri",
                                        "CDATA", requestURI);
                      atts.addAttribute(null, "clean-uri", "clean-uri",
                                        "CDATA", cleanURI(requestURI, item));
                      atts.addAttribute(null, "page", "page", "CDATA",
                                        String.valueOf(pagesheet.getPageForItem(item,
                                            itemGroup)));
                      super.startElement(PAGINATE_URI, "item",
                                         PAGINATE_PREFIX_TOKEN+"item", atts);
                      if (item>1) {
                          atts.clear();
                          atts.addAttribute(null, "type", "type", "CDATA",
                                            "prev");
                          atts.addAttribute(null, "uri", "uri", "CDATA",
                                            encodeURI(requestURI, item,
                                                      item-1));
                          super.startElement(PAGINATE_URI, "link",
                                             PAGINATE_PREFIX_TOKEN+"link",
                                             atts);
                          super.endElement(PAGINATE_URI, "link",
                                           PAGINATE_PREFIX_TOKEN+"link");
                      }
                      if (item<=totalItems) {
                          atts.clear();
                          atts.addAttribute(null, "type", "type", "CDATA",
                                            "next");
                          atts.addAttribute(null, "uri", "uri", "CDATA",
                                            encodeURI(requestURI, item,
                                                      item+1));
                          super.startElement(PAGINATE_URI, "link",
                                             PAGINATE_PREFIX_TOKEN+"link",
                                             atts);
                          super.endElement(PAGINATE_URI, "link",
                                           PAGINATE_PREFIX_TOKEN+"link");
                      }
                      super.endElement(PAGINATE_URI, "item",
                                       PAGINATE_PREFIX_TOKEN+"item");
                  }
  
                  super.endPrefixMapping(PAGINATE_PREFIX);
              }
  
              super.endElement(uri, loc, raw);
          }
  
          pagesheet.processEndElement(uri, loc);
      }
  
      public static void addPaginateTags(Integer[] rangeLinks, int unitLinks,
                                         int currentPage, int totalPages,
                                         String requestURI,
                                         AbstractTransformer saxTransformer)
                                           throws SAXException {
          AttributesImpl atts = new AttributesImpl();
  
          atts.addAttribute(null, "current", "current", "CDATA",
                            String.valueOf(currentPage));
          atts.addAttribute(null, "total", "total", "CDATA",
                            String.valueOf(totalPages));
          atts.addAttribute(null, "current-uri", "current-uri", "CDATA",
                            requestURI);
          atts.addAttribute(null, "clean-uri", "clean-uri", "CDATA",
                            Paginator.cleanURI(requestURI, currentPage));
          saxTransformer.startElement(Paginator.PAGINATE_URI, "page",
                                      Paginator.PAGINATE_PREFIX_TOKEN+"page",
                                      atts);
  
          for (int i = rangeLinks.length-1; i>-1; i--) {
              int rangeLink = rangeLinks[i].intValue();
  
              if ((rangeLink>0) && (currentPage-rangeLink>=1)) {
                  atts.clear();
                  atts.addAttribute(null, "type", "type", "CDATA", "prev");
                  atts.addAttribute(null, "range", "range", "CDATA",
                                    rangeLinks[i].toString());
                  atts.addAttribute(null, "uri", "uri", "CDATA",
                                    Paginator.encodeURI(requestURI,
                                                        currentPage,
                                                        currentPage-rangeLink));
                  atts.addAttribute(null, "page", "page", "CDATA",
                                    String.valueOf(currentPage-rangeLink));
                  saxTransformer.startElement(Paginator.PAGINATE_URI,
                                              "range-link",
                                              Paginator.PAGINATE_PREFIX_TOKEN+
                                              "range-link", atts);
                  saxTransformer.endElement(Paginator.PAGINATE_URI,
                                            "range-link",
                                            Paginator.PAGINATE_PREFIX_TOKEN+
                                            "range-link");
              }
          }
  
          for (int i = currentPage-unitLinks; i<currentPage; i++) {
              if (i>0) {
                  atts.clear();
                  atts.addAttribute(null, "type", "type", "CDATA", "prev");
                  atts.addAttribute(null, "uri", "uri", "CDATA",
                                    Paginator.encodeURI(requestURI,
                                                        currentPage, i));
                  atts.addAttribute(null, "page", "page", "CDATA",
                                    String.valueOf(i));
                  saxTransformer.startElement(Paginator.PAGINATE_URI, "link",
                                              Paginator.PAGINATE_PREFIX_TOKEN+
                                              "link", atts);
                  saxTransformer.endElement(Paginator.PAGINATE_URI, "link",
                                            Paginator.PAGINATE_PREFIX_TOKEN+
                                            "link");
              }
          }
          for (int i = currentPage+1; i<=currentPage+unitLinks; i++) {
              if (i<=totalPages) {
                  atts.clear();
                  atts.addAttribute(null, "type", "type", "CDATA", "next");
                  atts.addAttribute(null, "uri", "uri", "CDATA",
                                    Paginator.encodeURI(requestURI,
                                                        currentPage, i));
                  atts.addAttribute(null, "page", "page", "CDATA",
                                    String.valueOf(i));
                  saxTransformer.startElement(Paginator.PAGINATE_URI, "link",
                                              Paginator.PAGINATE_PREFIX_TOKEN+
                                              "link", atts);
                  saxTransformer.endElement(Paginator.PAGINATE_URI, "link",
                                            Paginator.PAGINATE_PREFIX_TOKEN+
                                            "link");
              }
          }
  
          for (int i = 0; i<rangeLinks.length; i++) {
              int rangeLink = rangeLinks[i].intValue();
  
              if ((rangeLink>0) && (currentPage+rangeLink<=totalPages)) {
                  atts.clear();
                  atts.addAttribute(null, "type", "type", "CDATA", "next");
                  atts.addAttribute(null, "range", "range", "CDATA",
                                    rangeLinks[i].toString());
                  atts.addAttribute(null, "uri", "uri", "CDATA",
                                    Paginator.encodeURI(requestURI,
                                                        currentPage,
                                                        currentPage+rangeLink));
                  atts.addAttribute(null, "page", "page", "CDATA",
                                    String.valueOf(currentPage+rangeLink));
                  saxTransformer.startElement(Paginator.PAGINATE_URI,
                                              "range-link",
                                              Paginator.PAGINATE_PREFIX_TOKEN+
                                              "range-link", atts);
                  saxTransformer.endElement(Paginator.PAGINATE_URI,
                                            "range-link",
                                            Paginator.PAGINATE_PREFIX_TOKEN+
                                            "range-link");
              }
          }
  
          saxTransformer.endElement(Paginator.PAGINATE_URI, "page",
                                    Paginator.PAGINATE_PREFIX_TOKEN+"page");
      }
  
      /**
       * Receive notification of character data.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void characters(char c[], int start, int len) throws SAXException {
          pagesheet.processCharacters(c, start, len);
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.characters(c, start, len);
          }
      }
  
      /**
       * Receive notification of ignorable whitespace in element content.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void ignorableWhitespace(char c[], int start,
                                      int len) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.ignorableWhitespace(c, start, len);
          }
      }
  
      /**
       * Receive notification of a processing instruction.
       *
       * @param target The processing instruction target.
       * @param data The processing instruction data, or null if none
       *             was supplied.
       */
      public void processingInstruction(String target,
                                        String data) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.processingInstruction(target, data);
          }
      }
  
      /**
       * Receive notification of a skipped entity.
       *
       * @param name The name of the skipped entity. If it is a
       *             parameter entity, the name will begin with '%'.
       */
      public void skippedEntity(String name) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.skippedEntity(name);
          }
      }
  
      /**
       * Report the start of DTD declarations, if any.
       *
       * @param name The document type name.
       * @param publicId The declared public identifier for the external
       *                 DTD subset, or null if none was declared.
       * @param systemId The declared system identifier for the external
       *                 DTD subset, or null if none was declared.
       */
      public void startDTD(String name, String publicId,
                           String systemId) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.startDTD(name, publicId, systemId);
          } else {
              throw new SAXException("Recieved startDTD not in page.");
          }
      }
  
      /**
       * Report the end of DTD declarations.
       */
      public void endDTD() throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.endDTD();
          } else {
              throw new SAXException("Recieved endDTD not in page.");
          }
      }
  
      /**
       * Report the beginning of an entity.
       *
       *@param name The name of the entity. If it is a parameter
       *            entity, the name will begin with '%'.
       */
      public void startEntity(String name) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.startEntity(name);
          }
      }
  
      /**
       * Report the end of an entity.
       *
       * @param name The name of the entity that is ending.
       */
      public void endEntity(String name) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.endEntity(name);
          }
      }
  
      /**
       * Report the start of a CDATA section.
       */
      public void startCDATA() throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.startCDATA();
          }
      }
  
      /**
       * Report the end of a CDATA section.
       */
      public void endCDATA() throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.endCDATA();
          }
      }
  
      /**
       * Report an XML comment anywhere in the document.
       *
       * @param ch An array holding the characters in the comment.
       * @param start The starting position in the array.
       * @param len The number of characters to use from the array.
       */
      public void comment(char ch[], int start, int len) throws SAXException {
          if (pagesheet.isInPage(page, item, itemGroup)) {
              super.comment(ch, start, len);
          }
      }
  
      /**
       * Removes the pagination encoding from the URI by removing the page number
       * and the previous and next character.
       */
      public static String cleanURI(String uri, int current) {
          String currentS = String.valueOf(current);
          int index = uri.lastIndexOf(currentS);
  
          if (index==-1) {
              return uri;
          } else {
              return uri.substring(0, index-1)+
                     uri.substring(index+currentS.length()+1);
          }
      }
  
      /**
       * Encode the next page in the given URI. First tries to use the existing
       * encoding by replacing the current page number, but if the current
       * encoding is not found it appends "(xx)" to the filename (before the file
       * extention, if any) where "xx" is the next page value.
       */
      public static String encodeURI(String uri, int current, int next) {
          String currentS = String.valueOf(current);
          String nextS = String.valueOf(next);
          int index = uri.lastIndexOf(currentS);
  
          if (index==-1) {
              index = uri.lastIndexOf('.');
              if (index==-1) {
                  return uri+"("+nextS+")";
              } else {
                  return uri.substring(0, index)+"("+nextS+")."+
                         uri.substring(index+1);
              }
          } else {
              return uri.substring(0, index)+nextS+
                     uri.substring(index+currentS.length());
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/transformation/pagination/Pagesheet.java
  
  Index: Pagesheet.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.transformation.pagination;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.cocoon.Modifiable;
  import org.apache.cocoon.util.ResizableContainer;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  /**
   * Interprets the pagesheet rules to perform pagination.
   *
   * <pre>
   * FIXME (SM): this code sucks! It was done to show the concept of
   *             rule driven pagination (which I find very nice) but
   *             it needs major refactoring in order to be sufficiently
   *             stable to allow any input to enter without breaking
   *             SAX well-formness. I currently don't have the time to make
   *             it any better (along with implementing the char-based rule
   *             that is mostly useful for text documents) but if you want
   *             to blast the code and rewrite it better, you'll make me happy :)
   * </pre>
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:bhtek@yahoo.com">Boon Hian Tek</a>
   * @version CVS $Id: Pagesheet.java,v 1.1 2003/06/27 20:10:42 stefano Exp $
   */
  
  /*
  
  This is an example pagesheet to show the power of this:
  
    <?xml version="1.0"?>
    <pagesheet xmlns="http://apache.org/cocoon/paginate/1.0">
     <items>
      <group name="pictures" element="file" namespace="http://apache.org/cocoon/directory/2.0"/>
     </items>
     <rules page="1">
      <count type="element" name="file" namespace="http://apache.org/cocoon/directory/2.0" num="16"/>
       <link type="unit" num="2"/>
       <link type="range" value="10"/>
     </rules>
     <rules>
      <count type="element" name="file" namespace="http://apache.org/cocoon/directory/2.0" num="16"/>
       <link type="unit" num="5"/>
       <link type="range" value="20"/>
     </rules>
     <rules>
       <count type="element" name="file" namespace="http://apache.org/cocoon/directory/2.0" num="16"/>
       <link type="unit" num="5"/>
       <link type="range" value="2"/>
       <link type="range" value="5"/>
       <link type="range" value="10"/>
       <link type="range" value="20"/>
       <link type="range" value="100"/>
     </rules>
    </pagesheet>
  
  which indicates that:
  
   1) there is one item group called "picture" and each item is given by the
      element "file" of the namespace "http://apache.org/cocoon/directory/2.0".
  
   2) for the first page, the pagination rules indicate that there are two unit
      links (two above and two below, so linking to page -2 -1 0 +1 +2) and
      range links have value 10 (so they link to page -10 and +10).
  
   3) for the rest of the pages, there are three unit links (-3 -2 -1 0 +1 +2 +3)
      and range goes 20 (so +20 and -20).
  
   4) if more than one ranges are defined, range links will be created in sequence
  
   5) range links will be from big to small (eg. 20, 10, then 5) for backward links,
      range links will be from small to big (eg. 5, 10, then 20) for forward links
  
   6) range link(s) will have an attribute 'range' to indicate the range size
  
  */
  public class Pagesheet extends DefaultHandler
    implements Cloneable, Modifiable {
  
      // Used only during parsing of pagesheet document
      private int level = 0;
      private int pg = 0;
      private long lastModified;
      private PageRules rules;
  
      // Loaded pagesheet information
      ResizableContainer pageRules;
  
      Map itemGroupsPerName;
      Map itemGroupsPerElement;
      Map itemListsPerName;
      Map itemListsPerElement;
  
      // Runtime information
      private ResizableContainer pages;
      private Page currentPage = null;
      private int pageCounter = 1;
      private int elementCounter = 0;
      private int descendant = 0;
  
      private static class Page {
  
          public int elementStart;
          public int elementEnd;
          public int characters;
  
          public Page(PageRules rules, int elementStart) {
              this.elementStart = elementStart;
  
              if (rules.elementCount>0) {
                  this.elementEnd = this.elementStart+rules.elementCount-1;
              } else {
                  this.elementEnd = this.elementStart+1;
              }
          }
  
          public boolean validInPage(int elementCounter) {
              return (this.elementStart<=elementCounter) &&
                     (elementCounter<=this.elementEnd);
          }
      }
  
      private static class ItemList extends ArrayList {
  
          public ItemList(int capacity) {
              super(capacity);
          }
  
          public void addItem(int page) {
              this.add(new Integer(page));
          }
  
          public int getPageForItem(int item) {
              Integer i = (Integer) this.get(item-1);
  
              return (i==null) ? 0 : i.intValue();
          }
  
          public boolean valid(int item) {
              return (item==this.size());
          }
      }
  
      public Pagesheet() {
          this.pages = new ResizableContainer(2);
      }
  
      private Pagesheet(ResizableContainer rules, Map itemGroupsPerName,
                        Map itemGroupsPerElement) {
          this.pageRules = rules;
          this.itemGroupsPerName = itemGroupsPerName;
          this.itemGroupsPerElement = itemGroupsPerElement;
  
          this.pages = new ResizableContainer(5);
  
          if ((this.itemGroupsPerName!=null) &&
              (this.itemGroupsPerElement!=null)) {
              this.itemListsPerName = new HashMap(itemGroupsPerName.size());
              this.itemListsPerElement = new HashMap(itemGroupsPerName.size());
  
              Iterator iter = itemGroupsPerName.values().iterator();
  
              for (; iter.hasNext(); ) {
                  ItemGroup group = (ItemGroup) iter.next();
                  ItemList list = new ItemList(10);
  
                  this.itemListsPerName.put(group.getName(), list);
                  this.itemListsPerElement.put(group.getElementURI()+
                                               group.getElementName(), list);
              }
          }
      }
  
      // --------------- interprets the pagesheet document ----------------
  
      public void startPrefixMapping(String prefix,
                                     String uri) throws SAXException {
          if ( !uri.equals(Paginator.PAGINATE_URI)) {
              throw new SAXException("The pagesheet's namespace is not supported.");
          }
      }
  
      public void startElement(String uri, String loc, String raw,
                               Attributes a) throws SAXException {
          level++;
          switch (level) {
              case 1 :
                  if (loc.equals("pagesheet")) {
                      // This object represents pagesheet
                      return;
                  }
                  break;
  
              case 2 :
                  if (loc.equals("rules")) {
                      if (this.pageRules==null) {
                          this.pageRules = new ResizableContainer(2);
                      }
                      String key = a.getValue("page");
  
                      if (key!=null) {
                          try {
                              pg = Integer.parseInt(key);
                          } catch (NumberFormatException e) {
                              throw new SAXException("Syntax error: the attribute 'rules/@page' must contain a number");
                          }
                      } else {
                          pg = 0;
                      }
                      rules = new PageRules();
                      return;
                  } else if (loc.equals("items")) {
                      if (this.itemGroupsPerName==null) {
                          this.itemGroupsPerName = new HashMap(2);
                      }
                      if (this.itemGroupsPerElement==null) {
                          this.itemGroupsPerElement = new HashMap(2);
                      }
                      return;
                  }
                  break;
  
              case 3 :
                  if (loc.equals("count")) {
                      rules.elementName = a.getValue("name");
                      rules.elementURI = a.getValue("namespace");
  
                      if (a.getValue("type").equals("element")) {
                          try {
                              rules.elementCount = Integer.parseInt(a.getValue("num"));
                          } catch (NumberFormatException e) {
                              throw new SAXException("Syntax error: the attribute 'count/@num' must contain a number");
                          }
                      } else if (a.getValue("type").equals("chars")) {
                          try {
                              rules.charCount = Integer.parseInt(a.getValue("num"));
                          } catch (NumberFormatException e) {
                              throw new SAXException("Syntax error: the attribute 'count/@num' must contain a number.");
                          }
                      } else {
                          throw new SAXException("Syntax error: count type not supported.");
                      }
                      return;
                  } else if (loc.equals("link")) {
                      if (a.getValue("type").equals("unit")) {
                          try {
                              rules.unitLinks = Integer.parseInt(a.getValue("num"));
                          } catch (NumberFormatException e) {
                              throw new SAXException("Syntax error: the attribute 'link/@num' must contain a number.");
                          }
                      } else if (a.getValue("type").equals("range")) {
                          try {
                              rules.addRangeLink(a.getValue("value"));
                          } catch (NumberFormatException e) {
                              throw new SAXException("Syntax error: the attribute 'link/@value' must contain a number.");
                          }
                      } else {
                          throw new SAXException("Syntax error: link type not supported.");
                      }
                      return;
                  } else if (loc.equals("group")) {
                      String name = a.getValue("name");
  
                      if (name==null) {
                          throw new SAXException("Syntax error: the attribute 'group/@name' must be present.");
                      }
                      String elementName = a.getValue("element");
  
                      if (elementName==null) {
                          throw new SAXException("Syntax error: the attribute 'group/@element' must be present.");
                      }
                      String elementURI = a.getValue("namespace");
                      ItemGroup group = new ItemGroup(name, elementURI,
                                                      elementName);
  
                      this.itemGroupsPerName.put(name, group);
                      this.itemGroupsPerElement.put(elementURI+elementName,
                                                    group);
                      return;
                  }
          }
          throw new SAXException("Syntax error: element "+raw+
                                 " is not recognized or is misplaced.");
      }
  
      public void endElement(String uri, String loc,
                             String raw) throws SAXException {
          level--;
          if (loc.equals("rules")) {
              pageRules.set(pg, rules);
          }
      }
  
      public void endDocument() throws SAXException {
          if (pageRules.size()==0) {
              throw new SAXException("Pagesheet must contain at least a set of pagination rules.");
          }
          if (pageRules.get(0)==null) {
              throw new SAXException("Pagesheet must contain the global pagination rules.");
          }
      }
  
      // --------------- process the received element events ----------------
  
      public void processStartElement(String uri, String name) {
          PageRules rules = getPageRules(pageCounter);
  
          if (rules.match(name, uri)) {
              elementCounter++;
              descendant++;
  
              if (currentPage==null) {
                  currentPage = new Page(rules, 1);
              }
  
              if (elementCounter>currentPage.elementEnd) {
                  /*System.out.println(">>>> "+pageCounter+
                                     ": Starting new page!!! >>> "+
                                     elementCounter);*/
                  pageCounter++;
                  currentPage = new Page(rules, currentPage.elementEnd+1);
              }
  
              pages.set(pageCounter, currentPage);
          }
  
          if (itemGroupsPerElement!=null) {
              String qname = uri+name;
              ItemGroup group = (ItemGroup) this.itemGroupsPerElement.get(qname);
  
              if ((group!=null) && (group.match(uri))) {
                  ItemList list = (ItemList) this.itemListsPerElement.get(qname);
  
                  if (list!=null) {
                      list.addItem(pageCounter);
                  }
              }
          }
      }
  
      public void processEndElement(String uri, String name) {
          PageRules rules = getPageRules(pageCounter);
  
          if (rules.match(name, uri)) {
              descendant--;
  
              if ((rules.charCount>0) &&
                  (currentPage.characters>rules.charCount)) {
                  // We are over character limit. Flip the page.
                  // System.out.println(">>>> " + pageCounter + ": Flipping page!!!");
                  currentPage.elementEnd = elementCounter;
              } else if (rules.elementCount==0) {
                  // No limit on elements is specified, and limit on characters is not reached yet.
                  currentPage.elementEnd++;
              }
          }
      }
  
      public void processCharacters(char[] ch, int index, int len) {
          if (descendant>0) {
              // Count amount of characters in the currect page.
              // System.out.println(">>>> " + pageCounter + ": " + new String(ch, index, len) + " (" + len + " bytes)");
              currentPage.characters += len;
          }
      }
  
      // --------------- return the pagination information ----------------
  
      public boolean isInPage(int page, int item, String itemGroup) {
          return ((descendant==0) || valid(page, item, itemGroup));
      }
  
      public int getTotalPages() {
          return pageCounter;
      }
  
      public int getTotalItems(String itemGroup) {
          if (this.itemListsPerName==null) {
              return 0;
          }
          ItemList list = (ItemList) this.itemListsPerName.get(itemGroup);
  
          return (list==null) ? 0 : list.size();
      }
  
      public int getPageForItem(int item, String itemGroup) {
          if (this.itemListsPerName==null) {
              return 0;
          }
          ItemList list = (ItemList) this.itemListsPerName.get(itemGroup);
  
          return (list==null) ? 0 : list.getPageForItem(item);
      }
  
      public int itemCount(String elementURI, String elementName) {
          if (this.itemListsPerElement==null) {
              return 0;
          }
          ItemList list = (ItemList) this.itemListsPerElement.get(elementURI+
                              elementName);
  
          return (list==null) ? 0 : list.size();
      }
  
      public String getItemGroupName(String elementURI, String elementName) {
          if (this.itemListsPerElement==null) {
              return null;
          }
          return ((ItemGroup) this.itemGroupsPerElement.get(elementURI+
              elementName)).getName();
      }
  
      // ---------------- miscellaneous methods ----------------------------
  
      private boolean valid(int page, int item, String itemGroup) {
          if (item==0) {
              Page p = (Page) pages.get(page);
  
              return (p!=null) && (p.validInPage(elementCounter));
          } else {
              if (this.itemListsPerElement==null) {
                  return false;
              }
              ItemList list = (ItemList) this.itemListsPerName.get(itemGroup);
  
              return (list!=null) && (list.valid(item));
          }
      }
  
      public PageRules getPageRules(int page) {
          PageRules p = (PageRules) pageRules.get(page);
  
          return (p!=null) ? p : (PageRules) pageRules.get(0);
      }
  
      public void setLastModified(long lastModified) {
          this.lastModified = lastModified;
      }
  
      public boolean modifiedSince(long date) {
          return (date!=this.lastModified);
      }
  
      public Object clone() {
          return new Pagesheet(pageRules, itemGroupsPerName,
                               itemGroupsPerElement);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/transformation/pagination/Paginator.xconf
  
  Index: Paginator.xconf
  ===================================================================
  <?xml version="1.0"?>
  
  <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>
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/transformation/pagination/ItemGroup.java
  
  Index: ItemGroup.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
   
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
   Software Foundation, please see <http://www.apache.org/>.
   
  */
  
  package org.apache.cocoon.transformation.pagination;
  
  /**
   * Container class for the immutable pagination rules for each page.
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version CVS $Id: ItemGroup.java,v 1.1 2003/06/27 20:10:42 stefano Exp $
   */
  public class ItemGroup {
      
      private String name;
      private String elementName;
      private String elementURI;
      
      public ItemGroup (String name, String elementURI, String elementName) {
          this.name = name;
          this.elementURI = elementURI;
          this.elementName = elementName;
      }
      
      public boolean match(String elementName, String elementURI) {
          return (this.elementName.equals(elementName) && this.elementURI.equals(elementURI));
      }
  
      public boolean match(String elementURI) {
          return this.elementURI.equals(elementURI);
      }
  
      public String getName() {
          return this.name;
      }
  
      public String getElementURI() {
          return this.elementURI;
      }
      
      public String getElementName() {
          return this.elementName;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: sitemap.xmap,v 1.1 2003/06/27 20:10:42 stefano Exp $ -->
  
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
    <map:components>
      <map:generators default="file"/>
      <map:transformers default="xslt">
        <map:transformer name="paginate" src="org.apache.cocoon.transformation.pagination.Paginator"/>
      </map:transformers>
      <map:readers default="resource"/>
      <map:serializers default="html"/>
      <map:matchers default="wildcard"/>
      <map:selectors default="browser"/>
    </map:components>
  
    <map:pipelines>
      <map:pipeline>
        <map:match pattern="">
          <map:redirect-to uri="list(1)"/>
        </map:match>
   
        <map:match pattern="*(*)">
          <map:generate src="content/{1}.xml"/>
          <map:transform type="paginate" src="pagesheets/{1}.pagesheet" label="content">
            <map:parameter name="page" value="{2}"/>
          </map:transform>    
          <map:transform src="stylesheets/pagedlist2html.xsl"/>
          <map:serialize type="html"/>
        </map:match>
   
        <map:match pattern="*">
          <map:generate src="content/{1}.xml"/>
          <map:transform src="stylesheets/list2html.xsl"/>
          <map:serialize type="html"/>
        </map:match>
     </map:pipeline>
    </map:pipelines>
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/README.txt
  
  Index: README.txt
  ===================================================================
  
  CVS: $Id: README.txt,v 1.1 2003/06/27 20:10:42 stefano Exp $
  
  
  To get started, read the How-To for this component:
     http://localhost:8080/cocoon/howto/howto-paginator-transformer.html
  
  For those who don't like to read docs:
  
  Make sure you have a version 2.0.3 or greater of Cocoon. The PaginatorTransformer component
  source code is located in the scratchpad area. Therefore, you need to use the following
  command to build a deployable cocoon.war which includes the scratchpad libraries.
  
    ./build.[ sh | bat ] run 
  
  During the build process, the necessary configuration details for the PaginatorTransformer
  component are copied to cocoon.xconf of cocoon.war. This means that you don't need to
  manually configure cocoon.xconf.
  
  To get going with Cocoon 2.0.3, access:
        http://localhost:8080/cocoon/mount/paginator/list(1)
  
  To get going with Cocoon 2.1, access:
        http://localhost:8080/cocoon/samples/paginator/list(1)
  
  
  Have fun!
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/pagesheets/pagesheet.dtd
  
  Index: pagesheet.dtd
  ===================================================================
  <!-- =================================================================== -->
  <!-- CVS: $Id: pagesheet.dtd,v 1.1 2003/03/09 00:10:32 pier Exp $     -->
  <!--                                                                     -->
  <!--     Pagesheet DTD (Version 0.1)                                     -->
  <!--                                                                     -->
  <!-- =================================================================== -->
  
  <!ELEMENT pagesheet (items?, rules)*>
  <!ATTLIST pagesheet xmlns CDATA #IMPLIED>
  
  <!ELEMENT items (group)>
  
  <!ELEMENT group EMPTY >
  <!ATTLIST group 
     name CDATA #IMPLIED 
     element CDATA #IMPLIED >
  
  <!ELEMENT rules (link?, count?)*>
  
  <!ELEMENT link EMPTY >
  <!ATTLIST link 
     type ( unit | range ) #REQUIRED 
     num CDATA #REQUIRED 
   >
   
   <!ELEMENT count EMPTY >
   <!ATTLIST count 
     type ( element | char ) #REQUIRED 
     num CDATA #REQUIRED 
     name CDATA #IMPLIED 
     namespace CDATA #IMPLIED 
   >
  
  <!-- =================================================================== -->
  <!-- End of DTD                                                          -->
  <!-- =================================================================== -->
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/pagesheets/text.pagesheet
  
  Index: text.pagesheet
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: text.pagesheet,v 1.2 2003/05/06 14:13:02 vgritsenko Exp $ -->
  
  <pagesheet xmlns="http://apache.org/cocoon/paginate/1.0">
    <rules>
      <count type="chars" name="item" num="110"/>
      <link type="unit" num="1"/>
    </rules>
  </pagesheet>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/paginator/pagesheets/list.pagesheet
  
  Index: list.pagesheet
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- CVS: $Id: list.pagesheet,v 1.1 2003/03/09 00:10:32 pier Exp $ -->
  
  <pagesheet xmlns="http://apache.org/cocoon/paginate/1.0">
    <rules>
      <count type="element" name="item" num="4"/>
      <link type="unit" num="1"/>
    </rules>
  </pagesheet>
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/reading/ImageReader.java
  
  Index: ImageReader.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.reading;
  
  import org.apache.avalon.framework.parameters.Parameters;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.environment.SourceResolver;
  
  import com.sun.image.codec.jpeg.ImageFormatException;
  import com.sun.image.codec.jpeg.JPEGCodec;
  import com.sun.image.codec.jpeg.JPEGDecodeParam;
  import com.sun.image.codec.jpeg.JPEGImageDecoder;
  import com.sun.image.codec.jpeg.JPEGImageEncoder;
  import org.xml.sax.SAXException;
  
  import java.awt.geom.AffineTransform;
  import java.awt.image.AffineTransformOp;
  import java.awt.image.Raster;
  import java.awt.image.WritableRaster;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.Serializable;
  import java.util.Map;
  
  /**
   * The <code>ImageReader</code> component is used to serve binary image data
   * in a sitemap pipeline. It makes use of HTTP Headers to determine if
   * the requested resource should be written to the <code>OutputStream</code>
   * or if it can signal that it hasn't changed.
   *
   * Parameters:
   *   <dl>
   *     <dt>&lt;width&gt;</dt>
   *     <dd>This parameter is optional. When specified it determines the width
   *         of the image that should be served.
   *     </dd>
   *     <dt>&lt;height&gt;</dt>
   *     <dd>This parameter is optional. When specified it determines the height
   *         of the image that should be served.
   *     </dd>
   *   </dl>
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
   * @version CVS $Id: ImageReader.java,v 1.1 2003/06/27 20:10:43 stefano Exp $
   */
  final public class ImageReader extends ResourceReader {
  
      private int width;
      private int height;
  
      public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
              throws ProcessingException, SAXException, IOException {
  
          super.setup(resolver, objectModel, src, par);
  
          width = par.getParameterAsInteger("width", 0);
          height = par.getParameterAsInteger("height", 0);
      }
  
      /** 
       * Returns the affine transform that implements the scaling.
       * The behavior is the following: if both the new width and height values
       * are positive, the image is rescaled according to these new values and
       * the original aspect ration is lost.
       * Otherwise, if one of the two parameters is zero or negative, the
       * aspect ratio is maintained and the positive parameter indicates the
       * scaling.
       * If both new values are zero or negative, no scaling takes place (a unit
       * transformation is applied).
       */
      private AffineTransform getTransform(double ow, double oh, double nw, double nh) {
          double wm = 1.0d;
          double hm = 1.0d;
          
          if (nw > 0) {
              wm = nw / ow;
              if (nh > 0) {
                  hm = nh / oh;
              } else {
                  hm = wm;
              }
          } else {
              if (nh > 0) {
                  hm = nh / oh;
                  wm = hm;
              }
          }
  
          return new AffineTransform(wm, 0.0d, 0.0d, hm, 0.0d, 0.0d);
      }
      
      protected void processStream() throws IOException, ProcessingException {
          if (width > 0 || height > 0) {
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("image " + ((width==0)?"?":Integer.toString(width))
                                    + "x" + ((height==0)?"?":Integer.toString(height))
                                    + " expires: " + expires);
              }
  
              // since we create the image on the fly
              response.setHeader("Accept-Ranges", "none");
  
              /**
               * NOTE (SM):
               * Due to Bug Id 4502892 (which is found in *all* JVM implementations from
               * 1.2.x and 1.3.x on all OS!), we must buffer the JPEG generation to avoid
               * that connection resetting by the peer (user pressing the stop button,
               * for example) crashes the entire JVM (yes, dude, the bug is *that* nasty
               * since it happens in JPEG routines which are native!)
               * I'm perfectly aware of the huge memory problems that this causes (almost
               * doubling memory consuption for each image and making the GC work twice
               * as hard) but it's *far* better than restarting the JVM every 2 minutes
               * (since this is the average experience for image-intensive web application
               * such as an image gallery).
               * Please, go to the <a href="http://developer.java.sun.com/developer/bugParade/bugs/4502892.html">Sun Developers Connection</a>
               * and vote this BUG as the one you would like fixed sooner rather than
               * later and all this hack will automagically go away.
               * Many deep thanks to Michael Hartle <mhartle@hartle-klug.com> for tracking
               * this down and suggesting the workaround.
               *
               * UPDATE (SM):
               * This appears to be fixed on JDK 1.4
               */
  
              try {
                  JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(inputStream);
                  Raster original = decoder.decodeAsRaster();
                  JPEGDecodeParam decodeParam = decoder.getJPEGDecodeParam();
                  double ow = (double) decodeParam.getWidth();
                  double oh = (double) decodeParam.getHeight();
                  AffineTransformOp filter = new AffineTransformOp(getTransform(ow, oh, width, height), AffineTransformOp.TYPE_BILINEAR);
                  WritableRaster scaled = filter.createCompatibleDestRaster(original);
                  filter.filter(original, scaled);
  
                  // JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
  
                  ByteArrayOutputStream bstream = new ByteArrayOutputStream();
                  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bstream);
                  encoder.encode(scaled);
                  out.write(bstream.toByteArray());
  
                  out.flush();
              } catch (ImageFormatException e) {
                  throw new ProcessingException("Error reading the image. Note that only JPEG images are currently supported.");
              }
  
              inputStream.close();
          } else {
              // only read the resource - no modifications requested
              if (getLogger().isDebugEnabled()) {
                  getLogger().debug("passing original resource");
              }
              super.processStream();
          }
      }
  
      /**
       * Generate the unique key.
       * This key must be unique inside the space of this component.
       *
       * @return The generated key consists from src and width and height
       * parameters
      */
      public Serializable getKey() {
          if (width > 0 || height > 0) {
              return this.inputSource.getURI() + ':' + this.width + ':' + this.height;
          } else {
              return super.getKey();
          }
      }
  }
  
  
  
  1.9       +1 -22     cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml
  
  Index: scratchpad-samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/scratchpad-samples.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- scratchpad-samples.xml	22 Jun 2003 18:48:20 -0000	1.8
  +++ scratchpad-samples.xml	27 Jun 2003 20:10:43 -0000	1.9
  @@ -32,27 +32,6 @@
       </sample>
     </group>
   
  -  <group name="Paginator">
  -    <sample name="List Pagination" href="paginator/list(1)">
  -      Show the usage of the Paginator Transformer to paginate document based on items count limit.
  -    </sample>
  -    <sample name="Text Pagination" href="paginator/text(1)">
  -      Show the usage of the Paginator Transformer to paginate document based on characters count limit.
  -    </sample>
  -  </group>
  -  
  -  <group name="ImageReader">
  -    <sample name="Image" href="imagereader/image-0">
  -      Image of original size
  -    </sample>
  -    <sample name="Image 250x250" href="imagereader/image-250">
  -      Image scaled up to the size 250 x 250
  -    </sample>
  -    <sample name="Image 50x50" href="imagereader/image-50">
  -      Image scaled down to the size 50 x 50
  -    </sample>
  -  </group>
  -
     <group name="Jelly">
       <sample name="Test 1" href="jelly/test1">
         A test of the Jelly generator - you have to download and install the jelly.jar first!
  
  
  
  1.19      +22 -1     cocoon-2.1/src/webapp/samples/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/samples.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- samples.xml	20 May 2003 12:02:50 -0000	1.18
  +++ samples.xml	27 Jun 2003 20:10:43 -0000	1.19
  @@ -102,6 +102,27 @@
      </sample>
     </group>
   
  +  <group name="Paginator">
  +    <sample name="List Pagination" href="paginator/list(1)">
  +      Show the usage of the Paginator Transformer to paginate document based on items count limit.
  +    </sample>
  +    <sample name="Text Pagination" href="paginator/text(1)">
  +      Show the usage of the Paginator Transformer to paginate document based on characters count limit.
  +    </sample>
  +  </group>
  +  
  +  <group name="ImageReader">
  +    <sample name="Image" href="imagereader/image-0">
  +      Image of original size
  +    </sample>
  +    <sample name="Image 250x250" href="imagereader/image-250">
  +      Image scaled up to the size 250 x 250
  +    </sample>
  +    <sample name="Image 50x50" href="imagereader/image-50">
  +      Image scaled down to the size 50 x 50
  +    </sample>
  +  </group>
  +  
   <!-- 
   
     FIXME (SM): obsoleted by xmlform?
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/util/ResizableContainer.java
  
  Index: ResizableContainer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
   
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
   
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
   
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
   
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
   
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
   
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
   
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
   
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
   Software Foundation, please see <http://www.apache.org/>.
   
  */
  
  package org.apache.cocoon.util;
  
  /**
   * Add-only Container class.
   *
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version CVS $Id: ResizableContainer.java,v 1.1 2003/06/27 20:10:43 stefano Exp $
   */
  public class ResizableContainer {
  
      private int pointer = -1;
      private int size = 0;
      private Object[] container;
  
      public ResizableContainer(int initialCapacity){
          this.container = new Object[initialCapacity];
      }
  
      public void add(Object o) {
          set(++pointer,o);
      }
      
      public void set(int index, Object o) {
          adjustPointer(index);
          ensureCapacity(index+1);
          container[index] = o;
          size++;
      }
      
      public Object get(int index) {
          return (index < container.length) ? container[index] : null; 
      }    
  
      public int size() {
          return size;
      }
  
      private void adjustPointer(int newPointer) {
          this.pointer = Math.max(this.pointer, newPointer);
      }
      
      private void ensureCapacity(int minCapacity) {
          int oldCapacity = container.length;
          if (oldCapacity < minCapacity) {
              Object[] oldContainer = container;
              int newCapacity = (oldCapacity * 3)/2 + 1;
              if (newCapacity < minCapacity) {
                  newCapacity = minCapacity;
              }
              container = new Object[newCapacity];
              System.arraycopy(oldContainer, 0, container, 0, oldContainer.length);
          }
      }
  }
  
  
  

Mime
View raw message