import java.net.URL;

// ...

URL url = new URL( absoluteOrRelativeUrlString );

if ( url.getProtocol().length() == 0 )
   {
   // convert relative URL to absolute
   url = new URL ( getDocumentBase(), url.getPath() );
   }