001: /* StyleSheet.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Jun 2 12:32:59 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.servlet;
020:
021: import org.zkoss.lang.Objects;
022:
023: /**
024: * Represents a style sheet.
025: *
026: * @author tomyeh
027: */
028: public class StyleSheet implements java.io.Serializable, Cloneable {
029: private static final long serialVersionUID = 20060622L;
030:
031: private final String _href, _type, _content;
032:
033: /** Creates by specifying the file to contain the style sheets.
034: *
035: * @param href URI of the file containing the style sheets.
036: * @param type the type. If null, "text/css" is assumed.
037: */
038: public StyleSheet(String href, String type) {
039: this (href, type, false);
040: }
041:
042: /** Creates by assigning the content (style sheets).
043: *
044: * @param content the style content or an URI to an external file.
045: * @param type the type. If null, "text/css" is assumed.
046: * @param byContent the content argument is the style content, or
047: * an URI to an external content
048: */
049: public StyleSheet(String content, String type, boolean byContent) {
050: if (content == null)
051: throw new IllegalArgumentException("null content");
052:
053: if (byContent) {
054: _href = null;
055: _content = content;
056: } else {
057: _href = content;
058: _content = null;
059: }
060: _type = type != null && type.length() != 0 ? type : "text/css";
061: }
062:
063: /** Returns the href that contains the style sheets, or null if
064: * {@link #getContent} is not null.
065: */
066: public String getHref() {
067: return _href;
068: }
069:
070: /** Returns the type. */
071: public String getType() {
072: return _type;
073: }
074:
075: /** Returns the style sheets, or null if {@link #getHref} is not null.
076: */
077: public String getContent() {
078: return _content;
079: }
080:
081: //-- cloneable --//
082: public Object clone() {
083: try {
084: return super .clone();
085: } catch (CloneNotSupportedException e) {
086: throw new InternalError();
087: }
088: }
089:
090: //-- Object --//
091: public String toString() {
092: return "[href: " + _href + " type=" + _type + ']';
093: }
094:
095: public int hashCode() {
096: return _href.hashCode() + _type.hashCode();
097: }
098:
099: public boolean equals(Object o) {
100: if (!(o instanceof StyleSheet))
101: return false;
102: final StyleSheet ss = (StyleSheet) o;
103: return Objects.equals(ss._href, _href)
104: && Objects.equals(ss._type, _type)
105: && Objects.equals(ss._content, _content);
106: }
107: }
|