15 #include "textinput.h"
21 #include <tqdatetime.h>
23 #include <tqptrlist.h>
29 struct Document::Private :
public Shared
75 static TQString extractLink(
const TQDomNode& node, Format format)
77 if (format == AtomFeed)
80 for (n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {
81 const TQDomElement e = n.toElement();
82 if ( (e.tagName() == TQString::fromLatin1(
"link"))
83 && (e.attribute(TQString::fromLatin1(
"rel"), TQString::fromLatin1(
"alternate")) == TQString::fromLatin1(
"alternate")))
85 return n.toElement().attribute(TQString::fromLatin1(
"href"));
90 return extractNode(node, TQString::fromLatin1(
"link"));
97 TQDomNode rootNode = doc.documentElement();
103 if (rootNode.toElement().tagName()==TQString::fromLatin1(
"html"))
108 attr = rootNode.toElement().attribute(TQString::fromLatin1(
"version"), TQString());
109 if (rootNode.toElement().tagName()==TQString::fromLatin1(
"feed"))
112 if (attr == TQString::fromLatin1(
"0.3"))
113 d->version = vAtom_0_3;
114 else if (attr == TQString::fromLatin1(
"0.2"))
115 d->version = vAtom_0_2;
116 else if (attr == TQString::fromLatin1(
"0.1"))
117 d->version = vAtom_0_1;
119 d->version = vAtom_1_0;
124 if (attr == TQString::fromLatin1(
"0.91"))
126 else if (attr == TQString::fromLatin1(
"0.92"))
128 else if (attr == TQString::fromLatin1(
"0.93"))
130 else if (attr == TQString::fromLatin1(
"0.94"))
138 if (d->format==UnknownFormat)
140 attr = rootNode.toElement().attribute(TQString::fromLatin1(
"xmlns"), TQString());
141 if (!attr.isNull()) {
150 if (attr == TQString::fromLatin1(
"http://my.netscape.com/rdf/simple/0.9/")) {
154 else if (attr == TQString::fromLatin1(
"http://purl.org/rss/1.0/")) {
161 TQDomNode channelNode;
163 if (d->format == AtomFeed)
164 channelNode=rootNode;
166 channelNode=rootNode.namedItem(TQString::fromLatin1(
"channel"));
168 if (!(elemText = extractTitle(channelNode)).isNull())
170 TQString descriptionTagName =
"description";
172 if (d->format == AtomFeed)
174 if (d->version == vAtom_1_0)
175 descriptionTagName =
"subtitle";
177 descriptionTagName =
"tagline";
180 if (!(elemText = extractNode(channelNode, descriptionTagName)).isNull())
181 d->description = elemText;
183 d->link = extractLink(channelNode, d->format);
189 TQDomNode parentNode;
190 if (d->version == v0_90 || d->version == v1_0 || d->format == AtomFeed)
191 parentNode = rootNode;
195 if (!rootNode.namedItem(TQString::fromLatin1(
"item")).isNull())
196 parentNode = rootNode;
198 parentNode = channelNode;
202 TQDomNode n = parentNode.namedItem(TQString::fromLatin1(
"image"));
204 d->image =
new Image(n);
206 n = parentNode.namedItem(TQString::fromLatin1(
"textinput"));
212 if (d->format == AtomFeed)
213 tagName=TQString::fromLatin1(
"entry");
215 tagName=TQString::fromLatin1(
"item");
217 for (n = parentNode.firstChild(); !n.isNull(); n = n.nextSibling()) {
218 const TQDomElement e = n.toElement();
219 if (e.tagName() == tagName)
220 d->articles.append(
Article(e, d->format, d->version));
223 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"copyright"))).isNull())
224 d->copyright = elemText;
226 if (d->format == AtomFeed)
227 elemText = rootNode.toElement().attribute(TQString::fromLatin1(
"xml:lang"), TQString());
229 elemText = extractNode(channelNode, TQString::fromLatin1(
"language"));
231 if (!elemText.isNull()){
232 if (elemText == TQString::fromLatin1(
"af"))
234 else if (elemText == TQString::fromLatin1(
"sq"))
236 else if (elemText == TQString::fromLatin1(
"eu"))
238 else if (elemText == TQString::fromLatin1(
"be"))
240 else if (elemText == TQString::fromLatin1(
"bg"))
242 else if (elemText == TQString::fromLatin1(
"ca"))
244 else if (elemText == TQString::fromLatin1(
"zh-cn"))
246 else if (elemText == TQString::fromLatin1(
"zh-tw"))
248 else if (elemText == TQString::fromLatin1(
"hr"))
250 else if (elemText == TQString::fromLatin1(
"cs"))
252 else if (elemText == TQString::fromLatin1(
"da"))
254 else if (elemText == TQString::fromLatin1(
"nl"))
256 else if (elemText == TQString::fromLatin1(
"nl-be"))
258 else if (elemText == TQString::fromLatin1(
"nl-nl"))
260 else if (elemText == TQString::fromLatin1(
"en"))
262 else if (elemText == TQString::fromLatin1(
"en-au"))
264 else if (elemText == TQString::fromLatin1(
"en-bz"))
266 else if (elemText == TQString::fromLatin1(
"en-ca"))
268 else if (elemText == TQString::fromLatin1(
"en-ie"))
270 else if (elemText == TQString::fromLatin1(
"en-jm"))
272 else if (elemText == TQString::fromLatin1(
"en-nz"))
274 else if (elemText == TQString::fromLatin1(
"en-ph"))
276 else if (elemText == TQString::fromLatin1(
"en-za"))
278 else if (elemText == TQString::fromLatin1(
"en-tt"))
280 else if (elemText == TQString::fromLatin1(
"en-gb"))
282 else if (elemText == TQString::fromLatin1(
"en-us"))
284 else if (elemText == TQString::fromLatin1(
"en-zw"))
286 else if (elemText == TQString::fromLatin1(
"fo"))
288 else if (elemText == TQString::fromLatin1(
"fi"))
290 else if (elemText == TQString::fromLatin1(
"fr"))
292 else if (elemText == TQString::fromLatin1(
"fr-be"))
294 else if (elemText == TQString::fromLatin1(
"fr-ca"))
296 else if (elemText == TQString::fromLatin1(
"fr-fr"))
298 else if (elemText == TQString::fromLatin1(
"fr-lu"))
300 else if (elemText == TQString::fromLatin1(
"fr-mc"))
302 else if (elemText == TQString::fromLatin1(
"fr-ch"))
304 else if (elemText == TQString::fromLatin1(
"gl"))
306 else if (elemText == TQString::fromLatin1(
"gd"))
308 else if (elemText == TQString::fromLatin1(
"de"))
310 else if (elemText == TQString::fromLatin1(
"de-at"))
312 else if (elemText == TQString::fromLatin1(
"de-de"))
314 else if (elemText == TQString::fromLatin1(
"de-li"))
316 else if (elemText == TQString::fromLatin1(
"de-lu"))
318 else if (elemText == TQString::fromLatin1(
"de-ch"))
320 else if (elemText == TQString::fromLatin1(
"el"))
322 else if (elemText == TQString::fromLatin1(
"hu"))
324 else if (elemText == TQString::fromLatin1(
"is"))
326 else if (elemText == TQString::fromLatin1(
"id"))
328 else if (elemText == TQString::fromLatin1(
"ga"))
330 else if (elemText == TQString::fromLatin1(
"it"))
332 else if (elemText == TQString::fromLatin1(
"it-it"))
334 else if (elemText == TQString::fromLatin1(
"it-ch"))
336 else if (elemText == TQString::fromLatin1(
"ja"))
338 else if (elemText == TQString::fromLatin1(
"ko"))
340 else if (elemText == TQString::fromLatin1(
"mk"))
342 else if (elemText == TQString::fromLatin1(
"no"))
344 else if (elemText == TQString::fromLatin1(
"pl"))
346 else if (elemText == TQString::fromLatin1(
"pt"))
348 else if (elemText == TQString::fromLatin1(
"pt-br"))
350 else if (elemText == TQString::fromLatin1(
"pt-pt"))
352 else if (elemText == TQString::fromLatin1(
"ro"))
354 else if (elemText == TQString::fromLatin1(
"ro-mo"))
356 else if (elemText == TQString::fromLatin1(
"ro-ro"))
358 else if (elemText == TQString::fromLatin1(
"ru"))
360 else if (elemText == TQString::fromLatin1(
"ru-mo"))
362 else if (elemText == TQString::fromLatin1(
"ru-ru"))
364 else if (elemText == TQString::fromLatin1(
"sr"))
366 else if (elemText == TQString::fromLatin1(
"sk"))
368 else if (elemText == TQString::fromLatin1(
"sl"))
370 else if (elemText == TQString::fromLatin1(
"es"))
372 else if (elemText == TQString::fromLatin1(
"es-ar"))
374 else if (elemText == TQString::fromLatin1(
"es-bo"))
376 else if (elemText == TQString::fromLatin1(
"es-cl"))
378 else if (elemText == TQString::fromLatin1(
"es-co"))
380 else if (elemText == TQString::fromLatin1(
"es-cr"))
382 else if (elemText == TQString::fromLatin1(
"es-do"))
384 else if (elemText == TQString::fromLatin1(
"es-ec"))
386 else if (elemText == TQString::fromLatin1(
"es-sv"))
388 else if (elemText == TQString::fromLatin1(
"es-gt"))
390 else if (elemText == TQString::fromLatin1(
"es-hn"))
392 else if (elemText == TQString::fromLatin1(
"es-mx"))
394 else if (elemText == TQString::fromLatin1(
"es-ni"))
396 else if (elemText == TQString::fromLatin1(
"es-pa"))
398 else if (elemText == TQString::fromLatin1(
"es-py"))
400 else if (elemText == TQString::fromLatin1(
"es-pe"))
402 else if (elemText == TQString::fromLatin1(
"es-pr"))
404 else if (elemText == TQString::fromLatin1(
"es-es"))
406 else if (elemText == TQString::fromLatin1(
"es-uy"))
408 else if (elemText == TQString::fromLatin1(
"es-ve"))
410 else if (elemText == TQString::fromLatin1(
"sv"))
412 else if (elemText == TQString::fromLatin1(
"sv-fi"))
414 else if (elemText == TQString::fromLatin1(
"sv-se"))
416 else if (elemText == TQString::fromLatin1(
"tr"))
418 else if (elemText == TQString::fromLatin1(
"uk"))
421 d->language = UndefinedLanguage;
424 if (d->format == AtomFeed)
425 tagName=TQString::fromLatin1(
"issued");
428 tagName=TQString::fromLatin1(
"pubDate");
430 if (!(elemText = extractNode(channelNode, tagName)).isNull()) {
433 if (d->format == AtomFeed)
434 _time=parseISO8601Date(elemText);
436 _time=KRFCDate::parseDate(elemText);
441 d->pubDate.setTime_t(_time);
444 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"dc:date"))).isNull()) {
445 time_t _time = parseISO8601Date(elemText);
450 d->pubDate.setTime_t(_time);
453 if (d->format == AtomFeed)
454 tagName=TQString::fromLatin1(
"modified");
456 tagName=TQString::fromLatin1(
"lastBuildDate");
457 if (!(elemText = extractNode(channelNode, tagName)).isNull()) {
459 if (d->format == AtomFeed)
460 _time = parseISO8601Date(elemText);
462 _time = KRFCDate::parseDate(elemText);
463 d->lastBuildDate.setTime_t(_time);
466 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"rating"))).isNull())
467 d->rating = elemText;
468 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"docs"))).isNull())
470 if (!(elemText = extractNode(channelNode, TQString::fromLatin1((d->format == AtomFeed) ?
"author" :
"managingEditor"))).isNull())
471 d->managingEditor = elemText;
472 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"webMaster"))).isNull())
473 d->webMaster = elemText;
475 if (!(elemText = extractNode(channelNode, TQString::fromLatin1(
"ttl"))).isNull())
476 d->ttl = elemText.toUInt();
478 n = channelNode.namedItem(TQString::fromLatin1(
"skipHours"));
480 for (TQDomElement e = n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement())
481 if (e.tagName() == TQString::fromLatin1(
"hour"))
482 d->skipHours.append(e.text().toUInt());
484 n = channelNode.namedItem(TQString::fromLatin1(
"skipDays"));
488 for (TQDomElement e = n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement())
489 if (e.tagName() == TQString::fromLatin1(
"day")) {
490 elemText = e.text().lower();
491 if (elemText == TQString::fromLatin1(
"monday"))
493 else if (elemText == TQString::fromLatin1(
"tuesday"))
495 else if (elemText == TQString::fromLatin1(
"wednesday"))
497 else if (elemText == TQString::fromLatin1(
"thursday"))
499 else if (elemText == TQString::fromLatin1(
"friday"))
501 else if (elemText == TQString::fromLatin1(
"saturday"))
503 else if (elemText == TQString::fromLatin1(
"sunday"))
507 if (day != UndefinedDay)
508 d->skipDays.append(day);
531 switch (d->version) {
532 case v0_90:
return TQString::fromLatin1(
"0.90");
533 case v0_91:
return TQString::fromLatin1(
"0.91");
534 case v0_92:
return TQString::fromLatin1(
"0.92");
535 case v0_93:
return TQString::fromLatin1(
"0.93");
536 case v0_94:
return TQString::fromLatin1(
"0.94");
537 case v1_0:
return TQString::fromLatin1(
"1.0");
538 case v2_0:
return TQString::fromLatin1(
"2.0");
539 case vAtom_0_3:
return TQString::fromLatin1(
"0.3");
540 case vAtom_0_2:
return TQString::fromLatin1(
"0.2");
541 case vAtom_0_1:
return TQString::fromLatin1(
"0.1");
542 case vAtom_1_0:
return TQString::fromLatin1(
"1.0");
554 return d->description;
604 return d->lastBuildDate;
619 return d->managingEditor;
637 int Document::ttl()
const
644 if (
this != &other) {
Represents an article as stored in a RSS file.
TQValueList< Article > List
A list of articles.