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