java/alt2xml-bin/src/cz/frantovo/alt2xml/CLI.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 05 Jun 2014 22:01:58 +0200
changeset 11 aaf6648af0aa
parent 7 9107f7df660c
permissions -rw-r--r--
licence
franta-hg@11
     1
/**
franta-hg@11
     2
 * Alt2XML
franta-hg@11
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@11
     4
 *
franta-hg@11
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@11
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@11
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@11
     8
 * (at your option) any later version.
franta-hg@11
     9
 *
franta-hg@11
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@11
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@11
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@11
    13
 * GNU General Public License for more details.
franta-hg@11
    14
 *
franta-hg@11
    15
 * You should have received a copy of the GNU General Public License
franta-hg@11
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@11
    17
 */
franta-hg@2
    18
package cz.frantovo.alt2xml;
franta-hg@2
    19
franta-hg@3
    20
import cz.frantovo.alt2xml.výstup.EchoContentHandler;
franta-hg@2
    21
import java.io.InputStream;
franta-hg@2
    22
import java.io.OutputStream;
franta-hg@2
    23
import javax.xml.parsers.SAXParser;
franta-hg@2
    24
import javax.xml.parsers.SAXParserFactory;
franta-hg@2
    25
import javax.xml.stream.XMLOutputFactory;
franta-hg@2
    26
import javax.xml.stream.XMLStreamWriter;
franta-hg@2
    27
import org.xml.sax.helpers.DefaultHandler;
franta-hg@2
    28
franta-hg@2
    29
/**
franta-hg@2
    30
 *
franta-hg@2
    31
 * @author fiki
franta-hg@2
    32
 */
franta-hg@2
    33
public class CLI {
franta-hg@2
    34
franta-hg@2
    35
	public static void main(String[] args) throws Exception {
franta-hg@3
    36
		/**
franta-hg@3
    37
		 * Použijeme standardní vstup a výstup:
franta-hg@3
    38
		 */
franta-hg@2
    39
		InputStream vstup = System.in;
franta-hg@2
    40
		OutputStream výstup = System.out;
franta-hg@3
    41
		
franta-hg@3
    42
		/**
franta-hg@3
    43
		 * Serializujeme data do XML.
franta-hg@3
    44
		 * To normálně vůbec není potřeba – data se do tvaru proudu obsahujícího ostré závorky
franta-hg@3
    45
		 * vůbec nedostanou – zpracováváme události (volání javovských metod – začátky a konce elementů atd.)
franta-hg@3
    46
		 * a z nich např. deserializujeme nějaké naše objekty, provádíme nějaké akce, nebo třeba stavíme DOM.
franta-hg@3
    47
		 */
franta-hg@2
    48
		XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
franta-hg@2
    49
		XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(výstup);
franta-hg@2
    50
		DefaultHandler h = new EchoContentHandler(w);
franta-hg@3
    51
		
franta-hg@3
    52
		/**
franta-hg@3
    53
		 * Parsujeme JSON a děláme z něj XML:
franta-hg@3
    54
		 */
franta-hg@3
    55
		SAXParserFactory t = SAXParserFactory.newInstance(SAXTovarna.class.getName(), null);
franta-hg@3
    56
		SAXParser p = t.newSAXParser();
franta-hg@2
    57
		p.parse(vstup, h);
franta-hg@2
    58
	}
franta-hg@2
    59
}