OSDN Git Service

* Fixed bug.
[modchxj/mod_chxj.git] / src / chxj_jhtml.c
1 /*
2  * Copyright (C) 2005-2009 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. 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 #include "chxj_url_encode.h"
24 #include "chxj_str_util.h"
25 #include "chxj_header_inf.h"
26 #include "chxj_jreserved_tag.h"
27 #include "chxj_serf.h"
28 #include "chxj_conv_z2h.h"
29
30
31 #define GET_JHTML(X) ((jhtml_t *)(X))
32 #undef W_L
33 #undef W_V
34 #define W_L(X)          do { jhtml->out = BUFFERED_WRITE_LITERAL(jhtml->out, &doc->buf, (X)); } while(0)
35 #define W_V(X)          do { jhtml->out = (X) ? BUFFERED_WRITE_VALUE(jhtml->out, &doc->buf, (X))  \
36                                               : BUFFERED_WRITE_LITERAL(jhtml->out, &doc->buf, ""); } while(0)
37 #undef W_NLCODE
38 #define W_NLCODE()     do { char *nlcode = TO_NLCODE(jhtml->conf); W_V(nlcode); } while (0)
39
40 static char *s_jhtml_start_html_tag     (void *pdoc, Node *node);
41 static char *s_jhtml_end_html_tag       (void *pdoc, Node *node);
42 static char *s_jhtml_start_meta_tag     (void *pdoc, Node *node);
43 static char *s_jhtml_end_meta_tag       (void *pdoc, Node *node);
44 static char *s_jhtml_start_head_tag     (void *pdoc, Node *node);
45 static char *s_jhtml_end_head_tag       (void *pdoc, Node *node);
46 static char *s_jhtml_start_title_tag    (void *pdoc, Node *node);
47 static char *s_jhtml_end_title_tag      (void *pdoc, Node *node);
48 static char *s_jhtml_start_base_tag     (void *pdoc, Node *node);
49 static char *s_jhtml_end_base_tag       (void *pdoc, Node *node);
50 static char *s_jhtml_start_body_tag     (void *pdoc, Node *node);
51 static char *s_jhtml_end_body_tag       (void *pdoc, Node *node);
52 static char *s_jhtml_start_a_tag        (void *pdoc, Node *node);
53 static char *s_jhtml_end_a_tag          (void *pdoc, Node *node);
54 static char *s_jhtml_start_pre_tag      (void *pdoc, Node *node);
55 static char *s_jhtml_end_pre_tag        (void *pdoc, Node *node);
56 static char *s_jhtml_start_p_tag        (void *pdoc, Node *node);
57 static char *s_jhtml_end_p_tag          (void *pdoc, Node *node);
58 static char *s_jhtml_start_ul_tag       (void *pdoc, Node *node);
59 static char *s_jhtml_end_ul_tag         (void *pdoc, Node *node);
60 static char *s_jhtml_start_ol_tag       (void *pdoc, Node *node);
61 static char *s_jhtml_end_ol_tag         (void *pdoc, Node *node);
62 static char *s_jhtml_start_li_tag       (void *pdoc, Node *node);
63 static char *s_jhtml_end_li_tag         (void *pdoc, Node *node);
64 static char *s_jhtml_start_br_tag       (void *pdoc, Node *node);
65 static char *s_jhtml_end_br_tag         (void *pdoc, Node *node);
66 static char *s_jhtml_start_tr_tag       (void *pdoc, Node *node);
67 static char *s_jhtml_end_tr_tag         (void *pdoc, Node *node);
68 static char *s_jhtml_start_font_tag     (void *pdoc, Node *node);
69 static char *s_jhtml_end_font_tag       (void *pdoc, Node *node);
70 static char *s_jhtml_start_form_tag     (void *pdoc, Node *node);
71 static char *s_jhtml_end_form_tag       (void *pdoc, Node *node);
72 static char *s_jhtml_start_input_tag    (void *pdoc, Node *node);
73 static char *s_jhtml_end_input_tag      (void *pdoc, Node *node);
74 static char *s_jhtml_start_center_tag   (void *pdoc, Node *node);
75 static char *s_jhtml_end_center_tag     (void *pdoc, Node *node);
76 static char *s_jhtml_start_hr_tag       (void *pdoc, Node *node);
77 static char *s_jhtml_end_hr_tag         (void *pdoc, Node *node);
78 static char *s_jhtml_start_img_tag      (void *pdoc, Node *node);
79 static char *s_jhtml_end_img_tag        (void *pdoc, Node *node);
80 static char *s_jhtml_start_select_tag   (void *pdoc, Node *node);
81 static char *s_jhtml_end_select_tag     (void *pdoc, Node *node);
82 static char *s_jhtml_start_option_tag   (void *pdoc, Node *node);
83 static char *s_jhtml_end_option_tag     (void *pdoc, Node *node);
84 static char *s_jhtml_start_div_tag      (void *pdoc, Node *node);
85 static char *s_jhtml_end_div_tag        (void *pdoc, Node *node);
86 static char *s_jhtml_start_textarea_tag (void *pdoc, Node *node);
87 static char *s_jhtml_end_textarea_tag   (void *pdoc, Node *node);
88 static char *s_jhtml_start_b_tag        (void *pdoc, Node *node);
89 static char *s_jhtml_end_b_tag          (void *pdoc, Node *node);
90 static char *s_jhtml_chxjif_tag         (void *pdoc, Node *node); 
91 static char *s_jhtml_text_tag           (void *pdoc, Node *node);
92 static char *s_jhtml_start_blockquote_tag (void *pdoc, Node *node);
93 static char *s_jhtml_end_blockquote_tag  (void *pdoc, Node *node);
94 static char *s_jhtml_start_dir_tag      (void *pdoc, Node *node);
95 static char *s_jhtml_end_dir_tag        (void *pdoc, Node *node);
96 static char *s_jhtml_start_dl_tag       (void *pdoc, Node *node);
97 static char *s_jhtml_end_dl_tag         (void *pdoc, Node *node);
98 static char *s_jhtml_start_dt_tag       (void *pdoc, Node *node);
99 static char *s_jhtml_end_dt_tag         (void *pdoc, Node *node);
100 static char *s_jhtml_start_dd_tag       (void *pdoc, Node *node);
101 static char *s_jhtml_end_dd_tag         (void *pdoc, Node *node);
102 static char *s_jhtml_start_h1_tag       (void *pdoc, Node *node);
103 static char *s_jhtml_end_h1_tag         (void *pdoc, Node *node);
104 static char *s_jhtml_start_h2_tag       (void *pdoc, Node *node);
105 static char *s_jhtml_end_h2_tag         (void *pdoc, Node *node);
106 static char *s_jhtml_start_h3_tag       (void *pdoc, Node *node);
107 static char *s_jhtml_end_h3_tag         (void *pdoc, Node *node);
108 static char *s_jhtml_start_h4_tag       (void *pdoc, Node *node);
109 static char *s_jhtml_end_h4_tag         (void *pdoc, Node *node);
110 static char *s_jhtml_start_h5_tag       (void *pdoc, Node *node);
111 static char *s_jhtml_end_h5_tag         (void *pdoc, Node *node);
112 static char *s_jhtml_start_h6_tag       (void *pdoc, Node *node);
113 static char *s_jhtml_end_h6_tag         (void *pdoc, Node *node);
114 static char *s_jhtml_start_menu_tag     (void *pdoc, Node *node);
115 static char *s_jhtml_end_menu_tag       (void *pdoc, Node *node);
116 static char *s_jhtml_start_plaintext_tag       (void *pdoc, Node *node);
117 static char *s_jhtml_start_plaintext_tag_inner (void *pdoc, Node *node);
118 static char *s_jhtml_end_plaintext_tag         (void *pdoc, Node *node);
119 static char *s_jhtml_start_blink_tag  (void *pdoc, Node *node);
120 static char *s_jhtml_end_blink_tag    (void *pdoc, Node *node);
121 static char *s_jhtml_start_marquee_tag (void *pdoc, Node *node);
122 static char *s_jhtml_end_marquee_tag  (void *pdoc, Node *node);
123 static char *s_jhtml_newline_mark       (void *pdoc, Node *node);
124 static char *s_jhtml_link_tag           (void *pdoc, Node *node);
125 static char *s_jhtml_start_span_tag     (void *pdoc, Node *node);
126 static char *s_jhtml_end_span_tag       (void *pdoc, Node *node);
127 static char *s_jhtml_style_tag       (void *pdoc, Node *node);
128
129 static void  s_init_jhtml(jhtml_t *jhtml, Doc *doc, request_rec *r, device_table *spec);
130
131 static int   s_jhtml_search_emoji(jhtml_t *jhtml, char *txt, char **rslt);
132
133 static char *chxj_istyle_to_mode(apr_pool_t *p, const char *s);
134 static css_prop_list_t *s_jhtml_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
135 static css_prop_list_t *s_jhtml_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value);
136
137 static char *s_add_copyright_parameter(request_rec *r, char *value);
138
139
140 tag_handler jhtml_handler[] = {
141   /* tagHTML */
142   {
143     s_jhtml_start_html_tag,
144     s_jhtml_end_html_tag,
145   },
146   /* tagMETA */
147   {
148     s_jhtml_start_meta_tag,
149     s_jhtml_end_meta_tag,
150   },
151   /* tagTEXTAREA */
152   {
153     s_jhtml_start_textarea_tag,
154     s_jhtml_end_textarea_tag,
155   },
156   /* tagP */
157   {
158     s_jhtml_start_p_tag,
159     s_jhtml_end_p_tag,
160   },
161   /* tagPRE */
162   {
163     s_jhtml_start_pre_tag,
164     s_jhtml_end_pre_tag,
165   },
166   /* tagUL */
167   {
168     s_jhtml_start_ul_tag,
169     s_jhtml_end_ul_tag,
170   },
171   /* tagLI */
172   {
173     s_jhtml_start_li_tag,
174     s_jhtml_end_li_tag,
175   },
176   /* tagOL */
177   {
178     s_jhtml_start_ol_tag,
179     s_jhtml_end_ol_tag,
180   },
181   /* tagH1 */
182   {
183     s_jhtml_start_h1_tag,
184     s_jhtml_end_h1_tag,
185   },
186   /* tagH2 */
187   {
188     s_jhtml_start_h2_tag,
189     s_jhtml_end_h2_tag,
190   },
191   /* tagH3 */
192   {
193     s_jhtml_start_h3_tag,
194     s_jhtml_end_h3_tag,
195   },
196   /* tagH4 */
197   {
198     s_jhtml_start_h4_tag,
199     s_jhtml_end_h4_tag,
200   },
201   /* tagH5 */
202   {
203     s_jhtml_start_h5_tag,
204     s_jhtml_end_h5_tag,
205   },
206   /* tagH6 */
207   {
208     s_jhtml_start_h6_tag,
209     s_jhtml_end_h6_tag,
210   },
211   /* tagHEAD */
212   {
213     s_jhtml_start_head_tag,
214     s_jhtml_end_head_tag,
215   },
216   /* tagTITLE */
217   {
218     s_jhtml_start_title_tag,
219     s_jhtml_end_title_tag,
220   },
221   /* tagBASE */
222   {
223     s_jhtml_start_base_tag,
224     s_jhtml_end_base_tag,
225   },
226   /* tagBODY */
227   {
228     s_jhtml_start_body_tag,
229     s_jhtml_end_body_tag,
230   },
231   /* tagA */
232   {
233     s_jhtml_start_a_tag,
234     s_jhtml_end_a_tag,
235   },
236   /* tagBR */
237   {
238     s_jhtml_start_br_tag,
239     s_jhtml_end_br_tag,
240   },
241   /* tagTABLE */
242   {
243     NULL,
244     NULL,
245   },
246   /* tagTR */
247   {
248     s_jhtml_start_tr_tag,
249     s_jhtml_end_tr_tag,
250   },
251   /* tagTD */
252   {
253     NULL,
254     NULL,
255   },
256   /* tagTBODY */
257   {
258     NULL,
259     NULL,
260   },
261   /* tagFONT */
262   {
263     s_jhtml_start_font_tag,
264     s_jhtml_end_font_tag,
265   },
266   /* tagFORM */
267   {
268     s_jhtml_start_form_tag,
269     s_jhtml_end_form_tag,
270   },
271   /* tagINPUT */
272   {
273     s_jhtml_start_input_tag,
274     s_jhtml_end_input_tag,
275   },
276   /* tagCENTER */
277   {
278     s_jhtml_start_center_tag,
279     s_jhtml_end_center_tag,
280   },
281   /* tagHR */
282   {
283     s_jhtml_start_hr_tag,
284     s_jhtml_end_hr_tag,
285   },
286   /* tagIMG */
287   {
288     s_jhtml_start_img_tag,
289     s_jhtml_end_img_tag,
290   },
291   /* tagSELECT */
292   {
293     s_jhtml_start_select_tag,
294     s_jhtml_end_select_tag,
295   },
296   /* tagOPTION */
297   {
298     s_jhtml_start_option_tag,
299     s_jhtml_end_option_tag,
300   },
301   /* tagDIV */
302   {
303     s_jhtml_start_div_tag,
304     s_jhtml_end_div_tag,
305   },
306   /* tagCHXJIF */
307   {
308     s_jhtml_chxjif_tag,
309     NULL,
310   },
311   /* tagCHXJRAW */
312   {
313     s_jhtml_chxjif_tag,
314     NULL,
315   },
316   /* tagNOBR */
317   {
318     NULL,
319     NULL,
320   },
321   /* tagSMALL */
322   {
323     NULL,
324     NULL,
325   },
326   /* tagSTYLE */
327   {
328     s_jhtml_style_tag,
329     NULL,
330   },
331   /* tagSPAN */
332   {
333     s_jhtml_start_span_tag,
334     s_jhtml_end_span_tag,
335   },
336   /* tagTEXT */
337   {
338     s_jhtml_text_tag,
339     NULL,
340   },
341   /* tagTH */
342   {
343     NULL,
344     NULL,
345   },
346   /* tagB */
347   {
348     s_jhtml_start_b_tag,
349     s_jhtml_end_b_tag,
350   },
351   /* tagFIELDSET */
352   {
353     NULL,
354     NULL,
355   },
356   /* tagDT */
357   {
358     s_jhtml_start_dt_tag,
359     s_jhtml_end_dt_tag,
360   },
361   /* tagLEGEND */
362   {
363     NULL,
364     NULL,
365   },
366   /* tagLABEL */
367   {
368     NULL,
369     NULL,
370   },
371   /* tagBLOCKQUOTE */
372   {
373     s_jhtml_start_blockquote_tag,
374     s_jhtml_end_blockquote_tag,
375   },
376   /* tagDIR */
377   {
378     s_jhtml_start_dir_tag,
379     s_jhtml_end_dir_tag,
380   },
381   /* tagDL */
382   {
383     s_jhtml_start_dl_tag,
384     s_jhtml_end_dl_tag,
385   },
386   /* tagDD */
387   {
388     s_jhtml_start_dd_tag,
389     s_jhtml_end_dd_tag,
390   },
391   /* tagMENU */
392   {
393     s_jhtml_start_menu_tag,
394     s_jhtml_end_menu_tag,
395   },
396   /* tagPLAINTEXT */
397   {
398     s_jhtml_start_plaintext_tag,
399     s_jhtml_end_plaintext_tag,
400   },
401   /* tagBLINK */
402   {
403     s_jhtml_start_blink_tag,
404     s_jhtml_end_blink_tag,
405   },
406   /* tagMARQUEE */
407   {
408     s_jhtml_start_marquee_tag,
409     s_jhtml_end_marquee_tag,
410   },
411   /* tagLINK */
412   {
413     s_jhtml_link_tag,
414     NULL,
415   },
416   /* tagNLMARK */
417   {
418     s_jhtml_newline_mark,
419     NULL,
420   },
421   /* tagObject */
422   {
423     NULL,
424     NULL,
425   },
426   /* tagParam */
427   {
428     NULL,
429     NULL,
430   },
431   /* tagCAPTION */
432   {
433     NULL,
434     NULL,
435   },
436 };
437
438
439 /**
440  * converts from CHTML5.0 to JHTML.
441  *
442  * @param r     [i]   Requet_rec is appointed.
443  * @param spec  [i]   The result of the device specification processing which 
444  *                    was done in advance is appointed.
445  * @param src   [i]   The character string before the converting is appointed.
446  * @return The character string after the converting is returned.
447  */
448 char *
449 chxj_convert_jhtml(
450   request_rec         *r,
451   device_table        *spec,
452   const char          *src,
453   apr_size_t          srclen,
454   apr_size_t          *dstlen,
455   chxjconvrule_entry  *entryp,
456   cookie_t            *cookie
457 )
458 {
459   char      *dst;
460   char      *ss;
461   jhtml_t   jhtml;
462   Doc       doc;
463   apr_pool_t *pool;
464
465   dst = NULL;
466
467   /*--------------------------------------------------------------------------*/
468   /* If qrcode xml                                                            */
469   /*--------------------------------------------------------------------------*/
470   *dstlen = srclen;
471   dst = chxj_qr_code_blob_handler(r, src, (size_t*)dstlen);
472   if (dst) {
473     DBG(r,"I found qrcode xml");
474     return dst;
475   }
476   DBG(r,"not found qrcode xml");
477
478   /*--------------------------------------------------------------------------*/
479   /* The CHTML structure is initialized.                                      */
480   /*--------------------------------------------------------------------------*/
481   s_init_jhtml(&jhtml, &doc, r, spec);
482
483   jhtml.entryp = entryp;
484   jhtml.cookie = cookie;
485
486   chxj_set_content_type(r, chxj_header_inf_set_content_type(r, "text/html; charset=Windows-31J"));
487
488   /*--------------------------------------------------------------------------*/
489   /* The character string of the input is analyzed.                           */
490   /*--------------------------------------------------------------------------*/
491   qs_init_malloc(&doc);
492   qs_init_root_node(&doc);
493
494   apr_pool_create(&pool, r->pool);
495   ss = apr_pcalloc(pool, srclen + 1);
496
497   memset(ss,   0, srclen + 1);
498   memcpy(ss, src, srclen);
499
500 #ifdef DUMP_LOG
501   chxj_dump_out("[src] CHTML -> JHTML", ss, srclen);
502 #endif
503   if (IS_CSS_ON(jhtml.entryp)) {
504     /* current property list */
505     jhtml.css_prop_stack = chxj_new_prop_list_stack(&doc);
506   }
507
508   qs_parse_string(&doc,ss,strlen(ss));
509
510   chxj_buffered_write_init(r->pool, &doc.buf);
511   /*--------------------------------------------------------------------------*/
512   /* It converts it from CHTML to JHTML.                                      */
513   /*--------------------------------------------------------------------------*/
514   chxj_node_convert(spec,r,(void*)&jhtml, &doc, qs_get_root(&doc), 0);
515   jhtml.out = chxj_buffered_write_flush(jhtml.out, &doc.buf);
516   dst = apr_pstrdup(pool, jhtml.out);
517   chxj_buffered_write_terminate(&doc.buf);
518
519
520   qs_all_free(&doc,QX_LOGMARK);
521
522   if (! dst) 
523     return apr_pstrdup(pool,ss);
524
525   if (! strlen(dst)) 
526     dst = apr_psprintf(pool, "\n");
527
528   *dstlen = strlen(dst);
529
530 #ifdef DUMP_LOG
531   chxj_dump_out("[dst] CHTML -> JHTML", dst, *dstlen);
532 #endif
533
534   return dst;
535 }
536
537
538 /**
539  * The CHTML structure is initialized.
540  *
541  * @param jhtml [i/o] The pointer to the JHTML structure that wants to be
542  *                   initialized is specified.
543  * @param doc   [i]   The Doc structure that should be set to the initialized
544  *                   JHTML structure is specified.
545  * @param r     [i]   To use POOL, the pointer to request_rec is specified.
546  * @param spec  [i]   The pointer to the device_table
547  */
548 static void
549 s_init_jhtml(jhtml_t *jhtml, Doc *doc, request_rec *r, device_table *spec)
550 {
551   memset(doc,   0, sizeof(Doc));
552   memset(jhtml, 0, sizeof(jhtml_t));
553
554   doc->r      = r;
555   jhtml->doc  = doc;
556   jhtml->spec = spec;
557   jhtml->out  = qs_alloc_zero_byte_string(r->pool);
558   jhtml->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
559   jhtml->doc->parse_mode = PARSE_MODE_CHTML;
560 }
561
562
563 /**
564  * Corresponding EMOJI to a current character-code is retrieved. 
565  * The substitution character string is stored in the rslt pointer if agreeing.
566  *
567  * @param jhtml   [i]   The pointer to the CHTML structure is specified. 
568  * @param txt     [i]   The character string to want to examine whether it is 
569  *                      EMOJI is specified. 
570  * @param rslt    [o]   The pointer to the pointer that stores the result is 
571  *                      specified. 
572  * @return When corresponding EMOJI exists, it returns it excluding 0. 
573  */
574 static int
575 s_jhtml_search_emoji(jhtml_t *jhtml, char *txt, char **rslt)
576 {
577   emoji_t       *ee;
578   request_rec   *r;
579   device_table  *spec;
580   int           len;
581
582   spec = jhtml->spec;
583
584   len = strlen(txt);
585   r = jhtml->doc->r;
586
587   if (! spec) DBG(r,"spec is NULL");
588
589   for (ee = jhtml->conf->emoji;
590        ee;
591        ee = ee->next) {
592
593     unsigned char hex1byte;
594     unsigned char hex2byte;
595
596     if (! ee->imode) { 
597       DBG(r,"emoji->imode is NULL");
598       continue;
599     }
600
601     hex1byte = ee->imode->hex1byte & 0xff;
602     hex2byte = ee->imode->hex2byte & 0xff;
603
604     if (ee->imode->string
605     &&  strlen(ee->imode->string) > 0
606     &&  strncasecmp(ee->imode->string, txt, strlen(ee->imode->string)) == 0) {
607       if (spec == NULL || spec->emoji_type == NULL) {
608         *rslt = apr_psprintf(r->pool,"\e%s\ f", ee->jphone->string);
609         return strlen(ee->imode->string);
610       }
611
612       return 0;
613     }
614
615     if (len >= 2
616     && ((unsigned char)txt[0] & 0xff) == ((unsigned char)hex1byte)
617     && ((unsigned char)txt[1] & 0xff) == ((unsigned char)hex2byte)) {
618       if (spec == NULL || spec->emoji_type == NULL) {
619         *rslt = apr_psprintf(r->pool,"\e%s\ f", ee->jphone->string);
620         return 2;
621       }
622
623       return 0;
624     }
625   }
626
627   return 0;
628 }
629
630
631 char *
632 chxj_jhtml_emoji_only_converter(request_rec *r, device_table *spec, const char *src, apr_size_t len)
633 {
634   apr_size_t ii;
635   Doc __doc;
636   Doc *doc;
637   jhtml_t __jhtml;
638   jhtml_t *jhtml;
639   char one_byte[2];
640   char two_byte[3];
641   apr_pool_t *pool;
642
643   jhtml = &__jhtml;
644   doc   = &__doc;
645
646   DBG(r, "REQ[%X] start chxj_jhtml_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
647   memset(doc,   0, sizeof(Doc));
648   memset(jhtml, 0, sizeof(jhtml_t));
649
650   doc->r      = r;
651   jhtml->doc  = doc;
652   jhtml->spec = spec;
653   jhtml->out  = qs_alloc_zero_byte_string(r->pool);
654   jhtml->conf = chxj_get_module_config(r->per_dir_config, &chxj_module);
655   jhtml->doc->parse_mode = PARSE_MODE_CHTML;
656
657   apr_pool_create(&pool, r->pool);
658
659   chxj_buffered_write_init(pool, &doc->buf);
660
661   for (ii=0; ii<len; ii++) {
662     char *out;
663     int   rtn;
664
665     rtn = s_jhtml_search_emoji(jhtml, (char *)&src[ii], &out);
666     if (rtn) {
667       W_V(out);
668       ii+=(rtn - 1);
669       continue;
670     }
671
672     if (is_sjis_kanji(src[ii])) {
673       two_byte[0] = src[ii+0];
674       two_byte[1] = src[ii+1];
675       two_byte[2] = 0;
676       W_V(two_byte);
677       ii++;
678     }
679     else {
680       one_byte[0] = src[ii+0];
681       one_byte[1] = 0;
682       W_V(one_byte);
683     }
684   }
685   jhtml->out = chxj_buffered_write_flush(jhtml->out, &doc->buf);
686
687   DBG(r, "REQ[%X] end chxj_jhtml_emoji_eonly_converter()", (unsigned int)(apr_size_t)r);
688   return jhtml->out;
689 }
690
691
692 /**
693  * It is a handler who processes the HTML tag.
694  *
695  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
696  *                     destination is specified.
697  * @param node   [i]   The HTML tag node is specified.
698  * @return The conversion result is returned.
699  */
700 static char *
701 s_jhtml_start_html_tag(void *pdoc, Node *UNUSED(node)) 
702 {
703   jhtml_t       *jhtml;
704   Doc           *doc;
705   request_rec   *r;
706
707
708   jhtml  = GET_JHTML(pdoc);
709   doc    = jhtml->doc;
710   r      = doc->r;
711   DBG(r, "start s_jhtml_start_html_tag()");
712
713   /*--------------------------------------------------------------------------*/
714   /* start HTML tag                                                           */
715   /*--------------------------------------------------------------------------*/
716   W_L("<html>");
717
718   DBG(r, "end s_jhtml_start_html_tag()");
719
720   return jhtml->out;
721 }
722
723
724 /**
725  * It is a handler who processes the HTML tag.
726  *
727  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
728  *                     destination is specified.
729  * @param node   [i]   The HTML tag node is specified.
730  * @return The conversion result is returned.
731  */
732 static char *
733 s_jhtml_end_html_tag(void *pdoc, Node *UNUSED(child)) 
734 {
735   jhtml_t       *jhtml = GET_JHTML(pdoc);
736   Doc           *doc = jhtml->doc;
737
738   W_L("</html>");
739
740   return jhtml->out;
741 }
742
743
744 /**
745  * It is a handler who processes the META tag.
746  *
747  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
748  *                     destination is specified.
749  * @param node   [i]   The META tag node is specified.
750  * @return The conversion result is returned.
751  */
752 static char *
753 s_jhtml_start_meta_tag(void *pdoc, Node *node) 
754 {
755   jhtml_t      *jhtml;
756   Doc          *doc;
757   request_rec  *r;
758   Attr         *attr;
759   int          content_type_flag;
760   int          refresh_flag;
761
762   jhtml             = GET_JHTML(pdoc);
763   doc               = jhtml->doc;
764   r                 = doc->r;
765   refresh_flag      = 0;
766   content_type_flag = 0;
767
768   W_L("<meta");
769   /*--------------------------------------------------------------------------*/
770   /* Get Attributes                                                           */
771   /*--------------------------------------------------------------------------*/
772   for (attr = qs_get_attr(doc,node);
773        attr;
774        attr = qs_get_next_attr(doc,attr)) {
775     char *name   = qs_get_attr_name(doc,attr);
776     char *value  = qs_get_attr_value(doc,attr);
777     switch(*name) {
778     case 'h':
779     case 'H':
780       if (strcasecmp(name, "http-equiv") == 0 && value && *value) {
781         /*----------------------------------------------------------------------*/
782         /* CHTML 2.0                                                            */
783         /*----------------------------------------------------------------------*/
784         W_L(" http-equiv=\"");
785         W_V(value);
786         W_L("\"");
787         if (STRCASEEQ('c','C',"content-type",value)) {
788           content_type_flag = 1;
789         }
790         if (STRCASEEQ('r','R',"refresh",value)) {
791           refresh_flag = 1;
792         }
793       }
794       break;
795
796     case 'c':
797     case 'C':
798       if (strcasecmp(name, "content") == 0 && value && *value) {
799         /*----------------------------------------------------------------------*/
800         /* CHTML 2.0                                                            */
801         /*----------------------------------------------------------------------*/
802         if (content_type_flag)  {
803           W_L(" ");
804           W_V(name);
805           W_L("=\"");
806           W_V(chxj_header_inf_set_content_type(r, "text/html; charset=SHIFT_JIS"));
807           W_L("\"");
808         }
809         else
810         if (refresh_flag) {
811           char *buf;
812           char *sec;
813           char *url;
814   
815           buf = apr_pstrdup(r->pool, value);
816   
817           url = strchr(buf, ';');
818           if (url) {
819             sec = apr_pstrdup(r->pool, buf);
820             sec[url-buf] = 0;
821             url++;
822             url = chxj_encoding_parameter(r, url, 0);
823             url = chxj_add_cookie_parameter(r, url, jhtml->cookie);
824             W_L(" ");
825             W_V(name);
826             W_L("=\"");
827             W_V(sec);
828             W_L(";");
829             W_V(url);
830             W_L("\"");
831           }
832         }
833         else {
834           W_L(" ");
835           W_V(name);
836           W_L("=\"");
837           W_V(value);
838           W_L("\"");
839         }
840       }
841       break;
842     
843     default:
844       break;
845     }
846   }
847   W_L(">");
848   return jhtml->out;
849 }
850
851
852 /**
853  * It is a handler who processes the META tag.
854  *
855  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
856  *                     destination is specified.
857  * @param node   [i]   The META tag node is specified.
858  * @return The conversion result is returned.
859  */
860 static char *
861 s_jhtml_end_meta_tag(void *pdoc, Node *UNUSED(child)) 
862 {
863   jhtml_t *jhtml = GET_JHTML(pdoc);
864
865   return jhtml->out;
866 }
867
868
869 /**
870  * It is a handler who processes the HEAD tag.
871  *
872  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
873  *                     destination is specified.
874  * @param node   [i]   The HEAD tag node is specified.
875  * @return The conversion result is returned.
876  */
877 static char *
878 s_jhtml_start_head_tag(void *pdoc, Node *UNUSED(node)) 
879 {
880   jhtml_t       *jhtml;
881   Doc           *doc;
882   request_rec   *r;
883
884   jhtml = GET_JHTML(pdoc);
885   doc   = jhtml->doc;
886   r     = doc->r;
887
888   W_L("<head>");
889   return jhtml->out;
890 }
891
892
893 /**
894  * It is a handler who processes the HEAD tag.
895  *
896  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
897  *                     destination is specified.
898  * @param node   [i]   The HEAD tag node is specified.
899  * @return The conversion result is returned.
900  */
901 static char *
902 s_jhtml_end_head_tag(void *pdoc, Node *UNUSED(child)) 
903 {
904   jhtml_t       *jhtml;
905   Doc           *doc;
906   request_rec   *r;
907
908   jhtml = GET_JHTML(pdoc);
909   doc   = jhtml->doc;
910   r     = doc->r;
911
912   W_L("</head>");
913   return jhtml->out;
914 }
915
916
917 /**
918  * It is a handler who processes the TITLE tag.
919  *
920  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
921  *                     destination is specified.
922  * @param node   [i]   The TITLE tag node is specified.
923  * @return The conversion result is returned.
924  */
925 static char *
926 s_jhtml_start_title_tag(void *pdoc, Node *UNUSED(node)) 
927 {
928   jhtml_t      *jhtml;
929   Doc          *doc;
930   request_rec  *r;
931
932   jhtml = GET_JHTML(pdoc);
933   doc   = jhtml->doc;
934   r     = doc->r;
935
936   W_L("<title>");
937   return jhtml->out;
938 }
939
940
941 /**
942  * It is a handler who processes the TITLE tag.
943  *
944  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
945  *                     destination is specified.
946  * @param node   [i]   The TITLE tag node is specified.
947  * @return The conversion result is returned.
948  */
949 static char *
950 s_jhtml_end_title_tag(void *pdoc, Node *UNUSED(child)) 
951 {
952   jhtml_t       *jhtml;
953   Doc           *doc;
954   request_rec   *r;
955
956   jhtml = GET_JHTML(pdoc);
957   doc   = jhtml->doc;
958   r     = doc->r;
959
960   W_L("</title>");
961   return jhtml->out;
962 }
963
964
965 /**
966  * It is a handler who processes the BASE tag.
967  *
968  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
969  *                     destination is specified.
970  * @param node   [i]   The BASE tag node is specified.
971  * @return The conversion result is returned.
972  */
973 static char *
974 s_jhtml_start_base_tag(void *pdoc, Node *node) 
975 {
976   jhtml_t       *jhtml;
977   Attr          *attr;
978   Doc           *doc;
979   request_rec   *r;
980
981   jhtml = GET_JHTML(pdoc);
982   doc   = jhtml->doc;
983   r     = doc->r;
984
985   W_L("<base");
986   /*--------------------------------------------------------------------------*/
987   /* Get Attributes                                                           */
988   /*--------------------------------------------------------------------------*/
989   for (attr = qs_get_attr(doc,node);
990        attr;
991        attr = qs_get_next_attr(doc,attr)) {
992     char *name  = qs_get_attr_name(doc,attr);
993     char *value = qs_get_attr_value(doc,attr);
994     if (STRCASEEQ('h','H',"href",name)) {
995       W_L(" href=\"");
996       W_V(value);
997       W_L("\"");
998     }
999   }
1000   W_L(">");
1001   return jhtml->out;
1002 }
1003
1004
1005 /**
1006  * It is a handler who processes the BASE tag.
1007  *
1008  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1009  *                     destination is specified.
1010  * @param node   [i]   The BASE tag node is specified.
1011  * @return The conversion result is returned.
1012  */
1013 static char *
1014 s_jhtml_end_base_tag(void *pdoc, Node *UNUSED(child)) 
1015 {
1016   jhtml_t *jhtml = GET_JHTML(pdoc);
1017   return jhtml->out;
1018 }
1019
1020
1021 /**
1022  * It is a handler who processes the BODY tag.
1023  *
1024  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1025  *                     destination is specified.
1026  * @param node   [i]   The BODY tag node is specified.
1027  * @return The conversion result is returned.
1028  */
1029 static char *
1030 s_jhtml_start_body_tag(void *pdoc, Node *node) 
1031 {
1032   jhtml_t     *jhtml;
1033   Doc         *doc;
1034   request_rec *r;
1035   Attr        *attr;
1036   char        *attr_bgcolor = NULL;
1037   char        *attr_text    = NULL;
1038   char        *attr_link    = NULL;
1039   char        *attr_style   = NULL;
1040   char        *attr_vlink   = NULL;
1041
1042   jhtml = GET_JHTML(pdoc);
1043   doc   = jhtml->doc;
1044   r     = doc->r;
1045
1046   /*--------------------------------------------------------------------------*/
1047   /* Get Attributes                                                           */
1048   /*--------------------------------------------------------------------------*/
1049   for (attr = qs_get_attr(doc,node);
1050        attr;
1051        attr = qs_get_next_attr(doc,attr)) {
1052     char *name   = qs_get_attr_name(doc,attr);
1053     char *value  = qs_get_attr_value(doc,attr);
1054     if (STRCASEEQ('b','B',"bgcolor",name) && value && *value) {
1055       /*----------------------------------------------------------------------*/
1056       /* CHTML 2.0                                                            */
1057       /*----------------------------------------------------------------------*/
1058       attr_bgcolor = value;
1059     }
1060     else if (STRCASEEQ('t','T',"text",name) && value && *value) {
1061       /*----------------------------------------------------------------------*/
1062       /* CHTML 2.0                                                            */
1063       /*----------------------------------------------------------------------*/
1064       attr_text = value;
1065     }
1066     else if (STRCASEEQ('l','L',"link",name) && value && *value) {
1067       /*----------------------------------------------------------------------*/
1068       /* CHTML 2.0                                                            */
1069       /*----------------------------------------------------------------------*/
1070       attr_link = value;
1071     }
1072     else if (STRCASEEQ('a','A',"alink",name)) {
1073       /*----------------------------------------------------------------------*/
1074       /* CHTML 4.0                                                            */
1075       /*----------------------------------------------------------------------*/
1076       /* ignore */
1077     }
1078     else if (STRCASEEQ('v','V',"vlink",name) && value && *value) {
1079       /*----------------------------------------------------------------------*/
1080       /* CHTML 4.0                                                            */
1081       /*----------------------------------------------------------------------*/
1082       attr_vlink = value;
1083     }
1084     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
1085       /*----------------------------------------------------------------------*/
1086       /* CHTML 4.0                                                            */
1087       /*----------------------------------------------------------------------*/
1088       attr_style = value;
1089     }
1090   }
1091
1092   if (IS_CSS_ON(jhtml->entryp)) {
1093     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
1094     if (style) {
1095       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
1096       css_property_t *bgcolor_prop    = chxj_css_get_property_value(doc, style, "background-color");
1097       css_property_t *cur;
1098       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
1099         if (cur->value && *cur->value) {
1100           attr_text = apr_pstrdup(doc->pool, cur->value);
1101         }
1102       }
1103       for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
1104         if (cur->value && *cur->value) {
1105           attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
1106         }
1107       }
1108     }
1109     if (jhtml->style) {
1110       css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, jhtml->style);
1111       css_selector_t *cur_sel;
1112       for (cur_sel = pseudos->selector_head.next; cur_sel != &pseudos->selector_head; cur_sel = cur_sel->next) {
1113         if (cur_sel->name && strcasecmp(cur_sel->name, "a:link") == 0) {
1114           css_property_t *cur;
1115           for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
1116             if (cur->name && strcasecmp(cur->name, "color") == 0) {
1117               attr_link = apr_pstrdup(doc->pool, cur->value);
1118             }
1119           }
1120         }
1121         else if (cur_sel->name && strcasecmp(cur_sel->name, "a:visited") == 0) {
1122           css_property_t *cur;
1123           for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
1124             if (cur->name && strcasecmp(cur->name, "color") == 0) {
1125               attr_vlink = apr_pstrdup(doc->pool, cur->value);
1126             }
1127           }
1128         }
1129       }
1130     }
1131   }
1132
1133   W_L("<body");
1134   if (attr_bgcolor) {
1135     attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
1136     W_L(" bgcolor=\"");
1137     W_V(attr_bgcolor);
1138     W_L("\"");
1139   }
1140   if (attr_text) {
1141     attr_text = chxj_css_rgb_func_to_value(doc->pool, attr_text);
1142     W_L(" text=\"");
1143     W_V(attr_text);
1144     W_L("\"");
1145   }
1146   if (attr_link) {
1147     attr_link = chxj_css_rgb_func_to_value(doc->pool, attr_link);
1148     W_L(" link=\"");
1149     W_V(attr_link);
1150     W_L("\"");
1151   }
1152   if (attr_vlink) {
1153     attr_vlink = chxj_css_rgb_func_to_value(doc->pool, attr_vlink);
1154     W_L(" vlink=\"");
1155     W_V(attr_vlink);
1156     W_L("\"");
1157   }
1158   W_L(">");
1159
1160   return jhtml->out;
1161 }
1162
1163
1164 /**
1165  * It is a handler who processes the BODY tag.
1166  *
1167  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1168  *                     destination is specified.
1169  * @param node   [i]   The BODY tag node is specified.
1170  * @return The conversion result is returned.
1171  */
1172 static char *
1173 s_jhtml_end_body_tag(void *pdoc, Node *UNUSED(child)) 
1174 {
1175   jhtml_t       *jhtml;
1176   Doc           *doc;
1177   request_rec   *r;
1178
1179   jhtml = GET_JHTML(pdoc);
1180   doc   = jhtml->doc;
1181   r     = doc->r;
1182
1183   W_L("</body>");
1184   if (IS_CSS_ON(jhtml->entryp)) {
1185     chxj_css_pop_prop_list(jhtml->css_prop_stack);
1186   }
1187
1188   return jhtml->out;
1189 }
1190
1191
1192 /**
1193  * It is a handler who processes the A tag.
1194  *
1195  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1196  *                     destination is specified.
1197  * @param node   [i]   The A tag node is specified.
1198  * @return The conversion result is returned.
1199  */
1200 static char *
1201 s_jhtml_start_a_tag(void *pdoc, Node *node) 
1202 {
1203   jhtml_t     *jhtml;
1204   Doc         *doc;
1205   request_rec *r;
1206   Attr        *attr;
1207   char        *attr_style = NULL;
1208
1209   jhtml = GET_JHTML(pdoc);
1210   doc   = jhtml->doc;
1211   r     = doc->r;
1212
1213   W_L("<a");
1214   /*--------------------------------------------------------------------------*/
1215   /* Get Attributes                                                           */
1216   /*--------------------------------------------------------------------------*/
1217   for (attr = qs_get_attr(doc,node);
1218        attr; 
1219        attr = qs_get_next_attr(doc,attr)) {
1220     char *name  = qs_get_attr_name(doc,attr);
1221     char *value = qs_get_attr_value(doc,attr);
1222     if (STRCASEEQ('n','N',"name",name)) {
1223       /*----------------------------------------------------------------------*/
1224       /* CHTML1.0                                                             */
1225       /*----------------------------------------------------------------------*/
1226       W_L(" name=\"");
1227       W_V(value);
1228       W_L("\"");
1229     }
1230     else if (STRCASEEQ('h','H',"href",name)) {
1231       /*----------------------------------------------------------------------*/
1232       /* CHTML1.0                                                             */
1233       /*----------------------------------------------------------------------*/
1234       value = chxj_encoding_parameter(r, value, 0);
1235       if (! chxj_starts_with(value, "mailto:") && ! chxj_starts_with(value, "tel:")) {
1236         value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
1237         value = chxj_jreserved_tag_to_safe_for_query_string(r, value, jhtml->entryp, 0);
1238       }
1239       W_L(" href=\"");
1240       W_V(value);
1241       W_L("\"");
1242     }
1243     else if (STRCASEEQ('a','A',"accesskey",name)) {
1244       /*----------------------------------------------------------------------*/
1245       /* CHTML1.0                                                             */
1246       /*----------------------------------------------------------------------*/
1247       W_L(" accesskey=\"");
1248       W_V(value);
1249       W_L("\"");
1250     }
1251     else if (STRCASEEQ('c','C',"cti",name)) {
1252       /*----------------------------------------------------------------------*/
1253       /* CHTML 2.0                                                            */
1254       /*----------------------------------------------------------------------*/
1255       W_L(" cti=\"");
1256       W_V(value);
1257       W_L("\"");
1258     }
1259     else if (STRCASEEQ('i','I',"ijam",name)) {
1260       /*----------------------------------------------------------------------*/
1261       /* CHTML 3.0                                                            */
1262       /*----------------------------------------------------------------------*/
1263       /* ignore */
1264     }
1265     else if (STRCASEEQ('u','U',"utn",name)) {
1266       /*----------------------------------------------------------------------*/
1267       /* CHTML 3.0                                                            */
1268       /* It is special only for CHTML.                                        */
1269       /*----------------------------------------------------------------------*/
1270     }
1271     else if (STRCASEEQ('t','T',"telbook",name)) {
1272       /*----------------------------------------------------------------------*/
1273       /* CHTML 3.0                                                            */
1274       /*----------------------------------------------------------------------*/
1275       /* not support */
1276     }
1277     else if (STRCASEEQ('k','K',"kana",name)) {
1278       /*----------------------------------------------------------------------*/
1279       /* CHTML 3.0                                                            */
1280       /*----------------------------------------------------------------------*/
1281       /* not support */
1282     }
1283     else if (STRCASEEQ('e','E',"email",name)) {
1284       /*----------------------------------------------------------------------*/
1285       /* CHTML 3.0                                                            */
1286       /*----------------------------------------------------------------------*/
1287       /* not support */
1288     }
1289     else if (STRCASEEQ('i','I',"ista",name)) {
1290       /*----------------------------------------------------------------------*/
1291       /* CHTML 4.0                                                            */
1292       /*----------------------------------------------------------------------*/
1293       /* ignore */
1294     }
1295     else if (STRCASEEQ('i','I',"ilet",name)) {
1296       /*----------------------------------------------------------------------*/
1297       /* CHTML 5.0                                                            */
1298       /*----------------------------------------------------------------------*/
1299       /* ignore */
1300     }
1301     else if (STRCASEEQ('i','I',"iswf",name)) {
1302       /*----------------------------------------------------------------------*/
1303       /* CHTML 5.0                                                            */
1304       /*----------------------------------------------------------------------*/
1305       /* ignore */
1306     }
1307     else if (STRCASEEQ('i','I',"irst",name)) {
1308       /*----------------------------------------------------------------------*/
1309       /* CHTML 5.0                                                            */
1310       /*----------------------------------------------------------------------*/
1311       /* ignore */
1312     }
1313     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
1314       attr_style = value;
1315     }
1316   }
1317   W_L(">");
1318
1319   if (IS_CSS_ON(jhtml->entryp)) {
1320     s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
1321   }
1322
1323   return jhtml->out;
1324 }
1325
1326
1327 /**
1328  * It is a handler who processes the A tag.
1329  *
1330  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1331  *                     destination is specified.
1332  * @param node   [i]   The A tag node is specified.
1333  * @return The conversion result is returned.
1334  */
1335 static char *
1336 s_jhtml_end_a_tag(void *pdoc, Node *UNUSED(child)) 
1337 {
1338   jhtml_t      *jhtml;
1339   Doc          *doc;
1340   request_rec  *r;
1341
1342   jhtml = GET_JHTML(pdoc);
1343   doc   = jhtml->doc;
1344   r     = doc->r;
1345
1346   W_L("</a>");
1347
1348   if (IS_CSS_ON(jhtml->entryp)) {
1349     chxj_css_pop_prop_list(jhtml->css_prop_stack);
1350   }
1351
1352   return jhtml->out;
1353 }
1354
1355
1356 /**
1357  * It is a handler who processes the BR tag.
1358  *
1359  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1360  *                     destination is specified.
1361  * @param node   [i]   The BR tag node is specified.
1362  * @return The conversion result is returned.
1363  */
1364 static char *
1365 s_jhtml_start_br_tag(void *pdoc, Node *node)
1366 {
1367   jhtml_t      *jhtml;
1368   Doc          *doc;
1369   request_rec  *r;
1370   Attr         *attr;
1371
1372   jhtml = GET_JHTML(pdoc);
1373   doc   = jhtml->doc;
1374   r     = doc->r;
1375
1376   W_L("<br");
1377   /*--------------------------------------------------------------------------*/
1378   /* Get Attributes                                                           */
1379   /*--------------------------------------------------------------------------*/
1380   for (attr = qs_get_attr(doc,node);
1381        attr;
1382        attr = qs_get_next_attr(doc,attr)) {
1383     char *name  = qs_get_attr_name(doc,attr);
1384     char *value = qs_get_attr_value(doc,attr);
1385     if (STRCASEEQ('c','C',"clear",name)) {
1386       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('a','A',"all",value))) {
1387         W_L(" clear=\"");
1388         W_V(value);
1389         W_L("\"");
1390       }
1391     }
1392   }
1393   W_L(">");
1394   return jhtml->out;
1395 }
1396
1397
1398 /**
1399  * It is a handler who processes the BR tag.
1400  *
1401  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1402  *                     destination is specified.
1403  * @param node   [i]   The BR tag node is specified.
1404  * @return The conversion result is returned.
1405  */
1406 static char *
1407 s_jhtml_end_br_tag(void *pdoc, Node *UNUSED(child)) 
1408 {
1409   jhtml_t *jhtml = GET_JHTML(pdoc);
1410   return jhtml->out;
1411 }
1412
1413
1414 /**
1415  * It is a handler who processes the TR tag.
1416  *
1417  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1418  *                     destination is specified.
1419  * @param node   [i]   The TR tag node is specified.
1420  * @return The conversion result is returned.
1421  */
1422 static char *
1423 s_jhtml_start_tr_tag(void *pdoc, Node *UNUSED(node)) 
1424 {
1425   jhtml_t      *jhtml;
1426   Doc          *doc;
1427   request_rec  *r;
1428
1429   jhtml = GET_JHTML(pdoc);
1430   doc   = jhtml->doc;
1431   r     = doc->r;
1432
1433   W_L("<br>");
1434   return jhtml->out;
1435 }
1436
1437
1438 /**
1439  * It is a handler who processes the TR tag.
1440  *
1441  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1442  *                     destination is specified.
1443  * @param node   [i]   The TR tag node is specified.
1444  * @return The conversion result is returned.
1445  */
1446 static char *
1447 s_jhtml_end_tr_tag(void *pdoc, Node *UNUSED(child)) 
1448 {
1449   jhtml_t *jhtml = GET_JHTML(pdoc);
1450   return jhtml->out;
1451 }
1452
1453
1454 /**
1455  * It is a handler who processes the FONT tag.
1456  *
1457  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1458  *                     destination is specified.
1459  * @param node   [i]   The FONT tag node is specified.
1460  * @return The conversion result is returned.
1461  */
1462 static char *
1463 s_jhtml_start_font_tag(void *pdoc, Node *node) 
1464 {
1465   jhtml_t       *jhtml;
1466   Doc           *doc;
1467   request_rec   *r;
1468   Attr          *attr;
1469   char          *attr_color = NULL;
1470   char          *attr_style = NULL;
1471
1472   jhtml = GET_JHTML(pdoc);
1473   doc   = jhtml->doc;
1474   r     = doc->r;
1475
1476   /*--------------------------------------------------------------------------*/
1477   /* Get Attributes                                                           */
1478   /*--------------------------------------------------------------------------*/
1479   for (attr = qs_get_attr(doc,node);
1480        attr; 
1481        attr = qs_get_next_attr(doc,attr)) {
1482     char *name  = qs_get_attr_name(doc,attr);
1483     char *value = qs_get_attr_value(doc,attr);
1484     if (STRCASEEQ('c','C',"color",name) && value && *value) {
1485       attr_color = apr_pstrdup(doc->buf.pool, value);
1486       break;
1487     }
1488     else if (STRCASEEQ('s','S',"size",name)) {
1489       /*----------------------------------------------------------------------*/
1490       /* CHTML 5.0                                                            */
1491       /*----------------------------------------------------------------------*/
1492       /* ignore */
1493     }
1494     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
1495       attr_style = apr_pstrdup(doc->buf.pool, value);
1496     }
1497   }
1498   if (IS_CSS_ON(jhtml->entryp)) {
1499     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
1500     if (style) {
1501       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
1502       css_property_t *cur;
1503       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
1504         if (cur->value && *cur->value) {
1505           attr_color = apr_pstrdup(doc->pool, cur->value);
1506         }
1507       }
1508     }
1509   }
1510   if (attr_color) {
1511     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
1512     W_L("<font color=\"");
1513     W_V(attr_color);
1514     W_L("\">");
1515
1516     jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(*flg));
1517     flg->with_font_flag = 1;
1518     node->userData = flg;
1519   }
1520   else {
1521     node->userData = NULL;
1522   }
1523
1524   return jhtml->out;
1525 }
1526
1527
1528 /**
1529  * It is a handler who processes the FONT tag.
1530  *
1531  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1532  *                     destination is specified.
1533  * @param node   [i]   The FONT tag node is specified.
1534  * @return The conversion result is returned.
1535  */
1536 static char *
1537 s_jhtml_end_font_tag(void *pdoc, Node *node)
1538 {
1539   jhtml_t      *jhtml;
1540   request_rec  *r;
1541   Doc          *doc;
1542
1543   jhtml = GET_JHTML(pdoc);
1544   doc   = jhtml->doc;
1545   r     = jhtml->doc->r;
1546
1547   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
1548   if (flg && flg->with_font_flag) {
1549     W_L("</font>");
1550   }
1551   if (IS_CSS_ON(jhtml->entryp)) {
1552     chxj_css_pop_prop_list(jhtml->css_prop_stack);
1553   }
1554
1555   return jhtml->out;
1556 }
1557
1558
1559 /**
1560  * It is a handler who processes the FORM tag.
1561  *
1562  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1563  *                     destination is specified.
1564  * @param node   [i]   The FORM tag node is specified.
1565  * @return The conversion result is returned.
1566  */
1567 static char *
1568 s_jhtml_start_form_tag(void *pdoc, Node *node) 
1569 {
1570   jhtml_t     *jhtml;
1571   Doc         *doc;
1572   request_rec *r;
1573   Attr        *attr;
1574   char        *attr_action = NULL;
1575   char        *attr_method = NULL;
1576   char        *attr_style  = NULL;
1577   char        *attr_color  = NULL;
1578   char        *attr_align  = NULL;
1579   char        *new_hidden_tag = NULL;
1580
1581   jhtml = GET_JHTML(pdoc);
1582   doc     = jhtml->doc;
1583   r       = doc->r;
1584
1585   /*--------------------------------------------------------------------------*/
1586   /* Get Attributes                                                           */
1587   /*--------------------------------------------------------------------------*/
1588   for (attr = qs_get_attr(doc,node);
1589        attr;
1590        attr = qs_get_next_attr(doc,attr)) {
1591     char *name  = qs_get_attr_name(doc,attr);
1592     char *value = qs_get_attr_value(doc,attr);
1593     switch(*name) {
1594     case 'a':
1595     case 'A':
1596       if (strcasecmp(name, "action") == 0) {
1597         /*--------------------------------------------------------------------*/
1598         /* CHTML 1.0                                                          */
1599         /*--------------------------------------------------------------------*/
1600         attr_action = value;
1601       }
1602       break;
1603
1604     case 'm':
1605     case 'M':
1606       if (strcasecmp(name, "method") == 0) {
1607         /*--------------------------------------------------------------------*/
1608         /* CHTML 1.0                                                          */
1609         /*--------------------------------------------------------------------*/
1610         attr_method = value;
1611       }
1612       break;
1613
1614     case 's':
1615     case 'S':
1616       if (strcasecmp(name, "style") == 0) {
1617         attr_style = value;
1618       }
1619       break;
1620
1621     default:
1622       break;
1623     }
1624   }
1625   if (IS_CSS_ON(jhtml->entryp)) {
1626     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
1627     if (style) {
1628       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
1629       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
1630       css_property_t *cur;
1631       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
1632         if (STRCASEEQ('l','L',"left", cur->value)) {
1633           attr_align = apr_pstrdup(doc->pool, "left");
1634         }
1635         else if (STRCASEEQ('c','C',"center",cur->value)) {
1636           attr_align = apr_pstrdup(doc->pool, "center");
1637         }
1638         else if (STRCASEEQ('r','R',"right",cur->value)) {
1639           attr_align = apr_pstrdup(doc->pool, "right");
1640         }
1641       }
1642       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
1643         attr_color = apr_pstrdup(doc->pool, cur->value);
1644       }
1645     }
1646   }
1647
1648   int post_flag = (attr_method && strcasecmp(attr_method, "post") == 0) ? 1 : 0;
1649
1650   W_L("<form");
1651   if (attr_action) {
1652     attr_action = chxj_encoding_parameter(r, attr_action, 0);
1653     attr_action = chxj_add_cookie_parameter(r, attr_action, jhtml->cookie);
1654     char *q;
1655     char *old_qs = NULL;
1656     q = strchr(attr_action, '?');
1657     if (q) {
1658       new_hidden_tag = chxj_form_action_to_hidden_tag(r, doc->pool, attr_action, 0, post_flag, &old_qs, CHXJ_FALSE, CHXJ_TRUE, jhtml->entryp);
1659       if (new_hidden_tag || old_qs) {
1660         *q = 0;
1661       }
1662     }
1663     W_L(" action=\"");
1664     W_V(attr_action);
1665     if (old_qs) {
1666       W_L("?");
1667       W_V(old_qs);
1668     }
1669     W_L("\"");
1670   }
1671   if (attr_method) {
1672     W_L(" method=\"");
1673     W_V(attr_method);
1674     W_L("\"");
1675   }
1676   W_L(">");
1677
1678   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
1679   memset(flg, 0, sizeof(*flg));
1680   if (attr_color) {
1681     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
1682     W_L("<font color=\"");
1683     W_V(attr_color);
1684     W_L("\">");
1685     flg->with_font_flag = 1;
1686   }
1687   if (attr_align) {
1688     W_L("<div align=\"");
1689     W_V(attr_align);
1690     W_L("\">");
1691     flg->with_div_flag = 1;
1692   }
1693   node->userData = flg;
1694   /*-------------------------------------------------------------------------*/
1695   /* Add cookie parameter                                                    */
1696   /*-------------------------------------------------------------------------*/
1697   if (new_hidden_tag) {
1698     W_V(new_hidden_tag);
1699   }
1700   return jhtml->out;
1701 }
1702
1703
1704 /**
1705  * It is a handler who processes the FORM tag.
1706  *
1707  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1708  *                     destination is specified.
1709  * @param node   [i]   The FORM tag node is specified.
1710  * @return The conversion result is returned.
1711  */
1712 static char *
1713 s_jhtml_end_form_tag(void *pdoc, Node *node)
1714 {
1715   jhtml_t *jhtml = GET_JHTML(pdoc);
1716   Doc     *doc   = jhtml->doc;
1717
1718   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
1719   if (flg && flg->with_div_flag) {
1720     W_L("</div>");
1721   }
1722   if (flg && flg->with_font_flag) {
1723     W_L("</font>");
1724   }
1725   W_L("</form>");
1726   if (IS_CSS_ON(jhtml->entryp)) {
1727     chxj_css_pop_prop_list(jhtml->css_prop_stack);
1728   }
1729
1730   return jhtml->out;
1731 }
1732
1733
1734 /**
1735  * It is a handler who processes the INPUT tag.
1736  *
1737  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1738  *                     destination is specified.
1739  * @param node   [i]   The INPUT tag node is specified.
1740  * @return The conversion result is returned.
1741  */
1742 static char *
1743 s_jhtml_start_input_tag(void *pdoc, Node *node) 
1744 {
1745   jhtml_t     *jhtml;
1746   Doc         *doc;
1747   request_rec *r;
1748   Attr        *attr;
1749   char        *attr_accesskey  = NULL;
1750   char        *attr_max_length = NULL;
1751   char        *attr_type       = NULL;
1752   char        *attr_name       = NULL;
1753   char        *attr_value      = NULL;
1754   char        *attr_istyle     = NULL;
1755   char        *attr_size       = NULL;
1756   char        *attr_checked    = NULL;
1757   char        *attr_style      = NULL;
1758
1759   jhtml = GET_JHTML(pdoc);
1760   doc     = jhtml->doc;
1761   r       = doc->r;
1762
1763   /*--------------------------------------------------------------------------*/
1764   /* Get Attributes                                                           */
1765   /*--------------------------------------------------------------------------*/
1766   for (attr = qs_get_attr(doc,node);
1767        attr;
1768        attr = qs_get_next_attr(doc,attr)) {
1769     char *name  = qs_get_attr_name(doc,attr);
1770     char *value = qs_get_attr_value(doc,attr);
1771     if (STRCASEEQ('t','T',"type",name) && value && *value) {
1772       char *tmp_type = qs_trim_string(doc->buf.pool, value);
1773       if (tmp_type && (STRCASEEQ('t','T',"text",    tmp_type) ||
1774                        STRCASEEQ('p','P',"password",tmp_type) ||
1775                        STRCASEEQ('c','C',"checkbox",tmp_type) ||
1776                        STRCASEEQ('r','R',"radio",   tmp_type) ||
1777                        STRCASEEQ('h','H',"hidden",  tmp_type) ||
1778                        STRCASEEQ('s','S',"submit",  tmp_type) ||
1779                        STRCASEEQ('r','R',"reset",   tmp_type))) {
1780         attr_type = tmp_type;
1781       }
1782     }
1783     else if (STRCASEEQ('n','N',"name",name) && value && *value) {
1784       attr_name = value;
1785     }
1786     else if (STRCASEEQ('v','V',"value",name) && value && *value) {
1787       attr_value = value;
1788     }
1789     else if (STRCASEEQ('i','I',"istyle",name) && value && *value) {
1790       attr_istyle = value;
1791     }
1792     else if (STRCASEEQ('m','M',"maxlength",name) && value && *value) {
1793       attr_max_length = value;
1794     }
1795     else if (STRCASEEQ('c','C',"checked", name)) {
1796       attr_checked = value;
1797     }
1798     else if (STRCASEEQ('a','A',"accesskey", name) && value && *value) {
1799       attr_accesskey = value;
1800     }
1801     else if (STRCASEEQ('s','S',"size", name) && value && *value) {
1802       attr_size = value;
1803     }
1804     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
1805       attr_style = value;
1806     }
1807   }
1808
1809   if (IS_CSS_ON(jhtml->entryp)) {
1810     css_prop_list_t *style = s_jhtml_nopush_and_get_now_style(pdoc, node, attr_style);
1811     if (style) {
1812       css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
1813       css_property_t *cur;
1814       for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
1815         if (strcasestr(cur->value, "<ja:n>")) {
1816           attr_istyle = "4";
1817         }
1818         else if (strcasestr(cur->value, "<ja:en>")) {
1819           attr_istyle = "3";
1820         }
1821         else if (strcasestr(cur->value, "<ja:hk>")) {
1822           attr_istyle = "2";
1823         }
1824         else if (strcasestr(cur->value, "<ja:h>")) {
1825           attr_istyle = "1";
1826         }
1827       }
1828     }
1829   }
1830
1831   W_L("<input");
1832   if (attr_type) {
1833     W_L(" type=\"");
1834     W_V(attr_type);
1835     W_L("\"");
1836   }
1837   if (attr_size) {
1838     W_L(" size=\"");
1839     W_V(attr_size);
1840     W_L("\"");
1841   }
1842   if (attr_name) {
1843     W_L(" name=\"");
1844     W_V(chxj_jreserved_to_safe_tag(r, attr_name, jhtml->entryp));
1845     W_L("\"");
1846   }
1847   if (attr_value) {
1848     if (attr_type && (STRCASEEQ('s','S',"submit",attr_type) || STRCASEEQ('r','R',"reset",attr_type))) {
1849       apr_size_t value_len = strlen(attr_value);
1850       attr_value = chxj_conv_z2h(r, attr_value, &value_len, jhtml->entryp);
1851     }
1852
1853     W_L(" value=\"");
1854     W_V(chxj_add_slash_to_doublequote(doc->pool, attr_value));
1855     W_L("\"");
1856   }
1857   if (attr_accesskey) {
1858     W_L(" accesskey=\"");
1859     W_V(attr_accesskey);
1860     W_L("\"");
1861   }
1862   if (attr_istyle && (*attr_istyle == '1' || *attr_istyle == '2' || *attr_istyle == '3' || *attr_istyle == '4')) {
1863     /*------------------------------------------------------------------------*/
1864     /* CHTML 2.0                                                              */
1865     /*------------------------------------------------------------------------*/
1866     if (attr_type && STRCASEEQ('p','P',"password", attr_type) && ! jhtml->entryp->pc_flag ) {
1867       W_L(" mode=\"");
1868       W_L("numeric");
1869       W_L("\"");
1870     }
1871     else {
1872       char *vv = chxj_istyle_to_mode(doc->buf.pool,attr_istyle);
1873       W_L(" mode=\"");
1874       W_V(vv);
1875       W_L("\"");
1876     }
1877   }
1878   else if (attr_type && STRCASEEQ('p','P',"password",attr_type)) {
1879     W_L(" mode=\"");
1880     W_L("numeric");
1881     W_L("\"");
1882   }
1883   /*--------------------------------------------------------------------------*/
1884   /* The figure is default for the password.                                  */
1885   /*--------------------------------------------------------------------------*/
1886   if (attr_max_length && *attr_max_length) {
1887     if (chxj_chk_numeric(attr_max_length) == 0) {
1888       W_L(" maxlength=\"");
1889       W_V(attr_max_length);
1890       W_L("\"");
1891     }
1892   }
1893   if (attr_checked) {
1894     W_L(" checked");
1895   }
1896   W_L(">");
1897
1898   return jhtml->out;
1899 }
1900
1901
1902 /**
1903  * It is a handler who processes the INPUT tag.
1904  *
1905  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1906  *                     destination is specified.
1907  * @param node   [i]   The INPUT tag node is specified.
1908  * @return The conversion result is returned.
1909  */
1910 static char *
1911 s_jhtml_end_input_tag(void *pdoc, Node *UNUSED(child)) 
1912 {
1913   jhtml_t *jhtml = GET_JHTML(pdoc);
1914   return jhtml->out;
1915 }
1916
1917
1918 /**
1919  * It is a handler who processes the CENTER tag.
1920  *
1921  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1922  *                     destination is specified.
1923  * @param node   [i]   The CENTER tag node is specified.
1924  * @return The conversion result is returned.
1925  */
1926 static char *
1927 s_jhtml_start_center_tag(void *pdoc, Node *node)
1928 {
1929   jhtml_t *jhtml;
1930   Doc     *doc;
1931   Attr    *attr;
1932   char    *attr_style = NULL;
1933   char    *attr_color = NULL;
1934   char    *attr_size  = NULL;
1935
1936   jhtml = GET_JHTML(pdoc);
1937   doc     = jhtml->doc;
1938
1939   for (attr = qs_get_attr(doc,node);
1940        attr;
1941        attr = qs_get_next_attr(doc,attr)) {
1942     char *name  = qs_get_attr_name(doc,attr);
1943     char *value = qs_get_attr_value(doc,attr);
1944     if (STRCASEEQ('s','S',"style",name) && value && *value) {
1945       attr_style = value;
1946     }
1947   }
1948   if (IS_CSS_ON(jhtml->entryp)) {
1949     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
1950     if (style) {
1951       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
1952       css_property_t *cur;
1953       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
1954         if (cur->value && *cur->value) {
1955           attr_color = apr_pstrdup(doc->pool, cur->value);
1956         }
1957       }
1958     }
1959   }
1960
1961   W_L("<center>");
1962   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
1963   memset(flg, 0, sizeof(*flg));
1964   if (attr_color || attr_size) {
1965     W_L("<font");
1966     if (attr_color) {
1967       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
1968       W_L(" color=\"");
1969       W_V(attr_color);
1970       W_L("\"");
1971     }
1972     if (attr_size) {
1973       W_L(" size=\"");
1974       W_V(attr_size);
1975       W_L("\"");
1976     }
1977     flg->with_font_flag = 1;
1978     W_L(">");
1979   }
1980   node->userData = flg;
1981
1982   return jhtml->out;
1983 #if 0
1984   jhtml_t *jhtml = GET_JHTML(pdoc);
1985   Doc     *doc   = jhtml->doc;
1986   W_L("<center>");
1987   return jhtml->out;
1988 #endif
1989 }
1990
1991
1992 /**
1993  * It is a handler who processes the CENTER tag.
1994  *
1995  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
1996  *                     destination is specified.
1997  * @param node   [i]   The CENTER tag node is specified.
1998  * @return The conversion result is returned.
1999  */
2000 static char *
2001 s_jhtml_end_center_tag(void *pdoc, Node *node)
2002 {
2003   jhtml_t     *jhtml;
2004   Doc         *doc;
2005   request_rec *r;
2006
2007   jhtml = GET_JHTML(pdoc);
2008   doc   = jhtml->doc;
2009   r     = doc->r;
2010
2011   if (IS_CSS_ON(jhtml->entryp)) {
2012     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2013   }
2014   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
2015   if (flg && flg->with_font_flag) {
2016     W_L("</font>");
2017   }
2018   W_L("</center>");
2019   return jhtml->out;
2020 }
2021
2022
2023 /**
2024  * It is a handler who processes the li tag.
2025  *
2026  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2027  *                     destination is specified.
2028  * @param node   [i]   The li tag node is specified.
2029  * @return The conversion result is returned.
2030  */
2031 static char *
2032 s_jhtml_start_li_tag(void *pdoc, Node *node)
2033 {
2034   jhtml_t     *jhtml;
2035   Doc         *doc;
2036   request_rec *r;
2037   Attr        *attr;
2038   char        *attr_type = NULL;
2039   char        *attr_value = NULL;
2040   char        *attr_style = NULL;
2041
2042   jhtml = GET_JHTML(pdoc);
2043   doc   = jhtml->doc;
2044   r     = doc->r;
2045
2046   for (attr = qs_get_attr(doc,node);
2047        attr;
2048        attr = qs_get_next_attr(doc,attr)) {
2049     char *name = qs_get_attr_name(doc,attr);
2050     char *value = qs_get_attr_value(doc,attr);
2051     if (STRCASEEQ('t','T',"type",name) && value && (*value == '1' || *value == 'a' || *value == 'A')) {
2052       attr_type = value;
2053     }
2054     else if (STRCASEEQ('v','V',"value", name) && value && *value) {
2055       attr_value = value;
2056     }
2057     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
2058       attr_style = value;
2059     }
2060   }
2061   if (IS_CSS_ON(jhtml->entryp)) {
2062     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2063     if (style) {
2064       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
2065       css_property_t *cur;
2066       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
2067         if (STRCASEEQ('d','D',"decimal", cur->value)) {
2068           attr_type = apr_pstrdup(doc->pool, "1");
2069         }
2070         else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
2071           attr_type = apr_pstrdup(doc->pool, "A");
2072         }
2073         else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
2074           attr_type = apr_pstrdup(doc->pool, "a");
2075         }
2076       }
2077     }
2078   }
2079
2080   W_L("<li");
2081   if (attr_type) {
2082     W_L(" type=\"");
2083     W_V(attr_type);
2084     W_L("\"");
2085   }
2086   if (attr_value) {
2087     W_L(" value=\"");
2088     W_V(attr_value);
2089     W_L("\"");
2090   }
2091   W_L(">");
2092   return jhtml->out;
2093 }
2094
2095
2096 /**
2097  * It is a handler who processes the li tag.
2098  *
2099  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2100  *                     destination is specified.
2101  * @param node   [i]   The li tag node is specified.
2102  * @return The conversion result is returned.
2103  */
2104 static char *
2105 s_jhtml_end_li_tag(void *pdoc, Node *UNUSED(child)) 
2106 {
2107   jhtml_t     *jhtml;
2108   Doc         *doc;
2109   request_rec *r;
2110
2111   jhtml = GET_JHTML(pdoc);
2112   doc   = jhtml->doc;
2113   r     = doc->r;
2114
2115   W_L("</li>");
2116   if (IS_CSS_ON(jhtml->entryp)) {
2117     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2118   }
2119   return jhtml->out;
2120 }
2121
2122
2123 /**
2124  * It is a handler who processes the OL tag.
2125  *
2126  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2127  *                     destination is specified.
2128  * @param node   [i]   The OL tag node is specified.
2129  * @return The conversion result is returned.
2130  */
2131 static char *
2132 s_jhtml_start_ol_tag(void *pdoc, Node *node)
2133 {
2134   jhtml_t     *jhtml;
2135   Doc         *doc;
2136   request_rec *r;
2137   Attr        *attr;
2138   char        *attr_style = NULL;
2139   char        *attr_start = NULL;
2140   char        *attr_type  = NULL;
2141
2142   jhtml = GET_JHTML(pdoc);
2143   doc   = jhtml->doc;
2144   r     = doc->r;
2145
2146   /*--------------------------------------------------------------------------*/
2147   /* Get Attributes                                                           */
2148   /*--------------------------------------------------------------------------*/
2149   for (attr = qs_get_attr(doc,node);
2150        attr;
2151        attr = qs_get_next_attr(doc,attr)) {
2152     char *name = qs_get_attr_name(doc,attr);
2153     char *value = qs_get_attr_value(doc,attr);
2154     if (STRCASEEQ('t','T',"type",name) && value && (*value == '1' || *value == 'a' || *value == 'A')) {
2155       attr_type = value;
2156     }
2157     else if (STRCASEEQ('s','S',"start",name) && value && *value) {
2158       attr_start = value;
2159     }
2160     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
2161       attr_style = value;
2162     }
2163   }
2164   if (IS_CSS_ON(jhtml->entryp)) {
2165     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2166     if (style) {
2167       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "list-style-type");
2168       css_property_t *cur;
2169       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
2170         if (STRCASEEQ('d','D',"decimal", cur->value)) {
2171           attr_type = apr_pstrdup(doc->pool, "1");
2172         }
2173         else if (STRCASEEQ('u','U',"upper-alpha", cur->value)) {
2174           attr_type = apr_pstrdup(doc->pool, "A");
2175         }
2176         else if (STRCASEEQ('l','L',"lower-alpha", cur->value)) {
2177           attr_type = apr_pstrdup(doc->pool, "a");
2178         }
2179       }
2180     }
2181   }
2182   W_L("<ol");
2183   if (attr_type) {
2184     W_L(" type=\"");
2185     W_V(attr_type);
2186     W_L("\"");
2187   }
2188   if (attr_start) {
2189     W_L(" start=\"");
2190     W_V(attr_start);
2191     W_L("\"");
2192   }
2193   W_L(">");
2194
2195   return jhtml->out;
2196 }
2197
2198
2199 /**
2200  * It is a handler who processes the OL tag.
2201  *
2202  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2203  *                     destination is specified.
2204  * @param node   [i]   The OL tag node is specified.
2205  * @return The conversion result is returned.
2206  */
2207 static char *
2208 s_jhtml_end_ol_tag(void *pdoc, Node *UNUSED(child)) 
2209 {
2210   jhtml_t     *jhtml;
2211   Doc         *doc;
2212   request_rec *r;
2213
2214   jhtml = GET_JHTML(pdoc);
2215   doc   = jhtml->doc;
2216   r     = doc->r;
2217
2218   W_L("</ol>");
2219   if (IS_CSS_ON(jhtml->entryp)) {
2220     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2221   }
2222   return jhtml->out;
2223 }
2224
2225
2226 /**
2227  * It is a handler who processes the P tag.
2228  *
2229  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2230  *                     destination is specified.
2231  * @param node   [i]   The P tag node is specified.
2232  * @return The conversion result is returned.
2233  */
2234 static char *
2235 s_jhtml_start_p_tag(void *pdoc, Node *node)
2236 {
2237   jhtml_t     *jhtml;
2238   Doc         *doc;
2239   request_rec *r;
2240   Attr        *attr;
2241   char        *attr_align = NULL;
2242   char        *attr_style = NULL;
2243   char        *attr_color = NULL;
2244   char        *attr_blink = NULL;
2245
2246
2247   jhtml = GET_JHTML(pdoc);
2248   doc   = jhtml->doc;
2249   r     = doc->r;
2250
2251   for (attr = qs_get_attr(doc,node);
2252        attr;
2253        attr = qs_get_next_attr(doc,attr)) {
2254     char *nm  = qs_get_attr_name(doc,attr);
2255     char *val = qs_get_attr_value(doc,attr);
2256     if (STRCASEEQ('a','A',"align", nm)) {
2257       /*----------------------------------------------------------------------*/
2258       /* CHTML 1.0 (W3C version 3.2)                                          */
2259       /*----------------------------------------------------------------------*/
2260       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
2261         attr_align = apr_pstrdup(doc->buf.pool, val);
2262         break;
2263       }
2264     }
2265     else if (STRCASEEQ('s','S',"style", nm) && val && *val) {
2266       attr_style = apr_pstrdup(doc->buf.pool, val);
2267     }
2268   }
2269   if (IS_CSS_ON(jhtml->entryp)) {
2270     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2271     if (style) {
2272       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
2273       css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
2274       css_property_t *text_deco_prop  = chxj_css_get_property_value(doc, style, "text-decoration");
2275       css_property_t *cur;
2276       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
2277         if (STRCASEEQ('l','L',"left",cur->value)) {
2278           attr_align = apr_pstrdup(doc->pool, "left");
2279         }
2280         else if (STRCASEEQ('c','C',"center",cur->value)) {
2281           attr_align = apr_pstrdup(doc->pool, "center");
2282         }
2283         else if (STRCASEEQ('r','R',"right",cur->value)) {
2284           attr_align = apr_pstrdup(doc->pool, "right");
2285         }
2286       }
2287       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
2288         if (cur->value && *cur->value) {
2289           attr_color = apr_pstrdup(doc->pool, cur->value);
2290         }
2291       }
2292       for (cur = text_deco_prop->next; cur != text_deco_prop; cur = cur->next) {
2293         if (cur->value && *cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
2294           attr_blink = apr_pstrdup(doc->pool, cur->value);
2295         }
2296       }
2297     }
2298   }
2299   W_L("<p");
2300   if (attr_align) {
2301     W_L(" align=\"");
2302     W_V(attr_align);
2303     W_L("\"");
2304   }
2305   W_L(">");
2306
2307   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
2308   memset(flg, 0, sizeof(*flg));
2309   if (attr_color) {
2310     attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
2311     W_L("<font color=\"");
2312     W_V(attr_color);
2313     W_L("\">");
2314     flg->with_font_flag = 1;
2315   }
2316   if (attr_blink) {
2317     W_L("<blink>");
2318     flg->with_blink_flag = 1;
2319   }
2320   node->userData = (void *)flg;
2321
2322   return jhtml->out;
2323 }
2324
2325
2326 /**
2327  * It is a handler who processes the P tag.
2328  *
2329  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2330  *                     destination is specified.
2331  * @param node   [i]   The P tag node is specified.
2332  * @return The conversion result is returned.
2333  */
2334 static char *
2335 s_jhtml_end_p_tag(void *pdoc, Node *node)
2336 {
2337   jhtml_t   *jhtml = GET_JHTML(pdoc);
2338   Doc       *doc   = jhtml->doc;
2339
2340   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
2341   if (flg->with_font_flag) {
2342     W_L("</font>");
2343   }
2344   if (flg->with_blink_flag) {
2345     W_L("</blink>");
2346   }
2347   W_L("</p>");
2348
2349   if (IS_CSS_ON(jhtml->entryp)) {
2350     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2351   }
2352
2353   return jhtml->out;
2354 }
2355
2356
2357 /**
2358  * It is a handler who processes the PRE tag.
2359  *
2360  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2361  *                     destination is specified.
2362  * @param node   [i]   The PRE tag node is specified.
2363  * @return The conversion result is returned.
2364  */
2365 static char *
2366 s_jhtml_start_pre_tag(void *pdoc, Node *node)
2367 {
2368   jhtml_t  *jhtml = GET_JHTML(pdoc);
2369   Doc      *doc   = jhtml->doc;
2370   Attr      *attr;
2371   char      *attr_style = NULL;
2372
2373   for (attr = qs_get_attr(doc,node);
2374        attr;
2375        attr = qs_get_next_attr(doc,attr)) {
2376     char *nm  = qs_get_attr_name(doc,attr);
2377     char *val = qs_get_attr_value(doc,attr);
2378     if (val && STRCASEEQ('s','S',"style", nm)) {
2379       attr_style = val;
2380     }
2381   }
2382
2383   if (IS_CSS_ON(jhtml->entryp)) {
2384     s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2385   }
2386
2387   jhtml->pre_flag++;
2388   W_L("<pre>");
2389   return jhtml->out;
2390 }
2391
2392
2393 /**
2394  * It is a handler who processes the PRE tag.
2395  *
2396  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2397  *                     destination is specified.
2398  * @param node   [i]   The PRE tag node is specified.
2399  * @return The conversion result is returned.
2400  */
2401 static char *
2402 s_jhtml_end_pre_tag(void *pdoc, Node *UNUSED(child)) 
2403 {
2404   jhtml_t *jhtml = GET_JHTML(pdoc);
2405   Doc     *doc   = jhtml->doc;
2406
2407   W_L("</pre>");
2408   jhtml->pre_flag--;
2409   if (IS_CSS_ON(jhtml->entryp)) {
2410     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2411   }
2412
2413   return jhtml->out;
2414 }
2415
2416
2417 /**
2418  * It is a handler who processes the UL tag.
2419  *
2420  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2421  *                     destination is specified.
2422  * @param node   [i]   The UL tag node is specified.
2423  * @return The conversion result is returned.
2424  */
2425 static char *
2426 s_jhtml_start_ul_tag(void *pdoc, Node *node)
2427 {
2428   jhtml_t *jhtml = GET_JHTML(pdoc);
2429   Doc     *doc   = jhtml->doc;
2430   Attr        *attr;
2431   char        *attr_style = NULL;
2432
2433   for (attr = qs_get_attr(doc,node);
2434        attr;
2435        attr = qs_get_next_attr(doc,attr)) {
2436     char *nm  = qs_get_attr_name(doc,attr);
2437     char *val = qs_get_attr_value(doc,attr);
2438     if (val && STRCASEEQ('s','S',"style", nm)) {
2439       attr_style = val;
2440     }
2441   }
2442
2443   if (IS_CSS_ON(jhtml->entryp)) {
2444     s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2445   }
2446
2447   W_L("<ul>");
2448   return jhtml->out;
2449 }
2450
2451
2452 /**
2453  * It is a handler who processes the UL tag.
2454  *
2455  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2456  *                     destination is specified.
2457  * @param node   [i]   The UL tag node is specified.
2458  * @return The conversion result is returned.
2459  */
2460 static char *
2461 s_jhtml_end_ul_tag(void *pdoc, Node *UNUSED(child)) 
2462 {
2463   jhtml_t *jhtml = GET_JHTML(pdoc);
2464   Doc     *doc   = jhtml->doc;
2465
2466   W_L("</ul>");
2467   if (IS_CSS_ON(jhtml->entryp)) {
2468     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2469   }
2470   return jhtml->out;
2471 }
2472
2473
2474 /**
2475  * It is a handler who processes the HR tag.
2476  *
2477  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2478  *                     destination is specified.
2479  * @param node   [i]   The HR tag node is specified.
2480  * @return The conversion result is returned.
2481  */
2482 static char *
2483 s_jhtml_start_hr_tag(void *pdoc, Node *node) 
2484 {
2485   Attr        *attr;
2486   jhtml_t     *jhtml;
2487   Doc         *doc;
2488   request_rec *r;
2489   char        *attr_align   = NULL;
2490   char        *attr_size    = NULL;
2491   char        *attr_width   = NULL;
2492   char        *attr_noshade = NULL;
2493   char        *attr_style   = NULL;
2494   char        *attr_color   = NULL;
2495
2496   jhtml   = GET_JHTML(pdoc);
2497   doc     = jhtml->doc;
2498   r       = doc->r;
2499
2500   for (attr = qs_get_attr(doc,node);
2501        attr; 
2502        attr = qs_get_next_attr(doc,attr)) {
2503     char *name  = qs_get_attr_name (doc,attr);
2504     char *value = qs_get_attr_value(doc,attr);
2505     switch(*name) {
2506     case 'a':
2507     case 'A':
2508       if (strcasecmp(name, "align") == 0) {
2509         /*--------------------------------------------------------------------*/
2510         /* CHTML 1.0                                                          */
2511         /*--------------------------------------------------------------------*/
2512         if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
2513           attr_align = value;
2514         }
2515       }
2516       break;
2517
2518     case 's':
2519     case 'S':
2520       if (strcasecmp(name, "size") == 0) {
2521         /*--------------------------------------------------------------------*/
2522         /* CHTML 1.0                                                          */
2523         /*--------------------------------------------------------------------*/
2524         if (value && *value) {
2525           attr_size = value;
2526         }
2527       }
2528       else if (strcasecmp(name, "style") == 0) {
2529         if (value && *value) {
2530           attr_style = value;
2531         }
2532       }
2533       break;
2534
2535     case 'w':
2536     case 'W':
2537       if (strcasecmp(name, "width") == 0) {
2538         /*--------------------------------------------------------------------*/
2539         /* CHTML 1.0                                                          */
2540         /*--------------------------------------------------------------------*/
2541         if (value && *value) {
2542           attr_width = value;
2543         }
2544       }
2545       break;
2546
2547     case 'n':
2548     case 'N':
2549       if (strcasecmp(name, "noshade") == 0) {
2550         /*--------------------------------------------------------------------*/
2551         /* CHTML 1.0                                                          */
2552         /*--------------------------------------------------------------------*/
2553         attr_noshade = apr_pstrdup(doc->pool, "noshade");
2554       }
2555       break;
2556
2557     case 'c':
2558     case 'C':
2559       if (strcasecmp(name, "color") == 0 && value && *value) {
2560         /*--------------------------------------------------------------------*/
2561         /* CHTML 4.0                                                          */
2562         /*--------------------------------------------------------------------*/
2563         attr_color = value;
2564       }
2565       break;
2566
2567     default:
2568       break;
2569     }
2570   }
2571   if (IS_CSS_ON(jhtml->entryp)) {
2572     css_prop_list_t *style = s_jhtml_nopush_and_get_now_style(pdoc, node, attr_style);
2573     if (style) {
2574       css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style");
2575       css_property_t *height_prop       = chxj_css_get_property_value(doc, style, "height");
2576       css_property_t *width_prop        = chxj_css_get_property_value(doc, style, "width");
2577       css_property_t *cur;
2578       for (cur = border_style_prop->next; cur != border_style_prop; cur = cur->next) {
2579         if (STRCASEEQ('s','S',"solid",cur->value)) {
2580           attr_noshade = "noshade";
2581         }
2582       }
2583       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
2584         char *tmp = apr_pstrdup(doc->pool, cur->value);
2585         char *tmpp = strstr(tmp, "px");
2586         if (tmpp) { 
2587           *tmpp = 0;
2588           attr_size = apr_pstrdup(doc->pool, tmp);
2589         }
2590       }
2591       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
2592         char *tmp = apr_pstrdup(doc->pool, cur->value);
2593         char *tmpp = strstr(tmp, "px");
2594         if (tmpp) {
2595           *tmpp = 0;
2596           attr_width = apr_pstrdup(doc->pool, tmp);
2597         }
2598         else {
2599           tmpp = strstr(tmp, "%");
2600           if (tmpp) {
2601             attr_width = apr_pstrdup(doc->pool, tmp);
2602           }
2603         }
2604       }
2605     }
2606   }
2607   W_L("<hr");
2608   if (attr_align) {
2609     W_L(" align=\"");
2610     W_V(attr_align);
2611     W_L("\"");
2612   }
2613   if (attr_size) {
2614     W_L(" size=\"");
2615     W_V(attr_size);
2616     W_L("\"");
2617   }
2618   if (attr_width) {
2619     W_L(" width=\"");
2620     W_V(attr_width);
2621     W_L("\"");
2622   }
2623   if (attr_color) {
2624     W_L(" color=\"");
2625     W_V(attr_color);
2626     W_L("\"");
2627   }
2628   if (attr_noshade) {
2629     W_L(" noshade");
2630   }
2631   W_L(">");
2632   return jhtml->out;
2633 }
2634
2635
2636 /**
2637  * It is a handler who processes the HR tag.
2638  *
2639  * @param jhtml  [i/o] The pointer to the CHTML structure at the output
2640  *                     destination is specified.
2641  * @param node   [i]   The HR tag node is specified.
2642  * @return The conversion result is returned.
2643  */
2644 static char *
2645 s_jhtml_end_hr_tag(void *pdoc, Node *UNUSED(child)) 
2646 {
2647   jhtml_t *jhtml = GET_JHTML(pdoc);
2648   return jhtml->out;
2649 }
2650
2651
2652 /**
2653  * It is a handler who processes the IMG tag.
2654  *
2655  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2656  *                     destination is specified.
2657  * @param node   [i]   The IMG tag node is specified.
2658  * @return The conversion result is returned.
2659  */
2660 static char *
2661 s_jhtml_start_img_tag(void *pdoc, Node *node) 
2662 {
2663   jhtml_t     *jhtml;
2664   Doc         *doc;
2665   request_rec *r;
2666   Attr        *attr;
2667   char        *attr_src    = NULL;
2668   char        *attr_align  = NULL;
2669   char        *attr_style  = NULL;
2670   char        *attr_alt    = NULL;
2671   char        *attr_width  = NULL;
2672   char        *attr_height = NULL;
2673 #ifndef IMG_NOT_CONVERT_FILENAME
2674   device_table *spec;
2675 #endif
2676
2677   jhtml = GET_JHTML(pdoc);
2678 #ifndef IMG_NOT_CONVERT_FILENAME
2679   spec    = jhtml->spec;
2680 #endif
2681   doc     = jhtml->doc;
2682   r       = doc->r;
2683
2684   /*--------------------------------------------------------------------------*/
2685   /* Get Attributes                                                           */
2686   /*--------------------------------------------------------------------------*/
2687   for (attr = qs_get_attr(doc,node);
2688        attr;
2689        attr = qs_get_next_attr(doc,attr)) {
2690     char *name  = qs_get_attr_name (doc,attr);
2691     char *value = qs_get_attr_value(doc,attr);
2692     switch(*name) {
2693     case 's':
2694     case 'S':
2695       if (strcasecmp(name, "src") == 0) {
2696         /*--------------------------------------------------------------------*/
2697         /* CHTML 1.0                                                          */
2698         /*--------------------------------------------------------------------*/
2699 #ifdef IMG_NOT_CONVERT_FILENAME
2700       value = chxj_encoding_parameter(r, value, 0);
2701       value = chxj_jreserved_tag_to_safe_for_query_string(r, value, jhtml->entryp, 0);
2702       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
2703       value = chxj_add_cookie_no_update_parameter(r, value);
2704       value = chxj_img_rewrite_parameter(r,jhtml->conf,value);
2705       value = s_add_copyright_parameter(r, value);
2706       attr_src = value;
2707 #else
2708       value = chxj_img_conv(r, spec, value);
2709       value = chxj_encoding_parameter(r, value, 0);
2710       value = chxj_jreserved_tag_to_safe_for_query_string(r, value, jhtml->entryp, 0);
2711       value = chxj_add_cookie_parameter(r, value, jhtml->cookie);
2712       value = chxj_add_cookie_no_update_parameter(r, value);
2713       value = chxj_img_rewrite_parameter(r,jhtml->conf,value);
2714       value = s_add_copyright_parameter(r, value);
2715       attr_src = value;
2716 #endif
2717       }
2718       else if (strcasecmp(name,"style") == 0 && value && *value) {
2719         attr_style = value;
2720       }
2721       break;
2722
2723     case 'a':
2724     case 'A':
2725       if (strcasecmp(name, "align" ) == 0) {
2726         /*--------------------------------------------------------------------*/
2727         /* CHTML 1.0                                                          */
2728         /*--------------------------------------------------------------------*/
2729         /*--------------------------------------------------------------------*/
2730         /* CHTML 4.0                                                          */
2731         /*--------------------------------------------------------------------*/
2732         if (value) {
2733           if (STRCASEEQ('t','T',"top",   value) ||
2734               STRCASEEQ('m','M',"middle",value) ||
2735               STRCASEEQ('b','B',"bottom",value) ||
2736               STRCASEEQ('l','L',"left",  value) ||
2737               STRCASEEQ('r','R',"right", value)) {
2738             attr_align = value;
2739           }
2740           else if (STRCASEEQ('c','C',"center",  value)) {
2741             attr_align = apr_pstrdup(doc->pool, "middle");
2742           }
2743         }
2744       }
2745       else if (strcasecmp(name, "alt"   ) == 0 && value && *value) {
2746         /*--------------------------------------------------------------------*/
2747         /* CHTML 1.0                                                          */
2748         /*--------------------------------------------------------------------*/
2749         attr_alt = value;
2750       }
2751       break;
2752
2753     case 'w':
2754     case 'W':
2755       if (strcasecmp(name, "width" ) == 0 && value && *value) {
2756         /*--------------------------------------------------------------------*/
2757         /* CHTML 1.0                                                          */
2758         /*--------------------------------------------------------------------*/
2759         attr_width = value;
2760       }
2761       break;
2762
2763     case 'h':
2764     case 'H':
2765       if (strcasecmp(name, "height") == 0 && value && *value) {
2766         /*--------------------------------------------------------------------*/
2767         /* CHTML 1.0                                                          */
2768         /*--------------------------------------------------------------------*/
2769         attr_height = value;
2770       }
2771       else
2772       if (strcasecmp(name, "hspace") == 0 && value && *value) {
2773         /*--------------------------------------------------------------------*/
2774         /* CHTML 1.0                                                          */
2775         /*--------------------------------------------------------------------*/
2776       }
2777       break;
2778
2779     case 'v':
2780     case 'V':
2781       if (strcasecmp(name, "vspace") == 0 && value && *value) {
2782         /*--------------------------------------------------------------------*/
2783         /* CHTML 1.0                                                          */
2784         /*--------------------------------------------------------------------*/
2785       }
2786       break;
2787
2788     default:
2789       break;
2790     }
2791   }
2792
2793   if (IS_CSS_ON(jhtml->entryp)) {
2794     css_prop_list_t *style = s_jhtml_nopush_and_get_now_style(pdoc, node, attr_style);
2795     if (style) {
2796       css_property_t *height_prop = chxj_css_get_property_value(doc, style, "height");
2797       css_property_t *width_prop  = chxj_css_get_property_value(doc, style, "width");
2798       css_property_t *valign_prop = chxj_css_get_property_value(doc, style, "vertical-align");
2799       css_property_t *cur;
2800       for (cur = height_prop->next; cur != height_prop; cur = cur->next) {
2801         attr_height = apr_pstrdup(doc->pool, cur->value);
2802       }
2803       for (cur = width_prop->next; cur != width_prop; cur = cur->next) {
2804         attr_width = apr_pstrdup(doc->pool, cur->value);
2805       }
2806       for (cur = valign_prop->next; cur != valign_prop; cur = cur->next) {
2807         attr_align = apr_pstrdup(doc->pool, cur->value);
2808       }
2809     }
2810   }
2811
2812   W_L("<img");
2813   if (attr_src) {
2814     W_L(" src=\"");
2815     W_V(attr_src);
2816     W_L("\"");
2817   }
2818   if (attr_align) {
2819     W_L(" align=\"");
2820     W_V(attr_align);
2821     W_L("\"");
2822   }
2823   if (attr_alt) {
2824     W_L(" alt=\"");
2825     W_V(attr_alt);
2826     W_L("\"");
2827   }
2828   if (attr_width) {
2829     W_L(" width=\"");
2830     W_V(attr_width);
2831     W_L("\"");
2832   }
2833   if (attr_height) {
2834     W_L(" height=\"");
2835     W_V(attr_height);
2836     W_L("\"");
2837   }
2838   W_L(">");
2839   return jhtml->out;
2840 }
2841
2842
2843 /**
2844  * It is a handler who processes the IMG tag.
2845  *
2846  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2847  *                     destination is specified.
2848  * @param node   [i]   The IMG tag node is specified.
2849  * @return The conversion result is returned.
2850  */
2851 static char *
2852 s_jhtml_end_img_tag(void *pdoc, Node *UNUSED(child)) 
2853 {
2854   jhtml_t *jhtml = GET_JHTML(pdoc);
2855   return jhtml->out;
2856 }
2857
2858
2859 /**
2860  * It is a handler who processes the SELECT tag.
2861  *
2862  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2863  *                     destination is specified.
2864  * @param node   [i]   The SELECT tag node is specified.
2865  * @return The conversion result is returned.
2866  */
2867 static char *
2868 s_jhtml_start_select_tag(void *pdoc, Node *node)
2869 {
2870   jhtml_t *jhtml    = GET_JHTML(pdoc);
2871   Doc     *doc      = jhtml->doc;
2872   Attr    *attr;
2873   char    *size     = NULL;
2874   char    *name     = NULL;
2875   char    *multiple = NULL;
2876   char    *attr_style = NULL;
2877
2878   W_L("<select");
2879   for (attr = qs_get_attr(doc,node);
2880        attr;
2881        attr = qs_get_next_attr(doc,attr)) {
2882     char *nm  = qs_get_attr_name(doc,attr);
2883     char *val = qs_get_attr_value(doc,attr);
2884     if (STRCASEEQ('s','S',"size",nm)) {
2885       /*----------------------------------------------------------------------*/
2886       /* CHTML 1.0 version 2.0                                                */
2887       /*----------------------------------------------------------------------*/
2888       size = apr_pstrdup(doc->buf.pool, val);
2889     }
2890     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
2891       /*----------------------------------------------------------------------*/
2892       /* CHTML 1.0 version 2.0                                                */
2893       /*----------------------------------------------------------------------*/
2894       attr_style = apr_pstrdup(doc->buf.pool, val);
2895     }
2896     else if (STRCASEEQ('n','N',"name",nm)) {
2897       /*----------------------------------------------------------------------*/
2898       /* CHTML 1.0 version 2.0                                                */
2899       /*----------------------------------------------------------------------*/
2900       name = apr_pstrdup(doc->buf.pool, val);
2901     }
2902     else if (STRCASEEQ('m','M',"multiple", nm)) {
2903       /*----------------------------------------------------------------------*/
2904       /* CHTML 1.0 version 2.0                                                */
2905       /*----------------------------------------------------------------------*/
2906       multiple = apr_pstrdup(doc->buf.pool, val);
2907     }
2908   }
2909   if (size && *size) {
2910     W_L(" size=\"");
2911     W_V(size);
2912     W_L("\"");
2913   }
2914   if (name && *name) {
2915     W_L(" name=\"");
2916     W_V(name);
2917     W_L("\"");
2918   }
2919   if (multiple) {
2920     W_L(" multiple");
2921   }
2922   W_L(">");
2923   if (IS_CSS_ON(jhtml->entryp)) {
2924     s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
2925   }
2926   return jhtml->out;
2927 }
2928
2929
2930 /**
2931  * It is a handler who processes the SELECT tag.
2932  *
2933  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2934  *                     destination is specified.
2935  * @param node   [i]   The SELECT tag node is specified.
2936  * @return The conversion result is returned.
2937  */
2938 static char *
2939 s_jhtml_end_select_tag(void *pdoc, Node *UNUSED(child))
2940 {
2941   jhtml_t *jhtml = GET_JHTML(pdoc);
2942   Doc     *doc   = jhtml->doc;
2943
2944   W_L("</select>");
2945   if (IS_CSS_ON(jhtml->entryp)) {
2946     chxj_css_pop_prop_list(jhtml->css_prop_stack);
2947   }
2948   return jhtml->out;
2949 }
2950
2951 /**
2952  * It is a handler who processes the OPTION tag.
2953  *
2954  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
2955  *                     destination is specified.
2956  * @param node   [i]   The OPTION tag node is specified.
2957  * @return The conversion result is returned.
2958  */
2959 static char *
2960 s_jhtml_start_option_tag(void *pdoc, Node *node)
2961 {
2962   jhtml_t *jhtml = GET_JHTML(pdoc);
2963   Doc     *doc   = jhtml->doc;
2964   Attr    *attr;
2965
2966   char *selected   = NULL;
2967   char *value      = NULL;
2968   char *attr_style = NULL;
2969
2970   W_L("<option");
2971   for (attr = qs_get_attr(doc,node);
2972        attr;
2973        attr = qs_get_next_attr(doc,attr)) {
2974     char *nm  = qs_get_attr_name(doc,attr);
2975     char *val = qs_get_attr_value(doc,attr);
2976     if (STRCASEEQ('s','S',"selected",nm)) {
2977       /*----------------------------------------------------------------------*/
2978       /* CHTML 1.0 version 2.0                                                */
2979       /*----------------------------------------------------------------------*/
2980       selected = apr_pstrdup(doc->buf.pool, val);
2981     }
2982     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
2983       /*----------------------------------------------------------------------*/
2984       /* CHTML 1.0 version 2.0                                                */
2985       /*----------------------------------------------------------------------*/
2986       attr_style = apr_pstrdup(doc->buf.pool, val);
2987     }
2988     else if (STRCASEEQ('v','V',"value",nm)) {
2989       /*----------------------------------------------------------------------*/
2990       /* CHTML 1.0 version 2.0                                                */
2991       /*----------------------------------------------------------------------*/
2992       value = apr_pstrdup(doc->buf.pool, val);
2993     }
2994   }
2995   if (value) {
2996     W_L(" value=\"");
2997     W_V(value);
2998     W_L("\"");
2999   }
3000   if (selected) {
3001     W_L(" selected");
3002   }
3003   W_L(">");
3004
3005   if (IS_CSS_ON(jhtml->entryp)) {
3006     s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
3007   }
3008
3009   return jhtml->out;
3010 }
3011
3012
3013 /**
3014  * It is a handler who processes the OPTION tag.
3015  *
3016  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3017  *                     destination is specified.
3018  * @param node   [i]   The OPTION tag node is specified.
3019  * @return The conversion result is returned.
3020  */
3021 static char *
3022 s_jhtml_end_option_tag(void *pdoc, Node *UNUSED(child))
3023 {
3024   jhtml_t *jhtml = GET_JHTML(pdoc);
3025   /* Don't close */
3026   if (IS_CSS_ON(jhtml->entryp)) {
3027     chxj_css_pop_prop_list(jhtml->css_prop_stack);
3028   }
3029   return jhtml->out;
3030 }
3031
3032
3033 /**
3034  * It is a handler who processes the DIV tag.
3035  *
3036  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3037  *                     destination is specified.
3038  * @param node   [i]   The DIV tag node is specified.
3039  * @return The conversion result is returned.
3040  */
3041 static char *
3042 s_jhtml_start_div_tag(void *pdoc, Node *node)
3043 {
3044   jhtml_t     *jhtml;
3045   Doc         *doc;
3046   request_rec *r;
3047   Attr        *attr;
3048   char        *attr_style             = NULL;
3049   char        *attr_align             = NULL;
3050   char        *attr_display           = NULL;
3051   char        *attr_decoration        = NULL;
3052   char        *attr_wap_marquee_style = NULL;
3053   char        *attr_wap_marquee_dir   = NULL;
3054   char        *attr_wap_marquee_loop  = NULL;
3055   char        *attr_color             = NULL;
3056   char        *attr_bgcolor           = NULL;
3057   char        *attr_font_size         = NULL;
3058
3059   jhtml = GET_JHTML(pdoc);
3060   doc     = jhtml->doc;
3061   r       = doc->r;
3062
3063   for (attr = qs_get_attr(doc,node);
3064        attr;
3065        attr = qs_get_next_attr(doc,attr)) {
3066     char *nm  = qs_get_attr_name(doc,attr);
3067     char *val = qs_get_attr_value(doc,attr);
3068     if (STRCASEEQ('a','A', "align", nm)) {
3069       /*----------------------------------------------------------------------*/
3070       /* CHTML 1.0 (W3C version 3.2)                                          */
3071       /*----------------------------------------------------------------------*/
3072       if (val && (STRCASEEQ('l','L',"left",val) || STRCASEEQ('r','R',"right",val) || STRCASEEQ('c','C',"center",val))) {
3073         attr_align = apr_pstrdup(doc->buf.pool, val);
3074       }
3075     }
3076     else if (STRCASEEQ('s','S',"style",nm) && val && *val) {
3077       attr_style = apr_pstrdup(doc->buf.pool, val);
3078     }
3079   }
3080
3081   if (IS_CSS_ON(jhtml->entryp)) {
3082     css_prop_list_t *style = s_jhtml_nopush_and_get_now_style(pdoc, node, attr_style);
3083     if (style) {
3084       css_property_t *display_prop           = chxj_css_get_property_value(doc, style, "display");
3085       css_property_t *text_decoration_prop   = chxj_css_get_property_value(doc, style, "text-decoration");
3086       css_property_t *color_prop             = chxj_css_get_property_value(doc, style, "color");
3087       css_property_t *text_align_prop        = chxj_css_get_property_value(doc, style, "text-align");
3088       css_property_t *font_size_prop         = chxj_css_get_property_value(doc, style, "font-size");
3089       css_property_t *background_color_prop  = chxj_css_get_property_value(doc, style, "background-color");
3090       css_property_t *background_prop        = chxj_css_get_property_value(doc, style, "background");
3091
3092       css_property_t *cur;
3093       for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
3094         if (strcasecmp("-wap-marquee", cur->value) == 0) {
3095           attr_display = apr_pstrdup(doc->pool, cur->value);
3096         }
3097       }
3098       for (cur = text_decoration_prop->next; cur != text_decoration_prop; cur = cur->next) {
3099         if (STRCASEEQ('b','B',"blink", cur->value)) {
3100           attr_decoration = apr_pstrdup(doc->pool, cur->value);
3101         }
3102       }
3103       for (cur = background_color_prop->next; cur != background_color_prop; cur = cur->next) {
3104         attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
3105         attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
3106       }
3107       for (cur = background_prop->next; cur != background_prop; cur = cur->next) {
3108         char *ss = strchr(cur->value, '#');
3109         if (!ss || !*ss) {
3110           ss = strstr(cur->value, "rgb");
3111         }
3112         if (ss && *ss) {
3113           attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
3114           attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
3115         }
3116       }
3117       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3118         attr_color = apr_pstrdup(doc->pool, cur->value);
3119       }
3120       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
3121         attr_align = apr_pstrdup(doc->pool, cur->value);
3122       }
3123       for (cur = font_size_prop->next; cur != font_size_prop; cur = cur->next) {
3124         attr_font_size = apr_pstrdup(doc->pool, cur->value);
3125         if (STRCASEEQ('x','X',"xx-small",attr_font_size)) {
3126           attr_font_size = apr_pstrdup(doc->pool, "1");
3127         }
3128         else if (STRCASEEQ('x','X',"x-small",attr_font_size)) {
3129           attr_font_size = apr_pstrdup(doc->pool, "2");
3130         }
3131         else if (STRCASEEQ('s','S',"small",attr_font_size)) {
3132           attr_font_size = apr_pstrdup(doc->pool, "3");
3133         }
3134         else if (STRCASEEQ('m','M',"medium",attr_font_size)) {
3135           attr_font_size = apr_pstrdup(doc->pool, "4");
3136         }
3137         else if (STRCASEEQ('l','L',"large",attr_font_size)) {
3138           attr_font_size = apr_pstrdup(doc->pool, "5");
3139         }
3140         else if (STRCASEEQ('x','X',"x-large",attr_font_size)) {
3141           attr_font_size = apr_pstrdup(doc->pool, "6");
3142         }
3143         else if (STRCASEEQ('x','X',"xx-large",attr_font_size)) {
3144           attr_font_size = apr_pstrdup(doc->pool, "7");
3145         }
3146       }
3147       if (attr_display) {
3148         css_property_t *wap_marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
3149         css_property_t *wap_marquee_dir_prop   = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
3150         css_property_t *wap_marquee_loop_prop  = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
3151         for (cur = wap_marquee_style_prop->next; cur != wap_marquee_style_prop; cur = cur->next) {
3152           if (STRCASEEQ('s','S',"scroll", cur->value) || STRCASEEQ('s','S',"slide",cur->value) || STRCASEEQ('a','A',"alternate",cur->value)) {
3153             attr_wap_marquee_style = apr_pstrdup(doc->pool, cur->value);
3154           }
3155         }
3156         for (cur = wap_marquee_dir_prop->next; cur != wap_marquee_dir_prop; cur = cur->next) {
3157           if (STRCASEEQ('l','L',"ltr",cur->value)) {
3158             attr_wap_marquee_dir = apr_pstrdup(doc->pool, "right");
3159           }
3160           else if (STRCASEEQ('r','R',"rtl",cur->value)) {
3161             attr_wap_marquee_dir = apr_pstrdup(doc->pool, "left");
3162           }
3163         }
3164         for (cur = wap_marquee_loop_prop->next; cur != wap_marquee_loop_prop; cur = cur->next) {
3165           if (STRCASEEQ('i','I',"infinite",cur->value)) {
3166             attr_wap_marquee_loop = apr_pstrdup(doc->pool, "16");
3167           }
3168           else {
3169             attr_wap_marquee_loop = apr_pstrdup(doc->pool, cur->value);
3170           }
3171         }
3172       }
3173     }
3174   }  
3175   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
3176   memset(flg, 0, sizeof(*flg));
3177   if (attr_align) {
3178     W_L("<div");
3179     W_L(" align=\"");
3180     W_V(attr_align);
3181     W_L("\"");
3182     W_L(">");
3183     flg->with_div_flag = 1;
3184   }
3185   if ((attr_color
3186       && ! ((STRCASEEQ('w','W',"white",attr_color) || STRCASEEQ('#','#',"#ffffff",attr_color)) && attr_bgcolor))
3187       || attr_font_size) {
3188     W_L("<font");
3189     if (attr_color) {
3190       W_L(" color=\"");
3191       W_V(attr_color);
3192       W_L("\"");
3193     }
3194     if (attr_font_size) {
3195       W_L(" size=\"");
3196       W_V(attr_font_size);
3197       W_L("\"");
3198     }
3199     W_L(">");
3200     flg->with_font_flag = 1;
3201   }
3202   if (attr_decoration) {
3203     W_L("<blink>");
3204     flg->with_blink_flag = 1;
3205   }
3206   if (attr_display) {
3207     W_L("<marquee");
3208     if (attr_wap_marquee_style) {
3209       W_L(" behavior=\"");
3210       W_V(attr_wap_marquee_style);
3211       W_L("\"");
3212     }
3213     if (attr_wap_marquee_dir) {
3214       W_L(" direction=\"");
3215       W_V(attr_wap_marquee_dir);
3216       W_L("\"");
3217     }
3218     if (attr_wap_marquee_loop) {
3219       W_L(" loop=\"");
3220       W_V(attr_wap_marquee_loop);
3221       W_L("\"");
3222     }
3223     W_L(">");
3224     flg->with_marquee_flag = 1;
3225   }
3226   if (!attr_align && !attr_color && !attr_decoration && !attr_display && !attr_font_size) {
3227     W_L("<div>");
3228     flg->with_div_flag = 1;
3229   }
3230   node->userData = flg;
3231
3232   return jhtml->out;
3233 }
3234
3235
3236 /**
3237  * It is a handler who processes the DIV tag.
3238  *
3239  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3240  *                     destination is specified.
3241  * @param node   [i]   The DIV tag node is specified.
3242  * @return The conversion result is returned.
3243  */
3244 static char *
3245 s_jhtml_end_div_tag(void *pdoc, Node *node)
3246 {
3247   jhtml_t    *jhtml = GET_JHTML(pdoc);
3248   Doc          *doc = jhtml->doc;
3249
3250   jhtml_flags_t *flg = node->userData;
3251   if (flg && flg->with_marquee_flag) {
3252     W_L("</marquee>");
3253   }
3254   if (flg && flg->with_blink_flag) {
3255     W_L("</blink>");
3256   }
3257   if (flg && flg->with_font_flag) {
3258     W_L("</font>");
3259   }
3260   if (flg && flg->with_div_flag) {
3261     W_L("</div>");
3262   }
3263   if (IS_CSS_ON(jhtml->entryp)) {
3264     chxj_css_pop_prop_list(jhtml->css_prop_stack);
3265   }
3266   node->userData = NULL;
3267
3268   return jhtml->out;
3269 }
3270
3271
3272 static char *
3273 chxj_istyle_to_mode(apr_pool_t *p, const char *s)
3274 {
3275   char *tmp;
3276
3277   if (s) {
3278     switch (s[0]) {
3279     case '1': return apr_psprintf(p, "hiragana");
3280     case '2': return apr_psprintf(p, "hankakukana");
3281     case '3': return apr_psprintf(p, "alphabet");
3282     case '4': return apr_psprintf(p, "numeric");
3283     default: 
3284       tmp = apr_palloc(p, 1);
3285       tmp[0] = '\0';
3286       return apr_pstrdup(p, tmp);
3287     }
3288   }
3289
3290   tmp = apr_palloc(p, 1);
3291   tmp[0] = '\0';
3292   return apr_pstrdup(p,tmp);
3293 }
3294
3295
3296 static char *
3297 s_jhtml_chxjif_tag(void *pdoc, Node *node)
3298 {
3299   jhtml_t *jhtml;
3300   Doc     *doc;
3301   Node    *child;
3302   request_rec *r;
3303
3304   jhtml = GET_JHTML(pdoc);
3305   doc   = jhtml->doc;
3306   r     = doc->r;
3307
3308   for (child = qs_get_child_node(doc, node);
3309        child;
3310        child = qs_get_next_node(doc, child)) {
3311     W_V(child->otext);
3312     s_jhtml_chxjif_tag(jhtml, child);
3313   }
3314   return NULL;
3315 }
3316
3317
3318 /**
3319  * It is a handler who processes the TEXTARE tag.
3320  *
3321  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3322  *                     destination is specified.
3323  * @param node   [i]   The TEXTAREA tag node is specified.
3324  * @return The conversion result is returned.
3325  */
3326 static char *
3327 s_jhtml_start_textarea_tag(void *pdoc, Node *node) 
3328 {
3329   jhtml_t       *jhtml;
3330   Doc           *doc;
3331   request_rec   *r;
3332   Attr          *attr;
3333   char          *attr_accesskey = NULL;
3334   char          *attr_name      = NULL;
3335   char          *attr_rows      = NULL;
3336   char          *attr_cols      = NULL;
3337   char          *attr_istyle    = NULL;
3338   char          *attr_style     = NULL;
3339
3340   jhtml = GET_JHTML(pdoc);
3341   doc   = jhtml->doc;
3342   r     = doc->r;
3343
3344   jhtml->textarea_flag++;
3345   for (attr = qs_get_attr(doc,node);
3346        attr;
3347        attr = qs_get_next_attr(doc,attr)) {
3348     char *name  = qs_get_attr_name(doc,attr);
3349     char *value = qs_get_attr_value(doc,attr);
3350     if (STRCASEEQ('a','A',"accesskey",name) && value && *value != 0) {
3351       attr_accesskey = value;
3352     }
3353     else if (STRCASEEQ('i','I',"istyle", name) && value && (*value == '1' || *value == '2' || *value == '3' || *value == '4')) {
3354       attr_istyle = value;
3355     }
3356     else if (STRCASEEQ('n','N',"name", name) && value && *value) {
3357       attr_name = value;
3358     }
3359     else if (STRCASEEQ('r','R',"rows", name) && value && *value) {
3360       attr_rows = value;
3361     }
3362     else if (STRCASEEQ('c','C',"cols", name) && value && *value) {
3363       attr_cols = value;
3364     }
3365     else if (STRCASEEQ('s','S',"style", name) && value && *value) {
3366       attr_style = value;
3367     }
3368   }
3369   if (IS_CSS_ON(jhtml->entryp)) {
3370     css_prop_list_t *style = s_jhtml_nopush_and_get_now_style(pdoc, node, attr_style);
3371     if (style) {
3372       css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format");
3373       css_property_t *cur;
3374       for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) {
3375         if (strcasestr(cur->value, "<ja:n>")) {
3376           attr_istyle = "4";
3377         }
3378         else if (strcasestr(cur->value, "<ja:en>")) {
3379           attr_istyle = "3";
3380         }
3381         else if (strcasestr(cur->value, "<ja:hk>")) {
3382           attr_istyle = "2";
3383         }
3384         else if (strcasestr(cur->value, "<ja:h>")) {
3385           attr_istyle = "1";
3386         }
3387       }
3388     }
3389   }
3390   W_L("<textarea");
3391   if (attr_accesskey) {
3392     W_L(" accesskey=\"");
3393     W_V(attr_accesskey);
3394     W_L("\"");
3395   }
3396   if (attr_name) {
3397     W_L(" name=\"");
3398     W_V(attr_name);
3399     W_L("\"");
3400   }
3401   if (attr_rows) {
3402     W_L(" rows=\"");
3403     W_V(attr_rows);
3404     W_L("\"");
3405   }
3406   if (attr_cols) {
3407     W_L(" cols=\"");
3408     W_V(attr_cols);
3409     W_L("\"");
3410   }
3411   if (attr_istyle) {
3412     char *vv = chxj_istyle_to_mode(doc->buf.pool,attr_istyle);
3413     W_L(" mode=\"");
3414     W_V(vv);
3415     W_L("\"");
3416   }
3417   W_L(">");
3418   return jhtml->out;
3419 }
3420
3421
3422 /**
3423  * It is a handler who processes the TEXTAREA tag.
3424  *
3425  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3426  *                     destination is specified.
3427  * @param node   [i]   The TEXTAREA tag node is specified.
3428  * @return The conversion result is returned.
3429  */
3430 static char *
3431 s_jhtml_end_textarea_tag(void *pdoc, Node *UNUSED(child)) 
3432 {
3433   jhtml_t       *jhtml;
3434   Doc           *doc;
3435   request_rec   *r;
3436
3437   jhtml = GET_JHTML(pdoc);
3438   doc   = jhtml->doc;
3439   r     = doc->r;
3440
3441   W_L("</textarea>");
3442   jhtml->textarea_flag--;
3443
3444   return jhtml->out;
3445 }
3446
3447
3448 /**
3449  * It is a handler who processes the B tag.
3450  *
3451  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3452  *                     destination is specified.
3453  * @param node   [i]   The B tag node is specified.
3454  * @return The conversion result is returned.
3455  */
3456 static char*
3457 s_jhtml_start_b_tag(void* pdoc, Node* UNUSED(node)) 
3458 {
3459   jhtml_t*      jhtml;
3460   Doc*          doc;
3461   request_rec*  r;
3462
3463   jhtml = GET_JHTML(pdoc);
3464   doc   = jhtml->doc;
3465   r     = doc->r;
3466
3467   W_L("<b>");
3468   return jhtml->out;
3469 }
3470
3471
3472 /**
3473  * It is a handler who processes the B tag.
3474  *
3475  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
3476  *                     destination is specified.
3477  * @param node   [i]   The B tag node is specified.
3478  * @return The conversion result is returned.
3479  */
3480 static char*
3481 s_jhtml_end_b_tag(void* pdoc, Node* UNUSED(child)) 
3482 {
3483   jhtml_t*      jhtml = GET_JHTML(pdoc);
3484   Doc*          doc   = jhtml->doc;
3485
3486   W_L("</b>");
3487   return jhtml->out;
3488 }
3489
3490 static char*
3491 s_jhtml_text_tag(void *pdoc, Node *child)
3492 {
3493   jhtml_t      *jhtml;
3494   Doc          *doc;
3495   char         *textval;
3496   char         *tmp;
3497   char         *tdst;
3498   char         one_byte[2];
3499   int          ii;
3500   int          tdst_len;
3501   request_rec  *r;
3502   apr_size_t   z2h_input_len;
3503
3504   jhtml = GET_JHTML(pdoc);
3505   doc   = jhtml->doc;
3506   r     = doc->r;
3507   DBG(r, "start s_jhtml_text_tag()");
3508
3509   textval = qs_get_node_value(doc,child);
3510   if (strlen(textval) == 0) {
3511     return jhtml->out;
3512   }
3513
3514   tmp = apr_palloc(r->pool, qs_get_node_size(doc,child)+1);
3515   memset(tmp, 0, qs_get_node_size(doc,child)+1);
3516
3517   tdst     = qs_alloc_zero_byte_string(r->pool);
3518   memset(one_byte, 0, sizeof(one_byte));
3519   tdst_len = 0;
3520
3521   for (ii=0; ii<qs_get_node_size(doc,child); ii++) {
3522     char* out;
3523     int rtn = s_jhtml_search_emoji(jhtml, &textval[ii], &out);
3524     if (rtn) {
3525       tdst = qs_out_apr_pstrcat(r, tdst, out, &tdst_len);
3526       ii+=(rtn - 1);
3527       continue;
3528     }
3529
3530     if (is_sjis_kanji(textval[ii])) {
3531       one_byte[0] = textval[ii+0];
3532       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
3533       one_byte[0] = textval[ii+1];
3534       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
3535       ii++;
3536     }
3537     else 
3538     if (jhtml->pre_flag) {
3539       one_byte[0] = textval[ii+0];
3540       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
3541     }
3542     else
3543     if (jhtml->textarea_flag) {
3544       one_byte[0] = textval[ii+0];
3545       tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
3546     }
3547     else {
3548       if (textval[ii] != '\r' && textval[ii] != '\n') {
3549         one_byte[0] = textval[ii+0];
3550         tdst = qs_out_apr_pstrcat(r, tdst, one_byte, &tdst_len);
3551       }
3552     }
3553   }
3554   z2h_input_len = strlen(tdst);
3555   tdst = chxj_conv_z2h(r, tdst, &z2h_input_len, jhtml->entryp);
3556
3557   W_V(tdst);
3558   DBG(r, "end s_jhtml_text_tag()");
3559   return jhtml->out;
3560 }
3561
3562
3563 /**
3564  * It is a handler who processes the BLOCKQUOTE tag.
3565  *
3566  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3567  *                     destination is specified.
3568  * @param node   [i]   The BLOCKQUOTE tag node is specified.
3569  * @return The conversion result is returned.
3570  */
3571 static char *
3572 s_jhtml_start_blockquote_tag(void *pdoc, Node *node)
3573 {
3574   jhtml_t *jhtml;
3575   Doc     *doc;
3576   Attr    *attr;
3577   char    *attr_style = NULL;
3578   char    *attr_color = NULL;
3579   char    *attr_size  = NULL;
3580
3581   jhtml   = GET_JHTML(pdoc);
3582   doc     = jhtml->doc;
3583   for (attr = qs_get_attr(doc,node);
3584        attr;
3585        attr = qs_get_next_attr(doc,attr)) {
3586     char *nm  = qs_get_attr_name(doc,attr);
3587     char *val = qs_get_attr_value(doc,attr);
3588     if (val && STRCASEEQ('s','S',"style", nm)) {
3589       attr_style = val;
3590     }
3591   }
3592   if (IS_CSS_ON(jhtml->entryp)) {
3593     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
3594     if (style) {
3595       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
3596       css_property_t *font_size_prop = chxj_css_get_property_value(doc, style, "font-size");
3597       css_property_t *cur;
3598       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3599         if (cur->value && *cur->value) {
3600           attr_color = apr_pstrdup(doc->pool, cur->value);
3601         }
3602       }
3603       for (cur = font_size_prop->next; cur != font_size_prop; cur = cur->next) {
3604         if (cur->value && *cur->value) {
3605           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
3606             attr_size = apr_pstrdup(doc->pool, "1");
3607           }
3608           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
3609             attr_size = apr_pstrdup(doc->pool, "2");
3610           }
3611           else if (STRCASEEQ('s','S',"small",cur->value)) {
3612             attr_size = apr_pstrdup(doc->pool, "3");
3613           }
3614           else if (STRCASEEQ('m','M',"medium",cur->value)) {
3615             attr_size = apr_pstrdup(doc->pool, "4");
3616           }
3617           else if (STRCASEEQ('l','L',"large",cur->value)) {
3618             attr_size = apr_pstrdup(doc->pool, "5");
3619           }
3620           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
3621             attr_size = apr_pstrdup(doc->pool, "6");
3622           }
3623           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
3624             attr_size = apr_pstrdup(doc->pool, "7");
3625           }
3626         }
3627       }
3628     }
3629   }
3630   W_L("<blockquote>");
3631   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
3632   memset(flg, 0, sizeof(*flg));
3633   if (attr_color || attr_size) {
3634     W_L("<font");
3635     if (attr_color) {
3636       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
3637       W_L(" color=\"");
3638       W_V(attr_color);
3639       W_L("\"");
3640     }
3641     if (attr_size) {
3642       W_L(" size=\"");
3643       W_V(attr_size);
3644       W_L("\"");
3645     }
3646     W_L(">");
3647     flg->with_font_flag = 1;
3648   }
3649   node->userData = (void *)flg;
3650   return jhtml->out;
3651 }
3652
3653
3654 /**
3655  * It is a handler who processes the BLOCKQUOTE tag.
3656  *
3657  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3658  *                     destination is specified.
3659  * @param node   [i]   The BLOCKQUOTE tag node is specified.
3660  * @return The conversion result is returned.
3661  */
3662 static char *
3663 s_jhtml_end_blockquote_tag(void *pdoc, Node *node)
3664 {
3665   jhtml_t *jhtml = GET_JHTML(pdoc);
3666   Doc     *doc     = jhtml->doc;
3667   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
3668   if (flg && flg->with_font_flag) {
3669     W_L("</font>");
3670   }
3671   W_L("</blockquote>");
3672   if (IS_CSS_ON(jhtml->entryp)) {
3673     chxj_css_pop_prop_list(jhtml->css_prop_stack);
3674   }
3675   return jhtml->out;
3676 }
3677
3678
3679 /**
3680  * It is a handler who processes the DIR tag.
3681  *
3682  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3683  *                     destination is specified.
3684  * @param node   [i]   The DIR tag node is specified.
3685  * @return The conversion result is returned.
3686  */
3687 static char *
3688 s_jhtml_start_dir_tag(void *pdoc, Node *node)
3689 {
3690   jhtml_t *jhtml = GET_JHTML(pdoc);
3691   Doc     *doc     = jhtml->doc;
3692   Attr    *attr;
3693   char    *attr_style = NULL;
3694   char    *attr_color = NULL;
3695   char    *attr_size  = NULL;
3696   for (attr = qs_get_attr(doc,node);
3697        attr;
3698        attr = qs_get_next_attr(doc,attr)) {
3699     char *name   = qs_get_attr_name(doc,attr);
3700     char *value  = qs_get_attr_value(doc,attr);
3701     if (STRCASEEQ('s','S',"style", name) && value && *value) {
3702       attr_style = value;
3703     }
3704   }
3705   if (IS_CSS_ON(jhtml->entryp)) {
3706     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
3707     if (style) {
3708       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
3709       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
3710       css_property_t *cur;
3711       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3712         if (cur->value && *cur->value) {
3713           attr_color = apr_pstrdup(doc->pool, cur->value);
3714         }
3715       }
3716       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
3717         if (cur->value && *cur->value) {
3718           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
3719             attr_size = apr_pstrdup(doc->pool, "1");
3720           }
3721           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
3722             attr_size = apr_pstrdup(doc->pool, "2");
3723           }
3724           else if (STRCASEEQ('s','S',"small",cur->value)) {
3725             attr_size = apr_pstrdup(doc->pool, "3");
3726           }
3727           else if (STRCASEEQ('m','M',"medium",cur->value)) {
3728             attr_size = apr_pstrdup(doc->pool, "4");
3729           }
3730           else if (STRCASEEQ('l','L',"large",cur->value)) {
3731             attr_size = apr_pstrdup(doc->pool, "5");
3732           }
3733           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
3734             attr_size = apr_pstrdup(doc->pool, "6");
3735           }
3736           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
3737             attr_size = apr_pstrdup(doc->pool, "7");
3738           }
3739         }
3740       }
3741     }
3742   }
3743   W_L("<dir>");
3744   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
3745   memset(flg, 0, sizeof(*flg));
3746   if (attr_color || attr_size) {
3747     W_L("<font");
3748     if (attr_color) {
3749       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
3750       W_L(" color=\"");
3751       W_V(attr_color);
3752       W_L("\"");
3753     }
3754     if (attr_size) {
3755       W_L(" size=\"");
3756       W_V(attr_size);
3757       W_L("\"");
3758     }
3759     W_L(">");
3760     flg->with_font_flag = 1;
3761   }
3762   node->userData = (void *)flg;
3763   return jhtml->out;
3764 }
3765
3766
3767 /**
3768  * It is a handler who processes the DIR tag.
3769  *
3770  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3771  *                     destination is specified.
3772  * @param node   [i]   The DIR tag node is specified.
3773  * @return The conversion result is returned.
3774  */
3775 static char *
3776 s_jhtml_end_dir_tag(void *pdoc, Node *node)
3777 {
3778   jhtml_t *jhtml = GET_JHTML(pdoc);
3779   Doc *doc = jhtml->doc;
3780   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
3781   if (flg && flg->with_font_flag) {
3782     W_L("</font>");
3783   }
3784   W_L("</dir>");
3785   if (IS_CSS_ON(jhtml->entryp)) {
3786     chxj_css_pop_prop_list(jhtml->css_prop_stack);
3787   }
3788   return jhtml->out;
3789 }
3790
3791
3792 /**
3793  * It is a handler who processes the DL tag.
3794  *
3795  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3796  *                     destination is specified.
3797  * @param node   [i]   The DL tag node is specified.
3798  * @return The conversion result is returned.
3799  */
3800 static char *
3801 s_jhtml_start_dl_tag(void *pdoc, Node *node)
3802 {
3803   jhtml_t *jhtml = GET_JHTML(pdoc);
3804   Doc       *doc     = jhtml->doc;
3805   Attr      *attr;
3806   char      *attr_style = NULL;
3807   char      *attr_color = NULL;
3808   char      *attr_size  = NULL;
3809   for (attr = qs_get_attr(doc,node);
3810        attr;
3811        attr = qs_get_next_attr(doc,attr)) {
3812     char *name   = qs_get_attr_name(doc,attr);
3813     char *value  = qs_get_attr_value(doc,attr);
3814     if (STRCASEEQ('s','S',"style", name) && value && *value) {
3815       attr_style = value;
3816     }
3817   }
3818   if (IS_CSS_ON(jhtml->entryp)) {
3819     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
3820     if (style) {
3821       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
3822       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
3823       css_property_t *cur;
3824       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3825         if (cur->value && *cur->value) {
3826           attr_color = apr_pstrdup(doc->pool, cur->value);
3827         }
3828       }
3829       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
3830         if (cur->value && *cur->value) {
3831           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
3832             attr_size = apr_pstrdup(doc->pool, "1");
3833           }
3834           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
3835             attr_size = apr_pstrdup(doc->pool, "2");
3836           }
3837           else if (STRCASEEQ('s','S',"small",cur->value)) {
3838             attr_size = apr_pstrdup(doc->pool, "3");
3839           }
3840           else if (STRCASEEQ('m','M',"medium",cur->value)) {
3841             attr_size = apr_pstrdup(doc->pool, "4");
3842           }
3843           else if (STRCASEEQ('l','L',"large",cur->value)) {
3844             attr_size = apr_pstrdup(doc->pool, "5");
3845           }
3846           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
3847             attr_size = apr_pstrdup(doc->pool, "6");
3848           }
3849           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
3850             attr_size = apr_pstrdup(doc->pool, "7");
3851           }
3852         }
3853       }
3854     }
3855   }
3856   W_L("<dl>");
3857   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
3858   memset(flg, 0, sizeof(*flg));
3859   if (attr_color || attr_size) {
3860     W_L("<font");
3861     if (attr_color) {
3862       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
3863       W_L(" color=\"");
3864       W_V(attr_color);
3865       W_L("\"");
3866     }
3867     if (attr_size) {
3868       W_L(" size=\"");
3869       W_V(attr_size);
3870       W_L("\"");
3871     }
3872     W_L(">");
3873     flg->with_font_flag = 1;
3874   }
3875   node->userData = (void *)flg;
3876   return jhtml->out;
3877 }
3878
3879
3880 /**
3881  * It is a handler who processes the DL tag.
3882  *
3883  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3884  *                     destination is specified.
3885  * @param node   [i]   The DL tag node is specified.
3886  * @return The conversion result is returned.
3887  */
3888 static char *
3889 s_jhtml_end_dl_tag(void *pdoc, Node *node)
3890 {
3891   jhtml_t *jhtml = GET_JHTML(pdoc);
3892   Doc     *doc = jhtml->doc;
3893   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
3894   if (flg && flg->with_font_flag) {
3895     W_L("</font>");
3896   }
3897   W_L("</dl>");
3898   if (IS_CSS_ON(jhtml->entryp)) {
3899     chxj_css_pop_prop_list(jhtml->css_prop_stack);
3900   }
3901   return jhtml->out;
3902 }
3903
3904
3905 /**
3906  * It is a handler who processes the DT tag.
3907  *
3908  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3909  *                     destination is specified.
3910  * @param node   [i]   The DT tag node is specified.
3911  * @return The conversion result is returned.
3912  */
3913 static char *
3914 s_jhtml_start_dt_tag(void *pdoc, Node *node)
3915 {
3916   jhtml_t *jhtml = GET_JHTML(pdoc);
3917   Doc       *doc     = jhtml->doc;
3918   Attr      *attr;
3919   char      *attr_style = NULL;
3920   char      *attr_color = NULL;
3921   char      *attr_size  = NULL;
3922   for (attr = qs_get_attr(doc,node);
3923        attr;
3924        attr = qs_get_next_attr(doc,attr)) {
3925     char *name   = qs_get_attr_name(doc,attr);
3926     char *value  = qs_get_attr_value(doc,attr);
3927     if (STRCASEEQ('s','S',"style", name) && value && *value) {
3928       attr_style = value;
3929     }
3930   }
3931   if (IS_CSS_ON(jhtml->entryp)) {
3932     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
3933     if (style) {
3934       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
3935       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
3936       css_property_t *cur;
3937       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
3938         if (cur->value && *cur->value) {
3939           attr_color = apr_pstrdup(doc->pool, cur->value);
3940         }
3941       }
3942       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
3943         if (cur->value && *cur->value) {
3944           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
3945             attr_size = apr_pstrdup(doc->pool, "1");
3946           }
3947           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
3948             attr_size = apr_pstrdup(doc->pool, "2");
3949           }
3950           else if (STRCASEEQ('s','S',"small",cur->value)) {
3951             attr_size = apr_pstrdup(doc->pool, "3");
3952           }
3953           else if (STRCASEEQ('m','M',"medium",cur->value)) {
3954             attr_size = apr_pstrdup(doc->pool, "4");
3955           }
3956           else if (STRCASEEQ('l','L',"large",cur->value)) {
3957             attr_size = apr_pstrdup(doc->pool, "5");
3958           }
3959           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
3960             attr_size = apr_pstrdup(doc->pool, "6");
3961           }
3962           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
3963             attr_size = apr_pstrdup(doc->pool, "7");
3964           }
3965         }
3966       }
3967     }
3968   }
3969   W_L("<dt>");
3970   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
3971   memset(flg, 0, sizeof(*flg));
3972   if (attr_color || attr_size) {
3973     W_L("<font");
3974     if (attr_color) {
3975       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
3976       W_L(" color=\"");
3977       W_V(attr_color);
3978       W_L("\"");
3979     }
3980     if (attr_size) {
3981       W_L(" size=\"");
3982       W_V(attr_size);
3983       W_L("\"");
3984     }
3985     W_L(">");
3986     flg->with_font_flag = 1;
3987   }
3988   node->userData = (void *)flg;
3989   return jhtml->out;
3990 }
3991
3992
3993 /**
3994  * It is a handler who processes the DT tag.
3995  *
3996  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
3997  *                     destination is specified.
3998  * @param node   [i]   The DT tag node is specified.
3999  * @return The conversion result is returned.
4000  */
4001 static char *
4002 s_jhtml_end_dt_tag(void *pdoc, Node *node)
4003 {
4004   jhtml_t *jhtml = GET_JHTML(pdoc);
4005   Doc       *doc     = jhtml->doc;
4006   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
4007   if (flg && flg->with_font_flag) {
4008     W_L("</font>");
4009   }
4010   if (IS_CSS_ON(jhtml->entryp)) {
4011     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4012   }
4013   return jhtml->out;
4014 }
4015
4016
4017 /**
4018  * It is a handler who processes the DD tag.
4019  *
4020  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4021  *                     destination is specified.
4022  * @param node   [i]   The DD tag node is specified.
4023  * @return The conversion result is returned.
4024  */
4025 static char *
4026 s_jhtml_start_dd_tag(void *pdoc, Node *node)
4027 {
4028   jhtml_t *jhtml = GET_JHTML(pdoc);
4029   Doc       *doc     = jhtml->doc;
4030   Attr      *attr;
4031   char      *attr_style = NULL;
4032   char      *attr_color = NULL;
4033   char      *attr_size  = NULL;
4034   for (attr = qs_get_attr(doc,node);
4035        attr;
4036        attr = qs_get_next_attr(doc,attr)) {
4037     char *name   = qs_get_attr_name(doc,attr);
4038     char *value  = qs_get_attr_value(doc,attr);
4039     if (STRCASEEQ('s','S',"style", name) && value && *value) {
4040       attr_style = value;
4041     }
4042   }
4043   if (IS_CSS_ON(jhtml->entryp)) {
4044     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4045     if (style) {
4046       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
4047       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
4048       css_property_t *cur;
4049       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4050         if (cur->value && *cur->value) {
4051           attr_color = apr_pstrdup(doc->pool, cur->value);
4052         }
4053       }
4054       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
4055         if (cur->value && *cur->value) {
4056           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4057             attr_size = apr_pstrdup(doc->pool, "1");
4058           }
4059           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4060             attr_size = apr_pstrdup(doc->pool, "2");
4061           }
4062           else if (STRCASEEQ('s','S',"small",cur->value)) {
4063             attr_size = apr_pstrdup(doc->pool, "3");
4064           }
4065           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4066             attr_size = apr_pstrdup(doc->pool, "4");
4067           }
4068           else if (STRCASEEQ('l','L',"large",cur->value)) {
4069             attr_size = apr_pstrdup(doc->pool, "5");
4070           }
4071           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4072             attr_size = apr_pstrdup(doc->pool, "6");
4073           }
4074           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4075             attr_size = apr_pstrdup(doc->pool, "7");
4076           }
4077         }
4078       }
4079     }
4080   }
4081   W_L("<dd>");
4082   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
4083   memset(flg, 0, sizeof(*flg));
4084   if (attr_color || attr_size) {
4085     W_L("<font");
4086     if (attr_color) {
4087       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4088       W_L(" color=\"");
4089       W_V(attr_color);
4090       W_L("\"");
4091     }
4092     if (attr_size) {
4093       W_L(" size=\"");
4094       W_V(attr_size);
4095       W_L("\"");
4096     }
4097     W_L(">");
4098     flg->with_font_flag = 1;
4099   }
4100   node->userData = (void *)flg;
4101   return jhtml->out;
4102 }
4103
4104
4105 /**
4106  * It is a handler who processes the DD tag.
4107  *
4108  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4109  *                     destination is specified.
4110  * @param node   [i]   The DD tag node is specified.
4111  * @return The conversion result is returned.
4112  */
4113 static char *
4114 s_jhtml_end_dd_tag(void *pdoc, Node *node)
4115 {
4116   jhtml_t *jhtml = GET_JHTML(pdoc);
4117   Doc     *doc = jhtml->doc;
4118   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
4119   if (flg && flg->with_font_flag) {
4120     W_L("</font>");
4121   }
4122   if (IS_CSS_ON(jhtml->entryp)) {
4123     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4124   }
4125   return jhtml->out;
4126 }
4127
4128
4129 /**
4130  * It is a handler who processes the H1 tag.
4131  *
4132  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4133  *                     destination is specified.
4134  * @param node   [i]   The H1 tag node is specified.
4135  * @return The conversion result is returned.
4136  */
4137 static char *
4138 s_jhtml_start_h1_tag(void *pdoc, Node *node)
4139 {
4140   jhtml_t     *jhtml;
4141   Doc         *doc;
4142   request_rec *r;
4143   Attr        *attr;
4144   char        *attr_style = NULL;
4145   char        *attr_align = NULL;
4146
4147   jhtml   = GET_JHTML(pdoc);
4148   doc     = jhtml->doc;
4149   r       = doc->r;
4150
4151   for (attr = qs_get_attr(doc,node);
4152        attr;
4153        attr = qs_get_next_attr(doc,attr)) {
4154     char *name  = qs_get_attr_name(doc,attr);
4155     char *value = qs_get_attr_value(doc,attr);
4156     if (STRCASEEQ('a','A',"align", name)) {
4157       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4158         attr_align = value;
4159       }
4160     }
4161     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4162       attr_style = value;
4163     }
4164   }
4165   if (IS_CSS_ON(jhtml->entryp)) {
4166     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4167     if (style) {
4168       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4169       css_property_t *cur;
4170       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4171         if (STRCASEEQ('l','L',"left", cur->value)) {
4172           attr_align = apr_pstrdup(doc->pool, "left");
4173         }
4174         else if (STRCASEEQ('c','C',"center",cur->value)) {
4175           attr_align = apr_pstrdup(doc->pool, "center");
4176         }
4177         else if (STRCASEEQ('r','R',"right",cur->value)) {
4178           attr_align = apr_pstrdup(doc->pool, "right");
4179         }
4180       }
4181     }
4182   }
4183   if (attr_align) {
4184     W_L("<div align=\"");
4185     W_V(attr_align);
4186     W_L("\">");
4187     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4188     memset(flg, 0, sizeof(*flg));
4189     flg->with_div_align_flag = 1;
4190     node->userData = (void *)flg;
4191   }
4192   else {
4193     node->userData = NULL;
4194   }
4195   W_L("<h1>");
4196
4197   return jhtml->out;
4198 }
4199
4200
4201 /**
4202  * It is a handler who processes the H1 tag.
4203  *
4204  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4205  *                     destination is specified.
4206  * @param node   [i]   The H1 tag node is specified.
4207  * @return The conversion result is returned.
4208  */
4209 static char *
4210 s_jhtml_end_h1_tag(void *pdoc, Node *node)
4211 {
4212   jhtml_t*    jhtml;
4213   Doc*          doc;
4214   request_rec*  r;
4215
4216   jhtml = GET_JHTML(pdoc);
4217   doc     = jhtml->doc;
4218   r       = doc->r;
4219   
4220   jhtml_flags_t *flg = node->userData;
4221   W_L("</h1>");
4222   if (flg && flg->with_div_align_flag) {
4223     W_L("</div>");
4224     node->userData = NULL; 
4225   }
4226   if (IS_CSS_ON(jhtml->entryp)) {
4227     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4228   }
4229   return jhtml->out;
4230 }
4231
4232
4233 /**
4234  * It is a handler who processes the H2 tag.
4235  *
4236  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4237  *                     destination is specified.
4238  * @param node   [i]   The H1 tag node is specified.
4239  * @return The conversion result is returned.
4240  */
4241 static char *
4242 s_jhtml_start_h2_tag(void *pdoc, Node *node)
4243 {
4244   jhtml_t     *jhtml;
4245   Doc         *doc;
4246   request_rec *r;
4247   Attr        *attr;
4248   char        *attr_style = NULL;
4249   char        *attr_align = NULL;
4250
4251   jhtml   = GET_JHTML(pdoc);
4252   doc     = jhtml->doc;
4253   r       = doc->r;
4254
4255   for (attr = qs_get_attr(doc,node);
4256        attr;
4257        attr = qs_get_next_attr(doc,attr)) {
4258     char *name  = qs_get_attr_name(doc,attr);
4259     char *value = qs_get_attr_value(doc,attr);
4260     if (STRCASEEQ('a','A',"align", name)) {
4261       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4262         attr_align = value;
4263       }
4264     }
4265     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4266       attr_style = value;
4267     }
4268   }
4269   if (IS_CSS_ON(jhtml->entryp)) {
4270     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4271     if (style) {
4272       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4273       css_property_t *cur;
4274       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4275         if (STRCASEEQ('l','L',"left", cur->value)) {
4276           attr_align = apr_pstrdup(doc->pool, "left");
4277         }
4278         else if (STRCASEEQ('c','C',"center",cur->value)) {
4279           attr_align = apr_pstrdup(doc->pool, "center");
4280         }
4281         else if (STRCASEEQ('r','R',"right",cur->value)) {
4282           attr_align = apr_pstrdup(doc->pool, "right");
4283         }
4284       }
4285     }
4286   }
4287   if (attr_align) {
4288     W_L("<div align=\"");
4289     W_V(attr_align);
4290     W_L("\">");
4291     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4292     memset(flg, 0, sizeof(*flg));
4293     flg->with_div_align_flag = 1;
4294     node->userData = (void *)flg;
4295   }
4296   else {
4297     node->userData = NULL;
4298   }
4299   W_L("<h2>");
4300
4301   return jhtml->out;
4302 }
4303
4304
4305 /**
4306  * It is a handler who processes the H2 tag.
4307  *
4308  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4309  *                     destination is specified.
4310  * @param node   [i]   The H1 tag node is specified.
4311  * @return The conversion result is returned.
4312  */
4313 static char *
4314 s_jhtml_end_h2_tag(void *pdoc, Node *node)
4315 {
4316   jhtml_t     *jhtml;
4317   Doc         *doc;
4318   request_rec *r;
4319
4320   jhtml = GET_JHTML(pdoc);
4321   doc     = jhtml->doc;
4322   r       = doc->r;
4323
4324   jhtml_flags_t *flg = node->userData;
4325   W_L("</h2>");
4326   if (flg && flg->with_div_align_flag) {
4327     W_L("</div>");
4328     node->userData = NULL;
4329   }
4330   if (IS_CSS_ON(jhtml->entryp)) {
4331     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4332   }
4333   return jhtml->out;
4334 }
4335
4336
4337 /**
4338  * It is a handler who processes the H3 tag.
4339  *
4340  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4341  *                     destination is specified.
4342  * @param node   [i]   The H1 tag node is specified.
4343  * @return The conversion result is returned.
4344  */
4345 static char *
4346 s_jhtml_start_h3_tag(void *pdoc, Node *node)
4347 {
4348   jhtml_t     *jhtml;
4349   Doc         *doc;
4350   request_rec *r;
4351   Attr        *attr;
4352   char        *attr_style = NULL;
4353   char        *attr_align = NULL;
4354
4355   jhtml   = GET_JHTML(pdoc);
4356   doc     = jhtml->doc;
4357   r       = doc->r;
4358
4359   for (attr = qs_get_attr(doc,node);
4360        attr;
4361        attr = qs_get_next_attr(doc,attr)) {
4362     char *name  = qs_get_attr_name(doc,attr);
4363     char *value = qs_get_attr_value(doc,attr);
4364     if (STRCASEEQ('a','A',"align", name)) {
4365       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4366         attr_align = value;
4367       }
4368     }
4369     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4370       attr_style = value;
4371     }
4372   }
4373   if (IS_CSS_ON(jhtml->entryp)) {
4374     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4375     if (style) {
4376       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4377       css_property_t *cur;
4378       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4379         if (STRCASEEQ('l','L',"left", cur->value)) {
4380           attr_align = apr_pstrdup(doc->pool, "left");
4381         }
4382         else if (STRCASEEQ('c','C',"center",cur->value)) {
4383           attr_align = apr_pstrdup(doc->pool, "center");
4384         }
4385         else if (STRCASEEQ('r','R',"right",cur->value)) {
4386           attr_align = apr_pstrdup(doc->pool, "right");
4387         }
4388       }
4389     }
4390   }
4391   if (attr_align) {
4392     W_L("<div align=\"");
4393     W_V(attr_align);
4394     W_L("\">");
4395     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4396     memset(flg, 0, sizeof(*flg));
4397     flg->with_div_align_flag = 1;
4398     node->userData = (void *)flg;
4399   }
4400   else {
4401     node->userData = NULL;
4402   }
4403   W_L("<h3>");
4404
4405   return jhtml->out;
4406 }
4407
4408
4409 /**
4410  * It is a handler who processes the H3 tag.
4411  *
4412  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4413  *                     destination is specified.
4414  * @param node   [i]   The H1 tag node is specified.
4415  * @return The conversion result is returned.
4416  */
4417 static char *
4418 s_jhtml_end_h3_tag(void *pdoc, Node *node)
4419 {
4420   jhtml_t*    jhtml;
4421   Doc*          doc;
4422   request_rec*  r;
4423
4424   jhtml = GET_JHTML(pdoc);
4425   doc     = jhtml->doc;
4426   r       = doc->r;
4427   
4428   jhtml_flags_t *flg = node->userData;
4429   W_L("</h3>");
4430   if (flg && flg->with_div_align_flag) {
4431     W_L("</div>");
4432     node->userData = NULL;
4433   }
4434   if (IS_CSS_ON(jhtml->entryp)) {
4435     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4436   }
4437
4438   return jhtml->out;
4439 }
4440
4441
4442 /**
4443  * It is a handler who processes the H4 tag.
4444  *
4445  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4446  *                     destination is specified.
4447  * @param node   [i]   The H1 tag node is specified.
4448  * @return The conversion result is returned.
4449  */
4450 static char *
4451 s_jhtml_start_h4_tag(void *pdoc, Node *node)
4452 {
4453   jhtml_t     *jhtml;
4454   Doc         *doc;
4455   request_rec *r;
4456   Attr        *attr;
4457   char        *attr_style = NULL;
4458   char        *attr_align = NULL;
4459
4460   jhtml   = GET_JHTML(pdoc);
4461   doc     = jhtml->doc;
4462   r       = doc->r;
4463
4464   for (attr = qs_get_attr(doc,node);
4465        attr;
4466        attr = qs_get_next_attr(doc,attr)) {
4467     char *name  = qs_get_attr_name(doc,attr);
4468     char *value = qs_get_attr_value(doc,attr);
4469     if (STRCASEEQ('a','A',"align", name)) {
4470       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4471         attr_align = value;
4472       }
4473     }
4474     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4475       attr_style = value;
4476     }
4477   }
4478   if (IS_CSS_ON(jhtml->entryp)) {
4479     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4480     if (style) {
4481       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4482       css_property_t *cur;
4483       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4484         if (STRCASEEQ('l','L',"left", cur->value)) {
4485           attr_align = apr_pstrdup(doc->pool, "left");
4486         }
4487         else if (STRCASEEQ('c','C',"center",cur->value)) {
4488           attr_align = apr_pstrdup(doc->pool, "center");
4489         }
4490         else if (STRCASEEQ('r','R',"right",cur->value)) {
4491           attr_align = apr_pstrdup(doc->pool, "right");
4492         }
4493       }
4494     }
4495   }
4496   if (attr_align) {
4497     W_L("<div align=\"");
4498     W_V(attr_align);
4499     W_L("\">");
4500     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4501     memset(flg, 0, sizeof(*flg));
4502     flg->with_div_align_flag = 1;
4503     node->userData = (void *)flg;
4504   }
4505   else {
4506     node->userData = NULL;
4507   }
4508   W_L("<h4>");
4509   return jhtml->out;
4510 }
4511
4512
4513 /**
4514  * It is a handler who processes the H4 tag.
4515  *
4516  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4517  *                     destination is specified.
4518  * @param node   [i]   The H1 tag node is specified.
4519  * @return The conversion result is returned.
4520  */
4521 static char *
4522 s_jhtml_end_h4_tag(void *pdoc, Node *node)
4523 {
4524   jhtml_t      *jhtml;
4525   Doc          *doc;
4526   request_rec  *r;
4527
4528   jhtml = GET_JHTML(pdoc);
4529   doc     = jhtml->doc;
4530   r       = doc->r;
4531   
4532   jhtml_flags_t *flg = node->userData;
4533   W_L("</h4>");
4534   if (flg && flg->with_div_align_flag) {
4535     W_L("</div>");
4536     node->userData = NULL;
4537   }
4538   if (IS_CSS_ON(jhtml->entryp)) {
4539     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4540   }
4541   return jhtml->out;
4542 }
4543
4544
4545 /**
4546  * It is a handler who processes the H5 tag.
4547  *
4548  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4549  *                     destination is specified.
4550  * @param node   [i]   The H1 tag node is specified.
4551  * @return The conversion result is returned.
4552  */
4553 static char *
4554 s_jhtml_start_h5_tag(void *pdoc, Node *node)
4555 {
4556   jhtml_t     *jhtml;
4557   Doc         *doc;
4558   request_rec *r;
4559   Attr        *attr;
4560   char        *attr_style = NULL;
4561   char        *attr_align = NULL;
4562
4563   jhtml   = GET_JHTML(pdoc);
4564   doc     = jhtml->doc;
4565   r       = doc->r;
4566
4567   for (attr = qs_get_attr(doc,node);
4568        attr;
4569        attr = qs_get_next_attr(doc,attr)) {
4570     char *name  = qs_get_attr_name(doc,attr);
4571     char *value = qs_get_attr_value(doc,attr);
4572     if (STRCASEEQ('a','A',"align", name)) {
4573       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4574         attr_align = value;
4575       }
4576     }
4577     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4578       attr_style = value;
4579     }
4580   }
4581   if (IS_CSS_ON(jhtml->entryp)) {
4582     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4583     if (style) {
4584       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4585       css_property_t *cur;
4586       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4587         if (STRCASEEQ('l','L',"left", cur->value)) {
4588           attr_align = apr_pstrdup(doc->pool, "left");
4589         }
4590         else if (STRCASEEQ('c','C',"center",cur->value)) {
4591           attr_align = apr_pstrdup(doc->pool, "center");
4592         }
4593         else if (STRCASEEQ('r','R',"right",cur->value)) {
4594           attr_align = apr_pstrdup(doc->pool, "right");
4595         }
4596       }
4597     }
4598   }
4599   if (attr_align) {
4600     W_L("<div align=\"");
4601     W_V(attr_align);
4602     W_L("\">");
4603     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4604     memset(flg, 0, sizeof(*flg));
4605     flg->with_div_align_flag = 1;
4606     node->userData = (void *)flg;
4607   }
4608   else {
4609     node->userData = NULL;
4610   }
4611   W_L("<h5>");
4612   return jhtml->out;
4613 }
4614
4615
4616 /**
4617  * It is a handler who processes the H5 tag.
4618  *
4619  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4620  *                     destination is specified.
4621  * @param node   [i]   The H1 tag node is specified.
4622  * @return The conversion result is returned.
4623  */
4624 static char *
4625 s_jhtml_end_h5_tag(void *pdoc, Node *node)
4626 {
4627   jhtml_t*    jhtml;
4628   Doc*          doc;
4629   request_rec*  r;
4630
4631   jhtml = GET_JHTML(pdoc);
4632   doc     = jhtml->doc;
4633   r       = doc->r;
4634   
4635   jhtml_flags_t *flg = node->userData;
4636   W_L("</h5>");
4637   if (flg && flg->with_div_align_flag) {
4638     W_L("</div>");
4639     node->userData = NULL;
4640   }
4641   if (IS_CSS_ON(jhtml->entryp)) {
4642     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4643   }
4644
4645   return jhtml->out;
4646 }
4647
4648
4649 /**
4650  * It is a handler who processes the H6 tag.
4651  *
4652  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4653  *                     destination is specified.
4654  * @param node   [i]   The H1 tag node is specified.
4655  * @return The conversion result is returned.
4656  */
4657 static char *
4658 s_jhtml_start_h6_tag(void *pdoc, Node *node)
4659 {
4660   jhtml_t     *jhtml;
4661   Doc         *doc;
4662   request_rec *r;
4663   Attr        *attr;
4664   char        *attr_style = NULL;
4665   char        *attr_align = NULL;
4666
4667   jhtml   = GET_JHTML(pdoc);
4668   doc     = jhtml->doc;
4669   r       = doc->r;
4670
4671   for (attr = qs_get_attr(doc,node);
4672        attr;
4673        attr = qs_get_next_attr(doc,attr)) {
4674     char *name  = qs_get_attr_name(doc,attr);
4675     char *value = qs_get_attr_value(doc,attr);
4676     if (STRCASEEQ('a','A',"align", name)) {
4677       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) {
4678         attr_align = value;
4679       }
4680     }
4681     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
4682       attr_style = value;
4683     }
4684   }
4685   if (IS_CSS_ON(jhtml->entryp)) {
4686     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4687     if (style) {
4688       css_property_t *list_style_type_prop = chxj_css_get_property_value(doc, style, "text-align");
4689       css_property_t *cur;
4690       for (cur = list_style_type_prop->next; cur != list_style_type_prop; cur = cur->next) {
4691         if (STRCASEEQ('l','L',"left", cur->value)) {
4692           attr_align = apr_pstrdup(doc->pool, "left");
4693         }
4694         else if (STRCASEEQ('c','C',"center",cur->value)) {
4695           attr_align = apr_pstrdup(doc->pool, "center");
4696         }
4697         else if (STRCASEEQ('r','R',"right",cur->value)) {
4698           attr_align = apr_pstrdup(doc->pool, "right");
4699         }
4700       }
4701     }
4702   }
4703   if (attr_align) {
4704     W_L("<div align=\"");
4705     W_V(attr_align);
4706     W_L("\">");
4707     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
4708     memset(flg, 0, sizeof(*flg));
4709     flg->with_div_align_flag = 1;
4710     node->userData = (void *)flg;
4711   }
4712   else {
4713     node->userData = NULL;
4714   }
4715   W_L("<h6>");
4716
4717   return jhtml->out;
4718 }
4719
4720
4721 /**
4722  * It is a handler who processes the H6 tag.
4723  *
4724  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4725  *                     destination is specified.
4726  * @param node   [i]   The H1 tag node is specified.
4727  * @return The conversion result is returned.
4728  */
4729 static char *
4730 s_jhtml_end_h6_tag(void *pdoc, Node *node)
4731 {
4732   jhtml_t     *jhtml;
4733   Doc         *doc;
4734   request_rec *r;
4735
4736   jhtml = GET_JHTML(pdoc);
4737   doc     = jhtml->doc;
4738   r       = doc->r;
4739   
4740   jhtml_flags_t *flg = node->userData;
4741   W_L("</h6>");
4742   if (flg && flg->with_div_align_flag) {
4743     W_L("</div>");
4744     node->userData = NULL;
4745   }
4746   if (IS_CSS_ON(jhtml->entryp)) {
4747     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4748   }
4749
4750   return jhtml->out;
4751 }
4752
4753
4754 /**
4755  * It is a handler who processes the MENU tag.
4756  *
4757  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4758  *                     destination is specified.
4759  * @param node   [i]   The MENU tag node is specified.
4760  * @return The conversion result is returned.
4761  */
4762 static char *
4763 s_jhtml_start_menu_tag(void *pdoc, Node *node)
4764 {
4765   jhtml_t *jhtml = GET_JHTML(pdoc);
4766   Doc     *doc     = jhtml->doc;
4767   Attr    *attr;
4768   char    *attr_style = NULL;
4769   char    *attr_color = NULL;
4770   char    *attr_size  = NULL;
4771   for (attr = qs_get_attr(doc,node);
4772        attr;
4773        attr = qs_get_next_attr(doc,attr)) {
4774     char *name   = qs_get_attr_name(doc,attr);
4775     char *value  = qs_get_attr_value(doc,attr);
4776     if (STRCASEEQ('s','S',"style", name) && value && *value) {
4777       attr_style = value;
4778     }
4779   }
4780   if (IS_CSS_ON(jhtml->entryp)) {
4781     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4782     if (style) {
4783       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
4784       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
4785       css_property_t *cur;
4786       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4787         if (cur->value && *cur->value) {
4788           attr_color = apr_pstrdup(doc->pool, cur->value);
4789         }
4790       }
4791       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
4792         if (cur->value && *cur->value) {
4793           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4794             attr_size = apr_pstrdup(doc->pool, "1");
4795           }
4796           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4797             attr_size = apr_pstrdup(doc->pool, "2");
4798           }
4799           else if (STRCASEEQ('s','S',"small",cur->value)) {
4800             attr_size = apr_pstrdup(doc->pool, "3");
4801           }
4802           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4803             attr_size = apr_pstrdup(doc->pool, "4");
4804           }
4805           else if (STRCASEEQ('l','L',"large",cur->value)) {
4806             attr_size = apr_pstrdup(doc->pool, "5");
4807           }
4808           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4809             attr_size = apr_pstrdup(doc->pool, "6");
4810           }
4811           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4812             attr_size = apr_pstrdup(doc->pool, "7");
4813           }
4814         }
4815       }
4816     }
4817   }
4818   W_L("<menu>");
4819   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
4820   memset(flg, 0, sizeof(*flg));
4821   if (attr_color || attr_size) {
4822     W_L("<font");
4823     if (attr_color) {
4824       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4825       W_L(" color=\"");
4826       W_V(attr_color);
4827       W_L("\"");
4828     }
4829     if (attr_size) {
4830       W_L(" size=\"");
4831       W_V(attr_size);
4832       W_L("\"");
4833     }
4834     W_L(">");
4835     flg->with_font_flag = 1;
4836   }
4837   node->userData = (void *)flg;
4838   return jhtml->out;
4839 }
4840
4841
4842 /**
4843  * It is a handler who processes the MENU tag.
4844  *
4845  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4846  *                     destination is specified.
4847  * @param node   [i]   The MENU tag node is specified.
4848  * @return The conversion result is returned.
4849  */
4850 static char *
4851 s_jhtml_end_menu_tag(void *pdoc, Node *node)
4852 {
4853   jhtml_t *jhtml = GET_JHTML(pdoc);
4854   Doc *doc = jhtml->doc;
4855   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
4856   if (flg && flg->with_font_flag) {
4857     W_L("</font>");
4858   }
4859   W_L("</menu>");
4860   if (IS_CSS_ON(jhtml->entryp)) {
4861     chxj_css_pop_prop_list(jhtml->css_prop_stack);
4862   }
4863   return jhtml->out;
4864 }
4865
4866
4867 /**
4868  * It is a handler who processes the PLAINTEXT tag.
4869  *
4870  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4871  *                     destination is specified.
4872  * @param node   [i]   The PLAINTEXT tag node is specified.
4873  * @return The conversion result is returned.
4874  */
4875 static char *
4876 s_jhtml_start_plaintext_tag(void *pdoc, Node *node)
4877 {
4878   jhtml_t *jhtml;
4879   Doc *doc;
4880
4881   jhtml = GET_JHTML(pdoc);
4882   doc     = jhtml->doc;
4883   W_L("<plaintext>");
4884   s_jhtml_start_plaintext_tag_inner(pdoc,node);
4885   return jhtml->out;
4886 }
4887
4888 static char *
4889 s_jhtml_start_plaintext_tag_inner(void *pdoc, Node *node)
4890 {
4891   jhtml_t *jhtml;
4892   Doc *doc;
4893   Node *child;
4894   jhtml = GET_JHTML(pdoc);
4895   doc     = jhtml->doc;
4896   for (child = qs_get_child_node(doc, node);
4897        child;
4898        child = qs_get_next_node(doc, child)) {
4899     W_V(child->otext);
4900     s_jhtml_start_plaintext_tag_inner(pdoc, child);
4901   }
4902   return jhtml->out;
4903 }
4904
4905
4906 /**
4907  * It is a handler who processes the PLAINTEXT tag.
4908  *
4909  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4910  *                     destination is specified.
4911  * @param node   [i]   The PLAINTEXT tag node is specified.
4912  * @return The conversion result is returned.
4913  */
4914 static char *
4915 s_jhtml_end_plaintext_tag(void *pdoc, Node *UNUSED(child))
4916 {
4917   jhtml_t *jhtml = GET_JHTML(pdoc);
4918   return jhtml->out;
4919 }
4920
4921
4922 /**
4923  * It is a handler who processes the BLINK tag.
4924  *
4925  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
4926  *                     destination is specified.
4927  * @param node   [i]   The BLINK tag node is specified.
4928  * @return The conversion result is returned.
4929  */
4930 static char *
4931 s_jhtml_start_blink_tag(void *pdoc, Node *node)
4932 {
4933   jhtml_t *jhtml = GET_JHTML(pdoc);
4934   Doc     *doc     = jhtml->doc;
4935   Attr    *attr;
4936   char    *attr_style = NULL;
4937   char    *attr_color = NULL;
4938   char    *attr_size  = NULL;
4939   for (attr = qs_get_attr(doc,node);
4940        attr;
4941        attr = qs_get_next_attr(doc,attr)) {
4942     char *name   = qs_get_attr_name(doc,attr);
4943     char *value  = qs_get_attr_value(doc,attr);
4944     if (STRCASEEQ('s','S',"style", name) && value && *value) {
4945       attr_style = value;
4946     }
4947   }
4948   if (IS_CSS_ON(jhtml->entryp)) {
4949     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
4950     if (style) {
4951       css_property_t *color_prop           = chxj_css_get_property_value(doc, style, "color");
4952       css_property_t *size_prop            = chxj_css_get_property_value(doc, style, "font-size");
4953       css_property_t *cur;
4954       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
4955         if (cur->value && *cur->value) {
4956           attr_color = apr_pstrdup(doc->pool, cur->value);
4957         }
4958       }
4959       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
4960         if (cur->value && *cur->value) {
4961           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
4962             attr_size = apr_pstrdup(doc->pool, "1");
4963           }
4964           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
4965             attr_size = apr_pstrdup(doc->pool, "2");
4966           }
4967           else if (STRCASEEQ('s','S',"small",cur->value)) {
4968             attr_size = apr_pstrdup(doc->pool, "3");
4969           }
4970           else if (STRCASEEQ('m','M',"medium",cur->value)) {
4971             attr_size = apr_pstrdup(doc->pool, "4");
4972           }
4973           else if (STRCASEEQ('l','L',"large",cur->value)) {
4974             attr_size = apr_pstrdup(doc->pool, "5");
4975           }
4976           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
4977             attr_size = apr_pstrdup(doc->pool, "6");
4978           }
4979           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
4980             attr_size = apr_pstrdup(doc->pool, "7");
4981           }
4982         }
4983       }
4984     }
4985   }
4986   W_L("<blink>");
4987   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
4988   memset(flg, 0, sizeof(*flg));
4989   if (attr_color || attr_size) {
4990     W_L("<font");
4991     if (attr_color) {
4992       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
4993       W_L(" color=\"");
4994       W_V(attr_color);
4995       W_L("\"");
4996     }
4997     if (attr_size) {
4998       W_L(" size=\"");
4999       W_V(attr_size);
5000       W_L("\"");
5001     }
5002     W_L(">");
5003     flg->with_font_flag = 1;
5004   }
5005   node->userData = (void *)flg;
5006   return jhtml->out;
5007 }
5008
5009
5010 /**
5011  * It is a handler who processes the BLINK tag.
5012  *
5013  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5014  *                     destination is specified.
5015  * @param node   [i]   The BLINK tag node is specified.
5016  * @return The conversion result is returned.
5017  */
5018 static char *
5019 s_jhtml_end_blink_tag(void *pdoc, Node *node)
5020 {
5021   jhtml_t *jhtml = GET_JHTML(pdoc);
5022   Doc *doc = jhtml->doc;
5023   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
5024   if (flg && flg->with_font_flag) {
5025     W_L("</font>");
5026   }
5027   W_L("</blink>");
5028   if (IS_CSS_ON(jhtml->entryp)) {
5029     chxj_css_pop_prop_list(jhtml->css_prop_stack);
5030   }
5031   return jhtml->out;
5032 }
5033
5034
5035 /**
5036  * It is a handler who processes the MARQUEE tag.
5037  *
5038  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5039  *                     destination is specified.
5040  * @param node   [i]   The MARQUEE tag node is specified.
5041  * @return The conversion result is returned.
5042  */
5043 static char *
5044 s_jhtml_start_marquee_tag(void *pdoc, Node *node)
5045 {
5046   jhtml_t *jhtml = GET_JHTML(pdoc);
5047   Doc     *doc = jhtml->doc;
5048   Attr    *attr;
5049   char    *attr_direction = NULL;
5050   char    *attr_style     = NULL;
5051   char    *attr_color     = NULL;
5052   char    *attr_size      = NULL;
5053   /*--------------------------------------------------------------------------*/
5054   /* Get Attributes                                                           */
5055   /*--------------------------------------------------------------------------*/
5056   for (attr = qs_get_attr(doc,node);
5057        attr;
5058        attr = qs_get_next_attr(doc,attr)) {
5059     char *name   = qs_get_attr_name(doc,attr);
5060     char *value  = qs_get_attr_value(doc,attr);
5061     if (STRCASEEQ('d','D',"direction", name)) {
5062       if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value))) {
5063         attr_direction = value;
5064       }
5065     }
5066     else if (STRCASEEQ('b','B',"behavior",name)) {
5067       /* ignore */
5068     }
5069     else if (STRCASEEQ('l','L',"loop",name)) {
5070       /* ignore */
5071     }
5072     else if (STRCASEEQ('s','S',"style",name) && value && *value) {
5073       attr_style = value;
5074     }
5075   }
5076   if (IS_CSS_ON(jhtml->entryp)) {
5077     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
5078     if (style) {
5079       css_property_t *color_prop     = chxj_css_get_property_value(doc, style, "color");
5080       css_property_t *size_prop      = chxj_css_get_property_value(doc, style, "font-size");
5081       css_property_t *direction_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
5082       css_property_t *cur;
5083       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
5084         if (cur->value && *cur->value) {
5085           attr_color = apr_pstrdup(doc->pool, cur->value);
5086         }
5087       }
5088       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
5089         if (cur->value && *cur->value) {
5090           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
5091             attr_size = apr_pstrdup(doc->pool, "1");
5092           }
5093           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
5094             attr_size = apr_pstrdup(doc->pool, "2");
5095           }
5096           else if (STRCASEEQ('s','S',"small",cur->value)) {
5097             attr_size = apr_pstrdup(doc->pool, "3");
5098           }
5099           else if (STRCASEEQ('m','M',"medium",cur->value)) {
5100             attr_size = apr_pstrdup(doc->pool, "4");
5101           }
5102           else if (STRCASEEQ('l','L',"large",cur->value)) {
5103             attr_size = apr_pstrdup(doc->pool, "5");
5104           }
5105           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
5106             attr_size = apr_pstrdup(doc->pool, "6");
5107           }
5108           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
5109             attr_size = apr_pstrdup(doc->pool, "7");
5110           }
5111         }
5112       }
5113       for (cur = direction_prop->next; cur != direction_prop; cur = cur->next) {
5114         if (cur->value && *cur->value) {
5115           if (STRCASEEQ('l','L',"ltr",cur->value)) {
5116             attr_direction = "right";
5117           }
5118           else if (STRCASEEQ('r','R',"rtl",cur->value)) {
5119             attr_direction = "left";
5120           }
5121         }
5122       }
5123     }
5124   }
5125   W_L("<marquee");
5126   if (attr_direction) {
5127     W_L(" direction=\"");
5128     W_V(attr_direction);
5129     W_L("\"");
5130   }
5131   W_L(">");
5132
5133   jhtml_flags_t *flg = (jhtml_flags_t *)apr_palloc(doc->pool, sizeof(jhtml_flags_t));
5134   memset(flg, 0, sizeof(*flg));
5135   if (attr_color || attr_size) {
5136     W_L("<font");
5137     if (attr_color) {
5138       attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
5139       W_L(" color=\"");
5140       W_V(attr_color);
5141       W_L("\"");
5142     }
5143     if (attr_size) {
5144       W_L(" size=\"");
5145       W_V(attr_size);
5146       W_L("\"");
5147     }
5148     W_L(">");
5149     flg->with_font_flag = 1;
5150   }
5151   node->userData = (void *)flg;
5152   return jhtml->out;
5153 }
5154
5155
5156 /**
5157  * It is a handler who processes the MARQUEE tag.
5158  *
5159  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5160  *                     destination is specified.
5161  * @param node   [i]   The MARQUEE tag node is specified.
5162  * @return The conversion result is returned.
5163  */
5164 static char *
5165 s_jhtml_end_marquee_tag(void *pdoc, Node *node)
5166 {
5167   jhtml_t *jhtml = GET_JHTML(pdoc);
5168   Doc     *doc   = jhtml->doc;
5169
5170   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
5171   if (flg && flg->with_font_flag) {
5172     W_L("</font>");
5173   }
5174   W_L("</marquee>");
5175   if (IS_CSS_ON(jhtml->entryp)) {
5176     chxj_css_pop_prop_list(jhtml->css_prop_stack);
5177   }
5178   return jhtml->out;
5179 }
5180
5181
5182 /**
5183  * It is handler who processes the New Line Code.
5184  */
5185 static char *
5186 s_jhtml_newline_mark(void *pdoc, Node *UNUSED(node))
5187 {
5188   jhtml_t *jhtml = GET_JHTML(pdoc);
5189   Doc *doc = jhtml->doc;
5190   W_NLCODE();
5191   return jhtml->out;
5192 }
5193
5194
5195 /**
5196  * It is a handler who processes the LINK tag.
5197  *
5198  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
5199  *                     destination is specified.
5200  * @param node   [i]   The LINK tag node is specified.
5201  * @return The conversion result is returned.
5202  */
5203 static char *
5204 s_jhtml_link_tag(void *pdoc, Node *node)
5205 {
5206   jhtml_t       *jhtml;
5207   Doc           *doc;
5208   Attr          *attr;
5209   char          *rel  = NULL;
5210   char          *href = NULL;
5211   char          *type = NULL;
5212
5213   jhtml = GET_JHTML(pdoc);
5214   doc   = jhtml->doc;
5215
5216   if (! IS_CSS_ON(jhtml->entryp)) {
5217     return jhtml->out;
5218   }
5219
5220   for (attr = qs_get_attr(doc,node);
5221        attr;
5222        attr = qs_get_next_attr(doc,attr)) {
5223     char *name  = qs_get_attr_name(doc,attr);
5224     char *value = qs_get_attr_value(doc,attr);
5225     if (STRCASEEQ('r','R',"rel", name)) {
5226       if (value && *value && STRCASEEQ('s','S',"stylesheet", value)) {
5227         rel = value;
5228       }
5229     }
5230     else if (STRCASEEQ('h','H',"href", name)) {
5231       if (value && *value) {
5232         href = value;
5233       }
5234     }
5235     else if (STRCASEEQ('t','T',"type", name)) {
5236       if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
5237         type = value;
5238       }
5239     }
5240   }
5241
5242   if (rel && href && type) {
5243     DBG(doc->r, "start load CSS. url:[%s]", href);
5244     jhtml->style = chxj_css_parse_from_uri(doc->r, doc->pool, jhtml->style, href);
5245     DBG(doc->r, "end load CSS. url:[%s]", href);
5246   }
5247
5248   return jhtml->out;
5249 }
5250
5251
5252 static css_prop_list_t *
5253 s_jhtml_push_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
5254 {
5255   jhtml_t *jhtml = GET_JHTML(pdoc);
5256   Doc *doc = jhtml->doc;
5257   css_prop_list_t *last_css = NULL;
5258   if (IS_CSS_ON(jhtml->entryp)) {
5259     css_prop_list_t *dup_css;
5260     css_selector_t  *selector;
5261
5262     last_css = chxj_css_get_last_prop_list(jhtml->css_prop_stack);
5263     dup_css  = chxj_dup_css_prop_list(doc, last_css);
5264     selector = chxj_css_find_selector(doc, jhtml->style, node);
5265     if (selector) {
5266       chxj_css_prop_list_merge_property(doc, dup_css, selector);
5267     }
5268     chxj_css_push_prop_list(jhtml->css_prop_stack, dup_css);
5269     last_css = chxj_css_get_last_prop_list(jhtml->css_prop_stack);
5270
5271     if (style_attr_value) {
5272       css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
5273       if (ssheet) {
5274         chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
5275       }
5276     }
5277   }
5278   return last_css;
5279 }
5280
5281
5282 static css_prop_list_t *
5283 s_jhtml_nopush_and_get_now_style(void *pdoc, Node *node, const char *style_attr_value)
5284 {
5285   jhtml_t *jhtml = GET_JHTML(pdoc);
5286   Doc *doc = jhtml->doc;
5287   css_prop_list_t *last_css = NULL;
5288   if (IS_CSS_ON(jhtml->entryp)) {
5289     css_prop_list_t *dup_css;
5290     css_selector_t  *selector;
5291
5292     last_css = chxj_css_get_last_prop_list(jhtml->css_prop_stack);
5293     dup_css  = chxj_dup_css_prop_list(doc, last_css);
5294     selector = chxj_css_find_selector(doc, jhtml->style, node);
5295     if (selector) {
5296       chxj_css_prop_list_merge_property(doc, dup_css, selector);
5297     }
5298     last_css = dup_css;
5299
5300     if (style_attr_value) {
5301       css_stylesheet_t *ssheet = chxj_css_parse_style_attr(doc, NULL, apr_pstrdup(doc->pool, node->name), NULL, NULL, apr_pstrdup(doc->pool, style_attr_value));
5302       if (ssheet) {
5303         chxj_css_prop_list_merge_property(doc, last_css, ssheet->selector_head.next);
5304       }
5305     }
5306   }
5307   return last_css;
5308 }
5309
5310
5311 /**
5312  * It is a handler who processes the SPAN tag.
5313  *
5314  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5315  *                     destination is specified.
5316  * @param node   [i]   The SPAN tag node is specified.
5317  * @return The conversion result is returned.
5318  */
5319 static char *
5320 s_jhtml_start_span_tag(void *pdoc, Node *node)
5321 {
5322   jhtml_t *jhtml;
5323   Doc *doc;
5324   Attr *attr;
5325   char *attr_style = NULL;
5326   char *attr_color = NULL;
5327   char *attr_size = NULL;
5328   char *attr_align = NULL;
5329   char *attr_blink = NULL;
5330   char *attr_marquee = NULL;
5331   char *attr_marquee_dir = NULL;
5332   char *attr_marquee_style = NULL;
5333   char *attr_marquee_loop = NULL;
5334
5335   jhtml = GET_JHTML(pdoc);
5336   doc     = jhtml->doc;
5337
5338   for (attr = qs_get_attr(doc,node);
5339        attr;
5340        attr = qs_get_next_attr(doc,attr)) {
5341     char *nm  = qs_get_attr_name(doc,attr);
5342     char *val = qs_get_attr_value(doc,attr);
5343     if (val && STRCASEEQ('s','S',"style", nm)) {
5344       attr_style = val;
5345     }
5346   }
5347   if (IS_CSS_ON(jhtml->entryp)) {
5348     css_prop_list_t *style = s_jhtml_push_and_get_now_style(pdoc, node, attr_style);
5349     if (style) {
5350       css_property_t *color_prop = chxj_css_get_property_value(doc, style, "color");
5351       css_property_t *size_prop = chxj_css_get_property_value(doc, style, "font-size");
5352       css_property_t *text_align_prop = chxj_css_get_property_value(doc, style, "text-align");
5353       css_property_t *decoration_prop = chxj_css_get_property_value(doc, style, "text-decoration");
5354       css_property_t *display_prop = chxj_css_get_property_value(doc, style, "display");
5355       css_property_t *marquee_dir_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-dir");
5356       css_property_t *marquee_style_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-style");
5357       css_property_t *marquee_loop_prop = chxj_css_get_property_value(doc, style, "-wap-marquee-loop");
5358       css_property_t *cur;
5359       for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
5360         attr_color = apr_pstrdup(doc->pool, cur->value);
5361       }
5362       for (cur = size_prop->next; cur != size_prop; cur = cur->next) {
5363         if (cur->value && *cur->value) {
5364           if (STRCASEEQ('x','X',"xx-small",cur->value)) {
5365             attr_size = apr_pstrdup(doc->pool, "1");
5366           }
5367           else if (STRCASEEQ('x','X',"x-small",cur->value)) {
5368             attr_size = apr_pstrdup(doc->pool, "2");
5369           }
5370           else if (STRCASEEQ('s','S',"small",cur->value)) {
5371             attr_size = apr_pstrdup(doc->pool, "3");
5372           }
5373           else if (STRCASEEQ('m','M',"medium",cur->value)) {
5374             attr_size = apr_pstrdup(doc->pool, "4");
5375           }
5376           else if (STRCASEEQ('l','L',"large",cur->value)) {
5377             attr_size = apr_pstrdup(doc->pool, "5");
5378           }
5379           else if (STRCASEEQ('x','X',"x-large",cur->value)) {
5380             attr_size = apr_pstrdup(doc->pool, "6");
5381           }
5382           else if (STRCASEEQ('x','X',"xx-large",cur->value)) {
5383             attr_size = apr_pstrdup(doc->pool, "7");
5384           }
5385         }
5386       }
5387       for (cur = decoration_prop->next; cur != decoration_prop; cur = cur->next) {
5388         if (cur->value && STRCASEEQ('b','B',"blink",cur->value)) {
5389           attr_blink = apr_pstrdup(doc->pool, cur->value);
5390         }
5391       }
5392       for (cur = display_prop->next; cur != display_prop; cur = cur->next) {
5393         if (cur->value && strcasecmp("-wap-marquee",cur->value) == 0) {
5394           attr_marquee = apr_pstrdup(doc->pool, cur->value);
5395         }
5396       }
5397       for (cur = marquee_dir_prop->next; cur != marquee_dir_prop; cur = cur->next) {
5398         if (cur->value && *cur->value) {
5399           if (STRCASEEQ('l','L',"ltr",cur->value)) {
5400             attr_marquee_dir = "right";
5401           }
5402           else if (STRCASEEQ('r','R',"rtl",cur->value)) {
5403             attr_marquee_dir = "left";
5404           }
5405         }
5406       }
5407       for (cur = marquee_style_prop->next; cur != marquee_style_prop; cur = cur->next) {
5408         if (cur->value && *cur->value) {
5409           if ( STRCASEEQ('s','S',"scroll",cur->value)
5410             || STRCASEEQ('s','S',"slide",cur->value)
5411             || STRCASEEQ('a','A',"alternate",cur->value)) {
5412             attr_marquee_style = apr_pstrdup(doc->pool, cur->value);
5413           }
5414         }
5415       }
5416       for (cur = marquee_loop_prop->next; cur != marquee_loop_prop; cur = cur->next) {
5417         if (cur->value && *cur->value) {
5418           if (STRCASEEQ('i','I',"infinite",cur->value)) {
5419             attr_marquee_loop = "16";
5420           }
5421           else {
5422             attr_marquee_loop = apr_pstrdup(doc->pool, cur->value);
5423           }
5424         }
5425       }
5426       for (cur = text_align_prop->next; cur != text_align_prop; cur = cur->next) {
5427         if (STRCASEEQ('l','L',"left", cur->value)) {
5428           attr_align = apr_pstrdup(doc->pool, "left");
5429         }
5430         else if (STRCASEEQ('c','C',"center",cur->value)) {
5431           attr_align = apr_pstrdup(doc->pool, "center");
5432         }
5433         else if (STRCASEEQ('r','R',"right",cur->value)) {
5434           attr_align = apr_pstrdup(doc->pool, "right");
5435         }
5436       }
5437     }
5438   }
5439   if (attr_color || attr_size || attr_align || attr_blink || attr_marquee) {
5440     jhtml_flags_t *flg = apr_palloc(doc->pool, sizeof(*flg));
5441     memset(flg, 0, sizeof(*flg));
5442     if (attr_blink) {
5443       W_L("<blink>");
5444       flg->with_blink_flag = 1;
5445     }
5446     if (attr_marquee) {
5447       W_L("<marquee");
5448       if (attr_marquee_dir) {
5449         W_L(" direction=\"");
5450         W_V(attr_marquee_dir);
5451         W_L("\"");
5452       }
5453       if (attr_marquee_style) {
5454         W_L(" behavior=\"");
5455         W_V(attr_marquee_style);
5456         W_L("\"");
5457       }
5458       if (attr_marquee_loop) {
5459         W_L(" loop=\"");
5460         W_V(attr_marquee_loop);
5461         W_L("\"");
5462       }
5463       W_L(">");
5464       flg->with_marquee_flag = 1;
5465     }
5466     if (attr_color||attr_size) {
5467       W_L("<font");
5468       if (attr_color) {
5469         attr_color = chxj_css_rgb_func_to_value(doc->pool, attr_color);
5470         W_L(" color=\"");
5471         W_V(attr_color);
5472         W_L("\"");
5473       }
5474       if (attr_size) {
5475         W_L(" size=\"");
5476         W_V(attr_size);
5477         W_L("\"");
5478       }
5479       W_L(">");
5480       flg->with_font_flag = 1;
5481     }
5482     if (attr_align) {
5483       W_L("<div align=\"");
5484       W_V(attr_align);
5485       W_L("\">");
5486       flg->with_div_flag = 1;
5487     }
5488     node->userData = flg;
5489   }
5490   else {
5491     node->userData = NULL;
5492   }
5493   return jhtml->out;
5494 }
5495
5496
5497 /**
5498  * It is a handler who processes the SPAN tag.
5499  *
5500  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5501  *                     destination is specified.
5502  * @param node   [i]   The SPAN tag node is specified.
5503  * @return The conversion result is returned.
5504  */
5505 static char *
5506 s_jhtml_end_span_tag(void *pdoc, Node *node)
5507 {
5508   jhtml_t *jhtml = GET_JHTML(pdoc);
5509   Doc *doc = jhtml->doc;
5510
5511   jhtml_flags_t *flg = (jhtml_flags_t *)node->userData;
5512   if (flg && flg->with_div_flag) {
5513     W_L("</div>");
5514   }
5515   if (flg && flg->with_font_flag) {
5516     W_L("</font>");
5517   }
5518   if (flg && flg->with_marquee_flag) {
5519     W_L("</marquee>");
5520   }
5521   if (flg && flg->with_blink_flag) {
5522     W_L("</blink>");
5523   }
5524   if (IS_CSS_ON(jhtml->entryp)) {
5525     chxj_css_pop_prop_list(jhtml->css_prop_stack);
5526   }
5527   return jhtml->out;
5528 }
5529
5530
5531 /**
5532  * It is a handler who processes the STYLE tag.
5533  *
5534  * @param pdoc  [i/o] The pointer to the JHTML structure at the output
5535  *                     destination is specified.
5536  * @param node   [i]   The STYLE tag node is specified.
5537  * @return The conversion result is returned.
5538  */
5539 static char *
5540 s_jhtml_style_tag(void *pdoc, Node *node)
5541 {
5542   jhtml_t     *jhtml;
5543   Doc           *doc;
5544   Attr          *attr;
5545   char          *type = NULL;
5546
5547   jhtml = GET_JHTML(pdoc);
5548   doc     = jhtml->doc;
5549
5550   if (! IS_CSS_ON(jhtml->entryp)) {
5551     return jhtml->out;
5552   }
5553
5554   for (attr = qs_get_attr(doc,node);
5555        attr;
5556        attr = qs_get_next_attr(doc,attr)) {
5557     char *name  = qs_get_attr_name(doc,attr);
5558     char *value = qs_get_attr_value(doc,attr);
5559     if (STRCASEEQ('t','T',"type", name)) {
5560       if (value && *value && STRCASEEQ('t','T',"text/css",value)) {
5561         type = value;
5562       }
5563     }
5564   }
5565
5566   Node *child = qs_get_child_node(doc, node);
5567   if (type && child) {
5568     char *name  = qs_get_node_name(doc, child);
5569     if (STRCASEEQ('t','T',"text", name)) {
5570       char *value = qs_get_node_value(doc, child);
5571       DBG(doc->r, "start load CSS. buf:[%s]", value);
5572       jhtml->style = chxj_css_parse_style_value(doc, jhtml->style, value);
5573       DBG(doc->r, "end load CSS. value:[%s]", value);
5574     }
5575   }
5576   return jhtml->out;
5577 }
5578
5579
5580 static char *
5581 s_add_copyright_parameter(request_rec *r, char *value)
5582 {
5583   request_rec *sub_req = NULL;
5584   apr_pool_t *pool;
5585   int rr_status;
5586   char *content_type = NULL;
5587   apr_table_t *headers_out = NULL;
5588
5589   DBG(r, "REQ[%X] start s_add_copyright_parameter", TO_ADDR(r));
5590   apr_pool_create(&pool, r->pool);
5591
5592   if (chxj_starts_with(value, "http:") || chxj_starts_with(value, "https:")) {
5593     apr_table_t *response;
5594     int   response_code = 0;
5595     response = chxj_serf_head(r, pool, value, &response_code);
5596     if (response_code != HTTP_OK) {
5597       DBG(r, "REQ[%X] end s_add_copyright_parameter (serf_req->status:[%d])", TO_ADDR(r), response_code);
5598       return value;
5599     }
5600     content_type = (char *)apr_table_get(response, "Content-Type");
5601     headers_out = response;
5602   }
5603   else {
5604     //  sub_req = ap_sub_req_method_uri("GET", value, r, r->output_filters);
5605     sub_req = ap_sub_req_lookup_uri(value, r, r->output_filters);
5606     if (sub_req->status != HTTP_OK) {
5607       DBG(r, "REQ[%X] end s_add_copyright_parameter (sub_req->status:[%d])", TO_ADDR(r), sub_req->status);
5608       ap_destroy_sub_req(sub_req);
5609       return value;
5610     }
5611     sub_req->header_only = 1;
5612     sub_req->main = NULL;
5613     rr_status = ap_run_sub_req(sub_req);
5614     DBG(r, "REQ[%X] sub_req4:ContentType:[%s]", TO_ADDR(r), sub_req->content_type);
5615     DBG(r, "REQ[%X] rr_status:[%d]", TO_ADDR(r), rr_status);
5616     content_type = apr_pstrdup(pool, sub_req->content_type);
5617     headers_out = sub_req->headers_out;
5618   }
5619   if (headers_out && apr_table_get(headers_out, "x-jphone-copyright")) {
5620     if (content_type && strncasecmp("image/jpeg", content_type, 10) == 0) {
5621       if (strchr(value, '?')) {
5622         value = apr_psprintf(pool, "%s&_chxj_copy=.jpz", value);
5623       }
5624       else {
5625         value = apr_psprintf(pool, "%s?_chxj_copy=.jpz", value);
5626       }
5627     }
5628     else if (content_type && strncasecmp("image/png", content_type, 9) == 0) {
5629       if (strchr(value, '?')) {
5630         value = apr_psprintf(pool, "%s&_chxj_copy=.pnz", value);
5631       }
5632       else {
5633         value = apr_psprintf(pool, "%s?_chxj_copy=.pnz", value);
5634       }
5635     }
5636   }
5637   if (sub_req) {
5638     ap_destroy_sub_req(sub_req);
5639   }
5640   DBG(r, "REQ[%X] end s_add_copyright_parameter(result:[%s]", TO_ADDR(r), value);
5641   return value;
5642 }
5643
5644
5645 /*
5646  * vim:ts=2 et
5647  */