// DEFINITIONS
var PUBSUB_NODE = "home/meteo/foo";
var PUBSUB_JID = "pubsub.example.net";
var NS_PUBSUB = "http://jabber.org/protocol/pubsub";
var NS_PUBSUB_OWNER = NS_PUBSUB + "#owner";
var NS_PUBSUB_EVENT = NS_PUBSUB + "#event";
// STATE
var channel; // XXXbard: global
var testAccount = 'meteo@example.net/Firefox/SamePlace';
// FUNCTIONS
function init() {
channel = XMPP.createChannel();
channel.on({
event: 'iq',
direction: 'in',
stanza: function(s) {
return s.@type == 'result';
}
}, function(iq) {
alert(iq.stanza.@id);
});
channel.on({
event : 'iq',
direction : 'in',
stanza: function(s) {
default xml namespace="http://a9.com/-/spec/opensearch/1.1/"
return s..OpenSearchDescription;
}}, function(iq) {
//default xml namespace = 'http://jabber.org/protocol/pubsub';
alert("ha");
var foo = iq.stanza;
default xml namespace="http://a9.com/-/spec/opensearch/1.1/"
alert(foo..OpenSearchDescription.length()); //This doesn't seem to work.
});
channel.on({
event : 'iq',
direction : 'in',
stanza: function(s) {
return s..@subid;
}}, function(iq) {
//alert(iq.stanza..@subid);
SUBID = iq.stanza..@subid;
//alert(SUBID)
});
};
/* Releasing channel. Not all are implemented yet */
function finish() {
channel = XMPP.release();
}
/* Iq PubSub item handler */
function iq_pubsub_items_init() {
iq_pubsub_items_channel = XMPP.createChannel();
/* This is where I get stuck. I can't handle PubSub items like the following example :
-
Wikipedia (English)
Wikipedia (English)
http://en.wikipedia.org/favicon.ico
-
Wikipedia (English)
Wikipedia (English)
http://en.wikipedia.org/favicon.ico
I'd wish to get an array or a list of all PubSub items so that I can process them to import them in Firefox.
*/
};
// GUI REACTIONS
// XXXbard:
window.addEventListener('load', function() {
init();
}, false);
window.addEventListener('unload', function() {
finish();
}, false);
// NETWORK ACTIONS
// XXXbard: you don't want these in the top level,
function testPubsub() {
/* Get PubSub items */
var iq_pubsub_get_items =
;
//Get PubSub items
XMPP.send(testAccount, iq_pubsub_get_items);
/*Set PubSub items*/
var opensearch_plugin =
Wikipedia (English)
Wikipedia (English)
http://en.wikipedia.org/favicon.ico
;
var iq_pubsub_set_items =
- {opensearch_plugin}
- {opensearch_plugin}
;
XMPP.send(testAccount, iq_pubsub_set_items);
/* Get PubSub SubID */
var iq_pubsub_get_subs =
;
//print(iq_pubsub_subs);
var SUBID = "";
XMPP.send(testAccount, iq_pubsub_get_subs);
}
// XXXbard: don't care about save-to-disk now, get the protocol issues sorted first
function save() {
/* This is what follows after having retreived the PubSub OpenSearch items : the plugins are written into an XML file in the /tmp directory and then imported to Firefox. Here's only the writing part : */
// Writing file
const Cc = Components.classes;
const Ci = Components.interfaces;
var nsIProperties = Cc['@mozilla.org/file/directory_service;1']. getService(Ci.nsIProperties); var src_file = nsIProperties.get('TmpD', Ci.nsIFile); src_file.append('OpenSearchFox.xml');
var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(src_file, 0x02 | 0x08 | 0x20, 0664, 0);
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset ="utf-8"
var foo = "hello world"
var chunk = converter.ConvertFromUnicode(foo);
fos.write(chunk, chunk.length); fos.close();
/* And this is the code borrowed from OpenSearchFox which manages to write the XML file of the OpenSearch plugin and import it to Firefox */
/*
writeFile : function (str_Buffer, file, charset){
var fos = Cc["@mozilla.org/network/file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);
fos.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = charset;
var chunk = converter.ConvertFromUnicode(str_Buffer);
fos.write(chunk, chunk.length);
fos.close();
},
onDone : function(){
try{
var nsIProperties = Cc['@mozilla.org/file/directory_service;1'].
getService(Ci.nsIProperties);
var src_file = nsIProperties.get('TmpD', Ci.nsIFile);
src_file.append('OpenSearchFox.xml');
this.writeFile(this.createOpenSearchDescription(successful_controls), src_file, 'utf-8');
// this part import the OpenSearchFox.xml file as an OpenSearch plugin
var nsIBrowserSearchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
nsIBrowserSearchService.addEngine(this.getURLSpecFromFile(src_file),
Ci.nsISearchEngine.DATA_XML, '', false);
}
catch(e){
alert(e);
}
},
*/
}