27 #include <QtCore/QByteArray> 28 #include <QtXml/QDomElement> 29 #include <QtCore/QString> 30 #include <QtCore/QStringList> 35 class Content::ContentPrivate
39 ContentPrivate() : formatIdentified(false)
43 mutable bool formatIdentified;
50 Content::Content(
const QDomElement& element) : ElementWrapper(element), d(new ContentPrivate)
64 ElementWrapper::operator=(other);
71 return attribute(QLatin1String(
"type"));
76 return completeURI(attribute(QLatin1String(
"src")));
83 return QByteArray::fromBase64(text().trimmed().toLatin1());
87 static QStringList xmltypes;
96 if (
type.isNull() &&
src.isEmpty())
97 type = QLatin1String(
"text");
99 if (
type == QLatin1String(
"html")
100 ||
type == QLatin1String(
"text/html"))
103 if (
type == QLatin1String(
"text")
104 || (
type.startsWith(QLatin1String(
"text/"), Qt::CaseInsensitive)
105 && !
type.startsWith(QLatin1String(
"text/xml"), Qt::CaseInsensitive))
109 if (xmltypes.isEmpty())
111 xmltypes.append(QLatin1String(
"xhtml"));
112 xmltypes.append(QLatin1String(
"application/xhtml+xml"));
114 xmltypes.append(QLatin1String(
"text/xml"));
115 xmltypes.append(QLatin1String(
"application/xml"));
116 xmltypes.append(QLatin1String(
"text/xml-external-parsed-entity"));
117 xmltypes.append(QLatin1String(
"application/xml-external-parsed-entity"));
118 xmltypes.append(QLatin1String(
"application/xml-dtd"));
119 xmltypes.append(QLatin1String(
"text/x-dtd"));
122 if (xmltypes.contains(
type)
123 ||
type.endsWith(QLatin1String(
"+xml"), Qt::CaseInsensitive)
124 ||
type.endsWith(QLatin1String(
"/xml"), Qt::CaseInsensitive))
132 if (d->formatIdentified ==
false)
135 d->formatIdentified =
true;
147 return src().isEmpty();
171 return plainTextToHtml(text()).trimmed();
175 return text().trimmed();
179 return childNodesAsXML().trimmed();
188 info += QLatin1String(
"### Content: ###################\n");
189 info += QLatin1String(
"type: #") +
type() + QLatin1String(
"#\n");
191 info += QLatin1String(
"src: #") +
src() + QLatin1String(
"#\n");
193 info += QLatin1String(
"content: #") +
asString() + QLatin1String(
"#\n");
196 info += QLatin1String(
"binary length: #") + QString::number(
asByteArray().size()) + QLatin1String(
"#\n");
198 info += QLatin1String(
"### Content end ################\n");
bool isXML() const
returns whether the content is embedded XML.
The content element either contains or links the content of an entry.
the content is escaped HTML, (i.e., "<", ">" etc.
the content is plain text (i.e.
QString src() const
If src() is set, the content of this entry is not contained in the feed source, but available on the ...
Content & operator=(const Content &other)
assigns another content objecct
the content is base64-encoded binary content
bool isEscapedHTML() const
returns whether the content is escaped HTML or not Use asString() to access it
bool isContained() const
returns whether the content is contained in the feed source, or not.
QString asString() const
returns the content as string.
QString type() const
the type of the content.
Format format() const
returns the content format
QString debugInfo() const
returns a description of the content object for debugging purposes
the content is embedded XML
static Format mapTypeToFormat(const QString &type, const QString &src=QString())
maps a mimetype to Format enum according to the Atom 1.0 specification
QByteArray asByteArray() const
returns binary content as byte array.
Format
format of the content.
bool isBinary() const
returns whether the content is binary content or not.
Content()
creates a null content object.
bool isPlainText() const
returns whether the content is plain text or not.