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

org.ow2.jonas.autostart.parseurl.ParseUrl Maven / Gradle / Ivy

The newest version!
/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2010 Bull S.A.S.
 * Contact: [email protected]
 *
 * This library 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 any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: ParseUrl.java 20819 2011-02-02 16:00:53Z benoitf $
 * --------------------------------------------------------------------------
 */

package org.ow2.jonas.autostart.parseurl;

import org.ow2.jonas.autostart.parser.Parser;

/**
 * This class gets the url of latest version.
 * @author Samuel Kabore
 */
public class ParseUrl {

    /**
     * JOnAS type.
     */
    private String type;

    /**
     * Parser requested.
     */
    private Parser parser;

    /**
     * The prefix of URL.
     */
    private String startUrl;

    /**
     * Teh suffix of URL.
     */
    private String endUrl;

    /**
     * Build a new ParseUrl with the following parser, startUrl and endUrl.
     * @param parser the parser object
     * @param startUrl the prefix of URL
     * @param endUrl the suffix of URL
     */
    public ParseUrl(final Parser parser, final String startUrl, final String endUrl) {
        this.parser = parser;
        this.startUrl = startUrl;
        this.endUrl = endUrl;
    }

    /**
     * Build a new ParseUrl with the following parser, startUrl and endUrl.
     * @param parser the parser object
     * @param startUrl the prefix of URL
     * @param endUrl the suffix of URL
     * @param type the the type of JOnAS server zip file to download
     */
    public ParseUrl(final Parser parser, final String startUrl, final String endUrl, final String type) {
        this.parser = parser;
        if (type != null && !type.equals("") && (type.equalsIgnoreCase("micro") || type.equalsIgnoreCase("full"))) {
            // Default type
            if (type.equals("micro")) {
                this.type = "micro-jonas";
            } else {
                this.type = "jonas-full";
            }
            this.startUrl = startUrl + this.type + "/";
        } else {
            this.startUrl = startUrl;
        }
        this.endUrl = endUrl;
    }

    /**
     * Returns a string representation of the url.
     * @return a string representation of the url.
     */
    public String getUrl() {
        if (startUrl.toLowerCase().contains("postgresql")) {
            startUrl = startUrl + parser.getLatestVersion() + "/postgresql-";
            return startUrl + parser.getLatestVersion() + endUrl;
        } else if (startUrl.toLowerCase().contains("mysql")) {
            startUrl = startUrl + parser.getLatestVersion() + "/mysql-connector-java-";
            return startUrl + parser.getLatestVersion() + endUrl;
        } else {
            return startUrl + parser.getLatestVersion() + "/" + this.type + "-" + parser.getLatestVersion() + endUrl;
        }
    }

    /**
     * Returns a string representation of the url.
     * @return a string representation of the url.
     * @param version the version to get.
     */
    public String getUrl(final String version) {
        if (startUrl.toLowerCase().contains("postgresql")) {
            startUrl = startUrl + version + "/postgresql-";
            return startUrl + version + endUrl;
        } else if (startUrl.toLowerCase().contains("mysql")) {
            startUrl = startUrl + version + "/mysql-connector-java-";
            return startUrl + version + endUrl;
        } else {
            return startUrl + version + "/" + this.type + "-" + version + endUrl;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy