The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ThMLHeadings Class Reference

#include <thmlheadings.h>

+ Inheritance diagram for ThMLHeadings:
+ Collaboration diagram for ThMLHeadings:

Public Member Functions

virtual const char * getHeader () const
 
virtual const char * getOptionName ()
 
virtual const char * getOptionTip ()
 
virtual const char * getOptionValue ()
 
virtual StringList getOptionValues ()
 
bool isBoolean ()
 
virtual char processText (SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
virtual void setOptionValue (const char *ival)
 
 ThMLHeadings ()
 
virtual ~ThMLHeadings ()
 

Protected Attributes

bool isBooleanVal
 
bool option
 
SWBuf optionValue
 
const char * optName
 
const char * optTip
 
const StringListoptValues
 

Detailed Description

This Filter shows/hides headings in a ThML text

Definition at line 33 of file thmlheadings.h.

Constructor & Destructor Documentation

ThMLHeadings::ThMLHeadings ( )

Definition at line 48 of file thmlheadings.cpp.

49 }
static const StringList * oValues()
static const char oName[]
static const char oTip[]
ThMLHeadings::~ThMLHeadings ( )
virtual

Definition at line 52 of file thmlheadings.cpp.

52  {
53 }

Member Function Documentation

virtual const char* SWFilter::getHeader ( ) const
inlinevirtualinherited

This method can supply a header associated with the processing done with this filter. A typical example is a suggested CSS style block for classed containers.

Reimplemented in OSISLaTeX, OSISXHTML, ThMLLaTeX, ThMLXHTML, TEIXHTML, GBFLaTeX, and GBFXHTML.

Definition at line 62 of file swfilter.h.

62 { return ""; }
virtual const char* SWOptionFilter::getOptionName ( )
inlinevirtualinherited

gets the name of the option of this filter

Returns
option name

Reimplemented in UTF8Transliterator.

Definition at line 72 of file swoptfilter.h.

72 { return optName; }
const char * optName
Definition: swoptfilter.h:51
virtual const char* SWOptionFilter::getOptionTip ( )
inlinevirtualinherited

gets a short explanation of the option of this filter; it could be presented to the user in frontend programs

Returns
option tip/explanation

Reimplemented in UTF8Transliterator.

Definition at line 78 of file swoptfilter.h.

78 { return optTip; }
const char * optTip
Definition: swoptfilter.h:52
const char * SWOptionFilter::getOptionValue ( )
virtualinherited
Returns
The value of the current option.

Reimplemented in UTF8Transliterator.

Definition at line 62 of file swoptfilter.cpp.

62  {
63  return optionValue;
64 }
SWBuf optionValue
Definition: swoptfilter.h:50
virtual StringList SWOptionFilter::getOptionValues ( )
inlinevirtualinherited

returns a list of the possible option values

Returns
list of option values

Reimplemented in UTF8Transliterator.

Definition at line 84 of file swoptfilter.h.

84 { return *optValues; }
const StringList * optValues
Definition: swoptfilter.h:53
bool SWOptionFilter::isBoolean ( )
inlineinherited

many options are simple Off/On boolean type, and frontends may wish to show these with checkmarks or the like to the end user. This is a convenience method to allow a frontend to check if this filter has only Off/On values

Definition at line 67 of file swoptfilter.h.

67 { return isBooleanVal; }
char ThMLHeadings::processText ( SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
virtual

This method processes and appropriately modifies the text given it for a particular filter task

Parameters
textThe text to be filtered/converted
keyCurrent key That was used.
moduleCurrent module.
Returns
0

Implements SWFilter.

Definition at line 56 of file thmlheadings.cpp.

56  {
57  SWBuf token;
58  bool intoken = false;
59  bool isheader = false;
60  bool hide = false;
61  bool preverse = false;
62  bool withinDiv = false;
63  SWBuf header;
64  int headerNum = 0;
65  int pvHeaderNum = 0;
66  char buf[254];
67  XMLTag startTag;
68 
69  SWBuf orig = text;
70  const char *from = orig.c_str();
71 
72  XMLTag tag;
73 
74  for (text = ""; *from; ++from) {
75  if (*from == '<') {
76  intoken = true;
77  token = "";
78 
79  continue;
80  }
81  if (*from == '>') { // process tokens
82  intoken = false;
83 
84  if (!strnicmp(token.c_str(), "div", 3) || !strnicmp(token.c_str(), "/div", 4)) {
85  withinDiv = (!strnicmp(token.c_str(), "div", 3));
86  tag = token;
87  if (hide && tag.isEndTag()) {
88  if (module->isProcessEntryAttributes() && (option || (!preverse))) {
89  SWBuf heading;
90  SWBuf cls = startTag.getAttribute("class");
91  if (!cls.startsWith("fromEntryAttributes")) {
92  cls = SWBuf("fromEntryAttributes ") + cls;
93  startTag.setAttribute("class", cls);
94  }
95  heading += startTag;
96  heading += header;
97  heading += tag;
98  if (preverse) {
99  sprintf(buf, "%i", pvHeaderNum++);
100  module->getEntryAttributes()["Heading"]["Preverse"][buf] = heading;
101  }
102  else {
103  sprintf(buf, "%i", headerNum++);
104  module->getEntryAttributes()["Heading"]["Interverse"][buf] = heading;
105  if (option) { // we want the tag in the text
106  text.append(header);
107  }
108  }
109 
110  StringList attributes = startTag.getAttributeNames();
111  for (StringList::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
112  module->getEntryAttributes()["Heading"][buf][it->c_str()] = startTag.getAttribute(it->c_str());
113  }
114  }
115 
116  hide = false;
117  if (!option || preverse) { // we don't want the tag in the text anymore
118  preverse = false;
119  continue;
120  }
121  preverse = false;
122  }
123  if (tag.getAttribute("class") && ((!stricmp(tag.getAttribute("class"), "sechead"))
124  || (!stricmp(tag.getAttribute("class"), "title")))) {
125 
126  isheader = true;
127 
128  if (!tag.isEndTag()) { //start tag
129  if (!tag.isEmpty()) {
130  startTag = tag;
131 
132 /* how do we tell a ThML preverse title from one that should be in the text? probably if any text is before the title... just assuming all are preverse for now
133  }
134  if (tag.getAttribute("subtype") && !stricmp(tag.getAttribute("subtype"), "x-preverse")) {
135 */
136  hide = true;
137  preverse = true;
138  header = "";
139  continue;
140  } // move back up under startTag = tag
141  }
142 /* this is where non-preverse will go eventually
143  if (!tag.isEndTag()) { //start tag
144  hide = true;
145  header = "";
146  if (option) { // we want the tag in the text
147  text.append('<');
148  text.append(token);
149  text.append('>');
150  }
151  continue;
152  }
153 */
154  }
155  else {
156  isheader = false;
157  SWBuf cls = tag.getAttribute("class");
158  if (cls.startsWith("fromEntryAttributes ")) {
159  cls << SWBuf("fromEntryAttributes ").size();
160  tag.setAttribute("class", cls);
161  token = tag;
162  token << 1;
163  token.setSize(token.size() - 1);
164  }
165  }
166  }
167 
168  if (withinDiv && isheader) {
169  header.append('<');
170  header.append(token);
171  header.append('>');
172  } else {
173  // if not a heading token, keep token in text
174  if (!hide) {
175  text.append('<');
176  text.append(token);
177  text.append('>');
178  }
179  }
180  continue;
181  }
182  if (intoken) { //copy token
183  token.append(*from);
184  }
185  else if (!hide) { //copy text which is not inside a token
186  text.append(*from);
187  }
188  else header.append(*from);
189  }
190  return 0;
191 }
Definition: swbuf.h:47
const char * setAttribute(const char *attribName, const char *attribValue, int partNum=-1, char partSplit= '|')
Definition: utilxml.cpp:248
Definition: utilxml.h:38
bool startsWith(const SWBuf &prefix) const
Definition: swbuf.h:486
bool isEmpty() const
Definition: utilxml.h:60
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
const StringList getAttributeNames() const
Definition: utilxml.cpp:188
const char * c_str() const
Definition: swbuf.h:158
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
unsigned long size() const
Definition: swbuf.h:185
virtual bool isProcessEntryAttributes() const
Definition: swmodule.h:832
virtual AttributeTypeList & getEntryAttributes() const
Definition: swmodule.h:817
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
int strnicmp(const char *s1, const char *s2, int len)
Definition: utilstr.cpp:180
void setSize(unsigned long len)
Definition: swbuf.h:255
void SWOptionFilter::setOptionValue ( const char *  ival)
virtualinherited

sets the value of the option of this filter, e.g maybe a strong's filter might be set to "On" / "Off" - that would mean to show or not to show the strongs in the text, see also getOptionValues()

Parameters
ivalthe new option value

Reimplemented in UTF8Transliterator.

Definition at line 52 of file swoptfilter.cpp.

52  {
53  for (StringList::const_iterator loop = optValues->begin(); loop != optValues->end(); loop++) {
54  if (!stricmp(loop->c_str(), ival)) {
55  optionValue = *loop;
56  option = (!strnicmp(ival, "On", 2)); // convenience for boolean filters
57  break;
58  }
59  }
60 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
SWBuf optionValue
Definition: swoptfilter.h:50
int strnicmp(const char *s1, const char *s2, int len)
Definition: utilstr.cpp:180
const StringList * optValues
Definition: swoptfilter.h:53

Member Data Documentation

bool SWOptionFilter::isBooleanVal
protectedinherited

Definition at line 55 of file swoptfilter.h.

bool SWOptionFilter::option
protectedinherited

Definition at line 54 of file swoptfilter.h.

SWBuf SWOptionFilter::optionValue
protectedinherited

Definition at line 50 of file swoptfilter.h.

const char* SWOptionFilter::optName
protectedinherited

Definition at line 51 of file swoptfilter.h.

const char* SWOptionFilter::optTip
protectedinherited

Definition at line 52 of file swoptfilter.h.

const StringList* SWOptionFilter::optValues
protectedinherited

Definition at line 53 of file swoptfilter.h.


The documentation for this class was generated from the following files: