<commit_before>/**
 *  Copyright 2014-15 by <NAME> (TheCoder4.Eu) and <NAME> (http://www.beyondjava.net).
 *  
 *  This file is part of BootsFaces.
 *  
 *  BootsFaces is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  BootsFaces is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with BootsFaces. If not, see <http://www.gnu.org/licenses/>.
 */

package net.bootsfaces.component.panel;

import java.io.IOException;

import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.render.CoreRenderer;
import net.bootsfaces.render.H;
import net.bootsfaces.render.Tooltip;

/** This class generates the HTML code of &lt;b:panel /&gt;. */
// @ResourceDependencies({ @ResourceDependency(library = "bsf", name =
// "css/core.css"),
// @ResourceDependency(library = "bsf", name = "css/panels.css"),
// @ResourceDependency(library = "bsf", name = "css/bsf.css"),
// @ResourceDependency(library = "bsf", name = "js/collapse.js", target =
// "body") })
@FacesRenderer(componentFamily = "net.bootsfaces.component", rendererType = "net.bootsfaces.component.panel.Panel")
public class PanelRenderer extends CoreRenderer {
	/**
	 * This methods receives and processes input made by the user. More
	 * specifically, it ckecks whether the user has interacted with the current
	 * b:panel. The default implementation simply stores the input value in the
	 * list of submitted values. If the validation checks are passed, the values
	 * in the <code>submittedValues</code> list are store in the backend bean.
	 * 
	 * @param context
	 *            the FacesContext.
	 * @param component
	 *            the current b:panel.
	 */
	@Override
	public void decode(FacesContext context, UIComponent component) {
		Panel panel = (Panel) component;

		decodeBehaviors(context, panel);

		String clientId = panel.getClientId(context);
		String collapseStateId = clientId.replace(":", "_") + "_collapsed";

		String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(collapseStateId);

		if (submittedValue != null) {
			if (Boolean.valueOf(submittedValue) != panel.isCollapsed())
				panel.setCollapsed(Boolean.valueOf(submittedValue));
		}
	}

	/**
	 * This methods generates the HTML code of the current b:panel.
	 * <code>encodeBegin</code> generates the start of the component. After the,
	 * the JSF framework calls <code>encodeChildren()</code> to generate the
	 * HTML code between the beginning and the end of the component. For
	 * instance, in the case of a panel component the content of the panel is
	 * generated by <code>encodeChildren()</code>. After that,
	 * <code>encodeEnd()</code> is called to generate the rest of the HTML code.
	 * 
	 * @param context
	 *            the FacesContext.
	 * @param component
	 *            the current b:panel.
	 * @throws IOException
	 *             thrown if something goes wrong when writing the HTML code.
	 */
	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		if (!component.isRendered()) {
			return;
		}
		Panel panel = (Panel) component;
		ResponseWriter rw = context.getResponseWriter();
		String clientId = panel.getClientId();

		String jQueryClientID = clientId.replace(":", "_");

		boolean isCollapsible = panel.isCollapsible();

		if (isCollapsible) {
			rw.startElement(H.DIV, panel);
			rw.writeAttribute(H.CLASS, "panel-group", null);
		}

		String _look = panel.getLook();
		String _title = panel.getTitle();
		String _titleClass = panel.getTitleClass();
		String _styleClass = panel.getStyleClass();
		if (null == _styleClass) {
			_styleClass = "";
		} else {
			_styleClass += " ";
		}

		rw.startElement(H.DIV, panel);
		rw.writeAttribute(H.ID, clientId, H.ID);
		Tooltip.generateTooltip(context, panel, rw);
		String _style = panel.getStyle();
		if (null != _style && _style.length() > 0) {
			rw.writeAttribute("style", _style, "style");
		}

		if (_look != null) {
			rw.writeAttribute(H.CLASS, _styleClass + "panel panel-" + _look, H.CLASS);
		} else {
			rw.writeAttribute(H.CLASS, _styleClass + "panel panel-default", H.CLASS);
		}

		UIComponent head = panel.getFacet("heading");
		if (head != null || _title != null) {
			rw.startElement(H.DIV, panel);
			rw.writeAttribute(H.CLASS, "panel-heading", H.CLASS);
			String _titleStyle = panel.getTitleStyle();
			if (null != _titleStyle) {
				rw.writeAttribute("style", _titleStyle, "style");
			}
			if (_title != null) {
				rw.startElement(H.H4, panel);
				if (_titleClass != null) {
					rw.writeAttribute(H.CLASS, _titleClass, H.CLASS);
				} else {
					rw.writeAttribute(H.CLASS, "panel-title", H.CLASS);
				}
				if (isCollapsible) {
					rw.startElement(H.A, panel);
					rw.writeAttribute("data-toggle", "collapse", "null");
					rw.writeAttribute("data-target", "#" + jQueryClientID + "content", "null");
				}

				rw.writeText(_title, null);
				rw.endElement(H.A);
				rw.endElement(H.H4);
			} else {
				if (isCollapsible) {
					rw.startElement(H.A, panel);
					rw.writeAttribute("data-toggle", "collapse", "null");
					rw.writeAttribute("data-target", "#" + jQueryClientID + "content", "null");
				}
				head.encodeAll(context);
				rw.endElement(H.A);
			}
			rw.endElement(H.DIV);
		}

		rw.startElement(H.DIV, panel);
		rw.writeAttribute("id", jQueryClientID + "content", null);<commit_msg>fixed #126 wrong HTML markup when collapsible="false"<commit_after>/**
 *  Copyright 2014-15 by <NAME> (TheCoder4.Eu) and <NAME> (http://www.beyondjava.net).
 *  
 *  This file is part of BootsFaces.
 *  
 *  BootsFaces is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  BootsFaces is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with BootsFaces. If not, see <http://www.gnu.org/licenses/>.
 */

package net.bootsfaces.component.panel;

import java.io.IOException;

import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.render.CoreRenderer;
import net.bootsfaces.render.H;
import net.bootsfaces.render.Tooltip;

/** This class generates the HTML code of &lt;b:panel /&gt;. */
// @ResourceDependencies({ @ResourceDependency(library = "bsf", name =
// "css/core.css"),
// @ResourceDependency(library = "bsf", name = "css/panels.css"),
// @ResourceDependency(library = "bsf", name = "css/bsf.css"),
// @ResourceDependency(library = "bsf", name = "js/collapse.js", target =
// "body") })
@FacesRenderer(componentFamily = "net.bootsfaces.component", rendererType = "net.bootsfaces.component.panel.Panel")
public class PanelRenderer extends CoreRenderer {
	/**
	 * This methods receives and processes input made by the user. More
	 * specifically, it ckecks whether the user has interacted with the current
	 * b:panel. The default implementation simply stores the input value in the
	 * list of submitted values. If the validation checks are passed, the values
	 * in the <code>submittedValues</code> list are store in the backend bean.
	 * 
	 * @param context
	 *            the FacesContext.
	 * @param component
	 *            the current b:panel.
	 */
	@Override
	public void decode(FacesContext context, UIComponent component) {
		Panel panel = (Panel) component;

		decodeBehaviors(context, panel);

		String clientId = panel.getClientId(context);
		String collapseStateId = clientId.replace(":", "_") + "_collapsed";

		String submittedValue = (String) context.getExternalContext().getRequestParameterMap().get(collapseStateId);

		if (submittedValue != null) {
			if (Boolean.valueOf(submittedValue) != panel.isCollapsed())
				panel.setCollapsed(Boolean.valueOf(submittedValue));
		}
	}

	/**
	 * This methods generates the HTML code of the current b:panel.
	 * <code>encodeBegin</code> generates the start of the component. After the,
	 * the JSF framework calls <code>encodeChildren()</code> to generate the
	 * HTML code between the beginning and the end of the component. For
	 * instance, in the case of a panel component the content of the panel is
	 * generated by <code>encodeChildren()</code>. After that,
	 * <code>encodeEnd()</code> is called to generate the rest of the HTML code.
	 * 
	 * @param context
	 *            the FacesContext.
	 * @param component
	 *            the current b:panel.
	 * @throws IOException
	 *             thrown if something goes wrong when writing the HTML code.
	 */
	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		if (!component.isRendered()) {
			return;
		}
		Panel panel = (Panel) component;
		ResponseWriter rw = context.getResponseWriter();
		String clientId = panel.getClientId();

		String jQueryClientID = clientId.replace(":", "_");

		boolean isCollapsible = panel.isCollapsible();

		if (isCollapsible) {
			rw.startElement(H.DIV, panel);
			rw.writeAttribute(H.CLASS, "panel-group", null);
		}

		String _look = panel.getLook();
		String _title = panel.getTitle();
		String _titleClass = panel.getTitleClass();
		String _styleClass = panel.getStyleClass();
		if (null == _styleClass) {
			_styleClass = "";
		} else {
			_styleClass += " ";
		}

		rw.startElement(H.DIV, panel);
		rw.writeAttribute(H.ID, clientId, H.ID);
		Tooltip.generateTooltip(context, panel, rw);
		String _style = panel.getStyle();
		if (null != _style && _style.length() > 0) {
			rw.writeAttribute("style", _style, "style");
		}

		if (_look != null) {
			rw.writeAttribute(H.CLASS, _styleClass + "panel panel-" + _look, H.CLASS);
		} else {
			rw.writeAttribute(H.CLASS, _styleClass + "panel panel-default", H.CLASS);
		}

		UIComponent head = panel.getFacet("heading");
		if (head != null || _title != null) {
			rw.startElement(H.DIV, panel);
			rw.writeAttribute(H.CLASS, "panel-heading", H.CLASS);
			String _titleStyle = panel.getTitleStyle();
			if (null != _titleStyle) {
				rw.writeAttribute("style", _titleStyle, "style");
			}
			if (_title != null) {
				rw.startElement(H.H4, panel);
				if (_titleClass != null) {
					rw.writeAttribute(H.CLASS, _titleClass, H.CLASS);
				} else {
					rw.writeAttribute(H.CLASS, "panel-title", H.CLASS);
				}
				if (isCollapsible) {
					rw.startElement(H.A, panel);
					rw.writeAttribute("data-toggle", "collapse", "null");
					rw.writeAttribute("data-target", "#" + jQueryClientID + "content", "null");
				}

				rw.writeText(_title, null);
				rw.endElement(H.A);
				rw.endElement(H.H4);
			} else {
				if (isCollapsible) {
					rw.startElement(H.A, panel);
					rw.writeAttribute("data-toggle", "collapse", "null");
					rw.writeAttribute("data-target", "#" + jQueryClientID + "content", "null");
				}
				head.encodeAll(context);
				if (isCollapsible) {
					rw.endElement(H.A);
				}
			}
			rw.endElement(H.DIV);
		}

		rw.startElement(H.DIV, panel);
		rw.writeAttribute("id", jQueryClientID + "content", null);
{'fraction_non_alphanumeric': 0.12861152385669472, 'fraction_numerical': 0.0020637279181112763, 'mean_word_length': 3.7961203483768804, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2560289', 'n_tokens_mistral': 4038, 'n_tokens_neox': 3627, 'n_words': 1043}