@Override
public void write(Object value, Map<String, Object> componentAttributes, Appendable out) throws IOException {
try {
InstanceService instanceService = Aura.getInstanceService();
RenderingService renderingService = Aura.getRenderingService();
BaseComponentDef def = (BaseComponentDef) value;
ComponentDef templateDef = def.getTemplateDef();
Map<String, Object> attributes = Maps.newHashMap();
StringBuilder sb = new StringBuilder();
writeHtmlStyles(AuraServlet.getStyles(), sb);
attributes.put("auraStyleTags", sb.toString());
AuraContext context = Aura.getContextService().getCurrentContext();
DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
if (styleDefDesc != null) {
attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
}
String contextPath = context.getContextPath();
Mode mode = context.getMode();
if (mode.allowLocalRendering() && def.isLocallyRenderable()) {
DefType defType = def.getDescriptor().getDefType();
BaseComponent<?, ?> cmp = null;
if (defType == DefType.APPLICATION) {
cmp = (BaseComponent<?, ?>) instanceService.getInstance((ApplicationDef) def, componentAttributes);
} else {
cmp = (BaseComponent<?, ?>) instanceService.getInstance((ComponentDef) def, componentAttributes);
}
attributes.put("body", Lists.<BaseComponent<?, ?>> newArrayList(cmp));
attributes.put("bodyClass", "");
attributes.put("defaultBodyClass", "");
attributes.put("autoInitialize", "false");
} else {
if (ManifestUtil.isManifestEnabled()) {
attributes.put("manifest", ManifestUtil.getManifestUrl());
}
sb.setLength(0);
writeHtmlScripts(AuraServlet.getBaseScripts(context), sb);
attributes.put("auraBaseScriptTags", sb.toString());
sb.setLength(0);
writeHtmlScripts(AuraServlet.getNamespacesScripts(context), true, sb);
attributes.put("auraNamespacesScriptTags", sb.toString());
if(mode != Mode.PROD && mode != Mode.PRODDEBUG &&
Aura.getContextService().getCurrentContext().getIsDebugToolEnabled()) {
attributes.put("auraInitBlock", "<script>var debugWindow=window.open('/aura/debug.cmp','Aura Debug Tool','width=900,height=305,scrollbars=0,location=0,toolbar=0,menubar=0');$A.util.setDebugToolWindow(debugWindow);</script>");
}
Map<String, Object> auraInit = Maps.newHashMap();
if (componentAttributes != null && !componentAttributes.isEmpty()) {
auraInit.put("attributes", componentAttributes);
}
auraInit.put("descriptor", def.getDescriptor());
auraInit.put("deftype", def.getDescriptor().getDefType());
auraInit.put("host", contextPath);
StringBuilder contextWriter = new StringBuilder();
Aura.getSerializationService().write(context, null, AuraContext.class, contextWriter, "HTML");
auraInit.put("context", new Literal(contextWriter.toString()));