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;
1302   request_rec* r;
1303
1304   jhtml = GET_JHTML(pdoc);
1305   r     = jhtml->doc->r;
1306
1307   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</font>", NULL);
1308
1309   return jhtml->out;
1310 }
1311
1312
1313 /**
1314  * It is a handler who processes the FORM tag.
1315  *
1316  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1317  *                     destination is specified.
1318  * @param node   [i]   The FORM tag node is specified.
1319  * @return The conversion result is returned.
1320  */
1321 static char*
1322 s_jhtml_start_form_tag(void* pdoc, Node* node) 
1323 {
1324   jhtml_t*     jhtml;
1325   Doc*         doc;
1326   request_rec* r;
1327   Attr*        attr;
1328
1329   jhtml = GET_JHTML(pdoc);
1330   doc   = jhtml->doc;
1331   r     = doc->r;
1332
1333   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<form", NULL);
1334
1335   /*--------------------------------------------------------------------------*/
1336   /* Get Attributes                                                           */
1337   /*--------------------------------------------------------------------------*/
1338   for (attr = qs_get_attr(doc,node);
1339        attr;
1340        attr = qs_get_next_attr(doc,attr)) {
1341
1342     char* name;
1343     char* value;
1344
1345     name  = qs_get_attr_name(doc,attr);
1346     value = qs_get_attr_value(doc,attr);
1347
1348     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "action") == 0) {
1349       /*----------------------------------------------------------------------*/
1350       /* CHTML 1.0                                                            */
1351       /*----------------------------------------------------------------------*/
1352       jhtml->out = apr_pstrcat(r->pool, 
1353                                jhtml->out, 
1354                                " action=\"",
1355                                value,
1356                                "\"", 
1357                                NULL);
1358     }
1359     else
1360     if ((*name == 'm' || *name == 'M') && strcasecmp(name, "method") == 0) {
1361       /*----------------------------------------------------------------------*/
1362       /* CHTML 1.0                                                            */
1363       /*----------------------------------------------------------------------*/
1364       jhtml->out = apr_pstrcat(r->pool, 
1365                                jhtml->out, 
1366                                " method=\"",
1367                                value,
1368                                "\"", 
1369                                NULL);
1370     }
1371     else
1372     if ((*name == 'u' || *name == 'U') && strcasecmp(name, "utn") == 0) {
1373       /*----------------------------------------------------------------------*/
1374       /* CHTML 3.0                                                            */
1375       /* It is special only for CHTML.                                        */
1376       /*----------------------------------------------------------------------*/
1377       jhtml->out = apr_pstrcat(r->pool, 
1378                       jhtml->out, 
1379                       " utn ", 
1380                       NULL);
1381     }
1382   }
1383
1384   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
1385
1386   if (jhtml->cookie && jhtml->cookie->cookie_id) {
1387     jhtml->out = apr_psprintf(r->pool, "%s<input type='hidden' name='%s' value='%s'>",
1388                              jhtml->out, 
1389                              CHXJ_COOKIE_PARAM,
1390                              jhtml->cookie->cookie_id);
1391   }
1392
1393   return jhtml->out;
1394 }
1395
1396
1397 /**
1398  * It is a handler who processes the FORM tag.
1399  *
1400  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1401  *                     destination is specified.
1402  * @param node   [i]   The FORM tag node is specified.
1403  * @return The conversion result is returned.
1404  */
1405 static char*
1406 s_jhtml_end_form_tag(void* pdoc, Node* child) 
1407 {
1408   jhtml_t*     jhtml = GET_JHTML(pdoc);
1409   Doc*         doc   = jhtml->doc;
1410   request_rec* r     = doc->r;
1411
1412   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</form>", NULL);
1413
1414   return jhtml->out;
1415 }
1416
1417
1418 /**
1419  * It is a handler who processes the INPUT tag.
1420  *
1421  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1422  *                     destination is specified.
1423  * @param node   [i]   The INPUT tag node is specified.
1424  * @return The conversion result is returned.
1425  */
1426 static char*
1427 s_jhtml_start_input_tag(void* pdoc, Node* node) 
1428 {
1429   jhtml_t*      jhtml;
1430   Doc*          doc;
1431   request_rec*  r;
1432   char*         max_length;
1433   char*         type;
1434   char*         name;
1435   char*         value;
1436   char*         istyle;
1437   char*         size;
1438   char*         checked;
1439   char*         accesskey;
1440
1441   jhtml       = GET_JHTML(pdoc);
1442   doc         = jhtml->doc;
1443   r           = doc->r;
1444   max_length  = NULL;
1445   type        = NULL;
1446   name        = NULL;
1447   value       = NULL;
1448   istyle      = NULL;
1449   size        = NULL;
1450   checked     = NULL;
1451   accesskey   = NULL;
1452
1453   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<input", NULL);
1454
1455   /*--------------------------------------------------------------------------*/
1456   /* Get Attributes                                                           */
1457   /*--------------------------------------------------------------------------*/
1458
1459   type       = qs_get_type_attr(doc, node, r);
1460   name       = qs_get_name_attr(doc, node, r);
1461   value      = qs_get_value_attr(doc,node,r);
1462   istyle     = qs_get_istyle_attr(doc,node,r);
1463   max_length = qs_get_maxlength_attr(doc,node,r);
1464   checked    = qs_get_checked_attr(doc,node,r);
1465   accesskey  = qs_get_accesskey_attr(doc, node, r);
1466   size       = qs_get_size_attr(doc, node, r);
1467
1468   if (type) {
1469     jhtml->out = apr_pstrcat(r->pool,
1470                     jhtml->out, 
1471                     " type=\"", 
1472                     type, 
1473                     "\" ", 
1474                     NULL);
1475   }
1476   if (size) {
1477     jhtml->out = apr_pstrcat(r->pool, 
1478                     jhtml->out, 
1479                     " size=\"", 
1480                     size, 
1481                     "\" ", 
1482                     NULL);
1483   }
1484   if (name) {
1485     jhtml->out = apr_pstrcat(r->pool, 
1486                     jhtml->out, 
1487                     " name=\"", 
1488                     name, 
1489                     "\" ", 
1490                     NULL);
1491   }
1492   if (value) {
1493     jhtml->out = apr_pstrcat(r->pool, 
1494                     jhtml->out, 
1495                     " value=\"", 
1496                     value, 
1497                     "\" ", 
1498                     NULL);
1499   }
1500   if (accesskey) {
1501     jhtml->out = apr_pstrcat(r->pool, 
1502                     jhtml->out, 
1503                     " accesskey=\"", 
1504                     accesskey, "\" ", 
1505                     NULL);
1506   }
1507   if (istyle) {
1508     /*------------------------------------------------------------------------*/
1509     /* CHTML 2.0                                                              */
1510     /*------------------------------------------------------------------------*/
1511     if (type && (*type == 'p' || *type == 'P') && strcasecmp(type, "password") == 0
1512     && ! jhtml->entryp->pc_flag ) {
1513       jhtml->out = apr_pstrcat(r->pool, 
1514                                jhtml->out, 
1515                                " mode=\"", 
1516                                "numeric", 
1517                                "\" ", 
1518                                NULL);
1519     }
1520     else {
1521       jhtml->out = apr_pstrcat(r->pool, 
1522                                jhtml->out, 
1523                                " mode=\"", 
1524                                chxj_istyle_to_mode(r,istyle), 
1525                                "\" ", 
1526                                NULL);
1527     }
1528   }
1529   else
1530   if (istyle == NULL && type != NULL && strcasecmp(type, "password") == 0) {
1531     jhtml->out = apr_pstrcat(r->pool, 
1532                              jhtml->out, 
1533                              " mode=\"", 
1534                              "numeric", 
1535                              "\" ", 
1536                              NULL);
1537   }
1538   /*--------------------------------------------------------------------------*/
1539   /* The figure is default for the password.                                  */
1540   /*--------------------------------------------------------------------------*/
1541   if (max_length) {
1542     jhtml->out = apr_pstrcat(r->pool, 
1543                              jhtml->out, 
1544                              " maxlength=\"", 
1545                              max_length, 
1546                              "\"", 
1547                              NULL);
1548   }
1549
1550   if (checked) {
1551     jhtml->out = apr_pstrcat(r->pool, 
1552                              jhtml->out,
1553                              " checked ",
1554                              NULL);
1555   }
1556
1557   jhtml->out = apr_pstrcat(r->pool, jhtml->out, " >", NULL);
1558
1559   return jhtml->out;
1560 }
1561
1562
1563 /**
1564  * It is a handler who processes the INPUT tag.
1565  *
1566  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1567  *                     destination is specified.
1568  * @param node   [i]   The INPUT tag node is specified.
1569  * @return The conversion result is returned.
1570  */
1571 static char*
1572 s_jhtml_end_input_tag(void* pdoc, Node* child) 
1573 {
1574   jhtml_t*  jhtml = GET_JHTML(pdoc);
1575
1576   return jhtml->out;
1577 }
1578
1579
1580 /**
1581  * It is a handler who processes the CENTER tag.
1582  *
1583  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1584  *                     destination is specified.
1585  * @param node   [i]   The CENTER tag node is specified.
1586  * @return The conversion result is returned.
1587  */
1588 static char*
1589 s_jhtml_start_center_tag(void* pdoc, Node* node) 
1590 {
1591   jhtml_t*      jhtml = GET_JHTML(pdoc);
1592   Doc*          doc   = jhtml->doc;
1593   request_rec*  r     = doc->r;
1594
1595   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<center>", NULL);
1596
1597   return jhtml->out;
1598 }
1599
1600
1601 /**
1602  * It is a handler who processes the CENTER tag.
1603  *
1604  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1605  *                     destination is specified.
1606  * @param node   [i]   The CENTER tag node is specified.
1607  * @return The conversion result is returned.
1608  */
1609 static char*
1610 s_jhtml_end_center_tag(void* pdoc, Node* child) 
1611 {
1612   jhtml_t*      jhtml;
1613   Doc*          doc;
1614   request_rec*  r;
1615
1616   jhtml = GET_JHTML(pdoc);
1617   doc   = jhtml->doc;
1618   r     = doc->r;
1619
1620   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</center>", NULL);
1621
1622   return jhtml->out;
1623 }
1624
1625
1626 /**
1627  * It is a handler who processes the li tag.
1628  *
1629  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1630  *                     destination is specified.
1631  * @param node   [i]   The li tag node is specified.
1632  * @return The conversion result is returned.
1633  */
1634 static char*
1635 s_jhtml_start_li_tag(void* pdoc, Node* node) 
1636 {
1637   jhtml_t*      jhtml;
1638   Doc*          doc;
1639   request_rec*  r;
1640
1641   jhtml = GET_JHTML(pdoc);
1642   doc   = jhtml->doc;
1643   r     = doc->r;
1644
1645   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<li>", NULL);
1646
1647   return jhtml->out;
1648 }
1649
1650
1651 /**
1652  * It is a handler who processes the li tag.
1653  *
1654  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1655  *                     destination is specified.
1656  * @param node   [i]   The li tag node is specified.
1657  * @return The conversion result is returned.
1658  */
1659 static char*
1660 s_jhtml_end_li_tag(void* pdoc, Node* child) 
1661 {
1662   jhtml_t*      jhtml;
1663   Doc*          doc;
1664   request_rec*  r;
1665
1666   jhtml = GET_JHTML(pdoc);
1667   doc   = jhtml->doc;
1668   r     = doc->r;
1669
1670   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</li>", NULL);
1671
1672   return jhtml->out;
1673 }
1674
1675
1676 /**
1677  * It is a handler who processes the OL tag.
1678  *
1679  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1680  *                     destination is specified.
1681  * @param node   [i]   The OL tag node is specified.
1682  * @return The conversion result is returned.
1683  */
1684 static char*
1685 s_jhtml_start_ol_tag(void* pdoc, Node* node) 
1686 {
1687   jhtml_t*      jhtml;
1688   Doc*          doc;
1689   request_rec*  r;
1690
1691   jhtml = GET_JHTML(pdoc);
1692   doc   = jhtml->doc;
1693   r     = doc->r;
1694
1695   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<ol>", NULL);
1696
1697   return jhtml->out;
1698 }
1699
1700
1701 /**
1702  * It is a handler who processes the OL tag.
1703  *
1704  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1705  *                     destination is specified.
1706  * @param node   [i]   The OL tag node is specified.
1707  * @return The conversion result is returned.
1708  */
1709 static char*
1710 s_jhtml_end_ol_tag(void* pdoc, Node* child) 
1711 {
1712   jhtml_t*      jhtml;
1713   Doc*          doc;
1714   request_rec*  r;
1715
1716   jhtml = GET_JHTML(pdoc);
1717   doc   = jhtml->doc;
1718   r     = doc->r;
1719
1720   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</ol>", NULL);
1721
1722   return jhtml->out;
1723 }
1724
1725
1726 /**
1727  * It is a handler who processes the P tag.
1728  *
1729  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1730  *                     destination is specified.
1731  * @param node   [i]   The P tag node is specified.
1732  * @return The conversion result is returned.
1733  */
1734 static char*
1735 s_jhtml_start_p_tag(void* pdoc, Node* node) 
1736 {
1737   jhtml_t*      jhtml;
1738   Doc*          doc;
1739   request_rec*  r;
1740
1741   jhtml = GET_JHTML(pdoc);
1742   doc   = jhtml->doc;
1743   r     = doc->r;
1744
1745   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<p>", NULL);
1746
1747   return jhtml->out;
1748 }
1749
1750
1751 /**
1752  * It is a handler who processes the P tag.
1753  *
1754  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1755  *                     destination is specified.
1756  * @param node   [i]   The P tag node is specified.
1757  * @return The conversion result is returned.
1758  */
1759 static char*
1760 s_jhtml_end_p_tag(void* pdoc, Node* child) 
1761 {
1762   jhtml_t*      jhtml = GET_JHTML(pdoc);
1763   Doc*          doc   = jhtml->doc;
1764   request_rec*  r     = doc->r;
1765
1766   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</p>", NULL);
1767
1768   return jhtml->out;
1769 }
1770
1771
1772 /**
1773  * It is a handler who processes the PRE tag.
1774  *
1775  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1776  *                     destination is specified.
1777  * @param node   [i]   The PRE tag node is specified.
1778  * @return The conversion result is returned.
1779  */
1780 static char*
1781 s_jhtml_start_pre_tag(void* pdoc, Node* node) 
1782 {
1783   jhtml_t*      jhtml = GET_JHTML(pdoc);
1784   Doc*          doc   = jhtml->doc;
1785   request_rec*  r     = doc->r;
1786
1787   jhtml->pre_flag++;
1788   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<pre>", NULL);
1789
1790   return jhtml->out;
1791 }
1792
1793
1794 /**
1795  * It is a handler who processes the PRE tag.
1796  *
1797  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1798  *                     destination is specified.
1799  * @param node   [i]   The PRE tag node is specified.
1800  * @return The conversion result is returned.
1801  */
1802 static char*
1803 s_jhtml_end_pre_tag(void* pdoc, Node* child) 
1804 {
1805   jhtml_t*      jhtml = GET_JHTML(pdoc);
1806   Doc*          doc   = jhtml->doc;
1807   request_rec*  r     = doc->r;
1808
1809   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</pre>", NULL);
1810   jhtml->pre_flag--;
1811
1812   return jhtml->out;
1813 }
1814
1815
1816 /**
1817  * It is a handler who processes the UL tag.
1818  *
1819  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1820  *                     destination is specified.
1821  * @param node   [i]   The UL tag node is specified.
1822  * @return The conversion result is returned.
1823  */
1824 static char*
1825 s_jhtml_start_ul_tag(void* pdoc, Node* node) 
1826 {
1827   jhtml_t*      jhtml = GET_JHTML(pdoc);
1828   Doc*          doc   = jhtml->doc;
1829   request_rec*  r     = doc->r;
1830
1831   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<ul>", NULL);
1832
1833   return jhtml->out;
1834 }
1835
1836
1837 /**
1838  * It is a handler who processes the UL tag.
1839  *
1840  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1841  *                     destination is specified.
1842  * @param node   [i]   The UL tag node is specified.
1843  * @return The conversion result is returned.
1844  */
1845 static char*
1846 s_jhtml_end_ul_tag(void* pdoc, Node* child) 
1847 {
1848   jhtml_t*      jhtml = GET_JHTML(pdoc);
1849   Doc*          doc   = jhtml->doc;
1850   request_rec*  r     = doc->r;
1851
1852   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</ul>", NULL);
1853
1854   return jhtml->out;
1855 }
1856
1857
1858 /**
1859  * It is a handler who processes the HR tag.
1860  *
1861  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1862  *                     destination is specified.
1863  * @param node   [i]   The HR tag node is specified.
1864  * @return The conversion result is returned.
1865  */
1866 static char*
1867 s_jhtml_start_hr_tag(void* pdoc, Node* node) 
1868 {
1869   jhtml_t*     jhtml = GET_JHTML(pdoc);
1870   Doc*         doc   = jhtml->doc;
1871   request_rec* r     = doc->r;
1872   Attr*        attr;
1873
1874   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<hr ", NULL);
1875  
1876   for (attr = qs_get_attr(doc,node);
1877        attr; 
1878        attr = qs_get_next_attr(doc,attr)) {
1879     char* name = qs_get_attr_name(doc,attr);
1880     char* value = qs_get_attr_value(doc,attr);
1881     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align") == 0) {
1882       /*----------------------------------------------------------------------*/
1883       /* CHTML 1.0                                                            */
1884       /*----------------------------------------------------------------------*/
1885       jhtml->out = apr_pstrcat(r->pool,
1886                         jhtml->out, 
1887                         " align=\"", value, "\" ", NULL);
1888     }
1889     else
1890     if ((*name == 's' || *name == 'S') && strcasecmp(name, "size") == 0) {
1891       /*----------------------------------------------------------------------*/
1892       /* CHTML 1.0                                                            */
1893       /*----------------------------------------------------------------------*/
1894       jhtml->out = apr_pstrcat(r->pool,
1895                         jhtml->out, 
1896                         " size=\"", value, "\" ", NULL);
1897     }
1898     else
1899     if ((*name == 'w' || *name == 'W') && strcasecmp(name, "width") == 0) {
1900       /*----------------------------------------------------------------------*/
1901       /* CHTML 1.0                                                            */
1902       /*----------------------------------------------------------------------*/
1903       jhtml->out = apr_pstrcat(r->pool,
1904                         jhtml->out, 
1905                         " width=\"", value, "\" ", NULL);
1906     }
1907     else
1908     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "noshade") == 0) {
1909       /*----------------------------------------------------------------------*/
1910       /* CHTML 1.0                                                            */
1911       /*----------------------------------------------------------------------*/
1912       jhtml->out = apr_pstrcat(r->pool,
1913                         jhtml->out, 
1914                         " noshade ", NULL);
1915     }
1916     else
1917     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "color") == 0) {
1918       /*----------------------------------------------------------------------*/
1919       /* CHTML 4.0                                                            */
1920       /*----------------------------------------------------------------------*/
1921       /* ignore */
1922     }
1923   }
1924   jhtml->out = apr_pstrcat(r->pool, jhtml->out, " >", NULL);
1925
1926   return jhtml->out;
1927 }
1928
1929
1930 /**
1931  * It is a handler who processes the HR tag.
1932  *
1933  * @param jhtml  [i/o] The pointer to the CHTML structure at the output
1934  *                     destination is specified.
1935  * @param node   [i]   The HR tag node is specified.
1936  * @return The conversion result is returned.
1937  */
1938 static char*
1939 s_jhtml_end_hr_tag(void* pdoc, Node* child) 
1940 {
1941   jhtml_t* jhtml = GET_JHTML(pdoc);
1942
1943   return jhtml->out;
1944 }
1945
1946
1947 /**
1948  * It is a handler who processes the IMG tag.
1949  *
1950  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1951  *                     destination is specified.
1952  * @param node   [i]   The IMG tag node is specified.
1953  * @return The conversion result is returned.
1954  */
1955 static char*
1956 s_jhtml_start_img_tag(void* pdoc, Node* node) 
1957 {
1958   jhtml_t*      jhtml = GET_JHTML(pdoc);
1959   Doc*          doc   = jhtml->doc;
1960   request_rec*  r     = doc->r;
1961   Attr*         attr;
1962 #ifndef IMG_NOT_CONVERT_FILENAME
1963   device_table* spec = jhtml->spec;
1964 #endif
1965
1966   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<img", NULL);
1967  
1968
1969   /*--------------------------------------------------------------------------*/
1970   /* Get Attributes                                                           */
1971   /*--------------------------------------------------------------------------*/
1972   for (attr = qs_get_attr(doc,node);
1973        attr;
1974        attr = qs_get_next_attr(doc,attr)) {
1975     char* name  = qs_get_attr_name(doc,attr);
1976     char* value = qs_get_attr_value(doc,attr);
1977
1978     if ((*name == 's' || *name == 'S') && strcasecmp(name, "src") == 0) {
1979       /*----------------------------------------------------------------------*/
1980       /* CHTML 1.0                                                            */
1981       /*----------------------------------------------------------------------*/
1982 #ifdef IMG_NOT_CONVERT_FILENAME
1983       value = chxj_encoding_parameter(r, value);
1984       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1985       jhtml->out = apr_pstrcat(r->pool, 
1986                       jhtml->out, " src=\"",value,"\"", NULL);
1987 #else
1988       value = chxj_img_conv(r, spec, value);
1989       value = chxj_encoding_parameter(r, value);
1990       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1991       jhtml->out = apr_pstrcat(r->pool, 
1992                       jhtml->out, " src=\"", value, NULL);
1993       jhtml->out = apr_pstrcat(r->pool, jhtml->out, "\"", NULL);
1994 #endif
1995     }
1996     else
1997     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align" ) == 0) {
1998       /*----------------------------------------------------------------------*/
1999       /* CHTML 1.0                                                            */
2000       /*----------------------------------------------------------------------*/
2001       jhtml->out = apr_pstrcat(r->pool, 
2002                       jhtml->out, " align=\"",value,"\"", NULL);
2003     }
2004     else
2005     if ((*name == 'w' || *name == 'W') && strcasecmp(name, "width" ) == 0) {
2006       /*----------------------------------------------------------------------*/
2007       /* CHTML 1.0                                                            */
2008       /*----------------------------------------------------------------------*/
2009       jhtml->out = apr_pstrcat(r->pool, 
2010                       jhtml->out, " width=\"",value,"\"", NULL);
2011     }
2012     else
2013     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "height") == 0) {
2014       /*----------------------------------------------------------------------*/
2015       /* CHTML 1.0                                                            */
2016       /*----------------------------------------------------------------------*/
2017       jhtml->out = apr_pstrcat(r->pool, 
2018                       jhtml->out, " height=\"",value,"\"", NULL);
2019     }
2020     else
2021     if ((*name == 'h' || *name == 'H') && strcasecmp(name, "hspace") == 0) {
2022       /*----------------------------------------------------------------------*/
2023       /* CHTML 1.0                                                            */
2024       /*----------------------------------------------------------------------*/
2025       jhtml->out = apr_pstrcat(r->pool, 
2026                       jhtml->out, " hspace=\"",value,"\"", NULL);
2027     }
2028     else
2029     if ((*name == 'v' || *name == 'V') && strcasecmp(name, "vspace") == 0) {
2030       /*----------------------------------------------------------------------*/
2031       /* CHTML 1.0                                                            */
2032       /*----------------------------------------------------------------------*/
2033       jhtml->out = apr_pstrcat(r->pool, 
2034                       jhtml->out, " vspace=\"",value,"\"", NULL);
2035     }
2036     else
2037     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "alt"   ) == 0) {
2038       /*----------------------------------------------------------------------*/
2039       /* CHTML 1.0                                                            */
2040       /*----------------------------------------------------------------------*/
2041       jhtml->out = apr_pstrcat(r->pool, 
2042                       jhtml->out, " alt=\"",value,"\"", NULL);
2043     }
2044     else
2045     if ((*name == 'a' || *name == 'A') && strcasecmp(name, "align" ) == 0) {
2046       /*----------------------------------------------------------------------*/
2047       /* CHTML 4.0                                                            */
2048       /*----------------------------------------------------------------------*/
2049       /* ignore */
2050     }
2051   }
2052
2053   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2054
2055   return jhtml->out;
2056 }
2057
2058
2059 /**
2060  * It is a handler who processes the IMG tag.
2061  *
2062  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2063  *                     destination is specified.
2064  * @param node   [i]   The IMG tag node is specified.
2065  * @return The conversion result is returned.
2066  */
2067 static char*
2068 s_jhtml_end_img_tag(void* pdoc, Node* child) 
2069 {
2070   jhtml_t*  jhtml = GET_JHTML(pdoc);
2071
2072   return jhtml->out;
2073 }
2074
2075
2076 /**
2077  * It is a handler who processes the SELECT tag.
2078  *
2079  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2080  *                     destination is specified.
2081  * @param node   [i]   The SELECT tag node is specified.
2082  * @return The conversion result is returned.
2083  */
2084 static char*
2085 s_jhtml_start_select_tag(void* pdoc, Node* child)
2086 {
2087   jhtml_t*     jhtml = GET_JHTML(pdoc);
2088   Doc*         doc   = jhtml->doc;
2089   request_rec* r     = doc->r;
2090   Attr*        attr;
2091
2092   char* size      = NULL;
2093   char* name      = NULL;
2094
2095   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<select", NULL);
2096   for (attr = qs_get_attr(doc,child);
2097        attr;
2098        attr = qs_get_next_attr(doc,attr)) {
2099     char* nm  = qs_get_attr_name(doc,attr);
2100     char* val = qs_get_attr_value(doc,attr);
2101
2102     if ((*name == 's' || *name == 'S') && strcasecmp(nm, "size") == 0) {
2103       /*----------------------------------------------------------------------*/
2104       /* CHTML 1.0 version 2.0                                                */
2105       /*----------------------------------------------------------------------*/
2106       size = apr_pstrdup(r->pool, val);
2107     }
2108     else
2109     if ((*name == 'n' || *name == 'N') && strcasecmp(nm, "name") == 0) {
2110       /*----------------------------------------------------------------------*/
2111       /* CHTML 1.0 version 2.0                                                */
2112       /*----------------------------------------------------------------------*/
2113       name = apr_pstrdup(r->pool, val);
2114     }
2115     else
2116     if ((*name == 'm' || *name == 'M') && strcasecmp(nm, "multiple") == 0) {
2117       /*----------------------------------------------------------------------*/
2118       /* CHTML 1.0 version 2.0                                                */
2119       /*----------------------------------------------------------------------*/
2120       /* not support */
2121     }
2122   }
2123
2124   if (size)
2125     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " size=\"",size,"\"", NULL);
2126
2127   if (name)
2128     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " name=\"",name,"\"", NULL);
2129
2130   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">\n", NULL);
2131
2132   return jhtml->out;
2133 }
2134
2135 /**
2136  * It is a handler who processes the SELECT tag.
2137  *
2138  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2139  *                     destination is specified.
2140  * @param node   [i]   The SELECT tag node is specified.
2141  * @return The conversion result is returned.
2142  */
2143 static char*
2144 s_jhtml_end_select_tag(void* pdoc, Node* child)
2145 {
2146   jhtml_t*     jhtml = GET_JHTML(pdoc);
2147   Doc*         doc   = jhtml->doc;
2148   request_rec* r     = doc->r;
2149
2150   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</select>\n", NULL);
2151
2152   return jhtml->out;
2153 }
2154
2155 /**
2156  * It is a handler who processes the OPTION tag.
2157  *
2158  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2159  *                     destination is specified.
2160  * @param node   [i]   The OPTION tag node is specified.
2161  * @return The conversion result is returned.
2162  */
2163 static char*
2164 s_jhtml_start_option_tag(void* pdoc, Node* child)
2165 {
2166   jhtml_t*     jhtml = GET_JHTML(pdoc);
2167   Doc*         doc   = jhtml->doc;
2168   request_rec* r     = doc->r;
2169   Attr*        attr;
2170
2171   char* selected   = NULL;
2172   char* value      = NULL;
2173
2174   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<option", NULL);
2175   for (attr = qs_get_attr(doc,child);
2176        attr;
2177        attr = qs_get_next_attr(doc,attr)) {
2178     char* nm  = qs_get_attr_name(doc,attr);
2179     char* val = qs_get_attr_value(doc,attr);
2180
2181     if ((*nm == 's' || *nm == 'S') && strcasecmp(nm, "selected") == 0) {
2182       /*----------------------------------------------------------------------*/
2183       /* CHTML 1.0 version 2.0                                                */
2184       /*----------------------------------------------------------------------*/
2185       selected = apr_pstrdup(r->pool, val);
2186     }
2187     else
2188     if ((*nm == 'v' || *nm == 'V') && strcasecmp(nm, "value") == 0) {
2189       /*----------------------------------------------------------------------*/
2190       /* CHTML 1.0 version 2.0                                                */
2191       /*----------------------------------------------------------------------*/
2192       value = apr_pstrdup(r->pool, val);
2193     }
2194   }
2195
2196   if (value) 
2197     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " value=\"",value,"\"", NULL);
2198   else
2199     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " value=\"\"", NULL);
2200
2201   if (selected)
2202     jhtml->out = apr_pstrcat(r->pool, jhtml->out, " selected ", NULL);
2203
2204   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2205
2206   return jhtml->out;
2207 }
2208
2209
2210 /**
2211  * It is a handler who processes the OPTION tag.
2212  *
2213  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2214  *                     destination is specified.
2215  * @param node   [i]   The OPTION tag node is specified.
2216  * @return The conversion result is returned.
2217  */
2218 static char*
2219 s_jhtml_end_option_tag(void* pdoc, Node* child)
2220 {
2221   jhtml_t*  jhtml = GET_JHTML(pdoc);
2222
2223   /* Don't close */
2224
2225   return jhtml->out;
2226 }
2227
2228
2229 /**
2230  * It is a handler who processes the DIV tag.
2231  *
2232  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2233  *                     destination is specified.
2234  * @param node   [i]   The DIV tag node is specified.
2235  * @return The conversion result is returned.
2236  */
2237 static char*
2238 s_jhtml_start_div_tag(void* pdoc, Node* child)
2239 {
2240   jhtml_t*     jhtml = GET_JHTML(pdoc);
2241   Doc*         doc   = jhtml->doc;
2242   request_rec* r     = doc->r;
2243   Attr*        attr;
2244
2245   char* align   = NULL;
2246
2247   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<div", NULL);
2248   for (attr = qs_get_attr(doc,child);
2249        attr;
2250        attr = qs_get_next_attr(doc,attr)) {
2251     char* nm  = qs_get_attr_name(doc,attr);
2252     char* val = qs_get_attr_value(doc,attr);
2253
2254     if ((*nm == 'a' || *nm == 'A') && strcasecmp(nm, "align") == 0) {
2255       /*----------------------------------------------------------------------*/
2256       /* CHTML 1.0 (W3C version 3.2)                                          */
2257       /*----------------------------------------------------------------------*/
2258       align = apr_pstrdup(r->pool, val);
2259     }
2260   }
2261
2262   if (align)
2263     jhtml->out = apr_pstrcat(r->pool, 
2264                     jhtml->out, " align=\"", align, "\"", NULL);
2265
2266   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">", NULL);
2267
2268   return jhtml->out;
2269 }
2270
2271
2272 /**
2273  * It is a handler who processes the DIV tag.
2274  *
2275  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2276  *                     destination is specified.
2277  * @param node   [i]   The DIV tag node is specified.
2278  * @return The conversion result is returned.
2279  */
2280 static char*
2281 s_jhtml_end_div_tag(void* pdoc, Node* child)
2282 {
2283   jhtml_t*     jhtml = GET_JHTML(pdoc);
2284   Doc*         doc   = jhtml->doc;
2285   request_rec* r     = doc->r;
2286
2287   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</div>\n", NULL);
2288
2289   return jhtml->out;
2290 }
2291
2292
2293 static char*
2294 chxj_istyle_to_mode(request_rec* r, const char* s)
2295 {
2296   char* tmp;
2297
2298   if (s) {
2299     switch (s[0]) {
2300     case '1': return apr_psprintf(r->pool, "hiragana");
2301     case '2': return apr_psprintf(r->pool, "hankakukana");
2302     case '3': return apr_psprintf(r->pool, "alphabet");
2303     case '4': return apr_psprintf(r->pool, "numeric");
2304     default: 
2305       tmp = apr_palloc(r->pool, 1);
2306       tmp[0] = '\0';
2307       return apr_pstrdup(r->pool, tmp);
2308     }
2309   }
2310
2311   tmp = apr_palloc(r->pool, 1);
2312   tmp[0] = '\0';
2313   return apr_pstrdup(r->pool,tmp);
2314 }
2315
2316
2317 static char*
2318 s_jhtml_chxjif_tag(void* pdoc, Node* node)
2319 {
2320   jhtml_t*     jhtml = GET_JHTML(pdoc);
2321   Doc*         doc   = jhtml->doc;
2322   Node*        child;
2323   request_rec* r     = doc->r;
2324
2325   for (child = qs_get_child_node(doc, node);
2326        child;
2327        child = qs_get_next_node(doc, child)) {
2328     jhtml->out = apr_pstrcat(r->pool, jhtml->out, child->otext, NULL);
2329     s_jhtml_chxjif_tag(jhtml, child);
2330   }
2331   return NULL;
2332 }
2333
2334
2335 /**
2336  * It is a handler who processes the TEXTARE tag.
2337  *
2338  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2339  *                     destination is specified.
2340  * @param node   [i]   The TEXTAREA tag node is specified.
2341  * @return The conversion result is returned.
2342  */
2343 static char*
2344 s_jhtml_start_textarea_tag(void* pdoc, Node* node) 
2345 {
2346   jhtml_t*      jhtml = GET_JHTML(pdoc);
2347   Doc*          doc   = jhtml->doc;
2348   request_rec*  r     = doc->r;
2349   Attr*         attr;
2350
2351   jhtml->textarea_flag++;
2352   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<textarea ", NULL);
2353
2354   for (attr = qs_get_attr(doc,node);
2355        attr;
2356        attr = qs_get_next_attr(doc,attr)) {
2357
2358     char* name  = qs_get_attr_name(doc,attr);
2359     char* value = qs_get_attr_value(doc,attr);
2360
2361     if ((*name == 'n' || *name == 'N') && strcasecmp(name, "name") == 0) {
2362       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " name=\"",value,"\"", NULL);
2363     }
2364     else 
2365     if ((*name == 'r' || *name == 'R') && strcasecmp(name, "rows") == 0) {
2366       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " rows=\"",value,"\"", NULL);
2367     }
2368     else 
2369     if ((*name == 'c' || *name == 'C') && strcasecmp(name, "cols") == 0) {
2370       jhtml->out = apr_pstrcat(r->pool, jhtml->out, " cols=\"",value,"\"", NULL);
2371     }
2372   }
2373
2374   jhtml->out = apr_pstrcat(r->pool, jhtml->out, ">\r\n", NULL);
2375
2376   return jhtml->out;
2377 }
2378
2379
2380 /**
2381  * It is a handler who processes the TEXTAREA tag.
2382  *
2383  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2384  *                     destination is specified.
2385  * @param node   [i]   The TEXTAREA tag node is specified.
2386  * @return The conversion result is returned.
2387  */
2388 static char*
2389 s_jhtml_end_textarea_tag(void* pdoc, Node* child) 
2390 {
2391   jhtml_t*      jhtml = GET_JHTML(pdoc);
2392   Doc*          doc   = jhtml->doc;
2393   request_rec*  r     = doc->r;
2394
2395   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</textarea>\r\n", NULL);
2396   jhtml->textarea_flag--;
2397
2398   return jhtml->out;
2399 }
2400
2401 /**
2402  * It is a handler who processes the B tag.
2403  *
2404  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2405  *                     destination is specified.
2406  * @param node   [i]   The B tag node is specified.
2407  * @return The conversion result is returned.
2408  */
2409 static char*
2410 s_jhtml_start_b_tag(void* pdoc, Node* node) 
2411 {
2412   jhtml_t*      jhtml = GET_JHTML(pdoc);
2413   Doc*          doc   = jhtml->doc;
2414   request_rec*  r     = doc->r;
2415
2416   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "<b>", NULL);
2417
2418   return jhtml->out;
2419 }
2420
2421
2422 /**
2423  * It is a handler who processes the B tag.
2424  *
2425  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2426  *                     destination is specified.
2427  * @param node   [i]   The B tag node is specified.
2428  * @return The conversion result is returned.
2429  */
2430 static char*
2431 s_jhtml_end_b_tag(void* pdoc, Node* child) 
2432 {
2433   jhtml_t*      jhtml = GET_JHTML(pdoc);
2434   Doc*          doc   = jhtml->doc;
2435   request_rec*  r     = doc->r;
2436
2437   jhtml->out = apr_pstrcat(r->pool, jhtml->out, "</b>\r\n", NULL);
2438
2439   return jhtml->out;
2440 }
2441
2442 static char*
2443 s_jhtml_text_tag(void* pdoc, Node* child)
2444 {
2445   jhtml_t*     jhtml = GET_JHTML(pdoc);
2446   Doc*         doc = jhtml->doc;
2447   char*        textval;
2448   char*        tmp;
2449   char*        tdst;
2450   char         one_byte[2];
2451   int          ii;
2452   int          tdst_len;
2453   request_rec* r = doc->r;
2454
2455   textval = qs_get_node_value(doc,child);
2456   textval = qs_trim_string(jhtml->doc->r, textval);
2457   if (strlen(textval) == 0)
2458     return jhtml->out;
2459
2460   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
2461   memset(tmp, 0, qs_get_node_size(doc,child)+1);
2462
2463   tdst     = qs_alloc_zero_byte_string(r);
2464   memset(one_byte, 0, sizeof(one_byte));
2465   tdst_len = 0;
2466
2467   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
2468     char* out;
2469     int rtn = s_jhtml_search_emoji(jhtml, &textval[ii], &out);
2470     if (rtn) {
2471       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
2472       ii+=(rtn - 1);
2473       continue;
2474     }
2475
2476     if (is_sjis_kanji(textval[ii])) {
2477       one_byte[0] = textval[ii+0];
2478       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2479       one_byte[0] = textval[ii+1];
2480       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2481       ii++;
2482     }
2483     else 
2484     if (jhtml->pre_flag) {
2485       one_byte[0] = textval[ii+0];
2486       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2487     }
2488     else
2489     if (jhtml->textarea_flag) {
2490       one_byte[0] = textval[ii+0];
2491       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2492     }
2493     else {
2494       if (textval[ii] != '\r' && textval[ii] != '\n') {
2495         one_byte[0] = textval[ii+0];
2496         tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
2497       }
2498     }
2499   }
2500   jhtml->out = apr_pstrcat(r->pool, jhtml->out, tdst, NULL);
2501
2502   return jhtml->out;
2503 }
2504 /*
2505  * vim:ts=2 et
2506  */