Search in sources :

Example 1 with RendererFromCharsToCharsWithPreviewToUrl

use of org.incode.module.document.dom.impl.renderers.RendererFromCharsToCharsWithPreviewToUrl in project estatio by estatio.

the class DocumentTemplate method preview.

// endregion
// region > preview (programmatic)
@Programmatic
public URL preview(final Object rendererModel) throws IOException {
    serviceRegistry2.injectServicesInto(rendererModel);
    if (!getContentRenderingStrategy().isPreviewsToUrl()) {
        throw new IllegalStateException(String.format("RenderingStrategy '%s' does not support previewing to URL", getContentRenderingStrategy().getReference()));
    }
    final DocumentNature inputNature = getContentRenderingStrategy().getInputNature();
    final DocumentNature outputNature = getContentRenderingStrategy().getOutputNature();
    final Renderer renderer = getContentRenderingStrategy().newRenderer();
    switch(inputNature) {
        case BYTES:
            switch(outputNature) {
                case BYTES:
                    return ((RendererFromBytesToBytesWithPreviewToUrl) renderer).previewBytesToBytes(getType(), getAtPath(), getVersion(), asBytes(), rendererModel);
                case CHARACTERS:
                    return ((RendererFromBytesToCharsWithPreviewToUrl) renderer).previewBytesToChars(getType(), getAtPath(), getVersion(), asBytes(), rendererModel);
                default:
                    // shouldn't happen, above switch statement is complete
                    throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
            }
        case CHARACTERS:
            switch(outputNature) {
                case BYTES:
                    return ((RendererFromCharsToBytesWithPreviewToUrl) renderer).previewCharsToBytes(getType(), getAtPath(), getVersion(), asChars(), rendererModel);
                case CHARACTERS:
                    return ((RendererFromCharsToCharsWithPreviewToUrl) renderer).previewCharsToChars(getType(), getAtPath(), getVersion(), asChars(), rendererModel);
                default:
                    // shouldn't happen, above switch statement is complete
                    throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
            }
        default:
            // shouldn't happen, above switch statement is complete
            throw new IllegalArgumentException(String.format("Unknown input DocumentNature '%s'", inputNature));
    }
}
Also used : RendererFromCharsToCharsWithPreviewToUrl(org.incode.module.document.dom.impl.renderers.RendererFromCharsToCharsWithPreviewToUrl) RendererFromBytesToBytesWithPreviewToUrl(org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytesWithPreviewToUrl) RendererFromBytesToCharsWithPreviewToUrl(org.incode.module.document.dom.impl.renderers.RendererFromBytesToCharsWithPreviewToUrl) RendererFromCharsToBytesWithPreviewToUrl(org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytesWithPreviewToUrl) Renderer(org.incode.module.document.dom.impl.renderers.Renderer) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Programmatic (org.apache.isis.applib.annotation.Programmatic)1 Renderer (org.incode.module.document.dom.impl.renderers.Renderer)1 RendererFromBytesToBytesWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytesWithPreviewToUrl)1 RendererFromBytesToCharsWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromBytesToCharsWithPreviewToUrl)1 RendererFromCharsToBytesWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytesWithPreviewToUrl)1 RendererFromCharsToCharsWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromCharsToCharsWithPreviewToUrl)1