Package ipsk.net
Class URLContext
- java.lang.Object
-
- ipsk.net.URLContext
-
public class URLContext extends java.lang.Object
Generates absolute URLs from relative URLs in a given context. This class works much like @see java.net.URL#Constructor(URL context,String spec) .- Author:
- klausj
-
-
Constructor Summary
Constructors Constructor Description URLContext()
URLContext(java.net.URL context)
Creates an URL context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.net.URL
baseContextFromResourceURL(java.net.URL resURL)
java.net.URL
getContext()
Get URL context.java.net.URL
getContextURL(java.lang.String spec)
Creates a URL by parsing the given spec within the specified context.java.net.URL
getContextURL(java.net.URL relURL)
Creates a URL by parsing the given URL within the specified context.static java.net.URL
getContextURL(java.net.URL contextURL, java.lang.String spec)
Creates a URL by parsing the given spec within the specified context.static java.net.URL
getContextURL(java.net.URL contextURL, java.net.URL relURL)
Creates a URL by parsing the given URL within the specified context.static java.net.URL
getContextURLStrict(java.net.URL contextURL, java.lang.String spec)
Creates a URL by parsing the given spec within the specified context.boolean
inContext(java.net.URL url)
static void
main(java.lang.String[] args)
static java.lang.String
relativize(java.net.URL context, java.net.URL url)
java.lang.String
renameContextSpec(java.net.URL newContext, java.lang.String spec)
void
setContext(java.net.URL url)
Set URL context.
-
-
-
Method Detail
-
getContextURL
public java.net.URL getContextURL(java.net.URL relURL) throws java.net.MalformedURLException
Creates a URL by parsing the given URL within the specified context. If context isnull
the given URL is returned. If the URL is relative it is appended to the context. This method works much like the constructor @see java.net.URL#Constructor(URL context,String spec) , but it treats Windows pathnames like "C:/foo" as absolute.- Parameters:
relURL
- the URL to transform- Returns:
- absolute URL in the given context
- Throws:
java.net.MalformedURLException
-
getContextURL
public java.net.URL getContextURL(java.lang.String spec) throws java.net.MalformedURLException
Creates a URL by parsing the given spec within the specified context. If context isnull
an URL from the given spec is created. This method works much like the constructor @see java.net.URL#Constructor(URL context,String spec) , but it treats Windows pathnames like "C:/foo" as absolute.- Parameters:
spec
- URL specifcation- Returns:
- absolute URL in the given context
- Throws:
java.net.MalformedURLException
-
getContextURL
public static java.net.URL getContextURL(java.net.URL contextURL, java.net.URL relURL) throws java.net.MalformedURLException
Creates a URL by parsing the given URL within the specified context. If context isnull
the given URL is returned. If the URL is relative it is appended to the context. This method works much like the constructor @see java.net.URL#Constructor(URL context,String spec) , but it treats Windows pathnames like "C:/foo" as absolute.- Parameters:
contextURL
- the contextrelURL
- the URL to transform- Returns:
- absolute URL in the given context
- Throws:
java.net.MalformedURLException
-
getContextURL
public static java.net.URL getContextURL(java.net.URL contextURL, java.lang.String spec) throws java.net.MalformedURLException
Creates a URL by parsing the given spec within the specified context. If context isnull
an URL from the given spec is created. This method works much like the constructor @see java.net.URL#Constructor(URL context,String spec) , but it treats Windows pathnames like "C:/foo" as absolute. Note: the method accepts relative URLs with scheme part, which are not RFC conform. This URL's are used in Speechrecorder for project dir relative resources, e.g. file:project1_script.xml Use @see ipsk.net.URLContext#getContextURLStrict(URL context,String spec) for strict RFC behavoiur- Parameters:
contextURL
- the contextspec
- URL specifcation- Returns:
- absolute URL in the given context
- Throws:
java.net.MalformedURLException
-
getContextURLStrict
public static java.net.URL getContextURLStrict(java.net.URL contextURL, java.lang.String spec) throws java.net.MalformedURLException
Creates a URL by parsing the given spec within the specified context. If context isnull
an URL from the given spec is created. This method works much like the constructor @see java.net.URL#Constructor(URL context,String spec) , but it treats Windows pathnames like "C:/foo" as absolute.- Parameters:
contextURL
- the contextspec
- URL specifcation- Returns:
- absolute URL in the given context
- Throws:
java.net.MalformedURLException
-
inContext
public boolean inContext(java.net.URL url)
-
renameContextSpec
public java.lang.String renameContextSpec(java.net.URL newContext, java.lang.String spec) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
relativize
public static java.lang.String relativize(java.net.URL context, java.net.URL url)
-
getContext
public java.net.URL getContext()
Get URL context.- Returns:
- the context
-
setContext
public void setContext(java.net.URL url)
Set URL context.- Parameters:
url
- context
-
baseContextFromResourceURL
public static java.net.URL baseContextFromResourceURL(java.net.URL resURL) throws java.net.MalformedURLException
- Throws:
java.net.MalformedURLException
-
main
public static void main(java.lang.String[] args)
-
-