001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.header;
014:
015: import org.wings.SimpleURL;
016: import org.wings.URLResource;
017: import org.wings.io.Device;
018: import java.io.IOException;
019: import java.io.Serializable;
020:
021: /**
022: * Include a <code><SCRIPT></code>-element inside the HTML header of rendered page.
023: *
024: * @author Holger Engels
025: */
026: public class Script implements Header, Serializable {
027: protected String language = null;
028: protected String type = null;
029: protected URLResource urlSource = null;
030:
031: /**
032: * @deprecated language is deprecated, use Script(type, urlSource) instead
033: */
034: public Script(String language, String type, URLResource urlSource) {
035: this (type, urlSource);
036: this .language = language;
037: }
038:
039: /**
040: * creates a script object which can be added to the frame
041: * @param type the type of the script
042: * @param urlSource the url of the script
043: */
044: public Script(String type, URLResource urlSource) {
045: this .type = type;
046: this .urlSource = urlSource;
047: }
048:
049: public void setLanguage(String language) {
050: this .language = language;
051: }
052:
053: public String getLanguage() {
054: return language;
055: }
056:
057: public void setType(String type) {
058: this .type = type;
059: }
060:
061: public String getType() {
062: return type;
063: }
064:
065: public SimpleURL getURL() {
066: return urlSource != null ? urlSource.getURL() : null;
067: }
068:
069: public void write(Device d) throws IOException {
070: d.print("<script");
071: if (type != null)
072: d.print(" type=\"" + type + "\"");
073:
074: if (language != null)
075: d.print(" language=\"" + language + "\"");
076:
077: if (urlSource != null && urlSource.getURL() != null) {
078: d.print(" src=\"");
079: urlSource.getURL().write(d);
080: d.print("\"");
081: }
082: d.print("></script>");
083: }
084:
085: /* (non-Javadoc)
086: * @see java.lang.Object#equals(java.lang.Object)
087: */
088: public boolean equals(Object obj) {
089: if (obj == this )
090: return true;
091: if (obj == null)
092: return false;
093: if (!(obj instanceof Script))
094: return false;
095:
096: Script testObj = (Script) obj;
097:
098: if (testObj.getLanguage() == null) {
099: if (getLanguage() != null) {
100: return false;
101: }
102: } else {
103: if (!testObj.getLanguage().equals(getLanguage())) {
104: return false;
105: }
106: }
107:
108: if (testObj.getType() == null) {
109: if (getType() != null) {
110: return false;
111: }
112: } else {
113: if (!testObj.getType().equals(getType())) {
114: return false;
115: }
116: }
117:
118: if (testObj.getURL() == null) {
119: if (getURL() != null) {
120: return false;
121: }
122: } else {
123: if (!testObj.getURL().toString()
124: .equals(getURL().toString())) {
125: return false;
126: }
127: }
128: return true;
129: }
130:
131: public int hashCode() {
132: int hashCode = 17;
133: int dispersionFactor = 37;
134:
135: hashCode = hashCode
136: * dispersionFactor
137: + ((getLanguage() == null) ? 0 : getLanguage()
138: .hashCode());
139: hashCode = hashCode * dispersionFactor
140: + ((getType() == null) ? 0 : getType().hashCode());
141: hashCode = hashCode * dispersionFactor
142: + ((getURL() == null) ? 0 : getURL().hashCode());
143:
144: return hashCode;
145: }
146:
147: public String toString() {
148: return urlSource.getURL().toString();
149: }
150:
151: }
|