vgritsenko    2002/10/21 21:08:53

  Modified:    src/java/org/apache/cocoon/transformation Tag:
                        cocoon_2_0_3_branch FilterTransformer.java
  Log:
  Remove overoptimization.
  Document limitation.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +22 -18    
xml-cocoon2/src/java/org/apache/cocoon/transformation/FilterTransformer.java
  
  Index: FilterTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/FilterTransformer.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- FilterTransformer.java    22 Feb 2002 07:03:56 -0000      1.7
  +++ FilterTransformer.java    22 Oct 2002 04:08:53 -0000      1.7.2.1
  @@ -68,20 +68,22 @@
    * The filter transformer can be used to let only an amount of elements through in
    * a given block.
    *
  - * Usage in sitemap
  + * <p>Usage in the sitemap:
    *    &lt;map:transform type="filter"&gt;
    *     &lt;map:parameter name="element-name" value="row"/&gt;
    *     &lt;map:parameter name="count" value="5"/&gt;
    *     &lt;map:parameter name="blocknr" value="3"/&gt;
    *    &lt;/map:transform&gt;
    *
  - * Only the 3th block will be shown, containing only 5 row elements.
  + * <p>Only the 3rd block will be shown, containing only 5 row elements.
  + *
  + * <p><b>Known limitation: behaviour of transformer when trigger elements are nested
  + * is not predictable.</b>
    *
    * @author <a href="mailto:sven.beauprez@;the-ecorp.com">Sven Beauprez</a>
    * @author <a href="mailto:cziegeler@;apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  -
   public class FilterTransformer
   extends AbstractTransformer
   implements Cacheable {
  @@ -114,12 +116,12 @@
           this.skip=false;
           this.foundIt=false;
           this.parentName=null;
  -        this.elementName = parameters.getParameter(FilterTransformer.ELEMENT, "");
  -        this.count = parameters.getParameterAsInteger(FilterTransformer.COUNT, 
FilterTransformer.DEFAULT_COUNT);
  -        this.blocknr = parameters.getParameterAsInteger(FilterTransformer.BLOCKNR, 
FilterTransformer.DEFAULT_BLOCK);
  +        this.elementName = parameters.getParameter(ELEMENT, "");
  +        this.count = parameters.getParameterAsInteger(COUNT, DEFAULT_COUNT);
  +        this.blocknr = parameters.getParameterAsInteger(BLOCKNR, DEFAULT_BLOCK);
           if (this.elementName == null || this.elementName.equals("") || this.count 
== 0)  {
  -            throw new ProcessingException("FilterTransformer: both "+ 
FilterTransformer.ELEMENT + " and " +
  -                          FilterTransformer.COUNT + " parameters need to be 
specified");
  +            throw new ProcessingException("FilterTransformer: both "+ ELEMENT + " 
and " +
  +                          COUNT + " parameters need to be specified");
           }
       }
   
  @@ -132,8 +134,7 @@
        *              is currently not cacheable.
        */
       public long generateKey() {
  -        final StringBuffer hash = new StringBuffer(this.elementName);
  -        hash.append('<').append(this.count).append('>').append(this.blocknr);
  +        final String hash = this.elementName + '<' + this.count + '>' + 
this.blocknr;
           return HashUtil.hash(hash);
       }
   
  @@ -163,12 +164,12 @@
               if (this.currentBlocknr != 
(int)Math.ceil((float)this.counter/this.count)) {
                   this.currentBlocknr = 
(int)Math.ceil((float)this.counter/this.count);
                   AttributesImpl attr = new AttributesImpl();
  -                
attr.addAttribute(uri,FilterTransformer.BLOCKID,FilterTransformer.BLOCKID,"CDATA",String.valueOf(this.currentBlocknr));
  +                attr.addAttribute(uri, BLOCKID, 
BLOCKID,"CDATA",String.valueOf(this.currentBlocknr));
                   if (this.counter < this.count)  {
  -                    
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
  +                    super.contentHandler.startElement(uri, BLOCK, BLOCK, attr);
                   } else  {
  -                    
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
  -                    
super.contentHandler.startElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK,attr);
  +                    super.contentHandler.endElement(uri, BLOCK, BLOCK);
  +                    super.contentHandler.startElement(uri, BLOCK, BLOCK, attr);
                   }
               }
           } else if (!this.foundIt)  {
  @@ -182,8 +183,12 @@
       public void endElement(String uri,String name,String raw)
       throws SAXException  {
           if (this.foundIt && name.equals(this.parentName)) {
  -            
super.contentHandler.endElement(uri,FilterTransformer.BLOCK,FilterTransformer.BLOCK);
  -            super.contentHandler.endElement(uri,name,raw);
  +            // FIXME: VG: This will fail on XML like:
  +            // <parent>
  +            //   <element>
  +            //     <parent>
  +            super.contentHandler.endElement(uri, BLOCK, BLOCK);
  +            super.contentHandler.endElement(uri, name, raw);
               this.foundIt = false;
               this.skip = false;
           } else if (!this.skip)  {
  @@ -239,5 +244,4 @@
               super.lexicalHandler.comment(ch, start, len);
           }
       }
  -
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to