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