org.jenkins.ci.plugins.jobimport.RemoteJob.java Source code

Java tutorial

Introduction

Here is the source code for org.jenkins.ci.plugins.jobimport.RemoteJob.java

Source

/*
 * The MIT License
 * 
 * Copyright (c) 2011, Jesse Farinacci
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package org.jenkins.ci.plugins.jobimport;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;

/**
 * @author <a href="mailto:jieryn@gmail.com">Jesse Farinacci</a>
 * @since 1.0
 */
public final class RemoteJob implements Comparable<RemoteJob> {
    private String name;
    private String url;
    private String description;

    public RemoteJob() {
        this((String) null, (String) null, (String) null);
    }

    public RemoteJob(final String name) {
        this(name, (String) null, (String) null);
    }

    public RemoteJob(final String name, final String url) {
        this(name, url, (String) null);
    }

    public RemoteJob(final String name, final String url, final String description) {
        super();
        this.name = name;
        this.url = url;
        this.description = cleanRemoteString(description);
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(final String url) {
        this.url = url;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = cleanRemoteString(description);
    }

    public int compareTo(final RemoteJob other) {
        if (this == other) {
            return 0;
        }

        return name.compareTo(other.getName());
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof RemoteJob)) {
            return false;
        }

        return name.equals(((RemoteJob) obj).getName());
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

    @Override
    public String toString() {
        return new StringBuilder().append("RemoteJob: ").append(name).append(", ").append(url).append(", ")
                .append(description).toString();
    }

    protected static final int MAX_STRLEN = 4096;

    protected static final String cleanRemoteString(final String string) {
        return StringUtils.substring(StringEscapeUtils.escapeHtml(string), 0, MAX_STRLEN);
    }
}