Source Code Cross Referenced for UIWebUtility.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » ui » 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 » ERP CRM Financial » SourceTap CRM » com.sourcetap.sfa.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
004:         *
005:         *  The contents of this file are subject to the SourceTap Public License 
006:         * ("License"); You may not use this file except in compliance with the 
007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010:         * the specific language governing rights and limitations under the License.
011:         *
012:         * The above copyright notice and this permission notice shall be included
013:         * in all copies or substantial portions of the Software.
014:         *
015:         */
016:
017:        package com.sourcetap.sfa.ui;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.StringTokenizer;
023:        import java.util.Vector;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.entity.GenericEntityException;
029:
030:        /**
031:         * DOCUMENT ME!
032:         *
033:         */
034:        public class UIWebUtility extends UIUtility {
035:            public static final String module = UIWebUtility.class.getName();
036:            public static final String HTML_NAME_PREFIX_CURRENT = "";
037:            public static final String HTML_NAME_PREFIX_ORIGINAL = "#orig_";
038:            public static final String HTML_COMPOSITE_FORM_NAME = "compositeForm";
039:
040:            public UIWebUtility() {
041:            }
042:
043:            /**
044:             * DOCUMENT ME!
045:             *
046:             * @param sectionName 
047:             * @param fieldInfo 
048:             * @param row 
049:             *
050:             * @return 
051:             */
052:            public static String getHtmlName(String sectionName,
053:                    UIFieldInfo fieldInfo, int row) {
054:                return getHtmlName(sectionName, fieldInfo.getUiAttribute()
055:                        .getUiEntity().getEntityName(), fieldInfo
056:                        .getUiAttribute().getAttributeName(), row);
057:            }
058:
059:            public static String getHtmlName(String sectionName,
060:                    String entityName, String attributeName, int row) {
061:                return getParamName(HTML_NAME_PREFIX_CURRENT, sectionName,
062:                        entityName, attributeName, row);
063:            }
064:
065:            /**
066:             * DOCUMENT ME!
067:             *
068:             * @param sectionName 
069:             * @param fieldInfo 
070:             * @param row 
071:             *
072:             * @return 
073:             */
074:            public static String getHtmlNameOriginal(String sectionName,
075:                    UIFieldInfo fieldInfo, int row) {
076:                return getParamName(HTML_NAME_PREFIX_ORIGINAL, sectionName,
077:                        fieldInfo.getUiAttribute().getUiEntity()
078:                                .getEntityName(), fieldInfo.getUiAttribute()
079:                                .getAttributeName(), row);
080:            }
081:
082:            /**
083:             * DOCUMENT ME!
084:             *
085:             * @param htmlNamePrefix 
086:             * @param sectionName 
087:             * @param entityName 
088:             * @param attributeName 
089:             * @param row 
090:             *
091:             * @return 
092:             */
093:            public static String getParamName(String htmlNamePrefix,
094:                    String sectionName, String entityName,
095:                    String attributeName, int row) {
096:                return htmlNamePrefix + sectionName + "_" + entityName + "_"
097:                        + attributeName + "_" + String.valueOf(row);
098:            }
099:
100:            /** Converts a parameter variable name to a database name.
101:             * The naming conventions used to allow for this are as follows:
102:             * a database name (table or column) is in all capital letters,
103:             * and the words are separated by an underscore
104:             * (for example: NEAT_ENTITY_NAME or RANDOM_FIELD_NAME);
105:             * a parameter name or screens section name is a mix of
106:             * upper and lowercase with underscores mixed in.
107:             * The parameter name follows the format:
108:             * [original value][screensection][entity][attribute][number]
109:             * For example "AccountListReportQuery_Account_accountName_0"
110:             * [][AccountListReportQuery][Account][accountName][0]
111:             * will return ACCOUNT.ACCOUNT_NAME
112:             * @param reportName the screen section used for the report
113:             * @param paramName the parameter name on the form generated by the ui screen builder
114:             * @return The database name
115:             */
116:            public static String getDbNameFromParamName(String reportName,
117:                    String paramName) {
118:                String lsReturn = "";
119:
120:                String sectionName = getSectionNameFromParamName(paramName);
121:
122:                if (sectionName.equals(reportName)) {
123:
124:                    // We have a parameter that is part of this report
125:                    String entityName = getEntityFromParamName(paramName);
126:
127:                    String attributeName = getAttribFromParamName(paramName);
128:
129:                    String tableName = javaNameToDbName(entityName);
130:
131:                    String columnName = javaNameToDbName(attributeName);
132:
133:                    lsReturn = tableName + "." + columnName;
134:                }
135:
136:                return lsReturn;
137:            }
138:
139:            /** Converts a Java variable name to a database name.
140:             * The naming conventions used to allow for this are as follows:
141:             * a database name (table or column) is in all capital letters,
142:             * and the words are separated by an underscore
143:             * (for example: NEAT_ENTITY_NAME or RANDOM_FIELD_NAME);
144:             * a Java name (ejb or field) is in all lower case letters,
145:             * except the letter at the beginning of each word
146:             * (for example: NeatEntityName or RandomFieldName).
147:             * The convention of using a capital letter at the beginning of a class name in Java,
148:             * or a lower-case letter for the beginning of a variable name in Java is also used
149:             * along with the Java name convention above.
150:             * @param javaName The Java variable name
151:             * @return The database name
152:             */
153:            public static String javaNameToDbName(String javaName) {
154:                if (javaName == null) {
155:                    return null;
156:                }
157:
158:                if (javaName.length() <= 0) {
159:                    return "";
160:                }
161:
162:                StringBuffer dbName = new StringBuffer();
163:                dbName.append(Character.toUpperCase(javaName.charAt(0)));
164:
165:                int namePos = 1;
166:
167:                while (namePos < javaName.length()) {
168:                    char curChar = javaName.charAt(namePos);
169:
170:                    if (Character.isUpperCase(curChar)) {
171:                        dbName.append('_');
172:                    }
173:
174:                    dbName.append(Character.toUpperCase(curChar));
175:                    namePos++;
176:                }
177:
178:                return dbName.toString();
179:            }
180:
181:            /**
182:             * DOCUMENT ME!
183:             *
184:             * @param paramName 
185:             *
186:             * @return 
187:             */
188:            public static String getPrefixFromParamName(String paramName) {
189:                if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
190:                    // The "original" indicator is on the beginning of the parameter name. return it.
191:                    return HTML_NAME_PREFIX_ORIGINAL;
192:                }
193:
194:                return HTML_NAME_PREFIX_CURRENT;
195:            }
196:
197:            /**
198:             * DOCUMENT ME!
199:             *
200:             * @param paramName 
201:             *
202:             * @return 
203:             */
204:            public static String getSectionNameFromParamName(String paramName) {
205:                if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
206:                    // The "original" indicator is on the beginning of the parameter name. Remove it.
207:                    paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL
208:                            .length());
209:                }
210:
211:                if (paramName.indexOf("_") < 0) {
212:                    // The underscore was not found. The param name has no entity ID in it.
213:                    return "";
214:                }
215:
216:                StringTokenizer tokUnderscore = new StringTokenizer(paramName,
217:                        "_");
218:
219:                return tokUnderscore.nextToken();
220:            }
221:
222:            /**
223:             * DOCUMENT ME!
224:             *
225:             * @param paramName 
226:             *
227:             * @return 
228:             */
229:            public static String getEntityFromParamName(String paramName) {
230:                if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
231:                    // The "original" indicator is on the beginning of the parameter name. Remove it.
232:                    paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL
233:                            .length());
234:                }
235:
236:                if (paramName.indexOf("_") < 0) {
237:                    // The underscore was not found. The param name has no entity ID in it.
238:                    return "";
239:                }
240:
241:                StringTokenizer tokUnderscore = new StringTokenizer(paramName,
242:                        "_");
243:                String sectionName = tokUnderscore.nextToken();
244:
245:                return tokUnderscore.nextToken();
246:            }
247:
248:            /**
249:             * DOCUMENT ME!
250:             *
251:             * @param paramName 
252:             *
253:             * @return 
254:             */
255:            public static String getAttribFromParamName(String paramName) {
256:                if (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) == 0) {
257:                    // The "original" indicator is on the beginning of the parameter name. Remove it.
258:                    paramName = paramName.substring(HTML_NAME_PREFIX_ORIGINAL
259:                            .length());
260:                }
261:
262:                if (paramName.indexOf("_") < 0) {
263:                    // The underscore was not found. The param name is the attribute ID.
264:                    return paramName;
265:                }
266:
267:                StringTokenizer tokUnderscore = new StringTokenizer(paramName,
268:                        "_");
269:                String sectionName = tokUnderscore.nextToken();
270:                String entityName = tokUnderscore.nextToken();
271:
272:                return tokUnderscore.nextToken();
273:            }
274:
275:            /**
276:             * DOCUMENT ME!
277:             *
278:             * @param paramName 
279:             *
280:             * @return 
281:             */
282:            public static String getRowFromParamName(String paramName) {
283:                StringTokenizer tokUnderscore = new StringTokenizer(paramName,
284:                        "_");
285:                String sectionName = tokUnderscore.nextToken();
286:                String entityName = tokUnderscore.nextToken();
287:                String attributeName = tokUnderscore.nextToken();
288:
289:                return tokUnderscore.nextToken();
290:            }
291:
292:            /**
293:             * DOCUMENT ME!
294:             *
295:             * @param keyMap 
296:             * @param entityDetailsVector 
297:             *
298:             * @return 
299:             */
300:            public static String getUrlArgs(HashMap keyMap,
301:                    Vector entityDetailsVector) {
302:                // Get the key values for the header so we can make the arrow button pull up the right header row.
303:                String displayHtml = "";
304:                Iterator keyMapIterator = keyMap.keySet().iterator();
305:                int keyCount = 0;
306:
307:                while (keyMapIterator.hasNext()) {
308:                    String key = (String) keyMapIterator.next();
309:                    String valueSource = (String) keyMap.get(key);
310:
311:                    try {
312:                        String value = decodeAttributeValue(valueSource,
313:                                entityDetailsVector, "");
314:                        keyCount++;
315:                        displayHtml += ("&" + key + "=" + value);
316:                    } catch (Exception e) {
317:                        Debug
318:                                .logVerbose(
319:                                        "[UIWebUtility.getUrlArgs] An error occurred while trying to read the value for attribute "
320:                                                + valueSource
321:                                                + ": "
322:                                                + e.getLocalizedMessage(),
323:                                        module);
324:                    }
325:                }
326:
327:                keyMapIterator = null;
328:
329:                return displayHtml;
330:            }
331:
332:            /**
333:             * DOCUMENT ME!
334:             *
335:             * @param keyMap 
336:             * @param entityDetailsVector 
337:             * @param spaces 
338:             *
339:             * @return 
340:             */
341:            public static String getHiddenArgs(HashMap keyMap,
342:                    Vector entityDetailsVector, String spaces) {
343:                // Get the key values for the header so we can make the arrow button pull up the right header row.
344:                String displayHtml = "";
345:                Iterator keyMapIterator = keyMap.keySet().iterator();
346:                int keyCount = 0;
347:
348:                while (keyMapIterator.hasNext()) {
349:                    String key = (String) keyMapIterator.next();
350:                    String valueSource = (String) keyMap.get(key);
351:
352:                    try {
353:                        String value = decodeAttributeValue(valueSource,
354:                                entityDetailsVector, "");
355:                        keyCount++;
356:                        displayHtml += (spaces
357:                                + "<INPUT TYPE=\"hidden\" NAME=\"" + key
358:                                + "\" VALUE=\"" + value + "\">\n");
359:                    } catch (Exception e) {
360:                        Debug
361:                                .logError(
362:                                        "[UIWebUtility.getHiddenArgs] An error occurred while trying to read the value for attribute "
363:                                                + valueSource
364:                                                + ": "
365:                                                + e.getLocalizedMessage(),
366:                                        module);
367:                    }
368:                }
369:
370:                keyMapIterator = null;
371:
372:                return displayHtml;
373:            }
374:
375:            /**
376:             * DOCUMENT ME!
377:             *
378:             * @param keyMap 
379:             * @param spaces 
380:             *
381:             * @return 
382:             */
383:            public static String getHiddenArgs(HashMap keyMap, String spaces) {
384:                // Get the key values for the header so we can make the arrow button pull up the right header row.
385:                String displayHtml = "";
386:                Iterator keyMapIterator = keyMap.keySet().iterator();
387:                int keyCount = 0;
388:
389:                while (keyMapIterator.hasNext()) {
390:                    String key = (String) keyMapIterator.next();
391:                    String value = (String) keyMap.get(key);
392:                    keyCount++;
393:                    displayHtml += (spaces + "<INPUT TYPE=\"hidden\" NAME=\""
394:                            + key + "\" VALUE=\"" + value + "\">\n");
395:                }
396:
397:                keyMapIterator = null;
398:
399:                return displayHtml;
400:            }
401:
402:            /**
403:             * DOCUMENT ME!
404:             *
405:             * @param paramName 
406:             *
407:             * @return 
408:             */
409:            public static boolean checkReservedParameterName(String paramName) {
410:                if (!paramName.equals("action")
411:                        && !paramName.equals("rowCount")
412:                        && !paramName.equals("queryId")
413:                        && !paramName.equals("queryName")
414:                        && !paramName.equals("startRow")
415:                        && !paramName.equals("rowsPerPage")
416:                        && (paramName.indexOf(HTML_NAME_PREFIX_ORIGINAL) < 0)) {
417:                    return true;
418:                } else {
419:                    return false;
420:                }
421:            }
422:
423:            /**
424:             * DOCUMENT ME!
425:             *
426:             * @param uiDisplayObject 
427:             * @param htmlName 
428:             * @param dataValue 
429:             * @param displayValue 
430:             * @param entityDetailsVector 
431:             *
432:             * @return 
433:             */
434:            public static String displayFieldReadOnly(
435:                    UIDisplayObject uiDisplayObject, String htmlName,
436:                    String dataValue, String displayValue,
437:                    Vector entityDetailsVector) {
438:                return displayFieldReadOnly(uiDisplayObject, htmlName,
439:                        dataValue, displayValue,
440:                        UIWebUtility.translateAttribAnchorHrefDef(
441:                                uiDisplayObject.getAttribAnchorHrefDef(),
442:                                entityDetailsVector, UIWebUtility
443:                                        .getAttribFromParamName(htmlName)),
444:                        UIWebUtility
445:                                .translateAttribAnchorTarget(uiDisplayObject
446:                                        .getAttribAnchorTarget()));
447:            }
448:
449:            /**
450:             * DOCUMENT ME!
451:             *
452:             * @param uiDisplayObject 
453:             * @param htmlName 
454:             * @param dataValue 
455:             * @param displayValue 
456:             * @param anchorHref 
457:             * @param anchorTarget 
458:             *
459:             * @return 
460:             */
461:            public static String displayFieldReadOnly(
462:                    UIDisplayObject uiDisplayObject, String htmlName,
463:                    String dataValue, String displayValue, String anchorHref,
464:                    String anchorTarget) {
465:                StringBuffer displayHtml = new StringBuffer();
466:                displayHtml.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + htmlName
467:                        + "\" VALUE='" + dataValue + "'>\n");
468:
469:                if (anchorHref.equals("")) {
470:                    // No anchor specified. Just display the value.
471:                    displayHtml.append(displayValue);
472:                } else {
473:                    displayHtml.append("<A CLASS=\"\" ");
474:                    displayHtml.append(anchorHref);
475:                    displayHtml.append(anchorTarget);
476:                    displayHtml.append(">");
477:                    displayHtml.append(displayValue);
478:                    displayHtml.append("</A>\n");
479:                }
480:
481:                return displayHtml.toString();
482:            }
483:
484:            /**
485:             * DOCUMENT ME!
486:             *
487:             * @param attribAnchorHrefDef 
488:             * @param genericValueVector 
489:             * @param currentFieldName 
490:             *
491:             * @return 
492:             */
493:            public static String translateAttribAnchorHrefDef(
494:                    String attribAnchorHrefDef, Vector genericValueVector,
495:                    String currentFieldName) {
496:                if (!attribAnchorHrefDef.equals("")) {
497:                    // attribAnchorHrefDef attribute was set.
498:                    return " HREF=\""
499:                            + decodeEntityDisplayDef(attribAnchorHrefDef,
500:                                    genericValueVector, currentFieldName)
501:                            + "\"";
502:                } else {
503:                    return "";
504:                }
505:            }
506:
507:            /**
508:             * DOCUMENT ME!
509:             *
510:             * @param attribAnchorTarget 
511:             *
512:             * @return 
513:             */
514:            public static String translateAttribAnchorTarget(
515:                    String attribAnchorTarget) {
516:                if (!attribAnchorTarget.equals("")) {
517:                    // AnchorTarget attribute was set.
518:                    return " TARGET=\"" + attribAnchorTarget + "\"";
519:                } else {
520:                    return "";
521:                }
522:            }
523:
524:            /**
525:             * DOCUMENT ME!
526:             *
527:             * @param attribCols 
528:             *
529:             * @return 
530:             */
531:            public static String translateAttribCols(String attribCols) {
532:                if (!attribCols.equals("")) {
533:                    // Cols attribute was set.
534:                    return " COLS=\"" + attribCols + "\"";
535:                } else {
536:                    return "";
537:                }
538:            }
539:
540:            /**
541:             * DOCUMENT ME!
542:             *
543:             * @param attribRows 
544:             *
545:             * @return 
546:             */
547:            public static String translateAttribRows(String attribRows) {
548:                if (!attribRows.equals("")) {
549:                    // Rows attribute was set.
550:                    return " ROWS=\"" + attribRows + "\"";
551:                } else {
552:                    return "";
553:                }
554:            }
555:
556:            /**
557:             * DOCUMENT ME!
558:             *
559:             * @param attribMaxLength 
560:             * @param defaultMaxLength 
561:             *
562:             * @return 
563:             */
564:            public static String translateAttribMaxLength(
565:                    String attribMaxLength, String defaultMaxLength) {
566:                if (attribMaxLength.equals("")) {
567:                    // Max length was NOT specified in the display object. Use the one from the screen section info.
568:                    return " MAXLENGTH=\"" + String.valueOf(defaultMaxLength)
569:                            + "\"";
570:                } else {
571:                    // Max length was not specified in the display object. Use it.
572:                    return " MAXLENGTH=\"" + attribMaxLength + "\"";
573:                }
574:            }
575:
576:            /**
577:             * DOCUMENT ME!
578:             *
579:             * @param attribDisabled 
580:             *
581:             * @return 
582:             */
583:            public static String translateAttribDisabled(String attribDisabled) {
584:                if (attribDisabled.equals("Y")) {
585:                    // Disabled attribute was set.
586:                    return " DISABLED";
587:                } else {
588:                    return "";
589:                }
590:            }
591:
592:            /**
593:             * DOCUMENT ME!
594:             *
595:             * @param attribReadOnly 
596:             *
597:             * @return 
598:             */
599:            public static String translateAttribReadOnly(String attribReadOnly) {
600:                if (attribReadOnly.equals("Y")) {
601:                    // Read Only attribute was set.
602:                    return " READONLY";
603:                } else {
604:                    return "";
605:                }
606:            }
607:
608:            /**
609:             * DOCUMENT ME!
610:             *
611:             * @param attribAlign 
612:             *
613:             * @return 
614:             */
615:            public static String translateAttribAlign(String attribAlign) {
616:                if (attribAlign.equals("TOP") || attribAlign.equals("MIDDLE")
617:                        || attribAlign.equals("BOTTOM")) {
618:                    // Align attribute was set.
619:                    return " ALIGN=\"" + attribAlign + "\"";
620:                } else {
621:                    return "";
622:                }
623:            }
624:
625:            /**
626:             * DOCUMENT ME!
627:             *
628:             * @param attribWrap 
629:             *
630:             * @return 
631:             */
632:            public static String translateAttribWrap(String attribWrap) {
633:                if (attribWrap.equals("OFF") || attribWrap.equals("PHYSICAL")
634:                        || attribWrap.equals("VIRTUAL")) {
635:                    // Wrap attribute was set.
636:                    return " WRAP=\"" + attribWrap + "\"";
637:                } else {
638:                    return "";
639:                }
640:            }
641:
642:            /**
643:             * DOCUMENT ME!
644:             *
645:             * @param attribClass 
646:             *
647:             * @return 
648:             */
649:            public static String translateAttribClass(String attribClass) {
650:                if (!attribClass.equals("")) {
651:                    // Class attribute was set.
652:                    return " CLASS=\"" + attribClass + "\"";
653:                } else {
654:                    return "";
655:                }
656:            }
657:
658:            /**
659:             * DOCUMENT ME!
660:             *
661:             * @param attribSize 
662:             *
663:             * @return 
664:             */
665:            public static String translateAttribSize(String attribSize) {
666:                if (!attribSize.equals("")) {
667:                    // Size attribute was set.
668:                    return " SIZE=\"" + attribSize + "\"";
669:                } else {
670:                    return "";
671:                }
672:            }
673:
674:            /**
675:             * DOCUMENT ME!
676:             *
677:             * @param attribEventHandling 
678:             *
679:             * @return 
680:             */
681:            public static String translateAttribEventHandling(
682:                    String attribEventHandling) {
683:                if (!attribEventHandling.equals("")) {
684:                    // Event handling attribute was set.
685:                    return " " + attribEventHandling;
686:                } else {
687:                    return "";
688:                }
689:            }
690:
691:            /**
692:             * DOCUMENT ME!
693:             *
694:             * @param attribFieldName 
695:             *
696:             * @return 
697:             */
698:            public static String translateAttribFieldName(String attribFieldName) {
699:                if (!attribFieldName.equals("")) {
700:                    // fieldName attribute was set.
701:                    return " fieldName=\"" + attribFieldName + "\"";
702:                } else {
703:                    return "";
704:                }
705:            }
706:
707:            /**
708:             * DOCUMENT ME!
709:             *
710:             * @param attribEntityName 
711:             *
712:             * @return 
713:             */
714:            public static String translateAttribEntityName(
715:                    String attribEntityName) {
716:                if (!attribEntityName.equals("")) {
717:                    // entityName attribute was set.
718:                    return " entityName=\"" + attribEntityName + "\"";
719:                } else {
720:                    return "";
721:                }
722:            }
723:
724:            /**
725:             * DOCUMENT ME!
726:             *
727:             * @param attribIdName 
728:             *
729:             * @return 
730:             */
731:            public static String translateAttribIdName(String attribIdName) {
732:                if (!attribIdName.equals("")) {
733:                    // idName attribute was set.
734:                    return " idName=\"" + attribIdName + "\"";
735:                } else {
736:                    return "";
737:                }
738:            }
739:
740:            /**
741:             * DOCUMENT ME!
742:             *
743:             * @param attribFindClass 
744:             *
745:             * @return 
746:             */
747:            public static String translateAttribFindClass(String attribFindClass) {
748:                if (!attribFindClass.equals("")) {
749:                    // findClass attribute was set.
750:                    return " findClass=\"" + attribFindClass + "\"";
751:                } else {
752:                    return "";
753:                }
754:            }
755:
756:            /**
757:             * DOCUMENT ME!
758:             *
759:             * @return 
760:             */
761:            public static String writeConfirmDeleteScript() {
762:                StringBuffer displayHtml = new StringBuffer();
763:                displayHtml.append("<SCRIPT>\n");
764:                displayHtml.append("	function confirmDelete() {\n");
765:                displayHtml
766:                        .append("		if (confirm('Delete current record and all associated information from the data base?'))\n");
767:                displayHtml.append("			return true;\n");
768:                displayHtml.append("		else\n");
769:                displayHtml.append("			return false;\n");
770:                displayHtml.append("	}\n");
771:                displayHtml.append("</SCRIPT>\n");
772:
773:                return displayHtml.toString();
774:            }
775:
776:            /**
777:             * DOCUMENT ME!
778:             *
779:             * @param sectionName 
780:             * @param requiredFields 
781:             *
782:             * @return 
783:             */
784:            public static String writeVerifyRequiredScript(String sectionName,
785:                    ArrayList requiredFields) {
786:                StringBuffer displayHtml = new StringBuffer();
787:                displayHtml.append("<SCRIPT>\n");
788:                displayHtml.append("	function verifyRequired" + sectionName
789:                        + "(frm) {\n");
790:
791:                for (int fieldNbr = 0; fieldNbr < requiredFields.size(); fieldNbr++) {
792:                    UIFieldInfo fieldInfo = (UIFieldInfo) requiredFields
793:                            .get(fieldNbr);
794:                    String htmlName = getHtmlName(sectionName, fieldInfo, 0);
795:                    String displayLabel = fieldInfo.getDisplayLabel();
796:                    displayHtml.append("		if (isEmpty(frm." + htmlName
797:                            + ".value)) {\n");
798:                    displayHtml.append("			showMessage(\"" + displayLabel
799:                            + " is required.\", frm." + htmlName + ");\n");
800:                    displayHtml.append("			return false;\n");
801:                    displayHtml.append("		}\n");
802:                }
803:
804:                displayHtml.append("	}\n");
805:                displayHtml.append("\n");
806:                displayHtml
807:                        .append("	// Display a message to user and highlight invalid field.\n");
808:                displayHtml
809:                        .append("	function showMessage(sMessage, objField) {\n");
810:                displayHtml.append("		alert(sMessage)\n");
811:                displayHtml.append("		objField.focus()\n");
812:                displayHtml.append("		return\n");
813:                displayHtml.append("	}\n");
814:                displayHtml.append("\n");
815:                displayHtml.append("	function isNumeric(vVal)\n");
816:                displayHtml.append("	{\n");
817:                displayHtml
818:                        .append("		if (isNaN(vVal) || vVal==\"\"){return false}\n");
819:                displayHtml.append("		else{return true}\n");
820:                displayHtml.append("	}\n");
821:                displayHtml.append("\n");
822:                displayHtml
823:                        .append("	// general purpose function to see if an input value has been entered at all\n");
824:                displayHtml.append("	function isEmpty(inputStr) {\n");
825:                displayHtml
826:                        .append("		if (inputStr == \"\" || inputStr == null) {\n");
827:                displayHtml.append("			return true;\n");
828:                displayHtml.append("		}\n");
829:                displayHtml.append("		return false;\n");
830:                displayHtml.append("	}\n");
831:                displayHtml.append("\n");
832:                displayHtml.append("	function isAlpha(entry) {\n");
833:                displayHtml.append("		var inputStr = entry.value;\n");
834:                displayHtml
835:                        .append("		for (var i = 0; i < inputStr.length; i++) {\n");
836:                displayHtml
837:                        .append("			var oneChar = inputStr.substring(i, i + 1)\n");
838:                displayHtml
839:                        .append("			if (!isNaN(oneChar) && oneChar != ' ') {\n");
840:                displayHtml
841:                        .append("				alert(\"Please make sure entries are letters only.\");\n");
842:                displayHtml.append("				return false;\n");
843:                displayHtml.append("			}\n");
844:                displayHtml.append("		}\n");
845:                displayHtml.append("		return true;\n");
846:                displayHtml.append("	}\n");
847:                displayHtml.append("\n");
848:                displayHtml.append("</SCRIPT>\n");
849:
850:                return displayHtml.toString();
851:            }
852:
853:            /**
854:             * DOCUMENT ME!
855:             *
856:             * @param action 
857:             * @param request 
858:             *
859:             * @return 
860:             *
861:             * @throws GenericEntityException 
862:             */
863:            public static String convertButtonAction(String action,
864:                    HttpServletRequest request) throws GenericEntityException {
865:                if (action.equals(UIScreenSection.ACTION_BUTTON)) {
866:                    // A button was pushed from the title bar of a screen section.  Need to read the
867:                    // buttonAction parameter to see which button was pushed so we can change the action
868:                    // to one of the basic ones understood by the event processor and the UIWebScreenSection.
869:                    if ((request.getParameter("queryButton.x") != null)
870:                            || ((request.getParameter("buttonAction") != null) && (request
871:                                    .getParameter("buttonAction").equals(
872:                                            "Query")
873:                                    || request.getParameter("buttonAction")
874:                                            .equals("Advanced Query") || request
875:                                    .getParameter("buttonAction").equals(
876:                                            "Standard Query")))) {
877:                        // Query
878:
879:                        action = UIScreenSection.ACTION_SHOW_QUERY;
880:                    } else if ((request.getParameter("newButton.x") != null)
881:                            || ((request.getParameter("buttonAction") != null) && request
882:                                    .getParameter("buttonAction").equals("New"))) {
883:                        // New
884:
885:                        action = UIScreenSection.ACTION_SHOW_INSERT;
886:                    } else if ((request.getParameter("editButton.x") != null)
887:                            || ((request.getParameter("buttonAction") != null) && request
888:                                    .getParameter("buttonAction")
889:                                    .equals("Edit"))) {
890:                        // Edit
891:
892:                        action = UIScreenSection.ACTION_SHOW_UPDATE;
893:                    } else if ((request.getParameter("selectButton.x") != null)
894:                            || ((request.getParameter("buttonAction") != null) && request
895:                                    .getParameter("buttonAction").equals(
896:                                            "Select"))) {
897:                        // Select
898:                        action = UIScreenSection.ACTION_SHOW_SELECT;
899:                    } else if ((request.getParameter("deleteButton.x") != null)
900:                            || ((request.getParameter("buttonAction") != null) && request
901:                                    .getParameter("buttonAction").equals(
902:                                            "Delete"))) {
903:                        // Delete
904:                        action = UIScreenSection.ACTION_DELETE;
905:                    } else if ((request.getParameter("copyButton.x") != null)
906:                            || ((request.getParameter("buttonAction") != null) && request
907:                                    .getParameter("buttonAction")
908:                                    .equals("Copy"))) {
909:                        // Copy
910:                        action = UIScreenSection.ACTION_SHOW_COPY;
911:                    } else if ((request.getParameter("cancelButton.x") != null)
912:                            || ((request.getParameter("buttonAction") != null) && request
913:                                    .getParameter("buttonAction").equals(
914:                                            "Cancel"))) {
915:                        // Cancel
916:                        action = UIScreenSection.ACTION_SHOW_INSERT;
917:                    } else {
918:                        // Error. Button action is required if action is ACTION_BUTTON.
919:                        throw new GenericEntityException(
920:                                "The button.x or buttonAction parameter is required when action is \"button\".");
921:                    }
922:                }
923:
924:                return action;
925:            }
926:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.