franta-hg@43: /** franta-hg@43: * Alt2XML franta-hg@43: * Copyright © 2014 František Kučera (frantovo.cz) franta-hg@43: * franta-hg@43: * This program is free software: you can redistribute it and/or modify franta-hg@43: * it under the terms of the GNU General Public License as published by franta-hg@111: * the Free Software Foundation, version 3 of the License. franta-hg@43: * franta-hg@43: * This program is distributed in the hope that it will be useful, franta-hg@43: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@43: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@43: * GNU General Public License for more details. franta-hg@43: * franta-hg@43: * You should have received a copy of the GNU General Public License franta-hg@43: * along with this program. If not, see . franta-hg@43: */ franta-hg@43: package cz.frantovo.alt2xml.out.xml; franta-hg@43: franta-hg@43: import cz.frantovo.alt2xml.out.Action; franta-hg@43: import cz.frantovo.alt2xml.out.ActionContext; franta-hg@43: import cz.frantovo.alt2xml.out.ActionFactory; franta-hg@43: import cz.frantovo.alt2xml.out.OutputActionException; franta-hg@43: import javax.xml.stream.XMLOutputFactory; franta-hg@43: import javax.xml.stream.XMLStreamException; franta-hg@43: import javax.xml.stream.XMLStreamWriter; franta-hg@43: franta-hg@43: /** franta-hg@43: * Prints XML. franta-hg@43: * franta-hg@43: * @author Ing. František Kučera (frantovo.cz) franta-hg@43: */ franta-hg@43: public class XMLActionFactory implements ActionFactory { franta-hg@43: franta-hg@43: private XMLOutputFactory xmlOutputFactory; franta-hg@43: franta-hg@43: @Override franta-hg@43: public String getActionCode() { franta-hg@43: return "xml"; franta-hg@43: } franta-hg@43: franta-hg@43: @Override franta-hg@43: public Action getAction(ActionContext context) throws OutputActionException { franta-hg@43: try { franta-hg@43: XMLStreamWriter writer = getXmlOutputFactory().createXMLStreamWriter(context.getOutputStream()); franta-hg@43: return new XMLAction(context, writer); franta-hg@43: } catch (XMLStreamException e) { franta-hg@43: throw new OutputActionException("Unable to create XMLStreamWriter", e); franta-hg@43: } franta-hg@43: } franta-hg@43: franta-hg@43: private XMLOutputFactory getXmlOutputFactory() { franta-hg@43: if (xmlOutputFactory == null) { franta-hg@43: xmlOutputFactory = XMLOutputFactory.newFactory(); franta-hg@43: } franta-hg@43: return xmlOutputFactory; franta-hg@43: } franta-hg@43: franta-hg@43: }