01: /*
02: * calculator
03: *
04: * Enhydra super-servlet specification object
05: *
06: */
07:
08: package calculator.business;
09:
10: import calculator.spec.State;
11:
12: // Enhydra SuperServlet imports
13: import com.lutris.util.KeywordValueException;
14: import com.lutris.appserver.server.session.*;
15:
16: public class StateImpl implements State {
17: //DigitsChack
18: public String checkDigits(SessionData sd)
19: throws KeywordValueException {
20: String digits = (String) sd.get("digits");
21:
22: if (digits == null)
23: digits = "0";
24:
25: // If it's an integer, don't show the decimal point.
26: if (digits.endsWith(".0"))
27: digits = digits.substring(0, digits.length() - 2);
28:
29: // If it's too long to show, trim it or just show 0.
30: // An error indication would be nice to add (hint hint... :)
31:
32: if (digits.indexOf(".") != -1) {
33: if (digits.length() > 6) {
34: digits = digits.substring(0, 7);
35:
36: int dot = digits.indexOf(".");
37:
38: if (dot == 6)
39: digits = digits.substring(0, 6);
40:
41: }
42: } else {
43: if (digits.length() > 7)
44: digits = "0"; // Overflow.
45: }
46:
47: return digits;
48: }
49:
50: public String convertDigitsToHTML(String digits) {
51: // Convert the string of digits to HTML.
52: String digitHtml = "";
53: for (int i = 0; i < digits.length(); i++) {
54: char c = digits.charAt(i);
55: if (c == '0')
56: digitHtml += "<img src=media/zero.jpeg>";
57: else if (c == '1')
58: digitHtml += "<img src=media/one.jpeg>";
59: else if (c == '2')
60: digitHtml += "<img src=media/two.jpeg>";
61: else if (c == '3')
62: digitHtml += "<img src=media/three.jpeg>";
63: else if (c == '4')
64: digitHtml += "<img src=media/four.jpeg>";
65: else if (c == '5')
66: digitHtml += "<img src=media/five.jpeg>";
67: else if (c == '6')
68: digitHtml += "<img src=media/six.jpeg>";
69: else if (c == '7')
70: digitHtml += "<img src=media/seven.jpeg>";
71: else if (c == '8')
72: digitHtml += "<img src=media/eight.jpeg>";
73: else if (c == '9')
74: digitHtml += "<img src=media/nine.jpeg>";
75: else if (c == '-')
76: digitHtml += "<img src=media/dash.jpeg>";
77: else if (c == '.')
78: digitHtml += "<img src=media/point.jpeg>";
79: }
80: if (digitHtml.length() == 0)
81: digitHtml = "<img src=media/zero.jpeg>";
82:
83: return digitHtml;
84: }
85:
86: }
|