use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class DefaultOfficeResourceViewer method isPresentation.
/**
* Utility method for checking if a file name corresponds to an office presentation.
*
* @param fileName attachment file name
* @return {@code true} if the file extension represents an office presentation format, {@code false} otherwise
*/
private boolean isPresentation(String fileName) {
String extension = fileName.substring(fileName.lastIndexOf('.') + 1);
OfficeConverter officeConverter = this.officeServer.getConverter();
if (officeConverter != null) {
DocumentFormat format = officeConverter.getFormatRegistry().getFormatByExtension(extension);
return format != null && format.getInputFamily() == DocumentFamily.PRESENTATION;
}
return false;
}
use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class DefaultOfficeResourceViewerTest method configure.
/**
* Test fixture.
*
* @throws Exception in case of an exception raised during the fixture preparation
*/
@Before
public void configure() throws Exception {
final CacheManager cacheManager = mocker.getInstance(CacheManager.class);
attachmentCache = mock(Cache.class, "attachment");
externalCache = mock(Cache.class, "external");
when(cacheManager.<OfficeDocumentView>createNewCache(notNull(CacheConfiguration.class))).thenReturn(attachmentCache, externalCache);
EntityReferenceSerializer<String> entityReferenceSerializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
when(entityReferenceSerializer.serialize(ATTACHMENT_REFERENCE)).thenReturn(STRING_ATTACHMENT_REFERENCE);
when(entityReferenceSerializer.serialize(ATTACHMENT_REFERENCE.getDocumentReference())).thenReturn(STRING_DOCUMENT_REFERENCE);
AttachmentReferenceResolver<String> attachmentReferenceResolver = mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
when(attachmentReferenceResolver.resolve(STRING_ATTACHMENT_REFERENCE)).thenReturn(ATTACHMENT_REFERENCE);
this.resourceReferenceSerializer = mocker.getInstance(ResourceReferenceTypeSerializer.class);
when(this.resourceReferenceSerializer.serialize(ATTACHMENT_RESOURCE_REFERENCE)).thenReturn(STRING_ATTACHMENT_RESOURCE_REFERENCE);
ConverterManager converterManager = mocker.getInstance(ConverterManager.class);
when(converterManager.convert(boolean.class, null)).thenReturn(false);
when(converterManager.convert(DocumentReference.class, ATTACHMENT_REFERENCE.getDocumentReference())).thenReturn(ATTACHMENT_REFERENCE.getDocumentReference());
documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
officeDocumentBuilder = mocker.getInstance(XDOMOfficeDocumentBuilder.class);
OfficeServer officeServer = mocker.getInstance(OfficeServer.class);
OfficeConverter officeConverter = mock(OfficeConverter.class);
when(officeServer.getConverter()).thenReturn(officeConverter);
when(officeConverter.getFormatRegistry()).thenReturn(new DefaultDocumentFormatRegistry());
}
use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class OfficeImporterScriptService method isPresentation.
/**
* Utility method for checking if a file name corresponds to an office presentation.
*
* @param officeFileName office file name
* @return true if the file name / extension represents an office presentation format
*/
private boolean isPresentation(String officeFileName) {
String extension = officeFileName.substring(officeFileName.lastIndexOf('.') + 1);
OfficeConverter officeConverter = officeServer.getConverter();
if (officeConverter != null) {
DocumentFormat format = officeConverter.getFormatRegistry().getFormatByExtension(extension);
return format != null && format.getInputFamily() == DocumentFamily.PRESENTATION;
}
return false;
}
use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class DefaultXDOMOfficeDocumentBuilderTest method testXDOMOfficeDocumentBuilding.
/**
* Test {@link OfficeDocument} building.
*/
@Test
public void testXDOMOfficeDocumentBuilding() throws Exception {
// Create & register a mock document converter to by-pass the office server.
final InputStream mockOfficeFileStream = new ByteArrayInputStream(new byte[1024]);
final Map<String, InputStream> mockInput = new HashMap<String, InputStream>();
mockInput.put(INPUT_FILE_NAME, mockOfficeFileStream);
final Map<String, byte[]> mockOutput = new HashMap<String, byte[]>();
mockOutput.put(OUTPUT_FILE_NAME, "<html><head><title></tile></head><body><p><strong>Hello There</strong></p></body></html>".getBytes());
final OfficeConverter mockDocumentConverter = getMockery().mock(OfficeConverter.class);
final DocumentReference documentReference = new DocumentReference("xwiki", "Main", "Test");
getMockery().checking(new Expectations() {
{
oneOf(mockOfficeServer).getConverter();
will(returnValue(mockDocumentConverter));
allowing(mockDocumentConverter).convert(mockInput, INPUT_FILE_NAME, OUTPUT_FILE_NAME);
will(returnValue(mockOutput));
allowing(mockDocumentReferenceResolver).resolve("xwiki:Main.Test");
will(returnValue(documentReference));
allowing(mockDefaultStringEntityReferenceSerializer).serialize(documentReference);
will(returnValue("xwiki:Main.Test"));
}
});
XDOMOfficeDocument document = xdomOfficeDocumentBuilder.build(mockOfficeFileStream, INPUT_FILE_NAME, documentReference, true);
assertEquals("xwiki:Main.Test", document.getContentDocument().getMetaData().getMetaData(MetaData.BASE));
assertEquals("**Hello There**", document.getContentAsString());
assertEquals(0, document.getArtifacts().size());
}
use of org.xwiki.officeimporter.converter.OfficeConverter in project xwiki-platform by xwiki.
the class DefaultOfficeViewerScriptService method isConversionSupported.
/**
* Use this method to check if the unidirectional conversion from a document format (input media type) to another
* document format (output media type) is supported by this converter.
*
* @param inputMediaType the media type of the input document
* @param outputMediaType the media type of the output document
* @return {@code true} if a document can be converted from the input media type to the output media type,
* {@code false} otherwise
*/
private boolean isConversionSupported(String inputMediaType, String outputMediaType) {
OfficeConverter converter = this.officeServer.getConverter();
if (converter != null) {
DocumentFormat inputFormat = converter.getFormatRegistry().getFormatByMediaType(inputMediaType);
DocumentFormat outputFormat = converter.getFormatRegistry().getFormatByMediaType(outputMediaType);
return inputFormat != null && outputFormat != null && outputFormat.getStoreProperties(inputFormat.getInputFamily()) != null;
} else {
return false;
}
}
Aggregations