[Bbs2ch-cvs 366] [348] b2rStorageBbsmenu の実装 etThreadDataArray() の廃止

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 2月 3日 (日) 00:08:23 JST


Revision: 348
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=348
Author:   flyson
Date:     2008-02-03 00:08:23 +0900 (Sun, 03 Feb 2008)

Log Message:
-----------
b2rStorageBbsmenu の実装 etThreadDataArray() の廃止

Modified Paths:
--------------
    trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js
    trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageThread.js
    trunk/bbs2chreader/components/b2rIStorageService.xpt
    trunk/bbs2chreader/components/b2rStorageService.js
    trunk/bbs2chreader/components/idl/b2rIStorageService.idl

Added Paths:
-----------
    trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBbsmenu.js


-------------- next part --------------
Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js	2008-02-01 15:34:07 UTC (rev 347)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/bbsmenu/page.js	2008-02-02 15:08:23 UTC (rev 348)
@@ -85,6 +85,10 @@
 
 
 function createBbsmenuXML(){
+
+	var b2rStorageService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-storage-service;1", "b2rIStorageService");
+	b2rStorageService.updateBbsmenu(gBbsMenuFile);
+
 		// bbsmenu.html を読み込んで、行を配列に格納
 	var contentLines = gBbs2chService.readFile(gBbsMenuFile.path);
 	contentLines = gBbs2chService.fromSJIS(contentLines);

Added: trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBbsmenu.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBbsmenu.js	2008-02-01 15:34:07 UTC (rev 347)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBbsmenu.js	2008-02-02 15:08:23 UTC (rev 348)
@@ -0,0 +1,90 @@
+function b2rStorageBbsmenu(){
+	this._init();
+}
+
+b2rStorageBbsmenu.prototype = {
+	_init: function(){
+		var database = gStorageService.database;
+		database.beginTransaction();
+		try{
+			if(!database.tableExists("bbsmenu_category")){
+				let sql = <>
+					CREATE TABLE bbsmenu_category(
+					    title TEXT NOT NULL
+					);
+				</>.toString().replace(/\t/g, "");
+				database.executeSimpleSQL(sql);
+			}
+			if(!database.tableExists("bbsmenu_board")){
+				let sql = <>
+					CREATE TABLE bbsmenu_board(
+					    title    TEXT NOT NULL,
+					    title_n  TEXT NOT NULL,
+					    url      TEXT NOT NULL,
+					    type     INTEGER NOT NULL,
+					    board_id EXT NOT NULL,
+					    category INTEGER NOT NULL
+					);
+				</>.toString().replace(/\t/g, "");
+				database.executeSimpleSQL(sql);
+			}
+		}catch(ex){
+			Components.utils.reportError(ex);
+		}finally{
+			database.commitTransaction();
+		}
+
+	},
+
+
+	updateBbsmenu: function(aBbsmenuFile){
+		var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService");
+		var ioService = XPC.getService("@mozilla.org/network/io-service;1", "nsIIOService");
+
+		if(!aBbsmenuFile.exists()){
+			Components.utils.reportError("b2rStorageBbsmenu.createBbsmenu() : bbsmenu.html Is Not Found");
+			return;
+		}
+
+		var contentLines = b2rService.io.readFile(aBbsmenuFile, "Shift_JIS");
+			// ‰üsˆÊ’u‚ª‚¨‚©‚µ‚¢•”•ª‚̏C³
+		contentLines = contentLines.replace(/<\/B><BR><A HREF/igm, "</B><BR>\n<A HREF");
+		contentLines = contentLines.split("\n");
+
+		var categoryReg = /<BR><B>([^<]+)<\/B><BR>/i;
+		var threadReg	= /^<A HREF=([^> ]+)>([^<]+)<\/A>/i;
+		var threadReg2	= /^<A HREF=([^> ]+) TARGET=_blank>([^<]+)<\/A>/i;
+
+		var database = gStorageService.database;
+		var sql = "INSERT INTO bbsmenu_category(title) VALUES(?1);";
+		var categoryInsertStatement = database.createStatement(sql);
+		sql = "INSERT INTO bbsmenu_board(title, title_n, url, type, board_id, category) VALUES(?1, ?2, ?3, ?4, ?5, ?6);";
+		var bosrdInsertStatement = database.createStatement(sql);
+
+		database.executeSimpleSQL("DELETE FROM bbsmenu_category");
+		database.executeSimpleSQL("DELETE FROM bbsmenu_board");
+
+		var currentCategoryID = null;
+		for each(let line in contentLines){
+			if(categoryReg.test(line)){
+				let title = RegExp.$1;
+				categoryInsertStatement.bindStringParameter(0, title);
+				categoryInsertStatement.execute();
+				currentCategoryID = database.lastInsertRowID;
+			}else if((threadReg.test(line) || threadReg2.test(line)) && currentCategoryID){
+				let url = ioService.newURI(RegExp.$1, null, null).QueryInterface(Ci.nsIURL);
+				let title = RegExp.$2;
+				let type = b2rService.threadUtils.getBoardType(url);
+				bosrdInsertStatement.bindStringParameter(0, title);
+				bosrdInsertStatement.bindStringParameter(1, gStorageService._getNormarizedString(title));
+				bosrdInsertStatement.bindStringParameter(2, url.spec);
+				bosrdInsertStatement.bindInt32Parameter(3, type);
+				bosrdInsertStatement.bindStringParameter(4, (type==5) ? "" : b2rService.threadUtils.getBoardID(url));
+				bosrdInsertStatement.bindInt32Parameter(5, currentCategoryID);
+				bosrdInsertStatement.execute();
+			}
+
+		}
+	}
+
+};

Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageThread.js
===================================================================
--- trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageThread.js	2008-02-01 15:34:07 UTC (rev 347)
+++ trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageThread.js	2008-02-02 15:08:23 UTC (rev 348)
@@ -87,9 +87,6 @@
 
 		this._statements["deleteThreadData_delete"] = database.createStatement(
 				"DELETE FROM thread_data WHERE board_id=?1 AND dat_id=?2");
-
-		this._statements["getThreadDataArray_select"] = database.createStatement(
-				"SELECT dat_id,title,line_count FROM thread_data WHERE board_id=?1");
 	},
 
 
@@ -189,31 +186,6 @@
 		}finally{
 			gStorageService.database.commitTransaction();
 		}
-	},
-
-	getThreadDataArray:function(aBoardURL){
-		var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService");
-		var boardID = b2rService.threadUtils.getBoardID(aBoardURL);
-
-		var resultArray = new Array();
-		gStorageService.database.beginTransaction();
-		try{
-			var statement = this._statements["getThreadDataArray_select"];
-			statement.bindStringParameter(0, boardID);
-			while(statement.executeStep()){
-				resultArray.push({
-					datID: statement.getString(0),   // datID
-					title: statement.getString(1),   // title
-					lineCount: statement.getInt32(2) // lineCount
-				});
-			}
-			statement.reset();
-		}catch(ex){
-			Components.utils.reportError(ex);
-		}finally{
-			gStorageService.database.commitTransaction();
-		}
-		return resultArray;
 	}
 
 };

Modified: trunk/bbs2chreader/components/b2rIStorageService.xpt
===================================================================
(Binary files differ)

Modified: trunk/bbs2chreader/components/b2rStorageService.js
===================================================================
--- trunk/bbs2chreader/components/b2rStorageService.js	2008-02-01 15:34:07 UTC (rev 347)
+++ trunk/bbs2chreader/components/b2rStorageService.js	2008-02-02 15:08:23 UTC (rev 348)
@@ -77,11 +77,7 @@
 	deleteThreadData: function(aBoardURL, aDatID){
 		this._thread.deleteThreadData(aBoardURL, aDatID);
 	},
-	getThreadDataArray: function(aBoardURL){
-		return this._thread.getThreadDataArray(aBoardURL);
-	},
 
-
 	boardSubjectUpdate: function(aBoardURL, aBoardType, aSubjectFile){
 		this._board.boardSubjectUpdate(aBoardURL, aBoardType, aSubjectFile);
 	},
@@ -89,6 +85,10 @@
 		return this._board.getBoardData(aBoardURL);
 	},
 
+	updateBbsmenu: function(aBbsmenuFile){
+		return this._bbsmenu.updateBbsmenu(aBbsmenuFile);
+	},
+
 	_startup: function(){
 		var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService");
 		var dbFile = b2rService.io.getDataDir();
@@ -104,9 +104,11 @@
 		var subScriptLoader = XPC.getService("@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader");
 		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rStorageThread.js", null);
 		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rStorageBoard.js", null);
+		subScriptLoader.loadSubScript("chrome://bbs2chreader/content/components/b2rStorageBbsmenu.js", null);
 
 		this._thread = new b2rStorageThread();
 		this._board = new b2rStorageBoard();
+		this._bbsmenu = new b2rStorageBbsmenu();
 	},
 
 

Modified: trunk/bbs2chreader/components/idl/b2rIStorageService.idl
===================================================================
--- trunk/bbs2chreader/components/idl/b2rIStorageService.idl	2008-02-01 15:34:07 UTC (rev 347)
+++ trunk/bbs2chreader/components/idl/b2rIStorageService.idl	2008-02-02 15:08:23 UTC (rev 348)
@@ -52,9 +52,9 @@
 
 	void deleteThreadData(in nsIURL aBoardURL, in string aDatID);
 
-	nsIVariant getThreadDataArray(in nsIURL aBoardURL);
-
 	void boardSubjectUpdate(in nsIURL aBoardURL, in unsigned long aBoardType, in nsIFile aSubjectFile);
 
 	b2rIBoardData getBoardData(in nsIURL aBoardURL);
+
+	void updateBbsmenu(in nsIFile aBbsmenuFile);
 };
\ No newline at end of file


bbs2ch-cvs メーリングリストの案内
Back to archive index