(www-display-object-desc): Add code for genre `hng-card' to display
[chise/est.git] / cwiki-view.el
1 ;; -*- coding: utf-8-mcs-er -*-
2 (require 'cwiki-format)
3 (require 'char-db-json)
4
5 (defvar chise-wiki-view-url "view.cgi")
6 (defvar chise-wiki-edit-url "edit.cgi")
7 (defvar chise-wiki-add-url "add.cgi")
8
9 (defun www-edit-display-feature-input-box (char feature-name
10                                                 &optional format value)
11   (if (symbolp char)
12       (setq char (or (concord-decode-object '=id char 'feature)
13                      (concord-make-object 'feature char))))
14   (unless format
15     (setq format 'default))
16   (unless value
17     (setq value (www-get-feature-value char feature-name)))
18   (if (and (symbolp value)
19            (eq format 'wiki-text))
20       (setq value (list (list value))))
21   (princ
22    (format "<p><input type=\"text\" name=\"feature-name\"
23 size=\"32\" maxlength=\"256\" value=\"%s\">"
24            feature-name))
25   (princ (encode-coding-string " \u2190 " 'utf-8-mcs-er))
26   (princ
27    (format "%s<input type=\"text\" name=\"%s\"
28 size=\"64\" maxlength=\"256\" value=\"%s\">
29 <input type=\"submit\" value=\"set\" /></p>
30 "
31            (if (or (eq format 'HEX)(eq format 'hex))
32                "0x"
33              "")
34            format
35            (mapconcat (lambda (c)
36                         (cond
37                          ;; ((eq c ?<) "&amp;lt;")
38                          ;; ((eq c ?>) "&amp;gt;")
39                          ((eq c ?\u0022) "&quot;")
40                          (t
41                           (char-to-string c))))
42                       (est-format-list value format nil nil " ")
43                       "")))
44   )
45
46 (defun www-display-object-desc (genre uri-object &optional uri-feature-name
47                                       image-selection
48                                       lang level simple
49                                       uri-feature-name-to-edit editing-format)
50   (unless level
51     (setq level 0))
52   (let ((object (www-uri-decode-object genre uri-object))
53         (est-eval-list-feature-items-limit est-eval-list-feature-items-limit)
54         (est-view-url-prefix (if uri-feature-name
55                                  "../.."
56                                ".."))
57         (rdf-uri-object (if est-hide-cgi-mode
58                             (if (string-match "=" uri-object)
59                                 (concat
60                                  (est-uri-decode-feature-name-body
61                                   (substring uri-object 0 (match-beginning 0)))
62                                  ":"
63                                  (est-uri-decode-feature-name-body
64                                   (substring uri-object (match-end 0))))
65                               uri-object)))
66         feature-name-to-display feature-name-to-edit
67         base-name-to-edit metadata-name-to-edit
68         without-header
69         logical-feature chise-wiki-displayed-features
70         parents
71         GlyphWiki-id HNG-card ret object-spec)
72     (if (eq level 0)
73         (setq level 1
74               without-header nil)
75       (setq without-header t))
76     (when object
77       (when uri-feature-name-to-edit
78         (setq feature-name-to-edit
79               (www-uri-decode-feature-name uri-feature-name-to-edit))
80         (setq ret (symbol-name feature-name-to-edit))
81         (if (string-match "\\*" ret)
82             (setq base-name-to-edit (intern
83                                      (substring ret 0 (match-beginning 0)))
84                   metadata-name-to-edit (intern
85                                          (substring ret (match-end 0))))
86           (setq base-name-to-edit feature-name-to-edit))
87         (when (stringp editing-format)
88           (setq editing-format (intern editing-format))))
89       (when (and (eq genre 'character)
90                  (= (length uri-object) 1))
91         (setq uri-object (www-uri-encode-object object)))
92       (when (= level 1)
93         (princ
94          (encode-coding-string
95           (format "<head>
96 <style type=\"text/css\">
97 <!--
98 hr { color: green; }
99 .ids { vertical-align: middle; font-size: 40px; line-height: 100%%; }
100 a { text-decoration: none; }
101 .ids a { color: black; }
102 ul { margin: 0 0; color: black; }
103 li { margin: 0 0 0 2em; }
104 .feature-name { font-family: sans-serif; font-weight: bold; }
105 .feature-name a { color: black; }
106
107 .tooltip {
108     position: relative;
109     display: inline-block;
110     border-bottom: 1px dotted black;
111 }
112
113 .tooltip .tooltiptext {
114     visibility: hidden;
115     width: 120px;
116     top: 100%%;
117     left: 50%%;
118     margin-left: -60px;
119     background-color: black;
120     color: #fff;
121     text-align: center;
122     padding: 5px 0;
123     border-radius: 6px;
124  
125     position: absolute;
126     z-index: 1;
127 }
128
129 .list .tooltip:hover .tooltiptext {
130     visibility: visible;
131 }
132 -->
133 </style>
134
135 <script
136  src=\"http://hng.chise.org/openseadragon/openseadragon.min.js\"></script>
137
138 <title>EsT %s = %s</title>
139 </head>\n"
140                   genre
141                   (decode-uri-string uri-object 'utf-8-mcs-er))
142           'utf-8-mcs-er))
143         (princ "<body>\n"))
144       (when (eq genre 'character)
145         (dolist (feature (char-feature-property '$object 'additional-features))
146           (mount-char-attribute-table
147            (char-feature-name-at-domain feature '$rev=latest))))
148       (princ
149        (if simple
150            (format
151             (if est-hide-cgi-mode
152                 "<div style=\"text-align:right;\">
153 <a href=\"../../edit/view.cgi?%s=%s\">
154 <input type=\"submit\" value=\"Edit\" />
155 </a>\n"
156               "<div style=\"text-align:right;\">
157 <a href=\"edit/view.cgi?%s=%s\">
158 <input type=\"submit\" value=\"Edit\" />
159 </a>\n")
160             genre rdf-uri-object)
161          (format
162           "<div style=\"text-align:right;\">
163 <a href=\"../view/%s/%s\">
164 <input type=\"submit\" value=\"Simple\" />
165 </a>\n"
166           genre
167           (if (string-match ":" uri-object)
168               (concat
169                (est-uri-encode-feature-name-body
170                 (substring uri-object 0 (match-beginning 0)))
171                "="
172                (est-uri-encode-feature-name-body
173                 (substring uri-object (match-end 0))))))))
174       (princ
175        (format "<input type=\"submit\" value=\"New Account\" />
176 <a href=\"http://www.chise.org/est/rdf.cgi?%s=%s\">
177 <input type=\"submit\" value=\"RDF\" />
178 </a>%s
179 </div>
180 <hr />\n"
181                genre rdf-uri-object
182                (if (eq genre 'character)
183                    (format "
184 <a href=\"/est/view/%s/%s/data.json\">
185 <input type=\"submit\" value=\"JSON\" />
186 </a>\n"
187                            genre rdf-uri-object)
188                  "")))
189       (when (setq parents (www-get-feature-value object '<-denotational))
190         (princ (format "<p>%s %s</p>\n<hr>\n"
191                        (www-format-value-as-char-list parents)
192                        (www-format-feature-name '->denotational lang))))
193       (when (setq parents (www-get-feature-value object '<-subsumptive))
194         (princ (format "<p>%s %s</p>\n<hr>\n"
195                        (www-format-value-as-char-list parents)
196                        (www-format-feature-name '->subsumptive lang))))
197       (when (eq genre 'character)
198         (setq GlyphWiki-id (char-GlyphWiki-id object)))
199       (cond
200        ((eq genre 'image-resource)
201         (princ
202          (if (setq ret (concord-object-get object '=location@iiif))
203              (if (concord-object-get object 'image-offset-x)
204                  (format "<img alt=\"%s\" src=\"%s\" />"
205                          ret ret)
206                (format "<div id=\"openseadragon1\"
207  style=\"width: 800px; height: 600px;\"></div>
208
209 <script type=\"text/javascript\">
210     OpenSeadragon({
211         id: \"openseadragon1\",
212         prefixUrl: \"http://hng.chise.org/openseadragon/images/\",
213         preserveViewport:   true,
214         visibilityRatio:    1,
215         minZoomLevel:       1,
216         defaultZoomLevel:   1,
217         sequenceMode:       true,
218         tileSources:   [ \"%s/info.json\" ]
219     });
220 </script>
221 "
222                        ret))
223            (setq ret (concord-object-get object '=location))
224            (format "<img alt=\"%s\" src=\"%s\" />"
225                    ret ret)))
226         )
227        ((and (eq genre 'hng-card)
228              (setq ret (concord-object-get object '=hng-card))
229              (setq ret (symbol-name ret))
230              (string-match "\\([0-9]+\\)-\\([0-9]+\\)" ret))
231         (princ
232          (format
233           "<img alt=\"HNG-card:%s\"
234 src=\"http://hng.chise.org/images/HNG/%03d/cards/%04d.jpg\"
235 style=\"height: 480px;\" />"
236           ret
237           (string-to-int (match-string 1 ret))
238           (string-to-int (match-string 2 ret))))
239         )
240        (t
241         (setq ret (www-format-encode-string
242                    (est-format-object object 'readable)))
243         (setq HNG-card
244               (if (string-match
245                    "<img alt=\"HNG\\([0-9]+\\)-\\([0-9]+\\)\"" ret)
246                   (format "HNG/%s/cards/%s.jpg"
247                           (match-string 1 ret)
248                           (match-string 2 ret))))
249         (princ
250          (format "<h%d>%s%s</h%d>\n"
251                  level
252                  (cond
253                   (uri-feature-name
254                    (format "<a href=\"%s\">%s</a>"
255                            ;; (if est-hide-cgi-mode
256                            ;;     "<a href=\"../%s\">%s</a>"
257                            ;;   "<a href=\"%s\">%s</a>")
258                            (www-uri-make-object-url object uri-object)
259                            ret)
260                    )
261                   (HNG-card
262                    (format
263                     "<a href=\"http://hng.chise.org/images/%s\">%s</a>"
264                     HNG-card ret)
265                    )
266                   (t ret))
267                  (if GlyphWiki-id
268                      (format
269                       " <a href=\"http://glyphwiki.org/wiki/%s\"><img alt=\"%s\" src=\"http://glyphwiki.org/glyph/%s.50px.png\" /></a>"
270                       GlyphWiki-id
271                       GlyphWiki-id GlyphWiki-id)
272                    "")
273                  level))
274         ))
275       (if (> level 1)
276           (princ "<ul>"))
277       (when feature-name-to-edit
278         (princ "<form action=\"set.cgi\" method=\"GET\">\n")
279         (princ
280          (encode-coding-string
281           (format "<p>(%s : <input type=\"text\" name=\"%s\"
282 size=\"30\" maxlength=\"30\" value=\"%s\">)</p>
283 "
284                   genre genre
285                   (decode-uri-string uri-object 'utf-8-mcs-er))
286           'utf-8-mcs-er)))
287       (setq object-spec
288             (cond
289              (uri-feature-name
290               (setq feature-name-to-display
291                     (www-uri-decode-feature-name uri-feature-name))
292               (setq est-eval-list-feature-items-limit nil)
293               (list
294                (cons feature-name-to-display
295                      (if (eq genre 'character)
296                          (get-char-attribute object feature-name-to-display)
297                        (concord-object-get object feature-name-to-display)))))
298              (t
299               (if (eq genre 'character)
300                   (char-attribute-alist object)
301                 (concord-object-spec object)))))
302       (when feature-name-to-edit
303         (unless (assq base-name-to-edit object-spec)
304           (setq object-spec (cons (cons base-name-to-edit nil)
305                                   object-spec))))
306       (dolist (cell (sort object-spec
307                           (lambda (a b)
308                             (char-attribute-name<
309                              (char-feature-name-sans-versions (car a))
310                              (char-feature-name-sans-versions (car b))))))
311         (setq logical-feature (char-feature-name-sans-versions (car cell)))
312         (unless (memq logical-feature chise-wiki-displayed-features)
313           (push logical-feature chise-wiki-displayed-features)
314           (cond
315            ((and feature-name-to-edit
316                  (eq (car cell) feature-name-to-edit))
317             (www-edit-display-feature-input-box
318              object feature-name-to-edit editing-format)
319             )
320            (t
321             (princ
322              (if (= level 1)
323                  "<div class=\"feature\" style=\"line-height:150%\">\n"
324                "<li>\n"))
325             (princ
326              (www-format-eval-list
327               (www-feature-format logical-feature)
328               object
329               logical-feature ; (car cell)
330               lang uri-object
331               nil simple))
332             (unless simple
333               (princ
334                (format " <a href=\"%s?%s=%s&feature=%s&format=wiki-text\"
335 ><input type=\"submit\" value=\"note\" /></a>"
336                        chise-wiki-edit-url
337                        genre
338                        (www-format-encode-string uri-object)
339                        (www-format-encode-string
340                         (www-uri-encode-feature-name
341                          (intern (format "%s*note"
342                                          logical-feature ; (car cell)
343                                          )))))))
344             (when (and feature-name-to-edit
345                        (eq base-name-to-edit (car cell)) metadata-name-to-edit)
346               (princ "<ul>\n")
347               (princ "<li>")
348               (www-edit-display-feature-input-box
349                object feature-name-to-edit editing-format)
350               (princ "</li>")
351               (princ "</ul>"))
352             (princ
353              (if (= level 1)
354                  "</div>\n"
355                "<li>\n"))
356             ))
357           ))
358       (princ
359        (if (= level 1)
360            "<p>\n"
361          "<li>\n"))
362       (when feature-name-to-edit
363         (princ "</form>\n"))
364       (unless simple
365         (princ
366          (format "<a href=\"%s?%s=%s\"
367 ><input type=\"submit\" value=\"add feature\" /></a>
368 "
369                  chise-wiki-add-url
370                  genre
371                  (www-format-encode-string uri-object))))
372       (princ
373        (if (= level 1)
374            "<p>\n"
375          "<li>\n"))
376       (when (eq genre 'character)
377         (princ
378          "<form action=\"http://www.chise.org/ids-find\">\n")
379         (princ
380          (www-format-encode-string
381           (est-format-object object)
382           ;; (if (eq genre 'character)
383           ;;     (format "%c" object)
384           ;;   (format "%s" (concord-object-id object)))
385           ))
386         (princ
387          (format
388           " <input type=\"text\" name=\"components\"
389 size=\"30\" maxlength=\"30\" value=\"%s\" />"
390           (encode-coding-string
391            (est-format-object object)
392            ;; (if (eq genre 'character)
393            ;;     (char-to-string object)
394            ;;   (format "%s" (concord-object-id object)))
395            'utf-8-jp-er)))
396         (princ
397          (www-format-encode-string
398           "を\u542Bむ\u6F22\u5B57を\u63A2す"))
399         (princ " <input type=\"submit\" value=\"search\" />\n")
400         (princ "</form>\n")
401
402         (princ
403          "<form action=\"http://www.chise.org/hng-ids-find\">\n")
404         (princ
405          (www-format-encode-string
406           (est-format-object object)
407           ;; (if (eq genre 'character)
408           ;;     (format "%c" object)
409           ;;   (format "%s" (concord-object-id object)))
410           ))
411         (princ
412          (format
413           " <input type=\"text\" name=\"components\"
414 size=\"30\" maxlength=\"30\" value=\"%s\" />"
415           (encode-coding-string
416            (est-format-object object)
417            ;; (if (eq genre 'character)
418            ;;     (char-to-string object)
419            ;;   (format "%s" (concord-object-id object)))
420            'utf-8-jp-er)))
421         (princ
422          (www-format-encode-string
423           "を\u542Bむ HNG の\u6F22\u5B57を\u63A2す"))
424         (princ " <input type=\"submit\" value=\"search\" />\n")
425         (princ "</form>\n")
426         )
427       (princ
428        (if (= level 1)
429            "</p>\n"
430          "<li>\n"))
431       )))
432
433 (defun www-display-feature-desc (uri-feature-name genre uri-object
434                                                   &optional lang simple)
435   (let ((rdf-uri-object (if est-hide-cgi-mode
436                             (if (string-match "=" uri-object)
437                                 (concat
438                                  (est-uri-decode-feature-name-body
439                                   (substring uri-object 0 (match-beginning 0)))
440                                  ":"
441                                  (est-uri-decode-feature-name-body
442                                   (substring uri-object (match-end 0))))
443                               uri-object)))
444         (feature-name (www-uri-decode-feature-name uri-feature-name))
445         (name@lang (intern (format "name@%s" lang))))
446     (princ
447      (encode-coding-string
448       (format "<head>
449 <title>EsT feature: %s</title>
450 </head>\n"
451               feature-name)
452       'utf-8-mcs-er))
453     (princ "<body>\n")
454     (princ
455      (if simple
456          (format
457           (if est-hide-cgi-mode
458               "<div style=\"text-align:right;\">
459 <a href=\"../../../edit/view.cgi?feature=%s&%s=%s\">
460 <input type=\"submit\" value=\"Edit\" />
461 </a>
462 <input type=\"submit\" value=\"New Account\" />
463 </div>
464 <hr />\n"
465             "<div style=\"text-align:right;\">
466 <a href=\"edit/view.cgi?feature=%s&%s=%s\">
467 <input type=\"submit\" value=\"Edit\" />
468 </a>
469 <input type=\"submit\" value=\"New Account\" />
470 </div>
471 <hr />\n")
472           uri-feature-name genre rdf-uri-object)
473        (format
474         "<div style=\"text-align:right;\">
475 <a href=\"../view/feature/%s&%s/%s\">
476 <input type=\"submit\" value=\"Simple\" />
477 </a>
478 </div>
479 <hr />\n"
480         uri-feature-name genre uri-object)))
481     (princ
482      (format "<h1>%s</h1>\n"
483              (www-format-encode-string
484               (symbol-name feature-name))))
485     (princ (format "<p>name : %s "
486                    (or (www-format-feature-name feature-name) "")))
487     (unless simple
488       (princ
489        (format
490         " <a href=\"%s?feature=%s&property=name&format=string&%s=%s\">"
491         chise-wiki-edit-url
492         uri-feature-name
493         genre
494         uri-object))
495       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
496     (princ "</p>\n")
497     (when lang
498       (princ "<p>")
499       (princ
500        (www-format-encode-string
501         (format "%s : %s"
502                 name@lang
503                 (or (char-feature-property feature-name name@lang) ""))))
504       (unless simple
505         (princ
506          (format
507           " <a href=\"%s?feature=%s&property=%s&format=string&%s=%s\">"
508           chise-wiki-edit-url
509           uri-feature-name
510           name@lang
511           genre
512           uri-object))
513         (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
514       (princ "</p>\n"))
515     (www-html-display-paragraph
516      (format "type : %s"
517              (or (www-feature-type feature-name)
518                  ;; (char-feature-property feature-name 'type)
519                  'generic)))
520     (princ (format "<p>value-format : %s "
521                    (www-format-value
522                     nil 'value-format 
523                     (or (www-feature-value-format feature-name)
524                         'default)
525                     'default
526                     'without-tags)
527                    ))
528     (unless simple
529       (princ
530        (format
531         " <a href=\"%s?feature=%s&property=value-format&format=wiki-text&%s=%s\"
532 >"
533         chise-wiki-edit-url
534         uri-feature-name
535         genre
536         uri-object))
537       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
538     (princ "</p>\n")
539
540     (princ (format "<p>value-presentation-format : %s "
541                    (www-format-value
542                     nil 'value-presentation-format 
543                     (or (www-feature-value-format feature-name)
544                         'default)
545                     'default
546                     'without-tags)
547                    ))
548     (unless simple
549       (princ
550        (format
551         " <a href=\"%s?feature=%s&property=value-presentation-format&format=wiki-text&%s=%s\"
552 >"
553         chise-wiki-edit-url
554         uri-feature-name
555         genre
556         uri-object))
557       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
558     (princ "</p>\n")
559
560     (princ "<p>format : ")
561     (www-html-display-text
562      (decode-coding-string
563       (www-xml-format-list
564        (www-feature-format feature-name))
565       'utf-8-mcs-er))
566     (unless simple
567       (princ
568        (format
569         " <a href=\"%s?feature=%s&property=format&format=wiki-text&%s=%s\"
570 >"
571         chise-wiki-edit-url
572         uri-feature-name
573         genre
574         uri-object))
575       (princ "<input type=\"submit\" value=\"edit\" /></a>\n"))
576     (princ "</p>\n")
577     
578     (www-html-display-paragraph
579      (format "description : %s"
580              (or (decode-coding-string
581                   (char-feature-property feature-name 'description)
582                   'utf-8-mcs-er)
583                  "")))
584     (when lang
585       (www-html-display-paragraph
586        (format "description@%s : %s"
587                lang
588                (or (char-feature-property
589                     feature-name
590                     (intern (format "description@%s" lang)))
591                    ""))))
592     ))
593   
594 (defun www-batch-view ()
595   (setq terminal-coding-system 'binary)
596   (condition-case err
597       (let* ((target (pop command-line-args-left))
598              (user (pop command-line-args-left))
599              (accept-language (pop command-line-args-left))
600              (mode (intern (pop command-line-args-left)))
601              (lang
602               (intern
603                (car (split-string
604                      (car (split-string
605                            (car (split-string accept-language ","))
606                            ";"))
607                      "-"))))
608              ret genre)
609         (princ "Content-Type: text/html; charset=UTF-8
610
611 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
612             \"http://www.w3.org/TR/html4/loose.dtd\">
613 <html lang=\"ja\">
614 ")
615         (cond
616          ((stringp target)
617           (when (string-match "^char=\\(&[^&;]+;\\)" target)
618             (setq ret (match-end 0))
619             (setq target
620                   (concat "char="
621                           (www-uri-encode-object
622                            (www-uri-decode-object
623                             'character (match-string 1 target)))
624                           (substring target ret))))
625           (setq target
626                 (mapcar (lambda (cell)
627                           (if (string-match "=" cell)
628                               (progn
629                                 (setq genre (substring cell 0 (match-beginning 0))
630                                       ret (substring cell (match-end 0)))
631                                 (cons
632                                  (intern
633                                   (decode-uri-string genre 'utf-8-mcs-er))
634                                  ret))
635                             (list (decode-uri-string cell 'utf-8-mcs-er))))
636                         (split-string target "&")))
637           (setq ret (car target))
638           (cond ((eq (car ret) 'char)
639                  (www-display-object-desc
640                   'character (cdr ret) (cdr (assq 'feature target))
641                   nil
642                   lang nil
643                   (eq mode 'simple))
644                  )
645                 ((eq (car ret) 'feature)
646                  (www-display-feature-desc
647                   (decode-uri-string (cdr ret) 'utf-8-mcs-er)
648                   (car (nth 1 target))
649                   (cdr (nth 1 target))
650                   lang
651                   (eq mode 'simple))
652                  )
653                 (t
654                  (www-display-object-desc
655                   (car ret) (cdr ret) (cdr (assq 'feature target))
656                   nil
657                   lang nil
658                   (eq mode 'simple))
659                  ))
660           ))
661         (princ "\n<hr>\n")
662         (princ (format "mode=%S\n" mode))
663         (princ (format "user=%s\n" user))
664         ;; (princ (format "local user=%s\n" (user-login-name)))
665         (princ (format "lang=%S\n" lang))
666         (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
667         ;; (princ " CHISE ")
668         ;; (princ xemacs-chise-version)
669         (princ "
670 </body>
671 </html>")
672         )
673     (error nil
674            (princ (format "%S" err)))
675     ))
676
677 (defun www-batch-view-smart ()
678   (setq debug-on-error t)
679   (setq terminal-coding-system 'binary)
680   (condition-case err
681       (let* ((est-hide-cgi-mode t)
682              (target (pop command-line-args-left))
683              (user (pop command-line-args-left))
684              (accept-language (pop command-line-args-left))
685              (mode (intern (pop command-line-args-left)))
686              (lang
687               (intern
688                (car (split-string
689                      (car (split-string
690                            (car (split-string accept-language ","))
691                            ";"))
692                      "-"))))
693              ret genre feature obj-url json obj)
694         (cond
695          ((stringp target)
696           (when (string-match "/data\\.json$" target)
697             (setq json t
698                   target (substring target 0 (match-beginning 0))))
699           (when (string-match "^char/\\(&[^&;]+;\\)" target)
700             (setq ret (match-end 0))
701             (setq target
702                   (concat "char/"
703                           (www-uri-encode-object
704                            (www-uri-decode-object
705                             'character (match-string 1 target)))
706                           (substring target ret))))
707           (setq target
708                 (mapcar
709                  (lambda (cell)
710                    (if (string-match "/" cell)
711                        (progn
712                          (setq genre (substring cell 0 (match-beginning 0))
713                                ret (substring cell (match-end 0)))
714                          (cons
715                           (intern (decode-uri-string genre 'utf-8-mcs-er))
716                           (if (string-match "/feature=" ret)
717                               (list (substring ret 0 (match-beginning 0))
718                                     (substring ret (match-end 0)))
719                             (list ret))))
720                      (list (decode-uri-string cell 'utf-8-mcs-er)))
721                    ;; (setq ret (split-string cell "/"))
722                    ;; (cons (intern
723                    ;;        (decode-uri-string (car ret) 'utf-8-mcs-er))
724                    ;;       (cdr ret))
725                    )
726                  (split-string target "&")))
727           (setq ret (car target))
728           (if json
729               (princ "Content-Type: application/json; charset=UTF-8
730
731 ")
732             (princ "Content-Type: text/html; charset=UTF-8
733
734 <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
735             \"http://www.w3.org/TR/html4/loose.dtd\">
736 <html lang=\"ja\">
737 ")
738             )
739           ;; (princ (format "<p>%S, %S, %S</p>"
740           ;;                (car ret)(nth 1 ret)(nth 2 ret)))
741           ;; (princ (format "// %S %S\n" ret json))
742           (cond ((or (eq (car ret) 'char)
743                      (eq (car ret) 'character))
744                  (if (and json
745                           (setq obj (www-uri-decode-object
746                                      (car ret)(nth 1 ret)))
747                           (characterp obj))
748                      (with-temp-buffer
749                        ;; (princ (encode-coding-string
750                        ;;         (format "// %S\n" obj)
751                        ;;         char-db-file-coding-system))
752                        (char-db-json-char-data-with-variant obj 'printable)
753                        (encode-coding-region
754                         (point-min)(point-max)
755                         char-db-file-coding-system)
756                        (princ (buffer-string))
757                        )
758                    (www-display-object-desc
759                     'character (nth 1 ret) (nth 2 ret)
760                     nil
761                     lang nil
762                     (eq mode 'simple)))
763                  )
764                 ((eq (car ret) 'feature)
765                  (www-display-feature-desc
766                   (decode-uri-string (nth 1 ret) 'utf-8-mcs-er)
767                   (car (nth 1 target))
768                   (nth 1 (nth 1 target))
769                   lang
770                   (eq mode 'simple))
771                  )
772                 ;; ((eq (car ret) 'image-resource)
773                 ;; ;;  (cond
774                 ;; ;;   ((string-match "^\\.iiif=" (nth 1 ret))
775                 ;; ;;    (setq obj-url (decode-uri-string
776                 ;; ;;                   (substring (nth 1 ret) (match-end 0))
777                 ;; ;;                   'utf-8-mcs-er))
778                 ;; ;;    (setq obj (concord-images-add-iiif obj-url))
779                 ;; ;;    (www-display-object-desc
780                 ;; ;;     'image-resource
781                 ;; ;;     (www-uri-encode-object obj)
782                 ;; ;;     (nth 2 ret)
783                 ;; ;;     lang nil
784                 ;; ;;     (eq mode 'simple))
785                 ;; ;;    )
786                 ;; ;;   (t
787                 ;;  (princ (nth 1 ret))
788                 ;;  (www-display-object-desc
789                 ;;   'image-resource (nth 1 ret) (nth 2 ret)
790                 ;;   lang nil
791                 ;;   (eq mode 'simple))
792                 ;; ;;    ))
793                 ;;  )
794                 (t
795                  (www-display-object-desc
796                   (car ret) (nth 1 ret) (nth 2 ret)
797                   nil
798                   lang nil
799                   (eq mode 'simple))
800                  ))
801           ))
802         (unless json
803           (princ "\n<hr>\n")
804           (princ (format "mode=%S\n" mode))
805           (princ (format "user=%s\n" user))
806           ;; (princ (format "local user=%s\n" (user-login-name)))
807           (princ (format "lang=%S\n" lang))
808           (princ (encode-coding-string (emacs-version) 'utf-8-jp-er))
809           ;; (princ " CHISE ")
810           ;; (princ xemacs-chise-version)
811           (princ "
812 </body>
813 </html>")
814           )
815         )
816     (error nil
817            (princ (format "%S" err)))
818     ))
819
820 (provide 'cwiki-view)