--- parser3/src/include/pa_stylesheet_connection.h 2001/09/15 11:48:41 1.2 +++ parser3/src/include/pa_stylesheet_connection.h 2001/11/05 11:46:25 1.16 @@ -1,11 +1,10 @@ /** @file - Parser: stylesheet fstylesheet decl. + Parser: Stylesheet connection decl. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://paf.design.ru) - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_stylesheet_connection.h,v 1.2 2001/09/15 11:48:41 parser Exp $ + $Id: pa_stylesheet_connection.h,v 1.16 2001/11/05 11:46:25 paf Exp $ */ #ifndef PA_STYLESHEET_CONNECTION_H @@ -13,11 +12,11 @@ #include "pa_config_includes.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 +#include "XalanTransformer2.hpp" // defines @@ -31,12 +30,13 @@ class Stylesheet_connection : public Poo public: Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), - ftransformer(new XalanTransformer), + ftransformer(new XalanTransformer2), ffile_spec(afile_spec), time_used(0), prev_disk_time(0), - fservices_pool(0) { + fservices_pool(0), + fstylesheet(0) { } const String& file_spec() { return ffile_spec; } @@ -48,9 +48,10 @@ public: bool expired(time_t older_dies) { return time_usedclose_connection(ffile_spec, *this); + stylesheet_manager->close_connection(ffile_spec, *this); } void disconnect() { @@ -62,8 +63,9 @@ public: bool connected() { return fstylesheet!=0; } - XalanCompiledStylesheet& stylesheet() { - if(time_t new_disk_time=get_new_disk_time()) + const XalanCompiledStylesheet& stylesheet(bool nocache) { + time_t new_disk_time=get_new_disk_time(); + if(nocache || new_disk_time) load(new_disk_time); return *fstylesheet; } @@ -78,11 +80,27 @@ private: 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, - &ffile_spec, - ftransformer->getLastError()); + try{ + const XalanCompiledStylesheet *nstylesheet; + ftransformer->compileStylesheet2(ffile_spec.cstr(String::UL_FILE_SPEC), nstylesheet); + ftransformer->destroyStylesheet(fstylesheet); + fstylesheet=nstylesheet; + } + catch (XSLException& e) { + Exception::provide_source(pool, &ffile_spec, e); + } + catch (SAXParseException& e) { + Exception::provide_source(pool, &ffile_spec, e); + } + catch (SAXException& e) { + Exception::provide_source(pool, &ffile_spec, e); + } + catch (XMLException& e) { + Exception::provide_source(pool, &ffile_spec, e); + } + catch(const XalanDOMException& e) { + Exception::provide_source(pool, &ffile_spec, e); + } prev_disk_time=new_disk_time; } @@ -92,27 +110,31 @@ private: time_t atime, mtime, ctime; String stamp_file_spec(ffile_spec); stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; - // {file_spec}.stamp modification time OR {file_spec} mtime - if(!file_stat(file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec, + // {file_spec}.stamp modification time OR {file_spec} + const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; + file_stat(stat_file_spec, size, atime, mtime, ctime, - false/*no exceptions on global pool, please*/)) - mtime=0; // no file=no time + true/*exception on error*/); return mtime; } private: const String& ffile_spec; - XalanCompiledStylesheet *fstylesheet; + const XalanCompiledStylesheet *fstylesheet; time_t time_used; time_t prev_disk_time; private: - XalanTransformer *ftransformer; + XalanTransformer2 *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