Package ipsk.net

Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URLContext

        public URLContext()
      • URLContext

        public URLContext​(java.net.URL context)
        Creates an URL context.
        Parameters:
        context - the 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 is null 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 is null 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 is null 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 context
        relURL - 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 is null 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 context
        spec - 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 is null 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 context
        spec - 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)