use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class DocumentAbstract method getId.
// endregion
// region > id (programmatic, for comparison)
@Programmatic
public String getId() {
Object objectId = JDOHelper.getObjectId(this);
if (objectId == null) {
return "";
}
String objectIdStr = objectId.toString();
final String id = objectIdStr.split("\\[OID\\]")[0];
return id;
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class DocumentTemplate method newAttachmentAdvisor.
@Programmatic
public AttachmentAdvisor newAttachmentAdvisor(final Object domainObject) {
final Class<?> domainObjectClass = domainObject.getClass();
final com.google.common.base.Optional<Applicability> applicabilityIfAny = FluentIterable.from(getAppliesTo()).filter(applicability -> applies(applicability, domainObjectClass)).first();
if (!applicabilityIfAny.isPresent()) {
return null;
}
final AttachmentAdvisor attachmentAdvisor = (AttachmentAdvisor) classService.instantiate(applicabilityIfAny.get().getAttachmentAdvisorClassName());
serviceRegistry2.injectServicesInto(attachmentAdvisor);
return attachmentAdvisor;
}
use of org.apache.isis.applib.annotation.Programmatic in project estatio by estatio.
the class DocumentTemplate method newRendererModelFactory.
@Programmatic
public RendererModelFactory newRendererModelFactory(final Object domainObject) {
final Class<?> domainObjectClass = domainObject.getClass();
final com.google.common.base.Optional<Applicability> applicabilityIfAny = FluentIterable.from(getAppliesTo()).filter(applicability -> applies(applicability, domainObjectClass)).first();
if (!applicabilityIfAny.isPresent()) {
return null;
}
final RendererModelFactory rendererModelFactory = (RendererModelFactory) classService.instantiate(applicabilityIfAny.get().getRendererModelFactoryClassName());
serviceRegistry2.injectServicesInto(rendererModelFactory);
return rendererModelFactory;
}
use of org.apache.isis.applib.annotation.Programmatic 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);
}
}
use of org.apache.isis.applib.annotation.Programmatic 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));
}
}
Aggregations