1.1 --- a/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java Sat Jun 07 11:28:27 2014 +0200
1.2 +++ b/java/alt2xml-in-properties/src/cz/frantovo/alt2xml/in/properties/Reader.java Sat Jun 07 15:03:52 2014 +0200
1.3 @@ -19,8 +19,11 @@
1.4
1.5 import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
1.6 import java.io.IOException;
1.7 +import java.util.Map.Entry;
1.8 +import java.util.Properties;
1.9 import org.xml.sax.InputSource;
1.10 import org.xml.sax.SAXException;
1.11 +import org.xml.sax.helpers.AttributesImpl;
1.12
1.13 /**
1.14 *
1.15 @@ -28,8 +31,34 @@
1.16 */
1.17 public class Reader extends AbstractAlt2XmlReader {
1.18
1.19 + /**
1.20 + * <p>
1.21 + * TODO: same format as Java XML properties</p>
1.22 + * <p>
1.23 + * TODO: support also nested mode <code>aaa.bbb.ccc=xxx</code> →
1.24 + * <code><aaa><bbb><ccc>xxx</ccc></bbb></aaa></code></p>
1.25 + */
1.26 @Override
1.27 public void parse(InputSource input) throws IOException, SAXException {
1.28 + Properties loadedData = new Properties();
1.29 + loadedData.load(input.getByteStream());
1.30
1.31 + contentHandler.startDocument();
1.32 + contentHandler.startElement(null, null, "properties", null);
1.33 +
1.34 + for (Entry<Object, Object> e : loadedData.entrySet()) {
1.35 + String key = (String) e.getKey();
1.36 + String value = (String) e.getValue();
1.37 +
1.38 + AttributesImpl attributes = new AttributesImpl();
1.39 + attributes.setAttribute(0, null, "name", "name", "xs:string", key);
1.40 +
1.41 + contentHandler.startElement(null, null, "property", attributes);
1.42 + contentHandler.characters(value.toCharArray(), 0, value.length());
1.43 + contentHandler.endElement(null, null, "property");
1.44 + }
1.45 +
1.46 + contentHandler.endElement(null, null, "properties");
1.47 + contentHandler.endDocument();
1.48 }
1.49 }