[10] Adjustments to HTML output: 1.

  • From: TimBray@kenai.com
  • To: commits@mod-atom.kenai.com
  • Subject: [10] Adjustments to HTML output: 1.
  • Date: Tue, 16 Sep 2008 23:37:49 +0000 (GMT)

Revision: 10
Author:   tim.bray@sun.com
Date:     2008-09-16 23:37:45 UTC

Log Message:
-----------
Adjustments to HTML output:
1. Always use an extension of .html not .xhtml, confuses
servers/browsers
2. When it's <content type="text"> just brute-force-dump it into a
.text file



Modified Paths:
--------------
    src/mod_atom.csrc/filter.c

Diffs:
-----
Index: src/mod_atom.c
===================================================================
--- src/mod_atom.c      (revision 9)
+++ src/mod_atom.c      (revision 10)
@@ -21,8 +21,6 @@
 /* XXX TODO:
  *  - When type_of_content == TEXT_TYPE, should just whatever's in
<content>
  *    into the .text file, no HTML fanciness
- *  - restore access control so that collections & atom entries not
visible
- *    via D/pub/..., only via D/atom/...
  */
 
 /* mod_atom.c: Minimal implementation of the Atom Publishing Protocol,
which
@@ -902,7 +900,7 @@
          *  to figure out the exact name, but why not just try
deleting any
         *  of them.
          */
-       char * extensions[] = { ".html", ".text", ".xhtml", NULL };
+       char * extensions[] = { ".html", ".text", ".html", NULL };
        int i;
        char * base =  apr_pstrdup(r->pool, r->filename);
        *(rindex(base, '.')) = 0;
@@ -1022,7 +1020,7 @@
     switch (e->type_of_content) {
     case MEDIA_TYPE: return "";
     case HTML_TYPE: return ".html";
-    case XHTML_TYPE: return ".xhtml";
+    case XHTML_TYPE: return ".html";
     case TEXT_TYPE: return ".text";
     }
     return NULL;
@@ -2291,13 +2289,9 @@
     genxWriter gw;
     void * writer;
     char * problem;
-    apr_xml_elem
-            * title = NULL, * summary = NULL, * rights = NULL, *
content = NULL;
 
     apr_xml_doc * template;
     char * template_fn;
-    char * wanted[] = { "content", "title", "summary", "rights", NULL
};
-    apr_xml_elem * * children[] = { &content, &title, &summary,
&rights };
 
     char * extension = entry_extension(r->pool, e);
 
@@ -2310,9 +2304,6 @@
     if (!is_html_enabled(r->pool, e->pub))
        return;
 
-    /* first, we have to find the text constructs */
-    atom_xml_children(e->xml, e->xml->root, ATOM_NS, wanted,
children);
-
     filename = atom_join(r->pool, e->pub->dir, PUB_DIR, e->path,
NULL);
     filename = apr_pstrcat(r->pool, filename, extension, NULL);
     tempname = dir_of(r->pool, filename);
@@ -2326,30 +2317,48 @@
 
     /* the tempname we'll actually write into */
     tempname = temp_filename(r->pool, filename);
-    status = apr_file_open(&fp, tempname,
-                           APR_FOPEN_WRITE | APR_FOPEN_CREATE, PERMS,
r->pool);
-    if (status != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
-                     "Can't create HTML file '%s'", tempname);
-        return;
-    }
 
-    writer = atom_genx_file_writer(r->pool, fp, &problem);
-    if (!writer) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
-                     "Can't make XML writer for '%s': %s", tempname,
problem);
-        return;
-    }
-    gw = atom_genx_get_writer(writer);
+    /* type could be HTML, XHTML, or TEXT.  If TEXT, just dump the
sucker */
+    if (e->type_of_content == TEXT_TYPE) {
+       apr_xml_elem * content;
+       char * problem;
 
-    template_fn = atom_join(r->pool, e->pub->dir, PUB_DIR, EXTRAS_DIR,
-                            TEMPLATES_DIR, ENTRY_TEMPLATE, NULL);
-    if (xnarf(template_fn, &template, r->pool) != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
-                     "Can't parse entry template '%s'", template_fn);
-        return;
+       content = atom_xml_child(e->xml, e->xml->root, ATOM_NS,
"content");
+       if ((problem = to_file(tempname, element_text(content,
r->pool),
+                              r->pool)))
+           ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+                        "Can't write text file '%s': %s", tempname,
problem);
+    } else {
+
+       /* HTML */
+       status = apr_file_open(&fp, tempname,
+                              APR_FOPEN_WRITE | APR_FOPEN_CREATE,
PERMS,
+                              r->pool);
+       if (status != APR_SUCCESS) {
+           ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+                        "Can't create HTML file '%s'", tempname);
+           return;
+       }
+       writer = atom_genx_file_writer(r->pool, fp, &problem);
+       if (!writer) {
+           ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+                        "Can't make XML writer for '%s': %s",
+                        tempname, problem);
+           return;
+       }
+
+       gw = atom_genx_get_writer(writer);
+
+       template_fn = atom_join(r->pool, e->pub->dir, PUB_DIR,
EXTRAS_DIR,
+                               TEMPLATES_DIR, ENTRY_TEMPLATE, NULL);
+       if (xnarf(template_fn, &template, r->pool) != APR_SUCCESS) {
+           ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+                        "Can't parse entry template '%s'",
template_fn);
+           return;
+       }
+       run_e_template(gw, template, r, e);
+       apr_file_close(fp);
     }
-    run_e_template(gw, template, r, e);
 
     /* rename tempfile to final target */
     if (apr_file_rename(tempname, filename, r->pool) != APR_SUCCESS) {
Index: src/filter.c
===================================================================
--- src/filter.c        (revision 9)
+++ src/filter.c        (revision 10)
@@ -210,13 +210,15 @@
            if (a_value == NULL)
                a_value = "";
            
-            if (!apr_hash_get(whitelist_a, tidyAttrName(a),
APR_HASH_KEY_STRING))
+            if (!apr_hash_get(whitelist_a, tidyAttrName(a),
+                             APR_HASH_KEY_STRING))
                 continue;
 
             /* attribute probably OK */
             if (strcmp(a_name, "href") == 0 || strcmp(a_name, "src")
== 0) {
                 int is_abs = (ap_regexec(abs_uri_re, a_value, 0, NULL,
0) == 0);
-                int is_http = (ap_regexec(http_uri_re, a_value, 0,
NULL, 0) == 0);
+                int is_http =
+                   (ap_regexec(http_uri_re, a_value, 0, NULL, 0) ==
0);
 
                 if (is_abs && (!is_http))
                     continue;


[10] Adjustments to HTML output: 1.

TimBray 09/16/2008
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close