Annotation of parser3/src/include/pa_stylesheet_connection.h, revision 1.1
1.1 ! parser 1: /** @file
! 2: Parser: stylesheet fstylesheet decl.
! 3:
! 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
! 5:
! 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
! 7:
! 8: $Id: pa_connection_connection.h,v 1.12 2001/08/24 07:04:52 parser Exp $
! 9: */
! 10:
! 11: #ifndef PA_STYLESHEET_CONNECTION_H
! 12: #define PA_STYLESHEET_CONNECTION_H
! 13:
! 14: #include "pa_config_includes.h"
! 15: #include "pa_pool.h"
! 16: #include "pa_xslt_stylesheet_manager.h"
! 17: #include "pa_exception.h"
! 18: #include "pa_common.h"
! 19:
! 20: #include <XalanTransformer/XalanTransformer.hpp>
! 21:
! 22: // defines
! 23:
! 24: #define STYLESHEET_FILENAME_STAMP_SUFFIX ".stamp"
! 25:
! 26: /** Connection with stylesheet:
! 27: remembers time and can figure out that it needs recompilation
! 28: @test free ftransformer somehow
! 29: */
! 30: class Stylesheet_connection : public Pooled {
! 31:
! 32: public:
! 33:
! 34: Stylesheet_connection(Pool& pool, const String& afile_spec) : Pooled(pool),
! 35: ftransformer(new XalanTransformer),
! 36:
! 37: ffile_spec(afile_spec),
! 38: time_used(0),
! 39: prev_disk_time(0),
! 40: fservices_pool(0) {
! 41: }
! 42:
! 43: const String& file_spec() { return ffile_spec; }
! 44:
! 45: void set_services(Pool *aservices_pool) {
! 46: time_used=time(0); // they started to use at this time
! 47: fservices_pool=aservices_pool;
! 48: }
! 49: bool expired(time_t older_dies) {
! 50: return time_used<older_dies;
! 51: }
! 52:
! 53: void close() {
! 54: XSLT_stylesheet_manager->close_connection(ffile_spec, *this);
! 55: }
! 56:
! 57: void disconnect() {
! 58: /*ignore error*/ftransformer->destroyStylesheet(fstylesheet); fstylesheet=0;
! 59: }
! 60:
! 61: bool connected() { return fstylesheet!=0; }
! 62:
! 63: XalanCompiledStylesheet& stylesheet() {
! 64: if(time_t new_disk_time=get_new_disk_time())
! 65: load(new_disk_time);
! 66: return *fstylesheet;
! 67: }
! 68:
! 69: private:
! 70:
! 71: time_t get_new_disk_time() {
! 72: time_t now_disk_time=get_disk_time();
! 73: return now_disk_time>prev_disk_time?now_disk_time:0;
! 74: }
! 75:
! 76: void load(time_t new_disk_time) {
! 77: Pool& pool=*fservices_pool;
! 78:
! 79: int error=ftransformer->compileStylesheet(ffile_spec.cstr(String::UL_FILE_SPEC), fstylesheet);
! 80: if(error)
! 81: PTHROW(0, 0,
! 82: &ffile_spec,
! 83: ftransformer->getLastError());
! 84:
! 85: prev_disk_time=new_disk_time;
! 86: }
! 87:
! 88: time_t get_disk_time() {
! 89: size_t size;
! 90: time_t atime, mtime, ctime;
! 91: String stamp_file_spec(ffile_spec);
! 92: stamp_file_spec << STYLESHEET_FILENAME_STAMP_SUFFIX;
! 93: // {file_spec}.stamp modification time OR {file_spec} mtime
! 94: if(!file_stat(file_readable(stamp_file_spec)?stamp_file_spec:ffile_spec,
! 95: size,
! 96: atime, mtime, ctime,
! 97: false/*no exceptions on global pool, please*/))
! 98: mtime=0; // no file=no time
! 99: return mtime;
! 100: }
! 101:
! 102: private:
! 103:
! 104: const String& ffile_spec;
! 105: XalanCompiledStylesheet *fstylesheet;
! 106: time_t time_used;
! 107: time_t prev_disk_time;
! 108:
! 109: private:
! 110:
! 111: XalanTransformer *ftransformer;
! 112:
! 113: Pool *fservices_pool;
! 114: };
! 115:
! 116: #endif
E-mail: