View Javadoc

1   package net.sf.imca.taglibs;
2   
3   import java.util.Locale;
4   
5   import javax.servlet.jsp.JspException;
6   import javax.servlet.jsp.JspTagException;
7   
8   import net.sf.imca.model.PersonBO;
9   import net.sf.imca.model.entities.CommitteeMemberEntity;
10  import net.sf.imca.services.CommitteeService;
11  
12  public class ImcaNationalCommittee extends javax.servlet.jsp.tagext.TagSupport {
13  
14      /**
15       * Generated serialVersionUID
16       */
17      private static final long serialVersionUID = 8944804977828774091L;
18  
19      private String countryCode = "";
20  
21      private String area = "";
22  
23      int count = 0;
24  
25      CommitteeMemberEntity[] committee;
26  
27      public int doStartTag() throws JspException {
28  
29          String parameterCountryCode = this.pageContext.getRequest()
30                  .getParameter("countrycode");
31          if (parameterCountryCode != null) {
32              countryCode = parameterCountryCode;
33          }
34  
35          String parameterArea = this.pageContext.getRequest().getParameter(
36                  "area");
37          if (parameterArea != null) {
38              area = parameterArea;
39          }
40          
41          CommitteeService service = new CommitteeService();
42          committee = service.getAssociationCommittee(countryCode, area);
43  
44          if (committee == null) {
45              return SKIP_BODY;
46          }
47          
48          count = 0;
49          if (committee.length > 0) {
50              setPageAttributes();
51              return EVAL_BODY_INCLUDE;
52          } else {
53              return SKIP_BODY;
54          }
55      }
56  
57      public int doAfterBody() throws JspTagException {
58  
59          // set page Attributes
60          count++;
61          if (count < committee.length) {
62              setPageAttributes();
63              return EVAL_BODY_AGAIN;
64          } else {
65              return SKIP_BODY;
66          }
67      }
68  
69      private void setPageAttributes() {
70          
71          PersonBO personBO = new PersonBO(committee[count].getPerson());
72          
73          pageContext.setAttribute("position", committee[count].getPositionName());
74          pageContext.setAttribute("name", personBO.getName());
75          pageContext.setAttribute("addressHtml", personBO.getAddressHtml());
76          pageContext.setAttribute("smallPictureUrl", personBO.getSmallPictureUrl());
77          
78          pageContext.setAttribute("tel", committee[count].getPerson().getTel());
79          pageContext.setAttribute("mobile", committee[count].getPerson()
80                  .getMobile());
81          String email = committee[count].getPerson().getEmail();
82          int atPos = email.indexOf("@");
83          if (atPos > 0) {
84              pageContext.setAttribute("email_username", email.substring(0, email
85                      .indexOf("@")));
86              pageContext.setAttribute("email_domain", email.substring(email
87                      .indexOf("@") + 1));
88          } else {
89              pageContext.setAttribute("email_username", "");
90              pageContext.setAttribute("email_domain", "");
91          }
92      }
93  
94      public String getArea() {
95          return area;
96      }
97  
98      public void setArea(String area) {
99          this.area = area;
100     }
101 
102     public String getCountryCode() {
103         return countryCode;
104     }
105 
106     public void setCountryCode(String countryCode) {
107         this.countryCode = countryCode;
108     }
109 
110 }