|
|
| version 1.19, 2002/01/16 10:28:35 | version 1.33, 2003/07/24 11:31:21 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: Stylesheet connection decl. | Parser: Stylesheet connection decl. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | |
| */ | */ |
| #ifndef PA_STYLESHEET_CONNECTION_H | #ifndef PA_STYLESHEET_CONNECTION_H |
| #define PA_STYLESHEET_CONNECTION_H | #define PA_STYLESHEET_CONNECTION_H |
| #include "libxslt/libxslt.h" | static const char* IDENT_STYLESHEET_CONNECTION_H="$Date$"; |
| #include "libxslt/xslt.h" | |
| #include "libxslt/xsltInternals.h" | #include "libxslt/xsltInternals.h" |
| #include "pa_pool.h" | |
| #include "pa_stylesheet_manager.h" | |
| #include "pa_exception.h" | #include "pa_exception.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_globals.h" | |
| // defines | // defines |
| Line 25 | Line 25 |
| /** Connection with stylesheet: | /** Connection with stylesheet: |
| remembers time and can figure out that it needs recompilation | remembers time and can figure out that it needs recompilation |
| */ | */ |
| class Stylesheet_connection : public Pooled { | class Stylesheet_connection: public PA_Object { |
| friend class Stylesheet_connection_ptr; | friend class Stylesheet_connection_ptr; |
| private: | |
| const String& ffile_spec; | |
| xsltStylesheet *fstylesheet; | |
| time_t time_used; | |
| time_t prev_disk_time; | |
| public: | public: |
| Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool), | Stylesheet_connection(const String& afile_spec): |
| ffile_spec(afile_spec), | ffile_spec(afile_spec), |
| prev_disk_time(0), | prev_disk_time(0), |
| fservices_pool(0), | |
| fstylesheet(0), | fstylesheet(0), |
| time_used(0), used(0) { | time_used(0), used(0) {} |
| } | |
| const String& file_spec() { return ffile_spec; } | const String& file_spec() { return ffile_spec; } |
| void set_services(Pool *aservices_pool) { | |
| fservices_pool=aservices_pool; | |
| } | |
| bool expired(time_t older_dies) { | bool expired(time_t older_dies) { |
| return !used && time_used<older_dies; | return !used && time_used<older_dies; |
| } | } |
| Line 65 public: | Line 67 public: |
| private: | private: |
| /// return to cache | /// return to cache |
| void close() { | void close(); |
| stylesheet_manager->close_connection(ffile_spec, *this); | |
| } | |
| private: | private: |
| Line 76 private: | Line 76 private: |
| return now_disk_time>prev_disk_time?now_disk_time:0; | return now_disk_time>prev_disk_time?now_disk_time:0; |
| } | } |
| /// @test grab errors | |
| void load(time_t new_disk_time) { | void load(time_t new_disk_time) { |
| Pool& pool=*fservices_pool; | int saved=xmlDoValidityCheckingDefaultValue;// |
| xmlDoValidityCheckingDefaultValue=0;// | |
| xsltStylesheet *nstylesheet; | xsltStylesheet *nstylesheet= |
| nstylesheet=xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::UL_FILE_SPEC)); | xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::L_FILE_SPEC)); |
| xmlDoValidityCheckingDefaultValue = saved;// | |
| if(xmlHaveGenericErrors()) { | |
| GdomeException exc=0; | |
| throw Exception(&ffile_spec, exc); | |
| } | |
| if(!nstylesheet) | if(!nstylesheet) |
| throw Exception(0, 0, | throw Exception("file.missing", |
| &ffile_spec, | &ffile_spec, |
| "error compiling. TODO: grab errors"); | "stylesheet failed to load"); |
| xsltFreeStylesheet(fstylesheet); | xsltFreeStylesheet(fstylesheet); |
| fstylesheet=nstylesheet; | fstylesheet=nstylesheet; |
| Line 95 private: | Line 99 private: |
| time_t get_disk_time() { | time_t get_disk_time() { |
| size_t size; | size_t size; |
| time_t atime, mtime, ctime; | time_t atime, mtime, ctime; |
| String stamp_file_spec(ffile_spec); | String stamp_file_spec(ffile_spec); |
| stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; | stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX; |
| // {file_spec}.stamp modification time OR {file_spec} | // {file_spec}.stamp modification time OR {file_spec} |
| const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; | const String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; |
| Line 108 private: | Line 112 private: |
| private: // connection usage methods | private: // connection usage methods |
| int used; | |
| void use() { | void use() { |
| time_used=time(0); // they started to use at this time | time_used=time(0); // they started to use at this time |
| used++; | used++; |
| Line 118 private: // connection usage methods | Line 123 private: // connection usage methods |
| close(); | close(); |
| } | } |
| private: // connection usage data | |
| int used; | |
| private: | |
| const String& ffile_spec; | |
| xsltStylesheet *fstylesheet; | |
| time_t time_used; | |
| time_t prev_disk_time; | |
| private: | |
| Pool *fservices_pool; | |
| private: | |
| void *malloc(size_t size) { return fservices_pool->malloc(size); } | |
| void *calloc(size_t size) { return fservices_pool->calloc(size); } | |
| }; | }; |
| /// Auto-object used to track Stylesheet_connection usage | /// Auto-object used to track Stylesheet_connection usage |
| Line 152 public: | Line 139 public: |
| Stylesheet_connection* operator->() { | Stylesheet_connection* operator->() { |
| return fconnection; | return fconnection; |
| } | } |
| /* Stylesheet_connection& operator*() { | |
| return *fconnection; | |
| }*/ | |
| // copying | // copying |
| Stylesheet_connection_ptr(const Stylesheet_connection_ptr& src) : fconnection(src.fconnection) { | Stylesheet_connection_ptr(const Stylesheet_connection_ptr& src) : fconnection(src.fconnection) { |