svnno****@sourc*****
svnno****@sourc*****
2008年 1月 26日 (土) 23:14:45 JST
Revision: 335 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=335 Author: flyson Date: 2008-01-26 23:14:44 +0900 (Sat, 26 Jan 2008) Log Message: ----------- b2rStorageBoard Modified Paths: -------------- trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js trunk/bbs2chreader/chrome/content/bbs2chreader/board/subscribe.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/b2rStorageBoard.js -------------- next part -------------- Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js 2008-01-26 13:44:58 UTC (rev 334) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/board/page.js 2008-01-26 14:14:44 UTC (rev 335) @@ -502,6 +502,9 @@ return; } + var b2rStorageService = Cc["@bbs2ch.sourceforge.jp/b2r-storage-service;1"].getService(Ci.b2rIStorageService); + b2rStorageService.boardSubjectUpdate(gBoardItems.url, gBoardItems.type, gBoardItems.subjectFile); + if(!gBoardItems.settingFile.exists() || gBoardItems.settingFile.fileSize==0){ settingUpdate(); }else{ Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/board/subscribe.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/board/subscribe.js 2008-01-26 13:44:58 UTC (rev 334) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/board/subscribe.js 2008-01-26 14:14:44 UTC (rev 335) @@ -393,6 +393,10 @@ gTreeSubscribe.treeBoxObject.endUpdateBatch(); if(boardTreeItemLength > 0){ setBoardState(boardItmes.url.spec, "Updated"); + + var b2rStorageService = Cc["@bbs2ch.sourceforge.jp/b2r-storage-service;1"].getService(Ci.b2rIStorageService); + b2rStorageService.boardSubjectUpdate(boardItmes.url, boardItmes.type, boardItmes.subjectFile); + }else{ setBoardState(boardItmes.url.spec, "Normal"); } Added: trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBoard.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBoard.js 2008-01-26 13:44:58 UTC (rev 334) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/components/b2rStorageBoard.js 2008-01-26 14:14:44 UTC (rev 335) @@ -0,0 +1,241 @@ +/* ***** 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) 2008 + * 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 b2rStorageBoard(){ + this._init(); +} + +b2rStorageBoard.prototype = { + + _init: function(){ + var database = gStorageService.database; + database.beginTransaction(); + try{ + if(!database.tableExists("board_subject")){ + let sql = <> + CREATE TABLE board_subject( + board_id TEXT NOT NULL, + dat_id TEXT NOT NULL, + title TEXT, + title_n TEXT, + line_count INTEGER DEFAULT 0, + ordinal INTEGER DEFAULT 0 + ); + </>.toString().replace(/\t/g, ""); + database.executeSimpleSQL(sql); + // database.executeSimpleSQL("CREATE INDEX IF NOT EXISTS board_subject_board_id_index ON board_subject(board_id);"); + // database.executeSimpleSQL("CREATE INDEX IF NOT EXISTS board_subject_dat_id_index ON board_subject(dat_id);"); + } + + if(!database.tableExists("board_data")){ + let sql = <> + CREATE TABLE board_data( + board_id TEXT NOT NULL, + url TEXT NOT NULL, + type INTEGER DEFAULT 0, + last_modified INTEGER DEFAULT 0, + subscribed INTEGER DEFAULT 0, + post_name TEXT, + post_mail TEXT + ); + </>.toString().replace(/\t/g, ""); + database.executeSimpleSQL(sql); + // database.executeSimpleSQL("CREATE INDEX IF NOT EXISTS board_data_board_id_index ON board_data(board_id);"); + } + }catch(ex){ + Components.utils.reportError(ex); + }finally{ + database.commitTransaction(); + } + + this._statements = new Array(); + this._statements["boardSubjectUpdate_insert"] = database.createStatement( + "INSERT INTO board_subject(board_id, dat_id, title, title_n, line_count, ordinal) VALUES(?1,?2,?3,?4,?5,?6);"); + + this._statements["_setBoardData_select"] = database.createStatement( + "SELECT _rowid_ FROM board_data WHERE board_id=?1;"); + this._statements["_setBoardData_update"] = database.createStatement( + "UPDATE board_data SET url=?1, type=?2, last_modified=?3 WHERE _rowid_=?4;"); + this._statements["_setBoardData_insert"] = database.createStatement( + "INSERT OR REPLACE INTO board_data(board_id, url, type, last_modified) VALUES(?1,?2,?3,?4);"); + }, + + + boardSubjectUpdate: function(aBoardURL, aBoardType, aSubjectFile){ + var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService"); + var boardID = b2rService.threadUtils.getBoardID(aBoardURL); + var database = gStorageService.database; + + + // 行の解析に使う正規表現 + var regLine; + switch(aBoardType){ + case b2rService.BOARD_TYPE_2CH: + case b2rService.BOARD_TYPE_BE2CH: + regLine = /^(\d{9,10})\.dat<>(.+) ?\((\d{1,4})\)/; + break; + case b2rService.BOARD_TYPE_JBBS: + case b2rService.BOARD_TYPE_MACHI: + regLine = /^(\d{9,10})\.cgi,(.+) ?\((\d{1,4})\)/; + break; + } + + var charset; + switch(aBoardType){ + case b2rService.BOARD_TYPE_2CH: + charset = "Shift_JIS"; + break; + case b2rService.BOARD_TYPE_BE2CH: + case b2rService.BOARD_TYPE_JBBS: + case b2rService.BOARD_TYPE_MACHI: + charset = "euc-jp"; + break; + } + + var fileStream = b2rService.io.getFileInputStream(aSubjectFile, charset) + .QueryInterface(Ci.nsIUnicharLineInputStream); + + database.beginTransaction(); + try{ + database.executeSimpleSQL("DELETE FROM board_subject WHERE board_id='" + boardID + "';"); + var statement = this._statements["boardSubjectUpdate_insert"]; + let(line={}, c=0, ordinal=0){ + do { + c = fileStream.readLine(line); + if(!regLine.test(line.value)) continue; + let datID = RegExp.$1; + let title = gStorageService._html2Text(RegExp.$2); + let count = Number(RegExp.$3); + + statement.bindStringParameter(0, boardID); + statement.bindStringParameter(1, datID); + statement.bindStringParameter(2, title); + statement.bindStringParameter(3, gStorageService._getNormarizedString(title)); + statement.bindInt32Parameter(4, count); + statement.bindInt32Parameter(5, ordinal); + statement.execute(); + ordinal++; + }while(c); + } + }catch(ex){ + Components.utils.reportError(ex); + }finally{ + database.commitTransaction(); + fileStream.close(); + } + this._setBoardData(aBoardURL, aBoardType, aSubjectFile.lastModifiedTime); + }, + + + _setBoardData: function(aBoardURL, aType, aLastModified){ + var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService"); + var boardID = b2rService.threadUtils.getBoardID(aBoardURL); + + var database = gStorageService.database; + database.beginTransaction(); + try{ + var statement; + statement = this._statements["_setBoardData_select"]; + statement.bindStringParameter(0, boardID); + var boardRowID = 0; + if(statement.executeStep()){ + boardRowID = statement.getInt64(0); + } + statement.reset(); + + if(boardRowID){ + statement = this._statements["_setBoardData_update"]; + statement.bindStringParameter(0, aBoardURL.spec); + statement.bindInt32Parameter(1, aType); + statement.bindInt64Parameter(2, aLastModified); + statement.bindInt64Parameter(3, boardRowID); + }else{ + statement = this._statements["_setBoardData_insert"]; + statement.bindStringParameter(0, boardID); + statement.bindStringParameter(1, aBoardURL.spec); + statement.bindInt32Parameter(2, aType); + statement.bindInt64Parameter(3, aLastModified); + statement.execute(); + } + }catch(ex){ + Components.utils.reportError(ex); + }finally{ + database.commitTransaction(); + } + }, + + _getBoardData: function(aBoardID){ + return null; + } + +}; + + +function b2rBoardData(aBoardID, aURL, aType, aLastModified, aSubscribed, aPostName, aPostMail){ + this._boardID = aBoardID; + this._url = aURL; + this._type = aType; + this._lastModified = aLastModified; + this._subscribed = aSubscribed; + this._postName = aPostName; + this._postMail = aPostMail; +} + +b2rBoardData.prototype = { + get boardID() { + return this._boardID; + }, + get url() { + return this._url; + }, + get type() { + return this._type; + }, + get lastModified() { + return this._lastModified; + }, + get subscribed() { + return this._subscribed; + }, + get postName() { + return this._postName; + }, + get postMail() { + return this._postMail; + } +}; \ No newline at end of file Modified: trunk/bbs2chreader/components/b2rIStorageService.xpt =================================================================== (Binary files differ) Modified: trunk/bbs2chreader/components/b2rStorageService.js =================================================================== --- trunk/bbs2chreader/components/b2rStorageService.js 2008-01-26 13:44:58 UTC (rev 334) +++ trunk/bbs2chreader/components/b2rStorageService.js 2008-01-26 14:14:44 UTC (rev 335) @@ -82,6 +82,11 @@ }, + boardSubjectUpdate: function(aBoardURL, aBoardType, aSubjectFile){ + this._board.boardSubjectUpdate(aBoardURL, aBoardType, aSubjectFile); + }, + + _startup: function(){ var b2rService = XPC.getService("@bbs2ch.sourceforge.jp/b2r-global-service;1", "b2rIGlobalService"); var dbFile = b2rService.io.getDataDir(); @@ -96,7 +101,10 @@ 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); + this._thread = new b2rStorageThread(); + this._board = new b2rStorageBoard(); }, @@ -112,14 +120,16 @@ var unicodeNormalizer = Cc["@mozilla.org/intl/unicodenormalizer;1"].createInstance(Ci.nsIUnicodeNormalizer); var normalizedStr = {}; unicodeNormalizer.NormalizeUnicodeNFKC(aString.toLowerCase(), normalizedStr); - normalizedStr = normalizedStr.value - .replace(/"/g, "\"") - .replace(/&/g, "&") - .replace(/</g, "<") - .replace(/>/g, ">") - return normalizedStr; + return this._html2Text(normalizedStr.value); }, + _html2Text: function(aString){ + if(aString.indexOf("&") == -1){ + return aString; + } + return aString.replace(/"/g, "\"").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); + }, + // ********** ********* implements nsIObserver ********** ********** observe: function(aSubject, aTopic, aData){ Modified: trunk/bbs2chreader/components/idl/b2rIStorageService.idl =================================================================== --- trunk/bbs2chreader/components/idl/b2rIStorageService.idl 2008-01-26 13:44:58 UTC (rev 334) +++ trunk/bbs2chreader/components/idl/b2rIStorageService.idl 2008-01-26 14:14:44 UTC (rev 335) @@ -3,6 +3,7 @@ interface mozIStorageConnection; interface nsIURL; interface nsIVariant; +interface nsIFile; [scriptable, uuid(fd50f55e-ef2a-49f3-8e9e-10e4d3295939)] interface b2rIThreadData : nsISupports @@ -39,4 +40,7 @@ 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); + }; \ No newline at end of file