OSDN Git Service

* Added body tag with CSS for CHTML2.0 converter.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Tue, 15 Jul 2008 07:43:58 +0000 (07:43 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Tue, 15 Jul 2008 07:43:58 +0000 (07:43 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2934 1a406e8e-add9-4483-a2c8-d8cac5b7c224

src/chxj_chtml20.c
test/chxj_chtml20/test_chxj_chtml20.c

index 16253e2..88c56ea 100644 (file)
@@ -929,12 +929,15 @@ s_chtml20_start_body_tag(void *pdoc, Node *node)
   Doc         *doc;
   request_rec *r;
   Attr        *attr;
+  char        *attr_bgcolor = NULL;
+  char        *attr_text    = NULL;
+  char        *attr_link    = NULL;
+  char        *attr_style   = NULL;
 
   chtml20 = GET_CHTML20(pdoc);
   doc     = chtml20->doc;
   r       = doc->r;
 
-  W_L("<body");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
@@ -950,9 +953,7 @@ s_chtml20_start_body_tag(void *pdoc, Node *node)
         /*----------------------------------------------------------------------*/
         /* CHTML 2.0                                                            */
         /*----------------------------------------------------------------------*/
-        W_L(" bgcolor=\"");
-        W_V(value);
-        W_L("\"");
+        attr_bgcolor = value;
       }
       break;
 
@@ -962,9 +963,14 @@ s_chtml20_start_body_tag(void *pdoc, Node *node)
         /*----------------------------------------------------------------------*/
         /* CHTML 2.0                                                            */
         /*----------------------------------------------------------------------*/
-        W_L(" text=\"");
-        W_V(value);
-        W_L("\"");
+        attr_text = value;
+      }
+      break;
+
+    case 's':
+    case 'S':
+      if (strcasecmp(name, "style") == 0 && value && *value != 0) {
+        attr_style = value;
       }
       break;
 
@@ -974,9 +980,7 @@ s_chtml20_start_body_tag(void *pdoc, Node *node)
         /*----------------------------------------------------------------------*/
         /* CHTML 2.0                                                            */
         /*----------------------------------------------------------------------*/
-        W_L(" link=\"");
-        W_V(value);
-        W_L("\"");
+        attr_link = value;
       }
       break;
 
@@ -1004,6 +1008,56 @@ s_chtml20_start_body_tag(void *pdoc, Node *node)
       break;
     }
   }
+  if (IS_CSS_ON(chtml20->entryp)) {
+    css_prop_list_t *style = s_chtml20_push_and_get_now_style(pdoc, node, attr_style);
+    if (style) {
+      css_property_t *color_prop      = chxj_css_get_property_value(doc, style, "color");
+      css_property_t *bgcolor_prop    = chxj_css_get_property_value(doc, style, "background-color");
+      css_property_t *cur;
+      for (cur = color_prop->next; cur != color_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_text = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+      for (cur = bgcolor_prop->next; cur != bgcolor_prop; cur = cur->next) {
+        if (cur->value && *cur->value) {
+          attr_bgcolor = apr_pstrdup(doc->pool, cur->value);
+        }
+      }
+    }
+    if (chtml20->style) {
+      css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, chtml20->style);
+      css_selector_t *cur_sel;
+      for (cur_sel = pseudos->selector_head.next; cur_sel != &pseudos->selector_head; cur_sel = cur_sel->next) {
+        if (cur_sel->name && strcasecmp(cur_sel->name, "a:link") == 0) {
+          css_property_t *cur;
+          for (cur = cur_sel->property_head.next; cur != &cur_sel->property_head; cur = cur->next) {
+            if (cur->name && strcasecmp(cur->name, "color") == 0) {
+              attr_link = apr_pstrdup(doc->pool, cur->value);
+              break;
+            }
+          }
+          break;
+        }
+      }
+    }
+  }
+  W_L("<body");
+  if (attr_bgcolor) {
+    W_L(" bgcolor=\"");
+    W_V(attr_bgcolor);
+    W_L("\"");
+  }
+  if (attr_text) {
+    W_L(" text=\"");
+    W_V(attr_text);
+    W_L("\"");
+  }
+  if (attr_link) {
+    W_L(" link=\"");
+    W_V(attr_link);
+    W_L("\"");
+  }
   W_L(">");
 
   return chtml20->out;
@@ -3614,7 +3668,7 @@ s_chtml20_end_dl_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a handter who processes the DT tag.
+ * It is a handler who processes the DT tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3632,7 +3686,7 @@ s_chtml20_start_dt_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a handter who processes the DT tag.
+ * It is a handler who processes the DT tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3649,7 +3703,7 @@ s_chtml20_end_dt_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a handder who processes the DD tag.
+ * It is a handler who processes the DD tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3667,7 +3721,7 @@ s_chtml20_start_dd_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a handder who processes the DD tag.
+ * It is a handler who processes the DD tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3684,7 +3738,7 @@ s_chtml20_end_dd_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a hanmenuer who processes the MENU tag.
+ * It is a handler who processes the MENU tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3703,7 +3757,7 @@ s_chtml20_start_menu_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a hanmenuer who processes the MENU tag.
+ * It is a handler who processes the MENU tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
@@ -3722,7 +3776,7 @@ s_chtml20_end_menu_tag(void *pdoc, Node *UNUSED(child))
 
 
 /**
- * It is a hanplaintexter who processes the PLAINTEXT tag.
+ * It is a handler who processes the PLAINTEXT tag.
  *
  * @param pdoc  [i/o] The pointer to the CHTML structure at the output
  *                     destination is specified.
index c6f5346..405b1f9 100644 (file)
@@ -577,6 +577,7 @@ void test_chtml20_body_tag_with_css_001();
 void test_chtml20_body_tag_with_css_002();
 void test_chtml20_body_tag_with_css_003();
 void test_chtml20_body_tag_with_css_004();
+void test_chtml20_body_tag_with_css_005();
 /* pend */
 
 int
@@ -1115,6 +1116,7 @@ main()
   CU_add_test(chtml20_suite, "test body with css 002",                             test_chtml20_body_tag_with_css_002);
   CU_add_test(chtml20_suite, "test body with css 003",                             test_chtml20_body_tag_with_css_003);
   CU_add_test(chtml20_suite, "test body with css 004",                             test_chtml20_body_tag_with_css_004);
+  CU_add_test(chtml20_suite, "test body with css 005",                             test_chtml20_body_tag_with_css_005);
   /* aend */
 
   CU_basic_run_tests();
@@ -15672,6 +15674,8 @@ void test_chtml20_body_tag_with_css_004()
   tmp = chxj_encoding(&r, TEST_STRING, &destlen);
   ret = chxj_convert_chtml20(&r, &spec, tmp, destlen, &destlen, &entry, &cookie);
   ret = chxj_rencoding(&r, ret, &destlen);
+  fprintf(stderr, "actual:[%s]\n", ret);
+  fprintf(stderr, "expect:[%s]\n", RESULT_STRING);
   CU_ASSERT(ret != NULL);
   CU_ASSERT(strcmp(RESULT_STRING, ret) == 0);
   CU_ASSERT(destlen == sizeof(RESULT_STRING)-1);
@@ -15681,6 +15685,52 @@ void test_chtml20_body_tag_with_css_004()
 #undef TEST_STRING
 #undef RESULT_STRING
 }
+char *test_chxj_serf_get060(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len)
+{
+  static char *css = "a:focus { display: none }\n"
+                     "a:link  { display: none }\n"
+                     "a       { display: none }\n"
+                     "hr      { display: none }\n"
+                     "a:link  { color:#ff0000 }\n";
+  *len = strlen(css);
+  call_check = 1;
+  return css;
+}
+void test_chtml20_body_tag_with_css_005()
+{
+#define  TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\"  type=\"text/css\" />" \
+                     "</head><body>あいう</body></html>"
+#define  RESULT_STRING "<html><head></head><body link=\"#ff0000\">あいう</body></html>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+  chxj_serf_get = test_chxj_serf_get060;
+  call_check = 0;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+  entry.action |= CONVRULE_CSS_ON_BIT;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml20(&r, &spec, tmp, destlen, &destlen, &entry, &cookie);
+  ret = chxj_rencoding(&r, ret, &destlen);
+  fprintf(stderr, "actual:[%s]\n", ret);
+  fprintf(stderr, "expect:[%s]\n", RESULT_STRING);
+  CU_ASSERT(ret != NULL);
+  CU_ASSERT(strcmp(RESULT_STRING, ret) == 0);
+  CU_ASSERT(destlen == sizeof(RESULT_STRING)-1);
+  CU_ASSERT(call_check == 1);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
 /*
  * vim:ts=2 et
  */