--- parser3/src/include/pa_stylesheet_connection.h 2001/10/01 08:53:58 1.7 +++ parser3/src/include/pa_stylesheet_connection.h 2002/01/14 17:48:56 1.18 @@ -2,22 +2,22 @@ Parser: Stylesheet connection decl. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_stylesheet_connection.h,v 1.7 2001/10/01 08:53:58 parser Exp $ + $Id: pa_stylesheet_connection.h,v 1.18 2002/01/14 17:48:56 paf Exp $ */ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H -#include "pa_config_includes.h" +#include "libxslt/libxslt.h" +#include "libxslt/xsltInternals.h" + #include "pa_pool.h" -#include "pa_xslt_stylesheet_manager.h" +#include "pa_stylesheet_manager.h" #include "pa_exception.h" #include "pa_common.h" -#include - // defines #define STYLESHEET_FILENAME_STAMP_SUFFIX ".stamp" @@ -30,8 +30,6 @@ class Stylesheet_connection : public Poo public: Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), - ftransformer(new XalanTransformer), - ffile_spec(afile_spec), time_used(0), prev_disk_time(0), @@ -48,25 +46,23 @@ public: bool expired(time_t older_dies) { return time_usedclose_connection(ffile_spec, *this); + stylesheet_manager->close_connection(ffile_spec, *this); } void disconnect() { - /*ignore error*/ftransformer->destroyStylesheet(fstylesheet); fstylesheet=0; - - // connection effectively useless now, free up some memory - delete ftransformer; + xsltFreeStylesheet(fstylesheet); fstylesheet=0; } bool connected() { return fstylesheet!=0; } - const XalanCompiledStylesheet& stylesheet(bool nocache) { + xsltStylesheet *stylesheet(bool nocache) { time_t new_disk_time=get_new_disk_time(); if(nocache || new_disk_time) load(new_disk_time); - return *fstylesheet; + return fstylesheet; } private: @@ -76,15 +72,19 @@ private: return now_disk_time>prev_disk_time?now_disk_time:0; } + /// @test grab errors void load(time_t new_disk_time) { Pool& pool=*fservices_pool; - int error=ftransformer->compileStylesheet(ffile_spec.cstr(String::UL_FILE_SPEC), fstylesheet); - if(error) - PTHROW(0, 0, + xsltStylesheet *nstylesheet; + nstylesheet=xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::UL_FILE_SPEC)); + if(!nstylesheet) + throw Exception(0, 0, &ffile_spec, - ftransformer->getLastError()); + "error compiling. TODO: grab errors"); + xsltFreeStylesheet(fstylesheet); + fstylesheet=nstylesheet; prev_disk_time=new_disk_time; } @@ -95,26 +95,27 @@ private: stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; // {file_spec}.stamp modification time OR {file_spec} const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; - if(!file_stat(stat_file_spec, + file_stat(stat_file_spec, size, atime, mtime, ctime, - false/*no exception on global pool[stat_file_spec], please*/)) - mtime=1; //no file=pseudo non-zero time, see get_new_disk_time + true/*exception on error*/); return mtime; } private: const String& ffile_spec; - const XalanCompiledStylesheet *fstylesheet; + xsltStylesheet *fstylesheet; time_t time_used; time_t prev_disk_time; private: - XalanTransformer *ftransformer; - Pool *fservices_pool; + +private: + void *malloc(size_t size) { return fservices_pool->malloc(size); } + void *calloc(size_t size) { return fservices_pool->calloc(size); } }; #endif