bug fixes after testing
[Evergreen.git] / Open-ILS / src / apachemods / mod_xmlbuilder.h
1 #include "apachetools.h"
2 #include "opensrf/xml_utils.h"
3 #include "opensrf/osrf_hash.h"
4 #include "opensrf/osrf_list.h"
5 #include <libxslt/xslt.h>
6 #include <libxslt/transform.h>
7 #include <libxslt/xsltutils.h>
8
9 #define MODULE_NAME     "xmlbuilder_module"     /* our module name */
10
11 /* ------------------------------------------------------------------------------ */
12 /* Apache config items.  These are defaults which are only  used if they are not
13         overriden by the Apache config or URL where appropriate */
14 /* ------------------------------------------------------------------------------ */
15 /* The default directory where the DTD files are stored */
16 #define MODXMLB_DEFAULT_LOCALE_PARAM    "locale"
17 #define MODXMLB_DEFAULT_BASE_DIR                        "/openils/var/web/locale"
18 #define MODXMLB_DEFAULT_LOCALE                  "en-US"                 
19 #define MODXMLB_DEFAULT_DTD                             NULL /* if defined, use this DTD only */
20 /* ------------------------------------------------------------------------------ */
21
22 #define MODXMLB_CONFIG_LOCALE           "XMLBuilderDefaultLocale"
23 #define MODXMLB_CONFIG_BASE_DIR         "XMLBuilderBaseDir"
24 #define MODXMLB_CONFIG_POST_XSL                 "XMLBuilderPostXSL"
25 #define MODXMLB_CONFIG_DEFAULT_DTD      "XMLBuilderDefaultDTD"
26 #define MODXMLB_CONFIG_LOCALE_PARAM "XMLBuilderLocaleParam"
27 #define MODXMLB_CONFIG_CONTENT_TYPE "XMLBuilderContentType"
28
29
30
31 /* This module */
32 module AP_MODULE_DECLARE_DATA xmlbuilder_module;
33
34
35 /* our config structure */
36 typedef struct {
37
38         char* baseDir;                                  /* directory on disk where the DTD files live */
39         char* defaultLocale;                    /* locale dir from config or default */
40         char* defaultDtd;                               /* if defined, we load this DTD only */
41         char* localeParam;                      /* the CGI param used to choose the locale dir dynamically */
42         char* contentType;                      /* what content type to serve our files as (derfault is text/html) */
43         xsltStylesheetPtr postXSL;      /* if defined, run this XSL after parsing */
44
45 } xmlBuilderConfig;
46
47 typedef struct {
48         xmlBuilderConfig* config;
49         xmlDocPtr doc;
50         osrfHash* entHash;
51         osrfHash* dtdHash;
52         osrfList* nodeList;
53         int xmlError;
54         char* xmlFile;
55 } xmlBuilderContext;
56
57
58
59 xmlDocPtr xmlBuilderProcessFile( char* XMLFile, xmlBuilderConfig* config );
60
61 void xmlBuilderAddDtd( const char* sysId, xmlBuilderContext* context );
62 void xmlBuilderAddAtts( xmlBuilderContext* ctx, xmlNodePtr ptr, const xmlChar** atts );
63
64 /* SAX Callbacks */
65 void xmlBuilderStartElement( void* blob, const xmlChar *name, const xmlChar **atts );
66 void xmlBuilderEndElement( void* blob, const xmlChar* name );
67 void xmlBuilderHandleCharacter(void* blob, const xmlChar *ch, int len);
68 void xmlBuilderParseError( void* blob, const char* msg, ... );
69 xmlEntityPtr xmlBuilderGetEntity( void* blob, const xmlChar* name );
70 void xmlBuilderExtSubset( void* blob, const xmlChar* name, const xmlChar* extId, const xmlChar* sysId );
71 void xmlBuilderProcInstruction( void* blob, const xmlChar* name, const xmlChar* data );
72 void xmlBuilderComment( void* blob, const xmlChar* data );
73
74
75 static xmlSAXHandler xmlBuilderSaxHandlerStruct = {
76    NULL,                                                                /* internalSubset */
77    NULL,                                                                /* isStandalone */
78    NULL,                                                                /* hasInternalSubset */
79    NULL,                                                                /* hasExternalSubset */
80         NULL,                                                           /* resolveEntity */
81    xmlBuilderGetEntity,                 /* getEntity */
82    NULL,                                                        /* entityDecl */
83    NULL,                                                                /* notationDecl */
84    NULL,                                                                /* attributeDecl */
85    NULL,                                                                /* elementDecl */
86    NULL,                                                        /* unparsedEntityDecl */
87    NULL,                                                                /* setDocumentLocator */
88    NULL,                                                                /* startDocument */
89    NULL,                                                                /* endDocument */
90         xmlBuilderStartElement,         /* startElement */
91         xmlBuilderEndElement,           /* endElement */
92    NULL,                                                                /* reference */
93         xmlBuilderHandleCharacter,      /* characters */
94    NULL,                                                                /* ignorableWhitespace */
95    xmlBuilderProcInstruction, /* processingInstruction */
96    xmlBuilderComment,                   /* comment */
97    xmlBuilderParseError,                /* xmlParserWarning */
98    xmlBuilderParseError,                /* xmlParserError */
99    NULL,                                                                /* xmlParserFatalError : unused */
100    NULL,                                                                /* getParameterEntity */
101    NULL,                                                                /* cdataBlock; */
102    xmlBuilderExtSubset,                 /* externalSubset; */
103    1,
104    NULL,
105    NULL,                                                                /* startElementNs */
106    NULL,                                                                /* endElementNs */
107         NULL                                                            /* xmlStructuredErrorFunc */
108 };
109 static const xmlSAXHandlerPtr xmlBuilderSaxHandler = &xmlBuilderSaxHandlerStruct;
110
111