#include <string>
#include <cstdio>
#include <cerrno>
+#include <climits>
+#include <cmath>
+#include <cstdlib>
using namespace WrtDB;
m_properNamespace(false)
{}
+ static const char* const REGEXP_ID;
+
private:
void VerifyIdAndPackage()
{
}
static const char* const REGEXP_PACKAGE;
- static const char* const REGEXP_ID;
static const char* const REGEXP_VERSION;
ConfigParserData& m_data;
virtual void Verify()
{
+ if (m_label.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "box-label element cannot be empty - ignoring");
+ }
m_data.m_label = m_label;
}
virtual void Verify()
{
+ if (m_icon.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "src attribute of box-icon element is mandatory - ignoring");
+ }
m_data.m_icon = m_icon;
}
virtual void Verify()
{
+ if(m_size.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "size is mandatory - ignoring");
+ }
+
std::pair<DPL::String, DPL::String> boxSize;
boxSize.first = m_size;
boxSize.second = m_preview;
m_width = attribute.value;
} else if (attribute.name == L"height") {
m_height = attribute.value;
- } else if (attribute.name == L"fast-open") {
- m_fastOpen= attribute.value;
}
}
}
virtual void Verify()
{
+ if (m_src.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "src attribute of pd element is mandatory - ignoring");
+ }
+
+ if (m_width.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "width attribute of pd element is mandatory - ignoring");
+ }
+
+ if (m_height.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "height attribute of pd element is mandatory - ignoring");
+ }
+
+ if (ConvertToInt(m_width).IsNull()) {
+ ThrowMsg(Exception::ParseError,
+ "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
+ }
+
+
+ DPL::OptionalInt height = ConvertToInt(m_height);
+
+ if (height.IsNull()) {
+ ThrowMsg(Exception::ParseError,
+ "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
+ }
+
+ if (*height < 1) {
+ m_height = L"1";
+ LogDebug("height attribute of pd element shouldn't be less than 1. Changed to 1 from " << *height);
+ } else if (*height > 380){
+ m_height = L"380";
+ LogDebug("height attribute of pd element shouldn't be greater than 380. Changed to 380 from " << *height);
+ }
+
m_data.m_pdSrc = m_src;
m_data.m_pdWidth = m_width;
m_data.m_pdHeight = m_height;
- m_data.m_pdFastOpen = m_fastOpen;
}
explicit PdParser(
{}
private:
+ DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
+ {
+ char * endptr;
+ std::string tempStr = DPL::ToUTF8String(intAsString);
+ const char * intAsString_c = tempStr.c_str();
+ errno = 0;
+ long int intAsString_i = strtol(intAsString_c, &endptr, 10);
+
+ if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
+ || intAsString_i > INT_MAX || intAsString_i < INT_MIN
+ || *endptr != '\0') {
+ return DPL::OptionalInt::Null;
+ }
+
+ return static_cast<int>(intAsString_i);
+ }
+
DPL::String m_src;
DPL::String m_width;
DPL::String m_height;
- DPL::String m_fastOpen;
bool m_properNamespace;
ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
virtual void Verify()
{
+ if (m_box.m_boxSrc.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "src attribute of box-content element is mandatory - ignoring");
+ }
+
+ if (!m_box.m_boxMouseEvent.empty() &&
+ CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent))
+ {
+ ThrowMsg(Exception::ParseError,
+ "mouse-event attribute of box-content element should be true or false - ignoring");
+ }
+
+ if (!m_box.m_boxTouchEffect.empty() &&
+ CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect))
+ {
+ ThrowMsg(Exception::ParseError,
+ "touch-effect attribute of box-content element should be true or false - ignoring");
+ }
+
+ if (m_box.m_boxMouseEvent.empty()) {
+ m_box.m_boxMouseEvent = L"false";
+ }
+
+ if (m_box.m_boxTouchEffect.empty()) {
+ m_box.m_boxTouchEffect = L"true";
+ }
+
+ if (m_box.m_boxSize.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "box-size element of box-content element not found - ignoring");
+ }
+
m_data.m_boxInfo = m_box;
}
}
private:
- DPL::String m_src;
bool m_properNamespace;
ConfigParserData::LiveboxInfo& m_data;
ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
m_autoLaunch = attribute.value;
} else if (attribute.name == L"update-period") {
m_updatePeriod = attribute.value;
- } else if (attribute.name == L"type") {
- m_type = attribute.value;
}
}
}
virtual void Verify()
{
+ if (m_liveboxId.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "app-widget element must have id attribute");
+ }
+ else
+ {
+ pcrecpp::RE re(REGEXP_ID_STRING.c_str());
+ if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
+ {
+ ThrowMsg(Exception::ParseError,
+ "invalid format of app-widget id attribute");
+ }
+ }
+
+ if (m_primary.empty())
+ {
+ ThrowMsg(Exception::ParseError,
+ "app-widget element must have primary attribute");
+ } else if (CheckIfNotTrueNorFalse(m_primary))
+ {
+ ThrowMsg(Exception::ParseError,
+ "auto-launch attribute of app-widget element should be true or false - ignoring");
+ }
+
+ if (!m_autoLaunch.empty() &&
+ CheckIfNotTrueNorFalse(m_autoLaunch))
+ {
+ ThrowMsg(Exception::ParseError,
+ "auto-launch attribute of app-widget element should be true or false - ignoring");
+ }
+
+ if (!m_updatePeriod.empty())
+ {
+ char * endptr;
+ std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
+ const char * up_cstr = tempStr.c_str();
+
+ errno = 0;
+ double update_period = strtod(up_cstr, &endptr);
+
+ if ((errno == ERANGE && (update_period == -HUGE_VAL || update_period == HUGE_VAL))
+ || *endptr != '\0') {
+ ThrowMsg(Exception::ParseError,
+ "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
+ } else if (update_period < 60.0) {
+ LogDebug("update-period attribute of app-widget element shouldn't be less than 60.0 - changed to 60 from value: " << m_updatePeriod);
+ m_updatePeriod = L"60.0";
+ }
+ }
+
+ if (m_autoLaunch.empty()) {
+ m_autoLaunch = L"false";
+ }
+
+ if(m_livebox.m_label.empty()) {
+ ThrowMsg(Exception::ParseError,
+ "box-label element of app-widget element not found - ignoring");
+ }
+
+ if(!m_boxContentFound) {
+ ThrowMsg(Exception::ParseError,
+ "box-content element of app-widget element not found - ignoring");
+ }
+
m_livebox.m_liveboxId = m_liveboxId;
m_livebox.m_primary = m_primary;
m_livebox.m_autoLaunch = m_autoLaunch;
m_livebox.m_updatePeriod = m_updatePeriod;
- m_livebox.m_type = m_type;
m_data.m_livebox.push_back(m_livebox);
}
explicit AppWidgetParser(ConfigParserData& data) :
ElementParser(),
m_data(data),
- m_properNamespace(false)
+ m_properNamespace(false),
+ m_boxContentFound(false)
{
m_livebox = ConfigParserData::LiveboxInfo();
}
ElementParserPtr OnBoxLabelElement()
{
+
return ElementParserPtr(new BoxLabelParser(m_livebox));
}
ElementParserPtr OnBoxContentElement()
{
+ m_boxContentFound = true;
return ElementParserPtr(new BoxContentParser(m_livebox));
}
private:
+ static std::string REGEXP_ID_STRING;
ConfigParserData& m_data;
ConfigParserData::LiveboxInfo m_livebox;
DPL::String m_liveboxId;
DPL::String m_primary;
DPL::String m_autoLaunch;
DPL::String m_updatePeriod;
- DPL::String m_type;
bool m_properNamespace;
+ bool m_boxContentFound;
+
+ static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
+ {
+ return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
+ }
};
+std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
+
class AllowNavigationParser : public ElementParser
{
public: