Source Code Cross Referenced for HtmlSSNComponent.java in  » J2EE » Sofia » com » salmonllc » html » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.html;
002:
003:        /////////////////////////
004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlSSNComponent.java $
005:        //$Author: Dan $
006:        //$Revision: 18 $
007:        //$Modtime: 10/20/03 3:44p $
008:        /////////////////////////
009:
010:        import java.util.Hashtable;
011:
012:        import com.salmonllc.html.events.ValueChangedEvent;
013:        import com.salmonllc.properties.Props;
014:
015:        /**
016:         * Implements a three-part entry field for a social security number.
017:         */
018:        public class HtmlSSNComponent extends HtmlFormComponent {
019:            protected HtmlTextEdit _hteSSPart1, _hteSSPart2, _hteSSPart3;
020:
021:            protected HtmlContainer _cont;
022:
023:            public HtmlComponent _hcFocusComp;
024:
025:            public String _sSSN, _sSeparator;
026:            private HtmlText _htSeparator1;
027:            private HtmlText _htSeparator2;
028:
029:            private String _sPart1, _sPart2, _sPart3;
030:
031:            private final int iLength1 = 3;
032:            private final int iLength2 = 2;
033:            private final int iLength3 = 4;
034:
035:            private String _font;
036:            private String _fontStartTag;
037:            private String _fontEndTag;
038:
039:            /**
040:             * HtmlSSNComponent constructor comment.
041:             *
042:             * @param name		Name of component.
043:             * @param p			Page containing component.
044:             */
045:            public HtmlSSNComponent(String name, HtmlPage p) {
046:                this (name, p, "-");
047:            }
048:
049:            /**
050:             * HtmlSSNComponent constructor comment.
051:             *
052:             * @param name		Name of component.
053:             * @param p			Page containing component.
054:             * @param separator	Character to display between the three part of the Social Security Number
055:             */
056:            public HtmlSSNComponent(String name, HtmlPage p, String separator) {
057:                this (name, p, "-", true);
058:            }
059:
060:            /**
061:             * HtmlSSNComponent constructor comment.
062:             *
063:             * @param name			Name of component.
064:             * @param p				Page containing component.
065:             * @param separator		Character to display between the three part of the Social Security Number
066:             * @param bEnableFlag	Flag to set the component to editable (true) or read only (false)
067:             */
068:            public HtmlSSNComponent(String name, HtmlPage p, String separator,
069:                    boolean bEnableFlag) {
070:                super (name, p);
071:                _cont = new HtmlContainer(name, p);
072:                _sSeparator = separator;
073:
074:                _cont.add(_hteSSPart1 = new HtmlTextEdit("SSPart1", p));
075:
076:                _hteSSPart1.setGenerateNewline(false);
077:                _hteSSPart1.setSize(iLength1);
078:                _hteSSPart1.setMaxLength(iLength1);
079:
080:                if (_sSeparator != null && !_sSeparator.trim().equals(""))
081:                    _cont.add(_htSeparator1 = new HtmlText(_sSeparator,
082:                            getPage()));
083:
084:                _cont.add(_hteSSPart2 = new HtmlTextEdit("SSPart2", p));
085:                _hteSSPart2.setGenerateNewline(false);
086:                _hteSSPart2.setSize(iLength2);
087:                _hteSSPart2.setMaxLength(iLength2);
088:
089:                if (_sSeparator != null && !_sSeparator.trim().equals(""))
090:                    _cont.add(_htSeparator2 = new HtmlText(_sSeparator,
091:                            getPage()));
092:
093:                _cont.add(_hteSSPart3 = new HtmlTextEdit("SSPart3", p));
094:
095:                _hteSSPart3.setGenerateNewline(false);
096:                _hteSSPart3.setSize(iLength3);
097:                _hteSSPart3.setMaxLength(iLength3);
098:
099:                setEnabled(bEnableFlag);
100:            }
101:
102:            /**
103:             * HtmlSSNComponent constructor comment.
104:             *
105:             * @param name			Name of component.
106:             * @param p				Page containing component.
107:             * @param bEnableFlag	Flag to set the component to editable (true) or read only (false)
108:             */
109:            public HtmlSSNComponent(String name, HtmlPage p, boolean bEnableFlag) {
110:                this (name, p, "-", bEnableFlag);
111:            }
112:
113:            public void generateHTML(java.io.PrintWriter p, int row)
114:                    throws Exception {
115:                // It is essential to call getValue() here because there may be a ValueChanged
116:                // event in the queue for this object, which needs to be removed, which getValue()
117:                // does.  The secondary calls to getValue() from the container will not
118:                // do this because there are no events associated with them.
119:                String val = getValue(row, true);
120:
121:                if (val == null || val.trim().equals("")) {
122:                    _hteSSPart1.setValue(null, row);
123:                    _hteSSPart2.setValue(null, row);
124:                    _hteSSPart3.setValue(null, row);
125:                } else {
126:                    String sVal;
127:
128:                    if (_dsBuff != null) {
129:                        if (row >= 0)
130:                            sVal = _dsBuff.getString(row, _dsColNo);
131:                        else
132:                            sVal = _dsBuff.getString(_dsColNo);
133:                    } else
134:                        sVal = val;
135:
136:                    if (sVal.length() == iLength1 + iLength2 + iLength3) {
137:                        _hteSSPart1.setValue(sVal.substring(0, 3), row);
138:                        _hteSSPart2.setValue(sVal.substring(3, 5), row);
139:                        _hteSSPart3.setValue(sVal.substring(5), row);
140:                    }
141:                }
142:
143:                _cont.generateHTML(p, row);
144:
145:                if (_visible && _enabled)
146:                    p.println("");
147:            }
148:
149:            /**
150:             * Returns the sub-component to be used for setting focus.
151:             * @return com.salmonllc.html.HtmlComponent
152:             */
153:            public HtmlComponent getFocusPart1() {
154:                return _hteSSPart1;
155:            }
156:
157:            /**
158:             * Returns the sub-component to be used for setting focus.
159:             * @return com.salmonllc.html.HtmlComponent
160:             */
161:            public HtmlComponent getFocusPart2() {
162:                return _hteSSPart2;
163:            }
164:
165:            /**
166:             * Returns the sub-component to be used for setting focus.
167:             * @return com.salmonllc.html.HtmlComponent
168:             */
169:            public HtmlComponent getFocusPart3() {
170:                return _hteSSPart3;
171:            }
172:
173:            /**
174:             * This method will return the font type used by this control.See the Constants at the top of the class for valid font types.
175:             */
176:            public String getFont() {
177:                return _font;
178:            }
179:
180:            /**
181:             * This method returns the formatted SSN provided that the component
182:             * contains a valid value otherwise it returns an empty string
183:             *
184:             * Date: 01/10/2001
185:             *
186:             * @return java.lang.String
187:             */
188:            public String getFormattedValue() {
189:                String sFormattedSSN = "";
190:
191:                if (isValid()) {
192:                    sFormattedSSN = _sPart1 + _sSeparator + _sPart2
193:                            + _sSeparator + _sPart3;
194:                }
195:                return sFormattedSSN;
196:            }
197:
198:            /**
199:             * Gets the separator char.
200:             * @return java.lang.String
201:             */
202:            public java.lang.String getSsnSeparator() {
203:                return _sSeparator;
204:            }
205:
206:            /**
207:             * This method returns the SSN provided that the component
208:             * contains a valid value otherwise it returns an empty string
209:             *
210:             * Date: 01/08/2001
211:             *
212:             * @return java.lang.String
213:             */
214:            public String getValue() {
215:                _sSSN = "";
216:
217:                if (isValid())
218:                    _sSSN = _sPart1 + _sPart2 + _sPart3;
219:
220:                return _sSSN;
221:            }
222:
223:            /**
224:             * Returns whether component is visible or not.
225:             * Creation date: (7/19/01 8:41:20 AM)
226:             * @return boolean Indicates if component is visible or not.
227:             */
228:            public boolean getVisible() {
229:                return _cont.getVisible();
230:            }
231:
232:            /**
233:             * Returns whether the SSN entered is valid or not.
234:             * @return boolean Indicates whether SSN is valid or not.
235:             */
236:            public boolean isValid() {
237:                boolean bNumeric = true;
238:
239:                boolean bNumeric1 = true;
240:                boolean bNumeric2 = true;
241:                boolean bNumeric3 = true;
242:
243:                String sPart1 = _sPart1;
244:                String sPart2 = _sPart2;
245:                String sPart3 = _sPart3;
246:
247:                _hteSSPart1.setValue(_sPart1);
248:                _hteSSPart2.setValue(_sPart2);
249:                _hteSSPart3.setValue(_sPart3);
250:
251:                // Validate part1 of the SSN - 3 characters
252:                int iValidLength = iLength1;
253:                int iSSNLength = sPart1.length();
254:
255:                if (iSSNLength != iValidLength) {
256:                    _hcFocusComp = getFocusPart1();
257:                    bNumeric1 = false;
258:                } else {
259:                    for (int i = 0; i < iSSNLength; i++) {
260:                        char c = sPart1.charAt(i);
261:
262:                        if (!Character.isDigit(c)) {
263:                            _hcFocusComp = getFocusPart1();
264:                            bNumeric1 = false;
265:                            break;
266:                        }
267:                    }
268:                }
269:
270:                // Validate part2 of the SSN - 2 characters
271:                iValidLength = iLength2;
272:                iSSNLength = sPart2.length();
273:
274:                if (iSSNLength != iValidLength) {
275:                    if (bNumeric1)
276:                        _hcFocusComp = getFocusPart2();
277:                    bNumeric2 = false;
278:                } else {
279:                    for (int i = 0; i < iSSNLength; i++) {
280:                        char c = sPart2.charAt(i);
281:
282:                        if (!Character.isDigit(c)) {
283:                            if (bNumeric1)
284:                                _hcFocusComp = getFocusPart2();
285:                            bNumeric2 = false;
286:                            break;
287:                        }
288:                    }
289:                }
290:
291:                // Validate part3 of the SSN - 4 characters
292:                iValidLength = iLength3;
293:                iSSNLength = sPart3.length();
294:
295:                if (iSSNLength != iValidLength) {
296:                    if (bNumeric1 && bNumeric2)
297:                        _hcFocusComp = getFocusPart3();
298:                    bNumeric3 = false;
299:                } else {
300:                    for (int i = 0; i < iSSNLength; i++) {
301:                        char c = sPart3.charAt(i);
302:
303:                        if (!Character.isDigit(c)) {
304:                            if (bNumeric1 && bNumeric2)
305:                                _hcFocusComp = getFocusPart3();
306:                            bNumeric3 = false;
307:                            break;
308:                        }
309:                    }
310:                }
311:
312:                bNumeric = bNumeric1 && bNumeric2 && bNumeric3;
313:
314:                return bNumeric;
315:            }
316:
317:            public boolean processParms(Hashtable htParms, int iRowNo)
318:                    throws Exception {
319:                if (!getVisible() || !getEnabled())
320:                    return false;
321:
322:                // Determine the old value from both edit fields.
323:
324:                String sOldValue;
325:
326:                if (_dsBuff == null) {
327:                    sOldValue = _hteSSPart1.getValue() + _hteSSPart2.getValue()
328:                            + _hteSSPart3.getValue();
329:                } else {
330:                    String s;
331:                    if (iRowNo > -1)
332:                        s = _dsBuff.getString(iRowNo, _dsColNo);
333:                    else
334:                        s = _dsBuff.getString(_dsColNo);
335:
336:                    sOldValue = (s != null) ? s : null;
337:
338:                    if (s == null)
339:                        sOldValue = null;
340:                    else
341:                        sOldValue = s;
342:                }
343:
344:                // Determine the new value from both edit fields.
345:
346:                String sNewValue;
347:
348:                String sName1 = _hteSSPart1.getFullName();
349:                if (iRowNo > -1)
350:                    sName1 += "_" + iRowNo;
351:
352:                String[] asValues = (String[]) htParms.get(sName1);
353:                if (asValues != null) {
354:                    _sPart1 = sNewValue = asValues[0].trim();
355:                    if (sNewValue.equals(""))
356:                        sNewValue = null;
357:                } else
358:                    sNewValue = null;
359:
360:                String sName2 = _hteSSPart2.getFullName();
361:
362:                if (iRowNo > -1)
363:                    sName2 += "_" + iRowNo;
364:
365:                asValues = (String[]) htParms.get(sName2);
366:
367:                if (asValues != null) {
368:                    String s = _sPart2 = asValues[0].trim();
369:
370:                    if (!s.equals("")) {
371:                        if (sNewValue == null)
372:                            sNewValue = "";
373:                        sNewValue += s;
374:                    }
375:                }
376:
377:                String sName3 = _hteSSPart3.getFullName();
378:
379:                if (iRowNo > -1)
380:                    sName3 += "_" + iRowNo;
381:
382:                asValues = (String[]) htParms.get(sName3);
383:
384:                if (asValues != null) {
385:                    String s = _sPart3 = asValues[0].trim();
386:
387:                    if (!s.equals("")) {
388:                        if (sNewValue == null)
389:                            sNewValue = "";
390:                        sNewValue += s;
391:                    }
392:                }
393:
394:                // Compare old and new values and possibly create a ValueChangedEvent.
395:                if (!valuesEqual(sOldValue, sNewValue)) {
396:                    ValueChangedEvent e = new ValueChangedEvent(getPage(),
397:                            this , getName(), getFullName(), sOldValue,
398:                            sNewValue, iRowNo, _dsColNo, _dsBuff);
399:                    addEvent(e);
400:                }
401:                return false;
402:            }
403:
404:            /**
405:             * This method will clear all pending events from the event queue for this component.
406:             */
407:            public void reset() {
408:                super .reset();
409:                _cont.reset();
410:            }
411:
412:            /**
413:             * Specifies the Style Class to be used for the SSN Component.
414:             * Creation date: (7/19/01 8:41:20 AM)
415:             * @param sClass java.lang.String A name of a class in Html to be used by this component
416:             */
417:            public void setClassName(String sClass) {
418:
419:                super .setClassName(sClass);
420:
421:                if (sClass != null) {
422:                    _hteSSPart1.setClassName(sClass);
423:                    _hteSSPart2.setClassName(sClass);
424:                    _hteSSPart3.setClassName(sClass);
425:                    _htSeparator1.setClassName(sClass);
426:                    _htSeparator2.setClassName(sClass);
427:                }
428:            }
429:
430:            /**
431:             * Sets the font end tag for disabled mode.
432:             * @param tag java.lang.String
433:             */
434:            public void setDisabledFontEndTag(String tag) {
435:
436:                _hteSSPart1.setDisabledFontEndTag(tag);
437:                _hteSSPart2.setDisabledFontEndTag(tag);
438:                _hteSSPart3.setDisabledFontEndTag(tag);
439:
440:                _htSeparator1.setFontEndTag(tag);
441:                _htSeparator2.setFontEndTag(tag);
442:            }
443:
444:            /**
445:             * Sets the font tag for disabled mode.
446:             * @param tag java.lang.String
447:             */
448:            public void setDisabledFontStartTag(String tag) {
449:
450:                _hteSSPart1.setDisabledFontStartTag(tag);
451:                _hteSSPart2.setDisabledFontStartTag(tag);
452:                _hteSSPart3.setDisabledFontStartTag(tag);
453:
454:                _htSeparator1.setFontStartTag(tag);
455:                _htSeparator2.setFontStartTag(tag);
456:            }
457:
458:            /**
459:             * Enables or disables the ability of this component to respond to user input.
460:             * @param editable boolean
461:             */
462:            public void setEnabled(boolean enabled) {
463:                super .setEnabled(enabled);
464:                _cont.setEnabled(enabled);
465:            }
466:
467:            /**
468:             * This method will load the font start and end tags from the page properties object.See the Constants at the top of the class for valid values to pass to this method.
469:             */
470:            public void setFont(String font) {
471:                _font = font;
472:
473:                Props props = getPage().getPageProperties();
474:
475:                if (_font != null) {
476:                    _fontStartTag = props.getThemeProperty(null, _font
477:                            + Props.TAG_START);
478:                    _fontEndTag = props.getThemeProperty(null, _font
479:                            + Props.TAG_END);
480:                } else {
481:                    _fontStartTag = props.getThemeProperty(null,
482:                            HtmlText.FONT_DEFAULT + Props.TAG_START);
483:                    _fontEndTag = props.getThemeProperty(null,
484:                            HtmlText.FONT_DEFAULT + Props.TAG_END);
485:                }
486:
487:                _hteSSPart1.setFontStartTag(_fontStartTag);
488:                _hteSSPart1.setFontEndTag(_fontEndTag);
489:
490:                _hteSSPart2.setFontStartTag(_fontStartTag);
491:                _hteSSPart2.setFontEndTag(_fontEndTag);
492:
493:                _hteSSPart3.setFontStartTag(_fontStartTag);
494:                _hteSSPart3.setFontEndTag(_fontEndTag);
495:
496:                if (_htSeparator1 != null) {
497:                    _htSeparator1.setFontStartTag(_fontStartTag);
498:                    _htSeparator1.setFontEndTag(_fontEndTag);
499:                }
500:                if (_htSeparator2 != null) {
501:                    _htSeparator2.setFontStartTag(_fontStartTag);
502:                    _htSeparator2.setFontEndTag(_fontEndTag);
503:                }
504:            }
505:
506:            /**
507:             * Specifies the parent component for this SSN Component.
508:             * Creation date: (7/19/01 8:41:20 AM)
509:             * @param sClass java.lang.String A name of a class in Html to be used by this component
510:             */
511:            public void setParent(HtmlComponent parent) {
512:                super .setParent(parent);
513:                // This is necessary for the name to be generated correctly, else the leading
514:                // sequence of parent names will be lost.
515:                _cont.setParent(parent);
516:            }
517:
518:            /**
519:             * Replaces the separator between the ssn numbers
520:             * @param newSsnSeparator java.lang.String
521:             */
522:            public void setSsnSeparator(java.lang.String newSsnSeparator) {
523:                _sSeparator = newSsnSeparator;
524:
525:                // create new text comp
526:                HtmlText txtNewSeparator1 = new HtmlText(newSsnSeparator,
527:                        getPage());
528:                HtmlText txtNewSeparator2 = new HtmlText(newSsnSeparator,
529:                        getPage());
530:
531:                // replace old area code end comp with new one
532:                _cont.replaceComponent(txtNewSeparator1, _htSeparator1);
533:                _cont.replaceComponent(txtNewSeparator2, _htSeparator2);
534:
535:                //	save ref of new comp
536:                _htSeparator1 = txtNewSeparator1;
537:                _htSeparator2 = txtNewSeparator2;
538:            }
539:
540:            /**
541:             * This method sets the property theme for the component.
542:             * @param theme The theme to use.
543:             */
544:            public void setTheme(String theme) {
545:
546:                super .setTheme(theme);
547:
548:                if (theme != null) {
549:                    _hteSSPart1.setTheme(theme);
550:                    _hteSSPart2.setTheme(theme);
551:                    _hteSSPart3.setTheme(theme);
552:                    _htSeparator1.setTheme(theme);
553:                    _htSeparator2.setTheme(theme);
554:                }
555:            }
556:
557:            /**
558:             * Sets the visibility of the component.
559:             * Creation date: (7/19/01 8:41:20 AM)
560:             * @param visible boolean Indicates the visibility of the component
561:             */
562:            public void setVisible(boolean visible) {
563:                _cont.setVisible(visible);
564:            }
565:
566:            /**
567:             * @returns the access key html attribute
568:             */
569:            public String getAccessKey() {
570:                return _hteSSPart1.getAccessKey();
571:            }
572:
573:            /**
574:             * @returns the read only html attribute
575:             */
576:            public boolean getReadOnly() {
577:                return _hteSSPart1.getReadOnly();
578:            }
579:
580:            /**
581:             * @returns the tab index html attribute
582:             */
583:            public int getTabIndex() {
584:                return _hteSSPart1.getTabIndex();
585:            }
586:
587:            /**
588:             * @param sets the access key html attribute
589:             */
590:            public void setAccessKey(String val) {
591:                _hteSSPart1.setAccessKey(val);
592:            }
593:
594:            /**
595:             * @param sets the read only html attribute
596:             */
597:            public void setReadOnly(boolean val) {
598:                _hteSSPart1.setReadOnly(val);
599:                _hteSSPart2.setReadOnly(val);
600:                _hteSSPart3.setReadOnly(val);
601:            }
602:
603:            /**
604:             * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
605:             */
606:            public void setTabIndex(int val) {
607:                _hteSSPart1.setTabIndex(val);
608:                _hteSSPart2.setTabIndex(val + 1);
609:                _hteSSPart3.setTabIndex(val + 2);
610:            }
611:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.