--- parser3/src/include/pa_stylesheet_connection.h 2001/09/26 10:32:25 1.5 +++ parser3/src/include/pa_stylesheet_connection.h 2003/03/06 15:32:37 1.32.2.4 @@ -1,22 +1,23 @@ /** @file - Parser: stylesheet fstylesheet decl. + Parser: Stylesheet connection decl. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: pa_stylesheet_connection.h,v 1.5 2001/09/26 10:32:25 parser Exp $ + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef PA_STYLESHEET_CONNECTION_H #define PA_STYLESHEET_CONNECTION_H -#include "pa_config_includes.h" +static const char* IDENT_STYLESHEET_CONNECTION_H="$Date: 2003/03/06 15:32:37 $"; + +#include "libxslt/xslt.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 +#include "pa_globals.h" // defines @@ -25,47 +26,47 @@ /** Connection with stylesheet: remembers time and can figure out that it needs recompilation */ -class Stylesheet_connection : public Pooled { +class Stylesheet_connection: public PA_Object { +private: -public: + StringPtr ffile_spec; + xsltStylesheet *fstylesheet; + time_t time_used; + time_t prev_disk_time; - Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), - ftransformer(new XalanTransformer), +public: + Stylesheet_connection(StringPtr afile_spec): ffile_spec(afile_spec), - time_used(0), prev_disk_time(0), - fservices_pool(0), - fstylesheet(0) { - } + fstylesheet(0), + time_used(0) {} - const String& file_spec() { return ffile_spec; } + StringPtr file_spec() { return ffile_spec; } - void set_services(Pool *aservices_pool) { - time_used=time(0); // they started to use at this time - fservices_pool=aservices_pool; - } bool expired(time_t older_dies) { - return time_usedclose_connection(ffile_spec, *this); + return references()==1/*!used*/ && time_useddestroyStylesheet(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() { - if(time_t new_disk_time=get_new_disk_time()) + 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: + + /// return to cache + void close() { + stylesheet_manager.close_connection(ffile_spec, *this); } private: @@ -76,44 +77,45 @@ 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()); + int saved=xmlDoValidityCheckingDefaultValue;// + xmlDoValidityCheckingDefaultValue=0;// + xsltStylesheet *nstylesheet= + xsltParseStylesheetFile(BAD_CAST ffile_spec->cstr(String::UL_FILE_SPEC).get()); + xmlDoValidityCheckingDefaultValue = saved;// + if(xmlHaveGenericErrors()) { + GdomeException exc=0; + throw Exception(ffile_spec, exc); + } + if(!nstylesheet) + throw Exception("file.missing", + ffile_spec, + "stylesheet failed to load"); + xsltFreeStylesheet(fstylesheet); + fstylesheet=nstylesheet; prev_disk_time=new_disk_time; } time_t get_disk_time() { size_t size; time_t atime, mtime, ctime; - String stamp_file_spec(ffile_spec); - stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; + StringPtr stamp_file_spec(ffile_spec); + *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, + StringPtr stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_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; - time_t time_used; - time_t prev_disk_time; - -private: - - XalanTransformer *ftransformer; + void touch() { + time_used=time(0); // they started to use at this time + } - Pool *fservices_pool; }; +DECLARE_OBJECT_PTR(Stylesheet_connection); + #endif