From de034f2f14f1527e2fc3f09bd43af944d02fb57d Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 9 Aug 2005 13:54:40 +0000 Subject: [PATCH] untested xsl code git-svn-id: svn://svn.open-ils.org/ILS/trunk@1627 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/apachemods/mod_xmltools.c | 52 ++++++++++++++++++++++++-- Open-ILS/src/apachemods/mod_xmltools.h | 18 +++++++-- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/apachemods/mod_xmltools.c b/Open-ILS/src/apachemods/mod_xmltools.c index 6d801e4d25..aa7f843c46 100644 --- a/Open-ILS/src/apachemods/mod_xmltools.c +++ b/Open-ILS/src/apachemods/mod_xmltools.c @@ -14,12 +14,32 @@ static const char* mod_xmltools_set_default_locale(cmd_parms *parms, void *confi return NULL; } +static const char* mod_xmltools_set_pre_xsl(cmd_parms *parms, void *config, const char *arg) { + mod_xmltools_config *cfg = ap_get_module_config(parms->server->module_config, &mod_xmltools); + cfg->pre_xsl = xsltParseStylesheetFile( (xmlChar*) arg ); + if(cfg->pre_xsl == NULL) { + fprintf(stderr, "Unable to parse PreXSL stylesheet %s\n", (char*) arg ); + fflush(stderr); + } + return NULL; +} + +static const char* mod_xmltools_set_post_xsl(cmd_parms *parms, void *config, const char *arg) { + mod_xmltools_config *cfg = ap_get_module_config(parms->server->module_config, &mod_xmltools); + cfg->post_xsl = xsltParseStylesheetFile( (xmlChar*) arg ); + if(cfg->post_xsl == NULL) { + fprintf(stderr, "Unable to parse PostXSL stylesheet %s\n", (char*) arg ); + fflush(stderr); + } + return NULL; +} + /* tell apache about our commands */ static const command_rec mod_xmltools_cmds[] = { - AP_INIT_TAKE1( "XMLToolsDefaultLocale", mod_xmltools_set_default_locale, - NULL, RSRC_CONF, "XMLToolsDefaultLocale - Test"), - AP_INIT_TAKE1( "XMLToolsLocaleDir", mod_xmltools_set_locale_dir, - NULL, RSRC_CONF, "XMLToolsLocaleDir - Test"), + AP_INIT_TAKE1( CONFIG_LOCALE, mod_xmltools_set_default_locale, NULL, RSRC_CONF, "default locale"), + AP_INIT_TAKE1( CONFIG_LOCALE_DIR, mod_xmltools_set_locale_dir, NULL, RSRC_CONF, "locale directory"), + AP_INIT_TAKE1( CONFIG_PRE_XSL, mod_xmltools_set_pre_xsl, NULL, RSRC_CONF, "pre xsl"), + AP_INIT_TAKE1( CONFIG_POST_XSL, mod_xmltools_set_post_xsl, NULL, RSRC_CONF, "post xsl"), {NULL} }; @@ -48,6 +68,8 @@ static int mod_xmltools_handler (request_rec* r) { mod_xmltools_config *cfg = ap_get_module_config(r->server->module_config, &mod_xmltools); char* locale_dir = cfg->locale_dir; char* default_locale = cfg->default_locale; + xsltStylesheetPtr pre_xsl = cfg->pre_xsl; + xsltStylesheetPtr post_xsl = cfg->post_xsl; /* we accept get/post requests */ r->allowed |= (AP_METHOD_BIT << M_GET); @@ -74,6 +96,17 @@ static int mod_xmltools_handler (request_rec* r) { fflush(stderr); + if(pre_xsl) { + xmlDocPtr newdoc; + newdoc = xsltApplyStylesheet(pre_xsl, doc, NULL ); + if(newdoc == NULL) { + fprintf(stderr, "Error applying PreXSL stylesheet\n"); + fflush(stderr); + } + xmlFreeDoc(doc); + doc = newdoc; + } + /* process xincludes */ if( xmlXIncludeProcess(doc) < 0 ) { fprintf(stderr, "\n ^-- Error processing XIncludes for file %s\n", file); @@ -94,6 +127,17 @@ static int mod_xmltools_handler (request_rec* r) { /* force DTD entity replacement */ doc = xmlProcessDtdEntities(doc); + if(post_xsl) { + xmlDocPtr newdoc; + newdoc = xsltApplyStylesheet(post_xsl, doc, NULL ); + if(newdoc == NULL) { + fprintf(stderr, "Error applying PostXSL stylesheet\n"); + fflush(stderr); + } + xmlFreeDoc(doc); + doc = newdoc; + } + /* stringify */ char* xml = xmlDocToString(doc, 0); diff --git a/Open-ILS/src/apachemods/mod_xmltools.h b/Open-ILS/src/apachemods/mod_xmltools.h index 75a00f8292..8dd7e63994 100644 --- a/Open-ILS/src/apachemods/mod_xmltools.h +++ b/Open-ILS/src/apachemods/mod_xmltools.h @@ -1,12 +1,14 @@ #include "apachetools.h" #include "xmltools.h" +#include +#include +#include #define MODULE_NAME "mod_xmltools" /* our module name */ #define PARAM_LOCALE "locale" /* the URL param for the local directory */ #define LANG_DTD "lang.dtd" /* the DTD for the test entities */ - /* ------------------------------------------------------------------------------ */ /* Apache config items. These are defaults which are only used if they are not overriden by the Apache config or URL where appropriate */ @@ -16,6 +18,12 @@ #define DEFAULT_LOCALE "en-US" /* ------------------------------------------------------------------------------ */ +#define CONFIG_LOCALE "XMLToolsDefaultLocale" +#define CONFIG_LOCALE_DIR "XMLToolsLocaleDir" +#define CONFIG_PRE_XSL "XMLToolsPreXSL" +#define CONFIG_POST_XSL "XMLToolsPostXSL" + + /* This module */ module AP_MODULE_DECLARE_DATA mod_xmltools; @@ -23,9 +31,13 @@ module AP_MODULE_DECLARE_DATA mod_xmltools; /* our config structure */ typedef struct { - /* directory on disk where the locale directories live */ - char* locale_dir; + + char* locale_dir; /* directory on disk where the locale directories live */ char* default_locale; + + xsltStylesheetPtr pre_xsl; + xsltStylesheetPtr post_xsl; + } mod_xmltools_config; -- 2.43.2