Render components (ie. expand <kwc ...>)

Pass 1 for content that can be stored in fullPage cache,
2 for everything else. 2 includes 1, so calling just with 2 also works
@param string render content
@param bool if returned contents is cacheable
547738
protected function _renderPass1($ret, &$pass1Cacheable = true)
    {
        static $benchmarkEnabled;
        if (!isset($benchmarkEnabled)) $benchmarkEnabled = Kwf_Benchmark::isEnabled();

        $offset = 0;
        while ($target = $this->_getNextRenderTarget($ret, 1, $offset)) {
            if ($benchmarkEnabled) $startTime = microtime(true);
            $helper = $this->_getHelper($target['type']);

            $statType = null;

            $content = null;
            if ($this->_enableCache) {
                $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']);
            }
            if (!is_null($content)) {
                //cache hit
                $statType = 'hit';

                //look for UseViewCache plugin in $content
                if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) {
                    if (!$p['plugin']->useViewCache($this)) {
                        //useViewCache=false: re-render but don't cache
                        $pass1Cacheable = false;
                        $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']);
                    } else {
                        //useViewCache=true
                        //continue with <pluginC in $content (so it can be cached in fullPage cache)
                    }
                }
            } else {
                //cache miss
                $statType = 'miss';

                $cacheSaved = true;
                $content = $this->_renderAndCache(
                    $target['componentId'], $target['type'], $target['value'], $target['config'],
                    true, //addPluginPlaceholders (so it can be cached in fullPage cache)
                    $cacheSaved //will be set to false if we can't use fullPage cache because eg a UseViewCache plugin returned false
                );
                if (!$cacheSaved) $pass1Cacheable = false;
            }

            //if $pass1Cacheable=true $content must include all <plugin?s
            //if $pass1Cacheable=false $contents must only include <pluginA and all other plugins must be executed already

            $content = $helper->renderCached($content, $target['componentId'], $target['config']);

            $ret = substr($ret, 0, $target['start']).$content.substr($ret, $target['end']+1);

            if ($statType) {
                if ($benchmarkEnabled) Kwf_Benchmark::count("rendered $statType", $target['statId']);
                Kwf_Benchmark::countLog('render-'.$statType);
            }

            if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint($target['componentId'].' '.$target['type'], microtime(true)-$startTime);
        }
        return $ret;
    }
1073024
@Override
	protected void renderContent(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		log.trace("renderContent");

		Map<String, String> pageProps = new HashMap<String, String>();
		pageProps.put("message", "");
		pageProps.put("searchAllChecked", "");
		pageProps.put("resourceType", "");

		ComponentBindingsProviderFactoryImpl factoryImpl = (ComponentBindingsProviderFactoryImpl) factory;

		if ("true".equals(req.getParameter("reloadCache"))) {
			factoryImpl.reloadCache();
			pageProps.put("message", "Cache Reloaded");
		}
		List<ServiceReference> bindingProviders = new ArrayList<ServiceReference>();
		String resourceType = req.getParameter("resourceType");
		if (!StringUtils.isEmpty(resourceType)) {
			log.debug("Searching for resource type: {}", resourceType);
			pageProps.put("resourceType", resourceType);
			bindingProviders = factoryImpl.getReferences(req
					.getParameter("resourceType"));
		} else if ("true".equals(req.getParameter("searchAll"))) {
			pageProps.put("searchAllChecked", "checked");
			log.debug("Searching for all binding providers");
			for (String rt : factoryImpl.getLoadedResourceTypes()) {
				log.debug("Searching for resource type: {}", rt);
				for (ServiceReference reference : factoryImpl.getReferences(rt)) {
					if (!bindingProviders.contains(reference)) {
						bindingProviders.add(reference);
					}
				}
			}
		}

		renderBlock(res, "header.html", pageProps);
		renderBlock(res, "search.html", pageProps);

		for (int i = 0; i < bindingProviders.size(); i++) {
			Map<String, String> properties = loadProperties(bindingProviders
					.get(i));
			properties.put("state", (i + 1) % 2 == 0 ? "even" : "odd");
			renderBlock(res, "result.html", properties);
		}
		res.getWriter().write("</tbody></table>");

		res.getWriter()
				.write("<table><tr><th class=\"content ui-state-default\">Recent Exceptions</th></tr>");

		for (final Object obj : componentBindingsValuesProvider
				.getRecentExceptions()) {
			renderBlock(res, "exception.html", new HashMap<String, String>() {
				private static final long serialVersionUID = 1L;
				{
					put("ex", obj.toString());
				}
			});
		}
		res.getWriter().write("</table>");
	}
204192
public function setRender(INabuHTTPResponseRender $render = null)
    {
        if ($render instanceof INabuHTTPResponseRender) {
            $this->render = $render;
        } elseif ($render === null) {
            $this->render = null;
        } else {
            throw new ENabuCoreException(
                ENabuCoreException::ERROR_METHOD_PARAMETER_IS_EMPTY,
                array('setRender', '$render')
            );
        }
    }
802110
public function renderContentBegin()
    {
        echo CHtml::openTag('div', $this->htmlContentOptions);
        if (!empty($this->content)) {
            echo $this->content;
        }
    }
1285790
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WRow row = (WRow) component;
		XmlStringBuilder xml = renderContext.getWriter();
		int cols = row.getChildCount();
		Size gap = row.getSpace();
		String gapString = gap != null ? gap.toString() : null;

		if (cols > 0) {
			xml.appendTagOpen("ui:row");
			xml.appendAttribute("id", component.getId());
			xml.appendOptionalAttribute("class", component.getHtmlClass());
			xml.appendOptionalAttribute("track", component.isTracking(), "true");
			xml.appendOptionalAttribute("gap", gapString);
			xml.appendClose();

			// Render margin
			MarginRendererUtil.renderMargin(row, renderContext);

			paintChildren(row, renderContext);

			xml.appendEndTag("ui:row");
		}
	}
185669
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WDefinitionList list = (WDefinitionList) component;
		XmlStringBuilder xml = renderContext.getWriter();

		xml.appendTagOpen("ui:definitionlist");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");

		switch (list.getType()) {
			case FLAT:
				xml.appendAttribute("type", "flat");
				break;

			case COLUMN:
				xml.appendAttribute("type", "column");
				break;

			case STACKED:
				xml.appendAttribute("type", "stacked");
				break;

			case NORMAL:
				break;

			default:
				throw new SystemException("Unknown layout type: " + list.getType());
		}

		xml.appendClose();

		// Render margin
		MarginRendererUtil.renderMargin(list, renderContext);

		for (Duplet<String, ArrayList<WComponent>> term : list.getTerms()) {
			xml.appendTagOpen("ui:term");
			xml.appendAttribute("text", I18nUtilities.format(null, term.getFirst()));
			xml.appendClose();

			for (WComponent data : term.getSecond()) {
				xml.appendTag("ui:data");
				data.paint(renderContext);
				xml.appendEndTag("ui:data");
			}

			xml.appendEndTag("ui:term");
		}

		xml.appendEndTag("ui:definitionlist");
	}
1116660
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WPanel panel = (WPanel) component;
		XmlStringBuilder xml = renderContext.getWriter();
		ListLayout layout = (ListLayout) panel.getLayout();
		int childCount = panel.getChildCount();
		Size gap = layout.getSpace();
		String gapString = gap != null ? gap.toString() : null;

		xml.appendTagOpen("ui:listlayout");

		switch (layout.getType()) {
			case FLAT:
				xml.appendAttribute("type", "flat");
				break;

			case STACKED:
				xml.appendAttribute("type", "stacked");
				break;

			case STRIPED:
				xml.appendAttribute("type", "striped");
				break;

			default:
				throw new IllegalArgumentException("Invalid type: " + layout.getType());
		}

		switch (layout.getAlignment()) {
			case LEFT:
				// left is assumed if omitted
				break;

			case RIGHT:
				xml.appendAttribute("align", "right");
				break;

			case CENTER:
				xml.appendAttribute("align", "center");
				break;

			default:
				throw new IllegalArgumentException("Invalid alignment: " + layout.getAlignment());
		}

		switch (layout.getSeparator()) {
			case NONE:
				// none is assumed if omitted
				break;

			case BAR:
				xml.appendAttribute("separator", "bar");
				break;

			case DOT:
				xml.appendAttribute("separator", "dot");
				break;

			default:
				throw new IllegalArgumentException("Invalid separator: " + layout.getSeparator());
		}

		xml.appendOptionalAttribute("ordered", layout.isOrdered(), "true");

		xml.appendOptionalAttribute("gap", gapString);

		xml.appendClose();

		// Paint children
		for (int i = 0; i < childCount; i++) {
			xml.appendTag("ui:cell");
			panel.getChildAt(i).paint(renderContext);
			xml.appendEndTag("ui:cell");
		}

		xml.appendEndTag("ui:listlayout");
	}
49588
function (str, options, cb) {
    var ECT = this.engine;
    var tmpl = this.cache(options) || this.cache(options, new ECT({ root: { page: str }}));
    tmpl.render('page', options, cb);
  }
203783
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WHeading heading = (WHeading) component;
		XmlStringBuilder xml = renderContext.getWriter();

		xml.appendTagOpen("ui:heading");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendAttribute("level", heading.getHeadingLevel().getLevel());
		xml.appendOptionalAttribute("accessibleText", heading.getAccessibleText());
		xml.appendClose();

		// Render margin
		MarginRendererUtil.renderMargin(heading, renderContext);

		if (heading.getDecoratedLabel() == null) {
			// Constructed with a String
			xml.append(heading.getText(), heading.isEncodeText());
		} else {
			heading.getDecoratedLabel().paint(renderContext);
		}

		xml.appendEndTag("ui:heading");
	}
221049
public function render($__layout, $__data = [], $__more = [])
    {
        // TODO: Aliases

        $this->incrementRender();

        $__path = $this->loader->find($__layout);

        if ($this->cache->isExpired($__path)) {
            $compiler = $this->prepareExtensions(clone $this->compiler);

            $this->cache->store($__path, $compiler->compile($this->loader->load($__path)));

            unset($compiler);
        }

        $__data = array_merge($this->getGlobals(true), $__more, $__data);

        foreach ($__data as $__key => $__value) {
            if ($__key === '__path' || $__key === '__data') {
                continue;
            }

            $$__key = $__value;
        }

        unset($__data, $__value, $__key);

        ob_start();

        try {
            if ($this->cache instanceof EdgeFileCache) {
                include $this->cache->getCacheFile($this->cache->getCacheKey($__path));
            } else {
                eval(' ?>' . $this->cache->load($__path) . '<?php ');
            }
        } catch (\Throwable $e) {
            ob_clean();
            $this->wrapException($e, $__path, $__layout);

            return null;
        }

        $result = ltrim(ob_get_clean());

        $this->decrementRender();

        $this->flushSectionsIfDoneRendering();

        return $result;
    }
187423
public function render($render = true)
    {
        if ($render) {
            ob_clean();
            header('Content-Type: application/rss+xml; charset=utf-8');
            echo $this->createXmlDocument();
            flush();
            die();
        }

        return $this->createXmlDocument();
    }
1341234
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WComponentGroup group = (WComponentGroup) component;
		XmlStringBuilder xml = renderContext.getWriter();
		List<WComponent> components = group.getComponents();

		if (components != null && !components.isEmpty()) {
			xml.appendTagOpen("ui:componentGroup");
			xml.appendAttribute("id", component.getId());
			xml.appendOptionalAttribute("track", component.isTracking(), "true");
			xml.appendClose();

			for (WComponent comp : components) {
				xml.appendTagOpen("ui:component");
				xml.appendAttribute("id", comp.getId());
				xml.appendEnd();
			}

			xml.appendEndTag("ui:componentGroup");
		}
	}
971307
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WTableRowRenderer renderer = (WTableRowRenderer) component;
		XmlStringBuilder xml = renderContext.getWriter();
		WTable table = renderer.getTable();
		TableModel dataModel = table.getTableModel();

		int[] columnOrder = table.getColumnOrder();
		final int numCols = columnOrder == null ? table.getColumnCount() : columnOrder.length;

		// Get current row details
		RowIdWrapper wrapper = renderer.getCurrentRowIdWrapper();
		List<Integer> rowIndex = wrapper.getRowIndex();

		boolean tableSelectable = table.getSelectMode() != SelectMode.NONE;
		boolean rowSelectable = tableSelectable && dataModel.isSelectable(rowIndex);
		boolean rowSelected = rowSelectable && table.getSelectedRows().contains(wrapper.getRowKey());

		boolean tableExpandable = table.getExpandMode() != WTable.ExpandMode.NONE;
		boolean rowExpandable = tableExpandable && dataModel.isExpandable(rowIndex) && wrapper.
				hasChildren();
		boolean rowExpanded = rowExpandable && table.getExpandedRows().contains(wrapper.getRowKey());

		String rowIndexAsString = TableUtil.rowIndexListToString(rowIndex);

		xml.appendTagOpen("ui:tr");
		xml.appendAttribute("rowIndex", rowIndexAsString);
		xml.appendOptionalAttribute("unselectable", !rowSelectable, "true");
		xml.appendOptionalAttribute("selected", rowSelected, "true");
		xml.appendOptionalAttribute("expandable", rowExpandable && !rowExpanded, "true");
		xml.appendClose();

		// wrote the column cell.
		boolean isRowHeader = table.isRowHeaders(); // need this before we get into the loop
		for (int i = 0; i < numCols; i++) {
			int colIndex = columnOrder == null ? i : columnOrder[i];
			WTableColumn col = table.getColumn(colIndex);
			String cellTag = "ui:td";

			if (col.isVisible()) {
				if (isRowHeader) { // The first rendered column will be the row header.
					cellTag = "ui:th";
					isRowHeader = false; // only set one col as the row header.
				}
				xml.appendTag(cellTag);
				renderer.getRenderer(colIndex).paint(renderContext);
				xml.appendEndTag(cellTag);
			}
		}

		if (rowExpandable) {
			xml.appendTagOpen("ui:subtr");
			xml.appendOptionalAttribute("open", rowExpanded, "true");
			xml.appendClose();

			if (rowExpanded || table.getExpandMode() == ExpandMode.CLIENT) {
				renderChildren(renderer, renderContext, wrapper.getChildren());
			}

			xml.appendEndTag("ui:subtr");
		}

		xml.appendEndTag("ui:tr");
	}
1289359
public function renderAction(ComponentInterface $component, ContentInterface $content)
    {
        if (empty($component->getData('_template'))) {
            // @todo log
            return new Response('');
        }

        return $this->get('synapse')
            ->createDecorator($component)
            ->decorate(array('content' => $content))
        ;
    }
373310
public function renderContent($content = null)
    {
        $repository = $this->editor->getRepository();

        if (null === $content) {
            if (null !== $page = $this->pageHelper->getCurrent()) {
                if (null === $content = $repository->loadSubjectContent($page)) {
                    if ($page->isAdvanced()) {
                        $content = $this->editor->createDefaultContent($page);
                        $this->persist($page);
                    } elseif (0 < strlen($html = $page->getHtml())) {
                        return $html;
                    } else {
                        return $this->config['default_content'];
                    }
                }
            } else {
                throw new Exception\RenderingException('Undefined content.');
            }
        } elseif ($content instanceof CM\ContentSubjectInterface) {
            if (null === $element = $repository->loadSubjectContent($content)) {
                $element = $this->editor->createDefaultContent($content);
                $this->persist($content);
            }
            $content = $element;
        } elseif (is_string($content)) {
            if (null === $element = $this->editor->getRepository()->findContentByName($content)) {
                $this->persist($element = $this->editor->createDefaultContent($content));
            }
            $content = $element;
        }

        if ($content instanceof EM\ContentInterface) {
            $this->tagManager->addTags($content->getEntityTag());

            $content = $this->editor->getViewBuilder()->buildContent($content);
        }

        if (!$content instanceof View\ContentView) {
            throw new Exception\InvalidArgumentException(
                'Expected string or instance of ' . CM\ContentSubjectInterface::class . ', ' .
                EM\ContentInterface::class . ' or ' . View\ContentView::class
            );
        }

        /** @noinspection PhpInternalEntityUsedInspection */
        return $this->getTemplate()->renderBlock('cms_content', [
            'content' => $content,
        ]);
    }
921788
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
		XmlStringBuilder xml = renderContext.getWriter();
		WDataTable table = renderer.getTable();
		TableDataModel dataModel = table.getDataModel();
		UIContext uic = UIContextHolder.getCurrent();

		final int numCols = table.getColumnCount();
		int[] columnOrder = table.getColumnOrder();
		int rowIndex = getRowIndex(table, (SubUIContext) uic);
		boolean unselectable = table.getSelectMode() != SelectMode.NONE
				&& !dataModel.isSelectable(rowIndex);

		xml.appendTagOpen("ui:tr");
		xml.appendAttribute("rowIndex", rowIndex);
		xml.appendOptionalAttribute("unselectable", unselectable, "true");
		xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
		xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));

		if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
			TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
			boolean expandable = !node.isLeaf() && !node.isExpanded();
			xml.appendOptionalAttribute("expandable", expandable, "true");
		}

		xml.appendClose();

		if (table.isShowRowHeaders()) {
			xml.appendTag("ui:th");
			renderer.getRowHeader().paint(renderContext);
			xml.appendEndTag("ui:th");
		}

		for (int i = 0; i < numCols; i++) {
			int colIndex = columnOrder == null ? i : columnOrder[i];
			WTableColumn col = table.getColumn(colIndex);

			if (col.isVisible()) {
				xml.appendTag("ui:td");
				renderer.getRenderer(colIndex).paint(renderContext);
				xml.appendEndTag("ui:td");
			}
		}

		if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
			TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
			TableTreeNode node = treeModel.getNodeAtLine(rowIndex);

			if (!node.isLeaf()) {
				xml.appendTagOpen("ui:subtr");
				xml.appendOptionalAttribute("open", node.isExpanded(), "true");
				xml.appendClose();

				if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
					WRepeater repeater = table.getRepeater();

					// If there a renderer specified by any child, we only paint content that has a specified renderer
					boolean rendererPresent = false;

					for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext();) {
						TableTreeNode child = (TableTreeNode) i.next();

						if (child.getRendererClass() != null) {
							rendererPresent = true;
						}
					}

					// Paint immediate children only.
					if (rendererPresent) {
						xml.appendTagOpen("ui:content");
						xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(),
								"true");
						xml.appendClose();

						for (Iterator<TreeNode> i = node.children(); i.hasNext();) {
							TableTreeNode child = (TableTreeNode) i.next();
							Integer rowId = child.getRowIndex() - 1;
							UIContext nodeContext = repeater.getRowContext(rowId);

							WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(
									child.getRendererClass());

							if (expandedRenderer != null) {
								UIContextHolder.pushContext(nodeContext);

								try {
									expandedRenderer.paint(renderContext);
								} finally {
									UIContextHolder.popContext();
								}
							}
						}

						xml.appendEndTag("ui:content");
					} else {
						for (Iterator<TreeNode> i = node.children(); i.hasNext();) {
							TableTreeNode child = (TableTreeNode) i.next();
							Integer rowId = child.getRowIndex() - 1;
							UIContext nodeContext = repeater.getRowContext(rowId);

							UIContextHolder.pushContext(nodeContext);

							try {
								render(component, renderContext);
							} finally {
								UIContextHolder.popContext();
							}
						}
					}
				}

				xml.appendEndTag("ui:subtr");
			}
		}

		xml.appendEndTag("ui:tr");
	}
639061
private void renderChildren(final WPanel panel, final WebXmlRenderContext renderContext) {
		LayoutManager layout = panel.getLayout();
		Renderer layoutRenderer = null;

		if (layout != null) {
			layoutRenderer = new RendererFactoryImpl().getRenderer(layout.getClass());
		}

		if (layoutRenderer == null) {
			renderContext.getWriter().appendTag("ui:content");
			paintChildren(panel, renderContext);
			renderContext.getWriter().appendEndTag("ui:content");
		} else {
			layoutRenderer.render(panel, renderContext);
		}
	}