static char *
s_jxhtml_start_body_tag(void *pdoc, Node *node)
{
- jxhtml_t *jxhtml;
- Doc *doc;
- request_rec *r;
- Attr *attr;
+ jxhtml_t *jxhtml;
+ Doc *doc;
+ request_rec *r;
+ Attr *attr;
+ char *attr_bgcolor = NULL;
+ char *attr_text = NULL;
+ char *attr_link = NULL;
+ char *attr_style = NULL;
jxhtml = GET_JXHTML(pdoc);
doc = jxhtml->doc;
r = doc->r;
- W_L("<body");
/*--------------------------------------------------------------------------*/
/* Get Attributes */
/*--------------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* CHTML 2.0 */
/*----------------------------------------------------------------------*/
- W_L(" bgcolor=\"");
- W_V(value);
- W_L("\"");
+ attr_bgcolor = value;
}
else if (STRCASEEQ('t','T',"text",name) && value && *value) {
/*----------------------------------------------------------------------*/
/* CHTML 2.0 */
/*----------------------------------------------------------------------*/
- W_L(" text=\"");
- W_V(value);
- W_L("\"");
+ attr_text = value;
}
else if (STRCASEEQ('l','L',"link",name) && value && *value) {
/*----------------------------------------------------------------------*/
/* CHTML 2.0 */
/*----------------------------------------------------------------------*/
- W_L(" link=\"");
- W_V(value);
- W_L("\"");
+ attr_link = value;
}
else if (STRCASEEQ('a','A',"alink",name)) {
/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/* ignore */
}
+ else if (STRCASEEQ('s','S',"style",name) && value && *value) {
+ attr_style = value;
+ }
+ }
+
+ if (IS_CSS_ON(jxhtml->entryp)) {
+ css_prop_list_t *style = s_jxhtml_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 (jxhtml->style) {
+ css_stylesheet_t *pseudos = chxj_find_pseudo_selectors(doc, jxhtml->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);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ W_L("<body");
+ if (attr_bgcolor || attr_text) {
+ W_L(" style=\"");
+ if (attr_bgcolor) {
+ attr_bgcolor = chxj_css_rgb_func_to_value(doc->pool, attr_bgcolor);
+ W_L("background-color:");
+ W_V(attr_bgcolor);
+ W_L(";");
+ }
+ if (attr_text) {
+ attr_text = chxj_css_rgb_func_to_value(doc->pool, attr_text);
+ W_L("color:");
+ W_V(attr_text);
+ W_L(";");
+ }
+ W_L("\"");
+ }
+ if (attr_link) {
+ attr_link = chxj_css_rgb_func_to_value(doc->pool, attr_link);
+ W_L(" link=\"");
+ W_V(attr_link);
+ W_L("\"");
}
W_L("><div>");
return jxhtml->out;
r = doc->r;
W_L("</div></body>");
+ if (IS_CSS_ON(jxhtml->entryp)) {
+ chxj_css_pop_prop_list(jxhtml->css_prop_stack);
+ }
return jxhtml->out;
}
void test_jxhtml_h6_tag_with_css_004();
void test_jxhtml_h6_tag_with_css_005();
void test_jxhtml_h6_tag_with_css_006();
+
+void test_jxhtml_body_tag_with_css_001();
+void test_jxhtml_body_tag_with_css_002();
+void test_jxhtml_body_tag_with_css_003();
+void test_jxhtml_body_tag_with_css_004();
/* pend */
int
CU_add_test(jxhtml_suite, "test h6 with css 004", test_jxhtml_h6_tag_with_css_004);
CU_add_test(jxhtml_suite, "test h6 with css 005", test_jxhtml_h6_tag_with_css_005);
CU_add_test(jxhtml_suite, "test h6 with css 006", test_jxhtml_h6_tag_with_css_006);
+
+ CU_add_test(jxhtml_suite, "test body with css 001", test_jxhtml_body_tag_with_css_001);
+ CU_add_test(jxhtml_suite, "test body with css 002", test_jxhtml_body_tag_with_css_002);
+ CU_add_test(jxhtml_suite, "test body with css 003", test_jxhtml_body_tag_with_css_003);
+ CU_add_test(jxhtml_suite, "test body with css 004", test_jxhtml_body_tag_with_css_004);
/* aend */
CU_basic_run_tests();
void test_jxhtml_body_tag_004()
{
#define TEST_STRING "<body bgcolor=\"#ff0000\"></body>"
-#define RESULT_STRING "<body bgcolor=\"#ff0000\"><div></div></body>"
+#define RESULT_STRING "<body style=\"background-color:#ff0000;\"><div></div></body>"
char *ret;
char *tmp;
device_table spec;
void test_jxhtml_body_tag_007()
{
#define TEST_STRING "<body text=\"#ff0000\"></body>"
-#define RESULT_STRING "<body text=\"#ff0000\"><div></div></body>"
+#define RESULT_STRING "<body style=\"color:#ff0000;\"><div></div></body>"
char *ret;
char *tmp;
device_table spec;
#undef TEST_STRING
#undef RESULT_STRING
}
+
+
+
+/*===========================================================================*/
+/* body tag with CSS */
+/*===========================================================================*/
+char *test_chxj_serf_get058(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:visited { display:none }\n"
+ "body { color:#ff0000 }\n";
+ *len = strlen(css);
+ call_check = 1;
+ return css;
+}
+void test_jxhtml_body_tag_with_css_001()
+{
+#define TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\" type=\"text/css\" />" \
+ "</head><body>あいう</body></html>"
+#define RESULT_STRING "<?xml version='1.0' encoding='Shift_JIS' ?>" \
+ "<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"html-basic10-plus.dtd\">" \
+ "<html><head></head><body style=\"color:#ff0000;\"><div>あいう</div></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_get058;
+ 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_jxhtml(&r, &spec, tmp, destlen, &destlen, &entry, &cookie);
+ ret = chxj_rencoding(&r, ret, &destlen);
+ 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
+}
+
+
+char *test_chxj_serf_get059(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:visited { display:none }\n"
+ "body { background-color:#ff0000 }\n";
+ *len = strlen(css);
+ call_check = 1;
+ return css;
+}
+void test_jxhtml_body_tag_with_css_002()
+{
+#define TEST_STRING "<html><head><link rel=\"stylesheet\" href=\"http://localhost/a.css\" type=\"text/css\" />" \
+ "</head><body>あいう</body></html>"
+#define RESULT_STRING "<?xml version='1.0' encoding='Shift_JIS' ?>" \
+ "<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"html-basic10-plus.dtd\">" \
+ "<html><head></head><body style=\"background-color:#ff0000;\"><div>あいう</div></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_get059;
+ 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_jxhtml(&r, &spec, tmp, destlen, &destlen, &entry, &cookie);
+ ret = chxj_rencoding(&r, ret, &destlen);
+ 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
+}
+
+void test_jxhtml_body_tag_with_css_003()
+{
+#define TEST_STRING "<html><head>" \
+ "</head><body style=\"color:#ffff00\">あいう</body></html>"
+#define RESULT_STRING "<?xml version='1.0' encoding='Shift_JIS' ?>" \
+ "<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"html-basic10-plus.dtd\">" \
+ "<html><head></head><body style=\"color:#ffff00;\"><div>あいう</div></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_get059;
+ 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_jxhtml(&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 == 0);
+
+ APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_jxhtml_body_tag_with_css_004()
+{
+#define TEST_STRING "<html><head>" \
+ "</head><body style=\"background-color:#ffff00\">あいう</body></html>"
+#define RESULT_STRING "<?xml version='1.0' encoding='Shift_JIS' ?>" \
+ "<!DOCTYPE html PUBLIC \"-//J-PHONE//DTD XHTML Basic 1.0 Plus//EN\" \"html-basic10-plus.dtd\">" \
+ "<html><head></head><body style=\"background-color:#ffff00;\"><div>あいう</div></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_get059;
+ 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_jxhtml(&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 == 0);
+
+ APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
/*
* vim:ts=2 et
*/