/* (non-Javadoc)
@see org.apereo.portal.portlet.rendering.IPortletExecutionManager#startPortletRender(org.apereo.portal.portlet.om.IPortletWindowId, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
779490
@Override
    public void startPortletRender(
            IPortletWindowId portletWindowId,
            HttpServletRequest request,
            HttpServletResponse response) {
        this.startPortletRenderInternal(portletWindowId, request, response);
    }
124464
protected void renderRowStart(
        FacesContext facesContext,
        ResponseWriter writer,
        UIData uiData,
        Styles styles, int rowStyleIndex) throws IOException
    {
        writer.startElement(HTML.TR_ELEM, null); // uiData);
        
        renderRowStyle(facesContext, writer, uiData, styles, rowStyleIndex);
        
        Object rowId = uiData.getAttributes().get(org.apache.myfaces.shared.renderkit.JSFAttr.ROW_ID);

        if (rowId != null)
        {
            writer.writeAttribute(HTML.ID_ATTR, rowId.toString(), null);
        }
    }
1036344
@Override
	public int doStartTag() throws JspException {

		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

		if (null == pageContext.getServletContext().getAttribute(getResourceHandlerAttributeName()))
			throw new IllegalStateException(
					"ResourceBundlesHandler not present in servlet context. Initialization of Jawr either failed or never occurred.");

		ResourceBundlesHandler rsHandler = (ResourceBundlesHandler) pageContext.getServletContext()
				.getAttribute(getResourceHandlerAttributeName());
		JawrConfig jawrConfig = rsHandler.getConfig();

		if (RendererRequestUtils.refreshConfigIfNeeded(request, jawrConfig)) {
			rsHandler = (ResourceBundlesHandler) pageContext.getServletContext()
					.getAttribute(getResourceHandlerAttributeName());
			jawrConfig = rsHandler.getConfig();
		}

		Boolean useRandomFlag = null;
		if (StringUtils.isNotEmpty(useRandomParam)) {
			useRandomFlag = Boolean.valueOf(useRandomParam);
		}
		// Renderer istance which takes care of generating the response
		BundleRenderer renderer = createRenderer(rsHandler, useRandomFlag);

		// set the debug override
		RendererRequestUtils.setRequestDebuggable(request, jawrConfig);

		try {
			BundleRendererContext ctx = RendererRequestUtils.getBundleRendererContext(request, renderer);
			renderer.renderBundleLinks(src, ctx, pageContext.getOut());

		} catch (IOException ex) {
			throw new JspException("Unexpected IOException when writing script tags for path " + src, ex);
		} finally {
			// Reset the Thread local for the Jawr context
			ThreadLocalJawrContext.reset();
		}

		return SKIP_BODY;
	}
181634
@Override
    public boolean isPortletRenderHeaderRequested(
            IPortletWindowId portletWindowId,
            HttpServletRequest request,
            HttpServletResponse response) {
        final Map<IPortletWindowId, IPortletRenderExecutionWorker> portletRenderingMap =
                this.getPortletHeaderRenderingMap(request);
        final IPortletRenderExecutionWorker tracker = portletRenderingMap.get(portletWindowId);

        return tracker != null;
    }
1141241
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WApplication application = (WApplication) component;
		XmlStringBuilder xml = renderContext.getWriter();

		UIContext uic = UIContextHolder.getCurrent();
		String focusId = uic.getFocussedId();

		// Check that this is the top level component
		if (application.getParent() != null) {
			LOG.warn("WApplication component should be the top level component.");
		}

		xml.appendTagOpen("ui:application");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendUrlAttribute("applicationUrl", uic.getEnvironment().getPostPath());
		xml.appendUrlAttribute("ajaxUrl", uic.getEnvironment().getWServletPath());
		xml.appendOptionalAttribute("unsavedChanges", application.hasUnsavedChanges(), "true");
		xml.appendOptionalAttribute("title", application.getTitle());
		xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId),
				focusId);
		xml.appendOptionalUrlAttribute("icon", WApplication.getIcon());
		xml.appendClose();

		// Tracking enabled globally
		if (TrackingUtil.isTrackingEnabled()) {
			xml.appendTagOpen("ui:analytic");
			xml.appendAttribute("clientId", TrackingUtil.getClientId());
			xml.appendOptionalAttribute("cd", TrackingUtil.getCookieDomain());
			xml.appendOptionalAttribute("dcd", TrackingUtil.getDataCollectionDomain());
			xml.appendOptionalAttribute("name", TrackingUtil.getApplicationName());
			xml.appendEnd();
		}

		// Hidden fields
		Map<String, String> hiddenFields = uic.getEnvironment().getHiddenParameters();

		if (hiddenFields != null) {
			for (Map.Entry<String, String> entry : hiddenFields.entrySet()) {
				xml.appendTagOpen("ui:param");
				xml.appendAttribute("name", entry.getKey());
				xml.appendAttribute("value", entry.getValue());
				xml.appendEnd();
			}
		}
		// Custom CSS Resources (if any)
		for (WApplication.ApplicationResource resource : application.getCssResources()) {
			String url = resource.getTargetUrl();
			if (!Util.empty(url)) {
				xml.appendTagOpen("ui:css");
				xml.appendUrlAttribute("url", url);
				xml.appendEnd();
			}
		}

		// Custom JavaScript Resources (if any)
		for (WApplication.ApplicationResource resource : application.getJsResources()) {
			String url = resource.getTargetUrl();
			if (!Util.empty(url)) {
				xml.appendTagOpen("ui:js");
				xml.appendUrlAttribute("url", url);
				xml.appendEnd();
			}
		}

		paintChildren(application, renderContext);

		xml.appendEndTag("ui:application");
	}
1171716
@Override
	protected final void onRender()
	{
		Iterator<? extends Component> it = renderIterator();
		while (it.hasNext())
		{
			Component child = it.next();
			if (child == null)
			{
				throw new IllegalStateException(
					"The render iterator returned null for a child. Container: " + this.toString() +
						"; Iterator=" + it.toString());
			}
			renderChild(child);
		}
	}
1368668
private void renderViewPorts(PdfContext context) {
		for (PrintComponent<?> child : getChildren()) {
			if (child instanceof ViewPortComponentImpl) {
				renderViewPort((ViewPortComponentImpl) child, context);
			}
		}
	}
1025311
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WRepeater repeater = (WRepeater) component;
		XmlStringBuilder xml = renderContext.getWriter();

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

		xml.appendTag("ui:content");
		paintRows(repeater, renderContext);
		xml.appendEndTag("ui:content");

		xml.appendEndTag("ui:panel");
	}
150721
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WFieldSet fieldSet = (WFieldSet) component;
		XmlStringBuilder xml = renderContext.getWriter();

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

		switch (fieldSet.getFrameType()) {
			case NO_BORDER:
				xml.appendOptionalAttribute("frame", "noborder");
				break;

			case NO_TEXT:
				xml.appendOptionalAttribute("frame", "notext");
				break;

			case NONE:
				xml.appendOptionalAttribute("frame", "none");
				break;

			case NORMAL:
			default:
				break;
		}

		xml.appendOptionalAttribute("required", fieldSet.isMandatory(), "true");
		xml.appendClose();

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

		// Label
		WDecoratedLabel label = fieldSet.getTitle();
		label.paint(renderContext);

		// Children
		xml.appendTag("ui:content");
		int size = fieldSet.getChildCount();

		for (int i = 0; i < size; i++) {
			WComponent child = fieldSet.getChildAt(i);

			// Skip label, as it has already been painted
			if (child != label) {
				child.paint(renderContext);
			}
		}

		xml.appendEndTag("ui:content");
		DiagnosticRenderUtil.renderDiagnostics(fieldSet, renderContext);
		xml.appendEndTag("ui:fieldset");
	}
275750
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WLink link = (WLink) component;
		XmlStringBuilder xml = renderContext.getWriter();
		String text = link.getText();
		String targetWindowName = link.getOpenNewWindow() ? link.getTargetWindowName() : null;
		String imageUrl = link.getImageUrl();

		xml.appendTagOpen("ui:link");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendOptionalAttribute("disabled", link.isDisabled(), "true");
		xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
		xml.appendOptionalAttribute("toolTip", link.getToolTip());
		xml.appendOptionalAttribute("accessibleText", link.getAccessibleText());
		xml.appendUrlAttribute("url", link.getUrl());
		xml.appendOptionalAttribute("rel", link.getRel());
		xml.appendOptionalAttribute("accessKey", Util.upperCase(link.getAccessKeyAsString()));

		if (imageUrl != null) {
			xml.appendUrlAttribute("imageUrl", imageUrl);
			ImagePosition imagePosition = link.getImagePosition();

			if (imagePosition != null) {
				switch (imagePosition) {
					case NORTH:
						xml.appendAttribute("imagePosition", "n");
						break;
					case EAST:
						xml.appendAttribute("imagePosition", "e");
						break;
					case SOUTH:
						xml.appendAttribute("imagePosition", "s");
						break;
					case WEST:
						xml.appendAttribute("imagePosition", "w");
						break;
					default:
						throw new SystemException("Unknown image position: " + imagePosition);
				}
			}
			// we have an image. We must have a text equivalent
			if (Util.empty(text) && Util.empty(link.getToolTip()) && Util.empty(link.getAccessibleText())) {
				// If the link has an umageUrl but no text equivalent get the text equivalent off of the image
				WImage linkImage = link.getImageHolder();
				if (null != linkImage) {
					xml.appendOptionalAttribute("toolTip", linkImage.getAlternativeText());
				}
			}
		}

		if (link.isRenderAsButton()) {
			xml.appendAttribute("type", "button");
		}

		xml.appendClose();

		if (targetWindowName != null) {
			xml.appendTagOpen("ui:windowAttributes");
			xml.appendAttribute("name", targetWindowName);

			WLink.WindowAttributes attributes = link.getWindowAttrs();

			if (attributes != null) {
				xml.appendOptionalAttribute("top", attributes.getTop() >= 0, attributes.getTop());
				xml.appendOptionalAttribute("left", attributes.getLeft() >= 0, attributes.getLeft());
				xml.appendOptionalAttribute("width", attributes.getWidth() > 0, attributes.
						getWidth());
				xml.appendOptionalAttribute("height", attributes.getHeight() > 0, attributes.
						getHeight());
				xml.appendOptionalAttribute("resizable", attributes.isResizable(), "true");
				xml.appendOptionalAttribute("showMenubar", attributes.isMenubar(), "true");
				xml.appendOptionalAttribute("showToolbar", attributes.isToolbars(), "true");
				xml.appendOptionalAttribute("showLocation", attributes.isLocation(), "true");
				xml.appendOptionalAttribute("showStatus", attributes.isStatus(), "true");
				xml.appendOptionalAttribute("showScrollbars", attributes.isScrollbars(), "true");
				xml.appendOptionalAttribute("showDirectories", attributes.isDirectories(), "true");
			}

			xml.appendEnd();
		}

		if (text != null) {
			xml.appendEscaped(text);
		}

		xml.appendEndTag("ui:link");

		// Paint the AJAX trigger if the link has an action
		if (link.getAction() != null) {
			paintAjaxTrigger(link, xml);
		}

	}
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>");
	}
135482
@Override
    public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) {
        try {
            collaborator.preInvoke(componentMetaData);
            return request.startAsync(arg0, arg1);
        } finally {
            collaborator.postInvoke();
        }
    }
619040
@Override
	protected BundleRenderer createRenderer(ResourceBundlesHandler rsHandler,
			Boolean useRandomParam, ComponentTag tag) {
		
		final IValueMap attributes = tag.getAttributes();
		boolean async = attributes.getBoolean(JawrConstant.ASYNC_ATTR);
		boolean defer = attributes.getBoolean(JawrConstant.DEFER_ATTR);
        String type = attributes.getString(JawrConstant.TYPE_ATTR);
        String crossorigin = attributes.getString(JawrConstant.CROSSORIGIN_ATTR);
		return RendererFactory.getJsBundleRenderer(rsHandler, type, useRandomParam, async, defer, crossorigin);
	}
1278776
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WList list = (WList) component;
		XmlStringBuilder xml = renderContext.getWriter();
		WList.Type type = list.getType();
		WList.Separator separator = list.getSeparator();
		Size gap = list.getSpace();
		String gapString = gap == null ? null : gap.toString();
		xml.appendTagOpen("ui:panel");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendOptionalAttribute("type", list.isRenderBorder(), "box");
		xml.appendClose();

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

		xml.appendTagOpen("ui:listlayout");
		xml.appendOptionalAttribute("gap", gapString);

		if (type != null) {
			switch (type) {
				case FLAT:
					xml.appendAttribute("type", "flat");
					break;

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

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

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

		if (separator != null) {
			switch (separator) {
				case BAR:
					xml.appendAttribute("separator", "bar");
					break;

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

				case NONE:
					break;

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

		xml.appendClose();

		paintRows(list, renderContext);

		xml.appendEndTag("ui:listlayout");
		xml.appendEndTag("ui:panel");
	}
146442
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WPopup popup = (WPopup) component;
		XmlStringBuilder xml = renderContext.getWriter();
		int width = popup.getWidth();
		int height = popup.getHeight();
		String targetWindow = popup.getTargetWindow();

		xml.appendTagOpen("ui:popup");
		xml.appendUrlAttribute("url", popup.getUrl());
		xml.appendOptionalAttribute("width", width > 0, width);
		xml.appendOptionalAttribute("height", height > 0, height);
		xml.appendOptionalAttribute("resizable", popup.isResizable(), "true");
		xml.appendOptionalAttribute("showScrollbars", popup.isScrollable(), "true");
		xml.appendOptionalAttribute("targetWindow", !Util.empty(targetWindow), targetWindow);
		xml.appendClose();
		xml.appendEndTag("ui:popup");
	}
1151837
@Override
    public IPortalUrlBuilder getPortalUrlBuilderByLayoutNode(
            HttpServletRequest request, String layoutNodeId, UrlType urlType) {
        final IPortletWindowId portletWindowId = getPortletWindowId(request, layoutNodeId);

        return new PortalUrlBuilder(
                this.urlSyntaxProvider, request, layoutNodeId, portletWindowId, urlType);
    }
576398
public int doStartTag() throws JspException
    {
        ServletRequest req = pageContext.getRequest();
        if (_cr == null)
            _cr = TagRenderingBase.Factory.getConstantRendering(req);

        // get the evaluated dataSource and default values
        Object val = evaluateDataSource();
        _defaultSelections = (List) evaluateDefaultValue();
        if (hasErrors()) {
            return SKIP_BODY;
        }

        // process the default values and create the matching array...
        if (val != null) {
            buildMatch(val);
            if (hasErrors()) {
                return SKIP_BODY;
            }
        }

        // if the checkbox group is disabled do not write out the
        // hidden field.
        _writer = new WriteRenderAppender(pageContext);
        if (!_repeater && !_disabled) {

            //Create hidden field for state tracking
            _state.clear();
            String hiddenParamName = null;
            hiddenParamName = getQualifiedDataSourceName() + OLDVALUE_SUFFIX;
            _state.name = hiddenParamName;
            _state.value = "true";

            TagRenderingBase hiddenTag = TagRenderingBase.Factory.getRendering(TagRenderingBase.INPUT_HIDDEN_TAG, req);
            hiddenTag.doStartTag(_writer, _state);
            hiddenTag.doEndTag(_writer);
        }

        if (isVertical())
            _cr.TABLE(_writer);

        // if this is a repeater then we shouid prime the pump...
        _dynamicAttrs = evaluateOptionsDataSource();
        assert (_dynamicAttrs != null);
        assert (_dynamicAttrs instanceof Map ||
                _dynamicAttrs instanceof Iterator);

        if (_repeater) {
            if (_dynamicAttrs instanceof Map) {
                _dynamicAttrs = ((Map) _dynamicAttrs).entrySet().iterator();
            }
            if (!(_dynamicAttrs instanceof Iterator)) {
                String s = Bundle.getString("Tags_OptionsDSIteratorError");
                registerTagError(s, null);
                return SKIP_BODY;
            }
            while (((Iterator) _dynamicAttrs).hasNext()) {
                _repCurItem = ((Iterator) _dynamicAttrs).next();
                if (_repCurItem != null)
                    break;
            }
            if (isVertical())
                _cr.TR_TD(_writer);

            DataAccessProviderStack.addDataAccessProvider(this, pageContext);
        }
        _saveBody = new InternalStringBuilder(128);

        // Continue processing this page
        return EVAL_BODY_BUFFERED;

    }