1 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 ; 24 25 29 public class Script implements Renderable { 30 private final transient static Log log = LogFactory.getLog(Script.class); 31 protected String language = null; 32 protected String type = null; 33 protected URLResource urlSource = null; 34 35 38 public Script(String language, String type, URLResource urlSource) { 39 this(type,urlSource); 40 this.language = language; 41 } 42 43 48 public Script(String type, URLResource urlSource) { 49 this.type = type; 50 this.urlSource = urlSource; 51 } 52 53 public void setLanguage(String language) { 54 this.language = language; 55 } 56 57 public String getLanguage() { return language; } 58 59 public void setType(String type) { 60 this.type = type; 61 } 62 63 public String getType() { return type; } 64 65 public SimpleURL getURL() { return urlSource!=null?urlSource.getURL():null; } 66 67 public void write(Device d) 68 throws IOException { 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 87 public boolean equals(Object 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 |