View Javadoc
1   package uk.ac.ebi.intenz.webapp.controller;
2   
3   import java.io.IOException;
4   
5   import javax.servlet.ServletException;
6   
7   import uk.ac.ebi.xchars.SpecialCharacters;
8   
9   /**
10   * This class provides methods to switch between a pure Unicode based special character
11   * representation and a browser dependent non-pure Unicode encoding.
12   *
13   * @author Michael Darsow
14   * @version 0.9 - 21-July-2003
15   */
16  public class ChangeCharacterRepresentationCommand extends NonDatabaseCommand {
17  
18    /**
19     * Depending on the given parameter this method switches between a Unicode representation for some
20     * <i>very</i> special characters (scissile, activated, ...) and a browser-dependent encoding.
21     * <p/>
22     * This class makes use of the Special Characters API, which allows to define a representation for
23     * special characters in different ways. See documentation (TODO: Insert link here).
24     *
25     * @throws ServletException
26     * @throws IOException
27     */
28    public void process() throws ServletException, IOException {
29      boolean unicodeOnly = request.getParameter("uo").equals("true");
30  
31  //    SpecialCharacters specialCharacters = (SpecialCharacters) request.getSession().getServletContext().getAttribute(
32  //            "characters");
33  //    SpecialCharacters specialCharactersCopy = SpecialCharacters.copy(specialCharacters);
34  
35  //    if (unicodeOnly) { // Use default setting (which is mainly Unicode).
36  //      specialCharactersCopy.setMappingIdentifier(null);
37  //      request.getSession().setAttribute("uo", "true");
38  //    } else {
39  //      specialCharactersCopy.setMappingIdentifier("defaultAlt");
40  //      request.getSession().setAttribute("uo", "false");
41  //    }
42  
43      request.setAttribute("info", getInfo(unicodeOnly));
44      forward("/info.jsp");
45    }
46  
47    /**
48     * Returns the content for the info page.
49     *
50     * @param unicodeOnly Use default encoding if set to <code>true</code>.
51     * @return the HTML info.
52     */
53    private String getInfo(boolean unicodeOnly) {
54      StringBuffer info = new StringBuffer();
55  
56      info.append("<form action=\"query?cmd=ChangeCharacterRepresentation\" method=\"post\">");
57      info.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
58      info.append("  <tr>\n");
59  
60      if (!unicodeOnly) {
61        info.append("    <td>You have switched to individual encoding (browser-dependent and font-independent) of " +
62                    "special characters. Some characters may now be displayed as images, depending on the browser version " +
63                    "you use. If you want to use the default encoding again, press the button below this text.</td></tr>\n");
64        info.append("<tr><td>&nbsp;</td></tr>\n");
65        info.append("      <tr><td align=\"center\"><input type=\"submit\" value=\"Switch to default encoding\">\n" +
66                    "      <input type=\"hidden\" name=\"uo\" value=\"true\"></td>\n");
67      } else {
68        info.append("    <td>You have switched to the default encoding for special characters. The default encoding uses " +
69                    "Unicode to display special characters and works best with current browser versions. Please check if you " +
70                    "have a Unicode font installed and if you can see all " +
71                    "<a href=\"javascript:windowOpenWithSize('encoding.html', 280, 400)\">special characters</a> used within " +
72                    "IntEnz. If you cannot see all characters or if you are not happy with the representation then press the " +
73                    "button below to enable individual encoding (browser-dependent and font-independent).</td></tr>\n");
74        info.append("<tr><td>&nbsp;</td></tr>\n");
75        info.append("      <tr><td align=\"center\"><input type=\"submit\" value=\"Switch to individual encoding\">\n" +
76                    "      <input type=\"hidden\" name=\"uo\" value=\"false\"></td>\n");
77      }
78  
79      info.append("  </tr>");
80      info.append("</table>");
81      info.append("</form>");
82      return info.toString();
83    }
84  
85  }