View Javadoc

1   /*
2    * Created on 09/05/2005
3    * 
4    */
5   package ecar.taglib.util;
6   
7   import java.util.Iterator;
8   import java.util.List;
9   
10  import javax.servlet.jsp.JspException;
11  import javax.servlet.jsp.JspWriter;
12  import javax.servlet.jsp.tagext.Tag;
13  import javax.servlet.jsp.tagext.TagSupport;
14  
15  import org.apache.log4j.Logger;
16  
17  import comum.util.Data;
18  
19  import ecar.dao.PopUpDao;
20  import ecar.pojo.PopupPpp;
21  import ecar.pojo.UsuarioUsu;
22  
23  /**
24   * @author felipe
25   * 
26   */
27  public class PopUpsTag extends TagSupport {
28  
29  	/**
30  	 * 
31  	 */
32  	private static final long serialVersionUID = 3920610661946783698L;
33  
34  	private Logger logger = Logger.getLogger(this.getClass());
35  
36  	private String pathEcar;
37  	
38  	/**
39  	 * Inicializa a montagem da tag para ser adicionada na tela de HTML.<br>
40  	 * 
41  	 * @author N/C
42  	 * @since N/C
43  	 * @version N/C
44  	 * @return int
45  	 * @throws JspException
46  	 */
47  	public int doStartTag() throws JspException {
48  		JspWriter writer = this.pageContext.getOut();
49  		
50  		try {
51  			
52  			List popUps = new PopUpDao(null).getPopUpsApresentadasNoDia(Data.getDataAtual());
53  			
54  			if("true".equals(this.pageContext.getRequest().getParameter("mostrarPopUps"))){
55  				Iterator it = popUps.iterator();
56  				while(it.hasNext()){
57  					PopupPpp pp = (PopupPpp) it.next();
58  					UsuarioUsu usuario = ((ecar.login.SegurancaECAR)this.pageContext.getSession().getAttribute("seguranca")).getUsuario();
59  					StringBuffer nomeCookie = new StringBuffer("popUp_").append(usuario.getCodUsu()).append("_").append(pp.getCodPpp());
60  					writer.println("<script>");
61  					writer.println("if(getCookie('" + nomeCookie + "') == null){");
62  					writer.println("abreJanela('" + getPathEcar() +  "/popUp/popUpAvisoPadrao.jsp?codPpp=" +  pp.getCodPpp() + "', " + pp.getJanelaLarguraPpp() + "," +  pp.getJanelaAlturaPpp() + ",'" + pp.getCodPpp() + "');");
63  					if(pp.getPopupComportamentoPppc().getCodPppc().intValue() == PopUpDao.POPUP_COMPORTAMENTO_ABRIR_SOMENTE_UMA_VEZ){
64  						writer.println("setCookie('" + nomeCookie + "','1',null,'" + this.pathEcar + "',null,null);");						
65  					}
66  					writer.println("}");
67  					writer.println("</script>");
68  				}			
69  			}
70  			
71  		} catch (Exception e) {
72  			logger.error(e);
73  		}
74  		/* nao processa o conteudo do corpo da tag, porque nao existe */
75  		return Tag.SKIP_BODY;
76  	}
77  
78  	/**
79  	 * Encerra Tag.<br>
80  	 * 
81  	 * @author N/C
82  	 * @since N/C
83  	 * @version N/C
84  	 * @return int
85  	 * @throws JspException
86  	 */
87  	public int doEndTag() throws JspException {
88  	    /* processa o restante da página jsp */
89  		return Tag.EVAL_PAGE;
90  	}
91  
92  	/**
93  	 * Retorna String pathEcar.<br>
94  	 * 
95  	 * @author N/C
96  	 * @since N/C
97  	 * @version N/C
98  	 * @return String - (Returns the pathEcar)
99  	 */
100 	public String getPathEcar() {
101 		return pathEcar;
102 	}
103 	
104 	/**
105 	 * Atribui valor especificado para String pathEcar.<br>
106 	 * 
107 	 * @author N/C
108 	 * @since N/C
109 	 * @version N/C
110 	 * @param String pathEcar - (The pathEcar to set)
111 	 */
112 	public void setPathEcar(String pathEcar) {
113 		this.pathEcar = pathEcar;
114 	}
115 }