All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wings.header.Script Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings.header;

import org.wings.SimpleURL;
import org.wings.URLResource;
import org.wings.io.Device;
import java.io.IOException;
import java.io.Serializable;

/**
 * Include a <SCRIPT>-element inside the HTML header of rendered page.
 *
 * @author Holger Engels
 */
public class Script implements Header, Serializable {
    protected String language = null;
    protected String type = null;
    protected URLResource urlSource = null;

    /**
     * @deprecated language is deprecated, use Script(type, urlSource) instead
     */
    public Script(String language, String type, URLResource urlSource) {
        this(type,urlSource);
        this.language = language;
    }

    /**
     * creates a script object which can be added to the frame
     * @param type the type of the script
     * @param urlSource the url of the script
     */
    public Script(String type, URLResource urlSource) {
        this.type = type;
        this.urlSource = urlSource;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getLanguage() { return language; }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() { return type; }

    public SimpleURL getURL() { return urlSource!=null?urlSource.getURL():null; }

    @Override
    public void write(Device d)
            throws IOException {
        d.print("");
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Script))
            return false;

        Script testObj = (Script) obj;

        if (testObj.language == null) {
            if (language != null) {
                return false;
            }
        } else {
            if (!testObj.language.equals(language)) {
                return false;
            }
        }

        if (testObj.type == null) {
            if (type != null) {
                return false;
            }
        } else {
            if (!testObj.type.equals(type)) {
                return false;
            }
        }

        if (testObj.getURL() == null) {
            if (getURL() != null) {
                return false;
            }
        } else {
            if (!testObj.getURL().toString().equals(getURL().toString())) {
                return false;
            }
        }
        return true;
    }

    public int hashCode() {
        int hashCode = 17;
        int dispersionFactor = 37;

        hashCode = hashCode * dispersionFactor + ((language == null) ? 0 : language.hashCode());
        hashCode = hashCode * dispersionFactor + ((type == null) ? 0 : type.hashCode());
        hashCode = hashCode * dispersionFactor + ((getURL() == null) ? 0 : getURL().hashCode());

        return hashCode;
    }

    public String toString() {
        return urlSource.getURL().toString();
    }

}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy