use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class DefaultOfficeViewerScriptServiceTest method isMimeTypeSupported.
@Test
public void isMimeTypeSupported() throws Exception {
OfficeServer officeServer = mocker.getInstance(OfficeServer.class);
OfficeConverter officeConverter = mock(OfficeConverter.class);
when(officeServer.getConverter()).thenReturn(officeConverter);
when(officeConverter.getFormatRegistry()).thenReturn(new DefaultDocumentFormatRegistry());
for (String mediaType : Arrays.asList("application/vnd.oasis.opendocument.text", "application/msword", "application/vnd.oasis.opendocument.presentation", "application/vnd.ms-powerpoint", "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.ms-excel")) {
Assert.assertTrue(mocker.getComponentUnderTest().isMimeTypeSupported(mediaType));
}
for (String mediaType : Arrays.asList("foo/bar", "application/pdf")) {
Assert.assertFalse(mocker.getComponentUnderTest().isMimeTypeSupported(mediaType));
}
}
use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class OfficeExporter method exportXHTML.
/**
* Converts the given XHTML to the specified format and writes the result to the output stream.
*
* @param xhtml the XHTML to be exported
* @param out where to write the export result
* @param format the office format to convert the XHTML to
* @param context the XWiki context, used to access the mapping between images embedded in the given XHTML and their
* location on the file system
* @throws XWikiException if the conversion fails
*/
private void exportXHTML(String xhtml, OutputStream out, DocumentFormat format, XWikiContext context) throws XWikiException {
String html = applyXSLT(xhtml, getOfficeExportXSLT(context));
String inputFileName = "export_input.html";
String outputFileName = "export_output." + format.getExtension();
Map<String, InputStream> inputStreams = new HashMap<String, InputStream>();
// We assume that the HTML was generated using the XWiki encoding.
Charset charset = Charset.forName(context.getWiki().getEncoding());
inputStreams.put(inputFileName, new ByteArrayInputStream(html.getBytes(charset)));
addEmbeddedObjects(inputStreams, context);
OfficeConverter officeConverter = this.officeServer.getConverter();
try {
Map<String, byte[]> ouput = officeConverter.convert(inputStreams, inputFileName, outputFileName);
out.write(ouput.values().iterator().next());
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_EXPORT, XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION, String.format("Exception while exporting to %s (%s).", format.getName(), format.getExtension()), e);
}
}
Aggregations