Coverage Report - org.melati.test.CharsetServletTest
 
Classes in this File Line Coverage Branch Coverage Complexity
CharsetServletTest
100%
38/38
100%
2/2
2
 
 1  
 /*
 2  
  * $Source: /usr/cvsroot/melati/melati/src/site/resources/withWebmacro/org.melati.test.CharsetServletTest.html,v $
 3  
  * $Revision: 1.1 $
 4  
  *
 5  
  * Copyright (C) 2003 Jim Wright
 6  
  *
 7  
  * Part of Melati (http://melati.org), a framework for the rapid
 8  
  * development of clean, maintainable web applications.
 9  
  *
 10  
  * Melati is free software; Permission is granted to copy, distribute
 11  
  * and/or modify this software under the terms either:
 12  
  *
 13  
  * a) the GNU General Public License as published by the Free Software
 14  
  *    Foundation; either version 2 of the License, or (at your option)
 15  
  *    any later version,
 16  
  *
 17  
  *    or
 18  
  *
 19  
  * b) any version of the Melati Software License, as published
 20  
  *    at http://melati.org
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License and
 23  
  * the Melati Software License along with this program;
 24  
  * if not, write to the Free Software Foundation, Inc.,
 25  
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
 26  
  * GNU General Public License and visit http://melati.org to obtain the
 27  
  * Melati Software License.
 28  
  *
 29  
  * Feel free to contact the Developers of Melati (http://melati.org),
 30  
  * if you would like to work out a different arrangement than the options
 31  
  * outlined here.  It is our intention to allow Melati to be used by as
 32  
  * wide an audience as possible.
 33  
  *
 34  
  * This program is distributed in the hope that it will be useful,
 35  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 36  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 37  
  * GNU General Public License for more details.
 38  
  *
 39  
  * Contact details for copyright holder:
 40  
  *
 41  
  *     Jim Wright <jimw At paneris.org>
 42  
  *     Bohemian Enterprise
 43  
  *     Predmerice nad Jizerou 77
 44  
  *     294 74
 45  
  *     Mlada Boleslav
 46  
  *     Czech Republic
 47  
  */
 48  
 
 49  
 package org.melati.test;
 50  
 
 51  
 import java.io.IOException;
 52  
 import java.io.PrintWriter;
 53  
 import java.util.Iterator;
 54  
 
 55  
 import javax.servlet.ServletException;
 56  
 
 57  
 import org.melati.servlet.ConfigServlet;
 58  
 import org.melati.Melati;
 59  
 
 60  
 /**
 61  
  * Test display of various characters without using a Template Engine.
 62  
  */
 63  2
 public class CharsetServletTest extends ConfigServlet {
 64  
   private static final long serialVersionUID = 1L;
 65  
 
 66  
   protected void doConfiguredRequest(Melati melati)
 67  
       throws ServletException, IOException {
 68  
 
 69  2
     melati.setResponseContentType("text/html");
 70  2
     PrintWriter w = new PrintWriter(melati.getWriter());
 71  2
     String charset = melati.getResponse().getCharacterEncoding();
 72  
 
 73  2
     w.println("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>");
 74  2
     w.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"");
 75  2
     w.println("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
 76  2
     w.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
 77  2
     w.println("<head>");
 78  2
     w.println("<title>" + getServletName() + "</title>");
 79  2
     w.println("</head>");
 80  2
     w.println("<body>");
 81  2
     w.println("<h1>Characters Displayed in a Servlet</h1>");
 82  2
     w.println("<p>Based on available configuration information Melati" +
 83  
               " has suggested the response encoding " + charset +
 84  
               " and we are using it for this test.</p>");
 85  2
     w.println("<p>The test data originally comes from the Unicode Database.");
 86  2
     w.println("If you are viewing it online then for copyright information ");
 87  2
     w.println("and UCD Terms click here: ");
 88  2
     w.println("<a href=\"http://www.unicode.org/unicode/copyright.html\">");
 89  2
     w.println("http://www.unicode.org/unicode/copyright.html</a>.");
 90  2
     w.println("Offline please refer to the Javadocs.</p>");
 91  2
     w.println("<table border=\"1\">");
 92  2
     w.println("<thead><tr><th>Description</th><th>Character Reference</th>" +
 93  
               "<th>Character</th><th>Entitied</th><th>Encoding Test</th></tr></thead>");
 94  2
     w.println("<tbody>");
 95  2
     for (Iterator i = CharData.getItems(); i.hasNext();) {
 96  1848
       CharData.Item cd = (CharData.Item)i.next();
 97  1848
       w.println("<tr>");
 98  1848
       w.println("<td>" + cd.getDescription() + "</td>");
 99  1848
       w.println("<td>" + cd.getReference() + "</td>");
 100  1848
       w.println("<td>" + cd.getChar() + "</td>");
 101  1848
       w.println("<td>" + melati.getMarkupLanguage().rendered(
 102  
                   cd.getChar()) + "</td>");
 103  1848
       w.println("<td>" + cd.encodingTest(melati) + "</td>");
 104  1848
       w.println("</tr>");
 105  1848
     }
 106  2
     w.println("</tbody>");
 107  2
     w.println("</table>");
 108  2
     w.println("</body>");
 109  2
     w.println("</html>");
 110  2
   }
 111  
 
 112  
   
 113  
 }