OSDN Git Service

* merge from mastergit
[modchxj/mod_chxj.git] / src / chxj_node_convert.c
old mode 100755 (executable)
new mode 100644 (file)
index a8ae6b4..67fc8d1
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 QSDN,Inc. All rights reserved.
+ * Copyright (C) 2005-2009 QSDN,Inc. All rights reserved.
  * Copyright (C) 2005 Atsushi Konno All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,19 +35,19 @@ tag_handlers chxj_tag_handlers[] = {
   },
   {
     .type    = CHXJ_SPEC_Chtml_4_0,
-    .handler = chtml30_handler,
+    .handler = chtml40_handler,
   },
   {
     .type    = CHXJ_SPEC_Chtml_5_0,
-    .handler = chtml30_handler,
+    .handler = chtml50_handler,
   },
   {
     .type    = CHXJ_SPEC_Chtml_6_0,
-    .handler = chtml30_handler,
+    .handler = ixhtml10_handler,
   },
   {
     .type    = CHXJ_SPEC_Chtml_7_0,
-    .handler = chtml30_handler,
+    .handler = ixhtml10_handler,
   },
   {
     .type    = CHXJ_SPEC_XHtml_Mobile_1_0,
@@ -62,6 +62,10 @@ tag_handlers chxj_tag_handlers[] = {
     .handler = jhtml_handler,
   },
   {
+    .type    = CHXJ_SPEC_Jxhtml,
+    .handler = jxhtml_handler,
+  },
+  {
     .type    = CHXJ_SPEC_HTML,
     .handler = NULL,
   },
@@ -102,11 +106,7 @@ chxj_node_convert(
   for (child = qs_get_child_node(doc,node);
        child;
        child = qs_get_next_node(doc,child)) {
-
-    char *name;
-
-    name = qs_get_node_name(doc,child);
-
+    char *name = qs_get_node_name(doc,child);
     switch(*name) {
     case 'h':
     case 'H':
@@ -224,6 +224,9 @@ chxj_node_convert(
         if (handlers[tagH6].end_tag_handler)
           handlers[tagH6].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
 
@@ -241,11 +244,10 @@ chxj_node_convert(
         if (handlers[tagP].end_tag_handler)
           handlers[tagP].end_tag_handler(pdoc, child);
       }
-      else
       /*----------------------------------------------------------------------*/
       /* <PRE>                                                                */
       /*----------------------------------------------------------------------*/
-      if (strcasecmp(name, "pre") == 0) {
+      else if (strcasecmp(name, "pre") == 0) {
         if (handlers[tagPRE].start_tag_handler) 
           handlers[tagPRE].start_tag_handler(pdoc, child);
 
@@ -254,6 +256,31 @@ chxj_node_convert(
         if (handlers[tagPRE].end_tag_handler)
           handlers[tagPRE].end_tag_handler(pdoc, child);
       }
+      /*----------------------------------------------------------------------*/
+      /* <PLAINTEXT>                                                          */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "plaintext") == 0) {
+        if (handlers[tagPLAINTEXT].start_tag_handler) 
+          handlers[tagPLAINTEXT].start_tag_handler(pdoc, child);
+
+        if (handlers[tagPLAINTEXT].end_tag_handler)
+          handlers[tagPLAINTEXT].end_tag_handler(pdoc, child);
+      }
+      /*----------------------------------------------------------------------*/
+      /* <PARAM>                                                              */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "param") == 0) {
+        if (handlers[tagPARAM].start_tag_handler) 
+          handlers[tagPARAM].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagPARAM].end_tag_handler)
+          handlers[tagPARAM].end_tag_handler(pdoc, child);
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'n':
@@ -270,6 +297,9 @@ chxj_node_convert(
         if (handlers[tagNOBR].end_tag_handler)
           handlers[tagNOBR].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'u':
@@ -286,6 +316,9 @@ chxj_node_convert(
         if (handlers[tagUL].end_tag_handler)
           handlers[tagUL].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'l':
@@ -328,6 +361,22 @@ chxj_node_convert(
         if (handlers[tagLABEL].end_tag_handler)
           handlers[tagLABEL].end_tag_handler(pdoc, child);
       }
+      else
+      /*----------------------------------------------------------------------*/
+      /* <LINK>                                                               */
+      /*----------------------------------------------------------------------*/
+      if (strcasecmp(name, "link") == 0) {
+        if (handlers[tagLINK].start_tag_handler) 
+          handlers[tagLINK].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagLINK].end_tag_handler)
+          handlers[tagLINK].end_tag_handler(pdoc, child);
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       
       break;
 
@@ -358,6 +407,22 @@ chxj_node_convert(
         if (handlers[tagOPTION].end_tag_handler)
           handlers[tagOPTION].end_tag_handler(pdoc, child);
       }
+      else
+      /*----------------------------------------------------------------------*/
+      /* <OBJECT>                                                             */
+      /*----------------------------------------------------------------------*/
+      if (strcasecmp(name, "object") == 0) {
+        if (handlers[tagOBJECT].start_tag_handler) 
+          handlers[tagOBJECT].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagOBJECT].end_tag_handler)
+          handlers[tagOBJECT].end_tag_handler(pdoc, child);
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
 
       break;
 
@@ -375,6 +440,33 @@ chxj_node_convert(
         if (handlers[tagMETA].end_tag_handler)
           handlers[tagMETA].end_tag_handler(pdoc, child);
       }
+      /*----------------------------------------------------------------------*/
+      /* <MENU>                                                               */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "menu") == 0) {
+        if (handlers[tagMENU].start_tag_handler) 
+          handlers[tagMENU].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagMENU].end_tag_handler)
+          handlers[tagMENU].end_tag_handler(pdoc, child);
+      }
+      /*----------------------------------------------------------------------*/
+      /* <MARQUEE>                                                            */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "marquee") == 0) {
+        if (handlers[tagMARQUEE].start_tag_handler) 
+          handlers[tagMARQUEE].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagMARQUEE].end_tag_handler)
+          handlers[tagMARQUEE].end_tag_handler(pdoc, child);
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'b':
@@ -420,8 +512,7 @@ chxj_node_convert(
       /*----------------------------------------------------------------------*/
       /* <BR>                                                                 */
       /*----------------------------------------------------------------------*/
-      else
-      if (strcasecmp(name, "br") == 0) {
+      else if (strcasecmp(name, "br") == 0) {
         if (handlers[tagBR].start_tag_handler) 
           handlers[tagBR].start_tag_handler(pdoc, child);
 
@@ -430,6 +521,33 @@ chxj_node_convert(
         if (handlers[tagBR].end_tag_handler)
           handlers[tagBR].end_tag_handler(pdoc, child);
       }
+      /*----------------------------------------------------------------------*/
+      /* <BLOCKQUOTE>                                                         */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "blockquote") == 0) {
+        if (handlers[tagBLOCKQUOTE].start_tag_handler) 
+          handlers[tagBLOCKQUOTE].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagBLOCKQUOTE].end_tag_handler)
+          handlers[tagBLOCKQUOTE].end_tag_handler(pdoc, child);
+      }
+      /*----------------------------------------------------------------------*/
+      /* <BLINK>                                                              */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "blink") == 0) {
+        if (handlers[tagBLINK].start_tag_handler) 
+          handlers[tagBLINK].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagBLINK].end_tag_handler)
+          handlers[tagBLINK].end_tag_handler(pdoc, child);
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'a':
@@ -446,6 +564,9 @@ chxj_node_convert(
         if (handlers[tagA].end_tag_handler)
           handlers[tagA].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'f':
@@ -488,6 +609,9 @@ chxj_node_convert(
         if (handlers[tagFIELDSET].end_tag_handler)
           handlers[tagFIELDSET].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'i':
@@ -517,6 +641,9 @@ chxj_node_convert(
         if (handlers[tagIMG].end_tag_handler)
           handlers[tagIMG].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 's':
@@ -540,6 +667,10 @@ chxj_node_convert(
       if (strcasecmp(name, "style") == 0) {
         if (handlers[tagSTYLE].start_tag_handler) 
           handlers[tagSTYLE].start_tag_handler(pdoc, child);
+#if 0
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+#endif
+
         if (handlers[tagSTYLE].end_tag_handler)
           handlers[tagSTYLE].end_tag_handler(pdoc, child);
       }
@@ -569,6 +700,16 @@ chxj_node_convert(
         if (handlers[tagSMALL].end_tag_handler)
           handlers[tagSMALL].end_tag_handler(pdoc, child);
       }
+      /*----------------------------------------------------------------------*/
+      /* <SCRIPT>                                                             */
+      /*----------------------------------------------------------------------*/
+      else 
+      if (strcasecmp(name, "script") == 0) {
+        /* ignore script block */
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
   
     case 'd':
@@ -586,10 +727,21 @@ chxj_node_convert(
           handlers[tagDIV].end_tag_handler(pdoc, child);
       }
       /*----------------------------------------------------------------------*/
+      /* <DIR>                                                                */
+      /*----------------------------------------------------------------------*/
+      else if (strcasecmp(name, "dir") == 0) {
+        if (handlers[tagDIR].start_tag_handler) 
+          handlers[tagDIR].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagDIR].end_tag_handler)
+          handlers[tagDIR].end_tag_handler(pdoc, child);
+      }
+      /*----------------------------------------------------------------------*/
       /* <DL>                                                                 */
       /*----------------------------------------------------------------------*/
-      else 
-      if (strcasecmp(name, "dl") == 0) {
+      else if (strcasecmp(name, "dl") == 0) {
         if (handlers[tagDL].start_tag_handler) 
           handlers[tagDL].start_tag_handler(pdoc, child);
 
@@ -601,8 +753,7 @@ chxj_node_convert(
       /*----------------------------------------------------------------------*/
       /* <DT>                                                                 */
       /*----------------------------------------------------------------------*/
-      else 
-      if (strcasecmp(name, "dt") == 0) {
+      else if (strcasecmp(name, "dt") == 0) {
         if (handlers[tagDT].start_tag_handler) 
           handlers[tagDT].start_tag_handler(pdoc, child);
 
@@ -614,8 +765,7 @@ chxj_node_convert(
       /*----------------------------------------------------------------------*/
       /* <DD>                                                                 */
       /*----------------------------------------------------------------------*/
-      else 
-      if (strcasecmp(name, "dd") == 0) {
+      else if (strcasecmp(name, "dd") == 0) {
         if (handlers[tagDD].start_tag_handler) 
           handlers[tagDD].start_tag_handler(pdoc, child);
 
@@ -624,11 +774,22 @@ chxj_node_convert(
         if (handlers[tagDD].end_tag_handler)
           handlers[tagDD].end_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 'c':
     case 'C':
       /*----------------------------------------------------------------------*/
+      /* NL (CrLf)                                                            */
+      /*----------------------------------------------------------------------*/
+      if (strcasecmp(name, QS_PARSE_NL_MARK) == 0) {
+        if (handlers[tagNLMARK].start_tag_handler) 
+          handlers[tagNLMARK].start_tag_handler(pdoc, child);
+      }
+      else
+      /*----------------------------------------------------------------------*/
       /* <CENTER>                                                             */
       /*----------------------------------------------------------------------*/
       if (strcasecmp(name, "center") == 0) {
@@ -640,6 +801,19 @@ chxj_node_convert(
         if (handlers[tagCENTER].end_tag_handler)
           handlers[tagCENTER].end_tag_handler(pdoc, child);
       }
+      else
+      /*----------------------------------------------------------------------*/
+      /* <CAPTION>                                                            */
+      /*----------------------------------------------------------------------*/
+      if (strcasecmp(name, "caption") == 0) {
+        if (handlers[tagCAPTION].start_tag_handler) 
+          handlers[tagCAPTION].start_tag_handler(pdoc, child);
+
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+
+        if (handlers[tagCAPTION].end_tag_handler)
+          handlers[tagCAPTION].end_tag_handler(pdoc, child);
+      }
       /*----------------------------------------------------------------------*/
       /* <CHXJ:IF>                                                            */
       /*----------------------------------------------------------------------*/
@@ -648,7 +822,7 @@ chxj_node_convert(
         if (chxj_chxjif_is_mine(spec, doc, child)) {
           char* parse_attr;
 
-          parse_attr = qs_get_parse_attr(doc, child, r);
+          parse_attr = qs_get_parse_attr(doc, child, r->pool);
 
           if (parse_attr && strcasecmp(parse_attr, "true") == 0) {
             chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
@@ -659,6 +833,18 @@ chxj_node_convert(
           }
         }
       }
+      /*----------------------------------------------------------------------*/
+      /* <CHXJ:RAW>                                                           */
+      /*----------------------------------------------------------------------*/
+      else
+      if (strcasecmp(name, "chxj:raw") == 0) {
+        if (handlers[tagCHXJRAW].start_tag_handler) {
+           handlers[tagCHXJRAW].start_tag_handler(pdoc, child);
+        }
+      }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     case 't':
@@ -761,6 +947,9 @@ chxj_node_convert(
         if (handlers[tagTEXT].start_tag_handler)
           handlers[tagTEXT].start_tag_handler(pdoc, child);
       }
+      else {
+        chxj_node_convert(spec, r, pdoc, doc, child, indent+1);
+      }
       break;
 
     default:
@@ -770,6 +959,74 @@ chxj_node_convert(
 
   return NULL;
 }
+
+
+char *
+chxj_node_convert_chxjif_only(
+  request_rec  *r,
+  device_table *spec,
+  const char   *src,
+  apr_size_t   *len  
+)
+{
+  Doc  doc;
+  char *dst;
+  int  pass = 0;
+  apr_size_t dst_pos = 0;
+  apr_size_t ii;
+
+  memset(&doc, 0, sizeof(Doc));
+
+  apr_pool_create(&doc.pool, r->pool);
+  doc.r = r;
+
+  dst = apr_palloc(doc.pool, *len + 1);
+  memset(dst, 0, *len + 1);
+
+  for (ii =0; ii<*len; ii++) {
+    if (src[ii + 0] == '<') {
+      apr_size_t endpoint = chxj_cut_tag(&src[ii + 0], *len - ii);
+      Node *node   = qs_parse_tag(&doc, &src[ii], endpoint);
+      char *name   = qs_get_node_name(&doc,node);
+      if (STRCASEEQ('c','C',"chxj:if", name)) {
+        if (! chxj_chxjif_is_mine(spec, &doc, node)) {
+          pass = 1;
+        }
+        ii += endpoint;
+      }
+      else if (STRCASEEQ('/','/', "/chxj:if", name)) {
+        pass = 0;
+        ii += endpoint;
+      }
+      else {
+        if (! pass) {
+#if 0
+          memcpy(&dst[dst_pos], &src[ii], endpoint + 1);
+          dst_pos += (endpoint + 1);
+#else
+          dst[dst_pos++] = src[ii];
+#endif
+        }
+#if 0
+        ii += endpoint;
+#endif
+      }
+    }
+    else {
+      if (! pass) {
+        if (is_sjis_kanji(src[ii])) {
+          dst[dst_pos++] = src[ii++];
+          dst[dst_pos++] = src[ii];
+        }
+        else  {
+          dst[dst_pos++] = src[ii];
+        }
+      }
+    }
+  }
+  *len = strlen(dst);
+  return dst;
+}
 /*
  * vim:ts=2 et
  */