22#include <QtCore/QXmlStreamReader>
32namespace DocumentsReader {
42 std::shared_ptr<StructuredDocumentXMLParser>
m_parser;
76 setlocale ( LC_ALL,
"" );
80 LINFO <<
"DocumentReader::init";
88 LDEBUG <<
"DocumentReader::init: DocumentsReaderResources::changeable().init(conf)";
93 LDEBUG <<
"DocumentReader::init: DocumentsReaderResources::changeable().init(conf) done";
98 LERROR <<
"no such module lp-xmlreaderclient";
137 m_d->
m_parser->setShiftFrom(shiftFrom);
142 m_d->
m_parser->setLinguisticXMLDocHandler ( handler );
152 LDEBUG <<
"DocumentReader::initFile: " << filename;
154 QFile file(filename);
155 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
160 auto content = QString::fromUtf8(file.readAll());
169 LDEBUG <<
"DocumentReader::initWithString: " << text.left(100) << (text.size()>100?
"(...)":
"");
173 m_d->
m_shiftFrom = std::make_shared<ShiftFrom>(text);
179 LDEBUG <<
"DocumentReader: initWithString NOT OK";
190 if (m_d->
m_reader->tokenType() == QXmlStreamReader::Characters)
191 return ( m_d->
m_reader->characterOffset() -1 );
193 return ( m_d->
m_reader->characterOffset() );
201 LDEBUG <<
"DocumentReader::readXMLDocument";
209 <<
"; tokenType:" << m_d->
m_reader->tokenType() <<
"; tokenString:"
212 if (m_d->
m_reader->isStartElement())
216 m_d->
m_reader->qualifiedName().toString(),
220 else if (m_d->
m_reader->isEndElement())
224 m_d->
m_reader->qualifiedName().toString(),
227 else if (m_d->
m_reader->isCharacters())
240 LERROR <<
"DocumentReader: readXMLDocument: parse error:" << m_d->
m_reader->errorString();
#define LIMA_EXCEPTION_SELECT_LOGINIT(X, Y, Z)
This macro writes the message Y to the error stream configured by its first parameter X,...
return a message when a 'module' is not found
DocumentReaderPrivate(ModuleConfigurationStructure &conf)
void init(Lima::Common::XMLConfigurationFiles::ModuleConfigurationStructure &conf)
virtual ~DocumentReaderPrivate()
QXmlStreamReader * m_reader
std::shared_ptr< ShiftFrom > m_shiftFrom
std::shared_ptr< StructuredDocumentXMLParser > m_parser
DocumentReader(Lima::Common::XMLConfigurationFiles::ModuleConfigurationStructure &conf)
bool initFile(const QString &filename)
initialize the reader with a file containing documents in XML format
void setShiftFrom(std::shared_ptr< const ShiftFrom > shiftFrom)
virtual ~DocumentReader()
void setLinguisticXMLDocHandler(StructuredXmlDocumentHandler *handler)
uint64_t getCurrentOffsetFromXmlReader()
Returns the reader's current character offset, starting with 0.
bool readXMLDocument()
read the next element in the current file (initFile must have been
bool initWithString(const QString &text)
static const DocumentsReaderResources & single()
const singleton accessor
static DocumentsReaderResources & changeable()
singleton accessor
Handler pour les elements de parsing de document structure.
Throw this exception when encountering problems with XML files opening or parsing.
originally detectModuleConfigurationStructure.h in detectlibraries
launch exception related to the configuration file parsing