Source code: com/RuntimeCollective/webapps/tag/TrackerLinkTag.java
1 /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/tag/TrackerLinkTag.java,v 1.6 2003/09/30 15:13:18 joe Exp $
2 * $Revision: 1.6 $
3 * $Date: 2003/09/30 15:13:18 $
4 *
5 * ====================================================================
6 *
7 * Josephine : http://www.runtime-collective.com/josephine/index.html
8 *
9 * Copyright (C) 2003 Runtime Collective
10 *
11 * This product includes software developed by the
12 * Apache Software Foundation (http://www.apache.org/).
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 package com.RuntimeCollective.webapps.tag;
31
32 import java.io.IOException;
33 import javax.servlet.jsp.JspWriter;
34 import javax.servlet.jsp.JspException;
35 import javax.servlet.jsp.JspTagException;
36 import javax.servlet.http.HttpServletRequest;
37 import java.lang.String;
38 import java.lang.RuntimeException;
39 import java.net.URLEncoder;
40 import java.io.UnsupportedEncodingException;
41
42 import javax.servlet.jsp.tagext.Tag;
43 import javax.servlet.jsp.tagext.TagSupport;
44
45 import org.apache.struts.taglib.html.BaseHandlerTag;
46 import com.RuntimeCollective.webapps.RuntimeParameters;
47
48
49 /** a custom jsp tag that creates a link to the Runtime Intranet taking its input either directly from the tag or from RuntimeParameters
50 * <ul>
51 * <li> <code> projectId </code> - The projectId on the intranet. [Optional]. </li>
52 * <li> <code> domainId </code> - The domainId on the intranet. [Optional and not always neccessary]. </li>
53 * <li> <code> linkText </code> - The text to be displayed as a link [Optional -- defaults to raise a ticket for this page]. </li>
54 *
55 * @author matt
56 * @version $Id: TrackerLinkTag.java,v 1.6 2003/09/30 15:13:18 joe Exp $
57 */
58
59 public class TrackerLinkTag extends BaseHandlerTag {
60
61 /** the projectId from the tag. */
62 protected String projectId ;
63 /** get the projectId from the tag. */
64 public String getProjectId() { return this.projectId; }
65 /** set the projectId. */
66 public void setProjectId(String projectId) { this.projectId = projectId; }
67
68 /** the domainId from the tag. */
69 protected String domainId ;
70 /** get the domainId from the tag. */
71 public String getDomainId() { return this.domainId; }
72 /** set the domainId. */
73 public void setDomainId(String domainId) { this.domainId = domainId; }
74
75 /** the linkText from the tag. */
76 protected String linkText;
77 /** get the linkText from the tag. */
78 public String getLinkText() { return this.linkText; }
79 /** set the linkText. */
80 public void setLinkText(String linkText) { this.linkText = linkText; }
81
82 // == Tag methods ==================================
83
84 public int doStartTag() throws JspException {
85
86 String projectIdForLink = "";
87
88 if (projectId != null) {
89 projectIdForLink = projectId;
90 } else if (!RuntimeParameters.get("projectId").equals(null)) {
91 projectIdForLink = RuntimeParameters.get("projectId");
92 } else {
93 throw new JspException("trackerLink tag didn't find a value for projectId");
94 }
95
96
97 String domainIdForLink = "";
98
99 // IF RuntimeParamters get METHOD STOPS THROWING EXCEPTIONS SUBSTITUTE THE COMMENTED CODE BLOCKS
100
101 // if (domainId != null) {
102 // domainIdForLink = "domain_id="+domainId+"&";
103 // } else if (!RuntimeParameters.get("domainId").equals(null)) {
104 // domainIdForLink = "domain_id="+RuntimeParameters.get("domainId")+"&";
105 // } else {
106 // domainIdForLink = "domain_id=all&";
107 // }
108
109 if (domainId != null) {
110 domainIdForLink = "domain_id="+domainId+"&";
111 } else {
112 try {
113 domainIdForLink = "domain_id="+RuntimeParameters.get("domainId")+"&";
114 } catch(RuntimeException e) {
115 domainIdForLink = "";
116 }
117 }
118
119 String intranetUrl = "";
120
121 String linkTextForLink = "Raise a ticket for this page";
122 if (linkText != null ) {
123 linkTextForLink = linkText;
124 }
125
126
127
128 //try {
129 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
130 String theFile = request.getRequestURI();
131 //String fileCoded = URLEncoder.encode(theFile,"UTF-8");
132 String fileCoded = URLEncoder.encode(theFile);
133 intranetUrl = "http://intranet.runtime-collective.com/ticket/issue-new?"+domainIdForLink+"project_id="+projectIdForLink+"&one_line=" + fileCoded;
134 //} catch (UnsupportedEncodingException e) {
135 //RuntimeParameters.logDebug(this, "UnsupportedEncodingException "+e);
136 //throw new JspTagException("UnsupportedEncodingException" + e.getMessage());
137 //}
138 StringBuffer html = new StringBuffer();
139
140 html.append("<a href=\"");
141 html.append(intranetUrl);
142 html.append("\" target=\"_blank\">"+linkTextForLink+"</a>");
143
144
145 try {
146
147 pageContext.getOut().println( html.toString() );
148 } catch (IOException e) {
149 throw new JspTagException("I/O Exception " + e.getMessage() );
150 }
151
152 return SKIP_BODY;
153
154 }
155
156 public void release() {
157 projectId = "";
158 domainId = "";
159 linkText = "";
160 }
161
162 }
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177