OSDN Git Service

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