configure.ac
js/Makefile
js/base.js
+ js/base64.js
js/editPage.js
js/jquery-1.2.1.js
js/jquery-dom.js
+ js/localFile.js
js/screen.js
Flag build-test-suite
= proc (name, tree)
-> do updateInfo <- maybeA parseUpdateInfo -< tree
- mimeType <- (getXPathTreesInDoc "/page/@type/text()" >>> getText
- >>> arr read) -< tree
+ mimeTypeStr <- withDefault (getXPathTreesInDoc "/page/@type/text()" >>> getText) "" -< tree
lang <- maybeA (getXPathTreesInDoc "/page/@lang/text()" >>> getText) -< tree
fileName <- maybeA (getXPathTreesInDoc "/page/@filename/text()" >>> getText) -< tree
(Just text, Nothing ) -> (False, L.pack $ UTF8.encode text )
(Nothing , Just binary) -> (True , L.pack $ B64.decode binary)
_ -> error "one of textData or binaryData is required"
+ mimeType
+ = if isBinary then
+ if null mimeTypeStr then
+ guessMIMEType content
+ else
+ read mimeTypeStr
+ else
+ read mimeTypeStr
returnA -< Entity {
entityName = name
)
where
+import qualified Codec.Binary.Base64 as B64
import Control.Arrow
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
import Control.Monad.Trans
-import qualified Codec.Binary.UTF8.String as UTF8
-import qualified Data.ByteString.Lazy as Lazy
-import qualified Data.Map as M
+import qualified Data.ByteString.Lazy as Lazy (ByteString, pack)
+import qualified Data.ByteString.Lazy.Char8 as L8 hiding (ByteString)
import Network.HTTP.Lucu
import Network.HTTP.Lucu.Utils
import Rakka.Environment
import Rakka.Page
import Rakka.Utils
-import Rakka.Wiki
import Rakka.Wiki.Engine
-import Rakka.Wiki.Parser
-import Rakka.Wiki.Interpreter
-import Text.ParserCombinators.Parsec
import Text.XML.HXT.Arrow.Namespace
import Text.XML.HXT.Arrow.WriteDocument
import Text.XML.HXT.Arrow.XmlArrow
-}
handleRender :: Environment -> PageName -> Resource ()
handleRender env name
- = do bin <- inputLBS defaultLimit
+ = do entity <- inputLBS defaultLimit
cTypeM <- getContentType
- let cType = case cTypeM of
- Just t -> t
- Nothing -> guessMIMEType bin
+ let (bin, cType) = case cTypeM of
+ Just (MIMEType "application" "x-rakka-base64-stream" _)
+ -> let b = Lazy.pack $ B64.decode $ L8.unpack entity
+ in
+ (b, guessMIMEType b)
+ Just t
+ -> (entity, t)
+ Nothing
+ -> (entity, guessMIMEType entity)
setContentType $ read "text/xml"
[xmlStr] <- liftIO $ runX ( setErrorMsgHandler False fail
$(JQUERY_SOURCE) \
jquery-dom.js \
base.js \
+ base64.js \
editPage.js \
+ localFile.js \
redirection.js \
screen.js \
$(NULL)
--- /dev/null
+(function () {
+
+ var b64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ Rakka.encodeBase64 = function (src) {
+ var len = src.length;
+ var i = 0;
+ var ret = "";
+
+ while (i < len) {
+ var c1 = src.charCodeAt(i++);
+
+ if (i == len) {
+ ret += b64Chars.charAt(c1 >> 2);
+ ret += b64Chars.charAt((c1 & 0x03) << 4);
+ ret += "==";
+ }
+ else {
+ var c2 = src.charCodeAt(i++);
+
+ if (i == len) {
+ ret += b64Chars.charAt(c1 >> 2);
+ ret += b64Chars.charAt(((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4));
+ ret += b64Chars.charAt((c2 & 0x0F) << 2);
+ ret += "=";
+ }
+ else {
+ var c3 = src.charCodeAt(i++);
+
+ ret += b64Chars.charAt(c1 >> 2);
+ ret += b64Chars.charAt(((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4));
+ ret += b64Chars.charAt(((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6));
+ ret += b64Chars.charAt(c3 & 0x3F);
+ }
+ }
+ }
+
+ return ret;
+ };
+
+})();
\ No newline at end of file
Rakka.showPreview(resultDoc);
},
error : function (req) {
+ Rakka.hideWaitingMessage();
+ alert("Error: " + req.status + " " + req.statusText);
+ }
+ });
+};
+
+Rakka.previewBinaryPage = function (pageName, path) {
+ 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),
+ processData: false,
+ success : function (resultDoc) {
+ Rakka.hideWaitingMessage();
+ Rakka.showPreview(resultDoc);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
alert("Error: " + req.status + " " + req.statusText);
}
});
});
};
+Rakka.submitBinaryPage = function (pageName, oldRevision, givenPageName, path) {
+ var doc = document.implementation.createDocument(
+ "http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
+
+ var page = doc.documentElement;
+
+ if (oldRevision != null) {
+ // ページ書換時
+ var updateInfo = doc.createElement("updateInfo");
+ updateInfo.setAttribute("oldRevision", oldRevision);
+
+ if (pageName != givenPageName) {
+ var move = doc.createElement("move");
+ move.setAttribute("from", pageName);
+ updateInfo.appendChild(move);
+ }
+
+ page.appendChild(updateInfo);
+ }
+
+ page.setAttribute("type", "");
+
+ var bin = Rakka.loadLocalBinaryFile(path);
+ var b64 = Rakka.encodeBase64(bin);
+
+ var binaryData = doc.createElement("binaryData");
+ binaryData.appendChild(
+ doc.createTextNode(b64));
+
+ page.appendChild(binaryData);
+
+ Rakka.displayWaitingMessage("Submitting... please wait.");
+
+ var url = Rakka.baseURI + encodeURI(givenPageName);
+ $.ajax({
+ type : "PUT",
+ url : url,
+ contentType: "text/xml",
+ data : doc,
+ processData: false,
+ success : function () {
+ window.location.replace(url);
+ },
+ error : function (req) {
+ Rakka.hideWaitingMessage();
+
+ var $area = Rakka.switchScreen();
+ $area.text("Error: " + req.status + " " + req.statusText);
+ }
+ });
+};
+
Rakka.submitRedirection = function (pageName, oldRevision, givenPageName, destination) {
var doc = document.implementation.createDocument(
"http://cielonegro.org/schema/Rakka/Page/1.0", "page", null);
--- /dev/null
+(function () {
+
+ Rakka.canAccessLocalFile = function () {
+ return $.browser.mozilla;
+ };
+
+ var loadBin_mozilla = function (path) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ }
+ catch (e) {
+ alert("Permission to read local file was denied. " +
+ "Open about:config and check that " +
+ "signed.applets.codebase_principal_support is set to true.");
+ }
+
+ var localFile
+ = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+ localFile.initWithPath(path);
+
+ var stream
+ = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
+ stream.init(localFile, 0x01, 00004, null);
+
+ var bstream
+ = Components.classes["@mozilla.org/network/buffered-input-stream;1"].getService();
+ bstream.QueryInterface(Components.interfaces.nsIBufferedInputStream);
+ bstream.init(stream, 1000);
+ bstream.QueryInterface(Components.interfaces.nsIInputStream);
+
+ var binary
+ = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
+ binary.setInputStream(stream);
+
+ return binary.readBytes(binary.available());
+ };
+
+ Rakka.loadLocalBinaryFile = function (path) {
+ if ($.browser.mozilla) {
+ return loadBin_mozilla(path);
+ }
+ };
+
+})();
\ No newline at end of file