Skip Headers

Oracle9i XML API Reference - XDK and Oracle XML DB
Release 2 (9.2)

Part Number A96616-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

35
Database URI Types

This chapter contains the following sections:


URI Support


Description

Oracle9i supports the UriType family of types that can be used to store and query Uri-refs inside the database. The UriType itself is an abstract object type and the HttpUriType, XDBUriType and DBUriType are subtypes of it.

You can create a UriType column and store instances of the DBUriType, XDBUriType or the HttpUriType inside of it.

You can also define your own subtypes of the UriType to handle different URL protocols.

Oracle9i also provides a UriFactory package that can be used as a factory method to automatically generate various instances of these UriTypes by scanning the prefix (for example, http:// or /oradb). You can also register your subtype and provide the prefix that you support. For instance, if you have written a subtype to handle the gopher protocol, you can register the prefix gopher:// to be handled by your subtype. The UriFactory will then generate your subtype instance for any URL starting with that prefix.

Table 35-1 URI Support Types
Type Description

UriType Super Type

An abstract type that is the base type of the database URI types.

HttpUriType Subtype

The HTTP implementation of URI type.

DBUriType Subtype

The implementation of URI type referencing database objects.

XDBUriType Subtype

The implementation of URI type referencing Oracle XML DB objects.

UriFactory Package

Package that generates the appropriate URI type for the given URI.


UriType Super Type


Description of UriType

The UriType is the abstract super type. It provides a standard set of functions to get the value pointed to by the URI. The actual implementation of the protocol must be defined by the subtypes of this type.

Instances of this type cannot be created directly. However, you can create columns of this type and store subtype instances in it.

For example,

    create table uri_tab ( url uritype);

insert into uri_tab values  
  (httpuritype.createuri('http://www.oracle.com'));
insert into uri_tab values 
  (dburitype.createuri('/SCOTT/EMPLOYEE/ROW[ENAME="Jack"]'));

Now you can select from the column without having to know what instance of the URL is actually stored. The following line of code would retrieve both the HTTP URL and the DBUri-ref:

select e.url.getclob() from uri_tab e;

Functions and Procedures of UriType

Table 35-2 Summary of Functions and Procedures of UriType  
Function Description

getBlob()

Returns the BLOB located at the address specified by the URL.

getClob()

Returns the CLOB located at the address specified by the URL.

getContentType()

Returns the URL, in escaped format, stored inside the UriType instance.

getExternalUrl()

Returns the URL, in escaped format, stored inside the UriType instance.

getUrl()

Returns the URL, in non-escaped format, stored inside the UriType instance.

getXML()

Returns the XMLType located at the address specified by the URL.

getBlob()

Description

This function returns the BLOB located at the address specified by the URL. This function can be overridden in the subtype instances. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getBlob()

RETURN blob;

This function returns the BLOB located at the address specified by the URL.

MEMBER FUNCTION getBlob(

content OUT VARCHAR2)

RETURN blob;

This function returns the BLOB located at the address specified by the URL and and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getClob()

Description

This function returns the CLOB located at the address specified by the URL. This function can be overridden in the subtype instances. This function returns either a permanent CLOB or a temporary CLOB. If a temporary CLOB is returned, it must be freed. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getClob()

RETURN clob;

This function returns the CLOB located at the address specified by the URL.

MEMBER FUNCTION getClob(

content OUT VARCHAR2)

RETURN clob;

This function returns the CLOB located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getContentType()

Description

This function returns the content type of the document pointed to by the URI. This function can be overridden in the subtype instances. This function returns the content type as VARCHAR2.

Syntax

MEMBER FUNCTION getContentType() RETURN VARCHAR2;

getExternalUrl()

Description

This function returns the URL, in escaped format, stored inside the UriType instance. The subtype instances override this member function to provide additional semantics. For instance, the HttpUriType function does not store the prefix http:// in the URL itself. When generating the external URL, it appends the prefix and generates it. For this reason, use the getExternalUrl function or the getUrl function to get to the URL value instead of using the attribute present in the UriType instance.

Syntax

MEMBER FUNCTION getExternalUrl() RETURN varchar2;

getUrl()

Description

This function returns the URL, in non-escaped format, stored inside the UriType instance. The subtype instances override this member function to provide additional semantics. For instance, the HttpUriType function does not store the prefix http:// in the URL itself. When generating the external URL, it appends the prefix and generates it. For this reason, use the getExternalUrl function or the getUrl function to get to the URL value instead of using the attribute present in the UriType instance.

Syntax

MEMBER FUNCTION getUrl() RETURN varchar2;

getXML()

Description

This function returns the XMLType located at the address specified by the URL. This function can be overridden in the subtype instances. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getXML()

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL.

MEMBER FUNCTION getXML(

content OUT VARCHAR2)

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.


HttpUriType Subtype


Description of HttpUriType

The HttpUriType is a subtype of the UriType that provides support for the HTTP protocol. This uses the UTL_HTTP package underneath to access the HTTP URLs. Proxy and secure wallets are not supported in this release.

The following example creates a uri table to store the Http instances

     create table uri_tab ( url httpuritype);

Insert the Http instance.

     insert into uri_tab values 
         (httpuritype.createUri('http://www.oracle.com'));

Generate the HTML

     select e.url.getclob() from uri_tab e;

Functions and Procedures of HttpUriType

Table 35-3 Summary of Functions and Procedures of HttpUriType  
Function Description

createUri()

Creates an instance of HTTPURIType from the given URI.

getBlob()

Returns the BLOB located at the address specified by the URL.

getClob()

Returns the CLOB located at the address specified by the URL.

getContentType()

Returns the content type of the document pointed to by the URI.

getExternalUrl()

Returns the URL, in escaped format, stored inside the UriType instance.

getUrl()

Returns the URL, in non-escaped format, stored inside the UriType instance.

getXML()

Returns the XMLType located at the address specified by the URL

httpUriType()

Creates an instance of HTTPURIType from the given URI.

createUri()

Description

This static function constructs a HttpUriType instance. The HttpUriType instance does not contain the prefix http:// in the stored URL.

Syntax

STATIC FUNCTION createUri(url IN varchar2) RETURN HttpUriType;

Parameter IN / OUT Description

url

(IN)

The URL string containing a valid HTTP URL. The URL string is expected in escaped format. For example, non-url characters are represented as the hexadecimal value for the UTF-8 encoding of those characters.

getBlob()

Description

This function returns the BLOB located at the address specified by the HTTP URL. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getBlob()

RETURN blob;

This function returns the BLOB located at the address specified by the HTTP URL.

MEMBER FUNCTION getBlob(

content OUT VARCHAR2)

RETURN blob;

This function returns the BLOB located at the address specified by the HTTP URL and and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getClob()

Description

This function returns the CLOB located at the address specified by the HTTP URL. This function returns either a permanent CLOB or a temporary CLOB. If a temporary CLOB is returned, it must be freed. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getClob()

RETURN clob;

Returns the CLOB located at the address specified by the HTTP URL.

MEMBER FUNCTION getClob(

content OUT VARCHAR2)

RETURN clob;

Returns the CLOB located at the address specified by the HTTP URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getContentType()

Description

Returns the content type of the document pointed to by the URI.

Syntax

MEMBER FUNCTION getContentType() RETURN VARCHAR2;

getExternalUrl()

Description

This function returns the URL, in escaped format, stored inside the HttpUriType instance. The subtype instances override this member function to provide additional semantics. The HttpUriType function does not store the prefix http:// in the URL itself. When generating the external URL, it prepends the prefix and generates it.

Syntax

MEMBER FUNCTION getExternalUrl() RETURN varchar2;

getUrl()

Description

This function returns the URL, in non-escaped format, stored inside the HttpUriType instance.

Syntax

MEMBER FUNCTION getUrl() RETURN varchar2;

getXML()

Description

This function returns the XMLType located at the address specified by the URL. An error tis thrown if the address does not point to a valid XML doc. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getXML()

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL.

MEMBER FUNCTION getXML(

content OUT VARCHAR2)

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

httpUriType()

Description

This constructs a HttpUriType instance. The HttpUriType instance does not contain the prefix http:// in the stored URL.

Syntax

CONSTRUCTOR FUNCTION httpUriType(url IN varchar2);

Parameter IN / OUT Description

url

(IN)

The URL string containing a valid HTTP URL. The URL string is expected in escaped format. For example, non-url characters are represented as the hexadecimal value for the UTF-8 encoding of those characters.


DBUriType Subtype


Description of DBUriType

The DBUriType is a subtype of the UriType that provides support for of DBUri-refs. A DBUri-ref is an intra-database URL that can be used to reference any row or row-column data in the database. The URL is specified as an XPath expression over a XML visualization of the database. The schemas become elements which contain tables and views. These tables and view further contain the rows and columns inside them.

For example, the virtual document that a user scott can see can be:

     <?xml version="1.0"?>
     <ORADB>
       <SCOTT>
         <EMPLOYEE>
           <ROWSET>
              <ROW>
               <EMPNO>100</EMPNO>
               <ENAME>John</ENAME>
               <ADDRESS>
                  <STREET>100 Main Street</STREET>
                  <CITY>Jacksonville</CITY>
                  <STATE>FL</STATE>
                  <ZIP>32607</ZIP>
                </ADDRESS>
              </ROW>
              <ROW>
                <EMPNO>200</EMPNO>
                <ENAME>Jack</ENAME>
                <ADDRESS>
                  <STREET>200 Front Street</STREET>
                  <CITY>San Francisco</CITY>
                  <STATE>CA</STATE>
                  <ZIP>94011</ZIP>
                </ADDRESS>
              </ROW>
            </ROWSET>
          </EMPLOYEE>
        </SCOTT>
      </ORADB>

Hence, to reference the State attribute inside the employee table, you can formulate a DBUri-ref as shown:

     /ORADB/SCOTT/EMPLOYEE/ROW[ENAME="Jack"]/ADDRESS/STATE

You can use the DBUriType to create instances of these and store them in columns.


Create a table

     create table dburi_tab (dburl dburitype);

Insert values

     insert into dburi_tab values (
        dburitype.createUri(  
             '/ORADB/SCOTT/EMPLOYEE/ROW[ENAME="Jack"]/ADDRESS/STATE'));
     select e.dburl.getclob() from dburi_tab e;

Will return

     <?xml version="1.0"?>
     <STATE>CA</STATE>

You can also generate the DBUri-ref dynamically using the SYS_DBURIGEN SQL function.

For example you can generate a DBUri-ref to the state attribute as shown:

select sys_dburigen( e.ename, e.address.state) AS urlcol
     from scott.employee e;

Functions and Procedures of DBUriType

Table 35-4 Summary of Functions and Procedures of DBUriType  
Function Description

createUri()

Constructs a DBUriType instance.

DBUriType()

Creates an instance of DBURIType from the given URI.

getBlob()

Returns the BLOB located at the address specified by the DBUriType instance.

getClob()

Returns the CLOB located at the address specified by the DBUriType instance.

getContentType()

Returns the content type of the document pointed to by the URI.

getExternalUrl()

Returns the URL, in escaped format, stored inside the DBUriType instance.

getUrl()

Returns the URL, in non-escaped format, stored inside the DBUriType instance.

getXML()

Returns the XMLType located at the address specified by the URL

createUri()

Description

This static function constructs a DBUriType instance. Parses the URL given and creates a DBUriType instance.

Syntax

STATIC FUNCTION createUri( url IN varchar2) RETURN DBUriType;

Parameter IN / OUT Description

url

(IN)

The URL string, in escaped format, containing a valid DBUri reference.

DBUriType()

Description

This constructs a DBUriType instance.

Syntax

CONSTRUCTOR FUNCTION DBUriType( url IN varchar2);

Parameter IN / OUT Description

url

(IN)

The URL string containing a valid DBUri reference.The URL string is expected in escaped format. For example, non-URL characters are represented as the hexadecimal value for the UTF-8 encoding of those characters.

getBlob()

Description

This function returns the BLOB located at the address specified by the URL. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getBlob()

RETURN blob;

This function returns the BLOB located at the address specified by the URL.

MEMBER FUNCTION getBlob(

content OUT VARCHAR2)

RETURN blob;

This function returns the BLOB located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getClob()

Description

This function returns the CLOB located at the address specified by the DBUriType instance. If a temporary CLOB is returned, it must be freed. The document returned may be an XML document or a text document. When the DBUri-ref identifies an element in the XPath, the result is a well-formed XML document. On the other hand, if it identifies a text node (using the text() function), then what is returned is only the text content of the column or attribute. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getClob()

RETURN clob;

Returns the CLOB located at the address specified by the DBUirType instance.

MEMBER FUNCTION getClob(

content OUT VARCHAR2)

RETURN clob;

Returns the CLOB located at the address specified by the DBUirType instance and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getContentType()

Description

This function returns the content type of the document pointed to by the URI.

Syntax

MEMBER FUNCTION getContentType() RETURN VARCHAR2;

getExternalUrl()

Description

This function returns the URL, in escaped format, stored inside the DBUriType instance. The DBUri servlet URL that processes the DBUriType has to be appended before using the escaped URL in web pages.

Syntax

MEMBER FUNCTION getExternalUrl() RETURN varchar2;

getUrl()

Description

This function returns the URL, in non-escaped format, stored inside the DBUriType instance.

Syntax

MEMBER FUNCTION getUrl() RETURN varchar2;

getXML()

Description

This function returns the XMLType located at the address specified by the URL. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getXML()

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL.

MEMBER FUNCTION getXML(

content OUT VARCHAR2)

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.


XDBUriType Subtype


Description of XDBUriType

XDBUriType is a new subtype of URIType. It provides a way to expose documents in the Oracle XML DB hierarchy as URIs that can be embedded in any URIType column in a table. The URL part of the URI is the hierarchical name of the XML document it refers to. The optional fragment part uses the XPath syntax, and is separated from the URL part by '#'. The more general XPointer syntax for specifying a fragment is not currently supported.


Functions and Procedures of XDBUriType

Table 35-5 Summary of Functions and Procedures XDBUriType Functions  
Function Description

createUri()

Returns the UriType corresponding to the specified URL.

getBlob()

Returns the BLOB corresponding to the contents of the document specified by the XDBUriType instance.

getClob()

Returns the CLOB corresponding to the contents of the document specified by the XDBUriType instance.

getContentType()

Returns the content type of the document pointed to by the URI.

getExternalUrl()

Returns the URL, in escaped format, stored inside the XDBUriType instance.

getUrl()

Returns the URL, in non-escaped format, stored inside the XDBUriType instance.

getXML()

Returns the XMLType corresponding to the contents of the document specified by the URL.

XDBUriType()

Creates an instance of XDBURIType from the given URI.

createUri()

Description

This static function constructs a XDBUriType instance. Parses the URL given and creates a XDBUriType instance.

Syntax

STATIC FUNCTION createUri(url IN varchar2) RETURN XDBUriType;
Parameter IN / OUT Description

url

(IN)

The URL string, in escaped format, containing a valid XDBUri reference.

getBlob()

Description

This function returns the BLOB located at the address specified by the XDBUriType instance. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getBlob()

RETURN blob;

This function returns the BLOB located at the address specified by the URL.

MEMBER FUNCTION getBlob(

content OUT VARCHAR2)

RETURN blob;

This function returns the BLOB located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getClob()

Description

This function returns the CLOB located at the address specified by the XDBUriType instance. If a temporary CLOB is returned, it must be freed. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getClob()

RETURN clob;

Returns the CLOB located at the address specified by the DBUirType instance.

MEMBER FUNCTION getClob(

content OUT VARCHAR2)

RETURN clob;

Returns the CLOB located at the address specified by the DBUirType instance and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

getContentType()

Description

This function returns the content type of the document pointed to by the URI. This function returns the content type as VARCHAR2.

Syntax

MEMBER FUNCTION getContentType() RETURN VARCHAR2;

getExternalUrl()

Description

This function returns the URL, in escaped format, stored inside the XDBUriType instance.

Syntax

MEMBER FUNCTION getExternalUrl() RETURN varchar2;

getUrl()

Description

This function returns the URL, in non-escaped format, stored inside the XDBUriType instance.

Syntax

MEMBER FUNCTION getUrl() RETURN varchar2;

getXML()

Description

This function returns the XMLType located at the address specified by the URL. The options are described in the following table.

Syntax Description

MEMBER FUNCTION getXML()

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL.

MEMBER FUNCTION getXML(

content OUT VARCHAR2)

RETURN XMLType;

This function returns the XMLType located at the address specified by the URL and the content type.

Parameter IN / OUT Description

content

(OUT)

Content type of the document to which URI is pointing.

XDBUriType()

Description

This constructs a XDBUriType instance.

Syntax

CONSTRUCTOR FUNCTION XDBUriType( url IN varchar2);

Parameter IN / OUT Description

url

(IN)

The URL string containing a valid XDBUri reference.The URL string is expected in escaped format. For example, non-URL characters are represented as the hexadecimal value for the UTF-8 encoding of those characters.


UriFactory Package


Description of UriFactory

The UriFactory package contains factory methods that can be used to generate the appropriate instance of the URI types without having to hard code the implementation in the program.

The UriFactory package also provides the ability to register new subtypes of the UriType to handle various other protocols not supported by Oracle9i. For example, one can invent a new protocol ecom:// and define a subtype of the UriType to handle that protocol and register it with UriFactory. After that any factory method would generate the new subtype instance if it sees the ecom:// prefix.

For example,

     create table url_tab (urlcol varchar2(20));

Insert a Http reference

     insert into url_tab values ('http://www.oracle.com');

Insert a DBuri-ref reference

     insert into url_tab values ('/SCOTT/EMPLOYEE/ROW[ENAME="Jack"]');

Create a new type to handle a new protocol called ecom://

     create type EComUriType under UriType
     (
       overriding member function getClob() return clob,
       overriding member function getBlob() return blob, 
          -- not supported
       overriding member function getExternalUrl() return varchar2,
       overriding member function getUrl() return varchar2,

       -- MUST NEED THIS for registering with the url handler
       static member function createUri(url in varchar2) 
              return EcomUriType
     );

Register a new protocol handler:

     begin
          -- register a new handler for ecom:// prefixes. The handler
          -- type name is ECOMURITYPE, schema is SCOTT
          -- Ignore the prefix case, when comparing and also strip 
          -- the prefix before calling the createUri function
          urifactory.registerHandler('ecom://','SCOTT','
                                      ECOMURITYPE', true,true);
     end;

     insert into url_tab values ('ECOM://company1/company2=22/comp');

Now use the factory to generate the instances

     select urifactory.getUri(urlcol) from url_tab;

Would now generate

     HttpUriType('www.oracle.com');  
             -- an Http uri type instance

     DBUriType('/SCOTT/EMPLOYEE/ROW[ENAME="Jack"],null); 
             -- a DBUriType

     EComUriType('company1/company2=22/comp');
             -- a EComUriType instance

Functions and Procedures of URIFactory

Table 35-6 Summary of Functions and Procedures of UriFactory  
Method Description

getUri()

Returns the correct URL handler for the given URL string.

escapeUri()

Returns a URL in escaped format.

unescapeUri()

Returns a URL in unescaped format.

registerUrlHandler()

Registers a particular type name for handling a particular URL.

unRegisterUrlHandler()

Unregisters a URL handler.

getUri()

Description

This factory method returns the correct URL handler for the given URL string. It returns a subtype instance of the UriType that can handle the protocol. By default, it always creates an XDBUriType instance, if it cannot resolve the URL. A URL handler can be registered for a particular prefix using the registerUrlHandler() function. If the prefix matches, getUrl() would then use that subtype.

Syntax

FUNCTION getUrl(url IN Varchar2) RETURN UriType;

Parameter IN / OUT Description

url

(IN)

The URL string, in escaped format, containing a valid HTTP URL.

escapeUri()

Description

This function returns a URL in escaped format. The subtype instances override this member function to provide additional semantics. For instance, the HttpUriType does not store the prefix http:// in the URL itself. When generating the external URL, it appends the prefix and generates it. For this reason, use the getExternalUrl function or the getUrl function to get to the URL value instead of using the attribute present in the UriType.

Syntax

MEMBER FUNCTION escapeUri() RETURN varchar2;

Parameter IN / OUT Description

url

(IN)

The URL string to be returned in escaped format.

unescapeUri()

Description

This function returns a URL in unescaped format. This function is the reverse of the escapeUri function. This function scans the string and converts any non-URL hexadecimal characters into the equivalent UTF-8 characters. Since the return type is a VARCHAR2, the characters would be converted into the equivalent characters as defined by the database character set.

Syntax

FUNCTION unescapeUri() RETURN varchar2;

Parameter IN / OUT Description

url

(IN)

The URL string to be returned in unescaped format.

registerUrlHandler()

Description

This procedure registers a particular type name for handling a particular URL. The type specified must be valid and must be a subtype of the UriType or one of its subtypes. It must also implement the following static member function:

    STATIC FUNCTION createUri(url IN varchar2) RETURN <typename>;



This function is called by the getUrl() function to generate an instance of the type. The stripprefix parameter indicates that the prefix must be stripped off before calling this function.

Syntax

PROCEDURE registerUrlHandler( prefix IN varchar2,
                              schemaName IN varchar2,
                              typename IN varchar2,
                              ignoreCase IN boolean := true,
                              stripprefix IN boolean := true);

Parameter IN / OUT Description

prefix

(IN)

The prefix to handle; for example, http://.

schemaName

(IN)

The name of the schema where the type resides; case sensitive.

typename

(IN)

The name of the type to handle the URL; case sensitive.

ignoreCase

(IN)

Ignore case when matching prefixes.

stripprefix

(IN)

Strip prefix before generating the instance of the type.

unRegisterUrlHandler()

Description

This procedure unregisters a URL handler. This only unregisters user registered handler prefixes and not predefined system prefixes such as http://.

Syntax

PROCEDURE unregisterUrlHandler(prefix IN varchar2);

Parameter IN / OUT Description

prefix

(IN)

The prefix to be unregistered.


Go to previous page Go to next page
Oracle
Copyright © 2001, 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback