* @param exec the execution (never null)
*/
public static final
void outPageContent(Execution exec, Page page, Writer out, boolean au)
throws IOException {
final Desktop desktop = page.getDesktop();
final PageCtrl pageCtrl = (PageCtrl)page;
final Component owner = pageCtrl.getOwner();
boolean contained = owner == null && exec.isIncluded();
//a standalong page (i.e., no owner), and being included by
//non-ZK page (e.g., JSP).
//
//Revisit Bug 2001707: OK to use exec.isIncluded() since
//we use PageRenderer now (rather than Servlet's include)
//TODO: test again
//prepare style
String style = page.getStyle();
if (style == null || style.length() == 0) {
style = null;
String wd = null, hgh = null;
if (owner instanceof HtmlBasedComponent) {
final HtmlBasedComponent hbc = (HtmlBasedComponent)owner;
wd = hbc.getWidth(); //null if not set
hgh = hbc.getHeight(); //null if not set
}
if (wd != null || hgh != null || contained) {
final StringBuffer sb = new StringBuffer(32);
HTMLs.appendStyle(sb, "width", wd != null ? wd: "100%");
HTMLs.appendStyle(sb, "height",
hgh != null ? hgh: contained ? null: "100%");
style = sb.toString();
}
}
RenderContext rc = null, old = null;
final boolean divRequired = !au || owner != null;
final boolean standalone = !au && owner == null;
if (standalone) {
rc = new RenderContext(
out, desktop.getWebApp().getConfiguration().isCrawlable());
setRenderContext(exec, rc);
} else if (owner != null) {
old = getRenderContext(exec); //store
setRenderContext(exec, null);
}
//generate div first
if (divRequired) {
outDivTemplateBegin(out, page.getUuid());
}
if (standalone) { //switch out
//don't call outDivTemplateEnd yet since rc.temp will be generated before it
out = new StringWriter();
} else if (divRequired) {
outDivTemplateEnd(out); //close it now since no rc.temp
}
//generate JS second
final boolean aupg = exec.isAsyncUpdate(page); //AU this page
if (divRequired) {
out.write("\n<script type=\"text/javascript\">");
if (!aupg && owner != null) {
out.write("zkq('");
out.write(owner.getUuid());
out.write("',function(){");
}
out.write(outZkIconJS());
}
exec.setAttribute(ATTR_DESKTOP_JS_GENED, Boolean.TRUE);
final int order = ComponentRedraws.beforeRedraw(false);
final String extra;
try {
if (order < 0)
out.write(aupg ? "[": divRequired ? "zkmx(": "zkx(");
else if (order > 0) //not first child
out.write(',');
out.write("\n[0,'"); //0: page
out.write(page.getUuid());
out.write("',{");
final StringBuffer props = new StringBuffer(128);
final String pgid = page.getId();
if (pgid.length() > 0)
appendProp(props, "id", pgid);
if (owner != null) {
appendProp(props, "ow", owner.getUuid());
} else {
appendProp(props, "dt", desktop.getId());
appendProp(props, "cu", getContextURI(exec));
appendProp(props, "uu", desktop.getUpdateURI(null));
appendProp(props, "ru", desktop.getRequestPath());
}
if (style != null)
appendProp(props, "style", style);
if (!isClientROD(page))
appendProp(props, "z$rod", Boolean.FALSE);