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 #include <swbuf.h>
00035
00036 #include <defs.h>
00037 #include <multimapwdef.h>
00038
00039 SWORD_NAMESPACE_START
00040
00041 #define SWMODULE_OPERATORS \
00042 operator const char *() { return RenderText(); } \
00043 operator SWKey &() { return *getKey(); } \
00044 operator SWKey *() { return getKey(); } \
00045 SWModule &operator <<(const char *inbuf) { setEntry(inbuf); return *this; } \
00046 SWModule &operator <<(const SWKey *sourceKey) { linkEntry(sourceKey); return *this; } \
00047 SWModule &operator -=(int steps) { decrement(steps); return *this; } \
00048 SWModule &operator +=(int steps) { increment(steps); return *this; } \
00049 SWModule &operator ++(int) { return *this += 1; } \
00050 SWModule &operator --(int) { return *this -= 1; } \
00051 SWModule &operator =(SW_POSITION p) { setPosition(p); return *this; }
00052
00053
00054 typedef std::list < SWFilter * >FilterList;
00055
00056 typedef std::map < std::string, std::string, std::less < std::string > > AttributeValue;
00057 typedef std::map < std::string, AttributeValue, std::less < std::string > > AttributeList;
00058 typedef std::map < std::string, AttributeList, std::less < std::string > > AttributeTypeList;
00059
00060 #define SWTextDirection char
00061 #define SWTextEncoding char
00062 #define SWTextMarkup char
00063
00064 enum {DIRECTION_LTR = 0, DIRECTION_RTL, DIRECTION_BIDI};
00065 enum {FMT_UNKNOWN = 0, FMT_PLAIN, FMT_THML, FMT_GBF, FMT_HTML, FMT_HTMLHREF, FMT_RTF, FMT_OSIS};
00066 enum {ENC_UNKNOWN = 0, ENC_LATIN1, ENC_UTF8, ENC_SCSU, ENC_UTF16, ENC_RTF, ENC_HTML};
00067
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 class SWDLLEXPORT SWModule : public SWCacher {
00087
00088 protected:
00089
00090 ConfigEntMap ownConfig;
00091 ConfigEntMap *config;
00092 mutable AttributeTypeList entryAttributes;
00093 mutable bool procEntAttr;
00094
00095 char error;
00096 bool skipConsecutiveLinks;
00097
00099 SWKey *key;
00100
00101 ListKey listkey;
00102 char *modname;
00103 char *moddesc;
00104 char *modtype;
00105 char *modlang;
00106
00107 char direction;
00108 char markup;
00109 char encoding;
00110
00112 SWDisplay *disp;
00113
00114 static SWDisplay rawdisp;
00115 SWBuf entryBuf;
00116
00118 FilterList *stripFilters;
00119
00121 FilterList *rawFilters;
00122
00124 FilterList *renderFilters;
00125
00127 FilterList *optionFilters;
00128
00130 FilterList *encodingFilters;
00131
00132 int entrySize;
00133 mutable long entryIndex;
00134
00135 public:
00142 static void nullPercent(char percent, void *userData);
00147 bool terminateSearch;
00159 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);
00162 virtual ~SWModule();
00167 virtual char Error();
00171 virtual const bool isUnicode() const { return (encoding == (char)ENC_UTF8 || encoding == (char)ENC_SCSU); }
00172
00173
00174
00175
00176 virtual const ConfigEntMap &getConfig() const { return *config; }
00177 virtual void setConfig(ConfigEntMap *config);
00178 virtual const char *getConfigEntry(const char *key) const;
00179
00183 virtual const int getEntrySize() const { return entrySize; }
00192 char SetKey(const SWKey *ikey) { return setKey(ikey); }
00193 virtual char setKey(const SWKey *ikey);
00194
00195
00196 virtual long Index() const { return entryIndex; }
00197 virtual long Index(long iindex) { entryIndex = iindex; return entryIndex; }
00198
00205 char SetKey(const SWKey &ikey) { return setKey(ikey); }
00206 char setKey(const SWKey &ikey) { return SetKey(&ikey); }
00207
00212 SWKey &Key() const { return *getKey(); }
00213 SWKey *getKey() const;
00214
00222 char Key(const SWKey & ikey) { return setKey(ikey); }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 virtual const char *KeyText(const char *ikeytext = 0) {
00233 if (ikeytext) setKey(ikeytext);
00234 return *getKey();
00235 }
00236
00241 virtual char Display();
00242
00249 virtual SWDisplay *Disp(SWDisplay * idisp = 0);
00256 virtual char *Name(const char *imodname = 0);
00263 virtual char *Description(const char *imoddesc = 0);
00270 virtual char *Type(const char *imodtype = 0);
00277 virtual char Direction(signed char newdir = -1);
00284 virtual char Encoding(signed char enc = -1);
00291 virtual char Markup(signed char markup = -1);
00298 virtual char *Lang(const char *imodlang = 0);
00299
00300
00301
00316 virtual ListKey & Search(const char *istr, int searchType = 0, int flags = 0,
00317 SWKey * scope = 0,
00318 bool * justCheckIfSupported = 0,
00319 void (*percent) (char, void *) = &nullPercent,
00320 void *percentUserData = 0);
00324 virtual signed char createSearchFramework() { return 0; }
00328 virtual bool hasSearchFramework() { return false; }
00333 virtual bool isSearchOptimallySupported(const char *istr, int searchType,
00334 int flags, SWKey * scope) {
00335 bool retVal = false;
00336 Search(istr, searchType, flags, scope, &retVal);
00337 return retVal;
00338 }
00345 virtual SWKey *CreateKey();
00350 #ifndef SWIG
00351 virtual SWBuf &getRawEntryBuf() = 0;
00352 #else
00353 virtual SWBuf &getRawEntryBuf() {};
00354 #endif
00355
00356 virtual const char *getRawEntry() { return getRawEntryBuf().c_str(); }
00357
00358
00362 virtual bool isWritable() { return false; }
00367 static signed char createModule(const char *path) { return -1; }
00372 virtual void setEntry(const char *inbuf, long len = -1) { }
00376 virtual void linkEntry(const SWKey *sourceKey) { }
00380 virtual void deleteEntry() {}
00381
00382
00383
00389 virtual void decrement(int steps = 1);
00395 virtual void increment(int steps = 1);
00401 virtual void setPosition(SW_POSITION pos);
00406 virtual SWModule & AddRenderFilter(SWFilter * newfilter) {
00407 renderFilters->push_back (newfilter);
00408 return *this;
00409 }
00414 virtual SWModule & RemoveRenderFilter(SWFilter * oldfilter) {
00415 renderFilters->remove (oldfilter);
00416 return *this;
00417 }
00423 virtual SWModule & ReplaceRenderFilter(SWFilter * oldfilter, SWFilter * newfilter) {
00424 FilterList::iterator iter;
00425 for (iter = renderFilters->begin(); iter != renderFilters->end(); iter++) {
00426 if (*iter == oldfilter)
00427 *iter = newfilter;
00428 }
00429 return *this;
00430 }
00436 virtual void renderFilter(SWBuf &buf, SWKey *key) {
00437 filterBuffer(renderFilters, buf, key);
00438 }
00443 virtual SWModule & AddEncodingFilter(SWFilter * newfilter) {
00444 encodingFilters->push_back (newfilter);
00445 return *this;
00446 }
00451 virtual SWModule & RemoveEncodingFilter(SWFilter * oldfilter) {
00452 encodingFilters->remove (oldfilter);
00453 return *this;
00454 }
00460 virtual SWModule & ReplaceEncodingFilter(SWFilter * oldfilter, SWFilter * newfilter) {
00461 FilterList::iterator iter;
00462 for (iter = encodingFilters->begin(); iter != encodingFilters->end(); iter++) {
00463 if (*iter == oldfilter)
00464 *iter = newfilter;
00465 }
00466 return *this;
00467 }
00473 virtual void encodingFilter(SWBuf &buf, SWKey *key) {
00474 filterBuffer(encodingFilters, buf, key);
00475 }
00480 virtual SWModule & AddStripFilter(SWFilter * newfilter) {
00481 stripFilters->push_back (newfilter);
00482 return *this;
00483 }
00489 virtual void stripFilter(SWBuf &buf, SWKey *key) {
00490 filterBuffer(stripFilters, buf, key);
00491 }
00496 virtual SWModule & AddRawFilter(SWFilter * newfilter) {
00497 rawFilters->push_back (newfilter);
00498 return *this;
00499 }
00506 virtual void filterBuffer(FilterList *filters, SWBuf &buf, SWKey *key) {
00507 FilterList::iterator it;
00508 for (it = filters->begin(); it != filters->end(); it++) {
00509 (*it)->processText(buf, key, this);
00510 }
00511 }
00517 virtual void rawFilter(SWBuf &buf, SWKey *key) {
00518 filterBuffer(rawFilters, buf, key);
00519 }
00524 virtual SWModule & AddOptionFilter(SWFilter * newfilter) {
00525 optionFilters->push_back(newfilter);
00526 return *this;
00527 }
00533 virtual void optionFilter(SWBuf &buf, SWKey *key) {
00534 filterBuffer(optionFilters, buf, key);
00535 }
00543 virtual const char *StripText(char *buf = 0, int len = -1);
00552 virtual const char *RenderText(char *buf = 0, int len = -1, bool render = true);
00558 virtual const char *StripText(SWKey * tmpKey);
00564 virtual const char *RenderText(SWKey * tmpKey);
00565
00572 virtual void setSkipConsecutiveLinks(bool val) { skipConsecutiveLinks = val; }
00573 virtual bool getSkipConsecutiveLinks() { return skipConsecutiveLinks; }
00574 virtual AttributeTypeList &getEntryAttributes() const { return entryAttributes; }
00575 virtual void processEntryAttributes(bool val) const { procEntAttr = val; }
00576 virtual bool isProcessEntryAttributes() const { return procEntAttr; }
00577
00578
00579
00580
00581
00582 SWMODULE_OPERATORS
00583
00584 };
00585
00586 SWORD_NAMESPACE_END
00587 #endif