KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ajaxtags > tags > AjaxAnchorsTag


1 /**
2  * Copyright 2005 Darren L. Spurgeon
3  * Copyright 2007 Jens Kapitza
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.ajaxtags.tags;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspWriter JavaDoc;
23 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
24
25 import org.ajaxtags.helpers.AjaxHtmlHelper;
26 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
27
28 /**
29  * Rewrites HTML anchor tags (<A>), replacing the href attribute with an
30  * onclick event so that retrieved content is loaded inside a region on the
31  * page.
32  *
33  * @author Darren Spurgeon
34  * @author Jens Kapitza
35  * @version $Revision: 1.3 $ $Date: 2007/07/22 16:29:16 $ $Author: jenskapitza $
36  */

37 public class AjaxAnchorsTag extends BodyTagSupport JavaDoc {
38
39     /**
40      * serialVersionUID
41      */

42     private static final long serialVersionUID = -1732745741282114289L;
43     private String JavaDoc ajaxFlag = "ajax";
44     private String JavaDoc target;
45
46     /**
47      * @return Returns the ajaxFlag.
48      */

49     public String JavaDoc getAjaxFlag() {
50         return this.ajaxFlag;
51     }
52
53     /**
54      * @param ajaxFlag
55      * The ajaxFlag to set.
56      */

57     public void setAjaxFlag(String JavaDoc ajaxFlag) {
58         this.ajaxFlag = ajaxFlag;
59     }
60
61     /**
62      * @return Returns the target.
63      */

64     public String JavaDoc getTarget() {
65         return this.target;
66     }
67
68     /**
69      * @param target
70      * The target to set.
71      */

72     public void setTarget(String JavaDoc target) {
73         this.target = target;
74     }
75
76     /**
77      * @see javax.servlet.jsp.tagext.Tag#doStartTag()
78      */

79     @Override JavaDoc
80     public int doStartTag() throws JspException JavaDoc {
81         initParameters();
82         return EVAL_BODY_BUFFERED;
83     }
84
85     /**
86      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
87      */

88     @Override JavaDoc
89     public int doEndTag() throws JspException JavaDoc {
90         JspWriter JavaDoc out = this.pageContext.getOut();
91         String JavaDoc body = this.bodyContent.getString();
92         try {
93             body = AjaxHtmlHelper.ajaxAnchors(body, this.target, this.ajaxFlag);
94             out.println(body);
95         } catch (IOException JavaDoc ex) {
96             throw new JspException JavaDoc(ex.getMessage());
97         }
98         return EVAL_PAGE;
99     }
100
101     /**
102      * @see javax.servlet.jsp.tagext.Tag#release()
103      */

104     @Override JavaDoc
105     public void release() {
106         this.ajaxFlag = null;
107         this.target = null;
108         super.release();
109     }
110
111     /**
112      * Set initial parameters.
113      *
114      * @throws JspException
115      */

116     protected void initParameters() throws JspException JavaDoc {
117         // Optional Properties
118
if (this.ajaxFlag != null) {
119             this.ajaxFlag = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
120                     "ajaxFlag", this.ajaxFlag, String JavaDoc.class, this,
121                     super.pageContext);
122         }
123         if (this.target != null) {
124             this.target = (String JavaDoc) ExpressionEvaluatorManager.evaluate(
125                     "target", this.target, String JavaDoc.class, this,
126                     super.pageContext);
127         }
128     }
129
130 }
131
Popular Tags