⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mocojoey.js.svn-base

📁 Joey is j2me client server application for for mobile platform. Build on top j2mepolish
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
        osvr.addObserver(this, "profile-change-teardown", false);    },    // nsIObserver implementation     observe: function(subject, topic, data)     {        switch(topic) {             case "profile-change-teardown":              {                 // get rid of all of the rss prefs.                 try {                     var prefs = Components.classes["@mozilla.org/preferences-service;1"]                                           .getService(Components.interfaces.nsIPrefService)                                           .getBranch("joey.rss");                     prefs.deleteBranch("");                 }                 catch (a) {alert(a);}             }             break;        }    },     QueryInterface: function (iid) {        if (iid.equals(Components.interfaces.mocoJoey) ||            iid.equals(Components.interfaces.nsIObserver) ||            iid.equals(Components.interfaces.nsISupports))            return this;        Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;        return null;    },            loginCallback: function (self, status, bytes)	{        if (status == 200)        {            g_joey_hasLogged = true;			            if (self.joey_listener != null)                self.joey_listener.onStatusChange("login", 0);                        // continue going.            self.uploadDataFromGlobals();            return;        }                if (self.joey_listener != null)        {            self.joey_listener.onStatusChange("login", -1);        }        g_joey_hasLogged=false;        g_joey_in_progress = false;        self.setListener(null);	},	loginToService: function()	{        // get an listener        var listener = new JoeyStreamListener(this, this.loginCallback, null);        // the IO service        var ioService = Components.classes["@mozilla.org/network/io-service;1"]                                  .getService(Components.interfaces.nsIIOService);        // create an nsIURI        var urlstring  = getJoeyURL() + "/users/login";        var uri = ioService.newURI(urlstring, null, null);	        // get a channel for that nsIURI        var channel = ioService.newChannelFromURI(uri);        // Create an input stream with the right data.        var postData = "rest=1&data[User][username]=" + this.joey_username + "&data[User][password]=" + this.joey_password;        var inputStream = Components.classes["@mozilla.org/io/string-input-stream;1"]                                    .createInstance(Components.interfaces.nsIStringInputStream);        inputStream.setData(postData, postData.length);        // set the input stream on the channel.        var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);        uploadChannel.setUploadStream(inputStream, "application/x-www-form-urlencoded", -1);        var httpChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);        httpChannel.requestMethod = "POST";         // order important - setUploadStream resets to PUT        //channel.notificationCallbacks = listener;        channel.asyncOpen(listener, null);	},    	uploadCallback: function (self, status, bytes)	{        var listener = self.joey_listener;        self.setListener(null);        g_joey_in_progress = false;        if (listener == null)            return;        if (status == 200 || status == 519) // if all okay, or if there is a dup.        {            listener.onStatusChange("upload", 1);  // 1 = okay all good.             return;        }        if (status == 517) // Out of Space for Upload        {            // Not enough space left for user            listener.onStatusChange("upload", -2);            return;        }                if (status == 511)        {            // set the hasLogged to false, and try again.            g_joey_in_progress = false;            g_joey_hasLogged = false;            this.uploadDataInternal( this.joey_title,                                     this.joey_url,                                      this.joey_file,                                     this.joey_content_type);            return;        }        //  TODO: if it is a No Active Session error, try        //  relogging in a # of times.          //        //  TODO: map more of the http status codes to        //  something the client might want to deal with.        //  General error        listener.onStatusChange("upload", -1);        return;	},	uploadDataFromGlobals: function ()	{        const BOUNDARY="111222111";                var mis=Components.classes["@mozilla.org/io/multiplex-input-stream;1"]                          .createInstance(Components.interfaces.nsIMultiplexInputStream);        var fileBuffer = null;        if (this.joey_isfile == true)        {            var fin=Components.classes["@mozilla.org/network/file-input-stream;1"]                              .createInstance(Components.interfaces.nsIFileInputStream);            fin.init(this.joey_data, 0x1, 0, 0);            fileBuffer=Components.classes["@mozilla.org/network/buffered-input-stream;1"]                          .createInstance(Components.interfaces.nsIBufferedInputStream);            fileBuffer.init(fin, 4096);        }        var preamble = Components.classes["@mozilla.org/io/string-input-stream;1"]                                 .createInstance(Components.interfaces.nsIStringInputStream);        function createParam( name , value )        {            return "--"+BOUNDARY+"\r\n" +                    "Content-disposition: form-data;name=\"" + name + "\"\r\n\r\n" +                   value + "\r\n";        }        var start = createParam("rest", "1") +                    createParam("data[Upload][title]", this.joey_title) +                    createParam("data[Upload][referrer]", this.joey_url);        var endstring;        if (fileBuffer == null)        {            start += createParam("data[Contentsourcetype][name]", this.joey_content_type) +                     createParam("data[Contentsource][source]", this.joey_data);            endstring = "--"+BOUNDARY+"--\r\n";        }        else        {            endstring = "\r\n--"+BOUNDARY+"--\r\n";        }        preamble.setData(start, start.length);        mis.appendStream(preamble);        if (fileBuffer != null)        {            var filePreamble = Components.classes["@mozilla.org/io/string-input-stream;1"]                                         .createInstance(Components.interfaces.nsIStringInputStream);                        var filePreambleString =  "--"+BOUNDARY+"\r\n" +                 "Content-disposition: form-data;name=\"data[File][Upload]\";filename=\"data[File][Upload]\"\r\n" +                "Content-Type: " + this.joey_content_type + "\r\n" +                "Content-Length: " + this.joey_data.fileSize + "\r\n\r\n";                        filePreamble.setData(filePreambleString, filePreambleString.length);                        mis.appendStream(filePreamble);            mis.appendStream(fileBuffer);        }                var postamble = Components.classes["@mozilla.org/io/string-input-stream;1"]                                  .createInstance(Components.interfaces.nsIStringInputStream);        postamble.setData(endstring, endstring.length);        mis.appendStream(postamble);        // get an listener        var listener = new JoeyStreamListener(this, this.uploadCallback, null);        // the IO service        var ioService = Components.classes["@mozilla.org/network/io-service;1"]                                  .getService(Components.interfaces.nsIIOService);        // create an nsIURI        var urlstring  = getJoeyURL() + "/uploads/add";        var uri = ioService.newURI(urlstring, null, null);	        // get a channel for that nsIURI        var channel = ioService.newChannelFromURI(uri);        // set the input stream on the channel.        var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);        uploadChannel.setUploadStream(mis, "multipart/form-data, boundary="+BOUNDARY, mis.available());        var httpChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);        httpChannel.requestMethod = "POST";         // order important - setUploadStream resets to PUT        channel.notificationCallbacks = listener;        channel.asyncOpen(listener, null);	},};var myModule = {    firstTime: true,    registerSelf: function (compMgr, fileSpec, location, type)     {        if (this.firstTime)         {            this.firstTime = false;            throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;        }        compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);        compMgr.registerFactoryLocation(this.myCID,                                        "Joey Mozilla Component",                                        this.myProgID,                                        fileSpec,                                        location,                                        type);    },    getClassObject: function (compMgr, cid, iid)     {        if (!cid.equals(this.myCID))            throw Components.results.NS_ERROR_NO_INTERFACE;        if (!iid.equals(Components.interfaces.nsIFactory))            throw Components.results.NS_ERROR_NOT_IMPLEMENTED;        return this.myFactory;    },    myCID: Components.ID("{66b3290c-6c74-4f15-8132-d6cc74e5d37f}"),    myProgID: "@mozilla.com/joey;1",    myFactory:     {        createInstance: function (outer, iid)         {            if (outer != null)                throw Components.results.NS_ERROR_NO_AGGREGATION;            return (new mocoJoey()).QueryInterface(iid);        }    },    canUnload: function(compMgr)     {        return true;    }};function NSGetModule(compMgr, fileSpec) {    return myModule;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -