1 package net.sf.imca.taglibs;
2
3 import java.util.List;
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.PersonEntity;
10 import net.sf.imca.services.EditDataService;
11
12 public class Riders extends javax.servlet.jsp.tagext.TagSupport {
13
14
15
16
17
18 private static final long serialVersionUID = 8944804977828774091L;
19
20 int count = 0;
21
22
23 PersonBO[] persons;
24
25 public int doStartTag() throws JspException {
26
27 EditDataService service = new EditDataService();
28
29 List<PersonEntity> list = service.search("Person", "");
30
31 persons = new PersonBO[list.size()];
32
33 for (int i=0; i < persons.length; i++) {
34 persons[i] = new PersonBO(list.get(i));
35 }
36 count = 0;
37
38 if ( persons.length > 0 ) {
39 setPageAttributes();
40 return EVAL_BODY_INCLUDE;
41 } else {
42 return SKIP_BODY;
43 }
44 }
45
46 public int doAfterBody() throws JspTagException {
47
48
49 count++;
50 if (count < persons.length) {
51 setPageAttributes();
52 return EVAL_BODY_AGAIN;
53 } else {
54 return SKIP_BODY;
55 }
56 }
57
58 private void setPageAttributes() {
59
60 pageContext.setAttribute("xmlId", persons[count].getXmlId());
61 pageContext.setAttribute("name", persons[count].getName());
62 pageContext.setAttribute("url", persons[count].getEntity().getUrl());
63 pageContext.setAttribute("street1", persons[count].getEntity().getAddress().getStreet1());
64 pageContext.setAttribute("street2", persons[count].getEntity().getAddress().getStreet2());
65 pageContext.setAttribute("city", persons[count].getEntity().getAddress().getCity());
66 pageContext.setAttribute("postcode", persons[count].getEntity().getAddress().getPostCode());
67 pageContext.setAttribute("country", persons[count].getCountry());
68
69 String email = persons[count].getEntity().getEmail();
70 int atPos = email.indexOf("@");
71 if (atPos > 0) {
72 pageContext.setAttribute("email_username", email.substring(0, email
73 .indexOf("@")));
74 pageContext.setAttribute("email_domain", email.substring(email
75 .indexOf("@") + 1));
76 } else {
77 pageContext.setAttribute("email_username", "");
78 pageContext.setAttribute("email_domain", "");
79 }
80
81 pageContext.setAttribute("tel", persons[count].getEntity().getTel());
82 pageContext.setAttribute("mobile", persons[count].getEntity().getMobile());
83 pageContext.setAttribute("club", persons[count].getEntity().getClub());
84 pageContext.setAttribute("countryCode", persons[count].getEntity().getAddress().getCountryCode());
85
86 }
87
88
89 }