org.esau.ptarmigan.util
Class HelperURL

java.lang.Object
  |
  +--org.esau.ptarmigan.util.HelperURL

public final class HelperURL
extends java.lang.Object

Some static methods for manipulation of URLs

Version:
$Revision: 1.3 $ $Date: 2002/10/04 11:55:43 $
Author:
Reed Esau

Constructor Summary
HelperURL()
           
 
Method Summary
static java.lang.String fileToSystemId(java.io.File file)
           
static java.lang.String maybeDecode(java.lang.String may_be_coded)
          If the specified string contains only ASCII characters, then try to escape any UTF-8 characters present.
static java.io.File systemIdToFile(java.lang.String system_id)
           
static java.net.URL toURL(java.io.File file)
          produce a UTF-8 encoded URL from a File source
static java.net.URL toURL(java.io.File base_dir, java.lang.String file_or_url)
          produce a UTF-8 encoded URL from various formats.
static java.io.File URLToFile(java.lang.String s_url)
          extract a File object from a UTF-8-encoded URL if the URL has a file protocol.
static java.io.File URLToFile(java.net.URL url)
          extract a File object from a UTF-8-encoded URL if the URL has a file protocol requires URIUtil from Jakarta Common's HttpClient NOTE: if truncation is occurring, it's probably because the URL wasn't encoded in UTF-8.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelperURL

public HelperURL()
Method Detail

systemIdToFile

public static java.io.File systemIdToFile(java.lang.String system_id)

fileToSystemId

public static java.lang.String fileToSystemId(java.io.File file)
                                       throws java.net.MalformedURLException

URLToFile

public static java.io.File URLToFile(java.lang.String s_url)
                              throws java.io.IOException,
                                     java.net.MalformedURLException
extract a File object from a UTF-8-encoded URL if the URL has a file protocol.

Useful for system_ids that specify local sources. BROKEN: may not handle # in filenames

Parameters:
s_url - that is prefixed by "file:" and represents a local file
Returns:
null if not prefixed by "file:"
Throws:
java.net.MalformedURLException - if there's some other problem building the URL

URLToFile

public static java.io.File URLToFile(java.net.URL url)
                              throws java.io.IOException
extract a File object from a UTF-8-encoded URL if the URL has a file protocol requires URIUtil from Jakarta Common's HttpClient NOTE: if truncation is occurring, it's probably because the URL wasn't encoded in UTF-8.
Parameters:
url -  
Returns:
null if URL is not a local file resource
Throws:
java.io.IOException -  

toURL

public static java.net.URL toURL(java.io.File file)
                          throws java.net.MalformedURLException,
                                 java.io.IOException
produce a UTF-8 encoded URL from a File source

toURL

public static java.net.URL toURL(java.io.File base_dir,
                                 java.lang.String file_or_url)
                          throws java.net.MalformedURLException,
                                 java.io.IOException
produce a UTF-8 encoded URL from various formats.

A path in a playlist may be of many different formats. Here we try to figure out which one and assign to a URL.

Convert

   C:\Billie Holiday\Body and Soul\01 - Body And Soul.mp3
   file:C:\Billie Holiday\Body and Soul\01 - Body And Soul.mp3
   file:/C:\Billie Holiday\Body and Soul\01 - Body And Soul.mp3
   file:/C%3A\Billie Holiday\Body and Soul\01 - Body And Soul.mp3
 
to
   file:/C:/Billie Holiday/Body and Soul/01%20-%20Body%20And%20Soul.mp3
 
Parameters:
base_dir - File the directory to be used with relative file paths
file_or_url - String the url or file path that needs to be resolved
Returns:
a valid URL
Throws:
java.net.MalformedURLException -  
java.io.IOException -  

maybeDecode

public static java.lang.String maybeDecode(java.lang.String may_be_coded)
                                    throws java.text.ParseException
If the specified string contains only ASCII characters, then try to escape any UTF-8 characters present.

This is tolerant of bad coding and will return null if decoding was not done.

Returns:
the decoded string; or original string if decoding not necessary
Throws:
java.text.ParseException - if decoding failed


Copyright © 2002 Reed Esau, All Rights Reserved.