1 16 package org.apache.cocoon.components.treeprocessor; 17 18 import org.xml.sax.Attributes ; 19 import org.xml.sax.ContentHandler ; 20 import org.xml.sax.Locator ; 21 import org.xml.sax.SAXException ; 22 23 27 class AnnotationsFilter implements ContentHandler { 28 public static final String ANNOTATIONS_NAMESPACE = "http://apache.org/cocoon/sitemap/annotations/1.0"; 29 30 private ContentHandler delegate; 31 32 private int nestingLevel; 33 34 private boolean isOutsideAnnotation() 35 { 36 return nestingLevel == 0; 37 } 38 39 public AnnotationsFilter(ContentHandler delegate) { 40 this.delegate = delegate; 41 } 42 43 public void setDocumentLocator(Locator locator) { 44 delegate.setDocumentLocator(locator); 45 } 46 47 public void startDocument() throws SAXException { 48 delegate.startDocument(); 49 } 50 51 public void endDocument() throws SAXException { 52 delegate.endDocument(); 53 } 54 55 public void startPrefixMapping(String prefix, String namespaceURI) throws SAXException { 56 if (isOutsideAnnotation()) { 57 delegate.startPrefixMapping(prefix, namespaceURI); 58 } 59 } 60 61 public void endPrefixMapping(String prefix) throws SAXException { 62 if (isOutsideAnnotation()) { 63 delegate.endPrefixMapping(prefix); 64 } 65 } 66 67 public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { 68 if (namespaceURI != null && namespaceURI.equals(ANNOTATIONS_NAMESPACE)) { 69 nestingLevel++; 70 } 71 if (isOutsideAnnotation()) { 72 delegate.startElement(namespaceURI, localName, qName, attributes); 73 } 74 } 75 76 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 77 if (isOutsideAnnotation()) { 78 delegate.endElement(namespaceURI, localName, qName); 79 } 80 if (namespaceURI != null && namespaceURI.equals(ANNOTATIONS_NAMESPACE)) { 81 nestingLevel--; 82 } 83 } 84 85 public void characters(char[] ch, int start, int len) throws SAXException { 86 if (isOutsideAnnotation()) { 87 delegate.characters(ch, start, len); 88 } 89 } 90 91 public void ignorableWhitespace(char[] ch, int start, int len) throws SAXException { 92 if (isOutsideAnnotation()) { 93 delegate.ignorableWhitespace(ch, start, len); 94 } 95 } 96 97 public void processingInstruction(String target, String data) throws SAXException { 98 if (isOutsideAnnotation()) { 99 delegate.processingInstruction(target, data); 100 } 101 } 102 103 public void skippedEntity(String name) throws SAXException { 104 if (isOutsideAnnotation()) { 105 delegate.skippedEntity(name); 106 } 107 } 108 } 109 | Popular Tags |