<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" version="XHTML+RDFa 1.0" xml:lang="en">
<?vsp

   declare _G, _S, _S_save, odd_position any;
   declare rdf_link, label, true_label, _subject any;
   declare arr, data, meta, h1, h2, inx, gr, host, pars, cookievec any;
   declare iri_type, iri_uri, links, langs, dspace, sid, error_message, cookiestr varchar;
   declare do_sponge, do_refresh, local_lookup, sponge_type, proxy_iri_fn int;

   set http_charset='utf-8';
   label := '';
   iri_type := 'unknown';
   _subject := '';
   error_message := null;
   odd_position := 0;
   do_refresh := null;
   sponge_type := '';
   connection_set ('ns_ctr', 1); /* for unknown xmlns to print in RDFa */
   host := http_request_header (http_request_header (), 'Host');
   langs := rdfdesc_get_lang_acc (lines);
   gr := get_keyword ('g', params, '');
   if (gr like '%?debug=on' or gr like '%&debug=on')
     gr := subseq (gr, 0, length (gr) - 9);
   if (gr like '%?@Lookup@=%' or gr like '%&@Lookup@=%')
     {
       declare tmp any;
       tmp := regexp_substr ( '(.*)([\\?&]@Lookup@=.*)', gr, 2);
       tmp := split_and_decode (ltrim (tmp, '?&'));
       sponge_type := get_keyword ('@Lookup@', tmp, '');
       do_refresh := atoi (get_keyword ('refresh', tmp, '-1'));
       if (do_refresh < 0)
         do_refresh := null;
       gr := regexp_substr ( '(.*)([\\?&]@Lookup@=.*)', gr, 1); 
     } 
   arr := rfc1808_parse_uri (gr);
   if (arr[0] = '' and arr[1] = '' and arr[2] <> '') -- case when /about/html/www.cname/path i.e. when no scheme the default is http
     gr := 'http://' || gr;
   cookiestr := http_request_header (lines, 'Cookie', null, null);
   cookiestr := regexp_replace (cookiestr, ';[[:space:]]*', ';', 1, null);
   cookievec := split_and_decode (cookiestr, 0, '\0\0;=');
   if (cookievec is not null)
     sid := get_keyword ('__rdf_sponge_sid', cookievec);
   else
     sid := null;
   if (sid is null)
     {
        sid := xenc_rand_bytes (6, 1);
     	http_header (sprintf ('Set-Cookie: __rdf_sponge_sid=%s; expires=%s; path=/about;\r\n',
     		sid, date_rfc1123 (dateadd ('hour', 24, now ()))));
     }
   http_header (http_header_get () || 'Cache-Control: no-cache, must-revalidate\r\nPragma: no-cache\r\n');
   connection_set ('__rdf_sponge_sid', sid);
   if (get_keyword ('debug', params, '') = 'on')
     connection_set ('__rdf_sponge_debug', 1);
   else
     connection_set ('__rdf_sponge_debug', 0);
   proxy_iri_fn := get_keyword ('p', params, null);
   pars := split_and_decode (arr[4]);
   if (isarray (pars) and get_keyword ('p', pars, '') = proxy_iri_fn)
     proxy_iri_fn := null;
   connection_set ('proxy_iri_fn', proxy_iri_fn); -- setup proxy iri function

   _G := replace (gr, '%01', '#');
   _S := get_keyword ('res', params);
   do_sponge := 0;
   local_lookup := 0;
   if (_S is null)
     {
       do_sponge := 1;
       _S := _G;
     }
   else
     _S := replace (_S, '%01', '#');

   if (_S like 'feed:%')
     _S := 'http:' || subseq (_S, 5);
   if (_S like 'webcal:%')
     _S := 'http:' || subseq (_S, 7);

   arr := rfc1808_parse_uri (_G);
   dspace := arr[1];
   if (arr[2] = '/' and DB.DBA.vspx_uri_compose (arr) <> _G)
     arr[2] := '';
   -- enable to stop sponge for #fragment
   --if (arr[5] <> '')
   --  do_sponge := 0;
   arr[0] := lower (arr[0]);
   if (arr[0] not in ('http', 'https', 'file', 'feed', 'doi', 'webcal') and arr[0] not like 'urn:lsid:%')
     {
       do_sponge := 0;
       local_lookup := 1;
     }
   arr [5] := '';
   if (arr[0] = 'feed')
     arr[0] := 'http';
   _G := DB.DBA.vspx_uri_compose (arr);

   if (arr[1] = host and arr[2] like '/about/id/%')
     {
       declare pa, sch, nhost, len, tmp, npath any;
       pa := split_and_decode (arr[2], 0, '\0\0/');
       if (length (pa) > 5 and pa[3] = 'entity' and pa[4] <> '' and pa [5] <> '')
         {
	    sch := pa[4];
	    nhost := pa [5];
	    tmp := '/about/id/entity/' || sch || '/' || nhost;
	    npath := subseq (arr[2], length (tmp));
	    arr[0] := sch;
	    arr[1] := nhost;
	    arr[2] := npath;
	    _G := DB.DBA.vspx_uri_compose (arr);
	    --do_sponge := 0;
         }
       else if (length (pa) > 4 and pa[3] <> '' and pa [4] <> '')
         {
	    sch := pa[3];
	    nhost := pa [4];
	    tmp := '/about/id/' || sch || '/' || nhost;
	    npath := subseq (arr[2], length (tmp));
	    arr[0] := sch;
	    arr[1] := nhost;
	    arr[2] := npath;
	    _G := DB.DBA.vspx_uri_compose (arr);
	    --do_sponge := 0;
         }
     }
   arr := rfc1808_parse_uri (_S);
   _S_save := _S;
   if (lower (arr[0]) in ('http', 'https') and (arr[1] <> host or arr[2] not like '/about/id/%'))
     {
       _S := RDF_SPONGE_PROXY_IRI (_S);
     }

   _S := replace (_S, '''', '%27');
   _G := replace (_G, '''', '%27');

   if (_S not like 'nodeID://%' and do_sponge)
     {
       declare exit handler for sqlstate '*'
       {
          if (__SQL_STATE = 'HT404')
	    {
	      http_status_set (404);
              error_message := 'Cannot find URL: ' || _G;
	    }
	  else
            {
	      error_message := __SQL_MESSAGE;
	    }
	  rollback work;
          _S := _G;
	  goto errors;
       };
       --DB.DBA.EXEC_AS (sprintf ('sparql define input:storage "" define get:soft "soft" SELECT * from <%S> where { ?x ?y ?z . }', _G), 'SPARQL');
       --DB.DBA.VT_INC_INDEX_DB_DBA_RDF_OBJ ();
       -- temporary work around to stop sponging twice
       DB.DBA.RM_DO_SPONGE (_G, sponge_type, do_refresh);
       commit work;
     }
   else if (_S like 'nodeID://%' or local_lookup = 1)
     {
       -- blank node is subject
       exec (sprintf ('sparql define input:storage "" select ?g where { graph ?g { <%S> ?p ?o . }} limit 1', _S),
	  null, null, vector (), 0, meta, data);
        if (length (data))
	  _G := data[0][0];
        else
          {
	    exec (sprintf ('sparql define input:storage "" select ?g where { graph ?g { ?s ?p <%S> . }} limit 1', _S),
	      null, null, vector (), 0, meta, data);
	    if (length (data))
	      _G := data[0][0];
	  }
     }

   exec (sprintf ('sparql ask where { graph <%S> { <%S> ?p ?o . filter (?p != <http://www.openlinksw.com/schema/attribution#isDescribedUsing>) }}',
     _G, _S), null, null, vector (), 0, meta, data);
   if (not length (data))
     {
       _S := _S_save;
       -- rdf views
       _S := replace (_S, '''', '%27');
       exec (sprintf ('sparql ask where { graph <%S> { <%s> ?p ?o . }}', _G, _S), null, null, vector (), 0, meta, data);
       if (not length (data))
         {
           exec (sprintf ('sparql ask where { graph <%S> { <%s#this> ?p ?o . }}', _G, _S), null, null, vector (), 0, meta, data);
           if (length (data))
             _S := _S || '#this';
           else 
	     {
	       _S := DB.DBA.RDF_PROXY_ENTITY_IRI (_G);
	     } 
         }
     }

   -- XXX: the bellow is a guess about subject, should not be used
   --exec (sprintf ('sparql ask where { graph <%S> { <%S> ?p ?o }}', _G, _S), null, null, vector (), 0, meta, data);
   --if (not length (data))
   --  {
   --     exec (sprintf ('sparql select ?s where { graph <%S> { ?s ?p ?o filter regex (?s, "%S#.*") }}', _G, _S),
   --	  null, null, vector (), 0, meta, data);
   --     if (length (data))
   --       {
   --         _S := data[0][0];
   --       }
   --  }

   label := rdfdesc_label (_S, _G, lines);
   label := cast (label as varchar);
   true_label := label;
   iri_type := rdfdesc_type (_G, _S, iri_uri);

   exec (sprintf ('sparql prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix dc: <http://purl.org/dc/elements/1.1/>
	select ?o where { graph <%S> { <%S> rdfs:comment ?o } }', _G, _S), null, null, vector (), 0, meta, data);
   if (length (data)) _subject := data[0][0];

   rdf_link := sprintf ('/sparql?default-graph-uri=%U&query=%U', _G, sprintf ('DESCRIBE <%s>',_S));

   links := sprintf ('Link: <http://%s%s&output=rdf>;\r\n rel="alternate"; type="application/rdf+xml"; title="Metadata in RDF/XML format",\r\n ', host, rdf_link); 
   links := links||sprintf ('<http://%s%s&output=n3>;\r\n rel="alternate"; type="text/n3"; title="Metadata in N3/Turtle format",\r\n ', host, rdf_link); 
   links := links||sprintf ('<http://%s%s&output=application%%2Fjson>;\r\n rel="alternate"; type="application/json"; title="Metadata in RDF/JSON format"\r\n', host, rdf_link); 
   links := links||sprintf ('<http://%s%s&output=application%%2Fatom%%2Bxml>;\r\n rel="alternate"; type="application/atom+xml"; title="OData (Atom feed) format"\r\n', host, rdf_link); 
   http_header (http_header_get () || links);
   errors:
   if (not length (label))
     label := _S;
   if (label like 'http%://%')
     label := rdfdesc_uri_curie (label);
   set isolation = 'uncommitted';
?>

<!-- header -->
<head profile="http://www.w3.org/1999/xhtml/vocab">
    <base href="http://<?V http_request_header (lines, 'Host') ?><?V http_map_get ('domain') ?>/" />
    <title>About: <?vsp http (sprintf ('%s', label)); ?></title>
    <link rel="alternate" type="application/rdf+xml" href="<?=rdf_link?>&output=rdf" title="Metadata in RDF/XML format" />
    <link rel="alternate" type="text/n3" href="<?=rdf_link?>&output=n3" title="Metadata in N3/Turtle format" />
    <link rel="alternate" type="application/json+rdf" href="<?=rdf_link?>&output=application%2Frdf%2Bjson" title="Metadata in RDF/JSON format" />
    <link rel="alternate" type="application/json" href="<?=rdf_link?>&output=application%2Fjson" title="Metadata in RDF/JSON format" />
    <link rel="alternate" type="application/atom+xml" href="<?=rdf_link?>&output=application%2Fatom%2Bxml" title="OData (Atom feed) format" />
    <link rel="stylesheet" type="text/css" href="statics/slidebar.css" />
    <link rel="stylesheet" type="text/css" href="statics/style_w.css" />
    <link href="statics/highlighter.css" type="text/css" rel="stylesheet" charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
    <script type="text/javascript" src="statics/script.js"></script>
    <script type="text/javascript" src="oat/loader.js"></script>
</head>
<!--
<body onload="init();" about="<?V _S ?>">
-->
<body about="<?V _S ?>">

    <div id="slb">
    <div id="sidebar">
      <h1>What Is This?</h1>
      <p>This is an HTML+RDFa representation of <b><i>metadata</i></b> describing this Web-addressable resource.</p>
      <h1>Why Is This Important?</h1>
      <p>The property (attributes and values pairs) links on this page unveil a different kind of link, one which enables the following on HTTP networks such as the Web:</p>
      <ol>
        <li><i>Unambiguous identity</i> for entities (aka. strong identifiers)</li>
        <li>Implicit binding of an entity and its metadata via <i>strong identifiers</i></li>
        <li><i>Multiple metadata representations</i> that enable a variety of presentations</li>
        <li><i>High precision Search and Find queries</i> that simply use the metadata documents (by referencing entity URIs) as the query's Data Source Name</li>
      </ol>
      <h1>How Do I Discover Alternative Metadata Representations?</h1>
      <p>
      This document exposes metadata in the following formats: (X)HTML+RDFa, Turtle, N3, RDF/JSON,  or RDF/XML. In the most basic form,  you can simply view the (X)HTML source markup of this page, and go directly to the &lt;head/&gt; section which contains a &lt;link/&gt; tag with relationship and type properties for each format.
     </p>
     <p>
     In addition, you can also explicitly request a desired metadata representation for a given resource via HTTP GET requests that use the entity's strong identifier as the call target.
     </p>
     <h1>How Can I Expose My Web Resources In This Manner?</h1>
     <p>
     Simply include the following in the &lt;head/&gt; section of your (static or dynamically generated) (X)HTML page:<br/><br/>
     &lt;link rel="alternate" title="My Data in RDF Linked Data form"<br/>
     type="application/rdf+xml"<br/>
     href="http://linkeddata.uriburner.com/about/id/&lt;this-page-URL&gt;/&gt;"
     </p>
     <h1>How Is This Related To The Linked Data Meme?</h1>
     <p>
     As stated above, the links in this page expose strong identifiers for its <b>primary topic, secondary topics, attributes, and some values</b>. These links, via  implicit association, act as conduits to their metadata-bearing documents, in a variety formats.
    </p>
    </div><!-- #sidebar -->
    </div> <!-- slb -->

    <div id="header">
      <div id="hd_l">
	  <h1 id="title">About: <a href="<?= case when _S like 'nodeID://%' then rdfdesc_http_url (_S) else _S end ?>"><?vsp http (label); ?></a></h1>
        <div id="homelink">
        </div>
        <div class="page-resource-uri">
	    An Entity of Type : <a href="<?V iri_uri ?>"><?V iri_type ?></a>, 
	    from Data Source : <a href="<?V _G ?>"><?V _G ?></a>, 
	    within Data Space : <a href="http://<?V dspace ?>"><?V host ?></a>
        </div>
      </div> <!-- hd_l -->
      <div id="hd_r">
        <a href="http://www.openlinksw.com" title="OpenLink Software"><img src="statics/openlinklogo_wstrap_2008.png" alt="[OpenLink Software]" height="80" width="191" /></a>
      </div> <!-- hd_r -->
    </div> <!-- header -->
    <div id="content_wrapper">
    <div id="content">

      <p><?vsp if (__tag (_subject) = 230) http_value (_subject); else http (sprintf ('%s', _subject)); ?></p>
      <?vsp if (error_message is not null) { ?>
      <div id="err"><?V error_message ?></div>
      <?vsp } else { ?>
     <div id="navarea">
       <div id="navbar">
         <ul id="navlist">
          <li>
            <a href="#" id="tab_attributes" onclick="toggle_tab('attributes'); return false;" class="current">Forward Links</a>
          </li>
          <li>
            <a href="#" id="tab_attributeof" onclick="toggle_tab('attributeof'); return false;">Backward Links</a>
          </li>
         </ul>
      </div> <!-- #navbar -->

      <div id="attributes">
<!-- proptable -->
      <table class="description">
	  <!--
	  <tr><th class="property">Attributes</th><th class="value">Values</th></tr>
	  -->

<?vsp
      exec (sprintf ('select "p" as PRED from (sparql select distinct ?p where { graph <%S> { <%S> ?p ?o } }) sp order by 1', _G, _S),
		null, null, vector (), 0, null, null, h1);
      while (0 = exec_next (h1, null, null, data))
	{
           declare PRED any;
	   pred := data[0];
	   rdfdesc_http_print_l (PRED, odd_position);
	   exec (sprintf ('sparql select ?o where { graph <%S> { <%S> <%S> ?o } } limit 300', _G, _S, PRED),
		null, null, vector (), 0, null, null, h2);
	   while (0 = exec_next (h2, null, null, data))
	      {
                declare OBJECT any;
		OBJECT := data [0];
		rdfdesc_http_print_r (OBJECT, PRED, true_label, 1, langs);
	      }
	   exec_close (h2);

	   http ('</ul></td></tr>');
	}
      exec_close (h1);
      if  (odd_position = 0)
      {
        http ('<tr><td colspan="2"><p>No further information is available.</p></td></tr>');
      }
?>
      </table>
      </div> <!-- #attributes -->

      <div id="attributeof" style="display: none;">
      <!-- inverseproptable -->
      <table class="description">
	  <!--
	  <tr><th class="property">Attributes</th><th class="value">Entities</th></tr>
	  -->

<?vsp
      exec (sprintf ('select "p" as PRED from (sparql select distinct ?p where { graph <%S> { ?o ?p <%S> } }) sp order by 1', _G, _S),
		null, null, vector (), 0, null, null, h1);
      inx := 0;
      while (0 = exec_next (h1, null, null, data))
	{
           declare PRED any;
	   pred := data[0];
	   inx := inx + 1;
	   rdfdesc_http_print_l (PRED, odd_position, 1);
	   exec (sprintf ('sparql select ?s where { graph <%S> { ?s <%S> <%S> } } limit 300', _G, PRED, _S),
		null, null, vector (), 0, null, null, h2);
	   while (0 = exec_next (h2, null, null, data))
	      {
                declare OBJECT any;
		OBJECT := data [0];
		rdfdesc_http_print_r (OBJECT, PRED, true_label, 0, langs);
	      }
	   exec_close (h2);

	   http ('</ul></td></tr>');
	}
      exec_close (h1);
      if  (odd_position = 0)
      {
        http ('<tr><td colspan="2"><p>No further information is available.</p></td></tr>');
      }
?>
      </table>
      </div> <!-- #attributeof -->
     </div> <!-- #navarea -->
      <?vsp } ?>
    </div> <!--  #content -->
    </div> <!--  #content_wrapper -->

<!-- footer -->
    <div id="footer">
      <?vsp if (error_message is null) { ?>
      <div id="ft_t">
       Explore alternative Linked Data Views via this <a title="OpenLink Data Explorer" href="/ode/?uri=<?vsp http_url (_S); ?>">OpenLink Data Explorer</a> link
       &nbsp; &nbsp;
       &nbsp; &nbsp; Raw Linked Data formats:
       <a href="<?=rdf_link || '&output=n3'?>">N3/Turtle</a> |
       <a href="<?=rdf_link || '&output=application%2Frdf%2Bjson'?>">RDF/JSON</a> |
       <a href="<?=rdf_link || '&output=application%2Fatom%2Bxml'?>">ODATA/ATOM</a> |
       <a href="<?=rdf_link || '&output=application%2Fodata%2Bjson'?>">ODATA/JSON</a> |
       <a href="<?=rdf_link || '&output=rdf'?>">RDF/XML</a>
      </div> <!-- #ft_t -->
      <?vsp } ?>
      <div id="ft_b">
        <a href="http://linkeddata.org/"><img alt="This material is Open Knowledge" src="statics/LoDLogo.gif" style="border-width:0"  /></a> &nbsp;
        <a href="http://dbpedia.org/sparql"><img alt="W3C Semantic Web Technology" src="statics/sw-sparql-blue.png" style="border-width:0" /></a> &nbsp;  &nbsp;
        <a href="http://www.opendefinition.org/"><img alt="This material is Open Knowledge" src="statics/od_80x15_red_green.png" style="border-width:0" /></a>
	<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="statics/creativecommons.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>. <br />
	<?vsp rdfdesc_virt_info (); ?>
      </div> <!-- #ft_b -->
    </div> <!-- #footer -->
    <div>
	<?vsp
	   if (registry_get ('__rdf_sponge_debug') = '1')
	     http ('Trace ID: ' || sid);
	?>
    </div>

    <?vsp if (isstring (registry_get ('urchinTracker'))) { ?>
    <script type="text/javascript">
     var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
     document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
   </script>
 <script type="text/javascript">
	try {
	var pageTracker = _gat._getTracker("<?V registry_get ('urchinTracker')  ?>");
     pageTracker._trackPageview();
	} catch(err) {}</script>
    <?vsp } ?>

 </body>
</html>
