Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**
     * Makes an absolute URI from the relative id. If the given
     * id is already an URI, it will be returned unchanged.
     * 
     * @param id A relative id
     * @param resType For example <em>track</em> (without namespace!)
     * 
     * @return An absolute URI
     */
    public static String convertIdToURI(String id, String resType) {
        URI absolute;
        try {
            absolute = new URI(id);
        } catch (URISyntaxException e) {
            return "http://musicbrainz.org/" + resType.toLowerCase() + "/" + id;
        }
        if (absolute.getScheme() == null) {
            return "http://musicbrainz.org/" + resType.toLowerCase() + "/" + id;
        }

        // may be already an absolute URI
        return id;
    }
}