You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ju...@apache.org on 2009/02/11 18:59:25 UTC
svn commit: r743430 -
/commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java
Author: jukka
Date: Wed Feb 11 17:59:25 2009
New Revision: 743430
URL: http://svn.apache.org/viewvc?rev=743430&view=rev
Log:
xml: Added a TeeContentHandler based on the similar class in Apache Tika.
Added:
commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java
- copied, changed from r743413, lucene/tika/trunk/src/main/java/org/apache/tika/sax/TeeContentHandler.java
Copied: commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java (from r743413, lucene/tika/trunk/src/main/java/org/apache/tika/sax/TeeContentHandler.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java?p2=commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java&p1=lucene/tika/trunk/src/main/java/org/apache/tika/sax/TeeContentHandler.java&r1=743413&r2=743430&rev=743430&view=diff
==============================================================================
--- lucene/tika/trunk/src/main/java/org/apache/tika/sax/TeeContentHandler.java (original)
+++ commons/sandbox/xml/trunk/src/main/java/org/apache/commons/xml/TeeContentHandler.java Wed Feb 11 17:59:25 2009
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.tika.sax;
+package org.apache.commons.xml;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@@ -23,17 +23,44 @@
import org.xml.sax.helpers.DefaultHandler;
/**
- * Content handler proxy that forwards the received SAX events to zero or
- * more underlying content handlers.
+ * A multiplexing content handler proxy that copies all received SAX events to
+ * zero or more proxied content handlers. If a proxied content handler throws
+ * an exception when receiving an event, then the exception is passed directly
+ * to the caller without giving any of the remaining handlers a chance to
+ * process the event.
+ * <p>
+ * As a convenience this class inherits the {@link DefaultHandler} class
+ * instead of just the {@link ContentHandler} interface. This makes it
+ * possible to pass instances of this class to methods like
+ * {@link javax.xml.parsers.SAXParser#parse(String, DefaultHandler)} that
+ * expect a DefaultHandler instance instead of a ContentHandler.
*/
public class TeeContentHandler extends DefaultHandler {
+ /**
+ * The proxied content handlers.
+ */
private final ContentHandler[] handlers;
+ /**
+ * Creates a multiplexing proxy that passes received SAX events to
+ * all the given content handlers.
+ *
+ * @param handlers content handlers to be proxied
+ */
public TeeContentHandler(ContentHandler... handlers) {
this.handlers = handlers;
}
+ //------------------------------------------------------< ContentHandler >
+
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param prefix passed through
+ * @param uri passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
@@ -42,6 +69,12 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param prefix passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void endPrefixMapping(String prefix) throws SAXException {
for (ContentHandler handler : handlers) {
@@ -49,6 +82,13 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param target passed through
+ * @param data passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void processingInstruction(String target, String data)
throws SAXException {
@@ -57,6 +97,11 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param locator passed through
+ */
@Override
public void setDocumentLocator(Locator locator) {
for (ContentHandler handler : handlers) {
@@ -64,6 +109,11 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @throws SAXException if an error occurs
+ */
@Override
public void startDocument() throws SAXException {
for (ContentHandler handler : handlers) {
@@ -71,6 +121,11 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @throws SAXException if an error occurs
+ */
@Override
public void endDocument() throws SAXException {
for (ContentHandler handler : handlers) {
@@ -78,6 +133,15 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param namespaceURI passed through
+ * @param localName passed through
+ * @param qName passed through
+ * @param atts passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void startElement(
String uri, String localName, String name, Attributes atts)
@@ -87,6 +151,14 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param namespaceURI passed through
+ * @param localName passed through
+ * @param qName passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
@@ -95,6 +167,14 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param ch passed through
+ * @param start passed through
+ * @param length passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
@@ -103,6 +183,14 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param ch passed through
+ * @param start passed through
+ * @param length passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void ignorableWhitespace(char[] ch, int start, int length)
throws SAXException {
@@ -111,6 +199,12 @@
}
}
+ /**
+ * Delegated to the proxied {@link #handlers}.
+ *
+ * @param name passed through
+ * @throws SAXException if an error occurs
+ */
@Override
public void skippedEntity(String name) throws SAXException {
for (ContentHandler handler : handlers) {