001 package fi.iki.hsivonen.xml; 002 003 import org.xml.sax.Attributes; 004 import org.xml.sax.SAXException; 005 import org.xml.sax.XMLReader; 006 import org.xml.sax.helpers.AttributesImpl; 007 import org.xml.sax.helpers.XMLFilterImpl; 008 009 public class XhtmlIdFilter extends XMLFilterImpl { 010 011 public XhtmlIdFilter() { 012 super(); 013 } 014 015 public XhtmlIdFilter(XMLReader parent) { 016 super(parent); 017 } 018 019 /** 020 * @see org.xml.sax.helpers.XMLFilterImpl#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 021 */ 022 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { 023 if ("http://www.w3.org/1999/xhtml".equals(uri)) { 024 int index = atts.getIndex("", "id"); 025 if (index != -1 && !"ID".equals(atts.getType(index))) { 026 AttributesImpl ai = new AttributesImpl(atts); 027 ai.setType(index, "ID"); 028 super.startElement(uri, localName, qName, ai); 029 } else { 030 super.startElement(uri, localName, qName, atts); 031 } 032 } else { 033 super.startElement(uri, localName, qName, atts); 034 } 035 } 036 }