Source Code Cross Referenced for JspLink.java in  » J2EE » Sofia » com » salmonllc » jsp » 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.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.salmonllc.jsp;
002:
003:        import java.util.Hashtable;
004:        import java.util.Vector;
005:
006:        import com.salmonllc.html.HtmlValidatorText;
007:        import com.salmonllc.html.events.SubmitEvent;
008:        import com.salmonllc.html.events.SubmitListener;
009:        import com.salmonllc.properties.Props;
010:        import com.salmonllc.sql.*;
011:        import com.salmonllc.util.MessageLog;
012:        import com.salmonllc.util.Util;
013:
014:        /**
015:         * This container will construct an anchor tag with a html link (HREF) reference.
016:         */
017:        public class JspLink extends JspContainer {
018:            private DataStoreEvaluator _dsEval;
019:            private String _bracketFont;
020:            private String _href;
021:            private String _onClick;
022:            private String _onMouseOut;
023:            private String _onMouseOver;
024:            private String _style;
025:            private String _target;
026:            private String _zoomTo = null;
027:            private Vector _listeners;
028:            private boolean _doSubmit = false;
029:            private boolean _genBracket = false;
030:            private boolean _generateLink = true;
031:            private boolean _submitAlreadyGenerated = false;
032:            private int _rowNo = -1;
033:            private Integer _tabIndex;
034:            private String _accessKey;
035:            private String _title;
036:
037:            /**
038:             * JspLink constructor comment.
039:             *
040:             * @param name The name of the link
041:             * @param href The url for the link
042:             * @param p The page the link will go in.
043:             */
044:            public JspLink(String name, String href,
045:                    com.salmonllc.html.HtmlPage p) {
046:                this (name, href, null, p);
047:            }
048:
049:            /**
050:             * JspLink constructor comment.
051:             *
052:             * @param name The name of the link
053:             * @param href The url for the link
054:             * @param target The target for the link
055:             * @param p The page the link will go in.
056:             */
057:            public JspLink(String name, String href, String target,
058:                    com.salmonllc.html.HtmlPage p) {
059:                super (name, p);
060:                _href = href;
061:                _target = target;
062:            }
063:
064:            /**
065:             * This method sets whether or not the anchor tag will be generated with brackets([]) around the Tag. Pass true to have the tag generated with and false not to.
066:             *
067:             * @param bracket DOCUMENT ME!
068:             */
069:            public void setBracket(boolean bracket) {
070:                _genBracket = bracket;
071:            }
072:
073:            /**
074:             * This method sets the font for the brackets around the link.
075:             *
076:             * @param font DOCUMENT ME!
077:             */
078:            public void setBracketFont(String font) {
079:                _bracketFont = font;
080:            }
081:
082:            /**
083:             * Sets whether or not the component will submit the page before transfering control to the link page. If the link does a submit, all the user entered data will sent to the server to be recorded. If the flag is true, the target and onClick properties cannot be used.
084:             *
085:             * @param doSubmit DOCUMENT ME!
086:             */
087:            public void setDoSubmit(boolean doSubmit) {
088:                _doSubmit = doSubmit;
089:            }
090:
091:            /**
092:             * Gets whether or not the component will submit the page before transfering control to the link page. If the link does a submit, all the user entered data will sent to the server to be recorded.
093:             *
094:             * @return DOCUMENT ME!
095:             */
096:            public boolean getDoSubmit() {
097:                return _doSubmit;
098:            }
099:
100:            /**
101:             * This method sets whether or not the anchor tag will be generated for the link. Pass true to have the a tag generated and false not to. Setting the value to false, will cause the items inside the container to be displayed but nothing will happen when the user clicks on them.
102:             *
103:             * @param gen DOCUMENT ME!
104:             */
105:            public void setGenerateLink(boolean gen) {
106:                _generateLink = gen;
107:            }
108:
109:            /**
110:             * This method gets whether or not the anchor tag will be generated for the link. Pass true to have the a tag generated and false not to. Setting the value to false, will cause the items inside the container to be displayed but nothing will happen when the user clicks on them.
111:             *
112:             * @return DOCUMENT ME!
113:             */
114:            public boolean getGenerateLink() {
115:                return _generateLink;
116:            }
117:
118:            /**
119:             * Sets the href for the link
120:             *
121:             * @param href java.lang.String
122:             */
123:            public void setHref(String href) {
124:                _href = href;
125:            }
126:
127:            /**
128:             * Returns the href for the link
129:             *
130:             * @return DOCUMENT ME!
131:             */
132:            public String getHref() {
133:                return _href;
134:            }
135:
136:            /**
137:             * This method sets a datastore expression that will be used to compute the href for the link.
138:             *
139:             * @param ds com.salmonllc.sql.DataStoreBuffer
140:             * @param expression The expression to evaluate
141:             *
142:             * @throws Exception DOCUMENT ME!
143:             */
144:            public void setHrefExpression(DataStoreBuffer ds,
145:                    DataStoreExpression expression) throws Exception {
146:                try {
147:                    _dsEval = new DataStoreEvaluator(ds, expression);
148:                } catch (Exception e) {
149:                    MessageLog
150:                            .writeErrorMessage(
151:                                    "setHrefExpression(DataStoreBuffer ds, DataStoreExpression expression )",
152:                                    e, this );
153:                    throw e;
154:                }
155:            }
156:
157:            /**
158:             * This method sets a datastore expression that will be used to compute the href for the link.
159:             *
160:             * @param ds com.salmonllc.sql.DataStoreBuffer
161:             * @param expression java.lang.String
162:             *
163:             * @throws Exception DOCUMENT ME!
164:             */
165:            public void setHrefExpression(DataStoreBuffer ds, String expression)
166:                    throws Exception {
167:                try {
168:                    _dsEval = new DataStoreEvaluator(ds, expression);
169:                } catch (Exception e) {
170:                    MessageLog
171:                            .writeErrorMessage(
172:                                    "setHrefExpression(DataStoreBuffer ds, String expression )",
173:                                    e, this );
174:                    throw e;
175:                }
176:            }
177:
178:            /**
179:             * This method gets the DataStoreEvaluator being used for href expressions.
180:             *
181:             * @return DataStoreEvaluator
182:             *
183:             * @see DataStoreEvaluator
184:             */
185:            public DataStoreEvaluator getHrefExpression() {
186:                return _dsEval;
187:            }
188:
189:            /**
190:             * Use this method to set the javascript that will be executed when the user clicks on one of the components in the link.
191:             *
192:             * @param onClick DOCUMENT ME!
193:             */
194:            public void setOnClick(String onClick) {
195:                _onClick = onClick;
196:            }
197:
198:            /**
199:             * Use this method to get the javascript that will be executed when the user clicks on one of the components in the link.
200:             *
201:             * @return DOCUMENT ME!
202:             */
203:            public String getOnClick() {
204:                return _onClick;
205:            }
206:
207:            /**
208:             * Use this method to set the javascript that will be executed when the mouse passes over out of all the components
209:             *
210:             * @param onMouseOut DOCUMENT ME!
211:             */
212:            public void setOnMouseOut(String onMouseOut) {
213:                _onMouseOut = onMouseOut;
214:            }
215:
216:            /**
217:             * Use this method to get the javascript that will be executed when the mouse passes over out of all the components
218:             *
219:             * @return DOCUMENT ME!
220:             */
221:            public String getOnMouseOut() {
222:                return _onMouseOut;
223:            }
224:
225:            /**
226:             * Use this method to set the javascript that will be executed when the mouse passes over any component in the link
227:             *
228:             * @param onMouseOver DOCUMENT ME!
229:             */
230:            public void setOnMouseOver(String onMouseOver) {
231:                _onMouseOver = onMouseOver;
232:            }
233:
234:            /**
235:             * Use this method to get the javascript that will be executed when the mouse passes over any component in the link
236:             *
237:             * @return DOCUMENT ME!
238:             */
239:            public String getOnMouseOver() {
240:                return _onMouseOver;
241:            }
242:
243:            /**
244:             * This method sets the sytle for the link.
245:             *
246:             * @param style DOCUMENT ME!
247:             */
248:            public void setStyle(String style) {
249:                _style = style;
250:            }
251:
252:            /**
253:             * Use this method to get the style that will be used to display the link
254:             *
255:             * @return DOCUMENT ME!
256:             */
257:            public String getStyle() {
258:                return _style;
259:            }
260:
261:            /**
262:             * Sets whether the script that allows a JspLink to listen for SumitPerformed events  has should be  generated. A case where you would need this method is if when you are on a page and  in the submit performed event you leave the page and the JspLink is hidden when you come back.  You will have to set the value to true before you leave the page otherwise when you come back to the page you
263:             * will recieve a javascript error.
264:             *
265:             * @param submitAlreadyGenerated boolean value
266:             */
267:            public void setSubmitAlreadyGenerated(boolean submitAlreadyGenerated) {
268:                _submitAlreadyGenerated = submitAlreadyGenerated;
269:            }
270:
271:            /**
272:             * Returns the whether the script that allows a JspLink to listen for SumitPerformed events  has been generated.
273:             *
274:             * @return boolean
275:             */
276:            public boolean isSubmitAlreadyGenerated() {
277:                return _submitAlreadyGenerated;
278:            }
279:
280:            /**
281:             * Sets the target for the link.<BR> _blank opens the destination document in a new unnamed window. <BR> _parent opens the destination document in the parent window of the one displaying the current document. <BR> _self opens the destination document in the same window as the one in which the link was clicked. <BR> _top opens the destination document in the full body of the current window.
282:             * This value can be used to ensure that the       destination document takes over the full window even if the original document was displayed in a frame. <BR>
283:             *
284:             * @param target DOCUMENT ME!
285:             */
286:            public void setTarget(String target) {
287:                _target = target;
288:            }
289:
290:            /**
291:             * Returns the target for the link.
292:             *
293:             * @return DOCUMENT ME!
294:             */
295:            public String getTarget() {
296:                return _target;
297:            }
298:
299:            /**
300:             * This method adds a listener the will be notified when this button causes the page to be submitted.
301:             *
302:             * @param l The listener to add.
303:             */
304:            public void addSubmitListener(SubmitListener l) {
305:                if (_listeners == null) {
306:                    _listeners = new Vector();
307:                }
308:
309:                int listenersSize = _listeners.size();
310:
311:                for (int i = 0; i < listenersSize; i++) {
312:                    if (((SubmitListener) _listeners.elementAt(i)) == l) {
313:                        return;
314:                    }
315:                }
316:
317:                _listeners.addElement(l);
318:                setDoSubmit(true);
319:            }
320:
321:            /**
322:             * Clears the submit component in this container or children containers. The container stores which component inside it submitted a particular page for one invocation so it can route to the correct submit performed methods. Once that's done, the framework needs to clear out that value for the next page invocation. This method is used by the framework and should not be called directly.
323:             */
324:            public void clearSubmit() {
325:                super .clearSubmit();
326:                setSubmitAlreadyGenerated(false);
327:            }
328:
329:            public boolean executeEvent(int eventType) throws Exception {
330:                if ((eventType == EVENT_SUBMIT) && (_zoomTo != null)) {
331:                    // check listeners
332:                    // if  any have been registered
333:                    if ((_listeners != null) && (_listeners.size() > 0)) {
334:                        SubmitEvent e = new SubmitEvent(getPage(), this ,
335:                                getName(), getFullName(), _rowNo);
336:                        SubmitListener l = null;
337:                        int listenersSize = _listeners.size();
338:
339:                        for (int i = 0; i < listenersSize; i++) {
340:                            l = (SubmitListener) _listeners.elementAt(i);
341:                            e
342:                                    .setNextListener(_listeners.size() > (i + 1) ? _listeners
343:                                            .elementAt(i + 1)
344:                                            : null);
345:                            if (!l.submitPerformed(e)) {
346:                                return false;
347:                            }
348:                        }
349:
350:                        return true;
351:                    } else {
352:                        getPage().getCurrentResponse().sendRedirect(_zoomTo);
353:                        _zoomTo = null;
354:                    }
355:                } else if (!super .executeEvent(eventType)) {
356:                    return false;
357:                }
358:
359:                return true;
360:            }
361:
362:            /**
363:             * Generates the Html for the component. This method is called by the framework and should not be called directly
364:             *
365:             * @param t DOCUMENT ME!
366:             * @param box DOCUMENT ME!
367:             * @param rowNo DOCUMENT ME!
368:             *
369:             * @throws java.io.IOException DOCUMENT ME!
370:             */
371:            public void generateHTML(TagWriter t, String box, int rowNo)
372:                    throws java.io.IOException {
373:                StringBuffer sb = new StringBuffer();
374:
375:                if (!isSubmitAlreadyGenerated()) {
376:                    if (_visible && _doSubmit && _generateLink) {
377:                        sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\""
378:                                + getFullName() + "_HIDDEN\" VALUE=\"\">");
379:                        getPage().writeScript(
380:                                getFormString() + getFullName()
381:                                        + "_HIDDEN.value = '';");
382:                        sb.append("<SCRIPT>");
383:                        sb.append("function " + getFullName()
384:                                + "_submit(row) {");
385:                        sb.append(getFormString() + getFullName()
386:                                + "_HIDDEN.value = row;");
387:                        sb.append(getFormString() + "submit();");
388:                        sb.append("}");
389:                        sb.append("</SCRIPT>");
390:                        setSubmitAlreadyGenerated(true);
391:                    }
392:                }
393:
394:                if (!_visible)
395:                    return;
396:
397:                String onClick = _onClick;
398:                String valScript = HtmlValidatorText
399:                        .generateOnClickJavaScriptForButtons(_onClick,
400:                                _listeners, getFullName());
401:                if (valScript != null) {
402:                    sb.append(valScript);
403:                    onClick = "return "
404:                            + HtmlValidatorText
405:                                    .generateOnClickJavaScriptFunctionName(getFullName())
406:                            + ";";
407:                }
408:
409:                _zoomTo = null;
410:
411:                StringBuffer href = null;
412:
413:                if (_doSubmit) {
414:                    href = new StringBuffer("javascript:" + getFullName()
415:                            + "_submit('" + rowNo + "');");
416:                } else {
417:                    try {
418:                        if (_dsEval != null) {
419:                            if (rowNo > -1) {
420:                                _href = _dsEval.evaluateRowFormat(rowNo);
421:                            } else {
422:                                _href = _dsEval.evaluateRowFormat();
423:                            }
424:                        }
425:                    } catch (Exception e) {
426:                        MessageLog.writeErrorMessage(
427:                                "generateHTML._dsEval.evaluateRowFormat", e,
428:                                this );
429:                    }
430:
431:                    // sr 12-08-2000 was getting a null pointer exception
432:                    if (!Util.isNull(_href)) {
433:                        href = new StringBuffer(_href);
434:                        if (!href.toString().toLowerCase().startsWith(
435:                                "javascript:")) {
436:                            int hrefLength = href.length();
437:
438:                            for (int i = 0; i < hrefLength; i++) {
439:                                if (href.charAt(i) == ' ') {
440:                                    href.setCharAt(i, '+');
441:                                }
442:                            }
443:                        }
444:                    }
445:                }
446:
447:                String row = "";
448:                String bracketStartFont = "";
449:                String bracketEndFont = "";
450:
451:                if (rowNo != -1) {
452:                    row = "_" + row + new Integer(rowNo).toString();
453:                }
454:
455:                if (_genBracket) {
456:                    com.salmonllc.properties.Props props = getPage()
457:                            .getPageProperties();
458:
459:                    if (_bracketFont != null) {
460:                        bracketStartFont = props.getProperty(_bracketFont
461:                                + Props.TAG_START);
462:                        bracketEndFont = props.getProperty(_bracketFont
463:                                + Props.TAG_END);
464:                    } else {
465:                        bracketStartFont = props
466:                                .getProperty(com.salmonllc.html.HtmlText.FONT_DEFAULT
467:                                        + Props.TAG_START);
468:                        bracketEndFont = props
469:                                .getProperty(com.salmonllc.html.HtmlText.FONT_DEFAULT
470:                                        + Props.TAG_END);
471:                    }
472:
473:                    sb.append(bracketStartFont + " [" + bracketEndFont);
474:                }
475:
476:                sb.append("<A NAME=\"" + getFullName() + row + "\" HREF=\""
477:                        + encodeURL(href) + "\"");
478:
479:                if (_target != null) {
480:                    sb.append(" TARGET=\"" + _target + "\"");
481:                }
482:
483:                if (onClick != null) {
484:                    sb.append(" ONCLICK=\"" + onClick + "\"");
485:                }
486:
487:                if (_onMouseOver != null) {
488:                    sb.append(" ONMOUSEOVER=\"" + _onMouseOver + "\"");
489:                }
490:
491:                if (_onMouseOut != null) {
492:                    sb.append(" ONMOUSEOUT=\"" + _onMouseOut + "\"");
493:                }
494:
495:                if (_style != null) {
496:                    sb.append(" CLASS=\"" + _style + "\"");
497:                }
498:                if (_title != null)
499:                    sb.append(" TITLE=\"" + _title + "\"");
500:
501:                if (_tabIndex != null) {
502:                    sb.append(" tabindex=\"");
503:                    sb.append(_tabIndex.toString());
504:                    sb.append("\"");
505:                }
506:                if (_accessKey != null) {
507:                    sb.append(" accesskey=\"");
508:                    sb.append(_accessKey);
509:                    sb.append("\"");
510:                }
511:                sb.append(">");
512:
513:                if (_generateLink) {
514:                    t.print(sb.toString(), TagWriter.TYPE_BEGIN_TAG);
515:                }
516:
517:                t.print(box, TagWriter.TYPE_CONTENT);
518:
519:                if (_generateLink) {
520:                    if (_genBracket) {
521:                        t.print("</A>" + bracketStartFont + "]"
522:                                + bracketEndFont, TagWriter.TYPE_END_TAG);
523:                    } else {
524:                        t.print("</A>", TagWriter.TYPE_END_TAG);
525:                    }
526:                }
527:            }
528:
529:            /**
530:             * This method inserts a listener the will be notified when this button causes the page to be submitted.
531:             *
532:             * @param l The listener to add.
533:             */
534:            public void insertSubmitListener(SubmitListener l) {
535:                if (_listeners == null) {
536:                    _listeners = new Vector();
537:                }
538:
539:                int listenersSize = _listeners.size();
540:
541:                for (int i = 0; i < listenersSize; i++) {
542:                    if (((SubmitListener) _listeners.elementAt(i)) == l) {
543:                        return;
544:                    }
545:                }
546:
547:                _listeners.insertElementAt(l, 0);
548:                setDoSubmit(true);
549:            }
550:
551:            /**
552:             * This method will process the parms from a post for every component in the container.
553:             *
554:             * @param parms DOCUMENT ME!
555:             * @param rowNo DOCUMENT ME!
556:             *
557:             * @return DOCUMENT ME!
558:             *
559:             * @throws Exception DOCUMENT ME!
560:             */
561:            public boolean processParms(Hashtable parms, int rowNo)
562:                    throws Exception {
563:                if (super .processParms(parms, rowNo)) {
564:                    return true;
565:                }
566:
567:                String name = getFullName() + "_HIDDEN";
568:                String p[] = (String[]) parms.get(name);
569:
570:                if ((p != null) && (p[0].trim().length() > 0)
571:                        && (_zoomTo == null)) {
572:                    _submit = this ;
573:
574:                    _rowNo = Integer.parseInt(p[0].trim());
575:
576:                    String href = "";
577:
578:                    if (_dsEval != null) {
579:                        if (_rowNo > -1) {
580:                            href = _dsEval.evaluateRowFormat(_rowNo);
581:                        } else {
582:                            href = _dsEval.evaluateRowFormat();
583:                        }
584:                    } else {
585:                        href = _href;
586:                    }
587:
588:                    _zoomTo = href;
589:
590:                    return true;
591:                }
592:
593:                return false;
594:            }
595:
596:            /**
597:             * This method removes a listener from the list that will be notified if this button causes the page to be submitted.
598:             *
599:             * @param l The listener to remove.
600:             */
601:            public void removeSubmitListener(SubmitListener l) {
602:                if (_listeners == null) {
603:                    return;
604:                }
605:
606:                //
607:                int listenersSize = _listeners.size();
608:
609:                for (int i = 0; i < listenersSize; i++) {
610:                    if (((SubmitListener) _listeners.elementAt(i)) == l) {
611:                        _listeners.removeElementAt(i);
612:
613:                        return;
614:                    }
615:                }
616:            }
617:
618:            /**
619:             * @returns the access key html attribute
620:             */
621:            public String getAccessKey() {
622:                return _accessKey;
623:            }
624:
625:            /**
626:             * @returns the tab index html attribute
627:             */
628:            public int getTabIndex() {
629:                if (_tabIndex == null)
630:                    return -1;
631:                return _tabIndex.intValue();
632:            }
633:
634:            /**
635:             * @param sets the access key html attribute
636:             */
637:            public void setAccessKey(String string) {
638:                _accessKey = string;
639:            }
640:
641:            /**
642:             * @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
643:             */
644:            public void setTabIndex(int val) {
645:                if (val == -1)
646:                    _tabIndex = null;
647:                else
648:                    _tabIndex = new Integer(val);
649:            }
650:
651:            /**
652:             * @return
653:             */
654:            public String getTitle() {
655:                return _title;
656:            }
657:
658:            /**
659:             * @param string
660:             */
661:            public void setTitle(String string) {
662:                _title = string;
663:            }
664:
665:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.