svnno****@sourc*****
svnno****@sourc*****
2007年 8月 5日 (日) 21:45:27 JST
Revision: 187 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=187 Author: flyson Date: 2007-08-05 21:45:27 +0900 (Sun, 05 Aug 2007) Log Message: ----------- abone 関連を b2rAboneManager として別コンポーネント化 Modified Paths: -------------- trunk/bbs2chreader/components/idl/nsIBbs2chService.idl trunk/bbs2chreader/components/nsBbs2chService.js trunk/bbs2chreader/components/nsIBbs2chService.xpt Added Paths: ----------- trunk/bbs2chreader/components/b2rAboneManager.js trunk/bbs2chreader/components/b2rIAboneManager.xpt trunk/bbs2chreader/components/idl/b2rIAboneManager.idl Added: trunk/bbs2chreader/components/b2rAboneManager.js =================================================================== --- trunk/bbs2chreader/components/b2rAboneManager.js 2007-08-04 16:51:11 UTC (rev 186) +++ trunk/bbs2chreader/components/b2rAboneManager.js 2007-08-05 12:45:27 UTC (rev 187) @@ -0,0 +1,376 @@ +/* ***** 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 bbs2chreader. + * + * The Initial Developer of the Original Code is + * flyson. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * flyson <flyso****@users*****> + * + * 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 ***** */ + + +function b2rAboneManager(){ + +} + +b2rAboneManager.prototype = { + + get ABONE_TYPE_NAME(){ return Components.interfaces.b2rIAboneManager.ABONE_TYPE_NAME }, + get ABONE_TYPE_MAIL(){ return Components.interfaces.b2rIAboneManager.ABONE_TYPE_MAIL }, + get ABONE_TYPE_ID (){ return Components.interfaces.b2rIAboneManager.ABONE_TYPE_ID }, + get ABONE_TYPE_WORD(){ return Components.interfaces.b2rIAboneManager.ABONE_TYPE_WORD }, + + _startup: function(){ + this._loadAboneData(); + dump("b2rAboneManager.startup\n"); + }, + + _shutdown: function(){ + this._saveAboneData(); + dump("b2rAboneManager.shutdown\n"); + }, + + _loadAboneData: function(){ + this._aboneData = new Array(); + this._aboneData["name"] = this._loadNgFile("NGnames.txt"); + this._aboneData["mail"] = this._loadNgFile("NGaddrs.txt"); + this._aboneData["id"] = this._loadNgFile("NGid.txt"); + this._aboneData["word"] = this._loadNgFile("NGwords.txt"); + }, + _loadNgFile: function(aNgFileName){ + var bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"] + .getService(Components.interfaces.nsIBbs2chService); + + var ngFile = bbs2chService.getDataDir(); + ngFile.appendRelativePath(aNgFileName); + if(!ngFile.exists()) return new Array(); + + var contentLine = bbs2chService.readFileLine(ngFile.path, {}); + var resultArray = new Array(); + // 空白行は読み込まない + for(let [i, line] in Iterator(contentLine)){ + if(line) resultArray.push(line); + } + return resultArray; + }, + + + _saveAboneData: function(){ + this._saveNgFile("NGnames.txt", this._aboneData["name"]); + this._saveNgFile("NGaddrs.txt", this._aboneData["mail"]); + this._saveNgFile("NGid.txt", this._aboneData["id"]); + this._saveNgFile("NGwords.txt", this._aboneData["word"]); + }, + _saveNgFile: function(aNgFileName, aboneDataArray){ + var bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"] + .getService(Components.interfaces.nsIBbs2chService); + + var ngFile = bbs2chService.getDataDir(); + ngFile.appendRelativePath(aNgFileName); + bbs2chService.writeFile(ngFile.path, aboneDataArray.join("\n"), false); + }, + + + + shouldAbone: function(aName, aMail, aID, aMsg){ + function checkFunc(aElement, aIndex, aArray){ + return this.indexOf(aElement) != -1; + } + if(this._aboneData["name"].some(checkFunc, aName)) return true; + if(this._aboneData["mail"].some(checkFunc, aMail)) return true; + if(this._aboneData["id"].some(checkFunc, aID)) return true; + if(this._aboneData["word"].some(checkFunc, aMsg)) return true; + + return false; + }, + + + getAboneData: function(aType){ + var ngArray; + switch(aType){ + case this.ABONE_TYPE_NAME: + ngArray = this._aboneData["name"]; + break; + case this.ABONE_TYPE_MAIL: + ngArray = this._aboneData["mail"]; + break; + case this.ABONE_TYPE_ID: + ngArray = this._aboneData["id"]; + break; + case this.ABONE_TYPE_WORD: + ngArray = this._aboneData["word"]; + break; + default: + return null; + } + + var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + unicodeConverter.charset = "Shift_JIS"; + + var resultArray = ngArray.map(function testFunc(aElement, aIndex, aArray){ + return unicodeConverter.ConvertToUnicode(aElement); + }); + return resultArray; + }, + + + addAbone: function(aWord, aType){ + var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + unicodeConverter.charset = "Shift_JIS"; + + var sjisWord = unicodeConverter.ConvertFromUnicode(aWord); + + var ngArray; + switch(aType){ + case this.ABONE_TYPE_NAME: + ngArray = this._aboneData["name"]; + break; + case this.ABONE_TYPE_MAIL: + ngArray = this._aboneData["mail"]; + break; + case this.ABONE_TYPE_ID: + ngArray = this._aboneData["id"]; + break; + case this.ABONE_TYPE_WORD: + ngArray = this._aboneData["word"]; + break; + default: + return; + } + + // 二重登録の禁止 + if(ngArray.indexOf(sjisWord) != -1) return; + + ngArray.push(sjisWord); + + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + + var type = Components.classes["@mozilla.org/supports-PRInt32;1"] + .createInstance(Components.interfaces.nsISupportsPRInt32); + type.data = aType; + + os.notifyObservers(type, "b2r-abone-data-add", aWord); + }, + + + removeAbone: function(aWord, aType){ + var unicodeConverter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Components.interfaces.nsIScriptableUnicodeConverter); + unicodeConverter.charset = "Shift_JIS"; + + var sjisWord = unicodeConverter.ConvertFromUnicode(aWord); + + var ngArray; + switch(aType){ + case this.ABONE_TYPE_NAME: + ngArray = this._aboneData["name"]; + break; + case this.ABONE_TYPE_MAIL: + ngArray = this._aboneData["mail"]; + break; + case this.ABONE_TYPE_ID: + ngArray = this._aboneData["id"]; + break; + case this.ABONE_TYPE_WORD: + ngArray = this._aboneData["word"]; + break; + default: + return; + } + + var wordIndex = ngArray.indexOf(sjisWord); + if(wordIndex != -1) ngArray.splice(wordIndex, 1); + + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + var type = Components.classes["@mozilla.org/supports-PRInt32;1"] + .createInstance(Components.interfaces.nsISupportsPRInt32); + type.data = aType; + os.notifyObservers(type, "b2r-abone-data-remove", aWord); + + }, + + + + + // ********** ********* implements nsIObserver ********** ********** + + observe: function(aSubject, aTopic, aData){ + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + switch(aTopic){ + case "app-startup": + dump("b2rAboneManager\n"); + os.addObserver(this, "profile-after-change", false); + os.addObserver(this, "quit-application", false); + break; + case "profile-after-change": + this._startup(); + os.removeObserver(this, "profile-after-change"); + break; + case "quit-application": + this._shutdown(); + os.removeObserver(this, "quit-application"); + break; + } + }, + + + // ********** ********* implements nsIClassInfo ********** ********** + + get classDescription() { + return "b2rAboneManager js component"; + }, + get classID() { + return Components.ID("{ff8a31ea-d3c1-47f1-a72b-0a2a0975d69a}"); + }, + get implementationLanguage() { + return Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT; + }, + get flags() { + return Components.interfaces.nsIClassInfo.SINGLETON; + }, + get contractID() { + return "@mozilla.org/b2r-abone-manager;1"; + }, + + getInterfaces: function(aCount) { + var interfaces = [ + Components.interfaces.b2rIAboneManager, + Components.interfaces.nsIClassInfo, + Components.interfaces.nsIObserver, + Components.interfaces.nsISupports + ]; + aCount.value = interfaces.length; + return interfaces; + }, + + getHelperForLanguage: function(aLanguage) { + return null; + }, + + + // ********** ********* implements nsISupports ********** ********** + + QueryInterface: function(aIID){ + if(aIID.equals(Components.interfaces.b2rIAboneManager) || + aIID.equals(Components.interfaces.nsIClassInfo) || + aIID.equals(Components.interfaces.nsIObserver) || + aIID.equals(Components.interfaces.nsISupports)){ + return this; + } + throw Components.results.NS_ERROR_NO_INTERFACE; + } + +}; + + + + +// ********** ********* Component Registration ********** ********** + +var Factory = { + + createInstance: function (aOuter, aIID){ + if(aOuter != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + if(aIID.equals(Components.interfaces.b2rIAboneManager)) + return this.getInstance(aIID); + if(aIID.equals(Components.interfaces.nsIClassInfo)) + return this.getInstance(aIID); + if(aIID.equals(Components.interfaces.nsIObserver)) + return this.getInstance(aIID); + if(aIID.equals(Components.interfaces.nsISupports)) + return this.getInstance(aIID); + + throw Components.results.NS_ERROR_INVALID_ARG; + }, + + getInstance: function(aIID){ + if(!this._instance){ + this._instance = new b2rAboneManager(); + } + return this._instance.QueryInterface(aIID); + } + +}; + +var Module = { + + CONTRACTID: "@mozilla.org/b2r-abone-manager;1", + CID: Components.ID("{ff8a31ea-d3c1-47f1-a72b-0a2a0975d69a}"), + CNAME: "b2rAboneManager js component", + + + registerSelf: function(aCompMgr, aFileSpec, aLocation, aType){ + aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + aCompMgr.registerFactoryLocation(this.CID, this.CNAME, this.CONTRACTID, + aFileSpec, aLocation, aType); + var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + categoryManager.addCategoryEntry("app-startup", this.CONTRACTID, + this.CONTRACTID, true, true); + }, + + + unregisterSelf: function(aCompMgr, aFileSpec, aLocation){ + aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + + var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + categoryManager.deleteCategoryEntry("app-startup", this.CONTRACTID, true); + }, + + + getClassObject: function(aCompMgr, aCID, aIID){ + if(aCID.equals(this.CID)) + return Factory; + + if(!aIID.equals(Components.interfaces.nsIFactory)) + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + + canUnload: function(aCompMgr){ + return true; + } + +}; + + +function NSGetModule(aCompMgr, aFileSpec){ + return Module; +} \ No newline at end of file Added: trunk/bbs2chreader/components/b2rIAboneManager.xpt =================================================================== (Binary files differ) Property changes on: trunk/bbs2chreader/components/b2rIAboneManager.xpt ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/bbs2chreader/components/idl/b2rIAboneManager.idl =================================================================== --- trunk/bbs2chreader/components/idl/b2rIAboneManager.idl 2007-08-04 16:51:11 UTC (rev 186) +++ trunk/bbs2chreader/components/idl/b2rIAboneManager.idl 2007-08-05 12:45:27 UTC (rev 187) @@ -0,0 +1,29 @@ +#include "nsISupports.idl" + +interface nsIVariant; + +[scriptable, uuid(cfdf8cd6-c1b2-4d17-a82b-0616d457e647)] +interface b2rIAboneManager : nsISupports +{ + + const unsigned long ABONE_TYPE_NAME = 0; + const unsigned long ABONE_TYPE_MAIL = 1; + const unsigned long ABONE_TYPE_ID = 2; + const unsigned long ABONE_TYPE_WORD = 3; + + + /** + * レスが、NGワードに該当したら真を返す。引数の文字列は SJIS を渡すこと + * @param aName 名前 + * @param aMail メールアドレス + * @param aID ID + * @param aMsg レス本文 + * @return boolean 該当したら真 + */ + boolean shouldAbone(in AString aName, in AString aMail, in AString aID, in AString aMsg); + + nsIVariant getAboneData(in unsigned long aType); + + boolean addAbone(in AString aWord, in unsigned long aType); + boolean removeAbone(in AString aWord, in unsigned long aType); +}; \ No newline at end of file Modified: trunk/bbs2chreader/components/idl/nsIBbs2chService.idl =================================================================== --- trunk/bbs2chreader/components/idl/nsIBbs2chService.idl 2007-08-04 16:51:11 UTC (rev 186) +++ trunk/bbs2chreader/components/idl/nsIBbs2chService.idl 2007-08-05 12:45:27 UTC (rev 187) @@ -216,22 +216,8 @@ */ nsIHttpChannel getHttpChannel(in nsIURL aURL); - /** - * レスが、NGワードに該当したら真を返す。引数の文字列は SJIS を渡すこと - * @param aName 名前 - * @param aMail メールアドレス - * @param aID ID - * @param aMsg レス本文 - * @return boolean 該当したら真 - */ - boolean shouldAbone(in AString aName, in AString aMail, in AString aID, in AString aMsg); /** - * あぼーんデータを再読み込みする - */ - void refreshAboneData(); - - /** * 2ch ビューア認証を行う */ void maruAuth(); Modified: trunk/bbs2chreader/components/nsBbs2chService.js =================================================================== --- trunk/bbs2chreader/components/nsBbs2chService.js 2007-08-04 16:51:11 UTC (rev 186) +++ trunk/bbs2chreader/components/nsBbs2chService.js 2007-08-05 12:45:27 UTC (rev 187) @@ -123,54 +123,6 @@ -function b2rAbone(aBbs2chService){ - this._init(aBbs2chService); -} - -b2rAbone.prototype = { - - _init: function(aBbs2chService){ - this._bbs2chService = aBbs2chService; - this.refreshAboneData(); - }, - - shouldAbone: function(aName, aMail, aID, aMsg){ - function checkFunc(aElement, aIndex, aArray){ - return this.indexOf(aElement) != -1; - } - if(this._aboneData["name"].some(checkFunc, aName)) return true; - if(this._aboneData["mail"].some(checkFunc, aMail)) return true; - if(this._aboneData["id"].some(checkFunc, aID)) return true; - if(this._aboneData["word"].some(checkFunc, aMsg)) return true; - - return false; - }, - - refreshAboneData: function(){ - this._aboneData = new Array(); - this._aboneData["name"] = this._loadNgFile("NGnames.txt"); - this._aboneData["mail"] = this._loadNgFile("NGaddrs.txt"); - this._aboneData["id"] = this._loadNgFile("NGid.txt"); - this._aboneData["word"] = this._loadNgFile("NGwords.txt"); - }, - - _loadNgFile: function(aNgFilePath){ - var ngFile = this._bbs2chService.getDataDir(); - ngFile.appendRelativePath(aNgFilePath); - if(!ngFile.exists()) return new Array(); - - var contentLine = this._bbs2chService.readFileLine(ngFile.path, {}); - var resultArray = new Array(); - // 空白行は読み込まない - for(var i=0; i<contentLine.length; i++){ - if(contentLine[i]) resultArray.push(contentLine[i]); - } - return resultArray; - } - -} - - function nsBbs2chService(){ // getBoardType で利用する例外的な URL のリスト( 2ch だけど板じゃない URL) this._exURLs = new Array( @@ -185,7 +137,6 @@ this.__unicodeConverter = null; this.__ioService = null; this._globalHistory = null; - this._abone = null; this._pref = null; this._prefDefault = null; this._userAgent = null; @@ -284,7 +235,6 @@ _delayInit: function(){ this._globalHistory = new b2rGlobalHistory(this); - this._abone = new b2rAbone(this); this._maruAutoAuth(); }, @@ -292,7 +242,6 @@ this.__unicodeConverter = null; this.__ioService = null; this._globalHistory = null; - this._abone = null; this._pref = null; this._prefDefault = null; this._userAgent = null; @@ -636,15 +585,6 @@ }, - shouldAbone: function(aName, aMail, aID, aMsg){ - return this._abone.shouldAbone(aName, aMail, aID, aMsg); - }, - - refreshAboneData: function(){ - this._abone.refreshAboneData(); - }, - - _createLocalFile: function(aFilePath){ var localFile = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); Modified: trunk/bbs2chreader/components/nsIBbs2chService.xpt =================================================================== (Binary files differ)