vgritsenko 2002/10/21 21:08:53 Modified: src/java/org/apache/cocoon/transformation FilterTransformer.java Log: Remove overoptimization. Document limitation. Revision Changes Path 1.9 +22 -19 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FilterTransformer.java 28 May 2002 13:08:13 -0000 1.8 +++ FilterTransformer.java 22 Oct 2002 04:08:53 -0000 1.9 @@ -67,20 +67,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: * <map:transform type="filter"> * <map:parameter name="element-name" value="row"/> * <map:parameter name="count" value="5"/> * <map:parameter name="blocknr" value="3"/> * </map:transform> * - * 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 CacheableProcessingComponent { @@ -113,12 +115,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"); } } @@ -131,9 +133,7 @@ * is currently not cacheable. */ public java.io.Serializable generateKey() { - final StringBuffer hash = new StringBuffer(this.elementName); - hash.append('<').append(this.count).append('>').append(this.blocknr); - return hash; + return this.elementName + '<' + this.count + '>' + this.blocknr; } /** @@ -162,12 +162,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) { @@ -181,8 +181,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) { @@ -238,5 +242,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]