1.1 --- a/java/alt2xml-cli/nbproject/project.properties Sat Jun 07 11:28:27 2014 +0200
1.2 +++ b/java/alt2xml-cli/nbproject/project.properties Sat Jun 07 15:03:52 2014 +0200
1.3 @@ -54,10 +54,10 @@
1.4 javadoc.use=true
1.5 javadoc.version=false
1.6 javadoc.windowtitle=
1.7 -main.class=cz.frantovo.alt2xml.CLI
1.8 +main.class=cz.frantovo.alt2xml.cli.CLI
1.9 manifest.file=manifest.mf
1.10 meta.inf.dir=${src.dir}/META-INF
1.11 -mkdist.disabled=false
1.12 +mkdist.disabled=true
1.13 platform.active=default_platform
1.14 project.alt2xml-lib=../alt2xml-lib
1.15 reference.alt2xml-lib.jar=${project.alt2xml-lib}/dist/alt2xml-lib.jar
2.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sat Jun 07 11:28:27 2014 +0200
2.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sat Jun 07 15:03:52 2014 +0200
2.3 @@ -18,7 +18,7 @@
2.4 package cz.frantovo.alt2xml.cli;
2.5
2.6 import cz.frantovo.alt2xml.ParserFactory;
2.7 -import java.io.InputStream;
2.8 +import java.io.File;
2.9 import java.io.OutputStream;
2.10 import javax.xml.parsers.SAXParser;
2.11 import javax.xml.parsers.SAXParserFactory;
2.12 @@ -33,10 +33,9 @@
2.13 public class CLI {
2.14
2.15 public static void main(String[] args) throws Exception {
2.16 - /**
2.17 - * Použijeme standardní vstup a výstup:
2.18 - */
2.19 - InputStream vstup = System.in;
2.20 + System.err.println("startuji…");
2.21 +
2.22 + File vstup = new File(args[0]);
2.23 OutputStream výstup = System.out;
2.24
2.25 /**
2.26 @@ -51,13 +50,10 @@
2.27 XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(výstup);
2.28 DefaultHandler h = new EchoContentHandler(w);
2.29
2.30 - /**
2.31 - * Parsujeme JSON a děláme z něj XML:
2.32 - */
2.33 SAXParserFactory t = SAXParserFactory.newInstance(ParserFactory.class.getName(), null);
2.34 + //SAXParserFactory t = SAXParserFactory.newInstance();
2.35 SAXParser p = t.newSAXParser();
2.36 p.parse(vstup, h);
2.37 -
2.38 -
2.39 +
2.40 }
2.41 }
3.1 --- a/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java Sat Jun 07 11:28:27 2014 +0200
3.2 +++ b/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java Sat Jun 07 15:03:52 2014 +0200
3.3 @@ -19,8 +19,11 @@
3.4
3.5 import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
3.6 import java.io.IOException;
3.7 +import java.util.Map.Entry;
3.8 +import java.util.Properties;
3.9 import org.xml.sax.InputSource;
3.10 import org.xml.sax.SAXException;
3.11 +import org.xml.sax.helpers.AttributesImpl;
3.12
3.13 /**
3.14 *
3.15 @@ -28,8 +31,34 @@
3.16 */
3.17 public class Reader extends AbstractAlt2XmlReader {
3.18
3.19 + /**
3.20 + * <p>
3.21 + * TODO: same format as Java XML properties</p>
3.22 + * <p>
3.23 + * TODO: support also nested mode <code>aaa.bbb.ccc=xxx</code> →
3.24 + * <code><aaa><bbb><ccc>xxx</ccc></bbb></aaa></code></p>
3.25 + */
3.26 @Override
3.27 public void parse(InputSource input) throws IOException, SAXException {
3.28 + Properties loadedData = new Properties();
3.29 + loadedData.load(input.getByteStream());
3.30
3.31 + contentHandler.startDocument();
3.32 + contentHandler.startElement(null, null, "properties", null);
3.33 +
3.34 + for (Entry<Object, Object> e : loadedData.entrySet()) {
3.35 + String key = (String) e.getKey();
3.36 + String value = (String) e.getValue();
3.37 +
3.38 + AttributesImpl attributes = new AttributesImpl();
3.39 + attributes.setAttribute(0, null, "name", "name", "xs:string", key);
3.40 +
3.41 + contentHandler.startElement(null, null, "property", attributes);
3.42 + contentHandler.characters(value.toCharArray(), 0, value.length());
3.43 + contentHandler.endElement(null, null, "property");
3.44 + }
3.45 +
3.46 + contentHandler.endElement(null, null, "properties");
3.47 + contentHandler.endDocument();
3.48 }
3.49 }
4.1 --- a/java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java Sat Jun 07 11:28:27 2014 +0200
4.2 +++ b/java/alt2xml-lib/src/cz/frantovo/alt2xml/SuperReader.java Sat Jun 07 15:03:52 2014 +0200
4.3 @@ -18,7 +18,7 @@
4.4 package cz.frantovo.alt2xml;
4.5
4.6 import java.io.IOException;
4.7 -import java.io.InputStreamReader;
4.8 +import java.net.URI;
4.9 import java.util.HashMap;
4.10 import java.util.Map;
4.11 import org.xml.sax.ContentHandler;
4.12 @@ -41,7 +41,7 @@
4.13 private ErrorHandler errorHandler;
4.14 private DTDHandler dtdHandler;
4.15 private EntityResolver entityResolver;
4.16 - private Map<String, Object> konfigurace = new HashMap<>();
4.17 + private Map<String, Object> properties = new HashMap<>();
4.18 private final ReaderFinder readerFinder;
4.19
4.20 public SuperReader(ReaderFinder readerFinder) {
4.21 @@ -50,20 +50,11 @@
4.22
4.23 @Override
4.24 public void parse(InputSource input) throws IOException, SAXException {
4.25 - /**
4.26 - * TODO: rozpornat formát vstupu a podle toho delegovat
4.27 - */
4.28 - //JSONParser p = new JSONParser();
4.29 - InputStreamReader vstup = new InputStreamReader(input.getByteStream());
4.30 - //JsonSimpleContentHandler handler = new JsonSimpleContentHandler(contentHandler);
4.31
4.32 - /*
4.33 - try {
4.34 - p.parse(vstup, handler);
4.35 - } catch (ParseException e) {
4.36 - throw new SAXException("Chyba při načítání JSONu", e);
4.37 - }
4.38 - */
4.39 + System.err.println("SystemId: " + input.getSystemId());
4.40 +
4.41 + XMLReader reader = readerFinder.findReader(input.getSystemId());
4.42 + reader.parse(input);
4.43 }
4.44
4.45 @Override
4.46 @@ -89,12 +80,12 @@
4.47
4.48 @Override
4.49 public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
4.50 - return konfigurace.get(name);
4.51 + return properties.get(name);
4.52 }
4.53
4.54 @Override
4.55 public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
4.56 - konfigurace.put(name, value);
4.57 + properties.put(name, value);
4.58 }
4.59
4.60 @Override