# HG changeset patch # User František Kučera # Date 1402232419 -7200 # Node ID a5020340362b5445a6df40e9e090140dd86e73a6 # Parent 3de77c1ac95e30040b359e3e6b8644aab8f2b38b LexicalHandler (for comments etc.); currnetly not supported diff -r 3de77c1ac95e -r a5020340362b analýza/alt2xml.txt --- a/analýza/alt2xml.txt Sun Jun 08 11:24:03 2014 +0200 +++ b/analýza/alt2xml.txt Sun Jun 08 15:00:19 2014 +0200 @@ -27,6 +27,13 @@ Možnost zakódovat properties XMLReaderu a skutečné SystemId do URI SystemId. +Komentáře přes LexicalHandler + To set the LexicalHandler for an XML reader, use the setProperty method + with the property name http://xml.org/sax/properties/lexical-handler + and an object implementing this interface (or null) as the value. + If the reader does not report lexical events, it will throw + a SAXNotRecognizedException when you attempt to register the handler. + Vstupní formáty: RegExp: hledá v textu shodu s výrazem (typicky bude končit koncem řádku) a vrací skupiny z výrazu jako elementy @@ -56,6 +63,7 @@ adresářová struktura atributy souborů (včetně rozšířených) volitelně obsah souborů + volitelně počítat hashe zpracovat celý podstrom nebo volitelně jen soubory/adresáře vyhovující regulárnímu výrazu vhodné pro konfiguraci programů Jednoduché XML @@ -87,8 +95,8 @@ --action - --action-property - --action-properties (last option, opaque data follows) + --action-property (recommended way of parametrization, self-documenting) + -- (last option/separator, followed by opaque data for output module) Self-documenting: diff -r 3de77c1ac95e -r a5020340362b java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 11:24:03 2014 +0200 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java Sun Jun 08 15:00:19 2014 +0200 @@ -26,6 +26,7 @@ import javax.xml.parsers.SAXParserFactory; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; +import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.DefaultHandler; /** @@ -34,6 +35,7 @@ */ public class CLI { + public static final String LEXICAL_HANDLER_PROPERTY = "http://xml.org/sax/properties/lexical-handler"; private static final Logger log = Logger.getLogger(CLI.class.getName()); public static void main(String[] args) { @@ -56,6 +58,20 @@ SAXParserFactory t = SAXParserFactory.newInstance(); SAXParser p = t.newSAXParser(); + + if (h instanceof LexicalHandler + // TODO: add option/feature to disable LexicalHandler registration + && false) { + try { + p.setProperty(LEXICAL_HANDLER_PROPERTY, h); + } catch (Exception e) { + log.log(Level.WARNING, "LexicalHandler registration exception:", e); + log.log(Level.WARNING, + "Tried to register the handler {0} as a LexicalHandler but LexicalHandlers are not supported by the parser {1}", + new Object[]{h, p}); + } + } + p.parse(vstup, h); } catch (Exception e) { log.log(Level.SEVERE, "Error during processing: " + Arrays.toString(args), e); diff -r 3de77c1ac95e -r a5020340362b java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sun Jun 08 11:24:03 2014 +0200 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/EchoContentHandler.java Sun Jun 08 15:00:19 2014 +0200 @@ -17,6 +17,7 @@ */ package cz.frantovo.alt2xml.cli; +import java.util.logging.Logger; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import org.xml.sax.Attributes; @@ -34,6 +35,7 @@ */ public class EchoContentHandler extends DefaultHandler { + private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName()); private XMLStreamWriter w; /** @@ -98,4 +100,49 @@ throw new SAXException(e); } } + + /** + * LexicalHandler methods + * + * @Override + * public void startDTD(String name, String publicId, String systemId) throws SAXException { + * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId, + * systemId}); + * } + * + * @Override + * public void endDTD() throws SAXException { + * log.log(Level.WARNING, "End of DTD"); + * } + * + * @Override + * public void startEntity(String name) throws SAXException { + * log.log(Level.WARNING, "Start of Entity: {0}", name); + * } + * + * @Override + * public void endEntity(String name) throws SAXException { + * log.log(Level.WARNING, "End of Entity: {0}", name); + * } + * + * @Override + * public void startCDATA() throws SAXException { + * log.log(Level.WARNING, "Start of CDATA"); + * } + * + * @Override + * public void endCDATA() throws SAXException { + * log.log(Level.WARNING, "End of CDATA"); + * } + * + * @Override + * public void comment(char[] ch, int start, int length) throws SAXException { + * try { + * w.writeComment(new String(ch, start, length)); + * w.flush(); + * } catch (XMLStreamException e) { + * throw new SAXException(e); + * } + * } + */ } diff -r 3de77c1ac95e -r a5020340362b java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java --- a/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java Sun Jun 08 11:24:03 2014 +0200 +++ b/java/alt2xml-lib-input/src/cz/frantovo/alt2xml/ParserFactory.java Sun Jun 08 15:00:19 2014 +0200 @@ -118,7 +118,7 @@ @Override public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { /** - * TODO: feature for disabling default SAXParserFactory + * TODO: feature for disabling default/fallback SAXParserFactory */ throw new SAXNotSupportedException("Zatím není podporováno."); }