/*
 * This file is part of libbluray
 * Copyright (C) 2010  William Hahne
 *
 * 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 (at your option) 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, see
 * <http://www.gnu.org/licenses/>.
 */

package javax.media;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;

public class MediaLocator implements Serializable
{
    public MediaLocator(URL url) {
        this(url.toExternalForm());
    }

    public MediaLocator(String locatorString) {
        int index = locatorString.indexOf(":");
        if (index <= 0)
            throw new IllegalArgumentException("Bad locator string.");
        protocol = locatorString.substring(0, index);
        remainder = locatorString.substring(index + 1);
    }

    public URL getURL() throws MalformedURLException {
        return new URL(toExternalForm());
    }

    public String getProtocol() {
        return protocol;
    }

    public String getRemainder() {
        return remainder;
    }

    public String toString() {
        return toExternalForm();
    }

    public String toExternalForm() {
        return protocol + ":" + remainder;
    }

    private String protocol = "";
    private String remainder = "";

    private static final long serialVersionUID = 1L;
}

@@ -961,218 +961,158 @@
 this
-(url.toExternalForm())
+.url = url
 ;%0A    
-%7D%0A%0A
     
-public MediaLocator(String locatorString) %7B%0A        int index = locatorString.indexOf(%22:%22);%0A        if (index %3C= 0)%0A   
+if (url != null) %7B%0A            this.locatorString = url.toString().trim();%0A        %7D%0A
     
- 
+%7D%0A%0A
     
-throw new IllegalArgumentException(%22Bad
+public MediaLocator(String
  locator
  str
@@ -1111,19 +1111,17 @@
 ator
- s
+S
 tring
-.%22);
+) %7B
 %0A   
@@ -1125,27 +1125,20 @@
         
-protocol = 
+if (
 locatorS
@@ -1146,297 +1146,676 @@
 ring
-.substring(0, index);%0A        remainder = locatorString.substring(index + 1);%0A    %7D%0A%0A    public URL getURL() throws MalformedURLException %7B%0A        return new URL(toExternalForm());%0A    %7D%0A%0A    public String getProtocol() %7B%0A        return protocol;%0A    %7D%0A%0A    public String getRemainder() %7B
+ != null)%0A            this.locatorString = locatorString.trim();%0A    %7D%0A%0A    public URL getURL() throws MalformedURLException %7B%0A        if (url == null) %7B%0A            url = new URL(locatorString);%0A        %7D%0A        return url;%0A    %7D%0A%0A    public String getProtocol() %7B%0A        String protocol = %22%22;%0A        int col = locatorString.indexOf(%22:%22);%0A        if (col %3E= 0) %7B%0A            protocol = locatorString.substring(0, col);%0A        %7D%0A        return protocol;%0A    %7D%0A%0A    public String getRemainder() %7B%0A        String remainder = %22%22;%0A        int col = locatorString.indexOf(%22:%22);%0A        if (col %3E= 0) %7B%0A            remainder = locatorString.substring(col + 1);%0A        %7D
 %0A   
@@ -1971,34 +1971,21 @@
 urn 
-protocol + %22:%22 + remainder
+locatorString
 ;%0A  
@@ -2004,32 +2004,37 @@
 vate String 
-protocol
+locatorString
  = %22%22;%0A    p
@@ -2040,37 +2040,30 @@
 private 
-String remainder = %22%22
+URL url = null
 ;%0A%0A    p

improve compatibility