KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > libtags > WindowOpenTag


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.libtags;
7
8 import java.io.IOException JavaDoc;
9
10 import javax.servlet.jsp.*;
11 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
12
13 import org.apache.struts.Globals;
14 import org.apache.struts.action.Action;
15 import org.apache.struts.util.RequestUtils;
16
17 import com.raptus.owxv3.LoggingManager;
18
19 /**
20  *
21  * <hr>
22  * <table width="100%" border="0">
23  * <tr>
24  * <td width="24%"><b>Filename</b></td><td width="76%">WindowOpenTag.java</td>
25  * </tr>
26  * <tr>
27  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
28  * </tr>
29  * <tr>
30  * <td width="24%"><b>Date</b></td><td width="76%">25th of September 2001</td>
31  * </tr>
32  * </table>
33  * <hr>
34  * <table width="100%" border="0">
35  * <tr>
36  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
37  * </tr>
38  * </table>
39  * <hr>
40  * <table width="100%" border="0">
41  * <tr>
42  * <td>The windowopen tag creates a link that opens a new window with the specified dimensions,<br>
43  * if JavaScript is available,otherwise creates a link with taget to a new window
44  * </td>
45  * </tr>
46  * </table>
47  * <hr>
48  *
49  */

50 public class WindowOpenTag extends TagSupport JavaDoc {
51
52
53     // ------------------------------------------------------------- Properties
54

55     /**
56      * The url wich should be opened in the new window
57      */

58     private String JavaDoc url = null;
59
60     public String JavaDoc getUrl() { return (this.url); }
61     public void setUrl(String JavaDoc url) { this.url = url; }
62
63
64     /**
65      *The width of the window
66      */

67     private int width;
68
69     public int getWidth() { return (this.width); }
70     public void setWidth(int w) { this.width = w; }
71
72
73     /**
74      *The height of the window
75      */

76     private int height;
77
78     public int getHeight() { return (this.height); }
79     public void setHeight(int h) { this.height = h; }
80
81      /**
82      *The text that will be displayed as the link
83      */

84     private String JavaDoc displaytag = null;
85
86     public String JavaDoc getDisplaytag() { return (this.displaytag); }
87     public void setDisplaytag(String JavaDoc tag) { this.displaytag = tag; }
88
89
90     /**
91      *The name of the window, this is optional
92      */

93     private String JavaDoc wname = null;
94
95     public String JavaDoc getWname() { return (this.wname); }
96     public void setWname(String JavaDoc wname) { this.wname = wname; }
97
98
99     /**
100      *The text that will be displayed when the mouse is over the link
101      */

102     private String JavaDoc statustext = null;
103
104     public String JavaDoc getStatustext() { return (this.statustext); }
105     public void setStatustext(String JavaDoc text) { this.statustext = text; }
106
107
108     /**
109      *
110      */

111     private String JavaDoc resources = Action.MESSAGES_KEY;;
112
113     public String JavaDoc getResources() { return (this.resources); }
114     public void setResources(String JavaDoc res) { this.resources = res; }
115
116
117     // --------------------------------------------------------- Public Methods
118

119
120     /**
121      * Process the start tag.
122      *
123      * @exception JspException if a JSP exception has occurred
124      */

125     public int doStartTag() throws JspException
126     {
127         if(wname==null) wname="wndname";
128
129         if(resources==null)
130         {
131             statustext="";
132         }
133         else
134         {
135             if(statustext!=null) statustext = RequestUtils.message(pageContext, resources, Globals.LOCALE_KEY, statustext);
136             else statustext="";
137         }
138
139
140
141         try
142         {
143             JspWriter out = pageContext.getOut();
144             out.println("<script language=\"javascript\">");
145             out.println("// <!--");
146             out.print("document.write('<a HREF=\"javascript:;\" onClick=\"window.open(\\'");
147             out.print(url);
148             out.print("\\',\\'");
149             out.print(wname);
150             out.print("\\',\\'width=");
151             out.print(width);
152             out.print(",height=");
153             out.print(height);
154             out.print("\\')\" onmouseover=\"window.status=\\'");
155             String JavaDoc s=replace(statustext,"'","\\\\\\'");
156             out.print(s);
157             out.print("\\'; return true\">");
158             out.println("');");
159             out.print("document.write('");
160             s=replace(displaytag,"'","\\'");
161             out.print(s);
162             out.println("</a>');");
163             out.println("// -->");
164             out.println("</script>");
165             out.println("<noscript>");
166
167             out.print("<a HREF=\"");
168             out.print(url);
169             out.print("\" target=\"_blank\">");
170             out.print(displaytag);
171             out.print("</a>");
172             out.println("</noscript>");
173
174         }
175         catch(IOException JavaDoc e) {
176             LoggingManager.log("Somenthing really screwed up", this);
177         }
178
179     // Continue processing this page
180
return (SKIP_BODY);
181
182     }
183
184
185     /**
186      * Release any acquired resources.
187      */

188     public void release()
189     {
190         url = null;
191         width = 0;
192         height = 0;
193         wname = null;
194         displaytag=null;
195         statustext=null;
196     }
197     
198     
199     /**
200       * Replaces all instances of oldString with newString in line.
201       *
202       *
203       * @param String original string.
204       * @param String string in line to replace.
205       * @param String replace oldString with this.
206       * @return String string with replacements.
207       */

208     private String JavaDoc replace(String JavaDoc line, String JavaDoc oldString,String JavaDoc newString)
209     {
210         // 20030212/gz: fix to not get NullPointerException ...
211
if(line != null)
212         {
213             int i = 0;
214             if ((i = line.indexOf(oldString, i)) >= 0)
215             {
216                 char [] line2 = line.toCharArray();
217                 char [] newString2 = newString.toCharArray();
218                 int oLength = oldString.length();
219                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc(line2.length);
220                 buf.append(line2, 0, i).append(newString2);
221                 i += oLength;
222                 int j = i;
223                 while ((i = line.indexOf(oldString, i)) > 0)
224                 {
225                     buf.append(line2, j, i - j).append(newString2);
226                     i += oLength;
227                     j = i;
228                 }
229                 buf.append(line2, j, line2.length - j);
230                 return buf.toString();
231             }
232         }
233         
234         return line;
235     }
236
237 }
238
239 // eof
240
Popular Tags