home *** CD-ROM | disk | FTP | other *** search
-
- var num_imported = 0;
- var new_imported = 0;
- var doImport = true;
-
- /*
- * Import Proxy List
- * sType is either 'url' or 'file'
- * sPath is the file or URL path
- * oList is the form list to append to
- * sUri is the RDF uri to append to
- */
- function switchproxy_anon_import(sType, sPath, oList, sUri){
-
- doImport = true;
- var sProxyList = "";
- var aProxies = new Array();
-
- try{
-
- /*
- * Get Proxy List
- */
-
- //File
- if(sType == 'file'){
- var oFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
- oFile.initWithPath(sPath);
- var oFileStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
- oFileStream.init(oFile, 0x01, 00440, null);
- var oScriptStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- oScriptStream.init(oFileStream);
-
- sProxyList = oScriptStream.read(oScriptStream.available());
- }
- //URL
- else if(sType == 'url'){
-
- var oRequest = new XMLHttpRequest();
- oRequest.open("GET", sPath, false);
- oRequest.send("")
-
- sProxyList = oRequest.responseText;
- }
- //Unknown Type
- else{
- throw "Incorrect type specified";
- }
-
- //Split Proxy List
- aProxies = sProxyList.split("\n");
-
- /*
- * Add to list
- */
- if(oList != null){
- num_imported = 0;
- new_imported = 0;
- for(var i = 0; i < aProxies.length; i++){
-
- if(!doImport) break; //Cancel
-
- aProxies[i] = switchproxy_trim(aProxies[i]);
-
- //Is valid domain & not duplicate
- if(switchproxy_isValidDomain(aProxies[i])){
- num_imported++;
-
- //Not Duplicate
- if(!switchproxy_existsInList(oList, aProxies[i])){
- new_imported++
- switchproxy_anon_addProxyToList(aProxies[i])
- }
- }
-
- }
- }
-
-
- /*
- * Add to RDF
- */
- if(sUri != null && aProxies.length > 0){
- num_imported = 0;
- new_imported = 0;
- var oRes = switchProxy_ds_getResource(sUri)
-
- //Remove existing proxies
- switchProxy_ds_removeProperty(gSProxyRdfNodeUriRoot + "#proxy", oRes);
-
- //Add Imported Proxies
- for(var i = 0; i < aProxies.length; i++){
-
- if(!doImport) break; //Cancel
-
- aProxies[i] = switchproxy_trim(aProxies[i]);
-
- //Is valid domain & not duplicate
- if(switchproxy_isValidDomain(aProxies[i])){
- switchProxy_ds_addProperty(oRes, switchProxy_ds_getResource(gSProxyRdfNodeUriRoot + "#proxy"), aProxies[i], true);
- num_imported++;
- new_imported++
- }
-
- }
- }
- }catch(err){ throw err; }
-
- }
-
- //Return the number of proxies imported
- function switchproxy_anon_getNumImported(){
- return num_imported;
- }
-
- //Return the number of new proxies imported
- function switchproxy_anon_getNewImported(){
- return new_imported;
- }
-
- //Cancel Import Process
- function switchproxy_anon_cancelImport(){
- doImport = false;
- }
-
- //Does Proxy exist in array from RDF
- function switchproxy_anon_doesProxyExist(aList){
-
- }