OSDN Git Service

* change writting.
[modchxj/mod_chxj.git] / src / chxj_jhtml.c
1 /*
2  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3  * Copyright (C) 2005 Atsushi Konno All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include "chxj_jhtml.h"
18 #include "chxj_hdml.h"
19 #include "chxj_dump.h"
20 #include "chxj_img_conv.h"
21 #include "chxj_qr_code.h"
22 #include "chxj_encoding.h"
23
24 #define GET_JHTML(X) ((jhtml_t*)(X))
25
26 static char* s_jhtml_start_html_tag     (void* pdoc, Node* node);
27 static char* s_jhtml_end_html_tag       (void* pdoc, Node* node);
28 static char* s_jhtml_start_meta_tag     (void* pdoc, Node* node);
29 static char* s_jhtml_end_meta_tag       (void* pdoc, Node* node);
30 static char* s_jhtml_start_head_tag     (void* pdoc, Node* node);
31 static char* s_jhtml_end_head_tag       (void* pdoc, Node* node);
32 static char* s_jhtml_start_title_tag    (void* pdoc, Node* node);
33 static char* s_jhtml_end_title_tag      (void* pdoc, Node* node);
34 static char* s_jhtml_start_base_tag     (void* pdoc, Node* node);
35 static char* s_jhtml_end_base_tag       (void* pdoc, Node* node);
36 static char* s_jhtml_start_body_tag     (void* pdoc, Node* node);
37 static char* s_jhtml_end_body_tag       (void* pdoc, Node* node);
38 static char* s_jhtml_start_a_tag        (void* pdoc, Node* node);
39 static char* s_jhtml_end_a_tag          (void* pdoc, Node* node);
40 static char* s_jhtml_start_pre_tag      (void* pdoc, Node* node);
41 static char* s_jhtml_end_pre_tag        (void* pdoc, Node* node);
42 static char* s_jhtml_start_p_tag        (void* pdoc, Node* node);
43 static char* s_jhtml_end_p_tag          (void* pdoc, Node* node);
44 static char* s_jhtml_start_ul_tag       (void* pdoc, Node* node);
45 static char* s_jhtml_end_ul_tag         (void* pdoc, Node* node);
46 static char* s_jhtml_start_ol_tag       (void* pdoc, Node* node);
47 static char* s_jhtml_end_ol_tag         (void* pdoc, Node* node);
48 static char* s_jhtml_start_li_tag       (void* pdoc, Node* node);
49 static char* s_jhtml_end_li_tag         (void* pdoc, Node* node);
50 static char* s_jhtml_start_br_tag       (void* pdoc, Node* node);
51 static char* s_jhtml_end_br_tag         (void* pdoc, Node* node);
52 static char* s_jhtml_start_tr_tag       (void* pdoc, Node* node);
53 static char* s_jhtml_end_tr_tag         (void* pdoc, Node* node);
54 static char* s_jhtml_start_font_tag     (void* pdoc, Node* node);
55 static char* s_jhtml_end_font_tag       (void* pdoc, Node* node);
56 static char* s_jhtml_start_form_tag     (void* pdoc, Node* node);
57 static char* s_jhtml_end_form_tag       (void* pdoc, Node* node);
58 static char* s_jhtml_start_input_tag    (void* pdoc, Node* node);
59 static char* s_jhtml_end_input_tag      (void* pdoc, Node* node);
60 static char* s_jhtml_start_center_tag   (void* pdoc, Node* node);
61 static char* s_jhtml_end_center_tag     (void* pdoc, Node* node);
62 static char* s_jhtml_start_hr_tag       (void* pdoc, Node* node);
63 static char* s_jhtml_end_hr_tag         (void* pdoc, Node* node);
64 static char* s_jhtml_start_img_tag      (void* pdoc, Node* node);
65 static char* s_jhtml_end_img_tag        (void* pdoc, Node* node);
66 static char* s_jhtml_start_select_tag   (void* pdoc, Node* node);
67 static char* s_jhtml_end_select_tag     (void* pdoc, Node* node);
68 static char* s_jhtml_start_option_tag   (void* pdoc, Node* node);
69 static char* s_jhtml_end_option_tag     (void* pdoc, Node* node);
70 static char* s_jhtml_start_div_tag      (void* pdoc, Node* node);
71 static char* s_jhtml_end_div_tag        (void* pdoc, Node* node);
72 static char* s_jhtml_start_textarea_tag (void* pdoc, Node* node);
73 static char* s_jhtml_end_textarea_tag   (void* pdoc, Node* node);
74 static char* s_jhtml_start_b_tag        (void* pdoc, Node* node);
75 static char* s_jhtml_end_b_tag          (void* pdoc, Node* node);
76 static char* s_jhtml_chxjif_tag         (void* pdoc, Node* node); 
77 static char* s_jhtml_text_tag           (void* pdoc, Node* node);
78
79 static void  s_init_jhtml(jhtml_t* jhtml, Doc* doc, request_rec* r, device_table* spec);
80
81 static int   s_jhtml_search_emoji(jhtml_t* jhtml, char* txt, char** rslt);
82
83 static char* chxj_istyle_to_mode(request_rec* r, const char* s);
84
85
86
87 tag_handler jhtml_handler[] = {
88   /* tagHTML */
89   {
90     s_jhtml_start_html_tag,
91     s_jhtml_end_html_tag,
92   },
93   /* tagMETA */
94   {
95     s_jhtml_start_meta_tag,
96     s_jhtml_end_meta_tag,
97   },
98   /* tagTEXTAREA */
99   {
100     s_jhtml_start_textarea_tag,
101     s_jhtml_end_textarea_tag,
102   },
103   /* tagP */
104   {
105     s_jhtml_start_p_tag,
106     s_jhtml_end_p_tag,
107   },
108   /* tagPRE */
109   {
110     s_jhtml_start_pre_tag,
111     s_jhtml_end_pre_tag,
112   },
113   /* tagUL */
114   {
115     s_jhtml_start_ul_tag,
116     s_jhtml_end_ul_tag,
117   },
118   /* tagLI */
119   {
120     s_jhtml_start_li_tag,
121     s_jhtml_end_li_tag,
122   },
123   /* tagOL */
124   {
125     s_jhtml_start_ol_tag,
126     s_jhtml_end_ol_tag,
127   },
128   /* tagH1 */
129   {
130     NULL,
131     NULL,
132   },
133   /* tagH2 */
134   {
135     NULL,
136     NULL,
137   },
138   /* tagH3 */
139   {
140     NULL,
141     NULL,
142   },
143   /* tagH4 */
144   {
145     NULL,
146     NULL,
147   },
148   /* tagH5 */
149   {
150     NULL,
151     NULL,
152   },
153   /* tagH6 */
154   {
155     NULL,
156     NULL,
157   },
158   /* tagHEAD */
159   {
160     s_jhtml_start_head_tag,
161     s_jhtml_end_head_tag,
162   },
163   /* tagTITLE */
164   {
165     s_jhtml_start_title_tag,
166     s_jhtml_end_title_tag,
167   },
168   /* tagBASE */
169   {
170     s_jhtml_start_base_tag,
171     s_jhtml_end_base_tag,
172   },
173   /* tagBODY */
174   {
175     s_jhtml_start_body_tag,
176     s_jhtml_end_body_tag,
177   },
178   /* tagA */
179   {
180     s_jhtml_start_a_tag,
181     s_jhtml_end_a_tag,
182   },
183   /* tagBR */
184   {
185     s_jhtml_start_br_tag,
186     s_jhtml_end_br_tag,
187   },
188   /* tagTABLE */
189   {
190     NULL,
191     NULL,
192   },
193   /* tagTR */
194   {
195     s_jhtml_start_tr_tag,
196     s_jhtml_end_tr_tag,
197   },
198   /* tagTD */
199   {
200     NULL,
201     NULL,
202   },
203   /* tagTBODY */
204   {
205     NULL,
206     NULL,
207   },
208   /* tagFONT */
209   {
210     s_jhtml_start_font_tag,
211     s_jhtml_end_font_tag,
212   },
213   /* tagFORM */
214   {
215     s_jhtml_start_form_tag,
216     s_jhtml_end_form_tag,
217   },
218   /* tagINPUT */
219   {
220     s_jhtml_start_input_tag,
221     s_jhtml_end_input_tag,
222   },
223   /* tagCENTER */
224   {
225     s_jhtml_start_center_tag,
226     s_jhtml_end_center_tag,
227   },
228   /* tagHR */
229   {
230     s_jhtml_start_hr_tag,
231     s_jhtml_end_hr_tag,
232   },
233   /* tagIMG */
234   {
235     s_jhtml_start_img_tag,
236     s_jhtml_end_img_tag,
237   },
238   /* tagSELECT */
239   {
240     s_jhtml_start_select_tag,
241     s_jhtml_end_select_tag,
242   },
243   /* tagOPTION */
244   {
245     s_jhtml_start_option_tag,
246     s_jhtml_end_option_tag,
247   },
248   /* tagDIV */
249   {
250     s_jhtml_start_div_tag,
251     s_jhtml_end_div_tag,
252   },
253   /* tagCHXJIF */
254   {
255     s_jhtml_chxjif_tag,
256     NULL,
257   },
258   /* tagNOBR */
259   {
260     NULL,
261     NULL,
262   },
263   /* tagSMALL */
264   {
265     NULL,
266     NULL,
267   },
268   /* tagSTYLE */
269   {
270     NULL,
271     NULL,
272   },
273   /* tagSPAN */
274   {
275     NULL,
276     NULL,
277   },
278   /* tagTEXT */
279   {
280     s_jhtml_text_tag,
281     NULL,
282   },
283   /* tagTH */
284   {
285     NULL,
286     NULL,
287   },
288   /* tagB */
289   {
290     s_jhtml_start_b_tag,
291     s_jhtml_end_b_tag,
292   },
293   /* tagFIELDSET */
294   {
295     NULL,
296     NULL,
297   },
298 };
299
300
301 /**
302  * converts from CHTML5.0 to JHTML.
303  *
304  * @param r     [i]   Requet_rec is appointed.
305  * @param spec  [i]   The result of the device specification processing which 
306  *                    was done in advance is appointed.
307  * @param src   [i]   The character string before the converting is appointed.
308  * @return The character string after the converting is returned.
309  */
310 char*
311 chxj_exchange_jhtml(
312   request_rec*        r,
313   device_table*       spec,
314   const char*         src,
315   apr_size_t          srclen,
316   apr_size_t*         dstlen,
317   chxjconvrule_entry* entryp,
318   cookie_t*           cookie
319 )
320 {
321   char*     dst;
322   char*     ss;
323   jhtml_t   jhtml;
324   Doc       doc;
325
326   dst = NULL;
327
328   /*--------------------------------------------------------------------------*/
329   /* If qrcode xml                                                            */
330   /*--------------------------------------------------------------------------*/
331   *dstlen = srclen;
332   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
333   if (dst) {
334     DBG(r,"I found qrcode xml");
335     return dst;
336   }
337   DBG(r,"not found qrcode xml");
338
339   /*--------------------------------------------------------------------------*/
340   /* The CHTML structure is initialized.                                      */
341   /*--------------------------------------------------------------------------*/
342   s_init_jhtml(&jhtml, &doc, r, spec);
343
344   jhtml.entryp = entryp;
345   jhtml.cookie = cookie;
346
347   ap_set_content_type(r, "text/html; charset=Windows-31J");
348
349   /*--------------------------------------------------------------------------*/
350   /* The character string of the input is analyzed.                           */
351   /*--------------------------------------------------------------------------*/
352   qs_init_malloc(&doc);
353   qs_init_root_node(&doc);
354
355   ss = apr_pcalloc(r->pool, srclen + 1);
356
357   memset(ss,   0, srclen + 1);
358   memcpy(ss, src, srclen);
359
360 #ifdef DUMP_LOG
361   chxj_dump_out("[src] CHTML -> JHTML", ss, srclen);
362 #endif
363
364   qs_parse_string(&doc,ss,strlen(ss));
365
366   /*--------------------------------------------------------------------------*/
367   /* It converts it from CHTML to JHTML.                                      */
368   /*--------------------------------------------------------------------------*/
369   chxj_node_exchange(spec,r,(void*)&jhtml, &doc, qs_get_root(&doc), 0);
370   dst = jhtml.out;
371
372   qs_all_free(&doc,QX_LOGMARK);
373
374   if (! dst) 
375     return apr_pstrdup(r->pool,ss);
376
377   if (! strlen(dst)) 
378     dst = apr_psprintf(r->pool, "\n");
379
380   *dstlen = strlen(dst);
381
382 #ifdef DUMP_LOG
383   chxj_dump_out("[dst] CHTML -> JHTML", dst, *dstlen);
384 #endif
385
386   return dst;
387 }
388
389
390 /**
391  * The CHTML structure is initialized.
392  *
393  * @param jhtml [i/o] The pointer to the JHTML structure that wants to be
394  *                   initialized is specified.
395  * @param doc   [i]   The Doc structure that should be set to the initialized
396  *                   JHTML structure is specified.
397  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
398  * @param spec  [i]   The pointer to the device_table
399  */
400 static void
401 s_init_jhtml(jhtml_t* jhtml, Doc* doc, request_rec* r, device_table* spec)
402 {
403   memset(doc,   0, sizeof(Doc));
404   memset(jhtml, 0, sizeof(jhtml_t));
405
406   doc->r      = r;
407   jhtml->doc  = doc;
408   jhtml->spec = spec;
409   jhtml->out  = qs_alloc_zero_byte_string(r);
410   jhtml->conf = ap_get_module_config(r->per_dir_config, &chxj_module);
411   jhtml->doc->parse_mode = PARSE_MODE_CHTML;
412 }
413
414
415 /**
416  * Corresponding EMOJI to a current character-code is retrieved. 
417  * The substitution character string is stored in the rslt pointer if agreeing.
418  *
419  * @param jhtml   [i]   The pointer to the CHTML structure is specified. 
420  * @param txt     [i]   The character string to want to examine whether it is 
421  *                      EMOJI is specified. 
422  * @param rslt    [o]   The pointer to the pointer that stores the result is 
423  *                      specified. 
424  * @return When corresponding EMOJI exists, it returns it excluding 0. 
425  */
426 static int
427 s_jhtml_search_emoji(jhtml_t* jhtml, char* txt, char** rslt)
428 {
429   emoji_t*      ee;
430   request_rec*  r;
431   device_table* spec;
432   int           len;
433
434   spec = jhtml->spec;
435
436   len = strlen(txt);
437   r = jhtml->doc->r;
438
439   if (! spec) DBG(r,"spec is NULL");
440
441   for (ee = jhtml->conf->emoji;
442        ee;
443        ee = ee->next) {
444
445     unsigned char hex1byte;
446     unsigned char hex2byte;
447
448     if (! ee->imode) { 
449       DBG(r,"emoji->imode is NULL");
450       continue;
451     }
452
453     hex1byte = ee->imode->hex1byte & 0xff;
454     hex2byte = ee->imode->hex2byte & 0xff;
455
456     if (ee->imode->string
457     &&  strlen(ee->imode->string) > 0
458     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
459       if (spec == NULL || spec->emoji_type == NULL) {
460         *rslt = apr_psprintf(r->pool,"\e%s\ f", ee->jphone->string);
461         return strlen(ee->imode->string);
462       }
463
464       return 0;
465     }
466
467     if (len >= 2
468     && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
469     && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
470       if (spec == NULL || spec->emoji_type == NULL) {
471         *rslt = apr_psprintf(r->pool,"\e%s\ f", ee->jphone->string);
472         return 2;
473       }
474
475       return 0;
476     }
477   }
478
479   return 0;
480 }
481
482
483 /**
484  * It is a handler who processes the HTML tag.
485  *
486  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
487  *                     destination is specified.
488  * @param node   [i]   The HTML tag node is specified.
489  * @return The conversion result is returned.
490  */
491 static char*
492 s_jhtml_start_html_tag(void* pdoc, Node* node) 
493 {
494   jhtml_t*      jhtml;
495   Doc*          doc;
496   request_rec*  r;
497
498
499   jhtml  = GET_JHTML(pdoc);
500   doc    = jhtml->doc;
501   r      = doc->r;
502   DBG(r, "start s_jhtml_start_html_tag()");
503
504   /*--------------------------------------------------------------------------*/
505   /* start HTML tag                                                           */
506   /*--------------------------------------------------------------------------*/
507   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<html>\n", NULL);
508
509   DBG(r, "end s_jhtml_start_html_tag()");
510
511   return jhtml->out;
512 }
513
514
515 /**
516  * It is a handler who processes the HTML tag.
517  *
518  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
519  *                     destination is specified.
520  * @param node   [i]   The HTML tag node is specified.
521  * @return The conversion result is returned.
522  */
523 static char*
524 s_jhtml_end_html_tag(void* pdoc, Node* child) 
525 {
526   jhtml_t*      jhtml = GET_JHTML(pdoc);
527   Doc*          doc = jhtml->doc;
528   request_rec*  r   = doc->r;
529
530   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</html>\n", NULL);
531
532   return jhtml->out;
533 }
534
535
536 /**
537  * It is a handler who processes the META tag.
538  *
539  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
540  *                     destination is specified.
541  * @param node   [i]   The META tag node is specified.
542  * @return The conversion result is returned.
543  */
544 static char*
545 s_jhtml_start_meta_tag(void* pdoc, Node* node) 
546 {
547   jhtml_t*     jhtml;
548   Doc*         doc;
549   request_rec* r;
550   Attr*        attr;
551   int          content_type_flag;
552   int          refresh_flag;
553
554   jhtml             = GET_JHTML(pdoc);
555   doc               = jhtml->doc;
556   r                 = doc->r;
557   refresh_flag      = 0;
558   content_type_flag = 0;
559
560   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<meta", NULL);
561
562
563   /*--------------------------------------------------------------------------*/
564   /* Get Attributes                                                           */
565   /*--------------------------------------------------------------------------*/
566   for (attr = qs_get_attr(doc,node);
567        attr;
568        attr = qs_get_next_attr(doc,attr)) {
569
570     char* name;
571     char* value;
572
573     name   = qs_get_attr_name(doc,attr);
574     value  = qs_get_attr_value(doc,attr);
575
576     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "http-equiv") == 0) {
577       /*----------------------------------------------------------------------*/
578       /* CHTML 2.0                                                            */
579       /*----------------------------------------------------------------------*/
580       jhtml->out = apr_pstrcat(r->pool, 
581                       jhtml->out, 
582                       " http-equiv=\"", 
583                       value,
584                       "\"",
585                       NULL);
586       if ((*value == 'c' || *value == 'C') 
587       && strcasecmp(value, "content-type") == 0) {
588         content_type_flag = 1;
589       }
590       if ((*value == 'r' || *value == 'R')
591       && strcasecmp(value, "refresh") == 0)
592         refresh_flag = 1;
593     }
594     else
595     if ((*name == 'c' || *name == 'C') &&strcasecmp(name, "content") == 0) {
596       /*----------------------------------------------------------------------*/
597       /* CHTML 2.0                                                            */
598       /*----------------------------------------------------------------------*/
599       if (content_type_flag)  {
600         jhtml->out = apr_pstrcat(r->pool,
601                                 jhtml->out,
602                                 " ",
603                                 name,
604                                 "=\"",
605                                 "text/html; charset=Windows-31J",
606                                 "\"",
607                                 NULL);
608       }
609       else
610       if (refresh_flag) {
611         char* buf;
612         char* sec;
613         char* url;
614
615         buf = apr_pstrdup(r->pool, value);
616
617         url = strchr(buf, ';');
618         if (url) {
619           sec = apr_pstrdup(r->pool, buf);
620           sec[url-buf] = 0;
621           url++;
622           url = chxj_encoding_parameter(r, url);
623           url = chxj_add_cookie_parameter(r, url, jhtml->cookie);
624           jhtml->out = apr_pstrcat(r->pool,
625                                    jhtml->out,
626                                    " ",
627                                    name,
628                                    "=\"",
629                                    sec,
630                                    ";",
631                                    url,
632                                    "\"",
633                                    NULL);
634         }
635       }
636       else
637         jhtml->out = apr_pstrcat(r->pool,
638                                  jhtml->out,
639                                  " ",
640                                  name,
641                                  "=\"",
642                                  value,
643                                  "\"",
644                                  NULL);
645     }
646   }
647
648   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
649
650   return jhtml->out;
651 }
652
653
654 /**
655  * It is a handler who processes the META tag.
656  *
657  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
658  *                     destination is specified.
659  * @param node   [i]   The META tag node is specified.
660  * @return The conversion result is returned.
661  */
662 static char*
663 s_jhtml_end_meta_tag(void* pdoc, Node* child) 
664 {
665   jhtml_t* jhtml;
666
667   jhtml = GET_JHTML(pdoc);
668
669   return jhtml->out;
670 }
671
672
673 /**
674  * It is a handler who processes the HEAD tag.
675  *
676  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
677  *                     destination is specified.
678  * @param node   [i]   The HEAD tag node is specified.
679  * @return The conversion result is returned.
680  */
681 static char*
682 s_jhtml_start_head_tag(void* pdoc, Node* node) 
683 {
684   jhtml_t*      jhtml;
685   Doc*          doc;
686   request_rec*  r;
687
688   jhtml = GET_JHTML(pdoc);
689   doc   = jhtml->doc;
690   r     = doc->r;
691
692   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<head>\r\n", NULL);
693
694   return jhtml->out;
695 }
696
697
698 /**
699  * It is a handler who processes the HEAD tag.
700  *
701  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
702  *                     destination is specified.
703  * @param node   [i]   The HEAD tag node is specified.
704  * @return The conversion result is returned.
705  */
706 static char*
707 s_jhtml_end_head_tag(void* pdoc, Node* child) 
708 {
709   jhtml_t*      jhtml;
710   Doc*          doc;
711   request_rec*  r;
712
713   jhtml = GET_JHTML(pdoc);
714   doc   = jhtml->doc;
715   r     = doc->r;
716
717   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</head>\r\n", NULL);
718
719   return jhtml->out;
720 }
721
722
723 /**
724  * It is a handler who processes the TITLE tag.
725  *
726  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
727  *                     destination is specified.
728  * @param node   [i]   The TITLE tag node is specified.
729  * @return The conversion result is returned.
730  */
731 static char*
732 s_jhtml_start_title_tag(void* pdoc, Node* node) 
733 {
734   jhtml_t*     jhtml;
735   Doc*         doc;
736   request_rec* r;
737
738   jhtml = GET_JHTML(pdoc);
739   doc   = jhtml->doc;
740   r     = doc->r;
741
742   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<title>", NULL);
743
744   return jhtml->out;
745 }
746
747
748 /**
749  * It is a handler who processes the TITLE tag.
750  *
751  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
752  *                     destination is specified.
753  * @param node   [i]   The TITLE tag node is specified.
754  * @return The conversion result is returned.
755  */
756 static char*
757 s_jhtml_end_title_tag(void* pdoc, Node* child) 
758 {
759   jhtml_t*      jhtml;
760   Doc*          doc;
761   request_rec*  r;
762
763   jhtml = GET_JHTML(pdoc);
764   doc   = jhtml->doc;
765   r     = doc->r;
766
767   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</title>\r\n", NULL);
768
769   return jhtml->out;
770 }
771
772
773 /**
774  * It is a handler who processes the BASE tag.
775  *
776  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
777  *                     destination is specified.
778  * @param node   [i]   The BASE tag node is specified.
779  * @return The conversion result is returned.
780  */
781 static char*
782 s_jhtml_start_base_tag(void* pdoc, Node* node) 
783 {
784   jhtml_t*      jhtml;
785   Attr*         attr;
786   Doc*          doc;
787   request_rec*  r;
788
789   jhtml = GET_JHTML(pdoc);
790   doc   = jhtml->doc;
791   r     = doc->r;
792
793   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<base", NULL);
794
795   /*--------------------------------------------------------------------------*/
796   /* Get Attributes                                                           */
797   /*--------------------------------------------------------------------------*/
798   for (attr = qs_get_attr(doc,node);
799        attr;
800        attr = qs_get_next_attr(doc,attr)) {
801
802     char* name;
803     char* value;
804
805     name = qs_get_attr_name(doc,attr);
806     value = qs_get_attr_value(doc,attr);
807
808     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "href") == 0) {
809       jhtml->out = apr_pstrcat(r->pool, 
810                       jhtml->out, 
811                       " href=\"", 
812                       value, 
813                       "\"", 
814                       NULL);
815     }
816   }
817
818   jhtml->out = apr_pstrcat(r->pool, jhtml->out, " >\r\n", NULL);
819
820   return jhtml->out;
821 }
822
823
824 /**
825  * It is a handler who processes the BASE tag.
826  *
827  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
828  *                     destination is specified.
829  * @param node   [i]   The BASE tag node is specified.
830  * @return The conversion result is returned.
831  */
832 static char*
833 s_jhtml_end_base_tag(void* pdoc, Node* child) 
834 {
835   jhtml_t* jhtml;
836
837   jhtml = GET_JHTML(pdoc);
838
839   return jhtml->out;
840 }
841
842
843 /**
844  * It is a handler who processes the BODY tag.
845  *
846  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
847  *                     destination is specified.
848  * @param node   [i]   The BODY tag node is specified.
849  * @return The conversion result is returned.
850  */
851 static char*
852 s_jhtml_start_body_tag(void* pdoc, Node* node) 
853 {
854   jhtml_t*     jhtml;
855   Doc*         doc;
856   request_rec* r;
857   Attr*        attr;
858
859   jhtml = GET_JHTML(pdoc);
860   doc   = jhtml->doc;
861   r     = doc->r;
862
863   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<body", NULL);
864
865   /*--------------------------------------------------------------------------*/
866   /* Get Attributes                                                           */
867   /*--------------------------------------------------------------------------*/
868   for (attr = qs_get_attr(doc,node);
869        attr;
870        attr = qs_get_next_attr(doc,attr)) {
871
872     char* name;
873     char* value;
874
875     name  = qs_get_attr_name(doc,attr);
876     value  = qs_get_attr_value(doc,attr);
877
878     if ((*name == 'b' || *name == 'B') && strcasecmp(name, "bgcolor") == 0) {
879       /*----------------------------------------------------------------------*/
880       /* CHTML 2.0                                                            */
881       /*----------------------------------------------------------------------*/
882       jhtml->out = apr_pstrcat(r->pool, 
883                                jhtml->out, 
884                                " bgcolor=\"", 
885                                value, 
886                                "\"", 
887                                NULL);
888     }
889     else
890     if ((*name == 't' || *name == 'T') && strcasecmp(name, "text") == 0) {
891       /*----------------------------------------------------------------------*/
892       /* CHTML 2.0                                                            */
893       /*----------------------------------------------------------------------*/
894       jhtml->out = apr_pstrcat(r->pool, 
895                                jhtml->out, 
896                                " text=\"", 
897                                value, 
898                                "\"", 
899                                NULL);
900     }
901     else
902     if ((*name == 'l' || *name == 'L') && strcasecmp(name, "link") == 0) {
903       /*----------------------------------------------------------------------*/
904       /* CHTML 2.0                                                            */
905       /*----------------------------------------------------------------------*/
906       jhtml->out = apr_pstrcat(r->pool, 
907                               jhtml->out, 
908                               " link=\"", 
909                               value, 
910                               "\"", 
911                               NULL);
912     }
913     else
914     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "alink") == 0) {
915       /*----------------------------------------------------------------------*/
916       /* CHTML 4.0                                                            */
917       /*----------------------------------------------------------------------*/
918       /* ignore */
919     }
920     else
921     if ((*name == 'v' || *name == 'V') && strcasecmp(name, "vlink") == 0) {
922       /*----------------------------------------------------------------------*/
923       /* CHTML 4.0                                                            */
924       /*----------------------------------------------------------------------*/
925       /* ignore */
926     }
927   }
928
929   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">\r\n", NULL);
930
931   return jhtml->out;
932 }
933
934
935 /**
936  * It is a handler who processes the BODY tag.
937  *
938  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
939  *                     destination is specified.
940  * @param node   [i]   The BODY tag node is specified.
941  * @return The conversion result is returned.
942  */
943 static char*
944 s_jhtml_end_body_tag(void* pdoc, Node* child) 
945 {
946   jhtml_t*      jhtml;
947   Doc*          doc;
948   request_rec*  r;
949
950   jhtml = GET_JHTML(pdoc);
951   doc   = jhtml->doc;
952   r     = doc->r;
953
954   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</body>\r\n", NULL);
955
956   return jhtml->out;
957 }
958
959
960 /**
961  * It is a handler who processes the A tag.
962  *
963  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
964  *                     destination is specified.
965  * @param node   [i]   The A tag node is specified.
966  * @return The conversion result is returned.
967  */
968 static char*
969 s_jhtml_start_a_tag(void* pdoc, Node* node) 
970 {
971   jhtml_t*      jhtml;
972   Doc*          doc;
973   request_rec*  r;
974   Attr*         attr;
975
976   jhtml = GET_JHTML(pdoc);
977   doc   = jhtml->doc;
978   r     = doc->r;
979
980   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<a", NULL);
981
982   /*--------------------------------------------------------------------------*/
983   /* Get Attributes                                                           */
984   /*--------------------------------------------------------------------------*/
985   for (attr = qs_get_attr(doc,node);
986        attr; 
987        attr = qs_get_next_attr(doc,attr)) {
988
989     char* name;
990     char* value;
991
992     name  = qs_get_attr_name(doc,attr);
993     value = qs_get_attr_value(doc,attr);
994
995     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0) {
996       /*----------------------------------------------------------------------*/
997       /* CHTML1.0                                                             */
998       /*----------------------------------------------------------------------*/
999       jhtml->out = apr_pstrcat(r->pool, 
1000                                jhtml->out, 
1001                                " name=\"", 
1002                                value, 
1003                                "\"", 
1004                                NULL);
1005     }
1006     else
1007     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "href") == 0) {
1008       /*----------------------------------------------------------------------*/
1009       /* CHTML1.0                                                             */
1010       /*----------------------------------------------------------------------*/
1011       value = chxj_encoding_parameter(r, value);
1012       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1013       jhtml->out = apr_pstrcat(r->pool, 
1014                                jhtml->out, 
1015                                " href=\"", 
1016                                value, 
1017                                "\"", 
1018                                NULL);
1019     }
1020     else
1021     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "accesskey") == 0) {
1022       /*----------------------------------------------------------------------*/
1023       /* CHTML1.0                                                             */
1024       /*----------------------------------------------------------------------*/
1025       jhtml->out = apr_pstrcat(r->pool, 
1026                                jhtml->out, 
1027                                " accesskey=\"", 
1028                                value, 
1029                                "\"", 
1030                                NULL);
1031     }
1032     else
1033     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "cti") == 0) {
1034       /*----------------------------------------------------------------------*/
1035       /* CHTML 2.0                                                            */
1036       /*----------------------------------------------------------------------*/
1037       jhtml->out = apr_pstrcat(r->pool, 
1038                                jhtml->out, 
1039                                " cti=\"", 
1040                                value, 
1041                                "\"", 
1042                                NULL);
1043     }
1044     else
1045     if ((*name == 'i' || *name == 'I') && strcasecmp(name, "ijam") == 0) {
1046       /*----------------------------------------------------------------------*/
1047       /* CHTML 3.0                                                            */
1048       /*----------------------------------------------------------------------*/
1049       /* ignore */
1050     }
1051     else
1052     if ((*name == 'u' || *name == 'U') && strcasecmp(name, "utn") == 0) {
1053       /*----------------------------------------------------------------------*/
1054       /* CHTML 3.0                                                            */
1055       /* It is special only for CHTML.                                        */
1056       /*----------------------------------------------------------------------*/
1057       jhtml->out = apr_pstrcat(r->pool, 
1058                                jhtml->out, 
1059                                " utn ", 
1060                                NULL);
1061     }
1062     else
1063     if ((*name == 't' || *name == 'T') && strcasecmp(name, "telbook") == 0) {
1064       /*----------------------------------------------------------------------*/
1065       /* CHTML 3.0                                                            */
1066       /*----------------------------------------------------------------------*/
1067       /* not support */
1068     }
1069     else
1070     if ((*name == 'k' || *name == 'K') && strcasecmp(name, "kana") == 0) {
1071       /*----------------------------------------------------------------------*/
1072       /* CHTML 3.0                                                            */
1073       /*----------------------------------------------------------------------*/
1074       /* not support */
1075     }
1076     else
1077     if ((*name == 'e' || *name == 'E') && strcasecmp(name, "email") == 0) {
1078       /*----------------------------------------------------------------------*/
1079       /* CHTML 3.0                                                            */
1080       /*----------------------------------------------------------------------*/
1081       /* not support */
1082     }
1083     else
1084     if ((*name == 'i' || *name == 'I') && strcasecmp(name, "ista") == 0) {
1085       /*----------------------------------------------------------------------*/
1086       /* CHTML 4.0                                                            */
1087       /*----------------------------------------------------------------------*/
1088       /* ignore */
1089     }
1090     else
1091     if ((*name == 'i' || *name == 'I') && strcasecmp(name, "ilet") == 0) {
1092       /*----------------------------------------------------------------------*/
1093       /* CHTML 5.0                                                            */
1094       /*----------------------------------------------------------------------*/
1095       /* ignore */
1096     }
1097     else
1098     if ((*name == 'i' || *name == 'I') && strcasecmp(name, "iswf") == 0) {
1099       /*----------------------------------------------------------------------*/
1100       /* CHTML 5.0                                                            */
1101       /*----------------------------------------------------------------------*/
1102       /* ignore */
1103     }
1104     else
1105     if ((*name == 'i' || *name == 'I') && strcasecmp(name, "irst") == 0) {
1106       /*----------------------------------------------------------------------*/
1107       /* CHTML 5.0                                                            */
1108       /*----------------------------------------------------------------------*/
1109       /* ignore */
1110     }
1111   }
1112
1113   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
1114
1115   return jhtml->out;
1116 }
1117
1118
1119 /**
1120  * It is a handler who processes the A tag.
1121  *
1122  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1123  *                     destination is specified.
1124  * @param node   [i]   The A tag node is specified.
1125  * @return The conversion result is returned.
1126  */
1127 static char*
1128 s_jhtml_end_a_tag(void* pdoc, Node* child) 
1129 {
1130   jhtml_t*     jhtml;
1131   Doc*         doc;
1132   request_rec* r;
1133
1134   jhtml = GET_JHTML(pdoc);
1135   doc   = jhtml->doc;
1136   r     = doc->r;
1137
1138   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</a>", NULL);
1139
1140   return jhtml->out;
1141 }
1142
1143
1144 /**
1145  * It is a handler who processes the BR tag.
1146  *
1147  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1148  *                     destination is specified.
1149  * @param node   [i]   The BR tag node is specified.
1150  * @return The conversion result is returned.
1151  */
1152 static char*
1153 s_jhtml_start_br_tag(void* pdoc, Node* node) 
1154 {
1155   jhtml_t*     jhtml;
1156   Doc*         doc;
1157   request_rec* r;
1158
1159   jhtml = GET_JHTML(pdoc);
1160   doc   = jhtml->doc;
1161   r     = doc->r;
1162
1163   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<br>\r\n", NULL);
1164
1165   return jhtml->out;
1166 }
1167
1168
1169 /**
1170  * It is a handler who processes the BR tag.
1171  *
1172  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1173  *                     destination is specified.
1174  * @param node   [i]   The BR tag node is specified.
1175  * @return The conversion result is returned.
1176  */
1177 static char*
1178 s_jhtml_end_br_tag(void* pdoc, Node* child) 
1179 {
1180   jhtml_t*  jhtml;
1181
1182   jhtml = GET_JHTML(pdoc);
1183
1184   return jhtml->out;
1185 }
1186
1187
1188 /**
1189  * It is a handler who processes the TR tag.
1190  *
1191  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1192  *                     destination is specified.
1193  * @param node   [i]   The TR tag node is specified.
1194  * @return The conversion result is returned.
1195  */
1196 static char*
1197 s_jhtml_start_tr_tag(void* pdoc, Node* node) 
1198 {
1199   jhtml_t*     jhtml;
1200   Doc*         doc;
1201   request_rec* r;
1202
1203   jhtml = GET_JHTML(pdoc);
1204   doc   = jhtml->doc;
1205   r     = doc->r;
1206
1207   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<br>\r\n", NULL);
1208
1209   return jhtml->out;
1210 }
1211
1212
1213 /**
1214  * It is a handler who processes the TR tag.
1215  *
1216  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1217  *                     destination is specified.
1218  * @param node   [i]   The TR tag node is specified.
1219  * @return The conversion result is returned.
1220  */
1221 static char*
1222 s_jhtml_end_tr_tag(void* pdoc, Node* child) 
1223 {
1224   jhtml_t* jhtml;
1225
1226   jhtml = GET_JHTML(pdoc);
1227
1228   return jhtml->out;
1229 }
1230
1231
1232 /**
1233  * It is a handler who processes the FONT tag.
1234  *
1235  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1236  *                     destination is specified.
1237  * @param node   [i]   The FONT tag node is specified.
1238  * @return The conversion result is returned.
1239  */
1240 static char*
1241 s_jhtml_start_font_tag(void* pdoc, Node* node) 
1242 {
1243   jhtml_t*      jhtml;
1244   Doc*          doc;
1245   request_rec*  r;
1246   Attr*         attr;
1247
1248   jhtml = GET_JHTML(pdoc);
1249   doc   = jhtml->doc;
1250   r     = doc->r;
1251
1252   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<font", NULL);
1253
1254   /*--------------------------------------------------------------------------*/
1255   /* Get Attributes                                                           */
1256   /*--------------------------------------------------------------------------*/
1257   for (attr = qs_get_attr(doc,node);
1258        attr; 
1259        attr = qs_get_next_attr(doc,attr)) {
1260
1261     char* name;
1262     char* value;
1263
1264     name  = qs_get_attr_name(doc,attr);
1265     value = qs_get_attr_value(doc,attr);
1266
1267     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "color") == 0) {
1268       jhtml->out = apr_pstrcat(r->pool, 
1269                       jhtml->out, 
1270                       " color=\"", 
1271                       value, 
1272                       "\"", 
1273                       NULL);
1274     }
1275     else
1276     if ((*name == 's' || *name == 'S') && strcasecmp(name, "size") == 0) {
1277       /*----------------------------------------------------------------------*/
1278       /* CHTML 5.0                                                            */
1279       /*----------------------------------------------------------------------*/
1280       /* ignore */
1281     }
1282   }
1283
1284   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
1285
1286   return jhtml->out;
1287 }
1288
1289
1290 /**
1291  * It is a handler who processes the FONT tag.
1292  *
1293  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1294  *                     destination is specified.
1295  * @param node   [i]   The FONT tag node is specified.
1296  * @return The conversion result is returned.
1297  */
1298 static char*
1299 s_jhtml_end_font_tag(void* pdoc, Node* child) 
1300 {
1301   jhtml_t* jhtml = GET_JHTML(pdoc);
1302   request_rec* r = jhtml->doc->r;
1303
1304   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</font>", NULL);
1305
1306   return jhtml->out;
1307 }
1308
1309
1310 /**
1311  * It is a handler who processes the FORM tag.
1312  *
1313  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1314  *                     destination is specified.
1315  * @param node   [i]   The FORM tag node is specified.
1316  * @return The conversion result is returned.
1317  */
1318 static char*
1319 s_jhtml_start_form_tag(void* pdoc, Node* node) 
1320 {
1321   jhtml_t*     jhtml = GET_JHTML(pdoc);
1322   Doc*         doc   = jhtml->doc;
1323   request_rec* r     = doc->r;
1324   Attr*        attr;
1325
1326   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<form", NULL);
1327
1328   /*--------------------------------------------------------------------------*/
1329   /* Get Attributes                                                           */
1330   /*--------------------------------------------------------------------------*/
1331   for (attr = qs_get_attr(doc,node);
1332        attr;
1333        attr = qs_get_next_attr(doc,attr)) {
1334     char* name = qs_get_attr_name(doc,attr);
1335     char* value = qs_get_attr_value(doc,attr);
1336
1337     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "action") == 0) {
1338       /*----------------------------------------------------------------------*/
1339       /* CHTML 1.0                                                            */
1340       /*----------------------------------------------------------------------*/
1341       jhtml->out = apr_pstrcat(r->pool, 
1342                       jhtml->out, 
1343                       " action=\"",
1344                       value,
1345                       "\"", 
1346                       NULL);
1347     }
1348     else
1349     if ((*name == 'm' || *name == 'M') && strcasecmp(name, "method") == 0) {
1350       /*----------------------------------------------------------------------*/
1351       /* CHTML 1.0                                                            */
1352       /*----------------------------------------------------------------------*/
1353       jhtml->out = apr_pstrcat(r->pool, 
1354                       jhtml->out, 
1355                       " method=\"",
1356                       value,
1357                       "\"", 
1358                       NULL);
1359     }
1360     else
1361     if ((*name == 'u' || *name == 'U') && strcasecmp(name, "utn") == 0) {
1362       /*----------------------------------------------------------------------*/
1363       /* CHTML 3.0                                                            */
1364       /* It is special only for CHTML.                                        */
1365       /*----------------------------------------------------------------------*/
1366       jhtml->out = apr_pstrcat(r->pool, 
1367                       jhtml->out, 
1368                       " utn ", 
1369                       NULL);
1370     }
1371   }
1372
1373   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
1374
1375   if (jhtml->cookie && jhtml->cookie->cookie_id) {
1376     jhtml->out = apr_psprintf(r->pool, "%s<input type='hidden' name='%s' value='%s'>",
1377                              jhtml->out, 
1378                              CHXJ_COOKIE_PARAM,
1379                              jhtml->cookie->cookie_id);
1380   }
1381
1382   return jhtml->out;
1383 }
1384
1385
1386 /**
1387  * It is a handler who processes the FORM tag.
1388  *
1389  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1390  *                     destination is specified.
1391  * @param node   [i]   The FORM tag node is specified.
1392  * @return The conversion result is returned.
1393  */
1394 static char*
1395 s_jhtml_end_form_tag(void* pdoc, Node* child) 
1396 {
1397   jhtml_t*     jhtml = GET_JHTML(pdoc);
1398   Doc*         doc   = jhtml->doc;
1399   request_rec* r     = doc->r;
1400
1401   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</form>", NULL);
1402
1403   return jhtml->out;
1404 }
1405
1406
1407 /**
1408  * It is a handler who processes the INPUT tag.
1409  *
1410  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1411  *                     destination is specified.
1412  * @param node   [i]   The INPUT tag node is specified.
1413  * @return The conversion result is returned.
1414  */
1415 static char*
1416 s_jhtml_start_input_tag(void* pdoc, Node* node) 
1417 {
1418   jhtml_t*      jhtml       = GET_JHTML(pdoc);
1419   Doc*          doc         = jhtml->doc;
1420   request_rec*  r           = doc->r;
1421   char*         max_length  = NULL;
1422   char*         type        = NULL;
1423   char*         name        = NULL;
1424   char*         value       = NULL;
1425   char*         istyle      = NULL;
1426   char*         size        = NULL;
1427   char*         checked     = NULL;
1428   char*         accesskey   = NULL;
1429
1430   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<input", NULL);
1431
1432   /*--------------------------------------------------------------------------*/
1433   /* Get Attributes                                                           */
1434   /*--------------------------------------------------------------------------*/
1435
1436   type       = qs_get_type_attr(doc, node, r);
1437   name       = qs_get_name_attr(doc, node, r);
1438   value      = qs_get_value_attr(doc,node,r);
1439   istyle     = qs_get_istyle_attr(doc,node,r);
1440   max_length = qs_get_maxlength_attr(doc,node,r);
1441   checked    = qs_get_checked_attr(doc,node,r);
1442   accesskey  = qs_get_accesskey_attr(doc, node, r);
1443   size       = qs_get_size_attr(doc, node, r);
1444
1445   if (type) {
1446     jhtml->out = apr_pstrcat(r->pool,
1447                     jhtml->out, 
1448                     " type=\"", 
1449                     type, 
1450                     "\" ", 
1451                     NULL);
1452   }
1453   if (size) {
1454     jhtml->out = apr_pstrcat(r->pool, 
1455                     jhtml->out, 
1456                     " size=\"", 
1457                     size, 
1458                     "\" ", 
1459                     NULL);
1460   }
1461   if (name) {
1462     jhtml->out = apr_pstrcat(r->pool, 
1463                     jhtml->out, 
1464                     " name=\"", 
1465                     name, 
1466                     "\" ", 
1467                     NULL);
1468   }
1469   if (value) {
1470     jhtml->out = apr_pstrcat(r->pool, 
1471                     jhtml->out, 
1472                     " value=\"", 
1473                     value, 
1474                     "\" ", 
1475                     NULL);
1476   }
1477   if (accesskey) {
1478     jhtml->out = apr_pstrcat(r->pool, 
1479                     jhtml->out, 
1480                     " accesskey=\"", 
1481                     accesskey, "\" ", 
1482                     NULL);
1483   }
1484   if (istyle) {
1485     /*------------------------------------------------------------------------*/
1486     /* CHTML 2.0                                                              */
1487     /*------------------------------------------------------------------------*/
1488     if (type && (*type == 'p' || *type == 'P') && strcasecmp(type, "password") == 0
1489     && ! jhtml->entryp->pc_flag ) {
1490       jhtml->out = apr_pstrcat(r->pool, 
1491                     jhtml->out, 
1492                     " mode=\"", 
1493                     "numeric", "\" ", 
1494                     NULL);
1495     }
1496     else {
1497       jhtml->out = apr_pstrcat(r->pool, 
1498                     jhtml->out, 
1499                     " mode=\"", 
1500                     chxj_istyle_to_mode(r,istyle), "\" ", 
1501                     NULL);
1502     }
1503   }
1504   else
1505   if (istyle == NULL && type != NULL && strcasecmp(type, "password") == 0) {
1506     jhtml->out = apr_pstrcat(r->pool, 
1507                     jhtml->out, 
1508                     " mode=\"", 
1509                     "numeric", "\" ", 
1510                     NULL);
1511   }
1512   /*--------------------------------------------------------------------------*/
1513   /* The figure is default for the password.                                  */
1514   /*--------------------------------------------------------------------------*/
1515   if (max_length) {
1516     jhtml->out = apr_pstrcat(r->pool, 
1517                       jhtml->out, 
1518                       " maxlength=\"", 
1519                       max_length, 
1520                       "\"", 
1521                       NULL);
1522   }
1523
1524   if (checked) {
1525     jhtml->out = apr_pstrcat(r->pool, 
1526                     jhtml->out, " checked ", NULL);
1527   }
1528
1529   jhtml->out = apr_pstrcat(r->pool, jhtml->out, " >", NULL);
1530
1531   return jhtml->out;
1532 }
1533
1534
1535 /**
1536  * It is a handler who processes the INPUT tag.
1537  *
1538  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1539  *                     destination is specified.
1540  * @param node   [i]   The INPUT tag node is specified.
1541  * @return The conversion result is returned.
1542  */
1543 static char*
1544 s_jhtml_end_input_tag(void* pdoc, Node* child) 
1545 {
1546   jhtml_t*  jhtml = GET_JHTML(pdoc);
1547
1548   return jhtml->out;
1549 }
1550
1551
1552 /**
1553  * It is a handler who processes the CENTER tag.
1554  *
1555  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1556  *                     destination is specified.
1557  * @param node   [i]   The CENTER tag node is specified.
1558  * @return The conversion result is returned.
1559  */
1560 static char*
1561 s_jhtml_start_center_tag(void* pdoc, Node* node) 
1562 {
1563   jhtml_t*      jhtml = GET_JHTML(pdoc);
1564   Doc*          doc   = jhtml->doc;
1565   request_rec*  r     = doc->r;
1566
1567   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<center>", NULL);
1568
1569   return jhtml->out;
1570 }
1571
1572
1573 /**
1574  * It is a handler who processes the CENTER tag.
1575  *
1576  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1577  *                     destination is specified.
1578  * @param node   [i]   The CENTER tag node is specified.
1579  * @return The conversion result is returned.
1580  */
1581 static char*
1582 s_jhtml_end_center_tag(void* pdoc, Node* child) 
1583 {
1584   jhtml_t*      jhtml = GET_JHTML(pdoc);
1585   Doc*          doc   = jhtml->doc;
1586   request_rec*  r     = doc->r;
1587
1588   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</center>", NULL);
1589
1590   return jhtml->out;
1591 }
1592
1593
1594 /**
1595  * It is a handler who processes the li tag.
1596  *
1597  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1598  *                     destination is specified.
1599  * @param node   [i]   The li tag node is specified.
1600  * @return The conversion result is returned.
1601  */
1602 static char*
1603 s_jhtml_start_li_tag(void* pdoc, Node* node) 
1604 {
1605   jhtml_t*      jhtml = GET_JHTML(pdoc);
1606   Doc*          doc   = jhtml->doc;
1607   request_rec*  r     = doc->r;
1608
1609   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<li>", NULL);
1610
1611   return jhtml->out;
1612 }
1613
1614
1615 /**
1616  * It is a handler who processes the li tag.
1617  *
1618  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1619  *                     destination is specified.
1620  * @param node   [i]   The li tag node is specified.
1621  * @return The conversion result is returned.
1622  */
1623 static char*
1624 s_jhtml_end_li_tag(void* pdoc, Node* child) 
1625 {
1626   jhtml_t*      jhtml = GET_JHTML(pdoc);
1627   Doc*          doc   = jhtml->doc;
1628   request_rec*  r     = doc->r;
1629
1630   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</li>", NULL);
1631
1632   return jhtml->out;
1633 }
1634
1635
1636 /**
1637  * It is a handler who processes the OL tag.
1638  *
1639  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1640  *                     destination is specified.
1641  * @param node   [i]   The OL tag node is specified.
1642  * @return The conversion result is returned.
1643  */
1644 static char*
1645 s_jhtml_start_ol_tag(void* pdoc, Node* node) 
1646 {
1647   jhtml_t*      jhtml = GET_JHTML(pdoc);
1648   Doc*          doc   = jhtml->doc;
1649   request_rec*  r     = doc->r;
1650
1651   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<ol>", NULL);
1652
1653   return jhtml->out;
1654 }
1655
1656
1657 /**
1658  * It is a handler who processes the OL tag.
1659  *
1660  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1661  *                     destination is specified.
1662  * @param node   [i]   The OL tag node is specified.
1663  * @return The conversion result is returned.
1664  */
1665 static char*
1666 s_jhtml_end_ol_tag(void* pdoc, Node* child) 
1667 {
1668   jhtml_t*      jhtml = GET_JHTML(pdoc);
1669   Doc*          doc   = jhtml->doc;
1670   request_rec*  r     = doc->r;
1671
1672   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</ol>", NULL);
1673
1674   return jhtml->out;
1675 }
1676
1677
1678 /**
1679  * It is a handler who processes the P tag.
1680  *
1681  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1682  *                     destination is specified.
1683  * @param node   [i]   The P tag node is specified.
1684  * @return The conversion result is returned.
1685  */
1686 static char*
1687 s_jhtml_start_p_tag(void* pdoc, Node* node) 
1688 {
1689   jhtml_t*      jhtml = GET_JHTML(pdoc);
1690   Doc*          doc   = jhtml->doc;
1691   request_rec*  r     = doc->r;
1692
1693   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<p>", NULL);
1694
1695   return jhtml->out;
1696 }
1697
1698
1699 /**
1700  * It is a handler who processes the P tag.
1701  *
1702  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1703  *                     destination is specified.
1704  * @param node   [i]   The P tag node is specified.
1705  * @return The conversion result is returned.
1706  */
1707 static char*
1708 s_jhtml_end_p_tag(void* pdoc, Node* child) 
1709 {
1710   jhtml_t*      jhtml = GET_JHTML(pdoc);
1711   Doc*          doc   = jhtml->doc;
1712   request_rec*  r     = doc->r;
1713
1714   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</p>", NULL);
1715
1716   return jhtml->out;
1717 }
1718
1719
1720 /**
1721  * It is a handler who processes the PRE tag.
1722  *
1723  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1724  *                     destination is specified.
1725  * @param node   [i]   The PRE tag node is specified.
1726  * @return The conversion result is returned.
1727  */
1728 static char*
1729 s_jhtml_start_pre_tag(void* pdoc, Node* node) 
1730 {
1731   jhtml_t*      jhtml = GET_JHTML(pdoc);
1732   Doc*          doc   = jhtml->doc;
1733   request_rec*  r     = doc->r;
1734
1735   jhtml->pre_flag++;
1736   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<pre>", NULL);
1737
1738   return jhtml->out;
1739 }
1740
1741
1742 /**
1743  * It is a handler who processes the PRE tag.
1744  *
1745  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1746  *                     destination is specified.
1747  * @param node   [i]   The PRE tag node is specified.
1748  * @return The conversion result is returned.
1749  */
1750 static char*
1751 s_jhtml_end_pre_tag(void* pdoc, Node* child) 
1752 {
1753   jhtml_t*      jhtml = GET_JHTML(pdoc);
1754   Doc*          doc   = jhtml->doc;
1755   request_rec*  r     = doc->r;
1756
1757   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</pre>", NULL);
1758   jhtml->pre_flag--;
1759
1760   return jhtml->out;
1761 }
1762
1763
1764 /**
1765  * It is a handler who processes the UL tag.
1766  *
1767  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1768  *                     destination is specified.
1769  * @param node   [i]   The UL tag node is specified.
1770  * @return The conversion result is returned.
1771  */
1772 static char*
1773 s_jhtml_start_ul_tag(void* pdoc, Node* node) 
1774 {
1775   jhtml_t*      jhtml = GET_JHTML(pdoc);
1776   Doc*          doc   = jhtml->doc;
1777   request_rec*  r     = doc->r;
1778
1779   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<ul>", NULL);
1780
1781   return jhtml->out;
1782 }
1783
1784
1785 /**
1786  * It is a handler who processes the UL tag.
1787  *
1788  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1789  *                     destination is specified.
1790  * @param node   [i]   The UL tag node is specified.
1791  * @return The conversion result is returned.
1792  */
1793 static char*
1794 s_jhtml_end_ul_tag(void* pdoc, Node* child) 
1795 {
1796   jhtml_t*      jhtml = GET_JHTML(pdoc);
1797   Doc*          doc   = jhtml->doc;
1798   request_rec*  r     = doc->r;
1799
1800   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</ul>", NULL);
1801
1802   return jhtml->out;
1803 }
1804
1805
1806 /**
1807  * It is a handler who processes the HR tag.
1808  *
1809  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1810  *                     destination is specified.
1811  * @param node   [i]   The HR tag node is specified.
1812  * @return The conversion result is returned.
1813  */
1814 static char*
1815 s_jhtml_start_hr_tag(void* pdoc, Node* node) 
1816 {
1817   jhtml_t*     jhtml = GET_JHTML(pdoc);
1818   Doc*         doc   = jhtml->doc;
1819   request_rec* r     = doc->r;
1820   Attr*        attr;
1821
1822   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<hr ", NULL);
1823  
1824   for (attr = qs_get_attr(doc,node);
1825        attr; 
1826        attr = qs_get_next_attr(doc,attr)) {
1827     char* name = qs_get_attr_name(doc,attr);
1828     char* value = qs_get_attr_value(doc,attr);
1829     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align") == 0) {
1830       /*----------------------------------------------------------------------*/
1831       /* CHTML 1.0                                                            */
1832       /*----------------------------------------------------------------------*/
1833       jhtml->out = apr_pstrcat(r->pool,
1834                         jhtml->out, 
1835                         " align=\"", value, "\" ", NULL);
1836     }
1837     else
1838     if ((*name == 's' || *name == 'S') && strcasecmp(name, "size") == 0) {
1839       /*----------------------------------------------------------------------*/
1840       /* CHTML 1.0                                                            */
1841       /*----------------------------------------------------------------------*/
1842       jhtml->out = apr_pstrcat(r->pool,
1843                         jhtml->out, 
1844                         " size=\"", value, "\" ", NULL);
1845     }
1846     else
1847     if ((*name == 'w' || *name == 'W') && strcasecmp(name, "width") == 0) {
1848       /*----------------------------------------------------------------------*/
1849       /* CHTML 1.0                                                            */
1850       /*----------------------------------------------------------------------*/
1851       jhtml->out = apr_pstrcat(r->pool,
1852                         jhtml->out, 
1853                         " width=\"", value, "\" ", NULL);
1854     }
1855     else
1856     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "noshade") == 0) {
1857       /*----------------------------------------------------------------------*/
1858       /* CHTML 1.0                                                            */
1859       /*----------------------------------------------------------------------*/
1860       jhtml->out = apr_pstrcat(r->pool,
1861                         jhtml->out, 
1862                         " noshade ", NULL);
1863     }
1864     else
1865     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "color") == 0) {
1866       /*----------------------------------------------------------------------*/
1867       /* CHTML 4.0                                                            */
1868       /*----------------------------------------------------------------------*/
1869       /* ignore */
1870     }
1871   }
1872   jhtml->out = apr_pstrcat(r->pool, jhtml->out, " >", NULL);
1873
1874   return jhtml->out;
1875 }
1876
1877
1878 /**
1879  * It is a handler who processes the HR tag.
1880  *
1881  * @param jhtml  [i/o] The pointer to the CHTML structure at the output
1882  *                     destination is specified.
1883  * @param node   [i]   The HR tag node is specified.
1884  * @return The conversion result is returned.
1885  */
1886 static char*
1887 s_jhtml_end_hr_tag(void* pdoc, Node* child) 
1888 {
1889   jhtml_t* jhtml = GET_JHTML(pdoc);
1890
1891   return jhtml->out;
1892 }
1893
1894
1895 /**
1896  * It is a handler who processes the IMG tag.
1897  *
1898  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1899  *                     destination is specified.
1900  * @param node   [i]   The IMG tag node is specified.
1901  * @return The conversion result is returned.
1902  */
1903 static char*
1904 s_jhtml_start_img_tag(void* pdoc, Node* node) 
1905 {
1906   jhtml_t*      jhtml = GET_JHTML(pdoc);
1907   Doc*          doc   = jhtml->doc;
1908   request_rec*  r     = doc->r;
1909   Attr*         attr;
1910 #ifndef IMG_NOT_CONVERT_FILENAME
1911   device_table* spec = jhtml->spec;
1912 #endif
1913
1914   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<img", NULL);
1915  
1916
1917   /*--------------------------------------------------------------------------*/
1918   /* Get Attributes                                                           */
1919   /*--------------------------------------------------------------------------*/
1920   for (attr = qs_get_attr(doc,node);
1921        attr;
1922        attr = qs_get_next_attr(doc,attr)) {
1923     char* name  = qs_get_attr_name(doc,attr);
1924     char* value = qs_get_attr_value(doc,attr);
1925
1926     if ((*name == 's' || *name == 'S') && strcasecmp(name, "src") == 0) {
1927       /*----------------------------------------------------------------------*/
1928       /* CHTML 1.0                                                            */
1929       /*----------------------------------------------------------------------*/
1930 #ifdef IMG_NOT_CONVERT_FILENAME
1931       value = chxj_encoding_parameter(r, value);
1932       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1933       jhtml->out = apr_pstrcat(r->pool, 
1934                       jhtml->out, " src=\"",value,"\"", NULL);
1935 #else
1936       value = chxj_img_conv(r, spec, value);
1937       value = chxj_encoding_parameter(r, value);
1938       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1939       jhtml->out = apr_pstrcat(r->pool, 
1940                       jhtml->out, " src=\"", value, NULL);
1941       jhtml->out = apr_pstrcat(r->pool, jhtml->out, "\"", NULL);
1942 #endif
1943     }
1944     else
1945     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align" ) == 0) {
1946       /*----------------------------------------------------------------------*/
1947       /* CHTML 1.0                                                            */
1948       /*----------------------------------------------------------------------*/
1949       jhtml->out = apr_pstrcat(r->pool, 
1950                       jhtml->out, " align=\"",value,"\"", NULL);
1951     }
1952     else
1953     if ((*name == 'w' || *name == 'W') && strcasecmp(name, "width" ) == 0) {
1954       /*----------------------------------------------------------------------*/
1955       /* CHTML 1.0                                                            */
1956       /*----------------------------------------------------------------------*/
1957       jhtml->out = apr_pstrcat(r->pool, 
1958                       jhtml->out, " width=\"",value,"\"", NULL);
1959     }
1960     else
1961     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "height") == 0) {
1962       /*----------------------------------------------------------------------*/
1963       /* CHTML 1.0                                                            */
1964       /*----------------------------------------------------------------------*/
1965       jhtml->out = apr_pstrcat(r->pool, 
1966                       jhtml->out, " height=\"",value,"\"", NULL);
1967     }
1968     else
1969     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "hspace") == 0) {
1970       /*----------------------------------------------------------------------*/
1971       /* CHTML 1.0                                                            */
1972       /*----------------------------------------------------------------------*/
1973       jhtml->out = apr_pstrcat(r->pool, 
1974                       jhtml->out, " hspace=\"",value,"\"", NULL);
1975     }
1976     else
1977     if ((*name == 'v' || *name == 'V') && strcasecmp(name, "vspace") == 0) {
1978       /*----------------------------------------------------------------------*/
1979       /* CHTML 1.0                                                            */
1980       /*----------------------------------------------------------------------*/
1981       jhtml->out = apr_pstrcat(r->pool, 
1982                       jhtml->out, " vspace=\"",value,"\"", NULL);
1983     }
1984     else
1985     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "alt"   ) == 0) {
1986       /*----------------------------------------------------------------------*/
1987       /* CHTML 1.0                                                            */
1988       /*----------------------------------------------------------------------*/
1989       jhtml->out = apr_pstrcat(r->pool, 
1990                       jhtml->out, " alt=\"",value,"\"", NULL);
1991     }
1992     else
1993     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align" ) == 0) {
1994       /*----------------------------------------------------------------------*/
1995       /* CHTML 4.0                                                            */
1996       /*----------------------------------------------------------------------*/
1997       /* ignore */
1998     }
1999   }
2000
2001   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2002
2003   return jhtml->out;
2004 }
2005
2006
2007 /**
2008  * It is a handler who processes the IMG tag.
2009  *
2010  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2011  *                     destination is specified.
2012  * @param node   [i]   The IMG tag node is specified.
2013  * @return The conversion result is returned.
2014  */
2015 static char*
2016 s_jhtml_end_img_tag(void* pdoc, Node* child) 
2017 {
2018   jhtml_t*  jhtml = GET_JHTML(pdoc);
2019
2020   return jhtml->out;
2021 }
2022
2023
2024 /**
2025  * It is a handler who processes the SELECT tag.
2026  *
2027  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2028  *                     destination is specified.
2029  * @param node   [i]   The SELECT tag node is specified.
2030  * @return The conversion result is returned.
2031  */
2032 static char*
2033 s_jhtml_start_select_tag(void* pdoc, Node* child)
2034 {
2035   jhtml_t*     jhtml = GET_JHTML(pdoc);
2036   Doc*         doc   = jhtml->doc;
2037   request_rec* r     = doc->r;
2038   Attr*        attr;
2039
2040   char* size      = NULL;
2041   char* name      = NULL;
2042
2043   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<select", NULL);
2044   for (attr = qs_get_attr(doc,child);
2045        attr;
2046        attr = qs_get_next_attr(doc,attr)) {
2047     char* nm  = qs_get_attr_name(doc,attr);
2048     char* val = qs_get_attr_value(doc,attr);
2049
2050     if ((*name == 's' || *name == 'S') && strcasecmp(nm, "size") == 0) {
2051       /*----------------------------------------------------------------------*/
2052       /* CHTML 1.0 version 2.0                                                */
2053       /*----------------------------------------------------------------------*/
2054       size = apr_pstrdup(r->pool, val);
2055     }
2056     else
2057     if ((*name == 'n' || *name == 'N') && strcasecmp(nm, "name") == 0) {
2058       /*----------------------------------------------------------------------*/
2059       /* CHTML 1.0 version 2.0                                                */
2060       /*----------------------------------------------------------------------*/
2061       name = apr_pstrdup(r->pool, val);
2062     }
2063     else
2064     if ((*name == 'm' || *name == 'M') && strcasecmp(nm, "multiple") == 0) {
2065       /*----------------------------------------------------------------------*/
2066       /* CHTML 1.0 version 2.0                                                */
2067       /*----------------------------------------------------------------------*/
2068       /* not support */
2069     }
2070   }
2071
2072   if (size)
2073     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " size=\"",size,"\"", NULL);
2074
2075   if (name)
2076     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " name=\"",name,"\"", NULL);
2077
2078   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">\n", NULL);
2079
2080   return jhtml->out;
2081 }
2082
2083 /**
2084  * It is a handler who processes the SELECT tag.
2085  *
2086  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2087  *                     destination is specified.
2088  * @param node   [i]   The SELECT tag node is specified.
2089  * @return The conversion result is returned.
2090  */
2091 static char*
2092 s_jhtml_end_select_tag(void* pdoc, Node* child)
2093 {
2094   jhtml_t*     jhtml = GET_JHTML(pdoc);
2095   Doc*         doc   = jhtml->doc;
2096   request_rec* r     = doc->r;
2097
2098   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</select>\n", NULL);
2099
2100   return jhtml->out;
2101 }
2102
2103 /**
2104  * It is a handler who processes the OPTION tag.
2105  *
2106  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2107  *                     destination is specified.
2108  * @param node   [i]   The OPTION tag node is specified.
2109  * @return The conversion result is returned.
2110  */
2111 static char*
2112 s_jhtml_start_option_tag(void* pdoc, Node* child)
2113 {
2114   jhtml_t*     jhtml = GET_JHTML(pdoc);
2115   Doc*         doc   = jhtml->doc;
2116   request_rec* r     = doc->r;
2117   Attr*        attr;
2118
2119   char* selected   = NULL;
2120   char* value      = NULL;
2121
2122   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<option", NULL);
2123   for (attr = qs_get_attr(doc,child);
2124        attr;
2125        attr = qs_get_next_attr(doc,attr)) {
2126     char* nm  = qs_get_attr_name(doc,attr);
2127     char* val = qs_get_attr_value(doc,attr);
2128
2129     if ((*nm == 's' || *nm == 'S') && strcasecmp(nm, "selected") == 0) {
2130       /*----------------------------------------------------------------------*/
2131       /* CHTML 1.0 version 2.0                                                */
2132       /*----------------------------------------------------------------------*/
2133       selected = apr_pstrdup(r->pool, val);
2134     }
2135     else
2136     if ((*nm == 'v' || *nm == 'V') && strcasecmp(nm, "value") == 0) {
2137       /*----------------------------------------------------------------------*/
2138       /* CHTML 1.0 version 2.0                                                */
2139       /*----------------------------------------------------------------------*/
2140       value = apr_pstrdup(r->pool, val);
2141     }
2142   }
2143
2144   if (value) 
2145     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " value=\"",value,"\"", NULL);
2146   else
2147     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " value=\"\"", NULL);
2148
2149   if (selected)
2150     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " selected ", NULL);
2151
2152   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2153
2154   return jhtml->out;
2155 }
2156
2157
2158 /**
2159  * It is a handler who processes the OPTION tag.
2160  *
2161  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2162  *                     destination is specified.
2163  * @param node   [i]   The OPTION tag node is specified.
2164  * @return The conversion result is returned.
2165  */
2166 static char*
2167 s_jhtml_end_option_tag(void* pdoc, Node* child)
2168 {
2169   jhtml_t*  jhtml = GET_JHTML(pdoc);
2170
2171   /* Don't close */
2172
2173   return jhtml->out;
2174 }
2175
2176
2177 /**
2178  * It is a handler who processes the DIV tag.
2179  *
2180  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2181  *                     destination is specified.
2182  * @param node   [i]   The DIV tag node is specified.
2183  * @return The conversion result is returned.
2184  */
2185 static char*
2186 s_jhtml_start_div_tag(void* pdoc, Node* child)
2187 {
2188   jhtml_t*     jhtml = GET_JHTML(pdoc);
2189   Doc*         doc   = jhtml->doc;
2190   request_rec* r     = doc->r;
2191   Attr*        attr;
2192
2193   char* align   = NULL;
2194
2195   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<div", NULL);
2196   for (attr = qs_get_attr(doc,child);
2197        attr;
2198        attr = qs_get_next_attr(doc,attr)) {
2199     char* nm  = qs_get_attr_name(doc,attr);
2200     char* val = qs_get_attr_value(doc,attr);
2201
2202     if ((*nm == 'a' || *nm == 'A') && strcasecmp(nm, "align") == 0) {
2203       /*----------------------------------------------------------------------*/
2204       /* CHTML 1.0 (W3C version 3.2)                                          */
2205       /*----------------------------------------------------------------------*/
2206       align = apr_pstrdup(r->pool, val);
2207     }
2208   }
2209
2210   if (align)
2211     jhtml->out = apr_pstrcat(r->pool, 
2212                     jhtml->out, " align=\"", align, "\"", NULL);
2213
2214   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2215
2216   return jhtml->out;
2217 }
2218
2219
2220 /**
2221  * It is a handler who processes the DIV tag.
2222  *
2223  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2224  *                     destination is specified.
2225  * @param node   [i]   The DIV tag node is specified.
2226  * @return The conversion result is returned.
2227  */
2228 static char*
2229 s_jhtml_end_div_tag(void* pdoc, Node* child)
2230 {
2231   jhtml_t*     jhtml = GET_JHTML(pdoc);
2232   Doc*         doc   = jhtml->doc;
2233   request_rec* r     = doc->r;
2234
2235   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</div>\n", NULL);
2236
2237   return jhtml->out;
2238 }
2239
2240
2241 static char*
2242 chxj_istyle_to_mode(request_rec* r, const char* s)
2243 {
2244   char* tmp;
2245
2246   if (s) {
2247     switch (s[0]) {
2248     case '1': return apr_psprintf(r->pool, "hiragana");
2249     case '2': return apr_psprintf(r->pool, "hankakukana");
2250     case '3': return apr_psprintf(r->pool, "alphabet");
2251     case '4': return apr_psprintf(r->pool, "numeric");
2252     default: 
2253       tmp = apr_palloc(r->pool, 1);
2254       tmp[0] = '\0';
2255       return apr_pstrdup(r->pool, tmp);
2256     }
2257   }
2258
2259   tmp = apr_palloc(r->pool, 1);
2260   tmp[0] = '\0';
2261   return apr_pstrdup(r->pool,tmp);
2262 }
2263
2264
2265 static char*
2266 s_jhtml_chxjif_tag(void* pdoc, Node* node)
2267 {
2268   jhtml_t*     jhtml = GET_JHTML(pdoc);
2269   Doc*         doc   = jhtml->doc;
2270   Node*        child;
2271   request_rec* r     = doc->r;
2272
2273   for (child = qs_get_child_node(doc, node);
2274        child;
2275        child = qs_get_next_node(doc, child)) {
2276     jhtml->out = apr_pstrcat(r->pool, jhtml->out, child->otext, NULL);
2277     s_jhtml_chxjif_tag(jhtml, child);
2278   }
2279   return NULL;
2280 }
2281
2282
2283 /**
2284  * It is a handler who processes the TEXTARE tag.
2285  *
2286  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2287  *                     destination is specified.
2288  * @param node   [i]   The TEXTAREA tag node is specified.
2289  * @return The conversion result is returned.
2290  */
2291 static char*
2292 s_jhtml_start_textarea_tag(void* pdoc, Node* node) 
2293 {
2294   jhtml_t*      jhtml = GET_JHTML(pdoc);
2295   Doc*          doc   = jhtml->doc;
2296   request_rec*  r     = doc->r;
2297   Attr*         attr;
2298
2299   jhtml->textarea_flag++;
2300   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<textarea ", NULL);
2301
2302   for (attr = qs_get_attr(doc,node);
2303        attr;
2304        attr = qs_get_next_attr(doc,attr)) {
2305
2306     char* name  = qs_get_attr_name(doc,attr);
2307     char* value = qs_get_attr_value(doc,attr);
2308
2309     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0) {
2310       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " name=\"",value,"\"", NULL);
2311     }
2312     else 
2313     if ((*name == 'r' || *name == 'R') && strcasecmp(name, "rows") == 0) {
2314       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " rows=\"",value,"\"", NULL);
2315     }
2316     else 
2317     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "cols") == 0) {
2318       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " cols=\"",value,"\"", NULL);
2319     }
2320   }
2321
2322   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">\r\n", NULL);
2323
2324   return jhtml->out;
2325 }
2326
2327
2328 /**
2329  * It is a handler who processes the TEXTAREA tag.
2330  *
2331  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2332  *                     destination is specified.
2333  * @param node   [i]   The TEXTAREA tag node is specified.
2334  * @return The conversion result is returned.
2335  */
2336 static char*
2337 s_jhtml_end_textarea_tag(void* pdoc, Node* child) 
2338 {
2339   jhtml_t*      jhtml = GET_JHTML(pdoc);
2340   Doc*          doc   = jhtml->doc;
2341   request_rec*  r     = doc->r;
2342
2343   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</textarea>\r\n", NULL);
2344   jhtml->textarea_flag--;
2345
2346   return jhtml->out;
2347 }
2348
2349 /**
2350  * It is a handler who processes the B tag.
2351  *
2352  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2353  *                     destination is specified.
2354  * @param node   [i]   The B tag node is specified.
2355  * @return The conversion result is returned.
2356  */
2357 static char*
2358 s_jhtml_start_b_tag(void* pdoc, Node* node) 
2359 {
2360   jhtml_t*      jhtml = GET_JHTML(pdoc);
2361   Doc*          doc   = jhtml->doc;
2362   request_rec*  r     = doc->r;
2363
2364   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<b>", NULL);
2365
2366   return jhtml->out;
2367 }
2368
2369
2370 /**
2371  * It is a handler who processes the B tag.
2372  *
2373  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2374  *                     destination is specified.
2375  * @param node   [i]   The B tag node is specified.
2376  * @return The conversion result is returned.
2377  */
2378 static char*
2379 s_jhtml_end_b_tag(void* pdoc, Node* child) 
2380 {
2381   jhtml_t*      jhtml = GET_JHTML(pdoc);
2382   Doc*          doc   = jhtml->doc;
2383   request_rec*  r     = doc->r;
2384
2385   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</b>\r\n", NULL);
2386
2387   return jhtml->out;
2388 }
2389
2390 static char*
2391 s_jhtml_text_tag(void* pdoc, Node* child)
2392 {
2393   jhtml_t*     jhtml = GET_JHTML(pdoc);
2394   Doc*         doc = jhtml->doc;
2395   char*        textval;
2396   char*        tmp;
2397   char*        tdst;
2398   char         one_byte[2];
2399   int          ii;
2400   int          tdst_len;
2401   request_rec* r = doc->r;
2402
2403   textval = qs_get_node_value(doc,child);
2404   textval = qs_trim_string(jhtml->doc->r, textval);
2405   if (strlen(textval) == 0)
2406     return jhtml->out;
2407
2408   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2409   memset(tmp, 0, qs_get_node_size(doc,child)+1);
2410
2411   tdst     = qs_alloc_zero_byte_string(r);
2412   memset(one_byte, 0, sizeof(one_byte));
2413   tdst_len = 0;
2414
2415   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2416     char* out;
2417     int rtn = s_jhtml_search_emoji(jhtml, &textval[ii], &out);
2418     if (rtn) {
2419       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2420       ii+=(rtn - 1);
2421       continue;
2422     }
2423
2424     if (is_sjis_kanji(textval[ii])) {
2425       one_byte[0] = textval[ii+0];
2426       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2427       one_byte[0] = textval[ii+1];
2428       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2429       ii++;
2430     }
2431     else 
2432     if (jhtml->pre_flag) {
2433       one_byte[0] = textval[ii+0];
2434       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2435     }
2436     else
2437     if (jhtml->textarea_flag) {
2438       one_byte[0] = textval[ii+0];
2439       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2440     }
2441     else {
2442       if (textval[ii] != '\r' && textval[ii] != '\n') {
2443         one_byte[0] = textval[ii+0];
2444         tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2445       }
2446     }
2447   }
2448   jhtml->out = apr_pstrcat(r->pool, jhtml->out, tdst, NULL);
2449
2450   return jhtml->out;
2451 }
2452 /*
2453  * vim:ts=2 et
2454  */