<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?vsp
--
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--
--  Copyright (C) 1998-2018 OpenLink Software
--
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
?><?vsp declare _path,_domain varchar;
      _domain := 'http://' || regexp_replace(HTTP_GET_HOST(),':80$','');
      _path := _domain || http_map_get('domain') || '/';
    ?>
<html>
 <head>
  <meta name="DESCRIPTION" content="Virtuoso Developer Tutorial" />
  <title>Virtuoso Tutorial - Web Services (SOAP,WSDL,UDDI) - DC-S-1</title>
  <meta name="KEYWORDS" content="SOAP, WSDL, UDDI, WS-Security, WS-ReliableMessaging, WS-Routing, Web Services, BPEL4WS, WS-Eventing, WebDAV, XML For Analysis, xmla, WS-Attachments, udf, udt, user defined types, user defined functions" />
  <link rel="alternate" type="application/rss+xml" title="Virtuoso Screencast Demos" href="http://support.openlinksw.com/viewlets/virtuoso_viewlets_rss.vsp" />
  <link rel="alternate" type="application/rss+xml" title="Virtuoso Tutorials" href="http://demo.openlinksw.com/tutorial/rss.vsp" />
  <link rel="alternate" type="application/rss+xml" title="Virtuoso Product Blog (RSS 2.0)" href="http://www.openlinksw.com/weblogs/virtuoso/gems/rss.xml" />
  <link rel="alternate" type="application/atom+xml" title="Virtuoso Product Blog (Atom)" href="http://www.openlinksw.com/weblogs/virtuoso/gems/atom.xml" />
  <link href="../../tutorial3.css" rel="stylesheet" type="text/css" />
  <link href="../../syntax/SyntaxHighlighter.css" rel="stylesheet" type="text/css" />
  <link rel="meta" type="application/rdf+xml" title="SIOC" href="<?V _path ?>sioc.vsp" />
 </head>
 <body>
  <table border="0" cellpadding="0" cellspacing="0" id="top">
   <tr>
    <td id="topnav"><img src="../../images/vtutorials_thin550.gif" alt="Virtuoso Developer Tutorial" width="550" height="75" />
    </td>
   </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="0" id="main">
   <tr>
    <td id="left">
     <ul class="lftmenu">
        <li class="lftmenu_title">Tutorial Quick Links</li>
      <li class="lftmenu1">
          <img src="../../images/vglobe_16.png" alt="Virtuoso Start Menu" title="Virtuoso Start Menu" />&nbsp;<a target="_blank" href="/">Virtuoso Start Menu</a>
      </li>
      <li class="lftmenu1">
          <img src="../../images/nav_arrow1.gif" alt="Virtuoso Conductor" title="Virtuoso Conductor" />&nbsp;<a target="_blank" href="/conductor/">Virtuoso Conductor</a>
      </li>
     </ul>
     <ul class="lftmenu">
        <li class="lftmenu_title">Reference</li>
        <li class="lftmenu_info">For a quick look up of any feature, function, or review of language syntax</li>
      <li class="lftmenu1">
          <img src="../../images/docs_16.png" alt="Documentation" title="Documentation" hspace="2" />&nbsp;<a href="/doc/docs.vsp" target="_empty">Documentation</a>
      </li>
      <li class="lftmenu1">
          <img src="../../images/nav_arrow1.gif" alt="Tutorial Quick Start Guide" title="Tutorial Quick Start Guide" hspace="2" />&nbsp;<a href="../../guide.vsp">Tutorial Quick Start Guide</a>
      </li>
      <li class="lftmenu1">
          <img src="../../images/docs_16.png" alt="Functions Index" title="Functions Index" hspace="2" />&nbsp;<a href="/doc/html/functions.html" target="_empty">Functions Index</a>
      </li>
     </ul>
     <div class="lftmenu">
        <div class="lftmenu_title">search</div>
      <div class="lftmenu1">
       <form method="get" action="../../search.vsp" style="display:inline;"><input type="text" name="q" id="q" value="" size="17" /><input name="post" value="Go" title="Search" alt="Search" type="submit" />
       </form>
      </div>
     </div>
     <ul class="lftmenu">
      <li class="lftmenu_title">
          <a href="http://www.openlinksw.com/weblogs/virtuoso/" target="_blank">Virtuoso Blog</a>
      </li>
        <li class="lftmenu_info">Check out the latest technology buzz on the Virtuoso Blog</li>
      <li class="lftmenu1">
          <a target="_blank" href="../../atom.vsp"><img src="../../images/blue-icon-16.gif" border="0" alt="ATOM" title="ATOM" hspace="3" />Atom</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../rss.vsp"><img src="../../images/rss-icon-16.gif" border="0" alt="RSS" title="RSS" hspace="3" />RSS</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../rdf.vsp"><img src="../../images/rdf-icon-16.gif" border="0" alt="RDF" title="RDF" hspace="3" />RDF</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../ocs.vsp"><img src="../../images/blue-icon-16.gif" border="0" alt="OCS" title="OCS" hspace="3" />OCS</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../opml.vsp"><img src="../../images/blue-icon-16.gif" border="0" alt="OPML" title="OPML" hspace="3" />OPML</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../xbel.vsp"><img src="../../images/blue-icon-16.gif" border="0" alt="XBEL" title="XBEL" hspace="3" />XBEL</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../sioc.vsp"><img src="../../images/rdf-icon-16.gif" border="0" alt="SIOC(RDF/XML)" title="SIOC(RDF/XML)" hspace="3" />SIOC(RDF/XML)</a>
      </li>
      <li class="lftmenu1">
          <a target="_blank" href="../../sioc_ttl.vsp"><img src="../../images/rdf-icon-16.gif" border="0" alt="SIOC(N3/Turtle)" title="SIOC(N3/Turtle)" hspace="3" />SIOC(N3/Turtle)</a>
      </li>
     </ul>
     <div class="lftmenu">
      <div class="lftmenu_info">Version: <?V sys_stat ('st_dbms_ver') ?>
      </div>
      <div class="lftmenu_info">Build: <?V sys_stat ('st_build_date') ?>
      </div>
     </div>
     <a target="_blank" href="http://www.openlinksw.com/virtuoso"><img alt="Powered by OpenLink Virtuoso Universal Server" src="../../images/PoweredByVirtuoso.gif" border="0" />
     </a>
    </td>
    <td id="right">
     <div id="navtabs">
      <table border="0" cellspacing="0" cellpadding="0">
       <tr>
        <td nowrap="nowrap" class="navtab_non_sel"><a href="../../hosting/">Data Management</a>
        </td>
            <td nowrap="nowrap" class="navtab_sel">Web Services</td>
        <td nowrap="nowrap" class="navtab_non_sel"><a href="../../bpeldemo/">Business Process Integration</a>
        </td>
        <td nowrap="nowrap" class="navtab_non_sel"><a href="../../web/">Development</a>
        </td>
        <td nowrap="nowrap" class="navtab_non_sel"><a href="../../apps/">Demo applications</a>
        </td>
       </tr>
      </table>
      <table border="0" cellpadding="0" cellspacing="0" id="navtabs2">
       <tr>
        <td nowrap="nowrap" class="navtab_sel2"><a href="../../services/">SOAP Services</a>
        </td>
        <td nowrap="nowrap" class="navtab_non_sel2"><a href="../../wap/">Wireless Access Protocols</a>
        </td>
       </tr>
      </table>
     </div>
     <div id="mainarea">
        <script language="JavaScript" type="text/javascript">
      var URL = '<?V http_path() ?>';
    </script><script language="JavaScript" src="../../example.js" type="text/javascript"></script>
      <div class="exp_nav">
          <img src="../../images/rewnd_16.png" alt="previous example" title="previous example" /> <a href="../../services/ud_s_3/ud_s_3.vsp">previous example</a> | <a href="../../services/">index</a> | <a href="../../wap/wa_b_1/wa_b_1.vsp">next example</a> <img src="../../images/fastf_16.png" alt="next example" title="next example" />
      </div>
      <div id="ex_navcontainer">
       <ul id="ex_navlist">
        <li>
              <a href="#" id="tab_info" onclick="toggle_tab('info')" class="current">Info</a>
        </li>
        <li>
              <a href="#" id="tab_initial_state" onclick="toggle_tab('initial_state')">Initial State</a>
        </li>
        <li>
              <a href="#" id="tab_view_source" onclick="toggle_tab('view_source')">View Source</a>
        </li>
        <li>
              <a href="#" id="tab_run" onclick="toggle_tab('run')">Run</a>
        </li>
       </ul>
      </div>
      <div id="info">
          <h1>WebID Identity Provider (IdP)</h1>
          <h2>IdP-S-1 Checking if WebID and specific Public Key are in a relation</h2>
          <h3>Checking WebID</h3>
          <h4>Example</h4>
          <ul>
            <li>The service is an alternative to using SPARQL queries via the SPARQL protocol against Virtuoso endpoints re. WebID verification i.e., lookup a profile graph to see if WebID and specific Public Key are in a relation.</li>
            <li>The webid_demo.vsp is a vsp page which implements WebID checking.</li>
            <li>The webid_demo.php is a PHP page which implements WebID checking.</li>
            <li>The webid_demo.html is a HTML (JS) page which implements WebID checking.</li>
          </ul> 


<?vsp
  declare f, tmp, description, pwd, current_page, current_loc, title, ht_description, ht_path, start_view, error varchar;
  declare sources, xt, start_l, load_l, load_c, demo_db, dep_vdb, dav_vsp, http_thr, xform_br, xslt_result any;
  declare i, j, len, sl, have_vsp, have_sql, have_init, show_desc integer;
  declare src_path, tutcss varchar;
  declare srv_cert, srv_key, srv_ca, cli_cert, deps, dependa, uagent varchar;
  declare is_moz, is_ie int;
  declare listed_src any;
  declare auth, current_page_auth varchar;
  declare user_agent,only_browser varchar;
  declare no_run int;
  declare showed_init_state int;
  no_run := 0;
  showed_init_state := 0;

  user_agent := http_request_header(lines, 'User-Agent', null, '');

  f := {?'f'};
  if (f is null)
    f := '1';
  f := '1';
  error := ''; show_desc := 1; src_path := ''; dependa := '';
  ht_path := http_physical_path ();
  if (ht_path like '%/dev.vsp')   -- exeption in development state
    ht_path := substring(http_physical_path(),1,length(http_physical_path()) - 8) || substring(http_path (),length(http_map_get('domain')) + 1,length(http_path ()));
  sl := strrchr (ht_path, '/');
  current_loc := substring (http_path(), 1, strrchr(http_path(),'/'));
  pwd := t_get_pwd (substring (ht_path, 1, sl));
  current_page := substring (ht_path, sl + 2, length (ht_path));
  current_page_auth := current_page;
  auth := '';
  if (connection_get('sid') is not null)
  {
   auth := auth || '?sid=' || connection_get('sid');
   auth := auth || '&realm=' || connection_get('realm') || '&';
  } else
     auth := '?';
  current_page_auth := current_page_auth || auth;
  start_view := null;
  listed_src := null;

  if (get_keyword ('load_scr_reset', params, '') <> '')
  {
    http_rewrite ();
    http_header ('Content-Type: text/html\r\n');

    if(not(registry_get('tutorial_'||current_page||'_completed') <> 0
       and cast(registry_get('tutorial_'||current_page||'_completed') as integer) < 100
       and cast(registry_get('tutorial_'||current_page||'_completed') as integer) > 0
       and registry_get('tutorial_'||current_page||'_started') <> 0
       and cast(registry_get('tutorial_'||current_page||'_started') as datetime ) > dateadd('second',(msec_time()/1000) * -1,now())))
    {
      registry_set('tutorial_'||current_page||'_completed','0');
      registry_set('tutorial_'||current_page||'_content','');
      registry_set('tutorial_'||current_page||'_started',datestring(now()));
    };
    connection_set('stop_execution','1');
    return (0);
  };

  if (get_keyword ('load_scr_status', params, '') <> '')
  {
    http_rewrite ();
    http_header ('Content-Type: text/html\r\n');
    if (registry_get('tutorial_'||current_page||'_content') = 0)
      http('noinit');
    else
      http(cast(registry_get('tutorial_'||current_page||'_completed') as varchar));
    http(':');
    if (registry_get('tutorial_'||current_page||'_content') = 0)
      http('This example has not been initialized yet.');
    else
      http(registry_get('tutorial_'||current_page||'_content'));
    connection_set('stop_execution','1');
    return (0);
  }

  is_moz := 0; is_ie := 0;
  uagent := lower (http_request_header (lines, 'User-Agent', null, ''));

  if (strstr (uagent, 'mozilla') is not null and strstr (uagent, 'gecko') is not null)
    is_moz := 1;
  else if (strstr (uagent, 'msie') is not null and strstr (uagent, 'opera') is null)
    is_ie := 1;

  start_l := vector ();
  load_l := ''; load_c := ''; dav_vsp := null; http_thr := null; xform_br := null;
  if (0 <> t_file_stat (concat (pwd, '/options.xml')))
  {
    declare exit handler for sqlstate '*' { error := concat (__SQL_STATE, '', __SQL_MESSAGE); start_view := null; goto err; };
    {
      start_view := t_file_to_string (concat (pwd, '/options.xml'));
      start_view := xml_tree_doc (start_view);
      only_browser := cast ( xpath_eval ('/init/@only_browser', start_view, 1) as varchar);
      start_l := xpath_eval ('/init/src/@start', start_view, 0);
      load_l  := cast (xpath_eval ('/init/src/@load_at_start',  start_view, 1) as varchar);
      load_c  := cast (xpath_eval ('/init/src/@load_to_clean',  start_view, 1) as varchar);
      if ( (only_browser is not null)  and (strcasestr (user_agent, only_browser) is null))
      {
        dependa := concat (dependa,
         sprintf ('<p style="color: red"><small>This example depends browser "%s" if you are using a diffrent browser the example may not function properly.</small></p>', only_browser));
      }
      demo_db  := cast (xpath_eval ('/init/depend/@demo_db',  start_view, 1) as varchar);
      xform_br  := cast (xpath_eval ('/init/depend/@xform_br',  start_view, 1) as varchar);
      dep_vdb   := cast (xpath_eval ('/init/depend/@vdb',  start_view, 1) as varchar);
      start_view := t_file_to_string (concat (pwd, '/options.xml'));
      start_view := xml_tree_doc (start_view);
      dav_vsp := cast (xpath_eval ('/init/dav_vsp/@val', start_view, 1) as varchar);
      http_thr := cast (xpath_eval ('/init/http_threads/@val', start_view, 1) as varchar);
      src_path := cast (xpath_eval ('/init/srcdir/@srcpath', start_view, 1) as varchar);
      srv_ca := cast (xpath_eval ('/init/https_server/@ca', start_view, 1) as varchar);
      srv_cert := cast (xpath_eval ('/init/https_server/@cert', start_view, 1) as varchar);
      srv_key := cast (xpath_eval ('/init/https_server/@key', start_view, 1) as varchar);
      cli_cert := cast (xpath_eval ('/init/https_client/@cert', start_view, 1) as varchar);
      deps  := xpath_eval ('/init/deps[@item and @example and @type]',  start_view, 0);
      listed_src := xpath_eval ('/init/files/file/@name', start_view, 0);
      if (length (listed_src) = 0)
        listed_src := null;
    }
  }

  if (get_keyword ('src', params, '') <> '')
  {
    declare ses any;
    ses := string_output ();
    http ('<html>\r\n<body>\r\n', ses);
    http ('<pre>\r\n', ses);
    http_rewrite ();
    http_header ('Content-Type: text/html\r\n');
    if (isstring (src_path) and length(src_path) > 1)
      http_value (t_file_to_string (concat (http_root (), src_path , get_keyword ('src', params, ''))), NULL, ses);
    else
      http_value (t_file_to_string (concat (pwd, '/', get_keyword ('src', params, ''))), NULL, ses);
    http ('\r\n</pre>\r\n', ses);
    http ('<div style="float:right"><a href="javascript:window.close();"><img src="'|| http_map_get('domain') ||'/images/close_16.png" border="0" alt="close this window" title="close this window" /> close this window</a></div>\r\n', ses);
    http ('<div style="position:absolute;top:10px;right:10px"><a href="javascript:window.close();"><img src="'|| http_map_get('domain') ||'/images/close_16.png" border="0" alt="close this window" title="close this window" /> close this window</a></div>\r\n', ses);
    http ('\r\n</body>\r\n</html>\r\n', ses);
    http (string_output_string (ses));
    connection_set('stop_execution','1');
    return (0);
  }

  {
    declare exit handler for sqlstate '*' { error := 'Warning: The Demo Database is not running, but is required for correct operation of the examples.'; };
    if (demo_db = 'yes')
    {
       declare num integer;
       select count (distinct KEY_TABLE) into num from DB.DBA.SYS_KEYS where KEY_TABLE like 'Demo.demo.%';
       if (num < 8)
         signal ('.....', 'The demo DB is not installed');
    }
  }
  -- vdb check
  if (dep_vdb = 'yes')
  {
    if (sys_stat('st_has_vdb') = 0)
        dependa := concat (dependa,
         '<div>
            <p style="color: red">This Virtual Database feature is available only in the commercial release of Virtuoso Universal Server.
            For more information on the commercial release of the Virtuoso Universal Server,
            click on the following links to learn more:</p>
            <small>
            <a href="http://virtuoso.openlinksw.com/">Virtual Database Home Page</a><br/>
            <a href="http://demo.openlinksw.com/tutorial">Virtual Database Tutorials</a><br/>
            <a href="http://docs.openlinksw.com/virtuoso">Virtual Database Documentation</a><br/>
            <a href="http://www.openlinksw.com/">OpenLink Software</a><br/>
            </small>
          </div>');
  }


  -- dependancy tests
  if (isarray (deps))
  {
    declare cn, ln integer;
    declare item, exam, type varchar;
    declare hosting_name,hosting_fail any;
    cn := 0; ln := length (deps);
    while (cn < ln)
    {
      item := cast (xpath_eval ('@item', deps[cn], 1) as varchar);
      exam := cast (xpath_eval ('@example', deps[cn], 1) as varchar);
      type := cast (xpath_eval ('@type', deps[cn], 1) as varchar);
      if (lower(type) = 'table' and not exists (select 1 from DB.DBA.SYS_KEYS where 0 = casemode_strcmp (KEY_TABLE, item)))
      {
        dependa := concat (dependa,
         sprintf ('<p style="color: red"><small>This example depends of table "%s" from "%s" demo, which isn''t initialized.</small></p>', item, exam));
      }
      else if (lower(type) = 'user' and not exists (select 1 from DB.DBA.SYS_USERS where 0 = casemode_strcmp (U_NAME, item)))
      {
        dependa := concat (dependa,
         sprintf ('<p style="color: red"><small>This example depends of user account "%s" from "%s" demo, which isn''t initialized.</small></p>', item, exam));
      }
      else if (lower(type) = 'procedure' and not exists (select 1 from DB.DBA.SYS_PROCEDURES where 0 = casemode_strcmp (P_NAME, item)))
      {
        dependa := concat (dependa,
         sprintf ('<p style="color: red"><small>This example depends of procedure "%s" from "%s" demo, which it isn''t initialized.</small></p>', item, exam));
      }
       else if (lower(type) = 'package' and not(tcheck_package(item)) )
      {
        dependa := concat (dependa,
         sprintf ('<p style="color: red"><small>This example depends of package "%s", which is not installed.</small></p>', item));
      }
       else if (lower(type) = 'hosting')
      {
        hosting_fail := 0;
        hosting_name := '';
        if (lower(item) = 'clr_mono' and isnull(__proc_exists ('clr_runtime_name', 2)))
        {
          hosting_fail := 1;
          hosting_name := 'Virtuoso Universal Server for Linux with Mono Hosting or Virtuoso Universal Server for Windows with .NET CLR Hosting';
        }
        else if (lower(item) = 'clr' and (isnull(__proc_exists ('clr_runtime_name', 2)) or lower(clr_runtime_name()) = 'mono'))
        {
          hosting_fail := 1;
          hosting_name := 'Virtuoso Universal Server for Windows with .NET CLR Hosting';
        }
        else if (lower(item) = 'mono' and (isnull(__proc_exists ('clr_runtime_name', 2)) or lower(clr_runtime_name()) <> 'mono'))
        {
          hosting_fail := 1;
          hosting_name := 'Virtuoso Universal Server for Linux with Mono Hosting';
        }
        else if (lower(item) = 'java' and isnull(__proc_exists ('java_vm_attach', 2)))
        {
          hosting_fail := 1;
          hosting_name := 'Java Runtime Hosting Enabled';
--        JSP hosting

          tut_generate_tomcat_url ('', lines);
          if (connection_get ('TomcatStatus') = 'BAD')
             dependa := concat (dependa, '<p style="color: red">
                 <small>In order to run this example you need start tomcat.</small></p>');

--      end JSP hosting
        }
        else if (lower(item) = 'php' and isnull(__proc_exists ('__http_handler_php', 2)))
        {
          hosting_fail := 1;
          hosting_name := 'PHP Runtime Hosting Enabled';
        }
        else if (lower(item) = 'perl' and isnull(__proc_exists ('WS.WS.__http_handler_pl')))
        {
          hosting_fail := 1;
          hosting_name := 'Perl Runtime Hosting Plugin Enabled';
        }
        else if (lower(item) = 'python' and isnull(__proc_exists ('WS.WS.__http_handler_py')))
        {
          hosting_fail := 1;
          hosting_name := 'Python Runtime Hosting Plugin Enabled';
        }
        else if (lower(item) = 'ruby' and isnull(__proc_exists ('WS.WS.__http_handler_rb')))
        {
          hosting_fail := 1;
          hosting_name := 'Ruby Runtime Hosting Plugin Enabled';
        }


        if (hosting_fail)
          dependa := concat (dependa, sprintf ('<p style="color: red"><small>In order to run this example you need %s.</small></p>', hosting_name));

      }
      cn := cn + 1;
    }
  }

  if (dav_vsp = '1')
  {
    if (cfg_item_value (virtuoso_ini_path(), 'HTTPServer', 'EnabledDavVSP') <> dav_vsp)
      error := 'Warning: WebDAV VSP Page Execution is currently disabled. Please enable in order to use this service.  Go to the Config file for the demo database (the file "demo.ini") and edit the section-key: EnabledDavVSP = 0 by uncommenting and then changing the 0 to 1.';
  }

  if (http_thr is not null and atoi(http_thr) > 1)
  {
    if (atoi (cfg_item_value (virtuoso_ini_path(), 'HTTPServer', 'ServerThreads')) < atoi (http_thr))
    {
      error := sprintf ('Warning: This example needs at least %s HTTP server threads configured.', http_thr);
    }
  }

  if (isstring (srv_cert))
  {
    if (t_file_stat (srv_cert) = 0 or
        t_file_stat (srv_key) = 0 or
        t_file_stat (srv_ca) = 0 or
        t_file_stat (cli_cert) = 0)
    {
      error := sprintf ('Warning: This example needs of following files to be installed:
      HTTPS Server: CA list:%s,  Certificate:%s, Private Key:%s and Client certificate:%s.',
      srv_ca, srv_cert, srv_key, cli_cert);
    }
  }

  if (isstring (src_path) and length(src_path) > 1)
    sources := t_sys_dirlist (concat (http_root(), src_path), 1, null, 1);
  else
    sources := t_sys_dirlist (pwd, 1, null, 1);

  len := length (sources); i := 0;
  if (isstring (load_l) and load_l <> '')
    t_load_script (concat (pwd, '/', load_l));

  if (get_keyword ('load_scr', params, '') <> '')
  {
    if(registry_get('tutorial_'||current_page||'_completed') <> 0
       and cast(registry_get('tutorial_'||current_page||'_completed') as integer) < 100
       and cast(registry_get('tutorial_'||current_page||'_completed') as integer) > 0)
    {
      http_rewrite ();
      http_header ('Content-Type: text/html\r\n');
      http('already running');
      http_flush ();
      connection_set('stop_execution','1');
      return (0);
    }

    declare cnt, parts, tm, res any;
    declare stat, msg any;
    declare sql_files any;
    declare count_all,count_executed integer;

    sql_files := vector();
    count_all := 0;
    count_executed := 0;

    res := string_output();

    while (i < len)
    {
      if ((load_c <> '' and aref (sources, i) = load_c) or (load_c = '' and aref (sources, i) like '%.sql'))
      {
        cnt := t_file_to_string (concat (pwd, '/', aref (sources, i)));
        parts := sql_split_text (cnt);
        sql_files := vector_concat(sql_files,vector(vector(aref (sources, i),parts)));
        count_all := count_all + length(parts);
      }
      i := i + 1;
    }

    http_rewrite ();
    http_header ('Content-Type: text/html\r\n');
    http_flush (1);
    http ('<html>\r\n<body>\r\n');
    http ('<pre>\r\n');

    foreach (any sql_file in sql_files) do
    {
      http (sprintf('Loading file: %s\r\n\r\n',sql_file[0]));
      http (sprintf('Loading file: %s\r\n\r\n',sql_file[0]),res);
      foreach (varchar s in sql_file[1]) do
      {
        stat := '00000';
        msg := '';
        tm := msec_time();
        exec (s, stat, msg);
        count_executed := count_executed + 1;
        if (stat <> '00000')
        {
          rollback work;
          if (lower (trim (s, ' \r\n')) like 'drop %')
          {
            http (sprintf ('<span style="color:green;">It is normal to see errors from drop statements, if this is the first time the sql is executed.<br/>*** Error %s: %s</span>',stat,msg));
            http (sprintf ('<span style="color:green;">It is normal to see errors from drop statements, if this is the first time the sql is executed.<br/>*** Error %s: %s</span>',stat,msg),res);
          }
          else
          {
            http (sprintf ('<span style="color:red;">*** Error %s: %s</span>',stat,msg));
             http (sprintf ('<span style="color:red;">*** Error %s: %s</span>',stat,msg),res);
          }
        }
        else
        {
          commit work;
          http (sprintf ('Done. -- %s msec.',cast(msec_time() - tm as varchar)));
          http (sprintf ('Done. -- %s msec.',cast(msec_time() - tm as varchar)),res);
        }
        http ('\r\n\r\n');
        http ('\r\n\r\n',res);
        registry_set('tutorial_'||current_page||'_completed',cast(ceiling(((100.0/count_all) * count_executed)) - 1 as varchar));
        registry_set('tutorial_'||current_page||'_content',string_output_string(res));
        http_flush (1);
      }
    }

    http ('Finished.\r\n');
    http ('Finished.\r\n',res);
    registry_set('tutorial_'||current_page||'_completed','100');
    registry_set('tutorial_'||current_page||'_content',string_output_string(res));
    http ('</pre>\r\n');
    http ('<div style="float:right"><a href="javascript:window.close();"><img src="'|| http_map_get('domain') ||'/images/close_16.png" border="0" alt="close this window" title="close this window" /> close this window</a></div>\r\n');
    http ('<div style="position:absolute;top:10px;right:10px"><a href="javascript:window.close();"><img src="'|| http_map_get('domain') ||'/images/close_16.png" border="0" alt="close this window" title="close this window" /> close this window</a></div>\r\n');
    http ('</body>\r\n</html>\r\n');
    http_flush(1);
    connection_set('stop_execution','1');
    return (0);
  }

  err:
  len := length (sources); i := 0; j := 0; have_vsp := 0; have_sql := 0; have_init := 0;
  if (isentity(start_view) and xpath_eval ('/init/run[@name and @link]',  start_view))
    have_vsp := have_vsp + 1;
  while (i < len)
  {
    if (listed_src is not null and not position (aref (sources, i), listed_src))
      ;
    else if (aref (sources, i) <> current_page and (
          aref (sources, i) like '%.vsp' or
          aref (sources, i) like '%.rq' or
          aref (sources, i) like '%.isparql' or
          aref (sources, i) like '%.csdl' or
          aref (sources, i) like '%.owl' or
          aref (sources, i) like '%.html' or
          aref (sources, i) like '%.vspx' or
          aref (sources, i) like '%.aspx' or
          aref (sources, i) like '%.pl' or
          aref (sources, i) like '%.py' or
          aref (sources, i) like '%.rb' or
          aref (sources, i) like '%.jsp' or
          (aref (sources, i) like '%.php' and
            aref (sources, i) not like '.%.php')))
      have_vsp := have_vsp + 1;
    else if (aref (sources, i) like '%.sql')
    {
      if (listed_src is not null and not position (sources[i], listed_src))
        ;
      else
        have_sql := have_sql + 1;
      if ((load_c <> '' and sources[i] = load_c) or (load_c = '' and sources[i] like '%.sql'))
        have_init := have_init + 1;
    }
    else if (listed_src is not null and position (sources[i], listed_src))
      have_vsp := have_vsp + 1;
    i := i + 1;
  }

  erri:
?>
<?vsp
  if (error <> '' and not show_desc)
    http (concat ('<p style="color: red"><b>', error,'</b></p>'));
?>
<?vsp
  if (not(have_init)) {
?>
    <script language="JavaScript" type="text/javascript">
      HaveInitialState = 0;
    </script>
<?vsp
  }
?>
  <a name="launchtable"> <!-- If we don't have at least space here IE will give unknown runtime error --></a>
<?vsp
  if (xform_br = 'yes')
  {
    http ('<object id="FormsPlayer" classid="CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58"><p style="color: red"><b>Warning: FormsPlayer has failed to load! Please check your installation.</b></p><p><b>The FormsPlayer is needed in order to run this sample.</b></p><br /></object>');
   }
  if (dependa <> '' and show_desc)
    http (dependa);
  if (have_vsp or have_sql)
  {
?>
<?vsp
     if (error <> '' and show_desc)
      http (concat ('<p style="color: red"><b>', error,'</b></p>'));
?>
  <table class="source_table_">
    <tr class="source_table_header">
      <th nowrap="nowrap"><b>View the source</b></th>
      <th><b>&nbsp;Action&nbsp;</b></th>
    </tr>
<?vsp
  }
  len := length (sources); i := 0; j := 0;
  -- Set Initial State
  while (i < len)
  {
    if (listed_src is not null and not position (sources[i], listed_src))
      ;
    else if (sources[i] like '%.sql' and ((load_c <> '' and sources[i] = load_c) or (load_c = '' and sources[i] like '%.sql')))
    {
      j := j + 1;
?>
      <tr>
        <td class="source_table_data">
           <?V j ?>.
          <a onclick="ViewSourceLink('<?V aref (sources, i) ?>')" href="#"><?V aref (sources, i) ?></a>
          <script language="JavaScript" type="text/javascript">Files.push('<?V aref (sources, i) ?>');</script>
        </td>
        <td class="source_table_action">
          <?vsp
            if (showed_init_state = 0)
            {
              showed_init_state := 1;
          ?>
              <a onclick="InitialStateLink()" href="#">Set the initial state</a>
          <?vsp
            }
          ?>
        </td>
      </tr>
<?vsp
    }
    i := i + 1;
  }
  -- dummy run links
  if (isentity(start_view))
  {
    declare run_name, run_link varchar;
    foreach(any xrun in xpath_eval ('/init/run[@name and @link ]',  start_view, 0))do
    {
      run_name := cast(xpath_eval('@name',xrun) as varchar);
      run_link := cast(xpath_eval('@link',xrun) as varchar);
      j := j + 1;
?>
      <tr>
        <td class="source_table_data">
          <?V j ?>.
          <?V run_name ?>
        </td>
        <td class="source_table_action">
          <a target="run_frame" onclick="RunLink('<?V replace(run_link,'''','\\''') ?>')" href="<?V run_link?>">Run</a>
          <script language="JavaScript" type="text/javascript">RunFiles.push(Array('<?V run_link ?>','<?V run_name ?>'));</script>
        </td>
      </tr>
<?vsp
    }
  }
  -- list of files
  declare sslhost, sslport, tmp varchar;
  
  sslhost := null; 
  sslport := null;
  for select top 1 HP_HOST, HP_LISTEN_HOST 
        from DB.DBA.HTTP_PATH
       where HP_LPATH like '/tutorial/webid' and HP_HOST not like '*sslini*' and HP_SECURITY = 'SSL' and length (HP_HOST) do
	{
	  tmp := split_and_decode (HP_LISTEN_HOST, 0, '\0\0:');
	  if (length (tmp) = 2)
	    tmp := tmp[1];
	  else
	    tmp := HP_LISTEN_HOST;
	  sslhost := HP_HOST;
	  sslport := tmp;
	  if (sslport <> '443')
	    sslhost := sslhost || ':' || sslport;
	}
  if (server_https_port () is not null and sslhost is null)
  {
    sslhost := registry_get ('URIQADefaultHost');
    tmp := split_and_decode (sslhost, 0, '\0\0:');
    if (length (tmp) = 2)
	    sslhost := tmp[0];
	    
    sslport := server_https_port ();
    if (sslport <> '443')
	    sslhost := sslhost || ':' || sslport;
  }
  sslhost := 'https://' || sslhost || '/tutorial/webid';

  i := 0;
  while (i < len)
  {
    declare src_name, source_ext, dot_pos any;

    src_name := sources[i];
    dot_pos := strrchr (src_name, '.');
    if (dot_pos is not null)
      source_ext := subseq (src_name, dot_pos + 1, length (src_name));
    else
      source_ext := null;

    if (listed_src is not null and not position (src_name, listed_src))
      ;
    else if (
      src_name <> current_page and
      src_name[0] <> ascii ('.') and
      src_name <> 'options.xml' and
      src_name <> regexp_replace (current_page, '.vspx?$', '.xml') and
      source_ext in
      ('rq', 'csdl', 'isparql', 'owl', 'vsp', 'sql','xsl','xml','xsd','html','java','pl','pm','py','rb','cs','vspx','aspx','wsdl','bpel','php', 'xq', 'xslt', 'cpp', 'h', 'jsp'))
    {
      if (sources[i] like '%.sql' and ((load_c <> '' and sources[i] = load_c) or (load_c = '' and sources[i] like '%.sql')))
        goto next_item;
      j := j + 1;
?>
      <tr>
        <td class="source_table_data">
          <?V j ?>.
          <a onclick="ViewSourceLink('<?V aref (sources, i) ?>')" href="#"><?V aref (sources, i) ?></a>
          <script language="JavaScript" type="text/javascript">Files.push('<?V aref (sources, i) ?>');</script>
        </td>
        <td class="source_table_action">
<?vsp
          if ((not no_run) and
            aref (sources, i) like '%.jsp')
            {
          ?>
          <a target="run_frame_java" href="<?=tut_generate_tomcat_url (sources[i], lines)?>">Run</a>
          <?vsp
            }
          if ( (not no_run) and
            (aref (sources, i) like '%.vsp'
            or aref (sources, i) like '%.html'
            or aref (sources, i) like '%.pl'
            or aref (sources, i) like '%.py'
            or aref (sources, i) like '%.isparql'
            or aref (sources, i) like '%.rb'
            or aref (sources, i) like '%.vspx'
            or aref (sources, i) like '%.aspx'
            or aref (sources, i) like '%.php'))
          {
            declare ii, ll, show_run integer;
            declare where_to_run varchar;
            if (start_view is not null)
            {
              declare fhost, furl, whost any;
              fhost := http_request_header (lines, 'Host', null, 'localhost');
              fhost := split_and_decode (fhost, 0, ':=:');
              where_to_run := cast (xpath_eval (sprintf ('/init/src[@start = ''%s'']/@link', sources [i]), start_view, 1) as varchar);

              furl := WS.WS.PARSE_URI (coalesce (where_to_run, ''));
              if (furl[0] <> '' and furl[1] <> '')
              {
                declare nhostp varchar;
                whost := split_and_decode (furl[1], 0, ':=:');
                if (length (whost) > 1)
                {
                  if (whost[1] = '<port>')
                  {
                    declare new_port any;
                    new_port := sprintf ('%d', atoi(server_http_port ()));
                    nhostp := sprintf ('%s:%s', fhost[0], new_port);
                  }
                  else if (whost[1] <> '<port+1>')
                    nhostp := sprintf ('%s:%s', fhost[0], whost[1]);
                  else
                  {
                    declare new_port any;
                    new_port := sprintf ('%d', atoi(server_http_port ())+1);
                    nhostp := sprintf ('%s:%s', fhost[0], new_port);
                  }
                }
                else
                  nhostp := fhost [0];
                where_to_run := sprintf ('%s://%s%s', furl[0], nhostp, furl[2]);
              }
            }

            show_run := 0;
            if (start_view is null or (isarray (start_l) and length (start_l) = 0))
            {
          ?>
              <a target="run_frame" onclick="RunLink('<?V concat(sslhost, '/', aref (sources, i)) ?><?Vauth?>')" href="<?V concat(sslhost, '/', aref (sources, i)) ?><?Vauth?>">Run</a>
              <script language="JavaScript" type="text/javascript">RunFiles.push(Array('<?V concat(sslhost, '/', aref (sources, i)) ?><?Vauth?>','<?V aref (sources, i) ?>'));</script>
          <?vsp
            }
            else if (isstring (where_to_run))
            {
              -- frame run
              if (strchr (where_to_run, '/') is null)
              {
                where_to_run := sprintf ('%s/%s', current_loc, where_to_run);
              }
            ?>
              <a target="run_frame" onclick="RunLink('<?V where_to_run ?>')" href="<?V where_to_run ?>">Run</a>
              <script language="JavaScript" type="text/javascript">RunFiles.push(Array('<?V where_to_run ?>','<?V aref (sources, i) ?>'));</script>
            <?vsp
            }
            else
              http('&nbsp;');
          }
          else
             http('&nbsp;');
      ?>
      </td>
    </tr>
<?vsp
    }
    next_item:
    i := i + 1;
  }
?>
<?vsp
  if (have_vsp or have_sql)
  {
?>
     </table>
<?vsp
  }
?>


      </div>
        <script language="JavaScript" type="text/javascript">
      if (!HaveInitialState)
        document.getElementById('tab_initial_state').parentNode.className = 'disabled';
      if (Files.length == 0)
        document.getElementById('tab_view_source').parentNode.className = 'disabled';
      if (RunFiles.length == 0)
        document.getElementById('tab_run').parentNode.className = 'disabled';
    </script>
      <div id="initial_state" style="display:none;">
       <div id="progressBar">
            <div id="PBcompleted"></div>
            <div id="PBcontent">0%</div>
       </div>
          <input type="button" id="bt_SetInitialState" onclick="SetInitialState()" value="Set the initial state" /><input type="button" onclick="CancelInitialState()" value="Cancel" />
       <div id="initial_state_content">
            <p>Checking state, please wait...</p>
       </div>
      </div>
      <div id="view_source" style="display:none;">
          <script language="JavaScript" src="../../syntax/shCore.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushSql.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushXml.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushCSharp.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushPhp.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushPython.js" type="text/javascript"></script><script language="JavaScript" src="../../syntax/shBrushVb.js" type="text/javascript"></script>
       <div>
            <input type="button" id="hilite" name="hilite" value="Show Syntax Highlight" onclick="doSyntax (this);" disabled="disabled" />
       </div>
       <div>
        <div id="filelist">
         <ul id="filelist_nav">
                <li>~no files~</li>
         </ul>
              <script language="JavaScript" type="text/javascript">
            FileListInit();
          </script>
        </div>
            <div id="filesource"></div>
       </div>
      </div>
      <div id="run" style="display:none;">
       <div id="runfilelist">
        <ul id="runfilelist_nav">
              <li>~no files~</li>
        </ul>
            <script language="JavaScript" type="text/javascript">
          RunFileListInit();
        </script>
       </div>
          <iframe id="run_frame" name="run_frame" src="../../1x1.html"></iframe>
      </div>
        <div id="debug"></div>
        <a name="exp_bot"></a>
      <div class="exp_nav">
          <img src="../../images/rewnd_16.png" alt="previous example" title="previous example" /> <a href="../../services/ud_s_3/ud_s_3.vsp#exp_bot">previous example</a> | <a href="../../services/">index</a> | <a href="../../wap/wa_b_1/wa_b_1.vsp#exp_bot">next example</a> <img src="../../images/fastf_16.png" alt="next example" title="next example" />
      </div>
     </div>
    </td>
   </tr>
  </table>
  <div class="footer">
   <div id="w3cval">
    <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" />
    </a>
   </div>
    <a target="_blank" href="http://www.openlinksw.com"><img src="../../images/web_24.png" border="0" alt="OpenLink Home" title="OpenLink Home" /> OpenLink Home</a> | <a target="_blank" href="http://www.openlinksw.com/virtuoso"><img src="../../images/web_24.png" border="0" alt="Virtuoso Home" title="Virtuoso Home" /> Virtuoso Home</a> | <a target="_blank" href="mailto:support@openlinksw.com"><img src="../../images/mail_24.png" border="0" alt="Technical Support" title="Technical Support" /> Technical Support</a> | <a target="_blank" href="http://www.openlinksw.com/main/contactu.html"><img src="../../images/mail_24.png" border="0" alt="Contact Us" title="Contact Us" /> Contact Us</a>
    <p class="copyright">Copyright &copy; 1999-<?V "LEFT" (datestring (now()), 4)?> OpenLink Software</p>
  </div>
 </body>
</html>
