325N/A/*
325N/A * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A *
325N/A * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.fastinfoset.tools;
325N/A
325N/Aimport com.sun.xml.internal.fastinfoset.Decoder;
325N/Aimport javax.xml.parsers.SAXParser;
325N/Aimport javax.xml.parsers.SAXParserFactory;
325N/Aimport javax.xml.transform.sax.SAXSource;
325N/Aimport com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetSource;
325N/Aimport java.io.BufferedInputStream;
325N/Aimport java.io.InputStream;
325N/Aimport java.io.OutputStream;
325N/Aimport javax.xml.transform.Transformer;
325N/Aimport javax.xml.transform.TransformerFactory;
325N/Aimport javax.xml.transform.dom.DOMResult;
325N/Aimport javax.xml.transform.dom.DOMSource;
325N/Aimport javax.xml.transform.sax.SAXResult;
325N/Aimport javax.xml.transform.stream.StreamSource;
325N/Aimport org.xml.sax.InputSource;
325N/Aimport org.xml.sax.XMLReader;
325N/A
325N/Apublic class FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent extends TransformInputOutput {
325N/A
325N/A public FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent() {
325N/A }
325N/A
325N/A public void parse(InputStream document, OutputStream events, String workingDirectory) throws Exception {
325N/A if (!document.markSupported()) {
325N/A document = new BufferedInputStream(document);
325N/A }
325N/A
325N/A document.mark(4);
325N/A boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document);
325N/A document.reset();
325N/A
325N/A TransformerFactory tf = TransformerFactory.newInstance();
325N/A Transformer t = tf.newTransformer();
325N/A DOMResult dr = new DOMResult();
325N/A
325N/A if (isFastInfosetDocument) {
325N/A t.transform(new FastInfosetSource(document), dr);
325N/A } else if (workingDirectory != null) {
325N/A SAXParser parser = getParser();
325N/A XMLReader reader = parser.getXMLReader();
325N/A reader.setEntityResolver(createRelativePathResolver(workingDirectory));
325N/A SAXSource source = new SAXSource(reader, new InputSource(document));
325N/A
325N/A t.transform(source, dr);
325N/A } else {
325N/A t.transform(new StreamSource(document), dr);
325N/A }
325N/A
325N/A SAXEventSerializer ses = new SAXEventSerializer(events);
325N/A t.transform(new DOMSource(dr.getNode()), new SAXResult(ses));
325N/A }
325N/A
325N/A public void parse(InputStream document, OutputStream events) throws Exception {
325N/A parse(document, events, null);
325N/A }
325N/A
325N/A private SAXParser getParser() {
325N/A SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
325N/A saxParserFactory.setNamespaceAware(true);
325N/A try {
325N/A return saxParserFactory.newSAXParser();
325N/A } catch (Exception e) {
325N/A return null;
325N/A }
325N/A }
325N/A
325N/A public static void main(String[] args) throws Exception {
325N/A FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent p = new FI_SAX_Or_XML_SAX_DOM_SAX_SAXEvent();
325N/A p.parse(args);
325N/A }
325N/A
325N/A}