Search in sources :

Example 1 with JavaSpecVersion

use of org.jivesoftware.util.JavaSpecVersion in project Openfire by igniterealtime.

the class AvailablePlugin method getInstance.

public static AvailablePlugin getInstance(Element plugin) {
    String pluginName = plugin.attributeValue("name");
    Version latestVersion = null;
    String latestVersionValue = plugin.attributeValue("latest");
    if (latestVersionValue != null && !latestVersionValue.isEmpty()) {
        latestVersion = new Version(latestVersionValue);
    }
    URL icon = null;
    String iconValue = plugin.attributeValue("icon");
    if (iconValue != null && !iconValue.isEmpty()) {
        try {
            icon = new URL(iconValue);
        } catch (MalformedURLException e) {
            Log.warn("Unable to create icon URL from value '{}' for plugin {}.", iconValue, pluginName, e);
        }
    }
    URL readme = null;
    String readmeValue = plugin.attributeValue("readme");
    if (readmeValue != null && !readmeValue.isEmpty()) {
        try {
            readme = new URL(readmeValue);
        } catch (MalformedURLException e) {
            Log.warn("Unable to create readme URL from value '{}' for plugin {}.", readmeValue, pluginName, e);
        }
    }
    URL changelog = null;
    String changelogValue = plugin.attributeValue("changelog");
    if (changelogValue != null && !changelogValue.isEmpty()) {
        try {
            changelog = new URL(changelogValue);
        } catch (MalformedURLException e) {
            Log.warn("Unable to create changelog URL from value '{}' for plugin {}.", changelogValue, pluginName, e);
        }
    }
    URL downloadUrl = null;
    String downloadUrlValue = plugin.attributeValue("url");
    if (downloadUrlValue != null && !downloadUrlValue.isEmpty()) {
        try {
            downloadUrl = new URL(downloadUrlValue);
        } catch (MalformedURLException e) {
            Log.warn("Unable to create download URL from value '{}' for plugin {}.", downloadUrlValue, pluginName, e);
        }
    }
    String license = plugin.attributeValue("licenseType");
    String description = plugin.attributeValue("description");
    String author = plugin.attributeValue("author");
    Version minServerVersion = null;
    String minServerVersionValue = plugin.attributeValue("minServerVersion");
    if (minServerVersionValue != null && !minServerVersionValue.isEmpty()) {
        minServerVersion = new Version(minServerVersionValue);
    }
    Version priorToServerVersion = null;
    String priorToServerVersionValue = plugin.attributeValue("priorToServerVersion");
    if (priorToServerVersionValue != null && !priorToServerVersionValue.isEmpty()) {
        priorToServerVersion = new Version(priorToServerVersionValue);
    }
    JavaSpecVersion minJavaVersion = null;
    String minJavaVersionValue = plugin.attributeValue("minJavaVersion");
    if (minJavaVersionValue != null && !minJavaVersionValue.isEmpty()) {
        minJavaVersion = new JavaSpecVersion(minJavaVersionValue);
    }
    String releaseDate = null;
    final String releaseDateString = plugin.attributeValue("releaseDate");
    if (releaseDateString != null) {
        try {
            releaseDate = RELEASE_DATE_DISPLAY_FORMAT.format(RELEASE_DATE_FORMAT.parse(releaseDateString));
        } catch (final ParseException e) {
            Log.warn("Unexpected exception parsing release date: " + releaseDateString, e);
        }
    }
    long fileSize = -1;
    String fileSizeValue = plugin.attributeValue("fileSize");
    if (fileSizeValue != null && !fileSizeValue.isEmpty()) {
        fileSize = Long.parseLong(fileSizeValue);
    }
    String canonical = downloadUrlValue != null ? downloadUrlValue.substring(downloadUrlValue.lastIndexOf('/') + 1, downloadUrlValue.lastIndexOf('.')) : null;
    return new AvailablePlugin(pluginName, canonical, description, latestVersion, author, icon, changelog, readme, license, minServerVersion, priorToServerVersion, minJavaVersion, downloadUrl, fileSize, releaseDate);
}
Also used : MalformedURLException(java.net.MalformedURLException) Version(org.jivesoftware.util.Version) JavaSpecVersion(org.jivesoftware.util.JavaSpecVersion) ParseException(java.text.ParseException) URL(java.net.URL) JavaSpecVersion(org.jivesoftware.util.JavaSpecVersion)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 JavaSpecVersion (org.jivesoftware.util.JavaSpecVersion)1 Version (org.jivesoftware.util.Version)1