Ejemplo n.º 1
0
	void OPMLParser::ParseOutline (const QDomElement& parentOutline,
			QStringList previousStrings) const
	{
		if (parentOutline.hasAttribute ("xmlUrl"))
		{
			OPMLItem item;
			item.URL_ = parentOutline.attribute ("xmlUrl");
			item.HTMLUrl_ = parentOutline.attribute ("htmlUrl");
			item.Title_ = parentOutline.attribute ("title");
			item.CustomFetchInterval_ = (parentOutline
				.attribute ("useCustomFetchInterval") == "true");
			item.MaxArticleAge_ = parentOutline
				.attribute ("maxArticleAge").toInt ();
			item.FetchInterval_ = parentOutline
				.attribute ("fetchInterval").toInt ();
			item.MaxArticleNumber_ = parentOutline
				.attribute ("maxArticleNumber").toInt ();
			item.Description_ = parentOutline.attribute ("description");
			item.Categories_ = previousStrings;
	
			Items_.push_back (item);
		}
	
		if (parentOutline.attribute ("text").size ())
			previousStrings << parentOutline.attribute ("text");
	
		QDomElement outline = parentOutline.firstChildElement ("outline");
		while (!outline.isNull ())
		{
			ParseOutline (outline, previousStrings);
			outline = outline.nextSiblingElement ("outline");
		}
	}
Ejemplo n.º 2
0
void PodcastParser::ParseOutline(QXmlStreamReader* reader, OpmlContainer* ret) const {
  while (!reader->atEnd()) {
    QXmlStreamReader::TokenType type = reader->readNext();
    switch (type) {
    case QXmlStreamReader::StartElement: {
      const QStringRef name = reader->name();
      if (name != "outline") {
        Utilities::ConsumeCurrentElement(reader);
        continue;
      }

      QXmlStreamAttributes attributes = reader->attributes();

      if (attributes.value("type").toString() == "rss") {
        // Parse the feed and add it to this container
        Podcast podcast;
        podcast.set_description(attributes.value("description").toString());
        podcast.set_title(attributes.value("text").toString());
        podcast.set_image_url_large(QUrl::fromEncoded(attributes.value("imageHref").toString().toAscii()));
        podcast.set_url(QUrl::fromEncoded(attributes.value("xmlUrl").toString().toAscii()));
        ret->feeds.append(podcast);

        // Consume any children and the EndElement.
        Utilities::ConsumeCurrentElement(reader);
      } else {
        // Create a new child container
        OpmlContainer child;

        // Take the name from the fullname attribute first if it exists.
        child.name = attributes.value("fullname").toString();
        if (child.name.isEmpty()) {
          child.name = attributes.value("text").toString();
        }

        // Parse its contents and add it to this container
        ParseOutline(reader, &child);
        ret->containers.append(child);
      }

      break;
    }

    case QXmlStreamReader::EndElement:
      return;

    default:
      break;
    }
  }
}
Ejemplo n.º 3
0
bool PodcastParser::ParseOpml(QXmlStreamReader* reader, OpmlContainer* ret) const {
  if (!Utilities::ParseUntilElement(reader, "body")) {
    return false;
  }

  ParseOutline(reader, ret);

  // OPML files sometimes consist of a single top level container.
  while (ret->feeds.count() == 0 &&
         ret->containers.count() == 1) {
    *ret = ret->containers[0];
  }

  return true;
}
Ejemplo n.º 4
0
	OPMLParser::items_container_t OPMLParser::Parse () const
	{
		if (!CacheValid_)
		{
			Items_.clear ();
	
			QDomElement body = Document_.documentElement ()
				.firstChildElement ("body");
			QDomElement outline = body.firstChildElement ("outline");
			while (!outline.isNull ())
			{ 
				ParseOutline (outline);
				outline = outline.nextSiblingElement ("outline");
			}
	
			CacheValid_ = true;
		}
	
		return Items_;
	}