[DOXIASITETOOLS-109] handle more URI formats (#10)

* handle more URI formats

* restore original behavior

* fix test on Windows

* fix test on Windows

* more whitespace
diff --git a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
index 002402b..f7cea88 100644
--- a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
+++ b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
@@ -126,7 +126,6 @@
     // Public methods
     // ----------------------------------------------------------------------
 
-    /** {@inheritDoc} */
     public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository,
                                                    List<ArtifactRepository> remoteArtifactRepositories,
                                                    DecorationModel decoration )
@@ -174,7 +173,6 @@
         return artifact;
     }
 
-    /** {@inheritDoc} */
     public Artifact getDefaultSkinArtifact( ArtifactRepository localRepository,
                                             List<ArtifactRepository> remoteArtifactRepositories )
         throws SiteToolException
@@ -182,12 +180,27 @@
         return getSkinArtifactFromRepository( localRepository, remoteArtifactRepositories, new DecorationModel() );
     }
 
-    /** {@inheritDoc} */
+    /**
+     * This method is not implemented according to the URI specification and has many weird
+     * corner cases where it doesn't do the right thing. Please consider using a better 
+     * implemented method from a different library such as org.apache.http.client.utils.URIUtils#resolve.
+     */
+    @Deprecated
     public String getRelativePath( String to, String from )
     {
         checkNotNull( "to", to );
         checkNotNull( "from", from );
-
+        
+        if ( to.contains( ":" ) && from.contains( ":" ) )
+        {
+            String toScheme = to.substring( 0, to.lastIndexOf( ':' ) );
+            String fromScheme = from.substring( 0, from.lastIndexOf( ':' ) );
+            if ( !toScheme.equals( fromScheme ) ) 
+            {
+                return to; 
+            }
+        }
+        
         URL toUrl = null;
         URL fromUrl = null;
 
@@ -207,6 +220,7 @@
             catch ( MalformedURLException e1 )
             {
                 getLogger().warn( "Unable to load a URL for '" + to + "': " + e.getMessage() );
+                return to;
             }
         }
 
@@ -223,6 +237,7 @@
             catch ( MalformedURLException e1 )
             {
                 getLogger().warn( "Unable to load a URL for '" + from + "': " + e.getMessage() );
+                return to;
             }
         }
 
@@ -1496,7 +1511,7 @@
         final Properties properties = new Properties();
         final String corePomProperties = "META-INF/maven/org.apache.maven/maven-core/pom.properties";
         final InputStream in = MavenProject.class.getClassLoader().getResourceAsStream( corePomProperties );
-       try
+        try
         {
             properties.load( in );
         }
diff --git a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java
index 0d54c5b..1698e2d 100644
--- a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java
+++ b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java
@@ -23,12 +23,28 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.junit.Before;
 
 /**
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  */
 public class DefaultSiteToolTest
 {
+	
+    private DefaultSiteTool tool = new DefaultSiteTool();
+    
+    @Before 
+    public void setUp() {
+    	Logger logger =  new ConsoleLogger(Logger.LEVEL_WARN, "tool");
+        tool.enableLogging(logger);
+    }
+	
     /**
      * test getNormalizedPath().
      */
@@ -56,4 +72,45 @@
         assertEquals( "file:/Documents and Settings/",
                 DefaultSiteTool.getNormalizedPath( "file://Documents and Settings/" ) );
     }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testGetRelativePath()
+    {
+        assertEquals(
+            ".." + File.separator + "bar.html",
+            tool.getRelativePath("http://example.com/foo/bar.html", "http://example.com/foo/baz.html"));
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testGetRelativePath_same()
+    {
+        assertTrue(
+          tool.getRelativePath( "http://example.com/foo/bar.html", "http://example.com/foo/bar.html" ).isEmpty() );
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testGetRelativePath_differentSchemes() {
+        assertEquals(
+          "scp://example.com/foo/bar.html",
+          tool.getRelativePath( "scp://example.com/foo/bar.html", "http://example.com/foo/bar.html" ) );
+      assertEquals(
+        "file:///tmp/bloop",
+         tool.getRelativePath( "file:///tmp/bloop", "scp://localhost:/tmp/blop" ) );
+    }
+
+    @SuppressWarnings("deprecation")
+    @Test
+    public void testGetRelativePath_differentDomains() {
+        assertEquals(
+          "https://example.org/bar.html",
+          tool.getRelativePath( "https://example.org/bar.html", "https://example.com/bar.html" ) );
+        assertEquals(
+          "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/",
+          tool.getRelativePath(
+            "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/",
+            "dav:https://nexus1.mysite.net:123/nexus/content/sites/site/mysite-parent/1.0.0/" ));
+    }
 }
diff --git a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
index f19ab61..6e12e4c 100644
--- a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
+++ b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
@@ -155,12 +155,11 @@
 
         String to = "http://maven.apache.org/downloads.html";
         String from = "http://maven.apache.org/index.html";
-        // FIXME! assertEquals( "downloads.html", tool.getRelativePath( to, from ) );
 
         // MSITE-600, MSHARED-203
         to = "file:///tmp/bloop";
         from = "scp://localhost:/tmp/blop";
-        // FIXME! assertEquals( tool.getRelativePath( to, from ), to );
+        assertEquals( tool.getRelativePath( to, from ), to );
 
         // note: 'tmp' is the host here which is probably not the intention, but at least the result is correct
         to = "file://tmp/bloop";