KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > taglib > html > LinkTag


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

16 package org.jmanage.webui.taglib.html;
17
18 import org.jmanage.webui.util.RequestParams;
19 import org.jmanage.webui.util.Utils;
20 import org.jmanage.webui.util.WebContext;
21 import org.jmanage.core.services.AccessController;
22
23 import javax.servlet.jsp.JspException JavaDoc;
24 import javax.servlet.jsp.JspWriter JavaDoc;
25 import javax.servlet.ServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 /**
30  *
31  * date: Jun 20, 2004
32  * @author Rakesh Kalra
33  */

34 public class LinkTag extends org.apache.struts.taglib.html.LinkTag {
35
36     private String JavaDoc acl;
37     private boolean hasAccess = true;
38
39     public String JavaDoc getAcl(){
40         return acl;
41     }
42
43     public void setAcl(String JavaDoc acl){
44         this.acl = acl;
45     }
46
47     public int doStartTag() throws JspException JavaDoc{
48         if(acl!=null){
49             WebContext context = WebContext.get(
50                     (HttpServletRequest JavaDoc)pageContext.getRequest());
51             if(!AccessController.canAccess(Utils.getServiceContext(context),acl)){
52                 hasAccess = false;
53                 return SKIP_BODY;
54             }
55         }
56         return super.doStartTag();
57     }
58
59     public int doEndTag() throws JspException JavaDoc {
60         if(!hasAccess){
61             hasAccess = true;
62             return EVAL_PAGE;
63         }
64         return super.doEndTag();
65     }
66     protected String JavaDoc calculateURL() throws JspException JavaDoc {
67         String JavaDoc url = super.calculateURL();
68         url = appendQueryStringParams(url);
69         return url;
70     }
71
72     private String JavaDoc appendQueryStringParams(String JavaDoc url) {
73         if(url.toLowerCase().startsWith("javascript:")){
74             return url;
75         }
76         ServletRequest JavaDoc request = pageContext.getRequest();
77         String JavaDoc applicationId =
78                 request.getParameter(RequestParams.APPLICATION_ID);
79         if (applicationId != null) {
80             url = Utils.appendURLParam(url, RequestParams.APPLICATION_ID,
81                     applicationId);
82         }
83         String JavaDoc objectName =
84                 request.getParameter(RequestParams.OBJECT_NAME);
85         if (objectName != null) {
86             url = Utils.appendURLParam(url, RequestParams.OBJECT_NAME,
87                     objectName);
88         }
89         return url;
90     }
91 }
92
Popular Tags