]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/apachemods/mod_xmlbuilder.h
libraries are now filtered on id (there are duplicate names, such as "Bookmobile")
[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
73
74 static xmlSAXHandler xmlBuilderSaxHandlerStruct = {
75    NULL,                                                                /* internalSubset */
76    NULL,                                                                /* isStandalone */
77    NULL,                                                                /* hasInternalSubset */
78    NULL,                                                                /* hasExternalSubset */
79         NULL,                                                           /* resolveEntity */
80    xmlBuilderGetEntity,                 /* getEntity */
81    NULL,                                                        /* entityDecl */
82    NULL,                                                                /* notationDecl */
83    NULL,                                                                /* attributeDecl */
84    NULL,                                                                /* elementDecl */
85    NULL,                                                        /* unparsedEntityDecl */
86    NULL,                                                                /* setDocumentLocator */
87    NULL,                                                                /* startDocument */
88    NULL,                                                                /* endDocument */
89         xmlBuilderStartElement,         /* startElement */
90         xmlBuilderEndElement,           /* endElement */
91    NULL,                                                                /* reference */
92         xmlBuilderHandleCharacter,      /* characters */
93    NULL,                                                                /* ignorableWhitespace */
94    xmlBuilderProcInstruction, /* processingInstruction */
95    NULL,                                                                /* comment */
96    xmlBuilderParseError,                /* xmlParserWarning */
97    xmlBuilderParseError,                /* xmlParserError */
98    NULL,                                                                /* xmlParserFatalError : unused */
99    NULL,                                                                /* getParameterEntity */
100    NULL,                                                                /* cdataBlock; */
101    xmlBuilderExtSubset,                 /* externalSubset; */
102    1,
103    NULL,
104    NULL,                                                                /* startElementNs */
105    NULL,                                                                /* endElementNs */
106         NULL                                                            /* xmlStructuredErrorFunc */
107 };
108 static const xmlSAXHandlerPtr xmlBuilderSaxHandler = &xmlBuilderSaxHandlerStruct;
109
110