[open-ils-commits] r8049 - trunk/Open-ILS/src/apachemods

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Nov 9 09:31:34 EST 2007


Author: dbs
Date: 2007-11-09 09:15:32 -0500 (Fri, 09 Nov 2007)
New Revision: 8049

Modified:
   trunk/Open-ILS/src/apachemods/mod_xmlent.c
Log:
Generate minimized tags for EMPTY elements if content-type = text/html


Modified: trunk/Open-ILS/src/apachemods/mod_xmlent.c
===================================================================
--- trunk/Open-ILS/src/apachemods/mod_xmlent.c	2007-11-09 01:34:43 UTC (rev 8048)
+++ trunk/Open-ILS/src/apachemods/mod_xmlent.c	2007-11-09 14:15:32 UTC (rev 8049)
@@ -1,4 +1,6 @@
 #include "httpd.h"
+/* vim:noet:ts=4
+ */
 #include "http_config.h"
 #include "http_core.h"
 #include "http_protocol.h"
@@ -40,12 +42,43 @@
 	int stripComments;	/* should we strip comments on the way out? */
 	int stripPI;			/* should we strip processing instructions on the way out? */
 	int stripDoctype;
-	int escapeScript;		/* if true, we html-escape anything text inside a <scritp> tag */
+	int escapeScript;		/* if true, we html-escape anything text inside a <script> tag */
 	char* contentType;	/* the content type used to server pages */
 	char* doctype;			/* the doctype header to send before any other data */
 } xmlEntConfig;
 
+/* check to see if this is an empty XHTML element */
+static int isEmptyElement(const char *element) {
+	/* derived from "grep EMPTY xhtml1-transitional.dtd" */
+	static char *emptyTags[] = {
+		"base",
+		"meta",
+		"link",
+		"hr",
+		"br",
+		"basefont",
+		"param",
+		"img",
+		"area",
+		"input",
+		"isindex",
+		"col",
+		0
+	};
 
+	int i, isEmpty;
+	const char *p;
+
+    i = 0;
+    isEmpty = 0;
+    p = *(emptyTags);
+	while (!isEmpty && p != 0) {
+		isEmpty = !strcmp((const char*)element, (const char*)p); 
+        p = *(emptyTags + ++i);
+	}
+	return isEmpty;
+}
+
 /* get the content type from the config */
 static const char* xmlEntSetContentType(cmd_parms *params, void *cfg, const char *arg) {
 	xmlEntConfig* config = (xmlEntConfig*) cfg;
@@ -54,7 +87,7 @@
 }
 
 
-/* get the stip PI flag from the config */
+/* get the strip PI flag from the config */
 static const char* xmlEntSetStripPI(cmd_parms *params, void *cfg, const char *arg) {
 	xmlEntConfig* config = (xmlEntConfig*) cfg;
 	char* a = (char*) arg;
@@ -191,9 +224,16 @@
 /* Starts an XML element */
 static void XMLCALL startElement(void *userData, const char *name, const char **atts) {
 	ap_filter_t* filter = (ap_filter_t*) userData;
+	xmlEntConfig* config = ap_get_module_config( 
+			filter->r->per_dir_config, &xmlent_module );
 	_fwrite(filter, "<%s", name );
 	printAttr( filter, atts );
-	_fwrite(filter, ">", name );
+	if (!strcmp(config->contentType, MODXMLENT_CONFIG_CONTENT_TYPE_DEFAULT)
+		&& isEmptyElement(name)) {
+		_fwrite(filter, " />", name );
+	} else {
+		_fwrite(filter, ">", name );
+	}
 	if(!strcmp(name, "script")) 
 		xmlEntInScript = 1;
 }
@@ -230,6 +270,12 @@
 /* Ends an XML element */
 static void XMLCALL endElement(void *userData, const char *name) {
 	ap_filter_t* filter = (ap_filter_t*) userData;
+	xmlEntConfig* config = ap_get_module_config( 
+			filter->r->per_dir_config, &xmlent_module );
+	if (!strcmp(config->contentType, MODXMLENT_CONFIG_CONTENT_TYPE_DEFAULT)
+			&& isEmptyElement(name)) { 
+		return;
+	}
 	_fwrite( filter, "</%s>", name );
 	if(!strcmp(name, "script")) 
 		xmlEntInScript = 1;
@@ -316,8 +362,8 @@
 		/* clean up when we're done */
 		if (APR_BUCKET_IS_EOS(currentBucket) || APR_BUCKET_IS_FLUSH(currentBucket)) {
     	  	APR_BUCKET_REMOVE(currentBucket);
-      	APR_BRIGADE_INSERT_TAIL(ctx->brigade, currentBucket);
-      	ap_pass_brigade(f->next, ctx->brigade);
+			APR_BRIGADE_INSERT_TAIL(ctx->brigade, currentBucket);
+			ap_pass_brigade(f->next, ctx->brigade);
 			XML_ParserFree(parser);
 			parser = NULL;
 		  	return APR_SUCCESS;



More information about the open-ils-commits mailing list