|
a/src/qtgui/xmltosd.cpp |
|
b/src/qtgui/xmltosd.cpp |
|
... |
|
... |
49 |
currentText += str;
|
49 |
currentText += str;
|
50 |
return true;
|
50 |
return true;
|
51 |
}
|
51 |
}
|
52 |
|
52 |
|
53 |
// The object we set up
|
53 |
// The object we set up
|
54 |
STD_SHARED_PTR<SearchData> sd;
|
54 |
std::shared_ptr<SearchData> sd;
|
55 |
bool isvalid;
|
55 |
bool isvalid;
|
56 |
|
56 |
|
57 |
private:
|
57 |
private:
|
58 |
void resetTemps()
|
58 |
void resetTemps()
|
59 |
{
|
59 |
{
|
|
... |
|
... |
80 |
bool SDHXMLHandler::startElement(const QString & /* namespaceURI */,
|
80 |
bool SDHXMLHandler::startElement(const QString & /* namespaceURI */,
|
81 |
const QString & /* localName */,
|
81 |
const QString & /* localName */,
|
82 |
const QString &qName,
|
82 |
const QString &qName,
|
83 |
const QXmlAttributes &attrs)
|
83 |
const QXmlAttributes &attrs)
|
84 |
{
|
84 |
{
|
85 |
LOGDEB2("SDHXMLHandler::startElement: name [" << ((const char *)qName.toUtf8()) << "]\n" );
|
85 |
LOGDEB2("SDHXMLHandler::startElement: name [" << qs2utf8s(qName) << "]\n");
|
86 |
if (qName == "SD") {
|
86 |
if (qName == "SD") {
|
87 |
// Advanced search history entries have no type. So we're good
|
87 |
// Advanced search history entries have no type. So we're good
|
88 |
// either if type is absent, or if it's searchdata
|
88 |
// either if type is absent, or if it's searchdata
|
89 |
int idx = attrs.index("type");
|
89 |
int idx = attrs.index("type");
|
90 |
if (idx >= 0 && attrs.value(idx).compare("searchdata")) {
|
90 |
if (idx >= 0 && attrs.value(idx).compare("searchdata")) {
|
91 |
LOGDEB("XMLTOSD: bad type\n" );
|
91 |
LOGDEB("XMLTOSD: bad type\n");
|
|
|
92 |
return false;
|
|
|
93 |
}
|
|
|
94 |
resetTemps();
|
|
|
95 |
// A new search descriptor. Allocate data structure
|
|
|
96 |
sd = std::shared_ptr<SearchData>(new SearchData);
|
|
|
97 |
if (!sd) {
|
|
|
98 |
LOGERR("SDHXMLHandler::startElement: out of memory\n");
|
92 |
return false;
|
99 |
return false;
|
93 |
}
|
100 |
}
|
94 |
}
|
101 |
}
|
95 |
return true;
|
102 |
return true;
|
96 |
}
|
103 |
}
|
97 |
|
104 |
|
98 |
bool SDHXMLHandler::endElement(const QString & /* namespaceURI */,
|
105 |
bool SDHXMLHandler::endElement(const QString & /* namespaceURI */,
|
99 |
const QString & /* localName */,
|
106 |
const QString & /* localName */,
|
100 |
const QString &qName)
|
107 |
const QString &qName)
|
101 |
{
|
108 |
{
|
102 |
LOGDEB2("SDHXMLHandler::endElement: name [" << ((const char *)qName.toUtf8()) << "]\n" );
|
109 |
LOGDEB2("SDHXMLHandler::endElement: name [" << qs2utf8s(qName) << "]\n");
|
103 |
|
110 |
|
104 |
if (qName == "CLT") {
|
111 |
if (qName == "CLT") {
|
105 |
if (currentText == "OR") {
|
112 |
if (currentText == "OR") {
|
106 |
sd->setTp(SCLT_OR);
|
113 |
sd->setTp(SCLT_OR);
|
107 |
}
|
114 |
}
|
|
... |
|
... |
136 |
c->setexclude(exclude);
|
143 |
c->setexclude(exclude);
|
137 |
} else if (whatclause == "NE") {
|
144 |
} else if (whatclause == "NE") {
|
138 |
c = new SearchDataClauseDist(SCLT_NEAR, text, slack, field);
|
145 |
c = new SearchDataClauseDist(SCLT_NEAR, text, slack, field);
|
139 |
c->setexclude(exclude);
|
146 |
c->setexclude(exclude);
|
140 |
} else {
|
147 |
} else {
|
141 |
LOGERR("Bad clause type [" << (qs2utf8s(whatclause)) << "]\n" );
|
148 |
LOGERR("Bad clause type [" << qs2utf8s(whatclause) << "]\n");
|
142 |
return false;
|
149 |
return false;
|
143 |
}
|
150 |
}
|
144 |
sd->addClause(c);
|
151 |
sd->addClause(c);
|
145 |
whatclause = "";
|
152 |
whatclause = "";
|
146 |
text.clear();
|
153 |
text.clear();
|
|
... |
|
... |
197 |
currentText.clear();
|
204 |
currentText.clear();
|
198 |
return true;
|
205 |
return true;
|
199 |
}
|
206 |
}
|
200 |
|
207 |
|
201 |
|
208 |
|
202 |
STD_SHARED_PTR<Rcl::SearchData> xmlToSearchData(const string& xml)
|
209 |
std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml)
|
203 |
{
|
210 |
{
|
204 |
SDHXMLHandler handler;
|
211 |
SDHXMLHandler handler;
|
205 |
QXmlSimpleReader reader;
|
212 |
QXmlSimpleReader reader;
|
206 |
reader.setContentHandler(&handler);
|
213 |
reader.setContentHandler(&handler);
|
207 |
reader.setErrorHandler(&handler);
|
214 |
reader.setErrorHandler(&handler);
|
208 |
|
215 |
|
209 |
QXmlInputSource xmlInputSource;
|
216 |
QXmlInputSource xmlInputSource;
|
210 |
xmlInputSource.setData(QString::fromUtf8(xml.c_str()));
|
217 |
xmlInputSource.setData(QString::fromUtf8(xml.c_str()));
|
211 |
|
218 |
|
212 |
if (!reader.parse(xmlInputSource) || !handler.isvalid) {
|
219 |
if (!reader.parse(xmlInputSource) || !handler.isvalid) {
|
213 |
LOGERR("xmlToSearchData: parse failed for [" << (xml) << "]\n" );
|
220 |
LOGERR("xmlToSearchData: parse failed for [" << xml << "]\n");
|
214 |
return STD_SHARED_PTR<SearchData>();
|
221 |
return std::shared_ptr<SearchData>();
|
215 |
}
|
222 |
}
|
216 |
return handler.sd;
|
223 |
return handler.sd;
|
217 |
}
|
224 |
}
|
218 |
|
225 |
|
219 |
|
226 |
|
|
... |
|
... |
258 |
bool SSHXMLHandler::startElement(const QString & /* namespaceURI */,
|
265 |
bool SSHXMLHandler::startElement(const QString & /* namespaceURI */,
|
259 |
const QString & /* localName */,
|
266 |
const QString & /* localName */,
|
260 |
const QString &qName,
|
267 |
const QString &qName,
|
261 |
const QXmlAttributes &attrs)
|
268 |
const QXmlAttributes &attrs)
|
262 |
{
|
269 |
{
|
263 |
LOGDEB2("SSHXMLHandler::startElement: name [" << ((const char *)qName.toUtf8()) << "]\n" );
|
270 |
LOGDEB2("SSHXMLHandler::startElement: name [" << u8s2qs(qName) << "]\n");
|
264 |
if (qName == "SD") {
|
271 |
if (qName == "SD") {
|
265 |
// Simple search saved data has a type='ssearch' attribute.
|
272 |
// Simple search saved data has a type='ssearch' attribute.
|
266 |
int idx = attrs.index("type");
|
273 |
int idx = attrs.index("type");
|
267 |
if (idx < 0 && attrs.value(idx).compare("ssearch")) {
|
274 |
if (idx < 0 && attrs.value(idx).compare("ssearch")) {
|
268 |
LOGDEB("XMLTOSSS: bad type\n" );
|
275 |
LOGDEB("XMLTOSSS: bad type\n");
|
269 |
return false;
|
276 |
return false;
|
270 |
}
|
277 |
}
|
271 |
resetTemps();
|
278 |
resetTemps();
|
272 |
}
|
279 |
}
|
273 |
return true;
|
280 |
return true;
|
|
... |
|
... |
275 |
|
282 |
|
276 |
bool SSHXMLHandler::endElement(const QString & /* namespaceURI */,
|
283 |
bool SSHXMLHandler::endElement(const QString & /* namespaceURI */,
|
277 |
const QString & /* localName */,
|
284 |
const QString & /* localName */,
|
278 |
const QString &qName)
|
285 |
const QString &qName)
|
279 |
{
|
286 |
{
|
280 |
LOGDEB2("SSHXMLHandler::endElement: name [" << ((const char *)qName.toUtf8()) << "]\n" );
|
287 |
LOGDEB2("SSHXMLHandler::endElement: name [" << u8s2qs(qName) << "]\n");
|
281 |
|
288 |
|
282 |
currentText = currentText.trimmed();
|
289 |
currentText = currentText.trimmed();
|
283 |
|
290 |
|
284 |
if (qName == "SL") {
|
291 |
if (qName == "SL") {
|
285 |
stringToStrings(qs2utf8s(currentText), data.stemlangs);
|
292 |
stringToStrings(qs2utf8s(currentText), data.stemlangs);
|
|
... |
|
... |
295 |
} else if (!currentText.compare("OR")) {
|
302 |
} else if (!currentText.compare("OR")) {
|
296 |
data.mode = SSearch::SST_ANY;
|
303 |
data.mode = SSearch::SST_ANY;
|
297 |
} else if (!currentText.compare("AND")) {
|
304 |
} else if (!currentText.compare("AND")) {
|
298 |
data.mode = SSearch::SST_ALL;
|
305 |
data.mode = SSearch::SST_ALL;
|
299 |
} else {
|
306 |
} else {
|
300 |
LOGERR("BAD SEARCH MODE: [" << (qs2utf8s(currentText)) << "]\n" );
|
307 |
LOGERR("BAD SEARCH MODE: [" << qs2utf8s(currentText) << "]\n");
|
301 |
return false;
|
308 |
return false;
|
302 |
}
|
309 |
}
|
303 |
} else if (qName == "AS") {
|
310 |
} else if (qName == "AS") {
|
304 |
stringToStrings(qs2utf8s(currentText), data.autosuffs);
|
311 |
stringToStrings(qs2utf8s(currentText), data.autosuffs);
|
305 |
} else if (qName == "AP") {
|
312 |
} else if (qName == "AP") {
|
|
... |
|
... |
322 |
|
329 |
|
323 |
QXmlInputSource xmlInputSource;
|
330 |
QXmlInputSource xmlInputSource;
|
324 |
xmlInputSource.setData(QString::fromUtf8(xml.c_str()));
|
331 |
xmlInputSource.setData(QString::fromUtf8(xml.c_str()));
|
325 |
|
332 |
|
326 |
if (!reader.parse(xmlInputSource) || !handler.isvalid) {
|
333 |
if (!reader.parse(xmlInputSource) || !handler.isvalid) {
|
327 |
LOGERR("xmlToSSearch: parse failed for [" << (xml) << "]\n" );
|
334 |
LOGERR("xmlToSSearch: parse failed for [" << xml << "]\n");
|
328 |
return false;
|
335 |
return false;
|
329 |
}
|
336 |
}
|
330 |
data = handler.data;
|
337 |
data = handler.data;
|
331 |
return true;
|
338 |
return true;
|
332 |
}
|
339 |
}
|