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:
019: import java.io.IOException;
020: import java.io.Serializable;
021:
022: /**
023: * Include a <code><LINK></code>-element inside the HTML header of rendered page.
024: *
025: * <p>Example usage to include a customer stylesheet.<br/>
026: * <code>frame.addHeader(new Link("stylesheet", null, "text/css", null, new DefaultURLResource("../css/appstyles.css")));</code>
027: *
028: * @author Holger Engels
029: */
030: public class Link implements Header, Serializable {
031: protected String rel = null;
032: protected String rev = null;
033: protected String type = null;
034: protected String target = null;
035: protected URLResource urlSource = null;
036:
037: /**
038: * Example usage to include a customer stylesheet.<br/>
039: * <code>frame.addHeader(new Link("stylesheet", null, "text/css", null, new DefaultURLResource("../css/appstyles.css")));</code>
040: * @param rel
041: * @param rev
042: * @param type
043: * @param target
044: * @param urlSource
045: */
046: public Link(String rel, String rev, String type, String target,
047: URLResource urlSource) {
048: this .rel = rel;
049: this .rev = rev;
050: this .type = type;
051: this .target = target;
052: this .urlSource = urlSource;
053: }
054:
055: public void setRel(String rel) {
056: this .rel = rel;
057: }
058:
059: public String getRel() {
060: return rel;
061: }
062:
063: public void setRev(String rev) {
064: this .rev = rev;
065: }
066:
067: public String getRev() {
068: return rev;
069: }
070:
071: public void setType(String type) {
072: this .type = type;
073: }
074:
075: public String getType() {
076: return type;
077: }
078:
079: public SimpleURL getURL() {
080: return urlSource.getURL();
081: }
082:
083: public void setTarget(String target) {
084: this .target = target;
085: }
086:
087: public String getTarget() {
088: return target;
089: }
090:
091: public void write(Device d) throws IOException {
092: d.print("<link");
093: if (rel != null)
094: d.print(" rel=\"" + rel + "\"");
095: if (rev != null)
096: d.print(" rev=\"" + rev + "\"");
097: if (type != null)
098: d.print(" type=\"" + type + "\"");
099: if (target != null)
100: d.print(" target=\"" + target + "\"");
101:
102: if (urlSource != null && urlSource.getURL() != null) {
103: d.print(" href=\"");
104: urlSource.getURL().write(d);
105: d.print("\"");
106: }
107: d.print("/>");
108: }
109:
110: /*
111: * @see java.lang.Object#equals(java.lang.Object)
112: */
113: public boolean equals(Object obj) {
114: if (obj == this )
115: return true;
116: if (obj == null)
117: return false;
118: if (!(obj instanceof Link))
119: return false;
120:
121: Link testObj = (Link) obj;
122:
123: if (testObj.getRel() == null) {
124: if (getRel() != null) {
125: return false;
126: }
127: } else {
128: if (!testObj.getRel().equals(getRel())) {
129: return false;
130: }
131: }
132:
133: if (testObj.getRev() == null) {
134: if (getRev() != null) {
135: return false;
136: }
137: } else {
138: if (!testObj.getRev().equals(getRev())) {
139: return false;
140: }
141: }
142:
143: if (testObj.getType() == null) {
144: if (getType() != null) {
145: return false;
146: }
147: } else {
148: if (!testObj.getType().equals(getType())) {
149: return false;
150: }
151: }
152:
153: if (testObj.getTarget() == null) {
154: if (getTarget() != null) {
155: return false;
156: }
157: } else {
158: if (!testObj.getTarget().equals(getTarget())) {
159: return false;
160: }
161: }
162:
163: if (testObj.getURL() == null) {
164: if (getURL() != null) {
165: return false;
166: }
167: } else {
168: if (!testObj.getURL().toString()
169: .equals(getURL().toString())) {
170: return false;
171: }
172: }
173: return true;
174: }
175:
176: public int hashCode() {
177: int hashCode = 17;
178: int dispersionFactor = 37;
179:
180: hashCode = hashCode * dispersionFactor
181: + ((getRel() == null) ? 0 : getRel().hashCode());
182: hashCode = hashCode * dispersionFactor
183: + ((getRev() == null) ? 0 : getRev().hashCode());
184: hashCode = hashCode * dispersionFactor
185: + ((getType() == null) ? 0 : getType().hashCode());
186: hashCode = hashCode * dispersionFactor
187: + ((getTarget() == null) ? 0 : getTarget().hashCode());
188: hashCode = hashCode * dispersionFactor
189: + ((getURL() == null) ? 0 : getURL().hashCode());
190:
191: return hashCode;
192: }
193:
194: public String toString() {
195: return urlSource.getURL().toString();
196: }
197:
198: }
|