public static List<File> writeToFiles(Options options, XmlOutput xmlOutput) { List<File> filesWritten = new ArrayList<>(); try { if (xmlOutput.getXmlOutputStream().isPresent() && options.getXmlOutputFile().isPresent()) { File xmlFile = new File(options.getXmlOutputFile().get()); try (FileOutputStream fos = new FileOutputStream(xmlFile)) { ByteArrayOutputStream outputStream = xmlOutput.getXmlOutputStream().get(); outputStream.writeTo(fos); filesWritten.add(xmlFile); if (xmlOutput.getHtmlOutputStream().isPresent() && options.getHtmlOutputFile().isPresent()) { File htmlFile = new File(options.getHtmlOutputFile().get()); try (FileOutputStream fos = new FileOutputStream(htmlFile)) { ByteArrayOutputStream outputStream = xmlOutput.getHtmlOutputStream().get(); outputStream.writeTo(fos); filesWritten.add(htmlFile); xmlOutput.close(); } catch (Exception e) { LOGGER.log(Level.FINE, "Failed to close XML file: " + e.getLocalizedMessage(), e);
private XmlOutput createXmlDocumentAndSchema(Options options, JApiCmpXmlRoot jApiCmpXmlRoot) { XmlOutput xmlOutput = new XmlOutput(); xmlOutput.setJApiCmpXmlRoot(jApiCmpXmlRoot); ByteArrayOutputStream xmlBaos = null; InputStream styleSheetAsInputStream = null; marshaller.marshal(jApiCmpXmlRoot, xmlBaos); if (options.getXmlOutputFile().isPresent()) { xmlOutput.setXmlOutputStream(Optional.of(xmlBaos)); if (xmlOutputGeneratorOptions.isCreateSchemaFile()) { final File xmlFile = new File(options.getXmlOutputFile().get()); ByteArrayOutputStream htmlOutputStream = new ByteArrayOutputStream(); transformer.transform(new StreamSource(byteArrayInputStream), new StreamResult(htmlOutputStream)); xmlOutput.setHtmlOutputStream(Optional.of(htmlOutputStream));
if (xmlOutputOptional.isPresent()) { XmlOutput xmlOutput = xmlOutputOptional.get(); if (xmlOutput.getHtmlOutputStream().isPresent()) { ByteArrayOutputStream htmlOutputStream = xmlOutput.getHtmlOutputStream().get(); String htmlString = htmlOutputStream.toString("UTF-8"); htmlString = htmlString.replaceAll("</?html>", "");
private XmlOutput createXmlDocumentAndSchema(Options options, JApiCmpXmlRoot jApiCmpXmlRoot) { XmlOutput xmlOutput = new XmlOutput(); xmlOutput.setJApiCmpXmlRoot(jApiCmpXmlRoot); ByteArrayOutputStream xmlBaos = null; InputStream styleSheetAsInputStream = null; marshaller.marshal(jApiCmpXmlRoot, xmlBaos); if (options.getXmlOutputFile().isPresent()) { xmlOutput.setXmlOutputStream(Optional.of(xmlBaos)); if (xmlOutputGeneratorOptions.isCreateSchemaFile()) { final File xmlFile = new File(options.getXmlOutputFile().get()); ByteArrayOutputStream htmlOutputStream = new ByteArrayOutputStream(); transformer.transform(new StreamSource(byteArrayInputStream), new StreamResult(htmlOutputStream)); xmlOutput.setHtmlOutputStream(Optional.of(htmlOutputStream));
public static List<File> writeToFiles(Options options, XmlOutput xmlOutput) { List<File> filesWritten = new ArrayList<>(); try { if (xmlOutput.getXmlOutputStream().isPresent() && options.getXmlOutputFile().isPresent()) { File xmlFile = new File(options.getXmlOutputFile().get()); try (FileOutputStream fos = new FileOutputStream(xmlFile)) { ByteArrayOutputStream outputStream = xmlOutput.getXmlOutputStream().get(); outputStream.writeTo(fos); filesWritten.add(xmlFile); if (xmlOutput.getHtmlOutputStream().isPresent() && options.getHtmlOutputFile().isPresent()) { File htmlFile = new File(options.getHtmlOutputFile().get()); try (FileOutputStream fos = new FileOutputStream(htmlFile)) { ByteArrayOutputStream outputStream = xmlOutput.getHtmlOutputStream().get(); outputStream.writeTo(fos); filesWritten.add(htmlFile); xmlOutput.close(); } catch (Exception e) { LOGGER.log(Level.FINE, "Failed to close XML file: " + e.getLocalizedMessage(), e);