001    /*
002     * Copyright (c) 2007 Henri Sivonen
003     * Copyright (c) 2007 Mozilla Foundation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a 
006     * copy of this software and associated documentation files (the "Software"), 
007     * to deal in the Software without restriction, including without limitation 
008     * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
009     * and/or sell copies of the Software, and to permit persons to whom the 
010     * Software is furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in 
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
018     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
020     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
021     * DEALINGS IN THE SOFTWARE.
022     */
023    
024    package nu.validator.xml;
025    
026    import org.xml.sax.Attributes;
027    import org.xml.sax.ContentHandler;
028    import org.xml.sax.Locator;
029    import org.xml.sax.SAXException;
030    
031    public class CombineContentHandler implements ContentHandler {
032    
033        private final ContentHandler first;
034    
035        private final ContentHandler second;
036    
037        /**
038         * @param first
039         * @param second
040         */
041        public CombineContentHandler(ContentHandler first, ContentHandler second) {
042            this.first = first;
043            this.second = second;
044        }
045    
046        /**
047         * @param arg0
048         * @param arg1
049         * @param arg2
050         * @throws SAXException
051         * @see org.xml.sax.ContentHandler#characters(char[], int, int)
052         */
053        public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
054            first.characters(arg0, arg1, arg2);
055            second.characters(arg0, arg1, arg2);
056        }
057    
058        /**
059         * @throws SAXException
060         * @see org.xml.sax.ContentHandler#endDocument()
061         */
062        public void endDocument() throws SAXException {
063            first.endDocument();
064            second.endDocument();
065        }
066    
067        /**
068         * @param arg0
069         * @param arg1
070         * @param arg2
071         * @throws SAXException
072         * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
073         *      java.lang.String, java.lang.String)
074         */
075        public void endElement(String arg0, String arg1, String arg2)
076                throws SAXException {
077            first.endElement(arg0, arg1, arg2);
078            second.endElement(arg0, arg1, arg2);
079        }
080    
081        /**
082         * @param arg0
083         * @throws SAXException
084         * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
085         */
086        public void endPrefixMapping(String arg0) throws SAXException {
087            first.endPrefixMapping(arg0);
088            second.endPrefixMapping(arg0);
089        }
090    
091        /**
092         * @param arg0
093         * @param arg1
094         * @param arg2
095         * @throws SAXException
096         * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
097         */
098        public void ignorableWhitespace(char[] arg0, int arg1, int arg2)
099                throws SAXException {
100            first.ignorableWhitespace(arg0, arg1, arg2);
101            second.ignorableWhitespace(arg0, arg1, arg2);
102        }
103    
104        /**
105         * @param arg0
106         * @param arg1
107         * @throws SAXException
108         * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String,
109         *      java.lang.String)
110         */
111        public void processingInstruction(String arg0, String arg1)
112                throws SAXException {
113            first.processingInstruction(arg0, arg1);
114            second.processingInstruction(arg0, arg1);
115        }
116    
117        /**
118         * @param arg0
119         * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
120         */
121        public void setDocumentLocator(Locator arg0) {
122            first.setDocumentLocator(arg0);
123            second.setDocumentLocator(arg0);
124        }
125    
126        /**
127         * @param arg0
128         * @throws SAXException
129         * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
130         */
131        public void skippedEntity(String arg0) throws SAXException {
132            first.skippedEntity(arg0);
133            second.skippedEntity(arg0);
134        }
135    
136        /**
137         * @throws SAXException
138         * @see org.xml.sax.ContentHandler#startDocument()
139         */
140        public void startDocument() throws SAXException {
141            first.startDocument();
142            second.startDocument();
143        }
144    
145        /**
146         * @param arg0
147         * @param arg1
148         * @param arg2
149         * @param arg3
150         * @throws SAXException
151         * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
152         *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
153         */
154        public void startElement(String arg0, String arg1, String arg2,
155                Attributes arg3) throws SAXException {
156            first.startElement(arg0, arg1, arg2, arg3);
157            second.startElement(arg0, arg1, arg2, arg3);
158        }
159    
160        /**
161         * @param arg0
162         * @param arg1
163         * @throws SAXException
164         * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String,
165         *      java.lang.String)
166         */
167        public void startPrefixMapping(String arg0, String arg1)
168                throws SAXException {
169            first.startPrefixMapping(arg0, arg1);
170            second.startPrefixMapping(arg0, arg1);
171        }
172    
173    }