use of com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream in project xwiki-platform by xwiki.
the class XWikiDocumentFilterUtils method importEntity.
/**
* @param entityClass to class used to find the {@link EntityOutputFilterStream} component
* @param entity the entity to write to or null to create a new entity of the passed class
* @param source the stream to read
* @param xarProperties the configuration of the input filter
* @param documentProperties the configuration of the output filter
* @return the imported entity, same as {@code entity} if not null
* @throws FilterException when failing to import
* @throws IOException when failing to import
* @throws ComponentLookupException when failing to find a EntityOutputFilterStream corresponding to passed class
*/
public <T> T importEntity(Class<T> entityClass, T entity, InputSource source, XARInputProperties xarProperties, DocumentInstanceOutputProperties documentProperties) throws FilterException, IOException, ComponentLookupException {
// Output
EntityOutputFilterStream<T> filterStream = this.componentManager.getInstance(new DefaultParameterizedType(null, EntityOutputFilterStream.class, entityClass));
filterStream.setProperties(documentProperties);
filterStream.setEntity(entity);
if (filterStream instanceof XWikiDocumentOutputFilterStream) {
((XWikiDocumentOutputFilterStream) filterStream).disableRenderingEvents();
}
// Input
xarProperties.setSourceType(getSourceType(entityClass));
xarProperties.setSource(source);
BeanInputFilterStream<XARInputProperties> xarReader = ((BeanInputFilterStreamFactory<XARInputProperties>) this.xarInputFilterStreamFactory).createInputFilterStream(xarProperties);
// Convert
xarReader.read(filterStream.getFilter());
xarReader.close();
return filterStream.getEntity();
}
Aggregations