1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.util.*; 22 import javax.servlet.*; 23 import javax.servlet.http.*; 24 25 33 34 public class GetLocales02 extends HttpServlet { 35 36 37 public void doGet(HttpServletRequest request, HttpServletResponse response) 38 throws IOException, ServletException { 39 40 response.reset(); 41 response.setContentType("text/plain"); 42 PrintWriter writer = response.getWriter(); 43 StringBuffer sb = new StringBuffer (); 44 boolean ok = true; 45 46 Enumeration locales = request.getLocales(); 47 if (locales == null) { 48 sb.append(" No locales returned/"); 49 ok = false; 50 } 51 52 if (ok) { 53 if (locales.hasMoreElements()) { 54 Locale expected = new Locale("en", "CA"); 55 Locale received = (Locale) locales.nextElement(); 56 if (!expected.equals(received)) { 57 sb.append(" Expected1='" + 58 expected.toString() + "' Received1='" + 59 received.toString() + "'"); 60 } 61 } else { 62 sb.append(" Zero locales returned/"); 63 ok = false; 64 } 65 } 66 67 if (ok) { 68 if (locales.hasMoreElements()) { 69 Locale expected = new Locale("en", "GB"); 70 Locale received = (Locale) locales.nextElement(); 71 if (!expected.equals(received)) { 72 sb.append(" Expected2='" + 73 expected.toString() + "' Received2='" + 74 received.toString() + "'"); 75 } 76 } else { 77 sb.append(" One locale returned/"); 78 ok = false; 79 } 80 } 81 82 if (ok) { 83 if (locales.hasMoreElements()) { 84 sb.append(" More than two locales returned/"); 85 ok = false; 86 } 87 } 88 89 if (ok && (sb.length() < 1)) { 90 writer.println("GetLocales02 PASSED"); 91 } else { 92 writer.print("GetLocales02 FAILED -"); 93 writer.println(sb.toString()); 94 } 95 96 97 while (true) { 98 String message = StaticLogger.read(); 99 if (message == null) 100 break; 101 writer.println(message); 102 } 103 StaticLogger.reset(); 104 105 } 106 107 108 } 109 | Popular Tags |