Bookmark via pref.

git-svn-id: svn://10.0.0.236/trunk@185589 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mgalli%geckonnection.com
2005-12-02 19:52:21 +00:00
parent 333a7a79b6
commit 82b3fbcffb
3 changed files with 193 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
function bmInit(targetDoc, targetElement) {
var testLoad=new bmProcessor();
testLoad.xslSet("bookmark_template.xml");
testLoad.setTargetDocument(targetDoc);
testLoad.setTargetElement(targetElement);
testLoad.run();
}
function bmProcessor() {
this.xmlRef=document.implementation.createDocument("","",null);
this.xslRef=document.implementation.createDocument("http://www.w3.org/1999/XSL/Transform","stylesheet",null);
var bookmarkStore=null;
try {
gPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
bookmarkStore = gPref.getCharPref("browser.bookmark.store");
} catch (ignore) {}
var aDOMParser = new DOMParser();
this.xmlRef = aDOMParser.parseFromString(bookmarkStore,"text/xml");
if(this.xmlRef&&this.xmlRef.firstChild&&this.xmlRef.firstChild.nodeName=="bm") {
// All good to go.
} else {
var bookmarkEmpty="<bm></bm>";
gPref.setCharPref("browser.bookmark.store",bookmarkEmpty);
this.xmlRef = aDOMParser.parseFromString(bookmarkEmpty,"text/xml");
}
this.xslUrl="";
var myThis=this;
var omega=function thisScopeFunction2() { myThis.xslLoaded(); }
this.xslRef.addEventListener("load",omega,false);
this.xmlLoadedState=true;
this.xslLoadedState=false;
}
bmProcessor.prototype.xmlLoaded = function () {
this.xmlLoadedState=true;
this.apply();
}
bmProcessor.prototype.xslLoaded = function () {
this.xslLoadedState=true;
this.apply();
}
bmProcessor.prototype.xmlSet = function (urlstr) {
this.xmlUrl=urlstr;
}
bmProcessor.prototype.xslSet = function (urlstr) {
this.xslUrl=urlstr;
}
bmProcessor.prototype.setTargetDocument = function (targetDoc) {
this.targetDocument=targetDoc;
}
bmProcessor.prototype.setTargetElement = function (targetEle) {
this.targetElement=targetEle;
}
bmProcessor.prototype.apply = function () {
if(this.xmlLoadedState&&this.xslLoadedState) {
var xsltProcessor = new XSLTProcessor();
var htmlFragment=null;
try {
xsltProcessor.importStylesheet(this.xslRef);
htmlFragment = xsltProcessor.transformToFragment(this.xmlRef, this.targetDocument);
} catch (e) {
}
this.targetElement.appendChild(htmlFragment.firstChild);
document.getElementById("loadmessage").style.display="none";
}
}
bmProcessor.prototype.run = function () {
try {
// Already parsed.
// this.xmlRef.load(this.xmlUrl);
} catch (e) {
}
try {
this.xslRef.load(this.xslUrl);
} catch (e) {
}
}

View File

@@ -0,0 +1,52 @@
<?xml version="1.0"?> <!-- -*- Mode: HTML -*- -->
<!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is
Netscape Communications Corporation.
Portions created by the Initial Developer are Copyright (C) 1998-2000
the Initial Developer. All Rights Reserved.
Contributor(s):
Marcio S. Galli, mgalli@geckonnection.com
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://minimo/skin/bookmarks/bookmarks.css" type="text/css"?>
<bookmarks xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xlink="http://www.w3.org/1999/xlink">
<html:head>
<html:link rel="icon" href="chrome://minimo/skin/bookmarks-favicon.png" type="image/png" />
<html:title>Bookmarks</html:title>
</html:head>
<html:body onload='bmInit(document,document.body)' />
<html:script src="bmview.js" />
</bookmarks>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stylesheet [
<!ATTLIST xsl:sort id ID #IMPLIED>
<!ATTLIST xsl:variable id ID #IMPLIED>
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rss="http://purl.org/rss/1.0/"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<div>
<xsl:for-each select="/bm/li">
<div class='item'>
<a>
<xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</div>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>