franta-hg@28: /** franta-hg@28: * parameter-lister franta-hg@28: * Copyright © 2015 František Kučera (frantovo.cz) franta-hg@28: * franta-hg@28: * This program is free software: you can redistribute it and/or modify franta-hg@28: * it under the terms of the GNU General Public License as published by franta-hg@28: * the Free Software Foundation, either version 3 of the License, or franta-hg@28: * (at your option) any later version. franta-hg@28: * franta-hg@28: * This program is distributed in the hope that it will be useful, franta-hg@28: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@28: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@28: * GNU General Public License for more details. franta-hg@28: * franta-hg@28: * You should have received a copy of the GNU General Public License franta-hg@28: * along with this program. If not, see . franta-hg@28: */ franta-hg@21: package info.glogalcode.parameterLister.modules; franta-hg@21: franta-hg@21: import info.glogalcode.parameterLister.OutputModule; franta-hg@21: import info.glogalcode.parameterLister.OutputModuleException; franta-hg@21: import java.io.OutputStream; franta-hg@21: import java.io.PrintWriter; franta-hg@21: import java.util.List; franta-hg@21: franta-hg@21: /** franta-hg@23: * Just a simple XML output. franta-hg@23: * For more complex documents, use {@linkplain javax.xml.stream.XMLStreamWriter} franta-hg@21: * franta-hg@21: * @author Ing. František Kučera (frantovo.cz) franta-hg@21: */ franta-hg@22: public class XmlModule implements OutputModule { franta-hg@21: franta-hg@21: @Override franta-hg@21: public void process(OutputStream output, List parameters) throws OutputModuleException { franta-hg@21: try (PrintWriter out = new PrintWriter(output)) { franta-hg@23: out.println(""); franta-hg@21: for (String parameter : parameters) { franta-hg@23: out.print("\t"); franta-hg@23: out.print(escapeXmlText(parameter)); franta-hg@23: out.println(""); franta-hg@21: out.flush(); franta-hg@21: } franta-hg@23: out.println(""); franta-hg@21: } franta-hg@21: } franta-hg@21: franta-hg@23: /** franta-hg@23: * @param s original text franta-hg@23: * @return escaped text that can be safely concatenated between two XML tags (not safe for franta-hg@23: * attribute franta-hg@23: * values) franta-hg@23: */ franta-hg@23: private static String escapeXmlText(String s) { franta-hg@23: return s.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"); franta-hg@23: } franta-hg@21: }