KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > xml > EmbeddedXMLPipe


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.xml;
17
18 import org.xml.sax.ContentHandler JavaDoc;
19 import org.xml.sax.SAXException JavaDoc;
20 import org.xml.sax.ext.LexicalHandler JavaDoc;
21
22 /**
23  * This class implements a ContentHandler for embedding a full SAX
24  * event stream into an existing stream of SAX events. An instance of
25  * this class will pass unmodified all the SAX events to the linked
26  * ContentHandler, but it will ignore the startDocument/endDocument
27  * and startDTD/endDTD events, as well as all comment events within
28  * the DTD.
29  *
30  * @author <a HREF="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
31  * @version CVS $Id: EmbeddedXMLPipe.java 53970 2004-10-07 14:03:05Z vgritsenko $
32  */

33 public class EmbeddedXMLPipe extends AbstractXMLPipe {
34
35     private boolean inDTD;
36
37     /**
38      * Creates an EmbeddedXMLPipe that writes into the given XMLConsumer.
39      */

40     public EmbeddedXMLPipe(XMLConsumer consumer) {
41         setConsumer(consumer);
42     }
43
44     /**
45      * Creates an EmbeddedXMLPipe that writes into the given ContentHandler.
46      */

47     public EmbeddedXMLPipe(ContentHandler JavaDoc handler) {
48         setContentHandler(handler);
49         if (handler instanceof LexicalHandler JavaDoc) {
50             setLexicalHandler((LexicalHandler JavaDoc) handler);
51         }
52     }
53
54     /**
55      * Creates an EmbeddedXMLPipe that writes into the given ContentHandler.
56      */

57     public EmbeddedXMLPipe(ContentHandler JavaDoc contentHandler, LexicalHandler JavaDoc lexicalHandler) {
58         setContentHandler(contentHandler);
59         setLexicalHandler(lexicalHandler);
60     }
61
62     /**
63      * Ignore the <code>startDocument</code> event: this method does nothing.
64      *
65      * @exception SAXException if an error occurs
66      */

67     public void startDocument() throws SAXException JavaDoc {
68     }
69
70     /**
71      * Ignore the <code>endDocument</code> event: this method does nothing.
72      *
73      * @exception SAXException if an error occurs
74      */

75     public void endDocument() throws SAXException JavaDoc {
76     }
77
78     /**
79      * Ignore the <code>startDTD</code> event: this method does nothing.
80      *
81      * @exception SAXException if an error occurs
82      */

83     public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId)
84     throws SAXException JavaDoc {
85         // Ignored
86
this.inDTD = true;
87     }
88
89     /**
90      * Ignore the <code>endDTD</code> event: this method does nothing.
91      *
92      * @exception SAXException if an error occurs
93      */

94     public void endDTD() throws SAXException JavaDoc {
95         // Ignored
96
this.inDTD = false;
97     }
98
99     /**
100      * Ignore all <code>comment</code> events if between
101      * startDTD/endDTD events.
102      *
103      * @exception SAXException if an error occurs
104      */

105     public void comment(char ch[], int start, int len)
106     throws SAXException JavaDoc {
107         if (!inDTD) {
108             super.comment(ch, start, len);
109         }
110     }
111 }
112
Popular Tags