1 16 package org.apache.cocoon.forms.generation; 17 18 import org.apache.cocoon.forms.FormsConstants; 19 import org.apache.cocoon.xml.AbstractXMLPipe; 20 import org.xml.sax.Attributes ; 21 import org.xml.sax.ContentHandler ; 22 import org.xml.sax.SAXException ; 23 import org.xml.sax.helpers.DefaultHandler ; 24 25 31 public class SelectionListFilter extends AbstractXMLPipe { 32 33 private ContentHandler next; 34 private int filterDepth = 0; 35 private int depth = 0; 36 private String filterValue; 37 private static final ContentHandler NULL_HANDLER = new DefaultHandler (); 38 39 public SelectionListFilter(String filterValue, ContentHandler next) { 40 this.next = next; 41 this.setContentHandler(next); 42 this.filterValue = filterValue; 43 } 44 45 public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { 46 depth++; 47 48 if (uri.equals(FormsConstants.INSTANCE_NS) && loc.equals("item")) { 49 String value = a.getValue("value"); 50 if (!value.startsWith(this.filterValue)) { 51 filterDepth = depth; 52 setContentHandler(NULL_HANDLER); 53 } 54 } 55 56 super.startElement(uri, loc, raw, a); 57 } 58 59 public void endElement(String uri, String loc, String raw) throws SAXException { 60 super.endElement(uri, loc, raw); 61 62 if (depth == filterDepth) { 63 filterDepth = 0; 64 setContentHandler(this.next); 65 } 66 67 depth--; 68 } 69 } 70 | Popular Tags |