From: pho Date: Tue, 11 Nov 2008 09:02:04 +0000 (+0900) Subject: hexdumping X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=9c2fc861f3ed609ebb4d0f135aea38ca055bbea8;p=Rakka.git hexdumping darcs-hash:20081111090204-62b54-52da8f89c5dbc653f3f0ea9a014a3d9af543eec4.gz --- diff --git a/Rakka.cabal b/Rakka.cabal index dca3575..37a87ab 100644 --- a/Rakka.cabal +++ b/Rakka.cabal @@ -37,6 +37,7 @@ Extra-Source-Files: js/base.js js/base64.js js/editPage.js + js/hexDump.js js/jquery-1.2.2.js js/jquery-dom.js js/localFile.js diff --git a/defaultPages/StyleSheet/CieloNegro.xml b/defaultPages/StyleSheet/CieloNegro.xml index c663274..e89e3ab 100644 --- a/defaultPages/StyleSheet/CieloNegro.xml +++ b/defaultPages/StyleSheet/CieloNegro.xml @@ -208,6 +208,12 @@ table.pageEditor { .pageEditor textarea.source { height: 30em; } +.pageEditor textarea.hexDump { + font-size: 70%; + font-family: monospace; + white-space: pre; + height: 10em; +} .pageEditor input[type="button"] { margin: 0 2px; } diff --git a/defaultPages/StyleSheet/Default.xml b/defaultPages/StyleSheet/Default.xml index 15be513..06b84e8 100644 --- a/defaultPages/StyleSheet/Default.xml +++ b/defaultPages/StyleSheet/Default.xml @@ -212,6 +212,12 @@ table.pageEditor { .pageEditor textarea.source { height: 30em; } +.pageEditor textarea.hexDump { + font-size: 70%; + font-family: monospace; + white-space: pre; + height: 10em; +} .pageEditor input[type="button"] { margin: 0 2px; } diff --git a/js/Makefile b/js/Makefile index ccd88fb..1fc9cee 100644 --- a/js/Makefile +++ b/js/Makefile @@ -7,6 +7,7 @@ SOURCES = \ base.js \ base64.js \ editPage.js \ + hexDump.js \ localFile.js \ login.js \ redirection.js \ diff --git a/js/editPage.js b/js/editPage.js index e4483a1..eb5097c 100644 --- a/js/editPage.js +++ b/js/editPage.js @@ -36,7 +36,8 @@ })(); var source = $page.attr("redirect") != null ? $page.attr("redirect") - : $page.find("textData").text() + : $page.attr("isBinary") != null ? Rakka.decodeBase64($page.find("binaryData").text()) + : $page.find("textData").text() ; var summary = $page.find("summary").text(); @@ -228,15 +229,18 @@ $(fldJSSource).change(makeDirty); + var uploadFileBin + = (defaultType == "binary" && source != null ? source : ""); var fldUploadFile - = $.INPUT({type: "text", disabled: true}); + = $.TEXTAREA({className: "hexDump", disabled: true}, Rakka.hexDump(uploadFileBin, 128)); var btnSelectFile - = $.INPUT({type: "button", value: "Select File"}); + = $.INPUT({type: "button", value: "Select file..."}); $(btnSelectFile).click(function () { var path = Rakka.selectFile("Select a binary file to upload", "open"); if (path != null) { - fldUploadFile.value = path; + uploadFileBin = Rakka.loadLocalBinaryFile(path); + fldUploadFile.value = Rakka.hexDump(uploadFileBin, 128); makeDirty(); } }); @@ -261,9 +265,9 @@ fldPageName.value, fldRakkaSource.value); } else if (btnTypeBinary.checked) { - if (fldUploadFile.value != "") { + if (uploadFileBin != "") { previewBinaryPage( - fldPageName.value, fldUploadFile.value); + fldPageName.value, uploadFileBin); } } }); @@ -318,7 +322,7 @@ $(selPageLang).val(), otherLangs, fldSummary.value, - fldUploadFile.value); + uploadFileBin); } } else if (btnTypeRedirect.checked) { @@ -478,7 +482,7 @@ } if (btnTypeBinary.checked) { - if (fldUploadFile.value == "") { + if (uploadFileBin == "") { return false; } } @@ -500,6 +504,7 @@ .add(fldRedirect) .change(validate) .keyup(validate); + $(btnSelectFile).click(validate); validate(); if (oldRevision == null || oldRevision == 0) { @@ -535,17 +540,16 @@ }); }; - var previewBinaryPage = function (pageName, path) { + var previewBinaryPage = function (pageName, data) { Rakka.displayWaitingMessage("Loading... please wait."); /* Firefox でバイナリを送らうとすると 0x00 の位置で切れてしまふ。*/ - var bin = Rakka.loadLocalBinaryFile(path); var url = Rakka.baseURI + "render/" + encodeURI(pageName); $.ajax({ type : "POST", url : url, contentType: "application/x-rakka-base64-stream", - data : Rakka.encodeBase64(bin), + data : Rakka.encodeBase64(data), processData: false, success : function (resultDoc) { Rakka.hideWaitingMessage(); @@ -649,7 +653,7 @@ }); }; - var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, path) { + var submitBinaryPage = function (pageName, oldRevision, givenPageName, isLocked, lang, otherLangs, summary, data) { var NS = "http://cielonegro.org/schema/Rakka/Page/1.0"; var doc = document.implementation.createDocument(NS, "page", null); var page = doc.documentElement; @@ -691,9 +695,7 @@ } page.appendChild(oLang); - var bin = Rakka.loadLocalBinaryFile(path); - var b64 = Rakka.encodeBase64(bin); - + var b64 = Rakka.encodeBase64(data); var binaryData = doc.createElementNS(NS, "binaryData"); binaryData.appendChild( doc.createTextNode(b64)); diff --git a/js/hexDump.js b/js/hexDump.js new file mode 100644 index 0000000..66c3e7f --- /dev/null +++ b/js/hexDump.js @@ -0,0 +1,85 @@ +(function () { + + var repeat = function (times, str) { + var ret = ""; + + for (var i = 0; i < times; i++) { + ret += str; + } + + return ret; + }; + + var printHex = function (width, num) { + var ret = Number(num).toString(16); + + if (ret.length < width) { + return repeat(width - ret.length, "0") + ret; + } + else { + return ret; + } + }; + + var isPrintableAscii = function (code) { + return (code >= 0x20 && code <= 0x7e); + }; + + Rakka.hexDump = function (data, limit) { + var offset = 0; + var size = Math.min(data.length, limit); + var ret = ""; + + for (; offset < size; offset += 16) { + ret += printHex(8, offset); + ret += " "; + + var begin = offset; + var end = Math.min(offset + 16, size); + + for (var i = begin; i < end; i++) { + var c = data.charCodeAt(i); + + ret += printHex(2, c); + ret += " "; + + if (end - i == 9) { + ret += " "; + } + } + for (var i = end; i < offset + 16; i++) { + ret += " "; + if (end - i == 9) { + ret += " "; + } + } + + ret += " |"; + + for (var i = begin; i < end; i++) { + var c = data.charCodeAt(i); + + if (isPrintableAscii(c)) { + ret += data.charAt(i); + } + else { + ret += "."; + } + } + ret += "|"; + for (var i = end; i < offset + 16; i++) { + ret += " "; + } + + ret += "\n"; + } + + if (data.length > limit) { + ret += printHex(8, offset); + ret += " ...\n"; + } + + return ret; + }; + + })(); \ No newline at end of file