001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: *
025: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026: */
027:
028: /*
029: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
030: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
031: *
032: * This code is free software; you can redistribute it and/or modify it
033: * under the terms of the GNU General Public License version 2 only, as
034: * published by the Free Software Foundation. Sun designates this
035: * particular file as subject to the "Classpath" exception as provided
036: * by Sun in the LICENSE file that accompanied this code.
037: *
038: * This code is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
040: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
041: * version 2 for more details (a copy is included in the LICENSE file that
042: * accompanied this code).
043: *
044: * You should have received a copy of the GNU General Public License version
045: * 2 along with this work; if not, write to the Free Software Foundation,
046: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047: *
048: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
049: * CA 95054 USA or visit www.sun.com if you need additional information or
050: * have any questions.
051: *
052: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
053: *
054: */
055:
056: package com.sun.xml.internal.fastinfoset.tools;
057:
058: import com.sun.xml.internal.fastinfoset.sax.SAXDocumentSerializer;
059: import java.io.InputStream;
060: import java.io.OutputStream;
061: import javax.xml.parsers.SAXParser;
062: import javax.xml.parsers.SAXParserFactory;
063: import java.io.Reader;
064: import org.xml.sax.InputSource;
065:
066: public class XML_SAX_FI extends TransformInputOutput {
067:
068: public XML_SAX_FI() {
069: }
070:
071: public void parse(InputStream xml, OutputStream finf)
072: throws Exception {
073: SAXParser saxParser = getParser();
074: SAXDocumentSerializer documentSerializer = getSerializer(finf);
075:
076: saxParser.setProperty(
077: "http://xml.org/sax/properties/lexical-handler",
078: documentSerializer);
079: saxParser.parse(xml, documentSerializer);
080: }
081:
082: public void convert(Reader reader, OutputStream finf)
083: throws Exception {
084: InputSource is = new InputSource(reader);
085:
086: SAXParser saxParser = getParser();
087: SAXDocumentSerializer documentSerializer = getSerializer(finf);
088:
089: saxParser.setProperty(
090: "http://xml.org/sax/properties/lexical-handler",
091: documentSerializer);
092: saxParser.parse(is, documentSerializer);
093: }
094:
095: private SAXParser getParser() {
096: SAXParserFactory saxParserFactory = SAXParserFactory
097: .newInstance();
098: saxParserFactory.setNamespaceAware(true);
099: try {
100: return saxParserFactory.newSAXParser();
101: } catch (Exception e) {
102: return null;
103: }
104: }
105:
106: private SAXDocumentSerializer getSerializer(OutputStream finf) {
107: SAXDocumentSerializer documentSerializer = new SAXDocumentSerializer();
108: documentSerializer.setOutputStream(finf);
109: return documentSerializer;
110: }
111:
112: public static void main(String[] args) throws Exception {
113: XML_SAX_FI s = new XML_SAX_FI();
114: s.parse(args);
115: }
116: }
|