|
|
| version 1.32.2.5.2.3, 2003/03/24 17:52:19 | version 1.39.14.1, 2005/08/05 13:03:00 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: Stylesheet connection decl. | Parser: Stylesheet connection decl. |
| Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| #ifndef PA_STYLESHEET_CONNECTION_H | #ifndef PA_STYLESHEET_CONNECTION_H |
| #define PA_STYLESHEET_CONNECTION_H | #define PA_STYLESHEET_CONNECTION_H |
| static const char* IDENT_STYLESHEET_CONNECTION_H="$Date$"; | static const char * const IDENT_STYLESHEET_CONNECTION_H="$Date$"; |
| #include "libxslt/xslt.h" | #include "libxslt/xslt.h" |
| #include "libxslt/xsltInternals.h" | #include "libxslt/xsltInternals.h" |
| #include "pa_exception.h" | #include "pa_xml_exception.h" |
| #include "pa_common.h" | #include "pa_common.h" |
| #include "pa_globals.h" | #include "pa_globals.h" |
| #include "pa_xml_io.h" | |
| // defines | // defines |
| #define STYLESHEET_FILENAME_STAMP_SUFFIX ".stamp" | |
| /** 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 |
| */ | */ |
| Line 31 class Stylesheet_connection: public PA_O | Line 30 class Stylesheet_connection: public PA_O |
| private: | private: |
| const String& ffile_spec; | String::Body ffile_spec; |
| xsltStylesheet *fstylesheet; | xsltStylesheet *fstylesheet; |
| HashStringBool* dependencies; | |
| time_t time_used; | time_t time_used; |
| time_t prev_disk_time; | time_t prev_disk_time; |
| public: | public: |
| Stylesheet_connection(const String& afile_spec): | Stylesheet_connection(String::Body afile_spec): |
| ffile_spec(afile_spec), | ffile_spec(afile_spec), |
| prev_disk_time(0), | |
| fstylesheet(0), | fstylesheet(0), |
| time_used(0), used(0) {} | dependencies(0), |
| time_used(0), | |
| prev_disk_time(0), | |
| used(0) | |
| {} | |
| const String& file_spec() { return ffile_spec; } | String::Body file_spec() { return ffile_spec; } |
| bool uncachable() { | |
| return !dependencies/*means they were external*/; | |
| } | |
| bool expired(time_t older_dies) { | bool expired(time_t older_dies) { |
| return !used && time_used<older_dies; | return uncachable() || !used && time_used<older_dies; |
| } | } |
| time_t get_time_used() { return time_used; } | time_t get_time_used() { return time_used; } |
| Line 57 public: | Line 64 public: |
| bool connected() { return fstylesheet!=0; } | bool connected() { return fstylesheet!=0; } |
| xsltStylesheet *stylesheet(bool nocache) { | xsltStylesheet *stylesheet() { |
| time_t new_disk_time=get_new_disk_time(); | time_t new_disk_time=0; |
| if(nocache || new_disk_time) | if(uncachable() || (new_disk_time=get_new_disk_time())) |
| load(new_disk_time); | load(new_disk_time); |
| return fstylesheet; | return fstylesheet; |
| } | } |
| Line 76 private: | Line 83 private: |
| return now_disk_time>prev_disk_time?now_disk_time:0; | return now_disk_time>prev_disk_time?now_disk_time:0; |
| } | } |
| void load(time_t new_disk_time) { | void load(time_t new_disk_time); |
| int saved=xmlDoValidityCheckingDefaultValue;// | time_t get_disk_time(); |
| xmlDoValidityCheckingDefaultValue=0;// | |
| xsltStylesheet *nstylesheet= | |
| xsltParseStylesheetFile(BAD_CAST ffile_spec.cstr(String::L_FILE_SPEC)); | |
| 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; | |
| // {file_spec}.stamp modification time OR {file_spec} | |
| String& stat_file_spec=file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec; | |
| file_stat(stat_file_spec, | |
| size, | |
| atime, mtime, ctime, | |
| true/*exception on error*/); | |
| return mtime; | |
| } | |
| private: // connection usage methods | private: // connection usage methods |