author | František Kučera <franta-hg@frantovo.cz> |
Thu, 24 Oct 2019 21:56:03 +0200 | |
changeset 111 | e4900596abdb |
parent 43 | 058c1c39251e |
permissions | -rw-r--r-- |
franta-hg@43 | 1 |
/** |
franta-hg@43 | 2 |
* Alt2XML |
franta-hg@43 | 3 |
* Copyright © 2014 František Kučera (frantovo.cz) |
franta-hg@43 | 4 |
* |
franta-hg@43 | 5 |
* This program is free software: you can redistribute it and/or modify |
franta-hg@43 | 6 |
* it under the terms of the GNU General Public License as published by |
franta-hg@111 | 7 |
* the Free Software Foundation, version 3 of the License. |
franta-hg@43 | 8 |
* |
franta-hg@43 | 9 |
* This program is distributed in the hope that it will be useful, |
franta-hg@43 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
franta-hg@43 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
franta-hg@43 | 12 |
* GNU General Public License for more details. |
franta-hg@43 | 13 |
* |
franta-hg@43 | 14 |
* You should have received a copy of the GNU General Public License |
franta-hg@43 | 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
franta-hg@43 | 16 |
*/ |
franta-hg@43 | 17 |
package cz.frantovo.alt2xml.out.xml; |
franta-hg@43 | 18 |
|
franta-hg@43 | 19 |
import cz.frantovo.alt2xml.out.Action; |
franta-hg@43 | 20 |
import cz.frantovo.alt2xml.out.ActionContext; |
franta-hg@43 | 21 |
import cz.frantovo.alt2xml.out.ActionFactory; |
franta-hg@43 | 22 |
import cz.frantovo.alt2xml.out.OutputActionException; |
franta-hg@43 | 23 |
import javax.xml.stream.XMLOutputFactory; |
franta-hg@43 | 24 |
import javax.xml.stream.XMLStreamException; |
franta-hg@43 | 25 |
import javax.xml.stream.XMLStreamWriter; |
franta-hg@43 | 26 |
|
franta-hg@43 | 27 |
/** |
franta-hg@43 | 28 |
* Prints XML. |
franta-hg@43 | 29 |
* |
franta-hg@43 | 30 |
* @author Ing. František Kučera (frantovo.cz) |
franta-hg@43 | 31 |
*/ |
franta-hg@43 | 32 |
public class XMLActionFactory implements ActionFactory { |
franta-hg@43 | 33 |
|
franta-hg@43 | 34 |
private XMLOutputFactory xmlOutputFactory; |
franta-hg@43 | 35 |
|
franta-hg@43 | 36 |
@Override |
franta-hg@43 | 37 |
public String getActionCode() { |
franta-hg@43 | 38 |
return "xml"; |
franta-hg@43 | 39 |
} |
franta-hg@43 | 40 |
|
franta-hg@43 | 41 |
@Override |
franta-hg@43 | 42 |
public Action getAction(ActionContext context) throws OutputActionException { |
franta-hg@43 | 43 |
try { |
franta-hg@43 | 44 |
XMLStreamWriter writer = getXmlOutputFactory().createXMLStreamWriter(context.getOutputStream()); |
franta-hg@43 | 45 |
return new XMLAction(context, writer); |
franta-hg@43 | 46 |
} catch (XMLStreamException e) { |
franta-hg@43 | 47 |
throw new OutputActionException("Unable to create XMLStreamWriter", e); |
franta-hg@43 | 48 |
} |
franta-hg@43 | 49 |
} |
franta-hg@43 | 50 |
|
franta-hg@43 | 51 |
private XMLOutputFactory getXmlOutputFactory() { |
franta-hg@43 | 52 |
if (xmlOutputFactory == null) { |
franta-hg@43 | 53 |
xmlOutputFactory = XMLOutputFactory.newFactory(); |
franta-hg@43 | 54 |
} |
franta-hg@43 | 55 |
return xmlOutputFactory; |
franta-hg@43 | 56 |
} |
franta-hg@43 | 57 |
|
franta-hg@43 | 58 |
} |