ouptup modules framework + XML (echo) output module
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 15 Jun 2014 14:50:49 +0200
changeset 43058c1c39251e
parent 42 f1e91d4ac35c
child 44 7bd195a5fa2a
ouptup modules framework + XML (echo) output module
java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/AbstractAction.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/Action.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/ActionContext.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/ActionFactory.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java
java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/OutputActionException.java
java/alt2xml-out-xml/config/META-INF/services/cz.frantovo.alt2xml.out.ActionFactory
java/alt2xml-out-xml/nbproject/build-impl.xml
java/alt2xml-out-xml/nbproject/genfiles.properties
java/alt2xml-out-xml/nbproject/project.properties
java/alt2xml-out-xml/nbproject/project.xml
java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLAction.java
java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLActionFactory.java
java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLHandler.java
scripts/alt2xml.sh
     1.1 --- a/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java	Sat Jun 14 22:56:51 2014 +0200
     1.2 +++ b/java/alt2xml-cli/src/cz/frantovo/alt2xml/cli/CLI.java	Sun Jun 15 14:50:49 2014 +0200
     1.3 @@ -17,16 +17,19 @@
     1.4   */
     1.5  package cz.frantovo.alt2xml.cli;
     1.6  
     1.7 -import cz.frantovo.alt2xml.out.EchoContentHandler;
     1.8 +import cz.frantovo.alt2xml.out.Action;
     1.9 +import cz.frantovo.alt2xml.out.ActionContext;
    1.10 +import cz.frantovo.alt2xml.out.ActionFactory;
    1.11  import java.io.File;
    1.12  import java.io.OutputStream;
    1.13  import java.util.Arrays;
    1.14 +import java.util.HashMap;
    1.15 +import java.util.Map;
    1.16 +import java.util.ServiceLoader;
    1.17  import java.util.logging.Level;
    1.18  import java.util.logging.Logger;
    1.19  import javax.xml.parsers.SAXParser;
    1.20  import javax.xml.parsers.SAXParserFactory;
    1.21 -import javax.xml.stream.XMLOutputFactory;
    1.22 -import javax.xml.stream.XMLStreamWriter;
    1.23  import org.xml.sax.ext.LexicalHandler;
    1.24  import org.xml.sax.helpers.DefaultHandler;
    1.25  
    1.26 @@ -43,37 +46,48 @@
    1.27  
    1.28  		try {
    1.29  			File vstup = new File(args[0]);
    1.30 -			OutputStream výstup = System.out;
    1.31 +			String actionCode = args[1];
    1.32 +			OutputStream outputStream = System.out;
    1.33  
    1.34 -			/**
    1.35 -			 * Serializujeme data do XML.
    1.36 -			 * To normálně vůbec není potřeba – data se do tvaru proudu obsahujícího ostré závorky
    1.37 -			 * vůbec nedostanou – zpracováváme události (volání javovských metod – začátky a konce
    1.38 -			 * elementů atd.)
    1.39 -			 * a z nich např. deserializujeme nějaké naše objekty, provádíme nějaké akce, nebo třeba
    1.40 -			 * stavíme DOM.
    1.41 -			 */
    1.42 -			XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
    1.43 -			XMLStreamWriter w = xmlOutputFactory.createXMLStreamWriter(výstup);
    1.44 -			DefaultHandler h = new EchoContentHandler(w);
    1.45 +			Map<String, ActionFactory> actionFactories = new HashMap<>();
    1.46  
    1.47 -			SAXParserFactory t = SAXParserFactory.newInstance();
    1.48 -			SAXParser p = t.newSAXParser();
    1.49 -
    1.50 -			if (h instanceof LexicalHandler
    1.51 -					// TODO: add option/feature to disable LexicalHandler registration
    1.52 -					&& false) {
    1.53 -				try {
    1.54 -					p.setProperty(LEXICAL_HANDLER_PROPERTY, h);
    1.55 -				} catch (Exception e) {
    1.56 -					log.log(Level.WARNING, "LexicalHandler registration exception:", e);
    1.57 -					log.log(Level.WARNING,
    1.58 -							"Tried to register the handler {0} as a LexicalHandler but LexicalHandlers are not supported by the parser {1}",
    1.59 -							new Object[]{h, p});
    1.60 -				}
    1.61 +			for (ActionFactory f : ServiceLoader.load(ActionFactory.class)) {
    1.62 +				String code = f.getActionCode();
    1.63 +				actionFactories.put(code, f);
    1.64 +				log.log(Level.CONFIG, "Discovered output module: {0} = {1}", new Object[]{code, f.getClass().getName()});
    1.65  			}
    1.66  
    1.67 -			p.parse(vstup, h);
    1.68 +			ActionFactory actionFactory = actionFactories.get(actionCode);
    1.69 +
    1.70 +			if (actionFactory == null) {
    1.71 +				log.log(Level.SEVERE, "No such output action with code: {0}", actionCode);
    1.72 +			} else {
    1.73 +
    1.74 +				ActionContext actionContext = new ActionContext(outputStream);
    1.75 +				Action action = actionFactory.getAction(actionContext);
    1.76 +
    1.77 +				DefaultHandler defaultHandler = action.getDefaultHandler();
    1.78 +				LexicalHandler lexicalHandler = action.getLexicalHandler();
    1.79 +
    1.80 +				SAXParserFactory t = SAXParserFactory.newInstance();
    1.81 +				SAXParser p = t.newSAXParser();
    1.82 +
    1.83 +				if (lexicalHandler == null) {
    1.84 +					log.log(Level.FINE, "No LexicalHandler provided.");
    1.85 +				} else {
    1.86 +					try {
    1.87 +						p.setProperty(LEXICAL_HANDLER_PROPERTY, defaultHandler);
    1.88 +					} catch (Exception e) {
    1.89 +						log.log(Level.WARNING, "LexicalHandler registration exception:", e);
    1.90 +						log.log(Level.WARNING,
    1.91 +								"Tried to register the handler {0} as a LexicalHandler but LexicalHandlers are not supported by the parser {1}",
    1.92 +								new Object[]{defaultHandler, p});
    1.93 +					}
    1.94 +				}
    1.95 +
    1.96 +				p.parse(vstup, defaultHandler);
    1.97 +			}
    1.98 +
    1.99  		} catch (Exception e) {
   1.100  			log.log(Level.SEVERE, "Error during processing: " + Arrays.toString(args), e);
   1.101  		}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/AbstractAction.java	Sun Jun 15 14:50:49 2014 +0200
     2.3 @@ -0,0 +1,47 @@
     2.4 +/**
     2.5 + * Alt2XML
     2.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package cz.frantovo.alt2xml.out;
    2.22 +
    2.23 +import org.xml.sax.ext.LexicalHandler;
    2.24 +
    2.25 +/**
    2.26 + * Recommended base class for Actions.
    2.27 + *
    2.28 + * @author Ing. František Kučera (frantovo.cz)
    2.29 + */
    2.30 +public abstract class AbstractAction implements Action {
    2.31 +
    2.32 +	private final ActionContext actionContext;
    2.33 +
    2.34 +	public AbstractAction(ActionContext actionContext) {
    2.35 +		this.actionContext = actionContext;
    2.36 +	}
    2.37 +
    2.38 +	protected ActionContext getActionContext() {
    2.39 +		return actionContext;
    2.40 +	}
    2.41 +
    2.42 +	/**
    2.43 +	 * @return null – lexical events are not supported
    2.44 +	 */
    2.45 +	@Override
    2.46 +	public LexicalHandler getLexicalHandler() {
    2.47 +		return null;
    2.48 +	}
    2.49 +
    2.50 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/Action.java	Sun Jun 15 14:50:49 2014 +0200
     3.3 @@ -0,0 +1,39 @@
     3.4 +/**
     3.5 + * Alt2XML
     3.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, either version 3 of the License, or
    3.11 + * (at your option) any later version.
    3.12 + *
    3.13 + * This program is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    3.16 + * GNU General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License
    3.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    3.20 + */
    3.21 +package cz.frantovo.alt2xml.out;
    3.22 +
    3.23 +import org.xml.sax.ext.LexicalHandler;
    3.24 +import org.xml.sax.helpers.DefaultHandler;
    3.25 +
    3.26 +/**
    3.27 + * Executive class of an output module.
    3.28 + *
    3.29 + * @author Ing. František Kučera (frantovo.cz)
    3.30 + */
    3.31 +public interface Action {
    3.32 +
    3.33 +	public DefaultHandler getDefaultHandler();
    3.34 +
    3.35 +	/**
    3.36 +	 * For e.g. comment nodes.
    3.37 +	 *
    3.38 +	 * @return may return null if this output module does not support lexical events
    3.39 +	 */
    3.40 +	public LexicalHandler getLexicalHandler();
    3.41 +
    3.42 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/ActionContext.java	Sun Jun 15 14:50:49 2014 +0200
     4.3 @@ -0,0 +1,39 @@
     4.4 +/**
     4.5 + * Alt2XML
     4.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, either version 3 of the License, or
    4.11 + * (at your option) any later version.
    4.12 + *
    4.13 + * This program is distributed in the hope that it will be useful,
    4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    4.16 + * GNU General Public License for more details.
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License
    4.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    4.20 + */
    4.21 +package cz.frantovo.alt2xml.out;
    4.22 +
    4.23 +import java.io.OutputStream;
    4.24 +
    4.25 +/**
    4.26 + * Context for one action instance.
    4.27 + *
    4.28 + * @author Ing. František Kučera (frantovo.cz)
    4.29 + */
    4.30 +public class ActionContext {
    4.31 +
    4.32 +	private OutputStream outputStream;
    4.33 +
    4.34 +	public ActionContext(OutputStream outputStream) {
    4.35 +		this.outputStream = outputStream;
    4.36 +	}
    4.37 +
    4.38 +	public OutputStream getOutputStream() {
    4.39 +		return outputStream;
    4.40 +	}
    4.41 +
    4.42 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/ActionFactory.java	Sun Jun 15 14:50:49 2014 +0200
     5.3 @@ -0,0 +1,39 @@
     5.4 +/**
     5.5 + * Alt2XML
     5.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     5.7 + *
     5.8 + * This program is free software: you can redistribute it and/or modify
     5.9 + * it under the terms of the GNU General Public License as published by
    5.10 + * the Free Software Foundation, either version 3 of the License, or
    5.11 + * (at your option) any later version.
    5.12 + *
    5.13 + * This program is distributed in the hope that it will be useful,
    5.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    5.16 + * GNU General Public License for more details.
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License
    5.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    5.20 + */
    5.21 +package cz.frantovo.alt2xml.out;
    5.22 +
    5.23 +/**
    5.24 + * Interface of an output module.
    5.25 + * Modules are discovered over META-INF/services.
    5.26 + * Must have non-parametric constructor.
    5.27 + * Should be lightweight – use lazy initialization
    5.28 + * (all factories are instantiated, even if not used).
    5.29 + *
    5.30 + * @author Ing. František Kučera (frantovo.cz)
    5.31 + */
    5.32 +public interface ActionFactory {
    5.33 +
    5.34 +	/**
    5.35 +	 * @return short code/name for this action – is used on command line to say, which action should
    5.36 +	 * be executed.
    5.37 +	 */
    5.38 +	public String getActionCode();
    5.39 +
    5.40 +	public Action getAction(ActionContext context) throws OutputActionException;
    5.41 +
    5.42 +}
     6.1 --- a/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/EchoContentHandler.java	Sat Jun 14 22:56:51 2014 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,148 +0,0 @@
     6.4 -/**
     6.5 - * Alt2XML
     6.6 - * Copyright © 2014 František Kučera (frantovo.cz)
     6.7 - *
     6.8 - * This program is free software: you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License as published by
    6.10 - * the Free Software Foundation, either version 3 of the License, or
    6.11 - * (at your option) any later version.
    6.12 - *
    6.13 - * This program is distributed in the hope that it will be useful,
    6.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    6.16 - * GNU General Public License for more details.
    6.17 - *
    6.18 - * You should have received a copy of the GNU General Public License
    6.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
    6.20 - */
    6.21 -package cz.frantovo.alt2xml.out;
    6.22 -
    6.23 -import java.util.logging.Logger;
    6.24 -import javax.xml.stream.XMLStreamException;
    6.25 -import javax.xml.stream.XMLStreamWriter;
    6.26 -import org.xml.sax.Attributes;
    6.27 -import org.xml.sax.SAXException;
    6.28 -import org.xml.sax.helpers.DefaultHandler;
    6.29 -
    6.30 -/**
    6.31 - * Slouží k převodu právě parsovaného XML zpět na XML.
    6.32 - * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery,
    6.33 - * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX).
    6.34 - *
    6.35 - * TODO: další typy uzlů a jmenné prostory.
    6.36 - *
    6.37 - * @author Ing. František Kučera (frantovo.cz)
    6.38 - */
    6.39 -public class EchoContentHandler extends DefaultHandler {
    6.40 -
    6.41 -	private static final Logger log = Logger.getLogger(EchoContentHandler.class.getName());
    6.42 -	private XMLStreamWriter w;
    6.43 -
    6.44 -	/**
    6.45 -	 * @param writer kam se bude vypisovat XML.
    6.46 -	 */
    6.47 -	public EchoContentHandler(XMLStreamWriter writer) {
    6.48 -		w = writer;
    6.49 -	}
    6.50 -
    6.51 -	@Override
    6.52 -	public void startDocument() throws SAXException {
    6.53 -		try {
    6.54 -			w.writeStartDocument();
    6.55 -		} catch (XMLStreamException e) {
    6.56 -			throw new SAXException(e);
    6.57 -		}
    6.58 -	}
    6.59 -
    6.60 -	@Override
    6.61 -	public void endDocument() throws SAXException {
    6.62 -		try {
    6.63 -			w.writeEndDocument();
    6.64 -			w.close();
    6.65 -		} catch (XMLStreamException e) {
    6.66 -			throw new SAXException(e);
    6.67 -		}
    6.68 -	}
    6.69 -
    6.70 -	@Override
    6.71 -	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    6.72 -		try {
    6.73 -			w.writeStartElement(qName);
    6.74 -
    6.75 -			if (attributes != null) {
    6.76 -				for (int i = 0; i < attributes.getLength(); i++) {
    6.77 -					w.writeAttribute(attributes.getQName(i), attributes.getValue(i));
    6.78 -				}
    6.79 -			}
    6.80 -
    6.81 -			w.flush();
    6.82 -		} catch (XMLStreamException e) {
    6.83 -			throw new SAXException(e);
    6.84 -		}
    6.85 -	}
    6.86 -
    6.87 -	@Override
    6.88 -	public void endElement(String uri, String localName, String qName) throws SAXException {
    6.89 -		try {
    6.90 -			w.writeEndElement();
    6.91 -			w.flush();
    6.92 -		} catch (XMLStreamException e) {
    6.93 -			throw new SAXException(e);
    6.94 -		}
    6.95 -	}
    6.96 -
    6.97 -	@Override
    6.98 -	public void characters(char[] ch, int start, int length) throws SAXException {
    6.99 -		try {
   6.100 -			w.writeCharacters(ch, start, length);
   6.101 -			w.flush();
   6.102 -		} catch (XMLStreamException e) {
   6.103 -			throw new SAXException(e);
   6.104 -		}
   6.105 -	}
   6.106 -
   6.107 -	/**
   6.108 -	 * LexicalHandler methods
   6.109 -	 *
   6.110 -	 * @Override
   6.111 -	 * public void startDTD(String name, String publicId, String systemId) throws SAXException {
   6.112 -	 * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
   6.113 -	 * systemId});
   6.114 -	 * }
   6.115 -	 *
   6.116 -	 * @Override
   6.117 -	 * public void endDTD() throws SAXException {
   6.118 -	 * log.log(Level.WARNING, "End of DTD");
   6.119 -	 * }
   6.120 -	 *
   6.121 -	 * @Override
   6.122 -	 * public void startEntity(String name) throws SAXException {
   6.123 -	 * log.log(Level.WARNING, "Start of Entity: {0}", name);
   6.124 -	 * }
   6.125 -	 *
   6.126 -	 * @Override
   6.127 -	 * public void endEntity(String name) throws SAXException {
   6.128 -	 * log.log(Level.WARNING, "End of Entity: {0}", name);
   6.129 -	 * }
   6.130 -	 *
   6.131 -	 * @Override
   6.132 -	 * public void startCDATA() throws SAXException {
   6.133 -	 * log.log(Level.WARNING, "Start of CDATA");
   6.134 -	 * }
   6.135 -	 *
   6.136 -	 * @Override
   6.137 -	 * public void endCDATA() throws SAXException {
   6.138 -	 * log.log(Level.WARNING, "End of CDATA");
   6.139 -	 * }
   6.140 -	 *
   6.141 -	 * @Override
   6.142 -	 * public void comment(char[] ch, int start, int length) throws SAXException {
   6.143 -	 * try {
   6.144 -	 * w.writeComment(new String(ch, start, length));
   6.145 -	 * w.flush();
   6.146 -	 * } catch (XMLStreamException e) {
   6.147 -	 * throw new SAXException(e);
   6.148 -	 * }
   6.149 -	 * }
   6.150 -	 */
   6.151 -}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/java/alt2xml-lib-output/src/cz/frantovo/alt2xml/out/OutputActionException.java	Sun Jun 15 14:50:49 2014 +0200
     7.3 @@ -0,0 +1,41 @@
     7.4 +/**
     7.5 + * Alt2XML
     7.6 + * Copyright © 2014 František Kučera (frantovo.cz)
     7.7 + *
     7.8 + * This program is free software: you can redistribute it and/or modify
     7.9 + * it under the terms of the GNU General Public License as published by
    7.10 + * the Free Software Foundation, either version 3 of the License, or
    7.11 + * (at your option) any later version.
    7.12 + *
    7.13 + * This program is distributed in the hope that it will be useful,
    7.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    7.16 + * GNU General Public License for more details.
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License
    7.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    7.20 + */
    7.21 +package cz.frantovo.alt2xml.out;
    7.22 +
    7.23 +/**
    7.24 + *
    7.25 + * @author Ing. František Kučera (frantovo.cz)
    7.26 + */
    7.27 +public class OutputActionException extends Exception {
    7.28 +
    7.29 +	public OutputActionException() {
    7.30 +	}
    7.31 +
    7.32 +	public OutputActionException(String message) {
    7.33 +		super(message);
    7.34 +	}
    7.35 +
    7.36 +	public OutputActionException(Throwable cause) {
    7.37 +		super(cause);
    7.38 +	}
    7.39 +
    7.40 +	public OutputActionException(String message, Throwable cause) {
    7.41 +		super(message, cause);
    7.42 +	}
    7.43 +
    7.44 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/java/alt2xml-out-xml/config/META-INF/services/cz.frantovo.alt2xml.out.ActionFactory	Sun Jun 15 14:50:49 2014 +0200
     8.3 @@ -0,0 +1,1 @@
     8.4 +cz.frantovo.alt2xml.out.xml.XMLActionFactory
     8.5 \ No newline at end of file
     9.1 --- a/java/alt2xml-out-xml/nbproject/build-impl.xml	Sat Jun 14 22:56:51 2014 +0200
     9.2 +++ b/java/alt2xml-out-xml/nbproject/build-impl.xml	Sun Jun 15 14:50:49 2014 +0200
     9.3 @@ -127,6 +127,7 @@
     9.4          </condition>
     9.5          <condition property="have.sources">
     9.6              <or>
     9.7 +                <available file="${src.config.dir}"/>
     9.8                  <available file="${src.dir}"/>
     9.9              </or>
    9.10          </condition>
    9.11 @@ -223,6 +224,7 @@
    9.12          <!-- You can override this target in the ../build.xml file. -->
    9.13      </target>
    9.14      <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
    9.15 +        <fail unless="src.config.dir">Must set src.config.dir</fail>
    9.16          <fail unless="src.dir">Must set src.dir</fail>
    9.17          <fail unless="test.src.dir">Must set test.src.dir</fail>
    9.18          <fail unless="build.dir">Must set build.dir</fail>
    9.19 @@ -245,7 +247,7 @@
    9.20      </target>
    9.21      <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
    9.22          <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
    9.23 -            <attribute default="${src.dir}" name="srcdir"/>
    9.24 +            <attribute default="${src.config.dir}:${src.dir}" name="srcdir"/>
    9.25              <attribute default="${build.classes.dir}" name="destdir"/>
    9.26              <attribute default="${javac.classpath}" name="classpath"/>
    9.27              <attribute default="${javac.processorpath}" name="processorpath"/>
    9.28 @@ -286,7 +288,7 @@
    9.29      </target>
    9.30      <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
    9.31          <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
    9.32 -            <attribute default="${src.dir}" name="srcdir"/>
    9.33 +            <attribute default="${src.config.dir}:${src.dir}" name="srcdir"/>
    9.34              <attribute default="${build.classes.dir}" name="destdir"/>
    9.35              <attribute default="${javac.classpath}" name="classpath"/>
    9.36              <attribute default="${javac.processorpath}" name="processorpath"/>
    9.37 @@ -319,7 +321,7 @@
    9.38      </target>
    9.39      <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
    9.40          <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
    9.41 -            <attribute default="${src.dir}" name="srcdir"/>
    9.42 +            <attribute default="${src.config.dir}:${src.dir}" name="srcdir"/>
    9.43              <attribute default="${build.classes.dir}" name="destdir"/>
    9.44              <attribute default="${javac.classpath}" name="classpath"/>
    9.45              <sequential>
    9.46 @@ -925,11 +927,12 @@
    9.47                  <include name="*"/>
    9.48              </dirset>
    9.49          </pathconvert>
    9.50 -        <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
    9.51 +        <j2seproject3:depend srcdir="${src.config.dir}:${src.dir}:${build.generated.subdirs}"/>
    9.52      </target>
    9.53      <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
    9.54          <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
    9.55          <copy todir="${build.classes.dir}">
    9.56 +            <fileset dir="${src.config.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    9.57              <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
    9.58          </copy>
    9.59      </target>
    9.60 @@ -951,7 +954,7 @@
    9.61      <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
    9.62          <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
    9.63          <j2seproject3:force-recompile/>
    9.64 -        <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
    9.65 +        <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.config.dir}:${src.dir}"/>
    9.66      </target>
    9.67      <target name="-post-compile-single">
    9.68          <!-- Empty placeholder for easier customization. -->
    9.69 @@ -1217,6 +1220,9 @@
    9.70              <classpath>
    9.71                  <path path="${javac.classpath}"/>
    9.72              </classpath>
    9.73 +            <fileset dir="${src.config.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
    9.74 +                <filename name="**/*.java"/>
    9.75 +            </fileset>
    9.76              <fileset dir="${src.dir}" excludes="${bug5101868workaround},${excludes}" includes="${includes}">
    9.77                  <filename name="**/*.java"/>
    9.78              </fileset>
    9.79 @@ -1227,6 +1233,9 @@
    9.80              <arg line="${javadoc.endorsed.classpath.cmd.line.arg}"/>
    9.81          </javadoc>
    9.82          <copy todir="${dist.javadoc.dir}">
    9.83 +            <fileset dir="${src.config.dir}" excludes="${excludes}" includes="${includes}">
    9.84 +                <filename name="**/doc-files/**"/>
    9.85 +            </fileset>
    9.86              <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
    9.87                  <filename name="**/doc-files/**"/>
    9.88              </fileset>
    10.1 --- a/java/alt2xml-out-xml/nbproject/genfiles.properties	Sat Jun 14 22:56:51 2014 +0200
    10.2 +++ b/java/alt2xml-out-xml/nbproject/genfiles.properties	Sun Jun 15 14:50:49 2014 +0200
    10.3 @@ -1,8 +1,8 @@
    10.4 -build.xml.data.CRC32=8bcc59de
    10.5 +build.xml.data.CRC32=8237fb99
    10.6  build.xml.script.CRC32=c7a10d41
    10.7  build.xml.stylesheet.CRC32=8064a381@1.74.2.48
    10.8  # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
    10.9  # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
   10.10 -nbproject/build-impl.xml.data.CRC32=8bcc59de
   10.11 -nbproject/build-impl.xml.script.CRC32=40cffe34
   10.12 +nbproject/build-impl.xml.data.CRC32=8237fb99
   10.13 +nbproject/build-impl.xml.script.CRC32=88681dba
   10.14  nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48
    11.1 --- a/java/alt2xml-out-xml/nbproject/project.properties	Sat Jun 14 22:56:51 2014 +0200
    11.2 +++ b/java/alt2xml-out-xml/nbproject/project.properties	Sun Jun 15 14:50:49 2014 +0200
    11.3 @@ -1,9 +1,10 @@
    11.4  annotation.processing.enabled=true
    11.5  annotation.processing.enabled.in.editor=false
    11.6 -annotation.processing.processor.options=
    11.7  annotation.processing.processors.list=
    11.8  annotation.processing.run.all.processors=true
    11.9  annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
   11.10 +application.title=alt2xml-out-xml
   11.11 +application.vendor=fiki
   11.12  build.classes.dir=${build.dir}/classes
   11.13  build.classes.excludes=**/*.java,**/*.form
   11.14  # This directory is removed when the project is cleaned:
   11.15 @@ -26,6 +27,7 @@
   11.16  dist.dir=dist
   11.17  dist.jar=${dist.dir}/alt2xml-out-xml.jar
   11.18  dist.javadoc.dir=${dist.dir}/javadoc
   11.19 +endorsed.classpath=
   11.20  excludes=
   11.21  includes=**
   11.22  jar.compress=false
   11.23 @@ -70,5 +72,6 @@
   11.24      ${javac.test.classpath}:\
   11.25      ${build.test.classes.dir}
   11.26  source.encoding=UTF-8
   11.27 +src.config.dir=config
   11.28  src.dir=src
   11.29  test.src.dir=test
    12.1 --- a/java/alt2xml-out-xml/nbproject/project.xml	Sat Jun 14 22:56:51 2014 +0200
    12.2 +++ b/java/alt2xml-out-xml/nbproject/project.xml	Sun Jun 15 14:50:49 2014 +0200
    12.3 @@ -5,6 +5,7 @@
    12.4          <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
    12.5              <name>alt2xml-out-xml</name>
    12.6              <source-roots>
    12.7 +                <root id="src.config.dir" name="Config"/>
    12.8                  <root id="src.dir"/>
    12.9              </source-roots>
   12.10              <test-roots>
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLAction.java	Sun Jun 15 14:50:49 2014 +0200
    13.3 @@ -0,0 +1,42 @@
    13.4 +/**
    13.5 + * Alt2XML
    13.6 + * Copyright © 2014 František Kučera (frantovo.cz)
    13.7 + *
    13.8 + * This program is free software: you can redistribute it and/or modify
    13.9 + * it under the terms of the GNU General Public License as published by
   13.10 + * the Free Software Foundation, either version 3 of the License, or
   13.11 + * (at your option) any later version.
   13.12 + *
   13.13 + * This program is distributed in the hope that it will be useful,
   13.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   13.16 + * GNU General Public License for more details.
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License
   13.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
   13.20 + */
   13.21 +package cz.frantovo.alt2xml.out.xml;
   13.22 +
   13.23 +import cz.frantovo.alt2xml.out.AbstractAction;
   13.24 +import cz.frantovo.alt2xml.out.ActionContext;
   13.25 +import javax.xml.stream.XMLStreamWriter;
   13.26 +import org.xml.sax.helpers.DefaultHandler;
   13.27 +
   13.28 +/**
   13.29 + *
   13.30 + * @author Ing. František Kučera (frantovo.cz)
   13.31 + */
   13.32 +public class XMLAction extends AbstractAction {
   13.33 +
   13.34 +	private final XMLHandler handler;
   13.35 +
   13.36 +	public XMLAction(ActionContext actionContext, XMLStreamWriter writer) {
   13.37 +		super(actionContext);
   13.38 +		handler = new XMLHandler(writer);
   13.39 +	}
   13.40 +
   13.41 +	@Override
   13.42 +	public DefaultHandler getDefaultHandler() {
   13.43 +		return handler;
   13.44 +	}
   13.45 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLActionFactory.java	Sun Jun 15 14:50:49 2014 +0200
    14.3 @@ -0,0 +1,59 @@
    14.4 +/**
    14.5 + * Alt2XML
    14.6 + * Copyright © 2014 František Kučera (frantovo.cz)
    14.7 + *
    14.8 + * This program is free software: you can redistribute it and/or modify
    14.9 + * it under the terms of the GNU General Public License as published by
   14.10 + * the Free Software Foundation, either version 3 of the License, or
   14.11 + * (at your option) any later version.
   14.12 + *
   14.13 + * This program is distributed in the hope that it will be useful,
   14.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   14.16 + * GNU General Public License for more details.
   14.17 + *
   14.18 + * You should have received a copy of the GNU General Public License
   14.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
   14.20 + */
   14.21 +package cz.frantovo.alt2xml.out.xml;
   14.22 +
   14.23 +import cz.frantovo.alt2xml.out.Action;
   14.24 +import cz.frantovo.alt2xml.out.ActionContext;
   14.25 +import cz.frantovo.alt2xml.out.ActionFactory;
   14.26 +import cz.frantovo.alt2xml.out.OutputActionException;
   14.27 +import javax.xml.stream.XMLOutputFactory;
   14.28 +import javax.xml.stream.XMLStreamException;
   14.29 +import javax.xml.stream.XMLStreamWriter;
   14.30 +
   14.31 +/**
   14.32 + * Prints XML.
   14.33 + *
   14.34 + * @author Ing. František Kučera (frantovo.cz)
   14.35 + */
   14.36 +public class XMLActionFactory implements ActionFactory {
   14.37 +
   14.38 +	private XMLOutputFactory xmlOutputFactory;
   14.39 +
   14.40 +	@Override
   14.41 +	public String getActionCode() {
   14.42 +		return "xml";
   14.43 +	}
   14.44 +
   14.45 +	@Override
   14.46 +	public Action getAction(ActionContext context) throws OutputActionException {
   14.47 +		try {
   14.48 +			XMLStreamWriter writer = getXmlOutputFactory().createXMLStreamWriter(context.getOutputStream());
   14.49 +			return new XMLAction(context, writer);
   14.50 +		} catch (XMLStreamException e) {
   14.51 +			throw new OutputActionException("Unable to create XMLStreamWriter", e);
   14.52 +		}
   14.53 +	}
   14.54 +
   14.55 +	private XMLOutputFactory getXmlOutputFactory() {
   14.56 +		if (xmlOutputFactory == null) {
   14.57 +			xmlOutputFactory = XMLOutputFactory.newFactory();
   14.58 +		}
   14.59 +		return xmlOutputFactory;
   14.60 +	}
   14.61 +
   14.62 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/java/alt2xml-out-xml/src/cz/frantovo/alt2xml/out/xml/XMLHandler.java	Sun Jun 15 14:50:49 2014 +0200
    15.3 @@ -0,0 +1,145 @@
    15.4 +/**
    15.5 + * Alt2XML
    15.6 + * Copyright © 2014 František Kučera (frantovo.cz)
    15.7 + *
    15.8 + * This program is free software: you can redistribute it and/or modify
    15.9 + * it under the terms of the GNU General Public License as published by
   15.10 + * the Free Software Foundation, either version 3 of the License, or
   15.11 + * (at your option) any later version.
   15.12 + *
   15.13 + * This program is distributed in the hope that it will be useful,
   15.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   15.16 + * GNU General Public License for more details.
   15.17 + *
   15.18 + * You should have received a copy of the GNU General Public License
   15.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
   15.20 + */
   15.21 +package cz.frantovo.alt2xml.out.xml;
   15.22 +
   15.23 +import java.util.logging.Logger;
   15.24 +import javax.xml.stream.XMLStreamException;
   15.25 +import javax.xml.stream.XMLStreamWriter;
   15.26 +import org.xml.sax.Attributes;
   15.27 +import org.xml.sax.SAXException;
   15.28 +import org.xml.sax.helpers.DefaultHandler;
   15.29 +
   15.30 +/**
   15.31 + * Slouží k převodu právě parsovaného XML zpět na XML.
   15.32 + * Určen pro testování a ladění a pro použití s neobvyklými „XML“ parsery,
   15.33 + * které nečtou XML ale jiný jazyk (např. JSON, INI atd.), ale používají stejné rozhraní (SAX).
   15.34 + *
   15.35 + * TODO: další typy uzlů a jmenné prostory.
   15.36 + *
   15.37 + * @author Ing. František Kučera (frantovo.cz)
   15.38 + */
   15.39 +public class XMLHandler extends DefaultHandler {
   15.40 +
   15.41 +	private static final Logger log = Logger.getLogger(XMLHandler.class.getName());
   15.42 +	private XMLStreamWriter w;
   15.43 +
   15.44 +	public XMLHandler(XMLStreamWriter writer) {
   15.45 +		w = writer;
   15.46 +	}
   15.47 +
   15.48 +	@Override
   15.49 +	public void startDocument() throws SAXException {
   15.50 +		try {
   15.51 +			w.writeStartDocument();
   15.52 +		} catch (XMLStreamException e) {
   15.53 +			throw new SAXException(e);
   15.54 +		}
   15.55 +	}
   15.56 +
   15.57 +	@Override
   15.58 +	public void endDocument() throws SAXException {
   15.59 +		try {
   15.60 +			w.writeEndDocument();
   15.61 +			w.close();
   15.62 +		} catch (XMLStreamException e) {
   15.63 +			throw new SAXException(e);
   15.64 +		}
   15.65 +	}
   15.66 +
   15.67 +	@Override
   15.68 +	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
   15.69 +		try {
   15.70 +			w.writeStartElement(qName);
   15.71 +
   15.72 +			if (attributes != null) {
   15.73 +				for (int i = 0; i < attributes.getLength(); i++) {
   15.74 +					w.writeAttribute(attributes.getQName(i), attributes.getValue(i));
   15.75 +				}
   15.76 +			}
   15.77 +
   15.78 +			w.flush();
   15.79 +		} catch (XMLStreamException e) {
   15.80 +			throw new SAXException(e);
   15.81 +		}
   15.82 +	}
   15.83 +
   15.84 +	@Override
   15.85 +	public void endElement(String uri, String localName, String qName) throws SAXException {
   15.86 +		try {
   15.87 +			w.writeEndElement();
   15.88 +			w.flush();
   15.89 +		} catch (XMLStreamException e) {
   15.90 +			throw new SAXException(e);
   15.91 +		}
   15.92 +	}
   15.93 +
   15.94 +	@Override
   15.95 +	public void characters(char[] ch, int start, int length) throws SAXException {
   15.96 +		try {
   15.97 +			w.writeCharacters(ch, start, length);
   15.98 +			w.flush();
   15.99 +		} catch (XMLStreamException e) {
  15.100 +			throw new SAXException(e);
  15.101 +		}
  15.102 +	}
  15.103 +
  15.104 +	/**
  15.105 +	 * LexicalHandler methods
  15.106 +	 *
  15.107 +	 * @Override
  15.108 +	 * public void startDTD(String name, String publicId, String systemId) throws SAXException {
  15.109 +	 * log.log(Level.WARNING, "Start of DTD: {0} | {1} | {2}", new Object[]{name, publicId,
  15.110 +	 * systemId});
  15.111 +	 * }
  15.112 +	 *
  15.113 +	 * @Override
  15.114 +	 * public void endDTD() throws SAXException {
  15.115 +	 * log.log(Level.WARNING, "End of DTD");
  15.116 +	 * }
  15.117 +	 *
  15.118 +	 * @Override
  15.119 +	 * public void startEntity(String name) throws SAXException {
  15.120 +	 * log.log(Level.WARNING, "Start of Entity: {0}", name);
  15.121 +	 * }
  15.122 +	 *
  15.123 +	 * @Override
  15.124 +	 * public void endEntity(String name) throws SAXException {
  15.125 +	 * log.log(Level.WARNING, "End of Entity: {0}", name);
  15.126 +	 * }
  15.127 +	 *
  15.128 +	 * @Override
  15.129 +	 * public void startCDATA() throws SAXException {
  15.130 +	 * log.log(Level.WARNING, "Start of CDATA");
  15.131 +	 * }
  15.132 +	 *
  15.133 +	 * @Override
  15.134 +	 * public void endCDATA() throws SAXException {
  15.135 +	 * log.log(Level.WARNING, "End of CDATA");
  15.136 +	 * }
  15.137 +	 *
  15.138 +	 * @Override
  15.139 +	 * public void comment(char[] ch, int start, int length) throws SAXException {
  15.140 +	 * try {
  15.141 +	 * w.writeComment(new String(ch, start, length));
  15.142 +	 * w.flush();
  15.143 +	 * } catch (XMLStreamException e) {
  15.144 +	 * throw new SAXException(e);
  15.145 +	 * }
  15.146 +	 * }
  15.147 +	 */
  15.148 +}
    16.1 --- a/scripts/alt2xml.sh	Sat Jun 14 22:56:51 2014 +0200
    16.2 +++ b/scripts/alt2xml.sh	Sun Jun 15 14:50:49 2014 +0200
    16.3 @@ -8,14 +8,18 @@
    16.4  	"$DIR/java/alt2xml-lib-output/dist/alt2xml-lib-output.jar"
    16.5  );
    16.6  
    16.7 -PLUGINS=(
    16.8 +INPUT_PLUGINS=(
    16.9  	"$DIR/java/alt2xml-in-properties/dist/alt2xml-in-properties.jar"
   16.10  	
   16.11  	"$DIR/java/alt2xml-in-json/dist/alt2xml-in-json.jar"
   16.12  	"$DIR/../temp/lib/json_simple-1.1.jar"
   16.13  );
   16.14  
   16.15 -for e in "${STANDARD_JARS[@]}" "${PLUGINS[@]}"; do
   16.16 +OUTPUT_PLUGINS=(
   16.17 +	"$DIR/java/alt2xml-out-xml/dist/alt2xml-out-xml.jar"
   16.18 +);
   16.19 +
   16.20 +for e in "${STANDARD_JARS[@]}" "${INPUT_PLUGINS[@]}" "${OUTPUT_PLUGINS[@]}"; do
   16.21  	CLASS_PATH="$CLASS_PATH:$e";
   16.22  done
   16.23