Class DynamicViewSourceGenerator
The edited model does not have to be applied: the template is rendered against a preview
metadata session built from the whole edited model
(DynamicModelManager.buildPreviewSession(io.jmix.dynmodel.meta.DynamicModelDefinition)), so a never-applied entity and attributes
added in the current editing session are reflected. The result is what an apply of the same
declaration would render, including the title resolution of
DynamicViewDeployer.resolveTitle(java.lang.String, io.jmix.dynmodel.meta.DynamicViewDefinition, io.jmix.dynmodel.meta.DynamicViewType).
The rendered XML is re-indented before it is returned, because a template renders component fragments and macro bodies at their own indentation and leaves blank lines where a directive produced nothing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DynamicModelManagerprotected DynamicViewDeployerprotected static final intprotected DynamicModelDefinitionModelConverter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerateSource(DynamicModelDefinitionModel model, DynamicEntityModel entity, DynamicViewModel view) Renders the template of the given view declaration into XML source.protected StringprettyPrint(String xml) Re-indents the given XML with one element per line.
-
Field Details
-
INDENT_SIZE
protected static final int INDENT_SIZE- See Also:
-
dynamicModelManager
-
modelConverter
-
dynamicViewDeployer
-
-
Constructor Details
-
DynamicViewSourceGenerator
public DynamicViewSourceGenerator()
-
-
Method Details
-
generateSource
public String generateSource(DynamicModelDefinitionModel model, DynamicEntityModel entity, DynamicViewModel view) Renders the template of the given view declaration into XML source.- Parameters:
model- the whole edited model, used to build the preview metadata sessionentity- the entity owning the viewview- the view declaration being edited; its template, parameters, id, and title are taken from this object, not frommodel, because the editor may hold changes not yet merged into the model graph- Returns:
- the rendered view XML, pretty-printed
- Throws:
IllegalArgumentException- when the declaration or the model is invalid
-
prettyPrint
Re-indents the given XML with one element per line. Source that cannot be parsed is returned unchanged, so that a template producing invalid XML still ends up in the editor where the user can fix it.
-