You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by au...@apache.org on 2001/02/01 15:22:05 UTC

cvs commit: xml-xalan/c/samples/ApacheModuleXSLT mod_xslt.c ApacheModuleXSLT.dsp

auriemma    01/02/01 06:22:05

  Added:       c/samples/ApacheModuleXSLT mod_xslt.c ApacheModuleXSLT.dsp
  Log:
  New sample which demonstrates how to use Xalan in Apache to perform dynamic transformations.
  
  Revision  Changes    Path
  1.1                  xml-xalan/c/samples/ApacheModuleXSLT/mod_xslt.c
  
  Index: mod_xslt.c
  ===================================================================
  /* ====================================================================
   * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * 4. The names "Apache Server" and "Apache Group" must not be used to
   *    endorse or promote products derived from this software without
   *    prior written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Apache Group
   *    for use in the Apache HTTP server project (http://www.apache.org/)."
   *
   * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Group and was originally based
   * on public domain software written at the National Center for
   * Supercomputing Applications, University of Illinois, Urbana-Champaign.
   * For more information on the Apache Group and the Apache HTTP server
   * project, please see <http://www.apache.org/>.
   *
   */
  /* 
   * ====================================================================
   * Configuration information for httpd.conf:
   * ====================================================================
  	<Location /xslt>
  			AddHandler mod_xslt .html
  			AddHandler mod_xslt .txt
  	</Location>
   * ====================================================================
  */
  #include "httpd.h"
  #include "http_config.h"
  #include "http_protocol.h"
  #include "http_log.h"
  #include "util_script.h"
  #include "http_main.h"
  #include "http_request.h"
  
  
  
  #include <XalanTransformer/XalanCAPI.h>
  
  
  
  static void xslt_init(server_rec *s, pool *p)
  {
  	ap_add_version_component("mod_xslt/Xalan/1.0");
  }
  
  
  
  static void xslt_child_init(server_rec *s, pool *p)
  {
  	XalanInitialize();
  }
  
  
  
  static void xslt_child_exit(server_rec *s, pool *p)
  {
  	XalanTerminate();
  }
  
  
  
  static unsigned long xalan_handler(const void *data, unsigned long length, const void *handle)
  {
  	request_rec *r = (request_rec*)handle;
  
  	char* d = (char *)data;
  
  	return ap_rwrite(d, length, r);
  }
  
  
  
  static int xslt_handler(request_rec *r)
  {
  	char * mimetype		= NULL;
  	char * filename		= NULL;
  	char * xmlfilename	= NULL;
  	char * xslfilename	= NULL;
  	
  	XalanHandle xalan = NULL;
  
  	int	error = DECLINED;
  	
  	mimetype = ap_pstrcat(r->pool, r->filename, NULL);
  
  	filename = ap_getword_nulls_nc(r->pool, &mimetype,'.');
  
  	xmlfilename = ap_pstrcat(r->pool,filename,".xml",NULL); 
  
  	xslfilename = ap_pstrcat(r->pool,filename,".xsl",NULL); 
  	
  	xalan = CreateXalanTransformer();
  	
  	//ap_send_http_header(r);
  
  	error = XalanTransformToHandler(xmlfilename, xslfilename, xalan, r, xalan_handler);
  
  	if(error)
  	{
  		r->uri = filename;
  		return DECLINED;
  	}
  
  	DeleteXalanTransformer(&xalan);
  
  	return OK;
  }
  
  
  
  static const handler_rec xslt_handlers[] =
  { 
      {"mod_xslt", xslt_handler},
      {NULL, NULL}
  };
  
  
  
  module MODULE_VAR_EXPORT xslt_module =
  {
      STANDARD_MODULE_STUFF,
      xslt_init,		/* initializer */
      NULL,			/* create per-directory config structure */
      NULL,			/* merge per-directory config structures */
      NULL,			/* create per-server config structure */
      NULL,			/* merge per-server config structures */
      NULL,			/* command table */
      xslt_handlers,	/* handlers */
      NULL,			/* translate_handler */
      NULL,			/* check_user_id */
      NULL,			/* check auth */
      NULL,			/* check access */
      NULL,			/* type_checker */
      NULL,			/* pre-run fixups */
      NULL,			/* logger */
      NULL,			/* header parser */
      xslt_child_init,/* child_init */
      xslt_child_exit,/* child_exit */
      NULL			/* post read-request */
  };
  
  
  
  1.1                  xml-xalan/c/samples/ApacheModuleXSLT/ApacheModuleXSLT.dsp
  
  Index: ApacheModuleXSLT.dsp
  ===================================================================
  # Microsoft Developer Studio Project File - Name="ApacheModuleXSLT" - Package Owner=<4>
  # Microsoft Developer Studio Generated Build File, Format Version 6.00
  # ** DO NOT EDIT **
  
  # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
  
  CFG=ApacheModuleXSLT - Win32 Debug
  !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  !MESSAGE use the Export Makefile command and run
  !MESSAGE 
  !MESSAGE NMAKE /f "ApacheModuleXSLT.mak".
  !MESSAGE 
  !MESSAGE You can specify a configuration when running NMAKE
  !MESSAGE by defining the macro CFG on the command line. For example:
  !MESSAGE 
  !MESSAGE NMAKE /f "ApacheModuleXSLT.mak" CFG="ApacheModuleXSLT - Win32 Debug"
  !MESSAGE 
  !MESSAGE Possible choices for configuration are:
  !MESSAGE 
  !MESSAGE "ApacheModuleXSLT - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
  !MESSAGE "ApacheModuleXSLT - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
  !MESSAGE 
  
  # Begin Project
  # PROP AllowPerConfigDependencies 0
  # PROP Scc_ProjName ""
  # PROP Scc_LocalPath ""
  CPP=cl.exe
  MTL=midl.exe
  RSC=rc.exe
  
  !IF  "$(CFG)" == "ApacheModuleXSLT - Win32 Release"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 0
  # PROP BASE Output_Dir "Release"
  # PROP BASE Intermediate_Dir "Release"
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 0
  # PROP Output_Dir "..\..\Build\Win32\VC6\Release"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Release\ApacheModuleXSLT"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEMODULEXSLT_EXPORTS" /YX /FD /c
  # ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\src" /I "\Apache Group\Apache\src\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEMODULEXSLT_EXPORTS" /YX /FD /c
  # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
  # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "NDEBUG"
  # ADD RSC /l 0x409 /d "NDEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
  # ADD LINK32 "\Apache Group\Apache\src\CoreR\ApacheCore.lib" ..\..\Build\Win32\VC6\Release\XalanTransformer.lib  kernel32.lib user32.lib /nologo /dll /machine:I386
  
  !ELSEIF  "$(CFG)" == "ApacheModuleXSLT - Win32 Debug"
  
  # PROP BASE Use_MFC 0
  # PROP BASE Use_Debug_Libraries 1
  # PROP BASE Target_Dir ""
  # PROP Use_MFC 0
  # PROP Use_Debug_Libraries 1
  # PROP Output_Dir "..\..\Build\Win32\VC6\Debug"
  # PROP Intermediate_Dir "..\..\Build\Win32\VC6\Debug\ApacheModuleXSLT"
  # PROP Ignore_Export_Lib 0
  # PROP Target_Dir ""
  # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEMODULEXSLT_EXPORTS" /YX /FD /GZ /c
  # ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "\Apache Group\Apache\src\include" /I "..\..\src" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEMODULEXSLT_EXPORTS" /YX /FD /GZ /c
  # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
  # ADD BASE RSC /l 0x409 /d "_DEBUG"
  # ADD RSC /l 0x409 /d "_DEBUG"
  BSC32=bscmake.exe
  # ADD BASE BSC32 /nologo
  # ADD BSC32 /nologo
  LINK32=link.exe
  # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
  # ADD LINK32 "\Apache Group\Apache\src\CoreD\ApacheCore.lib"  ..\..\Build\Win32\VC6\Debug\XalanTransformer.lib kernel32.lib user32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
  
  !ENDIF 
  
  # Begin Target
  
  # Name "ApacheModuleXSLT - Win32 Release"
  # Name "ApacheModuleXSLT - Win32 Debug"
  # Begin Group "Source Files"
  
  # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
  # Begin Source File
  
  SOURCE=.\mod_xslt.c
  # End Source File
  # End Group
  # Begin Group "Header Files"
  
  # PROP Default_Filter "h;hpp;hxx;hm;inl"
  # End Group
  # Begin Group "Resource Files"
  
  # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
  # End Group
  # End Target
  # End Project