1.1 --- a/analýza/alt2xml.txt Sun Jun 08 11:24:03 2014 +0200
1.2 +++ b/analýza/alt2xml.txt Sun Jun 08 15:00:19 2014 +0200
1.3 @@ -27,6 +27,13 @@
1.4
1.5 Možnost zakódovat properties XMLReaderu a skutečné SystemId do URI SystemId.
1.6
1.7 +Komentáře přes LexicalHandler
1.8 + To set the LexicalHandler for an XML reader, use the setProperty method
1.9 + with the property name http://xml.org/sax/properties/lexical-handler
1.10 + and an object implementing this interface (or null) as the value.
1.11 + If the reader does not report lexical events, it will throw
1.12 + a SAXNotRecognizedException when you attempt to register the handler.
1.13 +
1.14 Vstupní formáty:
1.15 RegExp:
1.16 hledá v textu shodu s výrazem (typicky bude končit koncem řádku) a vrací skupiny z výrazu jako elementy
1.17 @@ -56,6 +63,7 @@
1.18 adresářová struktura
1.19 atributy souborů (včetně rozšířených)
1.20 volitelně obsah souborů
1.21 + volitelně počítat hashe
1.22 zpracovat celý podstrom nebo volitelně jen soubory/adresáře vyhovující regulárnímu výrazu
1.23 vhodné pro konfiguraci programů
1.24 Jednoduché XML
1.25 @@ -87,8 +95,8 @@
1.26
1.27 --action <pluginName>
1.28
1.29 - --action-property <key> <value>
1.30 - --action-properties <array> (last option, opaque data follows)
1.31 + --action-property <key> <value> (recommended way of parametrization, self-documenting)
1.32 + -- <array> (last option/separator, followed by opaque data for output module)
1.33
1.34
1.35 Self-documenting:
2.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 11:24:03 2014 +0200
2.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 15:00:19 2014 +0200
2.3 @@ -26,6 +26,7 @@
2.4 import javax.xml.parsers.SAXParserFactory;
2.5 import javax.xml.stream.XMLOutputFactory;
2.6 import javax.xml.stream.XMLStreamWriter;
2.7 +import org.xml.sax.ext.LexicalHandler;
2.8 import org.xml.sax.helpers.DefaultHandler;
2.9
2.10 /**
2.11 @@ -34,6 +35,7 @@
2.12 */
2.13 public class CLI {
2.14
2.15 + public static final String LEXICAL_HANDLER_PROPERTY = "http://xml.org/sax/properties/lexical-handler";
2.16 private static final Logger log = Logger.getLogger(CLI.class.getName());
2.17
2.18 public static void main(String[] args) {
2.19 @@ -56,6 +58,20 @@
2.20
2.21 SAXParserFactory t = SAXParserFactory.newInstance();
2.22 SAXParser p = t.newSAXParser();
2.23 +
2.24 + if (h instanceof LexicalHandler
2.25 + // TODO: add option/feature to disable LexicalHandler registration
2.26 + && false) {
2.27 + try {
2.28 + p.setProperty(LEXICAL_HANDLER_PROPERTY, h);
2.29 + } catch (Exception e) {
2.30 + log.log(Level.WARNING, "LexicalHandler registration exception:", e);
2.31 + log.log(Level.WARNING,
2.32 + "Tried to register the handler {0} as a LexicalHandler but LexicalHandlers are not supported by the parser {1}",
2.33 + new Object[]{h, p});
2.34 + }
2.35 + }
2.36 +
2.37 p.parse(vstup, h);
2.38 } catch (Exception e) {
2.39 log.log(Level.SEVERE, "Error during processing: " + Arrays.toString(args), e);
3.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sun Jun 08 11:24:03 2014 +0200
3.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sun Jun 08 15:00:19 2014 +0200
3.3 @@ -17,6 +17,7 @@
3.4 */
3.5 package cz.frantovo.alt2xml.cli;
3.6
3.7 +import java.util.logging.Logger;
3.8 import javax.xml.stream.XMLStreamException;
3.9 import javax.xml.stream.XMLStreamWriter;
3.10 import org.xml.sax.Attributes;
3.11 @@ -34,6 +35,7 @@
3.12 */
3.13 public class EchoContentHandler extends DefaultHandler {
3.14
3.15 + private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName());
3.16 private XMLStreamWriter w;
3.17
3.18 /**
3.19 @@ -98,4 +100,49 @@
3.20 throw new SAXException(e);
3.21 }
3.22 }
3.23 +
3.24 + /**
3.25 + * LexicalHandler methods
3.26 + *
3.27 + * @Override
3.28 + * public void startDTD(String name, String publicId, String systemId) throws SAXException {
3.29 + * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
3.30 + * systemId});
3.31 + * }
3.32 + *
3.33 + * @Override
3.34 + * public void endDTD() throws SAXException {
3.35 + * log.log(Level.WARNING, "End of DTD");
3.36 + * }
3.37 + *
3.38 + * @Override
3.39 + * public void startEntity(String name) throws SAXException {
3.40 + * log.log(Level.WARNING, "Start of Entity: {0}", name);
3.41 + * }
3.42 + *
3.43 + * @Override
3.44 + * public void endEntity(String name) throws SAXException {
3.45 + * log.log(Level.WARNING, "End of Entity: {0}", name);
3.46 + * }
3.47 + *
3.48 + * @Override
3.49 + * public void startCDATA() throws SAXException {
3.50 + * log.log(Level.WARNING, "Start of CDATA");
3.51 + * }
3.52 + *
3.53 + * @Override
3.54 + * public void endCDATA() throws SAXException {
3.55 + * log.log(Level.WARNING, "End of CDATA");
3.56 + * }
3.57 + *
3.58 + * @Override
3.59 + * public void comment(char[] ch, int start, int length) throws SAXException {
3.60 + * try {
3.61 + * w.writeComment(new String(ch, start, length));
3.62 + * w.flush();
3.63 + * } catch (XMLStreamException e) {
3.64 + * throw new SAXException(e);
3.65 + * }
3.66 + * }
3.67 + */
3.68 }
4.1 --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java Sun Jun 08 11:24:03 2014 +0200
4.2 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java Sun Jun 08 15:00:19 2014 +0200
4.3 @@ -118,7 +118,7 @@
4.4 @Override
4.5 public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
4.6 /**
4.7 - * TODO: feature for disabling default SAXParserFactory
4.8 + * TODO: feature for disabling default/fallback SAXParserFactory
4.9 */
4.10 throw new SAXNotSupportedException("Zatím není podporováno.");
4.11 }