Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
XMLContentHandler Class Reference
Inheritance diagram for XMLContentHandler:
QXmlDefaultHandler QXmlContentHandler QXmlErrorHandler QXmlDTDHandler QXmlEntityResolver QXmlLexicalHandler QXmlDeclHandler

Public Member Functions

 XMLContentHandler (const QString &path)
 
 ~XMLContentHandler ()
 
- Public Member Functions inherited from QXmlDefaultHandler
 QXmlDefaultHandler ()
 
virtual ~QXmlDefaultHandler ()
 
void setDocumentLocator (QXmlLocator *locator)
 
bool startDocument ()
 
bool endDocument ()
 
bool startPrefixMapping (const QString &prefix, const QString &uri)
 
bool endPrefixMapping (const QString &prefix)
 
bool startElement (const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
 
bool endElement (const QString &namespaceURI, const QString &localName, const QString &qName)
 
bool characters (const QString &ch)
 
bool ignorableWhitespace (const QString &ch)
 
bool processingInstruction (const QString &target, const QString &data)
 
bool skippedEntity (const QString &name)
 
bool warning (const QXmlParseException &exception)
 
bool error (const QXmlParseException &exception)
 
bool fatalError (const QXmlParseException &exception)
 
bool notationDecl (const QString &name, const QString &publicId, const QString &systemId)
 
bool unparsedEntityDecl (const QString &name, const QString &publicId, const QString &systemId, const QString &notationName)
 
bool resolveEntity (const QString &publicId, const QString &systemId, QXmlInputSource *&ret)
 
bool startDTD (const QString &name, const QString &publicId, const QString &systemId)
 
bool endDTD ()
 
bool startCDATA ()
 
bool endCDATA ()
 
bool comment (const QString &ch)
 
bool attributeDecl (const QString &eName, const QString &aName, const QString &type, const QString &valueDefault, const QString &value)
 
bool internalEntityDecl (const QString &name, const QString &value)
 
bool externalEntityDecl (const QString &name, const QString &publicId, const QString &systemId)
 
QString errorString ()
 
- Public Member Functions inherited from QXmlContentHandler
virtual ~QXmlContentHandler ()
 
- Public Member Functions inherited from QXmlErrorHandler
virtual ~QXmlErrorHandler ()
 
- Public Member Functions inherited from QXmlDTDHandler
virtual ~QXmlDTDHandler ()
 
- Public Member Functions inherited from QXmlEntityResolver
virtual ~QXmlEntityResolver ()
 
- Public Member Functions inherited from QXmlLexicalHandler
virtual ~QXmlLexicalHandler ()
 
- Public Member Functions inherited from QXmlDeclHandler
virtual ~QXmlDeclHandler ()
 

Private Types

enum  FieldNames {
  UnknownField = 0, TypeField = 1, NameField = 2, ArgsField = 3,
  TagField = 4, UrlField = 5, KeywordField = 6, TextField = 7
}
 

Private Member Functions

bool startElement (const QString &, const QString &, const QString &name, const QXmlAttributes &attrib)
 
bool endElement (const QString &, const QString &, const QString &name)
 
bool characters (const QString &ch)
 

Private Attributes

Xapian::WritableDatabase m_db
 
Xapian::Document m_doc
 
Xapian::TermGenerator m_indexer
 
Xapian::Stem m_stemmer
 
std::string m_data
 
FieldNames m_curFieldName
 

Detailed Description

This class is a wrapper around SAX style XML parser, which parses the file without first building a DOM tree in memory.

Definition at line 143 of file doxyindexer.cpp.

Member Enumeration Documentation

Enumerator
UnknownField 
TypeField 
NameField 
ArgsField 
TagField 
UrlField 
KeywordField 
TextField 

Definition at line 163 of file doxyindexer.cpp.

Constructor & Destructor Documentation

XMLContentHandler::XMLContentHandler ( const QString path)
inline

Handler for parsing XML data

Definition at line 147 of file doxyindexer.cpp.

148  : m_db((path+"doxysearch.db").utf8().data(),Xapian::DB_CREATE_OR_OVERWRITE),
149  m_stemmer("english")
150  {
152  m_indexer.set_stemmer(m_stemmer);
153  m_indexer.set_document(m_doc);
154  }
Xapian::Stem m_stemmer
Xapian::TermGenerator m_indexer
Xapian::WritableDatabase m_db
Xapian::Document m_doc
FieldNames m_curFieldName
XMLContentHandler::~XMLContentHandler ( )
inline

Free data handler

Definition at line 157 of file doxyindexer.cpp.

158  {
159  m_db.commit();
160  }
Xapian::WritableDatabase m_db

Member Function Documentation

bool XMLContentHandler::characters ( const QString ch)
inlineprivatevirtual

Handler for inline text

Implements QXmlContentHandler.

Definition at line 265 of file doxyindexer.cpp.

266  {
267  m_data += ch.utf8();
268  return TRUE;
269  }
std::string m_data
QCString utf8() const
Definition: qstring.cpp:14507
const bool TRUE
Definition: qglobal.h:371
bool XMLContentHandler::endElement ( const QString ,
const QString ,
const QString name 
)
inlineprivatevirtual

Handler for an end tag. Called for </doc> and </field> tags

Implements QXmlContentHandler.

Definition at line 196 of file doxyindexer.cpp.

197  {
198  if (name=="doc") // </doc>
199  {
200  std::string term = m_doc.get_value(NameField);
201  std::string partTerm;
202  size_t pos = term.rfind("::");
203  if (pos!=std::string::npos)
204  {
205  partTerm = term.substr(pos+2);
206  }
207  if (m_doc.get_value(TypeField)=="class" ||
208  m_doc.get_value(TypeField)=="file" ||
209  m_doc.get_value(TypeField)=="namespace") // containers get highest prio
210  {
211  safeAddTerm(term,m_doc,1000);
212  if (!partTerm.empty())
213  {
214  safeAddTerm(partTerm,m_doc,500);
215  }
216  }
217  else // members and others get lower prio
218  {
219  safeAddTerm(m_doc.get_value(NameField),m_doc,100);
220  if (!partTerm.empty())
221  {
222  safeAddTerm(partTerm,m_doc,50);
223  }
224  }
225  m_db.add_document(m_doc);
226  m_doc.clear_values();
227  m_doc.clear_terms();
228  }
229  else if (name=="field" && m_curFieldName!=UnknownField) // </field>
230  {
231  // strip whitespace from m_data
232  m_data = reduce(m_data);
233  // replace XML entities
235  // add data to the document
236  m_doc.add_value(m_curFieldName,m_data);
237  switch (m_curFieldName)
238  {
239  case TypeField:
240  case NameField:
241  case TagField:
242  case UrlField:
243  // meta data that is not searchable
244  break;
245  case KeywordField:
246  addWords(m_data,m_doc,50);
247  break;
248  case ArgsField:
250  break;
251  case TextField:
252  addWords(m_data,m_doc,2);
253  break;
254  default:
255  break;
256  }
257  m_data="";
259  }
260  // reset m_data
261  return TRUE;
262  }
static std::string reduce(const std::string &str, const std::string &fill=" ", const std::string &whitespace=" \t")
Definition: doxyindexer.cpp:63
std::string string
Definition: nybbler.cc:12
static void addIdentifiers(const std::string &s, Xapian::Document &doc, int wfd)
Xapian::WritableDatabase m_db
Xapian::Document m_doc
std::string m_data
static void safeAddTerm(const std::string &term, Xapian::Document &doc, int wfd)
Definition: doxyindexer.cpp:41
static void addWords(const std::string &s, Xapian::Document &doc, int wfd)
Definition: doxyindexer.cpp:87
FieldNames m_curFieldName
const bool TRUE
Definition: qglobal.h:371
static std::string unescapeXmlEntities(const std::string &s)
bool XMLContentHandler::startElement ( const QString ,
const QString ,
const QString name,
const QXmlAttributes attrib 
)
inlineprivatevirtual

Handler for a start tag. Called for <doc> and <field> tags

Implements QXmlContentHandler.

Definition at line 176 of file doxyindexer.cpp.

178  {
179  m_data="";
180  if (name=="field")
181  {
182  QString fieldName = attrib.value("name");
183  if (fieldName=="type") m_curFieldName=TypeField;
184  else if (fieldName=="name") m_curFieldName=NameField;
185  else if (fieldName=="args") m_curFieldName=ArgsField;
186  else if (fieldName=="tag") m_curFieldName=TagField;
187  else if (fieldName=="url") m_curFieldName=UrlField;
188  else if (fieldName=="keywords") m_curFieldName=KeywordField;
189  else if (fieldName=="text") m_curFieldName=TextField;
191  }
192  return TRUE;
193  }
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QString value(int index) const
Definition: qxml.cpp:664
std::string m_data
FieldNames m_curFieldName
const bool TRUE
Definition: qglobal.h:371

Member Data Documentation

FieldNames XMLContentHandler::m_curFieldName
private

Definition at line 277 of file doxyindexer.cpp.

std::string XMLContentHandler::m_data
private

Definition at line 276 of file doxyindexer.cpp.

Xapian::WritableDatabase XMLContentHandler::m_db
private

Definition at line 272 of file doxyindexer.cpp.

Xapian::Document XMLContentHandler::m_doc
private

Definition at line 273 of file doxyindexer.cpp.

Xapian::TermGenerator XMLContentHandler::m_indexer
private

Definition at line 274 of file doxyindexer.cpp.

Xapian::Stem XMLContentHandler::m_stemmer
private

Definition at line 275 of file doxyindexer.cpp.


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