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@18
|
18 |
package cz.frantovo.alt2xml.in.properties;
|
franta-hg@2
|
19 |
|
franta-hg@17
|
20 |
import cz.frantovo.alt2xml.AbstractAlt2XmlReader;
|
franta-hg@2
|
21 |
import java.io.IOException;
|
franta-hg@21
|
22 |
import java.util.Map.Entry;
|
franta-hg@21
|
23 |
import java.util.Properties;
|
franta-hg@2
|
24 |
import org.xml.sax.InputSource;
|
franta-hg@2
|
25 |
import org.xml.sax.SAXException;
|
franta-hg@21
|
26 |
import org.xml.sax.helpers.AttributesImpl;
|
franta-hg@2
|
27 |
|
franta-hg@2
|
28 |
/**
|
franta-hg@2
|
29 |
*
|
franta-hg@17
|
30 |
* @author Ing. František Kučera (frantovo.cz)
|
franta-hg@2
|
31 |
*/
|
franta-hg@17
|
32 |
public class Reader extends AbstractAlt2XmlReader {
|
franta-hg@13
|
33 |
|
franta-hg@21
|
34 |
/**
|
franta-hg@21
|
35 |
* <p>
|
franta-hg@21
|
36 |
* TODO: same format as Java XML properties</p>
|
franta-hg@21
|
37 |
* <p>
|
franta-hg@21
|
38 |
* TODO: support also nested mode <code>aaa.bbb.ccc=xxx</code> →
|
franta-hg@21
|
39 |
* <code><aaa><bbb><ccc>xxx</ccc></bbb></aaa></code></p>
|
franta-hg@21
|
40 |
*/
|
franta-hg@2
|
41 |
@Override
|
franta-hg@6
|
42 |
public void parse(InputSource input) throws IOException, SAXException {
|
franta-hg@21
|
43 |
Properties loadedData = new Properties();
|
franta-hg@21
|
44 |
loadedData.load(input.getByteStream());
|
franta-hg@6
|
45 |
|
franta-hg@21
|
46 |
contentHandler.startDocument();
|
franta-hg@21
|
47 |
contentHandler.startElement(null, null, "properties", null);
|
franta-hg@21
|
48 |
|
franta-hg@21
|
49 |
for (Entry<Object, Object> e : loadedData.entrySet()) {
|
franta-hg@21
|
50 |
String key = (String) e.getKey();
|
franta-hg@21
|
51 |
String value = (String) e.getValue();
|
franta-hg@21
|
52 |
|
franta-hg@21
|
53 |
AttributesImpl attributes = new AttributesImpl();
|
franta-hg@21
|
54 |
attributes.setAttribute(0, null, "name", "name", "xs:string", key);
|
franta-hg@21
|
55 |
|
franta-hg@21
|
56 |
contentHandler.startElement(null, null, "property", attributes);
|
franta-hg@21
|
57 |
contentHandler.characters(value.toCharArray(), 0, value.length());
|
franta-hg@21
|
58 |
contentHandler.endElement(null, null, "property");
|
franta-hg@21
|
59 |
}
|
franta-hg@21
|
60 |
|
franta-hg@21
|
61 |
contentHandler.endElement(null, null, "properties");
|
franta-hg@21
|
62 |
contentHandler.endDocument();
|
franta-hg@6
|
63 |
}
|
franta-hg@2
|
64 |
}
|