Add support for resolving anonymous resources to their "#URL" property. ("Last Search Results" are anonymous, for example.)

This commit is contained in:
rjc%netscape.com 1999-09-17 10:38:40 +00:00
parent e63507631f
commit 871ea292a5
4 changed files with 70 additions and 10 deletions

View File

@ -66,7 +66,7 @@ function Init() {
}
function OnDblClick(treeitem)
function OnDblClick(treeitem, root)
{
// Deal with a double-click
@ -90,9 +90,39 @@ function OnDblClick(treeitem)
// Okay, it's not a container. See if it has a URL, and if so, open it.
var id = treeitem.getAttribute('id');
if (id) {
ContentWindow.location = id;
}
if (!id) return(false);
// rjc: add support for anonymous resources; if the node has
// a "#URL" property, use it, otherwise default to using the id
try
{
var rootNode = document.getElementById(root);
var ds = null;
if (rootNode)
{
ds = rootNode.database;
}
var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService();
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
if (rdf)
{
if (ds)
{
var src = rdf.GetResource(id, true);
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
var target = ds.GetTarget(src, prop, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target) id = target;
}
}
}
catch(ex)
{
}
ContentWindow.location = id;
}

View File

@ -41,7 +41,7 @@
<tree id="Tree"
style="width: 100%; height: 100%"
datasources="rdf:internetsearch"
ondblclick="return OnDblClick(event.target.parentNode.parentNode);">
ondblclick="return OnDblClick(event.target.parentNode.parentNode, 'Tree');">
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">

View File

@ -66,7 +66,7 @@ function Init() {
}
function OnDblClick(treeitem)
function OnDblClick(treeitem, root)
{
// Deal with a double-click
@ -90,9 +90,39 @@ function OnDblClick(treeitem)
// Okay, it's not a container. See if it has a URL, and if so, open it.
var id = treeitem.getAttribute('id');
if (id) {
ContentWindow.location = id;
}
if (!id) return(false);
// rjc: add support for anonymous resources; if the node has
// a "#URL" property, use it, otherwise default to using the id
try
{
var rootNode = document.getElementById(root);
var ds = null;
if (rootNode)
{
ds = rootNode.database;
}
var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService();
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
if (rdf)
{
if (ds)
{
var src = rdf.GetResource(id, true);
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
var target = ds.GetTarget(src, prop, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target) id = target;
}
}
}
catch(ex)
{
}
ContentWindow.location = id;
}

View File

@ -41,7 +41,7 @@
<tree id="Tree"
style="width: 100%; height: 100%"
datasources="rdf:internetsearch"
ondblclick="return OnDblClick(event.target.parentNode.parentNode);">
ondblclick="return OnDblClick(event.target.parentNode.parentNode, 'Tree');">
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">