00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef SWMODULE_H
00025 #define SWMODULE_H
00026
00027 #include <swdisp.h>
00028 #include <swkey.h>
00029 #include <listkey.h>
00030 #include <swfilter.h>
00031 #include <swconfig.h>
00032 #include <swcacher.h>
00033 #include <list>
00034
00035 #include <defs.h>
00036 #include <multimapwdef.h>
00037
00038 #define FILTERPAD 80
00039
00040 using namespace std;
00041
00042 typedef list < SWFilter * >FilterList;
00043
00044 typedef map < string, string, less < string > > AttributeValue;
00045 typedef map < string, AttributeValue, less < string > > AttributeList;
00046 typedef map < string, AttributeList, less < string > > AttributeTypeList;
00047
00048 #define SWTextDirection char
00049 #define SWTextEncoding char
00050 #define SWTextMarkup char
00051
00052 enum {DIRECTION_LTR = 0, DIRECTION_RTL, DIRECTION_BIDI};
00053 enum {FMT_UNKNOWN = 0, FMT_PLAIN, FMT_THML, FMT_GBF, FMT_HTML, FMT_HTMLHREF, FMT_RTF, FMT_OSIS};
00054 enum {ENC_UNKNOWN = 0, ENC_LATIN1, ENC_UTF8, ENC_SCSU, ENC_UTF16, ENC_RTF, ENC_HTML};
00055
00064 class SWDLLEXPORT SWModule : public SWCacher {
00065
00066 protected:
00067
00068 ConfigEntMap ownConfig;
00069 ConfigEntMap *config;
00070 mutable AttributeTypeList entryAttributes;
00071 mutable bool procEntAttr;
00072
00073 char error;
00074 bool skipConsecutiveLinks;
00075
00077 SWKey *key;
00078
00079 ListKey listkey;
00080 char *modname;
00081 char *moddesc;
00082 char *modtype;
00083 char *modlang;
00084
00085 char direction;
00086 char markup;
00087 char encoding;
00088
00090 SWDisplay *disp;
00091
00092 static SWDisplay rawdisp;
00093 char *entrybuf;
00094 unsigned long entrybufallocsize;
00095
00097 FilterList *stripFilters;
00098
00100 FilterList *rawFilters;
00101
00103 FilterList *renderFilters;
00104
00106 FilterList *optionFilters;
00107
00109 FilterList *encodingFilters;
00110
00111 int entrySize;
00112
00113 public:
00120 static void nullPercent (char percent, void *userData);
00125 bool terminateSearch;
00138 SWModule (const char *imodname = 0, const char *imoddesc = 0, SWDisplay * idisp = 0, char *imodtype = 0, SWTextEncoding encoding = ENC_UNKNOWN, SWTextDirection dir = DIRECTION_LTR, SWTextMarkup markup = FMT_UNKNOWN, const char* modlang = 0);
00141 virtual ~ SWModule ();
00146 virtual char Error ();
00150 virtual const bool isUnicode() const {return (encoding == (char)ENC_UTF8 || encoding == (char)ENC_SCSU);}
00151
00152
00153
00154
00155 virtual const ConfigEntMap &getConfig() const { return *config; }
00156 virtual void setConfig(ConfigEntMap *config);
00157 virtual const char *getConfigEntry(const char *key) const;
00158
00162 virtual const int getEntrySize() const {return entrySize;}
00170 virtual char SetKey (const SWKey *ikey);
00176 virtual char SetKey (const SWKey &ikey);
00180 virtual SWKey & Key () const {
00181 return *key;
00182 }
00189 virtual char Key (const SWKey & ikey) {
00190 return SetKey (ikey);
00191 }
00198 virtual const char *KeyText (const char *imodtype = 0);
00203 virtual char Display ();
00210 virtual SWDisplay *Disp (SWDisplay * idisp = 0);
00217 virtual char *Name (const char *imodname = 0);
00224 virtual char *Description (const char *imoddesc = 0);
00231 virtual char *Type (const char *imodtype = 0);
00238 virtual char Direction(signed char newdir = -1);
00245 virtual char Encoding(signed char enc = -1);
00252 virtual char Markup(signed char enc = -1);
00259 virtual char *Lang (const char *imodlang = 0);
00260
00261
00262
00274 virtual ListKey & Search (const char *istr, int searchType = 0, int flags = 0,
00275 SWKey * scope = 0,
00276 bool * justCheckIfSupported = 0,
00277 void (*percent) (char, void *) = &nullPercent,
00278 void *percentUserData = 0);
00282 virtual signed char createSearchFramework () {
00283 return 0;
00284 }
00288 virtual bool hasSearchFramework () {
00289 return false;
00290 }
00295 virtual bool isSearchOptimallySupported (const char *istr, int searchType,
00296 int flags, SWKey * scope) {
00297 bool retVal = false;
00298 Search (istr, searchType, flags, scope, &retVal);
00299 return retVal;
00300 }
00307 virtual SWKey *CreateKey ();
00311 virtual operator const char *();
00316 virtual char *getRawEntry () = 0;
00322 virtual operator SWKey & () {
00323 return *key;
00324 }
00333 virtual operator SWKey *() {
00334 return key;
00335 }
00336
00337
00338
00342 virtual bool isWritable () {
00343 return false;
00344 }
00349 static signed char createModule (const char *) {
00350 return -1;
00351 }
00356 virtual SWModule & setentry (const char *inbuf, long len) {
00357 return *this;
00358 }
00363 virtual SWModule & operator << (const char *) {
00364 return *this;
00365 }
00370 virtual SWModule & operator << (const SWKey *) {
00371 return *this;
00372 }
00376 virtual void deleteEntry () {
00377 }
00378
00379
00385 virtual SWModule & operator -= (int decrement);
00391 virtual SWModule & operator += (int increment);
00395 virtual SWModule & operator++ (int) {
00396 return *this += 1;
00397 }
00401 virtual SWModule & operator-- (int) {
00402 return *this -= 1;
00403 }
00409 virtual SWModule & operator = (SW_POSITION p);
00414 virtual SWModule & AddRenderFilter (SWFilter * newfilter) {
00415 renderFilters->push_back (newfilter);
00416 return *this;
00417 }
00422 virtual SWModule & RemoveRenderFilter (SWFilter * oldfilter) {
00423 renderFilters->remove (oldfilter);
00424 return *this;
00425 }
00431 virtual SWModule & ReplaceRenderFilter (SWFilter * oldfilter, SWFilter * newfilter) {
00432 FilterList::iterator iter;
00433 for (iter = renderFilters->begin(); iter != renderFilters->end(); iter++)
00434 if (*iter == oldfilter)
00435 *iter = newfilter;
00436 return *this;
00437 }
00444 virtual void renderFilter (char *buf, long size, SWKey *key) {
00445 filterBuffer(renderFilters, buf, size, key);
00446 }
00451 virtual SWModule & AddEncodingFilter (SWFilter * newfilter) {
00452 encodingFilters->push_back (newfilter);
00453 return *this;
00454 }
00459 virtual SWModule & RemoveEncodingFilter (SWFilter * oldfilter) {
00460 encodingFilters->remove (oldfilter);
00461 return *this;
00462 }
00468 virtual SWModule & ReplaceEncodingFilter (SWFilter * oldfilter, SWFilter * newfilter) {
00469 FilterList::iterator iter;
00470 for (iter = encodingFilters->begin(); iter != encodingFilters->end(); iter++)
00471 if (*iter == oldfilter)
00472 *iter = newfilter;
00473 return *this;
00474 }
00481 virtual void encodingFilter (char *buf, long size, SWKey *key) {
00482 filterBuffer(encodingFilters, buf, size, key);
00483 }
00488 virtual SWModule & AddStripFilter (SWFilter * newfilter) {
00489 stripFilters->push_back (newfilter);
00490 return *this;
00491 }
00498 virtual void stripFilter (char *buf, long size, SWKey *key) {
00499 filterBuffer(stripFilters, buf, size, key);
00500 }
00505 virtual SWModule & AddRawFilter (SWFilter * newfilter) {
00506 rawFilters->push_back (newfilter);
00507 return *this;
00508 }
00516 virtual void filterBuffer (FilterList *filters, char *buf, long size, SWKey *key) {
00517 FilterList::iterator it;
00518 for (it = filters->begin(); it != filters->end(); it++) {
00519 (*it)->ProcessText(buf, size, key, this);
00520 }
00521 }
00528 virtual void rawFilter (char *buf, long size, SWKey *key) {
00529 buf[size] = 0;
00530 filterBuffer(rawFilters, buf, size, key);
00531 }
00536 virtual SWModule & AddOptionFilter (SWFilter * newfilter) {
00537 optionFilters->push_back (newfilter);
00538 return *this;
00539 }
00546 virtual void optionFilter (char *buf, long size, SWKey *key) {
00547 filterBuffer(optionFilters, buf, size, key);
00548 }
00556 virtual const char *StripText (char *buf = 0, int len = -1);
00564 virtual const char *RenderText (char *buf = 0, int len = -1, bool render = true);
00570 virtual const char *StripText (SWKey * tmpKey);
00576 virtual const char *RenderText (SWKey * tmpKey);
00577
00584 virtual void setSkipConsecutiveLinks(bool val) { skipConsecutiveLinks = val; }
00585 virtual bool getSkipConsecutiveLinks() { return skipConsecutiveLinks; }
00586 virtual AttributeTypeList &getEntryAttributes() const { return entryAttributes; }
00587 virtual void processEntryAttributes(bool val) const { procEntAttr = val; }
00588 virtual bool isProcessEntryAttributes() const { return procEntAttr; }
00589 };
00590
00591
00592 #endif