1 37 38 package net.sourceforge.cruisecontrol.util; 39 40 import org.apache.log4j.Logger; 41 import org.xml.sax.Attributes ; 42 import org.xml.sax.SAXException ; 43 import org.xml.sax.XMLReader ; 44 import org.xml.sax.helpers.XMLFilterImpl ; 45 46 54 public class EmptyElementFilter extends XMLFilterImpl { 55 56 private static final Logger LOG = Logger.getLogger(EmptyElementFilter.class); 57 58 private final String tagName; 59 60 private boolean checkingTag = false; 61 private String messageUri; 63 private String messageQName; 64 private Attributes messageAtts; 65 66 69 public EmptyElementFilter(String tagName) { 70 super(); 71 this.tagName = tagName; 72 } 73 74 78 public EmptyElementFilter(String tagName, XMLReader arg0) { 79 super(arg0); 80 this.tagName = tagName; 81 } 82 83 86 public void characters(char[] ch, int start, int length) throws SAXException { 87 if (checkingTag) { 88 cancelCheck(); 89 } 90 super.characters(ch, start, length); 91 } 92 93 96 public void endElement(String uri, String localName, String qName) throws SAXException { 97 if (checkingTag) { 98 checkingTag = false; 100 LOG.debug("Skipping empty <" + localName + ">-tag"); 101 } else { 102 super.endElement(uri, localName, qName); 103 } 104 } 105 106 109 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { 110 if (checkingTag) { 111 cancelCheck(); 112 } 113 if (localName.equals(tagName)) { 114 checkingTag = true; 116 messageUri = uri; 117 messageQName = qName; 118 messageAtts = atts; 119 } else { 120 super.startElement(uri, localName, qName, atts); 121 } 122 } 123 124 private void cancelCheck() throws SAXException { 125 super.startElement(messageUri, tagName, messageQName, messageAtts); 127 checkingTag = false; 128 } 129 130 } 131 | Popular Tags |