KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ebank > web > template > InsertTag


1 /*
2  * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28
29 package com.sun.ebank.web.template;
30
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.jsp.JspTagException JavaDoc;
33 import javax.servlet.jsp.PageContext JavaDoc;
34 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
35 import java.util.HashMap JavaDoc;
36
37
38 public class InsertTag extends SimpleTagSupport JavaDoc {
39     private String JavaDoc parameterName = null;
40     private String JavaDoc definitionName = null;
41
42     public InsertTag() {
43         super();
44     }
45
46     public void setParameter(String JavaDoc parameter) {
47         this.parameterName = parameter;
48     }
49
50     public void setDefinition(String JavaDoc name) {
51         this.definitionName = name;
52     }
53
54     public void doTag() throws JspTagException JavaDoc {
55         Definition definition = null;
56         Parameter parameter = null;
57         boolean directInclude = false;
58         PageContext JavaDoc context = (PageContext JavaDoc) getJspContext();
59
60         // get the definition from the page context
61
definition =
62             (Definition) context.getAttribute(definitionName,
63                 context.APPLICATION_SCOPE);
64
65         // get the parameter
66
if ((parameterName != null) && (definition != null)) {
67             parameter = (Parameter) definition.getParam(parameterName);
68         }
69
70         if (parameter != null) {
71             directInclude = parameter.isDirect();
72         }
73
74         try {
75             // if parameter is direct, print to out
76
if (directInclude && (parameter != null)) {
77                 context.getOut()
78                        .print(parameter.getValue());
79             }
80             // if parameter is indirect, include results of dispatching to page
81
else {
82                 if ((parameter != null) && (parameter.getValue() != null)) {
83                     context.include(parameter.getValue());
84                 }
85             }
86         } catch (Exception JavaDoc ex) {
87             Throwable JavaDoc rootCause = null;
88
89             if (ex instanceof ServletException JavaDoc) {
90                 rootCause = ((ServletException JavaDoc) ex).getRootCause();
91             }
92
93             throw new JspTagException JavaDoc(ex.getMessage(), rootCause);
94         }
95     }
96 }
97
Popular Tags