1 | /* |
2 | This file is part of the syndication library |
3 | SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef SYNDICATION_ATOM_CONTENT_H |
9 | #define SYNDICATION_ATOM_CONTENT_H |
10 | |
11 | #include <syndication/elementwrapper.h> |
12 | |
13 | #include <QString> |
14 | |
15 | class QByteArray; |
16 | class QDomElement; |
17 | |
18 | namespace Syndication |
19 | { |
20 | namespace Atom |
21 | { |
22 | /*! |
23 | * \class Syndication::Atom::Content |
24 | * \inmodule Syndication |
25 | * \inheaderfile Syndication/Atom/Content |
26 | * |
27 | * \brief The content element either contains or links the content of an entry. |
28 | * |
29 | * The content is usually plain text or HTML, but arbitrary XML or binary |
30 | * content are also possible. If isContained() is false, the content is |
31 | * not contained in the feed source, but linked. |
32 | */ |
33 | class SYNDICATION_EXPORT Content : public ElementWrapper |
34 | { |
35 | public: |
36 | /*! |
37 | * format of the content. |
38 | * |
39 | * \value PlainText the content is plain text (i.e. "<", ">" etc. are text, not markup |
40 | * \value EscapedHTML the content is escaped HTML, (i.e., "<", ">" etc. are markup) |
41 | * \value XML the content is embedded XML |
42 | * \value Binary the content is base64-encoded binary content |
43 | */ |
44 | enum Format { |
45 | PlainText, |
46 | EscapedHTML, |
47 | XML, |
48 | Binary, |
49 | }; |
50 | |
51 | /*! |
52 | * maps a mimetype to Format enum according to the Atom 1.0 |
53 | * specification |
54 | * |
55 | * \a type a valid mimetype, or one of "text", "html", "xhtml" |
56 | * |
57 | * \a src content source, see src() for details. |
58 | */ |
59 | static Format mapTypeToFormat(const QString &type, const QString &src = QString()); |
60 | |
61 | /*! |
62 | * creates a null content object. |
63 | */ |
64 | Content(); |
65 | |
66 | /*! |
67 | * creates a Content object wrapping an atom:content element. |
68 | * |
69 | * \a element a DOM element, should be a atom:content element |
70 | * (although not enforced), otherwise this object will not parse |
71 | * anything useful |
72 | */ |
73 | explicit Content(const QDomElement &element); |
74 | |
75 | /*! |
76 | * creates a copy of another Content object |
77 | * |
78 | * \a other the content object to copy |
79 | */ |
80 | Content(const Content &other); |
81 | |
82 | ~Content() override; |
83 | |
84 | /*! |
85 | * assigns another content objecct |
86 | * |
87 | * \a other the Content object to assign |
88 | */ |
89 | Content &operator=(const Content &other); |
90 | |
91 | /*! |
92 | * the type of the content. This is either "text" (plain text), |
93 | * "html" (escaped HTML), "xhtml" (embedded XHTML) or a mime type |
94 | * |
95 | * Returns the content type. If no type is specified, "text" (the |
96 | * default) is returned. |
97 | */ |
98 | Q_REQUIRED_RESULT QString type() const; |
99 | |
100 | /*! |
101 | * If src() is set, the content of this entry is not contained in the |
102 | * feed source, but available on the net. |
103 | * src() then contains a URL (more precise: IRI reference) linking to |
104 | * remote content. |
105 | * If src is provided, type() should contain a mimetype, instead of "text", |
106 | * "html" or "xhtml". |
107 | * |
108 | * Returns a null string if the content is contained in the feed |
109 | * source, or a URL linking to the remote content |
110 | */ |
111 | Q_REQUIRED_RESULT QString src() const; |
112 | |
113 | /*! |
114 | * returns the content as string. If the content format is Text, the |
115 | * returned string contains the text as HTML. |
116 | * If the content is embedded XML, the XML is returned as string. |
117 | * |
118 | * Returns a string representation of the content, or a null string if |
119 | * the content is either binary content or not contained but linked |
120 | * (see isContained()) |
121 | */ |
122 | Q_REQUIRED_RESULT QString asString() const; |
123 | |
124 | /*! |
125 | * Returns byte array containing the embedded binary data, or |
126 | * an empty array if the content is not in binary format |
127 | */ |
128 | Q_REQUIRED_RESULT QByteArray asByteArray() const; |
129 | |
130 | /*! |
131 | * returns the content format |
132 | */ |
133 | Q_REQUIRED_RESULT Format format() const; |
134 | |
135 | /*! |
136 | * returns whether the content is contained in the feed source, |
137 | * or not. If it is not contained, src() provides a URL to the |
138 | * content. |
139 | */ |
140 | Q_REQUIRED_RESULT bool isContained() const; |
141 | |
142 | /*! |
143 | * returns whether the content is embedded XML. |
144 | * Use element() to access the DOM tree, or asString() to get the XML |
145 | * as string. |
146 | */ |
147 | Q_REQUIRED_RESULT bool isXML() const; |
148 | |
149 | /*! |
150 | * returns whether the content is binary content or not. |
151 | * Use asByteArray() to access it. |
152 | */ |
153 | Q_REQUIRED_RESULT bool isBinary() const; |
154 | |
155 | /*! |
156 | * returns whether the content is plain text or not. |
157 | * Use asString() to access it. |
158 | */ |
159 | Q_REQUIRED_RESULT bool isPlainText() const; |
160 | |
161 | /*! |
162 | * returns whether the content is escaped HTML or not |
163 | * Use asString() to access it |
164 | */ |
165 | Q_REQUIRED_RESULT bool isEscapedHTML() const; |
166 | |
167 | /*! |
168 | * returns a description of the content object |
169 | * for debugging purposes |
170 | */ |
171 | Q_REQUIRED_RESULT QString debugInfo() const; |
172 | |
173 | private: |
174 | class ContentPrivate; |
175 | QSharedPointer<ContentPrivate> d; |
176 | }; |
177 | |
178 | } // namespace Atom |
179 | } // namespace Syndication |
180 | |
181 | #endif // SYNDICATION_ATOM_CONTENT_H |
182 | |