<commit_before>package br.com.dbsoft.ui.component.messagelist;


import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;

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

import br.com.dbsoft.message.DBSMessage;
import br.com.dbsoft.message.DBSMessage.MESSAGE_TYPE;
import br.com.dbsoft.ui.component.DBSRenderer;
import br.com.dbsoft.ui.core.DBSFaces;
import br.com.dbsoft.util.DBSObject;


@FacesRenderer(componentFamily = DBSFaces.FAMILY, rendererType = DBSMessageList.RENDERER_TYPE)
public class DBSMessageListRenderer extends DBSRenderer {
	
	@Override
	public void decode(FacesContext pContext, UIComponent pComponent) {
		decodeBehaviors(pContext, pComponent); 
		DBSMessageList 	xMessageList = (DBSMessageList) pComponent;
		//Verifica se foi um submit de um dos botões de exclusão e exclui o item se for
//		pComponent.getClientId(pContext) + ":btDel";
		String 			xInputFooId = pvGetInputFooId(pContext, xMessageList);
		String			xSourceId = pContext.getExternalContext().getRequestParameterMap().get(DBSFaces.PARTIAL_SOURCE_PARAM);
		if (xSourceId !=null && xSourceId.startsWith(xInputFooId)){
			String xMessageKey = pContext.getExternalContext().getRequestParameterMap().get(xInputFooId);
			if (xMessageKey!=null){
				//Seta valor da mensagem 
				xMessageList.setMessageKey(xMessageKey);
				//Exclui mensagem da lista
				xMessageList.getValue().remove(xMessageKey);
//				xMessageList.getValue().getMessages().keySet().
				xMessageList.setDeleting(true);
			}else{
				xMessageList.setMessageKey("");
			}
		}
	}
	
	@Override
	public boolean getRendersChildren() {
		return true; // True=Chama o encodeChildren abaixo e interrompe a busca
						// por filho pela rotina renderChildren
	}

	@Override
	public void encodeChildren(FacesContext pContext, UIComponent pComponent) throws IOException {}


	@Override
	public void encodeBegin(FacesContext pContext, UIComponent pComponent) throws IOException {
		if (!pComponent.isRendered()) {
			return;
		}
		DBSMessageList 	xMessageList = (DBSMessageList) pComponent;
		ResponseWriter 	xWriter = pContext.getResponseWriter();
		String 			xClientId = xMessageList.getClientId(pContext);

		String xClass = DBSFaces.CSS.MESSAGELIST.MAIN.trim() + " " + xMessageList.getStyleClass();
		String xStyle = xMessageList.getStyle();

		MESSAGE_TYPE xType = MESSAGE_TYPE.INFORMATION; //Padrão
		Integer xCount = 0;
		Integer xNew = 0;
		//Encode principal
		xWriter.startElement("div", xMessageList);
			xWriter.writeAttribute("id", xClientId, null);
			xWriter.writeAttribute("name", xClientId, null);
			DBSFaces.setAttribute(xWriter, "class", xClass.trim(), null);
			if (!DBSObject.isEmpty(xStyle)){
				DBSFaces.setAttribute(xWriter, "style", xStyle, null);
			}

			//Verica se há mensagem a ser exibida
			if (xMessageList.getValue() != null){
				xCount = xMessageList.getValue().getMessages().size();
				if (xCount > 0){
					DBSMessage xMsg;
					Iterator<Entry<String, DBSMessage>> xI = xMessageList.getValue().iterator();
					while (xI.hasNext()){
						 xMsg = xI.next().getValue();
						 //Se msg ainda não foi validada(vista, neste caso)
						 if (xMsg.isValidated() == null || (xMsg.isValidated() != null && !xMsg.isValidated())){
							 //Conta a quantidade de mensagens novas
							 xNew++;
							 xMsg.setValidated(true); //Marca que mensagem como vista<commit_msg>Documentação<commit_after>package br.com.dbsoft.ui.component.messagelist;


import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map.Entry;

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

import br.com.dbsoft.message.DBSMessage;
import br.com.dbsoft.message.DBSMessage.MESSAGE_TYPE;
import br.com.dbsoft.ui.component.DBSRenderer;
import br.com.dbsoft.ui.core.DBSFaces;
import br.com.dbsoft.util.DBSObject;


@FacesRenderer(componentFamily = DBSFaces.FAMILY, rendererType = DBSMessageList.RENDERER_TYPE)
public class DBSMessageListRenderer extends DBSRenderer {
	
	@Override
	public void decode(FacesContext pContext, UIComponent pComponent) {
		decodeBehaviors(pContext, pComponent); 
		DBSMessageList 	xMessageList = (DBSMessageList) pComponent;
		//Verifica se foi um submit de um dos botões de exclusão e exclui o item se for
//		pComponent.getClientId(pContext) + ":btDel";
		String 			xInputFooId = pvGetInputFooId(pContext, xMessageList);
		String			xSourceId = pContext.getExternalContext().getRequestParameterMap().get(DBSFaces.PARTIAL_SOURCE_PARAM);
		if (xSourceId !=null && xSourceId.startsWith(xInputFooId)){
			String xMessageKey = pContext.getExternalContext().getRequestParameterMap().get(xInputFooId);
			if (xMessageKey!=null){
				//Seta valor da mensagem 
				xMessageList.setMessageKey(xMessageKey);
				//Exclui mensagem da lista
				xMessageList.getValue().remove(xMessageKey);
//				xMessageList.getValue().getMessages().keySet().
				xMessageList.setDeleting(true);
			}else{
				xMessageList.setMessageKey("");
			}
		}
	}
	
	@Override
	public boolean getRendersChildren() {
		return true; // True=Chama o encodeChildren abaixo e interrompe a busca
						// por filho pela rotina renderChildren
	}

	@Override
	public void encodeChildren(FacesContext pContext, UIComponent pComponent) throws IOException {}


	@Override
	public void encodeBegin(FacesContext pContext, UIComponent pComponent) throws IOException {
		if (!pComponent.isRendered()) {
			return;
		}
		DBSMessageList 	xMessageList = (DBSMessageList) pComponent;
		ResponseWriter 	xWriter = pContext.getResponseWriter();
		String 			xClientId = xMessageList.getClientId(pContext);

		String xClass = DBSFaces.CSS.MESSAGELIST.MAIN.trim() + " " + xMessageList.getStyleClass();
		String xStyle = xMessageList.getStyle();

		MESSAGE_TYPE xType = MESSAGE_TYPE.INFORMATION; //Padrão
		Integer xCount = 0;
		Integer xNew = 0;
		//Encode principal
		xWriter.startElement("div", xMessageList);
			xWriter.writeAttribute("id", xClientId, null);
			xWriter.writeAttribute("name", xClientId, null);
			DBSFaces.setAttribute(xWriter, "class", xClass.trim(), null);
			if (!DBSObject.isEmpty(xStyle)){
				DBSFaces.setAttribute(xWriter, "style", xStyle, null);
			}

			//Verica se há mensagem a ser exibida
			if (xMessageList.getValue() != null){
				xCount = xMessageList.getValue().getMessages().size();
				if (xCount > 0){
					DBSMessage xMsg;
					Iterator<Entry<String, DBSMessage>> xI = xMessageList.getValue().iterator();
					while (xI.hasNext()){
						 xMsg = xI.next().getValue();
						 //Se msg ainda não foi validada(visualizada, neste caso)
						 if (xMsg.isValidated() == null 
						  || !xMsg.isValidated()){
							 //Conta a quantidade de mensagens novas
							 xNew++;
							 xMsg.setValidated(true); //Marca que mensagem como vista
{'fraction_non_alphanumeric': 0.1141025641025641, 'fraction_numerical': 0.0008547008547008547, 'mean_word_length': 4.567803330689928, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3876102', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2260, 'n_words': 473}