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 com.sun.xml.internal.fastinfoset.sax.Properties;
325N/Aimport com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser;
325N/Aimport java.io.BufferedInputStream;
325N/Aimport java.io.InputStream;
325N/Aimport java.io.OutputStream;
325N/Aimport javax.xml.parsers.SAXParser;
325N/Aimport javax.xml.parsers.SAXParserFactory;
325N/Aimport com.sun.xml.internal.fastinfoset.tools.StAX2SAXReader;
325N/A
325N/Apublic class FI_StAX_SAX_Or_XML_SAX_SAXEvent extends TransformInputOutput {
325N/A
325N/A public FI_StAX_SAX_Or_XML_SAX_SAXEvent() {
325N/A }
325N/A
325N/A public void parse(InputStream document, OutputStream events) 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 if (isFastInfosetDocument) {
325N/A StAXDocumentParser parser = new StAXDocumentParser();
325N/A parser.setInputStream(document);
325N/A SAXEventSerializer ses = new SAXEventSerializer(events);
325N/A StAX2SAXReader reader = new StAX2SAXReader(parser, ses);
325N/A reader.setLexicalHandler(ses);
325N/A reader.adapt();
325N/A } else {
325N/A SAXParserFactory parserFactory = SAXParserFactory.newInstance();
325N/A parserFactory.setNamespaceAware(true);
325N/A SAXParser parser = parserFactory.newSAXParser();
325N/A SAXEventSerializer ses = new SAXEventSerializer(events);
325N/A parser.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, ses);
325N/A parser.parse(document, ses);
325N/A }
325N/A }
325N/A
325N/A public static void main(String[] args) throws Exception {
325N/A FI_StAX_SAX_Or_XML_SAX_SAXEvent p = new FI_StAX_SAX_Or_XML_SAX_SAXEvent();
325N/A p.parse(args);
325N/A }
325N/A
325N/A}