View Javadoc

1   /*
2    * Copyright 2007 The International Moth Class Association (IMCA)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.imca.web;
17  
18  import java.io.IOException;
19  import java.io.PrintWriter;
20  import java.lang.reflect.InvocationTargetException;
21  import java.lang.reflect.Method;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Enumeration;
25  import java.util.Hashtable;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  import javax.servlet.http.HttpServlet;
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  import javax.servlet.jsp.JspException;
33  
34  import net.sf.imca.model.PersonBO;
35  import net.sf.imca.model.entities.PersonEntity;
36  import net.sf.imca.services.EditDataService;
37  import net.sf.imca.services.ReflectionUtil;
38  import net.sf.imca.web.backingbeans.Utils;
39  
40  /**
41   * This is an old school style Servlet that allows simple access to the data 
42   * for administration.  It dynamically generates a form for entity classes.
43   *
44   * @author dougculnane
45   */
46  public class RidersDataServlet extends HttpServlet {
47  
48      /**
49       * Servlet implementation of HTTP get.
50       */
51      public void doGet(HttpServletRequest req, HttpServletResponse res) {
52          
53          try {
54          res.setContentType("text/xml");
55          res.setCharacterEncoding("UTF-8");
56          res.getWriter().write("<?xml version= \"1.0\" encoding=\"UTF-8\"?>\n" +
57                      "<?xml-stylesheet type=\"text/xsl\" href=\"/inc/riders.xsl\"?>\n" +
58                      "<riders>\n");
59              
60              EditDataService service = new EditDataService();
61              
62              List<PersonEntity> list = service.search("Person", "");
63              
64              
65              for (int i=0; i < list.size(); i++) {
66                  PersonBO person = new PersonBO(list.get(i));
67                 
68                  res.getWriter().write("<rider>\n" +
69                              "\t<id>" + person.getXmlId() + "</id>\n" +
70                  "\t<name>" + person.getName() + "</name>\n" +
71                  "\t<url>" + person.getEntity().getUrl() + "</url>\n" +
72                  "\t<address>\n" +
73                      "\t\t<street1>" + person.getEntity().getAddress().getStreet1() + "</street1>\n" +
74                      "\t\t<street2>" + person.getEntity().getAddress().getStreet2() + "</street2>\n" +
75                      "\t\t<city>" + person.getEntity().getAddress().getCity() + "</city>\n" +
76                      "\t\t<postcode>" + person.getEntity().getAddress().getPostCode() + "</postcode>\n" +
77                      "\t\t<country>" + person.getCountry() + "</country>\n" +
78                  "\t</address>\n");
79                  
80                  String email = person.getEntity().getEmail();
81                  int atPos = email.indexOf("@");
82                  if (atPos >0) {
83                      res.getWriter().write("\t<email>\n" +
84                              "\t\t<username>" + email.substring(0, atPos) + "</username>\n" +
85                              "\t\t<domain>" + email.substring(atPos + 1) + "</domain>\n" +
86                             "\t</email>\n");
87                  }
88              res.getWriter().write("\t<mobile>" + person.getEntity().getMobile() + "</mobile>\n" +
89                  "\t<tel>" + person.getEntity().getTel() + "</tel>\n" +
90                  "\t<club>" + person.getEntity().getClub() + "</club>\n" +
91                  "\t<landcode>" + person.getEntity().getAddress().getCountryCode().toLowerCase() + "</landcode>\n" +
92                  "</rider>\n");
93                  
94              }
95              res.getWriter().write("</riders>\n");
96          }catch (IOException ioe) {
97          
98          }
99                  
100     }
101 
102 }