OSDN Git Service

* merge from mastergit
[modchxj/mod_chxj.git] / src / chxj_node_convert.c
index b318a5c..67fc8d1 100644 (file)
@@ -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,
@@ -63,7 +63,7 @@ tag_handlers chxj_tag_handlers[] = {
   },
   {
     .type    = CHXJ_SPEC_Jxhtml,
-    .handler = jhtml_handler,
+    .handler = jxhtml_handler,
   },
   {
     .type    = CHXJ_SPEC_HTML,
@@ -266,6 +266,18 @@ chxj_node_convert(
         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);
       }
@@ -349,6 +361,19 @@ 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);
       }
@@ -387,7 +412,13 @@ chxj_node_convert(
       /* <OBJECT>                                                             */
       /*----------------------------------------------------------------------*/
       if (strcasecmp(name, "object") == 0) {
-        /* ignore object block */
+        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);
@@ -751,6 +782,14 @@ chxj_node_convert(
     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) {
@@ -762,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>                                                            */
       /*----------------------------------------------------------------------*/
@@ -770,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);
@@ -781,6 +833,15 @@ 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);
       }
@@ -898,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
  */