KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > DocumentOpenJavascriptLink


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core;
21
22 import com.sslexplorer.boot.Util;
23
24
25 /**
26  * Constructs a fragment of JavaScript to open a link using <i>document.open()</i>.
27  *
28  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
29  */

30 public class DocumentOpenJavascriptLink implements JavascriptLink {
31     
32     // Private instance variables
33
private String JavaDoc uri;
34     private String JavaDoc target;
35     
36     /**
37      * Constructor for links that go to _self
38      *
39      * @param uri uri to open (must be encoded)
40      *
41      */

42     public DocumentOpenJavascriptLink(String JavaDoc uri) {
43         this(uri, null);
44     }
45     
46     /**
47      * Constructor.
48      *
49      * @param uri uri to open (must be encoded)
50      * @param target target to open in (_blank, _self etc)
51      *
52      */

53     public DocumentOpenJavascriptLink(String JavaDoc uri, String JavaDoc target) {
54         this.uri = uri;
55         this.target = target;
56     }
57     
58     /**
59      * Get the URI
60      *
61      * @return uri
62      */

63     public String JavaDoc getURI() {
64         return uri;
65     }
66     
67     /**
68      * Generate the Javascript fragment.
69      *
70      * @return javascript fragement to open the window
71      */

72     public String JavaDoc toJavascript() {
73         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
74         buf.append("open('");
75         buf.append(Util.escapeForJavascriptString(uri));
76         buf.append("'");
77         if(target != null) {
78             buf.append(",'");
79             buf.append(target);
80             buf.append("'");
81         }
82         buf.append(");");
83         return buf.toString();
84     }
85 }
86
Free Books   Free Magazines  
Popular Tags