File indexing completed on 2023-10-03 03:26:51
0001 /* 0002 This file is part of the syndication library 0003 SPDX-FileCopyrightText: 2005 Frank Osterfeld <osterfeld@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef SYNDICATION_RSS2_ITEM_H 0009 #define SYNDICATION_RSS2_ITEM_H 0010 0011 #include <syndication/elementwrapper.h> 0012 #include <syndication/rss2/document.h> 0013 #include <syndication/specificitem.h> 0014 0015 #include <ctime> 0016 0017 class QDomElement; 0018 class QString; 0019 template<class T> 0020 class QList; 0021 0022 namespace Syndication 0023 { 0024 class SpecificItemVisitor; 0025 0026 namespace RSS2 0027 { 0028 class Category; 0029 class Enclosure; 0030 class Source; 0031 0032 /** 0033 * An Item, representing an entry in an RSS feed. 0034 * 0035 * @author Frank Osterfeld 0036 */ 0037 class SYNDICATION_EXPORT Item : public ElementWrapper, public Syndication::SpecificItem 0038 { 0039 public: 0040 /** 0041 * Default constructor, creates a null object, for which isNull() is 0042 * @c true. 0043 */ 0044 explicit Item(QSharedPointer<Document> doc = QSharedPointer<Document>()); 0045 0046 /** 0047 * Creates an Item object wrapping an @c <item> XML element. 0048 * 0049 * @param element The @c <item> element to wrap 0050 * @param doc the document this item is part of 0051 */ 0052 explicit Item(const QDomElement &element, QSharedPointer<Document> doc = QSharedPointer<Document>()); 0053 0054 /** 0055 * creates a copy of an item. As the d pointer is shared, 0056 * this is a cheap operation. 0057 * 0058 * @param other the item to copy 0059 */ 0060 Item(const Item &other); 0061 0062 /** 0063 * destructor 0064 */ 0065 ~Item() override; 0066 0067 /** 0068 * assigns another item. As the d pointer is shared, 0069 * this is a cheap operation. 0070 * 0071 * @param other the item to assign 0072 */ 0073 Item &operator=(const Item &other); 0074 0075 /** 0076 * Used by visitors for double dispatch. See SpecificItemVisitor 0077 * for more information. 0078 * @param visitor the visitor calling the method 0079 */ 0080 bool accept(SpecificItemVisitor *visitor) override; 0081 0082 /** 0083 * The title of the item. 0084 * 0085 * @return The title in plain text. Note that e.g. characters like <, 0086 * >, & are not escaped! 0087 * (TODO: this might change, check what makes more sense) 0088 */ 0089 QString title() const; 0090 0091 /** 0092 * The URL of the item. This usually links to the web representation 0093 * of the item, e.g. the full news article. 0094 * 0095 * @return an URL, or a null string if not set 0096 */ 0097 QString link() const; 0098 0099 /** 0100 * The item synopsis. This might contain a short summary of the 0101 * item, but also the full content. If content() is set, that usually 0102 * contains the full content instead. 0103 * 0104 * @return a string in HTML format (whitespace is irrelevant, 0105 * @c <br/> is used for newlines, "&", "<", ">" are escaped) 0106 * summarizing the item. A null string if no description was specified. 0107 */ 0108 QString description() const; 0109 0110 /** 0111 * Returns the actual content of the item. In RSS2, this can be stored 0112 * in various elements, e.g. in content:encoded, xhtml:body or 0113 * xhtml:div. If this is not set, description() might also contain the 0114 * content of the item. 0115 * 0116 * @return the content in HTML format (whitespace is irrelevant, 0117 * <br/> is used for newlines, "&", "<", ">" are escaped) 0118 * If no content is specified, a null string is returned. 0119 */ 0120 QString content() const; 0121 0122 /** 0123 * Set of categories this item is included in. 0124 * 0125 * @return a list of categories, possibly empty. 0126 */ 0127 QList<Category> categories() const; 0128 0129 /** 0130 * URL of a page for comments relating to the item. 0131 * 0132 * @return an URL to the comments, or a null string if not set 0133 */ 0134 QString comments() const; 0135 0136 /** 0137 * The email address of the author of this item. For newspapers and 0138 * magazines syndicating via RSS, the author is the person who wrote 0139 * the article that this item describes. For collaborative weblogs, the 0140 * author of the item might be different from the managing editor or 0141 * webmaster. 0142 * This method returns the content of the @c <author> element. If 0143 * @c <author> is not available, the method returns 0144 * @c <dc:creator> instead, if available. 0145 * 0146 * @return an email address of the author, or a null string if not 0147 * specified 0148 */ 0149 QString author() const; 0150 0151 /** 0152 * Descriptions of media objects that are attached to the item. 0153 * Note that the RSS2 spec is a bit unclear about whether an item can 0154 * have multiple enclosures or not. Originally it was not intended, but 0155 * in reality, some tools out there specify multiple enclosures. 0156 * So most of the time, this list be either empty or contains a 0157 * single item, but don't take that for granted 0158 */ 0159 QList<Enclosure> enclosures() const; 0160 0161 /** 0162 * "guid stands for globally unique identifier. It's a string that 0163 * uniquely identifies the item. When present, an aggregator may choose 0164 * to use this string to determine if an item is new. 0165 * There are no rules for the syntax of a guid. Aggregators must view 0166 * them as a string. It's up to the source of the feed to establish the 0167 * uniqueness of the string." 0168 * 0169 * @return a guid string, or a null string if none specified in the 0170 * feed 0171 */ 0172 QString guid() const; 0173 0174 /** 0175 * If @c true, it can be assumed that the guid is a permalink to the 0176 * item, that is, a url that can be opened in a Web browser, that 0177 * points to the full item. 0178 * 0179 * @return @c true if the guid is a permalink and can be interpreted as 0180 * URL 0181 */ 0182 bool guidIsPermaLink() const; 0183 0184 /** 0185 * Indicates when the item was published. If it's a date in the future, 0186 * you may choose to not display the item until that date. 0187 * This returns the content of the @c <pubDate> element. If @c 0188 * <pubDate> is not available, the method returns 0189 * @c <dc:date> instead, if available. 0190 * 0191 * @return the publication date, or 0 if no date was specified or 0192 * parsing failed 0193 */ 0194 time_t pubDate() const; 0195 0196 /** 0197 * expiration date, specifying a date when the item is not longer 0198 * available. 0199 * Only available in RSS 0.93. 0200 * 0201 * @return the expiration date, or 0 if no date was specified or 0202 * parsing failed 0203 */ 0204 time_t expirationDate() const; 0205 0206 /** 0207 * A Platform for Internet Content Selection (PICS) rating tag. 0208 * More information on the format of the rating tag can be found here: 0209 * http://www.w3.org/PICS/ 0210 * 0211 * @return PICS rating information, or a null string if not specified 0212 */ 0213 QString rating() const; 0214 0215 /** 0216 * The RSS channel that the item came from. See Source class for more 0217 * information. 0218 * 0219 * @return a Source object, or a null object (see Source.isNull()) if 0220 * not set. 0221 */ 0222 Source source() const; 0223 0224 /** 0225 * returns all child elements of this item not covered by this class. 0226 * You can use this to access additional metadata from RSS extensions. 0227 */ 0228 QList<QDomElement> unhandledElements() const; 0229 0230 /** 0231 * Returns a description of the object and its children for debugging 0232 * purposes. 0233 * 0234 * @return debug string 0235 */ 0236 QString debugInfo() const; 0237 0238 //@cond PRIVATE 0239 /** 0240 * @internal 0241 * returns the description content in unmodified form (no 0242 * plaintext/HTML conversions etc.) 0243 */ 0244 QString originalDescription() const; 0245 0246 /** 0247 * @internal 0248 * returns the title content in unmodified form (no 0249 * plaintext/HTML conversions etc.) 0250 */ 0251 QString originalTitle() const; 0252 //@endcond 0253 0254 private: 0255 class ItemPrivate; 0256 QSharedPointer<ItemPrivate> d; 0257 }; 0258 0259 } // namespace RSS2 0260 } // namespace Syndication 0261 0262 #endif // SYNDICATION_RSS2_ITEM_H