KickJava   Java API By Example, From Geeks To Geeks.

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


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.Attributes JavaDoc;
19 import org.xml.sax.ContentHandler JavaDoc;
20 import org.xml.sax.Locator JavaDoc;
21 import org.xml.sax.SAXException JavaDoc;
22 import org.xml.sax.ext.LexicalHandler JavaDoc;
23
24 /**
25  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
26  * @version CVS $Id: XMLMulticaster.java 30932 2004-07-29 17:35:38Z vgritsenko $
27  */

28
29 public final class XMLMulticaster implements XMLConsumer {
30
31     /**
32      * The XMLMulticaster forwards incomming sax events to a list of
33      * receiving objects.
34      */

35     private ContentHandler JavaDoc[] contentHandlerList;
36     private LexicalHandler JavaDoc[] lexicalHandlerList;
37
38     /**
39      * Create a new XMLMulticaster with two consumers
40      */

41     public XMLMulticaster(XMLConsumer firstConsumer, XMLConsumer secondConsumer) {
42         this.contentHandlerList = new ContentHandler JavaDoc[] {firstConsumer, secondConsumer};
43         this.lexicalHandlerList = new LexicalHandler JavaDoc[] {firstConsumer, secondConsumer};
44     }
45
46     /**
47      * Create a new XMLMulticaster from two contentHandler/lexicalHandler pairs
48      */

49     public XMLMulticaster(ContentHandler JavaDoc firstContentHandler,
50                           LexicalHandler JavaDoc firstLexicalHandler,
51                           ContentHandler JavaDoc secondContentHandler,
52                           LexicalHandler JavaDoc secondLexicalHandler) {
53         this.contentHandlerList = new ContentHandler JavaDoc[] {firstContentHandler, secondContentHandler};
54         this.lexicalHandlerList = new LexicalHandler JavaDoc[] {firstLexicalHandler, secondLexicalHandler};
55     }
56
57     public XMLMulticaster(ContentHandler JavaDoc[] chList,
58                           LexicalHandler JavaDoc[] lhList) {
59         this.contentHandlerList = chList;
60         this.lexicalHandlerList = lhList;
61     }
62
63     public void startDocument() throws SAXException JavaDoc {
64         for(int i=0; i<this.contentHandlerList.length; i++) {
65             this.contentHandlerList[i].startDocument();
66         }
67     }
68
69     public void endDocument() throws SAXException JavaDoc {
70         for(int i=0; i<this.contentHandlerList.length; i++) {
71                 this.contentHandlerList[i].endDocument();
72         }
73     }
74
75     public void startPrefixMapping(java.lang.String JavaDoc prefix, java.lang.String JavaDoc uri) throws SAXException JavaDoc {
76         for(int i=0; i<this.contentHandlerList.length; i++)
77                 this.contentHandlerList[i].startPrefixMapping(prefix, uri);
78     }
79
80     public void endPrefixMapping(java.lang.String JavaDoc prefix) throws SAXException JavaDoc {
81         for(int i=0; i<this.contentHandlerList.length; i++)
82                 this.contentHandlerList[i].endPrefixMapping(prefix);
83     }
84
85     public void startElement(java.lang.String JavaDoc namespaceURI, java.lang.String JavaDoc localName, java.lang.String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
86         for(int i=0; i<this.contentHandlerList.length; i++)
87                 this.contentHandlerList[i].startElement(namespaceURI, localName, qName, atts);
88     }
89
90     public void endElement(java.lang.String JavaDoc namespaceURI, java.lang.String JavaDoc localName, java.lang.String JavaDoc qName) throws SAXException JavaDoc {
91         for(int i=0; i<this.contentHandlerList.length; i++)
92                 this.contentHandlerList[i].endElement(namespaceURI, localName, qName);
93     }
94
95     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc {
96         for(int i=0; i<this.contentHandlerList.length; i++)
97                 this.contentHandlerList[i].characters(ch, start, length);
98     }
99
100     public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException JavaDoc {
101         for(int i=0; i<this.contentHandlerList.length; i++)
102                 this.contentHandlerList[i].ignorableWhitespace(ch, start, length);
103     }
104
105     public void processingInstruction(java.lang.String JavaDoc target, java.lang.String JavaDoc data) throws SAXException JavaDoc {
106         for(int i=0; i<this.contentHandlerList.length; i++)
107                 this.contentHandlerList[i].processingInstruction(target, data);
108     }
109
110     public void setDocumentLocator(Locator JavaDoc locator) {
111         for(int i=0; i<this.contentHandlerList.length; i++)
112                 this.contentHandlerList[i].setDocumentLocator(locator);
113     }
114
115     public void skippedEntity(java.lang.String JavaDoc name) throws SAXException JavaDoc {
116         for(int i=0; i<this.contentHandlerList.length; i++)
117                 this.contentHandlerList[i].skippedEntity(name);
118     }
119
120     public void startDTD(String JavaDoc name, String JavaDoc public_id, String JavaDoc system_id)
121                         throws SAXException JavaDoc {
122         for(int i=0; i<this.lexicalHandlerList.length; i++)
123             if (this.lexicalHandlerList[i] != null)
124                 this.lexicalHandlerList[i].startDTD(name, public_id, system_id);
125     }
126
127     public void endDTD() throws SAXException JavaDoc {
128         for(int i=0; i<this.lexicalHandlerList.length; i++)
129             if (this.lexicalHandlerList[i] != null)
130                 this.lexicalHandlerList[i].endDTD();
131     }
132
133     public void startEntity(String JavaDoc name) throws SAXException JavaDoc {
134         for(int i=0; i<this.lexicalHandlerList.length; i++)
135             if (this.lexicalHandlerList[i] != null)
136                  this.lexicalHandlerList[i].startEntity(name);
137     }
138
139     public void endEntity(String JavaDoc name) throws SAXException JavaDoc {
140         for(int i=0; i<this.lexicalHandlerList.length; i++)
141             if (this.lexicalHandlerList[i] != null)
142                 this.lexicalHandlerList[i].endEntity(name);
143     }
144
145     public void startCDATA() throws SAXException JavaDoc {
146         for(int i=0; i<this.lexicalHandlerList.length; i++)
147             if (this.lexicalHandlerList[i] != null)
148                 this.lexicalHandlerList[i].startCDATA();
149     }
150
151     public void endCDATA() throws SAXException JavaDoc {
152         for(int i=0; i<this.lexicalHandlerList.length; i++)
153             if (this.lexicalHandlerList[i] != null)
154                 this.lexicalHandlerList[i].endCDATA();
155     }
156
157     public void comment(char ary[], int start, int length)
158                         throws SAXException JavaDoc {
159         for(int i=0; i<this.lexicalHandlerList.length; i++)
160             if (this.lexicalHandlerList[i] != null)
161                 this.lexicalHandlerList[i].comment(ary, start, length);
162     }
163 }
164
Popular Tags