Require `char-db-json'.
authorMORIOKA Tomohiko <tomo.git@chise.org>
Wed, 4 May 2016 15:50:24 +0000 (00:50 +0900)
committerMORIOKA Tomohiko <tomo.git@chise.org>
Wed, 4 May 2016 15:50:24 +0000 (00:50 +0900)
(www-display-object-desc): Add [JSON] button.
(www-batch-view-smart): Support "/data.json" API for character genre.

cwiki-view.el

index 2164d60..3c4e0aa 100644 (file)
@@ -1,5 +1,6 @@
 ;; -*- coding: utf-8-mcs-er -*-
 (require 'cwiki-format)
 ;; -*- coding: utf-8-mcs-er -*-
 (require 'cwiki-format)
+(require 'char-db-json)
 
 (defvar chise-wiki-view-url "view.cgi")
 (defvar chise-wiki-edit-url "edit.cgi")
 
 (defvar chise-wiki-view-url "view.cgi")
 (defvar chise-wiki-edit-url "edit.cgi")
@@ -144,10 +145,17 @@ li { margin: 0 0 0 2em; }
        (format "<input type=\"submit\" value=\"New Account\" />
 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
 <input type=\"submit\" value=\"RDF\" />
        (format "<input type=\"submit\" value=\"New Account\" />
 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
 <input type=\"submit\" value=\"RDF\" />
-</a>
+</a>%s
 </div>
 <hr />\n"
 </div>
 <hr />\n"
-              genre rdf-uri-object))
+              genre rdf-uri-object
+              (if (eq genre 'character)
+                  (format "
+<a href=\"/est/view/%s/%s/data.json\">
+<input type=\"submit\" value=\"JSON\" />
+</a>\n"
+                          genre rdf-uri-object)
+                "")))
       (when (setq parents (www-get-feature-value object '<-denotational))
        (princ (format "<p>%s %s</p>\n<hr>\n"
                       (www-format-value-as-char-list parents)
       (when (setq parents (www-get-feature-value object '<-denotational))
        (princ (format "<p>%s %s</p>\n<hr>\n"
                       (www-format-value-as-char-list parents)
@@ -602,15 +610,12 @@ size=\"30\" maxlength=\"30\" value=\"%s\" />"
                           (car (split-string accept-language ","))
                           ";"))
                     "-"))))
                           (car (split-string accept-language ","))
                           ";"))
                     "-"))))
-            ret genre feature)
-       (princ "Content-Type: text/html; charset=UTF-8
-
-<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
-            \"http://www.w3.org/TR/html4/loose.dtd\">
-<html lang=\"ja\">
-")
+            ret genre feature json obj)
        (cond
         ((stringp target)
        (cond
         ((stringp target)
+         (when (string-match "/data\\.json$" target)
+           (setq json t
+                 target (substring target 0 (match-beginning 0))))
          (when (string-match "^char/\\(&[^&;]+;\\)" target)
            (setq ret (match-end 0))
            (setq target
          (when (string-match "^char/\\(&[^&;]+;\\)" target)
            (setq ret (match-end 0))
            (setq target
@@ -640,13 +645,40 @@ size=\"30\" maxlength=\"30\" value=\"%s\" />"
                   )
                 (split-string target "&")))
          (setq ret (car target))
                   )
                 (split-string target "&")))
          (setq ret (car target))
+         (if json
+             (princ "Content-Type: application/json; charset=UTF-8
+
+")
+           (princ "Content-Type: text/html; charset=UTF-8
+
+<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
+            \"http://www.w3.org/TR/html4/loose.dtd\">
+<html lang=\"ja\">
+")
+           )
           ;; (princ (format "<p>%S, %S, %S</p>"
           ;;                (car ret)(nth 1 ret)(nth 2 ret)))
           ;; (princ (format "<p>%S, %S, %S</p>"
           ;;                (car ret)(nth 1 ret)(nth 2 ret)))
-         (cond ((eq (car ret) 'char)
-                (www-display-object-desc
-                 'character (nth 1 ret) (nth 2 ret)
-                 lang nil
-                 (eq mode 'simple))
+          ;; (princ (format "// %S %S\n" ret json))
+         (cond ((or (eq (car ret) 'char)
+                    (eq (car ret) 'character))
+                (if (and json
+                         (setq obj (www-uri-decode-object
+                                    (car ret)(nth 1 ret)))
+                         (characterp obj))
+                    (with-temp-buffer
+                       ;; (princ (encode-coding-string
+                       ;;         (format "// %S\n" obj)
+                       ;;         char-db-file-coding-system))
+                      (char-db-json-char-data-with-variant obj)
+                      (encode-coding-region
+                       (point-min)(point-max)
+                       char-db-file-coding-system)
+                      (princ (buffer-string))
+                      )
+                  (www-display-object-desc
+                   'character (nth 1 ret) (nth 2 ret)
+                   lang nil
+                   (eq mode 'simple)))
                 )
                ((eq (car ret) 'feature)
                 (www-display-feature-desc
                 )
                ((eq (car ret) 'feature)
                 (www-display-feature-desc
@@ -663,17 +695,19 @@ size=\"30\" maxlength=\"30\" value=\"%s\" />"
                  (eq mode 'simple))
                 ))
          ))
                  (eq mode 'simple))
                 ))
          ))
-       (princ "\n<hr>\n")
-       (princ (format "mode=%S\n" mode))
-       (princ (format "user=%s\n" user))
-        ;; (princ (format "local user=%s\n" (user-login-name)))
-       (princ (format "lang=%S\n" lang))
-       (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
-        ;; (princ " CHISE ")
-        ;; (princ xemacs-chise-version)
-       (princ "
+       (unless json
+         (princ "\n<hr>\n")
+         (princ (format "mode=%S\n" mode))
+         (princ (format "user=%s\n" user))
+         ;; (princ (format "local user=%s\n" (user-login-name)))
+         (princ (format "lang=%S\n" lang))
+         (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
+         ;; (princ " CHISE ")
+         ;; (princ xemacs-chise-version)
+         (princ "
 </body>
 </html>")
 </body>
 </html>")
+         )
        )
     (error nil
           (princ (format "%S" err)))
        )
     (error nil
           (princ (format "%S" err)))