01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.utils;
07:
08: import java.io.IOException;
09: import java.io.StringReader;
10:
11: import javax.xml.parsers.ParserConfigurationException;
12: import javax.xml.parsers.SAXParserFactory;
13:
14: import org.xml.sax.ContentHandler;
15: import org.xml.sax.InputSource;
16: import org.xml.sax.SAXException;
17: import org.xml.sax.XMLReader;
18:
19: /**
20: * Convenience methods for SAX parsing
21: * @author Bernie Durfee, bdurfee@interactivebusiness.com
22: * @version $Revision: 34797 $
23: */
24: public class SAXHelper {
25:
26: /**
27: * Outputs SAX events to specified ContentHandler based on the content String
28: * @param out the ContentHandler
29: * @param content an XML string
30: * @exception SAXException, IOException, ParserConfigurationException
31: */
32: public static synchronized void outputContent(ContentHandler out,
33: String content) throws SAXException, IOException,
34: ParserConfigurationException {
35: XMLReader xmlReader = SAXParserFactory.newInstance()
36: .newSAXParser().getXMLReader();
37: xmlReader.setContentHandler(out);
38: xmlReader.parse(new InputSource(new StringReader(content)));
39: }
40: }
|