diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-06-07 23:30:05 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-06-07 23:30:05 +0900 |
| commit | 17b259df9cb6b28779d4881b2b6c805ee2e48eea (patch) | |
| tree | 5ed61937459cb7081089111b0242c01ec178f1f3 /reader/src/network/atom | |
| parent | 1cba8bce178eb2d6719c6f7f21e2c9352c5513a6 (diff) | |
| download | tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.tar.gz tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.zip | |
Rename to tde-ebook-reader
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'reader/src/network/atom')
| -rw-r--r-- | reader/src/network/atom/ATOMConstructs.cpp | 339 | ||||
| -rw-r--r-- | reader/src/network/atom/ATOMConstructs.h | 135 | ||||
| -rw-r--r-- | reader/src/network/atom/ATOMContainers.cpp | 49 | ||||
| -rw-r--r-- | reader/src/network/atom/ATOMContainers.h | 142 | ||||
| -rw-r--r-- | reader/src/network/atom/ATOMMetadata.cpp | 202 | ||||
| -rw-r--r-- | reader/src/network/atom/ATOMMetadata.h | 221 |
6 files changed, 1088 insertions, 0 deletions
diff --git a/reader/src/network/atom/ATOMConstructs.cpp b/reader/src/network/atom/ATOMConstructs.cpp new file mode 100644 index 0000000..9684825 --- /dev/null +++ b/reader/src/network/atom/ATOMConstructs.cpp @@ -0,0 +1,339 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "ATOMConstructs.h" + +#include <ZLStringUtil.h> + +#include <math.h> + + + +const std::string ATOMCommonAttributes::XML_BASE = "xml:base"; +const std::string ATOMCommonAttributes::XML_LANG = "xml:lang"; + + +ATOMCommonAttributes::ATOMCommonAttributes() { +} + +ATOMCommonAttributes::~ATOMCommonAttributes() { +} + +void ATOMCommonAttributes::readAttributes(const std::map<std::string, std::string> &attributes) { + readAttribute(XML_BASE, attributes); + readAttribute(XML_LANG, attributes); +} + +void ATOMCommonAttributes::readAttribute(const std::string &name, const std::map<std::string, std::string> &attributes) { + std::map<std::string, std::string>::const_iterator it = attributes.find(name); + if (it != attributes.end()) { + myAttributes[name] = it->second; + } +} + +void ATOMCommonAttributes::setUserData(const std::string &key, const std::string &value) { + myUserData[key] = value; +} + +const std::string ATOMCommonAttributes::userData(const std::string &key) const { + std::map<std::string,std::string>::const_iterator it = myUserData.find(key); + return (it != myUserData.end()) ? it->second : std::string(); +} + +ATOMPersonConstruct::ATOMPersonConstruct() { +} + +ATOMPersonConstruct::ATOMPersonConstruct(const std::string &name) : myName(name) { +} + + +ATOMDateConstruct::ATOMDateConstruct(int year) : + myYear(year), myMonth(0), myDay(0), + myHour(0), myMinutes(0), mySeconds(0), mySecondFraction(0), myTZHour(0), myTZMinutes(0) { +} + +ATOMDateConstruct::ATOMDateConstruct(int year, int month, int day) : + myYear(year), myMonth(month), myDay(day), + myHour(0), myMinutes(0), mySeconds(0), mySecondFraction(0), myTZHour(0), myTZMinutes(0) { +} + +ATOMDateConstruct::ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds) : + myYear(year), myMonth(month), myDay(day), + myHour(hour), myMinutes(minutes), mySeconds(seconds), mySecondFraction(0), myTZHour(0), myTZMinutes(0) { +} + +ATOMDateConstruct::ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds, float sfract) : + myYear(year), myMonth(month), myDay(day), + myHour(hour), myMinutes(minutes), mySeconds(seconds), mySecondFraction(sfract), myTZHour(0), myTZMinutes(0) { +} + +ATOMDateConstruct::ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes) : + myYear(year), myMonth(month), myDay(day), + myHour(hour), myMinutes(minutes), mySeconds(seconds), mySecondFraction(sfract), myTZHour(tzhour), myTZMinutes(tzminutes) { +} + +bool ATOMDateConstruct::operator<(const ATOMDateConstruct &a) const { + if (myYear < a.myYear) return true; + if (myYear > a.myYear) return false; + + if (myMonth < a.myMonth) return true; + if (myMonth > a.myMonth) return false; + + if (myDay < a.myDay) return true; + if (myDay > a.myDay) return false; + + if (myHour < a.myHour) return true; + if (myHour > a.myHour) return false; + + if (myMinutes < a.myMinutes) return true; + if (myMinutes > a.myMinutes) return false; + + if (mySeconds < a.mySeconds) return true; + if (mySeconds > a.mySeconds) return false; + +// if (mySecondFraction < a.mySecondFraction) return true; +// if (mySecondFraction > a.mySecondFraction) return false; + return false; +} + +bool ATOMDateConstruct::operator>(const ATOMDateConstruct &a) const { + if (myYear > a.myYear) return true; + if (myYear < a.myYear) return false; + + if (myMonth > a.myMonth) return true; + if (myMonth < a.myMonth) return false; + + if (myDay > a.myDay) return true; + if (myDay < a.myDay) return false; + + if (myHour > a.myHour) return true; + if (myHour < a.myHour) return false; + + if (myMinutes > a.myMinutes) return true; + if (myMinutes < a.myMinutes) return false; + + if (mySeconds > a.mySeconds) return true; + if (mySeconds < a.mySeconds) return false; + +// if (mySecondFraction < a.mySecondFraction) return true; +// if (mySecondFraction > a.mySecondFraction) return false; + return false; +} + +void ATOMDateConstruct::makeStringLength(std::string &str, int len) { + const int lendiff = str.length() - len; + if (lendiff > 0) { + str = str.substr(lendiff); + } else { + str = std::string(-lendiff, '0') + str; + } +} + + +std::string ATOMDateConstruct::getDateTime(bool brief) const { + std::string timezone = "Z"; + if (myTZMinutes != 0 || myTZHour != 0) { + int tzminnum = myTZMinutes; + int tzhournum = myTZHour; + char sign; + if (tzhournum == 0) { + sign = (tzminnum >= 0) ? '+' : '-'; + } else { + sign = (tzhournum > 0) ? '+' : '-'; + if (tzhournum > 0 && tzminnum < 0) { + --tzhournum; + tzminnum = 60 + tzminnum; + } else if (tzhournum < 0 && tzminnum > 0) { + ++tzhournum; + tzminnum = 60 - tzminnum; + } + } + std::string tzmin, tzhour; + ZLStringUtil::appendNumber(tzmin, tzminnum < 0 ? -tzminnum : tzminnum); + ZLStringUtil::appendNumber(tzhour, tzhournum < 0 ? -tzhournum : tzhournum); + makeStringLength(tzmin, 2); + makeStringLength(tzhour, 2); + timezone = sign + tzhour + ":" + tzmin; + } + + std::string time; + if (mySecondFraction >= 0.01) { + std::string sfr; + unsigned int sfrnum = (unsigned int) floor(100 * mySecondFraction + 0.5); + ZLStringUtil::appendNumber(sfr, sfrnum); + makeStringLength(sfr, 2); + time = "." + sfr; + } + if (!brief || !time.empty() || mySeconds != 0) { + std::string sec; + ZLStringUtil::appendNumber(sec, mySeconds); + makeStringLength(sec, 2); + time = ":" + sec + time; + } + if (!brief || !time.empty() || myHour != 0 || myMinutes != 0 || timezone != "Z") { + std::string hour, min; + ZLStringUtil::appendNumber(hour, myHour); + ZLStringUtil::appendNumber(min, myMinutes); + makeStringLength(hour, 2); + makeStringLength(min, 2); + time = hour + ":" + min + time; + } + + std::string date; + if (!brief || !time.empty() || myDay != 0) { + std::string day; + ZLStringUtil::appendNumber(day, myDay); + makeStringLength(day, 2); + date = "-" + day; + } + if (!brief || !date.empty() || myMonth != 0) { + std::string month; + ZLStringUtil::appendNumber(month, myMonth); + makeStringLength(month, 2); + date = "-" + month + date; + } + + std::string year; + ZLStringUtil::appendNumber(year, myYear); + makeStringLength(year, 4); + date = year + date; + + if (!brief || !time.empty()) { + date = date + "T" + time + timezone; + } + return date; +} + +bool ATOMDateConstruct::parse(const std::string &str, ATOMDateConstruct &dateTime) { + dateTime.setYear(0); + dateTime.setMonth(0); + dateTime.setDay(0); + dateTime.setHour(0); + dateTime.setMinutes(0); + dateTime.setSeconds(0); + dateTime.setSecondFraction(0); + dateTime.setTZHour(0); + dateTime.setTZMinutes(0); + const int len = str.length(); + if (len != 4 && len != 7 && len != 10 && len != 17 && len != 20 && len < 22) { + return false; + } + int num = 0, sign = 1; + float fnum = 0.0, fmult = 0.1; + int start, end, log; + char ch; + end = 4; start = 0; log = 0; + while (start < len) { + ch = str[start++]; + if (!std::isdigit(ch)) { + return false; + } + num = 10 * num + ((int) (ch - '0')); + fnum += fmult * ((int) (ch - '0')); + fmult *= 0.1; + if (start == end) { + switch (log) { + case 0: dateTime.setYear(num); break; + case 1: dateTime.setMonth(num); break; + case 2: dateTime.setDay(num); break; + case 3: dateTime.setHour(num); break; + case 4: dateTime.setMinutes(num); break; + case 5: dateTime.setSeconds(num); break; + case 6: dateTime.setSecondFraction(fnum); break; + case 7: dateTime.setTZHour(sign * num); break; + case 8: dateTime.setTZMinutes(sign * num); break; + default: return false; + } + num = 0; fnum = 0.0; fmult = 0.1; + if (start == len) return true; + switch (log) { + case 0: + case 1: + if (str[start++] != '-') return false; + end = start + 2; + break; + case 2: + if (str[start++] != 'T') return false; + end = start + 2; + break; + case 3: + case 7: + if (str[start++] != ':') return false; + end = start + 2; + break; + case 4: + ch = str[start++]; + if (ch == ':') { + end = start + 2; + } else if (ch == '+' || ch == '-') { + sign = (ch == '-') ? -1 : 1; + log += 2; + end = start + 2; + } else if (ch == 'Z') { + return true; + } else return false; + break; + case 5: + ch = str[start++]; + if (ch == '.') { + end = start; + while (std::isdigit(str[++end])) /* NOP */; + } else if (ch == '+' || ch == '-') { + sign = (ch == '-') ? -1 : 1; + log += 1; + end = start + 2; + } else if (ch == 'Z') { + return true; + } else return false; + break; + case 6: + ch = str[start++]; + if (ch == '+' || ch == '-') { + sign = (ch == '-') ? -1 : 1; + end = start + 2; + } else if (ch == 'Z') { + return true; + } else return false; + break; + //case 8: + default: return false; + } + ++log; + } + } + return false; +} + +long ATOMDateConstruct::getLongSeconds_stupid() { + return ((((((myYear - 2000) * 12 + myMonth) * 31 + myDay) * 24 + myHour) * 60 + myMinutes) * 60 + mySeconds); +} + +void ATOMDateConstruct::setLongSeconds_stupid(long t) { + myYear = t / (12*31*24*60*60) + 2000; + t = t % (12*31*24*60*60); + myMonth = t / (31*24*60*60); + t = t % (31*24*60*60); + myDay = t / (24*60*60); + t = t % (24*60*60); + myHour = t / (60*60); + t = t % (60*60); + myMinutes = t / (60); + t = t % (60); + mySeconds = t; +} diff --git a/reader/src/network/atom/ATOMConstructs.h b/reader/src/network/atom/ATOMConstructs.h new file mode 100644 index 0000000..2497bd4 --- /dev/null +++ b/reader/src/network/atom/ATOMConstructs.h @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ATOMCONSTRUCTS_H__ +#define __ATOMCONSTRUCTS_H__ + +#include <map> +#include <string> + + +class ATOMCommonAttributes { + +public: + static const std::string XML_BASE; + static const std::string XML_LANG; + +public: + ATOMCommonAttributes(); + virtual ~ATOMCommonAttributes(); + +public: + std::map<std::string, std::string> &attributes() { return myAttributes; } + const std::map<std::string, std::string> &attributes() const { return myAttributes; } + + std::string &base() { return myAttributes[XML_BASE]; } + std::string &lang() { return myAttributes[XML_LANG]; } + + virtual void readAttributes(const std::map<std::string, std::string> &attributes); + + void setUserData(const std::string &key, const std::string &value); + const std::string userData(const std::string &key) const; + +protected: + void readAttribute(const std::string &name, const std::map<std::string, std::string> &attributes); + +private: + std::map<std::string, std::string> myAttributes; + std::map<std::string,std::string> myUserData; +}; + + +class ATOMPersonConstruct : public ATOMCommonAttributes { + +public: + ATOMPersonConstruct(); + ATOMPersonConstruct(const std::string &name); + + const std::string &name() const { return myName; } + const std::string &uri() const { return myUri; } + const std::string &email() const { return myEmail; } + + void setName(const std::string &name) { myName = name; } + void setUri(const std::string &uri) { myUri = uri; } + void setEmail(const std::string &email) { myEmail = email; } + +private: + std::string myName; + std::string myUri; + std::string myEmail; +}; + + +class ATOMDateConstruct : public ATOMCommonAttributes { + +public: + static bool parse(const std::string &str, ATOMDateConstruct &dateTime); + +public: + ATOMDateConstruct(int year); + ATOMDateConstruct(int year, int month, int day); + ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds); + ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds, float sfract); + ATOMDateConstruct(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes); + + bool operator <(const ATOMDateConstruct& a) const; + bool operator >(const ATOMDateConstruct& a) const; + + std::string getDateTime(bool brief = false) const; + + int year() const { return myYear; } + int month() const { return myMonth; } + int day() const { return myDay; } + int hour() const { return myHour; } + int minutes() const { return myMinutes; } + int seconds() const { return mySeconds; } + float secondFraction() const { return mySecondFraction; } + int timeZoneHour() const { return myTZHour; } + int timeZoneMinutes() const { return myTZMinutes; } + + void setYear(int year) { myYear = year; } + void setMonth(int month) { myMonth = month; } + void setDay(int day) { myDay = day; } + void setHour(int hour) { myHour = hour; } + void setMinutes(int minutes) { myMinutes = minutes; } + void setSeconds(int seconds) { mySeconds = seconds; } + void setSecondFraction(float sfract) { mySecondFraction = sfract; } + void setTZHour(int tzhour) { myTZHour = tzhour; } + void setTZMinutes(int tzminutes) { myTZMinutes = tzminutes; } + + long getLongSeconds_stupid(); + void setLongSeconds_stupid(long t); + +private: + static void makeStringLength(std::string &str, int len); + +private: + int myYear; + int myMonth; + int myDay; + int myHour; + int myMinutes; + int mySeconds; + float mySecondFraction; + int myTZHour; + int myTZMinutes; +}; + + +#endif /* __ATOMCONSTRUCTS_H__ */ diff --git a/reader/src/network/atom/ATOMContainers.cpp b/reader/src/network/atom/ATOMContainers.cpp new file mode 100644 index 0000000..fb05c10 --- /dev/null +++ b/reader/src/network/atom/ATOMContainers.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "ATOMContainers.h" + +ATOMEntry::ATOMEntry() { +} + +ATOMEntry::ATOMEntry(shared_ptr<ATOMId> id, const std::string &title, shared_ptr<ATOMUpdated> updated) : + myId(id), myTitle(title), myUpdated(updated) { +} + + + +ATOMFeedMetadata::ATOMFeedMetadata() { +} + +ATOMFeedMetadata::ATOMFeedMetadata(shared_ptr<ATOMId> id, const std::string &title, shared_ptr<ATOMUpdated> updated) : + myId(id), myTitle(title), myUpdated(updated) { +} + + + +/* +ATOMFeed::ATOMFeed() { +} + +ATOMFeed::ATOMFeed(const ATOMId &id, const std::string &title, shared_ptr<ATOMUpdated> updated) : + ATOMFeedMatadata(id, title, updated) { +} +*/ + + diff --git a/reader/src/network/atom/ATOMContainers.h b/reader/src/network/atom/ATOMContainers.h new file mode 100644 index 0000000..1fb3f92 --- /dev/null +++ b/reader/src/network/atom/ATOMContainers.h @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ATOMCONTAINTERS_H__ +#define __ATOMCONTAINTERS_H__ + +#include <vector> + +#include <shared_ptr.h> + +#include "ATOMMetadata.h" + + + +class ATOMEntry : public ATOMCommonAttributes { + +public: + ATOMEntry(); + ATOMEntry(shared_ptr<ATOMId> id, const std::string &title, shared_ptr<ATOMUpdated> updated); + + std::vector<shared_ptr<ATOMAuthor> > &authors() { return myAuthors; } + std::vector<shared_ptr<ATOMCategory> > &categories() { return myCategories; } + std::vector<shared_ptr<ATOMContributor> > &contributors() { return myContributors; } + std::vector<shared_ptr<ATOMLink> > &links() { return myLinks; } + + shared_ptr<ATOMPublished> published() { return myPublished; } + shared_ptr<ATOMIcon> icon() { return myIcon; } + const std::string &rights() { return myRights; } + const std::string &summary() { return mySummary; } + const std::string &title() { return myTitle; } + shared_ptr<ATOMUpdated> updated() { return myUpdated; } + + void setPublished(shared_ptr<ATOMPublished> published) { myPublished = published; } + void setIcon(shared_ptr<ATOMIcon> icon) { myIcon = icon; } + void setRights(const std::string &rights) { myRights = rights; } + void setSummary(const std::string &summary) { mySummary = summary; } + void setTitle(const std::string &title) { myTitle = title; } + void setUpdated(shared_ptr<ATOMUpdated> updated) { myUpdated = updated; } + + shared_ptr<ATOMId> id() { return myId; } + void setId(shared_ptr<ATOMId> id) { myId = id; } + +private: + shared_ptr<ATOMId> myId; + + std::vector<shared_ptr<ATOMAuthor> > myAuthors; + std::vector<shared_ptr<ATOMCategory> > myCategories; + //shared_ptr<ATOMContent> myContent; TODO: implement ATOMContent + std::vector<shared_ptr<ATOMContributor> > myContributors; + std::vector<shared_ptr<ATOMLink> > myLinks; + shared_ptr<ATOMIcon> myIcon; + shared_ptr<ATOMPublished> myPublished; + std::string myRights; // TODO: implement ATOMTextConstruct + //shared_ptr<ATOMSource> mySource; // TODO: implement ATOMSource + std::string mySummary; // TODO: implement ATOMTextConstruct + std::string myTitle; // TODO: implement ATOMTextConstruct + shared_ptr<ATOMUpdated> myUpdated; +}; + + +class ATOMFeedMetadata : public ATOMCommonAttributes { + +public: + ATOMFeedMetadata(); + ATOMFeedMetadata(shared_ptr<ATOMId> id, const std::string &title, shared_ptr<ATOMUpdated> updated); + + std::vector<shared_ptr<ATOMAuthor> > &authors() { return myAuthors; } + std::vector<shared_ptr<ATOMCategory> > &categories() { return myCategories; } + std::vector<shared_ptr<ATOMContributor> > &contributors() { return myContributors; } + std::vector<shared_ptr<ATOMLink> > &links() { return myLinks; } + + shared_ptr<ATOMGenerator> generator() { return myGenerator; } + shared_ptr<ATOMIcon> icon() { return myIcon; } + shared_ptr<ATOMLogo> logo() { return myLogo; } + const std::string &rights() { return myRights; } + const std::string &subtitle() { return mySubtitle; } + const std::string &summary() { return mySummary; } + const std::string &title() { return myTitle; } + shared_ptr<ATOMUpdated> updated() { return myUpdated; } + + void setGenerator(shared_ptr<ATOMGenerator> generator) { myGenerator = generator; } + void setIcon(shared_ptr<ATOMIcon> icon) { myIcon = icon; } + void setLogo(shared_ptr<ATOMLogo> logo) { myLogo = logo; } + void setRights(const std::string &rights) { myRights = rights; } + void setSubtitle(const std::string &subtitle) { mySubtitle = subtitle; } + void setSummary(const std::string &summary) { mySummary = summary; } + void setTitle(const std::string &title) { myTitle = title; } + void setUpdated(shared_ptr<ATOMUpdated> updated) { myUpdated = updated; } + + shared_ptr<ATOMId> id() { return myId; } + void setId(shared_ptr<ATOMId> id) { myId = id; } + +private: + shared_ptr<ATOMId> myId; + + std::vector<shared_ptr<ATOMAuthor> > myAuthors; + std::vector<shared_ptr<ATOMCategory> > myCategories; + std::vector<shared_ptr<ATOMContributor> > myContributors; + shared_ptr<ATOMGenerator> myGenerator; + shared_ptr<ATOMIcon> myIcon; + std::vector<shared_ptr<ATOMLink> > myLinks; + shared_ptr<ATOMLogo> myLogo; + std::string myRights; // TODO: implement ATOMTextConstruct + std::string mySubtitle; // TODO: implement ATOMTextConstruct + std::string mySummary; // TODO: implement ATOMTextConstruct + std::string myTitle; // TODO: implement ATOMTextConstruct + shared_ptr<ATOMUpdated> myUpdated; +}; + + +/* +class ATOMFeed : public ATOMFeedMetadata { + +public: + ATOMFeed(); + ATOMFeed(const ATOMId &id, const std::string &title, shared_ptr<ATOMUpdated> updated); + + std::vector<shared_ptr<ATOMEntry> > entries() { return myEntries; } + +private: + std::vector<shared_ptr<ATOMEntry> > myEntries; +}; +*/ + + +#endif /* __ATOMCONTAINTERS_H__ */ diff --git a/reader/src/network/atom/ATOMMetadata.cpp b/reader/src/network/atom/ATOMMetadata.cpp new file mode 100644 index 0000000..cb81e0e --- /dev/null +++ b/reader/src/network/atom/ATOMMetadata.cpp @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include "ATOMMetadata.h" + + +const std::string ATOMConstants::TYPE_TEXT = "text"; +const std::string ATOMConstants::TYPE_HTML = "html"; +const std::string ATOMConstants::TYPE_XHTML = "xhtml"; + +const std::string ATOMConstants::TYPE_DEFAULT = TYPE_TEXT; + +const std::string ATOMConstants::REL_ALTERNATE = "alternate"; +const std::string ATOMConstants::REL_RELATED = "related"; +const std::string ATOMConstants::REL_SELF = "self"; +const std::string ATOMConstants::REL_ENCLOSURE = "enclosure"; +const std::string ATOMConstants::REL_VIA = "via"; + + + +const std::string ATOMCategory::TERM = "term"; +const std::string ATOMCategory::SCHEME = "scheme"; +const std::string ATOMCategory::LABEL = "label"; + +const std::string ATOMGenerator::URI = "uri"; +const std::string ATOMGenerator::VERSION_ATT = "version"; + +const std::string ATOMLink::HREF = "href"; +const std::string ATOMLink::REL = "rel"; +const std::string ATOMLink::TYPE = "type"; +const std::string ATOMLink::HREFLANG = "hreflang"; +const std::string ATOMLink::TITLE = "title"; +const std::string ATOMLink::LENGTH = "length"; + + + +ATOMAuthor::ATOMAuthor() { +} + +ATOMAuthor::ATOMAuthor(const std::string &name) : ATOMPersonConstruct(name) { +} + + + +ATOMCategory::ATOMCategory() { +} + +ATOMCategory::ATOMCategory(const std::string &termStr) { + term() = termStr; +} + +void ATOMCategory::readAttributes(const std::map<std::string, std::string> &attributes) { + ATOMCommonAttributes::readAttributes(attributes); + readAttribute(TERM, attributes); + readAttribute(SCHEME, attributes); + readAttribute(LABEL, attributes); +} + + + +ATOMContributor::ATOMContributor() { +} + +ATOMContributor::ATOMContributor(const std::string &name) : ATOMPersonConstruct(name) { +} + + + +ATOMGenerator::ATOMGenerator() { +} + +ATOMGenerator::ATOMGenerator(const std::string &text) : myText(text) { +} + +void ATOMGenerator::readAttributes(const std::map<std::string, std::string> &attributes) { + ATOMCommonAttributes::readAttributes(attributes); + readAttribute(URI, attributes); + readAttribute(VERSION_ATT, attributes); +} + + + +ATOMIcon::ATOMIcon() { +} + +ATOMIcon::ATOMIcon(const std::string &uri) : myUri(uri) { +} + + + +ATOMId::ATOMId() { +} + +ATOMId::ATOMId(const std::string &uri) : myUri(uri) { +} + + + +ATOMLink::ATOMLink() { +} + +ATOMLink::ATOMLink(const std::string &hrefStr) { + href() = hrefStr; +} + +ATOMLink::ATOMLink(const std::string &hrefStr, const std::string &relStr) { + href() = hrefStr; + rel() = relStr; +} + +ATOMLink::ATOMLink(const std::string &hrefStr, const std::string &relStr, const std::string &typeStr){ + href() = hrefStr; + rel() = relStr; + type() = typeStr; +} + +ATOMLink::ATOMLink(const std::string &hrefStr, const std::string &relStr, const std::string &typeStr, const std::string &titleStr) { + href() = hrefStr; + rel() = relStr; + type() = typeStr; + title() = titleStr; +} + +void ATOMLink::readAttributes(const std::map<std::string, std::string> &attributes) { + ATOMCommonAttributes::readAttributes(attributes); + readAttribute(HREF, attributes); + readAttribute(REL, attributes); + readAttribute(TYPE, attributes); + readAttribute(HREFLANG, attributes); + readAttribute(TITLE, attributes); + readAttribute(LENGTH, attributes); +} + +ATOMLogo::ATOMLogo() { +} + +ATOMLogo::ATOMLogo(const std::string &uri) : myUri(uri) { +} + + + +ATOMPublished::ATOMPublished() : ATOMDateConstruct(0) { +} + +ATOMPublished::ATOMPublished(int year) : ATOMDateConstruct(year) { +} + +ATOMPublished::ATOMPublished(int year, int month, int day) : ATOMDateConstruct(year, month, day) { +} + +ATOMPublished::ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds) { +} + +ATOMPublished::ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds, float sfract) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds, sfract) { +} + +ATOMPublished::ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds, sfract, tzhour, tzminutes) { +} + + + +ATOMUpdated::ATOMUpdated() : ATOMDateConstruct(0) { +} + +ATOMUpdated::ATOMUpdated(int year) : ATOMDateConstruct(year) { +} + +ATOMUpdated::ATOMUpdated(int year, int month, int day) : ATOMDateConstruct(year, month, day) { +} + +ATOMUpdated::ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds) { +} + +ATOMUpdated::ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds, float sfract) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds, sfract) { +} + +ATOMUpdated::ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes) : + ATOMDateConstruct(year, month, day, hour, minutes, seconds, sfract, tzhour, tzminutes) { +} + + diff --git a/reader/src/network/atom/ATOMMetadata.h b/reader/src/network/atom/ATOMMetadata.h new file mode 100644 index 0000000..3fb7619 --- /dev/null +++ b/reader/src/network/atom/ATOMMetadata.h @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#ifndef __ATOMMETADATA_H__ +#define __ATOMMETADATA_H__ + +#include "ATOMConstructs.h" + + +class ATOMConstants { + +private: + ATOMConstants(); + +public: + static const std::string TYPE_TEXT; + static const std::string TYPE_HTML; + static const std::string TYPE_XHTML; + static const std::string TYPE_DEFAULT; + + static const std::string REL_ALTERNATE; + static const std::string REL_RELATED; + static const std::string REL_SELF; + static const std::string REL_ENCLOSURE; + static const std::string REL_VIA; +}; + + + + + +class ATOMAuthor : public ATOMPersonConstruct { + +public: + ATOMAuthor(); + ATOMAuthor(const std::string &name); +}; + + + +class ATOMCategory : public ATOMCommonAttributes { + +public: + static const std::string TERM; + static const std::string SCHEME; + static const std::string LABEL; + +public: + ATOMCategory(); + ATOMCategory(const std::string &termStr); + +public: + std::string &term() { return attributes()[TERM]; } + std::string &scheme() { return attributes()[SCHEME]; } + std::string &label() { return attributes()[LABEL]; } + + void readAttributes(const std::map<std::string, std::string> &attributes); +}; + + + +class ATOMContributor : public ATOMPersonConstruct { + +public: + ATOMContributor(); + ATOMContributor(const std::string &name); +}; + + + +class ATOMGenerator : public ATOMCommonAttributes { + +public: + static const std::string URI; + static const std::string VERSION_ATT; + +public: + ATOMGenerator(); + ATOMGenerator(const std::string &text); + +public: + const std::string &text() const { return myText; } + void setText(const std::string &text) { myText = text; } + + std::string &uri() { return attributes()[URI]; } + std::string &version() { return attributes()[VERSION_ATT]; } + + void readAttributes(const std::map<std::string, std::string> &attributes); + +private: + std::string myText; +}; + + + +class ATOMIcon : public ATOMCommonAttributes { + +public: + ATOMIcon(); + ATOMIcon(const std::string &uri); + +public: + const std::string &uri() const { return myUri; } + void setUri(const std::string &uri) { myUri = uri; } + +private: + std::string myUri; +}; + + + +class ATOMId : public ATOMCommonAttributes { + +public: + ATOMId(); + ATOMId(const std::string &uri); + + const ATOMId &operator = (const ATOMId &id); + + bool operator == (const ATOMId &id) const; + bool operator != (const ATOMId &id) const; + +public: + const std::string &uri() const { return myUri; } + void setUri(const std::string &uri) { myUri = uri; } + +private: + std::string myUri; +}; + +inline const ATOMId &ATOMId::operator = (const ATOMId &id) { myUri = id.myUri; return *this; } +inline bool ATOMId::operator == (const ATOMId &id) const { return myUri == id.myUri; } +inline bool ATOMId::operator != (const ATOMId &id) const { return myUri != id.myUri; } + + + +class ATOMLink : public ATOMCommonAttributes { + +public: + static const std::string HREF; + static const std::string REL; + static const std::string TYPE; + static const std::string HREFLANG; + static const std::string TITLE; + static const std::string LENGTH; + +public: + ATOMLink(); + ATOMLink(const std::string &hrefStr); + ATOMLink(const std::string &hrefStr, const std::string &relStr); + ATOMLink(const std::string &hrefStr, const std::string &relStr, const std::string &typeStr); + ATOMLink(const std::string &hrefStr, const std::string &relStr, const std::string &typeStr, const std::string &titleStr); + +public: + std::string &href() { return attributes()[HREF]; } + std::string &rel() { return attributes()[REL]; } + std::string &type() { return attributes()[TYPE]; } + std::string &hreflang() { return attributes()[HREFLANG]; } + std::string &title() { return attributes()[TITLE]; } + std::string &length() { return attributes()[LENGTH]; } + + void readAttributes(const std::map<std::string, std::string> &attributes); +}; + + + +class ATOMLogo : public ATOMCommonAttributes { + +public: + ATOMLogo(); + ATOMLogo(const std::string &uri); + +public: + const std::string &uri() const { return myUri; } + void setUri(const std::string &uri) { myUri = uri; } + +private: + std::string myUri; +}; + + +class ATOMPublished : public ATOMDateConstruct { + +public: + ATOMPublished(); + ATOMPublished(int year); + ATOMPublished(int year, int month, int day); + ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds); + ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds, float sfract); + ATOMPublished(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes); +}; + +class ATOMUpdated : public ATOMDateConstruct { + +public: + ATOMUpdated(); + ATOMUpdated(int year); + ATOMUpdated(int year, int month, int day); + ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds); + ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds, float sfract); + ATOMUpdated(int year, int month, int day, int hour, int minutes, int seconds, float sfract, int tzhour, int tzminutes); +}; + + +#endif /* ATOMMETADATA */ |
