1.1 --- a/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sat Sep 06 22:04:11 2014 +0200
1.2 +++ b/java/alt2xml-in-ini/src/cz/frantovo/alt2xml/in/ini/Reader.java Sat Sep 06 23:27:18 2014 +0200
1.3 @@ -31,6 +31,7 @@
1.4 import java.util.regex.Pattern;
1.5 import org.xml.sax.InputSource;
1.6 import org.xml.sax.SAXException;
1.7 +import org.xml.sax.helpers.AttributesImpl;
1.8
1.9 /**
1.10 *
1.11 @@ -149,23 +150,30 @@
1.12
1.13 },
1.14 ENTRY(
1.15 - "\\s*(?<key>[^=\\s]+)\\s*=\\s*\"(?<value>[^']+)\"\\s*((;|#)\\s*(?<comment>.*)){0,1}", // quoted value → include spaces + might have comment
1.16 - "\\s*(?<key>[^=\\s]+)\\s*=\\s*'(?<value>[^']+)'\\s*((;|#)\\s*(?<comment>.*)){0,1}", // apostrophed value → include spaces + might have comment
1.17 - "\\s*(?<key>[^=\\s]+)\\s*=\\s*(?<value>.+)" // unquoted value → strip spaces + no comments
1.18 + "\\s*(?<key>[^=\\s\\]]+)(\\[(?<subkey>[^\\]]+)\\]){0,1}\\s*=\\s*\"(?<value>[^']+)\"\\s*((;|#)\\s*(?<comment>.*)){0,1}", // quoted value → include spaces + might have comment
1.19 + "\\s*(?<key>[^=\\s\\]]+)(\\[(?<subkey>[^\\]]+)\\]){0,1}\\s*=\\s*'(?<value>[^']+)'\\s*((;|#)\\s*(?<comment>.*)){0,1}", // apostrophed value → include spaces + might have comment
1.20 + "\\s*(?<key>[^=\\s\\]]+)(\\[(?<subkey>[^\\]]+)\\]){0,1}\\s*=\\s*(?<value>.+)" // unquoted value → strip spaces + no comments
1.21 ) {
1.22 @Override
1.23 public void processLine(LineContext lc, FileContext fc) throws SAXException {
1.24 String key = encodeXmlName(lc.matcher.group("key"), fc.lineNumber);
1.25 String value = lc.matcher.group("value");
1.26
1.27 - if (lc.matcher.groupCount() > 2) {
1.28 + if (lc.matcher.groupCount() > 4) {
1.29 String comment = lc.matcher.group("comment");
1.30 // TODO: comment → LexicalHandler
1.31 log.log(Level.FINER, "Line {0}: comment for entry „{1}“ is: {2}", new Object[]{fc.lineNumber, key, comment});
1.32 }
1.33
1.34 + AttributesImpl attributes = null;
1.35 + String subkey = lc.matcher.group("subkey");
1.36 + if (subkey != null) {
1.37 + attributes = new AttributesImpl();
1.38 + attributes.addAttribute(null, "sub", "sub", "xs:string", subkey);
1.39 + }
1.40 +
1.41 fc.contentHandler.indentation(fc.lastSection == null ? 1 : 2);
1.42 - fc.contentHandler.textElement(value, null, null, key, null);
1.43 + fc.contentHandler.textElement(value, null, null, key, attributes);
1.44 fc.contentHandler.lineBreak();
1.45
1.46 }