KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > AnnotationsFilter


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.treeprocessor;
17
18 import org.xml.sax.Attributes JavaDoc;
19 import org.xml.sax.ContentHandler JavaDoc;
20 import org.xml.sax.Locator JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22
23 /** Filter out annotations in the sitemap
24  * (bugzilla 25352)
25  * $Id$
26  */

27 class AnnotationsFilter implements ContentHandler JavaDoc {
28     public static final String JavaDoc ANNOTATIONS_NAMESPACE = "http://apache.org/cocoon/sitemap/annotations/1.0";
29
30     private ContentHandler JavaDoc delegate;
31
32     private int nestingLevel;
33
34     private boolean isOutsideAnnotation()
35     {
36         return nestingLevel == 0;
37     }
38
39     public AnnotationsFilter(ContentHandler JavaDoc delegate) {
40         this.delegate = delegate;
41     }
42
43     public void setDocumentLocator(Locator JavaDoc locator) {
44         delegate.setDocumentLocator(locator);
45     }
46
47     public void startDocument() throws SAXException JavaDoc {
48         delegate.startDocument();
49     }
50
51     public void endDocument() throws SAXException JavaDoc {
52         delegate.endDocument();
53     }
54
55     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc namespaceURI) throws SAXException JavaDoc {
56         if (isOutsideAnnotation()) {
57             delegate.startPrefixMapping(prefix, namespaceURI);
58         }
59     }
60
61     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc {
62         if (isOutsideAnnotation()) {
63             delegate.endPrefixMapping(prefix);
64         }
65     }
66
67     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
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 JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
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 JavaDoc {
86         if (isOutsideAnnotation()) {
87             delegate.characters(ch, start, len);
88         }
89     }
90
91     public void ignorableWhitespace(char[] ch, int start, int len) throws SAXException JavaDoc {
92         if (isOutsideAnnotation()) {
93             delegate.ignorableWhitespace(ch, start, len);
94         }
95     }
96
97     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
98         if (isOutsideAnnotation()) {
99             delegate.processingInstruction(target, data);
100         }
101     }
102
103     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
104         if (isOutsideAnnotation()) {
105             delegate.skippedEntity(name);
106         }
107     }
108 }
109
Popular Tags