001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.sax;
018:
019: import org.apache.cocoon.xml.XMLConsumer;
020: import org.apache.cocoon.xml.XMLPipe;
021: import org.apache.cocoon.xml.XMLProducer;
022: import org.xml.sax.Attributes;
023: import org.xml.sax.Locator;
024: import org.xml.sax.SAXException;
025:
026: /**
027: * This is a simple Tee Component.
028: * The incoming events are forwarded to two other components.
029: *
030: * @version $Id: XMLTeePipe.java 452060 2006-10-02 14:57:34Z vgritsenko $
031: */
032: public class XMLTeePipe implements XMLPipe {
033:
034: private XMLConsumer firstConsumer;
035: private XMLConsumer secondConsumer;
036:
037: /**
038: * Create a new XMLTeePipe with two consumers
039: */
040: public XMLTeePipe(XMLConsumer firstPipe, XMLConsumer secondConsumer) {
041: this .firstConsumer = firstPipe;
042: this .secondConsumer = secondConsumer;
043: }
044:
045: /**
046: * Set the <code>XMLConsumer</code> that will receive XML data.
047: */
048: public void setConsumer(XMLConsumer consumer) {
049: ((XMLProducer) this .firstConsumer).setConsumer(consumer);
050: }
051:
052: /**
053: * Reset consumers.
054: */
055: public void recycle() {
056: this .firstConsumer = null;
057: this .secondConsumer = null;
058: }
059:
060: //
061: // XMLPipe interface
062: //
063:
064: public void startDocument() throws SAXException {
065: this .firstConsumer.startDocument();
066: this .secondConsumer.startDocument();
067: }
068:
069: public void endDocument() throws SAXException {
070: this .firstConsumer.endDocument();
071: this .secondConsumer.endDocument();
072: }
073:
074: public void startPrefixMapping(String prefix, String uri)
075: throws SAXException {
076: this .firstConsumer.startPrefixMapping(prefix, uri);
077: this .secondConsumer.startPrefixMapping(prefix, uri);
078: }
079:
080: public void endPrefixMapping(String prefix) throws SAXException {
081: this .firstConsumer.endPrefixMapping(prefix);
082: this .secondConsumer.endPrefixMapping(prefix);
083: }
084:
085: public void startElement(String namespaceURI, String localName,
086: String qName, Attributes atts) throws SAXException {
087: this .firstConsumer.startElement(namespaceURI, localName, qName,
088: atts);
089: this .secondConsumer.startElement(namespaceURI, localName,
090: qName, atts);
091: }
092:
093: public void endElement(String namespaceURI, String localName,
094: String qName) throws SAXException {
095: this .firstConsumer.endElement(namespaceURI, localName, qName);
096: this .secondConsumer.endElement(namespaceURI, localName, qName);
097: }
098:
099: public void characters(char[] ch, int start, int length)
100: throws SAXException {
101: this .firstConsumer.characters(ch, start, length);
102: this .secondConsumer.characters(ch, start, length);
103: }
104:
105: public void ignorableWhitespace(char[] ch, int start, int length)
106: throws SAXException {
107: this .firstConsumer.ignorableWhitespace(ch, start, length);
108: this .secondConsumer.ignorableWhitespace(ch, start, length);
109: }
110:
111: public void processingInstruction(String target, String data)
112: throws SAXException {
113: this .firstConsumer.processingInstruction(target, data);
114: this .secondConsumer.processingInstruction(target, data);
115: }
116:
117: public void setDocumentLocator(Locator locator) {
118: this .firstConsumer.setDocumentLocator(locator);
119: this .secondConsumer.setDocumentLocator(locator);
120: }
121:
122: public void skippedEntity(String name) throws SAXException {
123: this .firstConsumer.skippedEntity(name);
124: this .secondConsumer.skippedEntity(name);
125: }
126:
127: public void startDTD(String name, String public_id, String system_id)
128: throws SAXException {
129: this .firstConsumer.startDTD(name, public_id, system_id);
130: this .secondConsumer.startDTD(name, public_id, system_id);
131: }
132:
133: public void endDTD() throws SAXException {
134: this .firstConsumer.endDTD();
135: this .secondConsumer.endDTD();
136: }
137:
138: public void startEntity(String name) throws SAXException {
139: this .firstConsumer.startEntity(name);
140: this .secondConsumer.startEntity(name);
141: }
142:
143: public void endEntity(String name) throws SAXException {
144: this .firstConsumer.endEntity(name);
145: this .secondConsumer.endEntity(name);
146: }
147:
148: public void startCDATA() throws SAXException {
149: this .firstConsumer.startCDATA();
150: this .secondConsumer.startCDATA();
151: }
152:
153: public void endCDATA() throws SAXException {
154: this .firstConsumer.endCDATA();
155: this .secondConsumer.endCDATA();
156: }
157:
158: public void comment(char ary[], int start, int length)
159: throws SAXException {
160: this.firstConsumer.comment(ary, start, length);
161: this.secondConsumer.comment(ary, start, length);
162: }
163: }
|