[Bbs2ch-cvs 24] CVS update: bbs2chreader/content/bbs2chreader/test

Back to archive index

flyson flyso****@users*****
2005年 10月 16日 (日) 11:05:25 JST


Index: bbs2chreader/content/bbs2chreader/test/thread-test.js
diff -u /dev/null bbs2chreader/content/bbs2chreader/test/thread-test.js:1.1
--- /dev/null	Sun Oct 16 11:05:25 2005
+++ bbs2chreader/content/bbs2chreader/test/thread-test.js	Sun Oct 16 11:05:25 2005
@@ -0,0 +1,218 @@
+/*
+	case "thread:":
+		tmpChannel = Components.classes["@mozilla.org/bbs2ch-channel;1"]
+						.createInstance(Components.interfaces.nsIBbs2chChannel);
+		tmpChannel.init(aURI, "text/plain", "Shift_JIS",
+						new b2rThreadFactory().create(aURI));
+		break;
+
+*/
+
+
+function b2rThreadFactory(){
+}
+
+b2rThreadFactory.prototype = {
+
+	create: function(aThreadURI){
+		var bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
+					.getService(Components.interfaces.nsIBbs2chService);
+		var ioService = Components.classes["@mozilla.org/network/io-service;1"]
+					.getService(Components.interfaces.nsIIOService);
+
+		var threadURLSpec = aThreadURI.spec.replace(/^bbs2ch:thread-test:/, "");
+		try{
+			var threadURL = ioService.newURI(threadURLSpec, null, null)
+					.QueryInterface(Components.interfaces.nsIURL);
+		}catch(ex){
+			return new b2rThread();
+		}
+		
+			// 板のタイプをチェック
+		var threadType = bbs2chService.getBoardType(threadURL.spec);
+		switch(threadType){
+			case bbs2chService.BOARD_TYPE_2CH:
+				return new b2r2chThread();
+			case bbs2chService.BOARD_TYPE_JBBS:
+				return new b2rJbbsThread();
+		}
+		return new b2rThread();
+	}
+
+}
+
+
+
+
+function b2rThread(){
+}
+
+b2rThread.prototype = {
+	init: function(aChannel){
+		this._channel = aChannel;
+		this._bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]
+					.getService(Components.interfaces.nsIBbs2chService);
+		this._ioService = Components.classes["@mozilla.org/network/io-service;1"]
+					.getService(Components.interfaces.nsIIOService);
+		
+		this.startThread();
+	},
+
+	startThread: function(){
+		var threadURLSpec = this._channel.URI.spec.replace(/^bbs2ch:thread-test:/, "");
+		this.requestRespond("BAD URL :\t" + threadURLSpec);
+		this.requestEnd();
+	},
+
+	requestRespond: function(aString){
+		aString = String(aString);
+		this._channel.requestRespond(aString, aString.length);
+	},
+
+	requestEnd: function(){
+		this._channel.requestEnd();
+	}
+}
+
+
+
+
+function b2r2chThread(){
+}
+
+b2r2chThread.prototype = {
+
+// ********** ********* プロパティ ********** **********
+
+	get threadURL(){
+		return this._threadURL;
+	},
+
+	get boardURL(){
+		return this._boardURL;
+	},
+
+	get type(){
+		return this._type;
+	},
+
+	get datURL(){
+		if(!this._datURL){
+			var datURLSpec = this.boardURL.resolve("dat/" + this.datID + ".dat");
+			this._datURL = this._ioService.newURI(datURLSpec, null, null)
+						.QueryInterface(Components.interfaces.nsIURL);
+		}
+		return this._datURL;
+	},
+
+	get datFile(){
+		return this._datFile;
+	},
+
+	get idxFile(){
+		return this._idxFile;
+	},
+
+	get datID(){
+		if(!this._datID)
+			this._datID = this.threadURL.directory.match(/\/(\d{9,10})/) ? RegExp.$1 : null;
+		return this._datID;
+	},
+
+	get title(){
+		return this._title;
+	},
+
+	get optionsStart(){
+	  return (this.threadURL.fileName.match(/(\d+)\-/)) ? RegExp.$1 : null;
+	},
+	get optionsLast(){
+	  return (this.threadURL.fileName.match(/l(\d+)/)) ? RegExp.$1 : null;
+	},
+	get optionsEnd(){
+	  return (this.threadURL.fileName.match(/\-(\d+)/)) ? RegExp.$1 : null;
+	},
+	get optionsNoFirst(){
+	  return (this.threadURL.fileName.indexOf("n") != -1);
+	},
+
+
+// ********** ********* メソッド ********** **********
+
+
+	startThread: function(){
+
+			// threadURL
+		var threadURLSpec = this._channel.URI.spec.replace(/^bbs2ch:thread-test:/, "");
+		this._threadURL = this._ioService.newURI(threadURLSpec, null, null)
+							.QueryInterface(Components.interfaces.nsIURL);
+			// URL が、DAT ID で終わるときは "/" を追加する
+		if(this.threadURL.fileName.match(/^\d{9,10}$/))
+			this._threadURL = this._ioService.newURI(threadURLSpec + "/", null, null)
+						.QueryInterface(Components.interfaces.nsIURL);
+		this._boardURL = this._bbs2chService.getBoardURL(this.threadURL.spec);
+		this._type = this._bbs2chService.getBoardType(this.threadURL.spec);
+		this._datFile = this._bbs2chService.getLogFileAtURL(
+								this.boardURL.resolve(this.datID + ".dat"));
+		this._idxFile = this._bbs2chService.getLogFileAtURL(
+								this.boardURL.resolve(this.datID + ".idx"));
+
+			// idx ファイルからタイトル等を取得
+		if(this.idxFile.exists()){
+			var idxContent =  this._bbs2chService.readFile(this.idxFile.path);
+
+			this._title = idxContent.match(/^title=(.+)/m) ? RegExp.$1 : "";
+			this._lineCount = idxContent.match(/^lineCount=(.+)/m) ? Number(RegExp.$1) : 0;
+			this._lastModified = idxContent.match(/^lastModified=(.+)/m) ? RegExp.$1 : "";
+			this._eTag = idxContent.match(/^etag=(.+)/m) ? RegExp.$1 : "";
+		}else{
+			this._title = "";
+			this._lineCount = 0;
+			this._lastModified = "";
+			this._eTag = "";
+		}
+
+		this.requestRespond("Thread URL    : " + this.threadURL.spec + "\n");
+		this.requestRespond("Board URL     : " + this.boardURL.spec + "\n");
+		this.requestRespond("DAT URL       : " + this.datURL.spec + "\n");
+		this.requestRespond("Type          : " + this.type + "\n");
+		this.requestRespond("DAT ID        : " + this.datID + "\n");
+		this.requestRespond("DAT File      : " + this.datFile.path + "\n");
+		this.requestRespond("IDX File      : " + this.idxFile.path + "\n");
+		this.requestRespond("----- ----- -----\n");
+		this.requestRespond("Title         : " + this.title + "\n");
+		this.requestRespond("LineCount     : " + this._lineCount + "\n");
+		this.requestRespond("LastModified  : " + this._lastModified + "\n");
+		this.requestRespond("ETag          : " + this._eTag + "\n");
+		this.requestRespond("----- ----- -----\n");
+		this.requestRespond("URL Options \n");
+		this.requestRespond("  Start       : " + this.optionsStart + "\n");
+		this.requestRespond("  Last        : " + this.optionsLast + "\n");
+		this.requestRespond("  End         : " + this.optionsEnd + "\n");
+		this.requestRespond("  NoFirst     : " + this.optionsNoFirst + "\n");
+		this.requestEnd();
+	}
+
+}
+b2r2chThread.prototype.__proto__ = b2rThread.prototype;
+
+
+
+
+function b2rJbbsThread(){
+}
+
+b2rJbbsThread.prototype = {
+
+	get datURL(){
+		if(!this._datURL){
+			var datURLSpec = this.threadURL.resolve("./").replace("read.cgi", "rawmode.cgi");
+			this._datURL = this._ioService.newURI(datURLSpec, null, null)
+						.QueryInterface(Components.interfaces.nsIURL);
+		}
+		return this._datURL;
+	},
+
+}
+b2rJbbsThread.prototype.__proto__ = b2r2chThread.prototype;
+


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