Source code: com/openwave/oui/waomelements/Format.java
1 package com.openwave.oui.waomelements;
2 import com.sun.java.util.collections.*;
3 import com.openwave.oui.framework.*;
4 /**
5 * The Format object is intended to overcome several differences in the support of input masks
6 * (AKA formats or input formats) in handsets by different vendors.<br/>
7 * Formats are very useful for guiding users typing text into an input field.
8 * When properly deployed, formats save users from excessive typing and, to an extent, validates
9 * the data before they are sent to the server.<br/>
10 * In short, formats are extremely important for usability. Unfortunately, there are differences
11 * in the support of format by the different handsets that often force developers to renounce input masks.<br/>
12 * In this context, the Format object lets developers exploit input masks in the best possible way on each phone. <br/>
13 * Just to give you an example, A mask of - let's say \+\4\4\ *N will, on the UP.Browser display +44
14 * and enter number mode. On a Nokia phone it will do nothing, and the user can enter anything.<br/>
15 * However, what the user types won't be accepted unless it matches the format exactly.
16 * Furthermore, Nokia 7110 phones won't go into number mode when an input mask like the one above is used,
17 * since the format includes non-numerical characters (such as a space and a plus sign).<br/>
18 * If the user enters +44 1638508520 then that would be OK. If they entered +441638508520 it wouldn't
19 * (missing the space) etc. The only workaround in generic WML is to accept anything, and rely on client-side
20 * (WMLScript) or server side checking. This is not a good option.<br/>
21 * If you want to exploit input masks in your application, while avoiding the need to branch your code,
22 * the Format object offers a solution in a specific (but common) case.<br/>
23 * If your format is composed by:<br/>
24 * <ul>
25 * <li>anything static (es: "+44 ") (the prefix)</li>
26 * <li>followed by a snippet of text that users are supposed to insert (es: 10 digits)</li>
27 * </ul>
28 * The Format object lets you specify the different parts of your input form and will build the most
29 * usable solution for you.<br/>
30 * The Format object will build an extra format attribute for the UP.Browser that is given by
31 * concatenating the format for the static part with the format provided by the developer.<br/>
32 * Creation date: (4/5/2001 10:08:44 AM)
33 * @author: Lars Gunder Knudsen
34 */
35 public class Format extends WaomLeaf {
36
37 private String staticText = null;
38 private String fullVarName = null;
39 private String dynVarName = null;
40 private String formatting = null;
41
42 private String upguiPicURL = null;
43 private final static long serialVersionUID = -7942254587760885358L;
44
45 /**
46 * Format constructor.
47 * @param format_prefix The static part of the mask expression.
48 * @param varname the variablename which will contain the value entered by the user on UP.Browser (not Nokia).
49 * @param backup_varname the variable name that is employed to support the well-behaved input format for the Nokia.
50 * @param format_string a string that expresses the dynamic part of the format. The format here should be simple and supported correctly by the Nokia (typically digits).
51 *
52 */
53 public Format(
54 String format_prefix,
55 String varname,
56 String backup_varname,
57 String format_string) {
58 super();
59 this.staticText = format_prefix;
60 this.fullVarName = varname;
61 this.dynVarName = backup_varname;
62 this.formatting = format_string;
63 //waomElementName = "Format";
64 setWaomElementName("Format");
65 }
66
67
68 /**
69 * Insert the method's description here.
70 * Creation date: (4/5/2001 10:33:38 AM)
71 */
72 public String getContentExpression() {
73 return "$"+this.fullVarName;
74 }
75
76
77 /**
78 * Insert the method's description here.
79 * Creation date: (4/5/2001 10:33:38 AM)
80 */
81 public String getDynVarName() {
82 return this.dynVarName;
83 }
84
85
86 /**
87 * Insert the method's description here.
88 * Creation date: (4/5/2001 10:33:38 AM)
89 */
90 public String getFormatting() {
91 return this.formatting;
92 }
93
94
95 /**
96 * Insert the method's description here.
97 * Creation date: (4/5/2001 10:33:38 AM)
98 */
99 public String getFullVarName() {
100 return this.fullVarName;
101 }
102
103
104 /**
105 * @return a string which represents the WML variable or expression representing the complete value (prevents modifications on the back-end). The expression is equivalent to: {prefix}$(backupvarname)
106 *
107 */
108 public String getNokiaContentExpression() {
109 return this.staticText + "$" + this.dynVarName;
110 }
111
112
113 /**
114 * Insert the method's description here.
115 * Creation date: (4/5/2001 10:33:38 AM)
116 */
117 public String getStaticText() {
118 return this.staticText;
119 }
120
121
122 public boolean isWidget(){
123 return true;
124 }
125
126
127 /**
128 * Insert the method's description here.
129 * Creation date: (4/5/2001 10:33:38 AM)
130 */
131 public void setDynVarName(String dynVarName) {
132 this.dynVarName = dynVarName;
133 }
134
135
136 /**
137 * Insert the method's description here.
138 * Creation date: (4/5/2001 10:33:38 AM)
139 */
140 public void setFormatting(String formatting) {
141 this.formatting = formatting;
142 }
143
144
145 /**
146 * Insert the method's description here.
147 * Creation date: (4/5/2001 10:33:38 AM)
148 */
149 public void setFullVarName(String fullVarName) {
150 this.fullVarName = fullVarName;
151 }
152
153
154 /**
155 * Insert the method's description here.
156 * Creation date: (4/5/2001 10:33:38 AM)
157 */
158 public void setStaticText(String staticText) {
159 this.staticText = staticText;
160 }
161
162
163 public void visit(WaomVisitor wv){
164 wv.visit(this);
165 }
166 }