KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > header > Script


1 /*
2  * $Id: Script.java,v 1.8 2005/06/07 12:55:58 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.header;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.wings.Renderable;
19 import org.wings.SimpleURL;
20 import org.wings.URLResource;
21 import org.wings.io.Device;
22
23 import java.io.IOException JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:hengels@mercatis.de">Holger Engels</a>
27  * @version $Revision: 1.8 $
28  */

29 public class Script implements Renderable {
30     private final transient static Log log = LogFactory.getLog(Script.class);
31     protected String JavaDoc language = null;
32     protected String JavaDoc type = null;
33     protected URLResource urlSource = null;
34
35     /**
36      * @deprecated language is deprecated, use Script(type, urlSource) instead
37      */

38     public Script(String JavaDoc language, String JavaDoc type, URLResource urlSource) {
39         this(type,urlSource);
40         this.language = language;
41     }
42
43     /**
44      * creates a script object which can be added to the frame
45      * @param type the type of the script
46      * @param urlSource the url of the script
47      */

48     public Script(String JavaDoc type, URLResource urlSource) {
49         this.type = type;
50         this.urlSource = urlSource;
51     }
52
53     public void setLanguage(String JavaDoc language) {
54         this.language = language;
55     }
56
57     public String JavaDoc getLanguage() { return language; }
58
59     public void setType(String JavaDoc type) {
60         this.type = type;
61     }
62
63     public String JavaDoc getType() { return type; }
64
65     public SimpleURL getURL() { return urlSource!=null?urlSource.getURL():null; }
66
67     public void write(Device d)
68             throws IOException JavaDoc {
69         d.print("<script");
70         if (type != null)
71             d.print(" type=\"" + type + "\"");
72
73         if (language != null)
74             d.print(" language=\"" + language + "\"");
75
76         if (urlSource != null && urlSource.getURL() != null) {
77             d.print(" SRC=\"");
78             urlSource.getURL().write(d);
79             d.print("\"");
80         }
81         d.print("></script>");
82     }
83
84     /* (non-Javadoc)
85      * @see java.lang.Object#equals(java.lang.Object)
86      */

87     public boolean equals(Object JavaDoc obj) {
88         if (obj.getClass() != Script.class) {
89             return false;
90         }
91         Script testObj = (Script) obj;
92         
93         if (testObj.getLanguage() == null) {
94             if (getLanguage() != null) {
95                 return false;
96             }
97         } else {
98             if (!testObj.getLanguage().equals(getLanguage())) {
99                 return false;
100             }
101         }
102         
103         if (testObj.getType() == null) {
104             if (getType() != null) {
105                 return false;
106             }
107         } else {
108             if (!testObj.getType().equals(getType())) {
109                 return false;
110             }
111         }
112         
113         if (testObj.getURL() == null) {
114             if (getURL() != null) {
115                 return false;
116             }
117         } else {
118             if (!testObj.getURL().toString().equals(getURL().toString())) {
119                 return false;
120             }
121         }
122         return true;
123     }
124     
125 }
126
127
128
Popular Tags