use of org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant.DISCLOSURE in project sw360portal by sw360.
the class DocxGenerator method generateOutputFile.
@Override
public byte[] generateOutputFile(Collection<LicenseInfoParsingResult> projectLicenseInfoResults, String projectName, String projectVersion, String licenseInfoHeaderText) throws SW360Exception {
ByteArrayOutputStream docxOutputStream = new ByteArrayOutputStream();
Optional<byte[]> docxTemplateFile = CommonUtils.loadResource(DocxGenerator.class, DOCX_TEMPLATE_FILE);
if (docxTemplateFile.isPresent()) {
try {
XWPFDocument xwpfDocument = new XWPFDocument(new ByteArrayInputStream(docxTemplateFile.get()));
switch(getOutputVariant()) {
case DISCLOSURE:
fillDocument(xwpfDocument, projectLicenseInfoResults, projectName, projectVersion, licenseInfoHeaderText, false);
break;
case REPORT:
fillDocument(xwpfDocument, projectLicenseInfoResults, projectName, projectVersion, licenseInfoHeaderText, true);
break;
default:
throw new IllegalArgumentException("Unknown generator variant type: " + getOutputVariant());
}
xwpfDocument.write(docxOutputStream);
docxOutputStream.close();
} catch (XmlException e) {
throw new SW360Exception("Got XmlException while generating docx document: " + e.getMessage());
} catch (IOException e) {
throw new SW360Exception("Got IOException when generating docx document: " + e.getMessage());
} catch (TException e) {
throw new SW360Exception("Error reading sw360 licenses: " + e.getMessage());
}
return docxOutputStream.toByteArray();
} else {
throw new SW360Exception("Could not load the template for xwpf document: " + DOCX_TEMPLATE_FILE);
}
}
Aggregations