swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
    Other Library Functions  
function  

uri.extend

 
 

Library: URI handling (OMURI)
Import: omuri.xmd
Return type: String

Returns: the resolved relative-uri


Declaration

export string function
   extend      value string base-uri
          with value string relative-uri
  

Argument definitions

base-uri
is an absolute or relative URI reference.
relative-uri
is a URI reference relative to base-uri.


Purpose

The function uri.extend resolves relative URI references. If base-uri is an absolute URI and relative-uri is a relative one, the result will be an absolute URI reference. If they are both relative, the result of uri.extend will be a relative URI.

There are two exceptional cases. If relative-uri is an absolute URI itself, uri.extend throws uri.already-absolute to indicate that. Alternatively, if relative-uri consists only of a URI fragment (e.g. "#section1"), uri.extend throws uri.current-document-reference. Neither exception has any parameters.

In the following example, the function fetch-fresh-page uses uri.extend to resolve HTTP redirections and access the content of an HTML page even if it has been moved to a new location.

  import "omuri.xmd" prefixed by uri.
  import "omvfs.xmd" prefixed by vfs.
    
  define string source function
     fetch-fresh-page value string url
  as
     local vfs.file html-page initial { vfs.open-http url }
  
     do scan vfs.reader of html-page
     match ul '<html>' white-space*
              '<meta' white-space+ 'http-equiv="refresh"' white-space+
              'content="0; url=' any ** => new-url '"' white-space* '>'
        output fetch-fresh-page uri.extend url with new-url
  
      ; uri.current-document-reference cannot be handled here
      catch uri.already-absolute
        output fetch-fresh-page new-url
  
     else
        output #current-input
     done

      Other Library Functions
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:38:10 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.