Search in sources :

Example 1 with EntityOutputFilterStream

use of com.xpn.xwiki.internal.filter.output.EntityOutputFilterStream 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();
}
Also used : EntityOutputFilterStream(com.xpn.xwiki.internal.filter.output.EntityOutputFilterStream) XWikiDocumentOutputFilterStream(com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream) BeanInputFilterStreamFactory(org.xwiki.filter.input.BeanInputFilterStreamFactory) XARInputProperties(org.xwiki.filter.xar.input.XARInputProperties) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Aggregations

EntityOutputFilterStream (com.xpn.xwiki.internal.filter.output.EntityOutputFilterStream)1 XWikiDocumentOutputFilterStream (com.xpn.xwiki.internal.filter.output.XWikiDocumentOutputFilterStream)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 BeanInputFilterStreamFactory (org.xwiki.filter.input.BeanInputFilterStreamFactory)1 XARInputProperties (org.xwiki.filter.xar.input.XARInputProperties)1