Source code: kelp/wireless/presentation/WelcomeServlet.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22 package kelp.wireless.presentation;
23
24 // Xerces imports
25 import org.w3c.dom.Element;
26
27 // Servlet imports
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletOutputStream;
30 import javax.servlet.http.HttpServlet;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33
34 // Standard imports
35 import java.io.IOException;
36 import java.io.PrintWriter;
37
38 //
39 public class WelcomeServlet extends HttpServlet {
40 public void doGet(HttpServletRequest request,
41 HttpServletResponse response) throws ServletException,
42 IOException {
43 ServletOutputStream out;
44 WelcomeWML welcome;
45 byte[] buffer;
46
47 welcome = createWelcomePage(request);
48 buffer = welcome.toDocument().getBytes();
49 response.setContentType("text/vnd.wap.wml");
50 response.setContentLength(buffer.length);
51 out = response.getOutputStream();
52 out.write(buffer);
53 out.flush();
54 }
55
56 private WelcomeWML createWelcomePage(HttpServletRequest request) {
57 WelcomeWML welcome = new WelcomeWML();
58 Element element = welcome.getElementGreeting();
59 String lang = "EN";
60
61 lang = request.getParameter("lang");
62 String greeting = "Hello";
63
64 if (lang == null) {
65
66 // keep default
67 } else if (lang.equalsIgnoreCase("HI")) {
68 greeting = "Aloha";
69 } else if (lang.equalsIgnoreCase("FR")) {
70 greeting = "Bon Jour";
71 }
72 element.getFirstChild().setNodeValue(greeting);
73 return welcome;
74 }
75
76 }