Search in sources :

Example 1 with Renderer

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

the class DocumentTemplate method renderContent.

// endregion
// region > renderContent (programmatic)
@Programmatic
public void renderContent(final Document document, final Object contentDataModel) {
    final String variant = "content";
    final String documentName = document.getName();
    try {
        final DocumentNature inputNature = getContentRenderingStrategy().getInputNature();
        final DocumentNature outputNature = getContentRenderingStrategy().getOutputNature();
        final Renderer renderer = getContentRenderingStrategy().newRenderer();
        switch(inputNature) {
            case BYTES:
                switch(outputNature) {
                    case BYTES:
                        final byte[] renderedBytes = ((RendererFromBytesToBytes) renderer).renderBytesToBytes(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromBytesToChars) renderer).renderBytesToChars(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    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:
                        final byte[] renderedBytes = ((RendererFromCharsToBytes) renderer).renderCharsToBytes(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromCharsToChars) renderer).renderCharsToChars(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    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));
        }
    } catch (IOException e) {
        throw new ApplicationException("Unable to render document template", e);
    }
}
Also used : Blob(org.apache.isis.applib.value.Blob) RendererFromCharsToChars(org.incode.module.document.dom.impl.renderers.RendererFromCharsToChars) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) RendererFromCharsToBytes(org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytes) IOException(java.io.IOException) RendererFromBytesToChars(org.incode.module.document.dom.impl.renderers.RendererFromBytesToChars) RendererFromBytesToBytes(org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes) ApplicationException(org.apache.isis.applib.ApplicationException) Renderer(org.incode.module.document.dom.impl.renderers.Renderer) Clob(org.apache.isis.applib.value.Clob) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 2 with Renderer

use of org.incode.module.document.dom.impl.renderers.Renderer 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)

Example 3 with Renderer

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

the class RenderingStrategy method newRenderer.

// endregion
// region > newRenderer (programmatic)
@Programmatic
public Renderer newRenderer() {
    final Renderer renderer = (Renderer) classService.instantiate(getRendererClassName());
    serviceRegistry2.injectServicesInto(renderer);
    return renderer;
}
Also used : Renderer(org.incode.module.document.dom.impl.renderers.Renderer) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Programmatic (org.apache.isis.applib.annotation.Programmatic)3 Renderer (org.incode.module.document.dom.impl.renderers.Renderer)3 IOException (java.io.IOException)1 ApplicationException (org.apache.isis.applib.ApplicationException)1 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)1 Blob (org.apache.isis.applib.value.Blob)1 Clob (org.apache.isis.applib.value.Clob)1 RendererFromBytesToBytes (org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes)1 RendererFromBytesToBytesWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytesWithPreviewToUrl)1 RendererFromBytesToChars (org.incode.module.document.dom.impl.renderers.RendererFromBytesToChars)1 RendererFromBytesToCharsWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromBytesToCharsWithPreviewToUrl)1 RendererFromCharsToBytes (org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytes)1 RendererFromCharsToBytesWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytesWithPreviewToUrl)1 RendererFromCharsToChars (org.incode.module.document.dom.impl.renderers.RendererFromCharsToChars)1 RendererFromCharsToCharsWithPreviewToUrl (org.incode.module.document.dom.impl.renderers.RendererFromCharsToCharsWithPreviewToUrl)1