1 // Copyright (c) 2012 Dennco Project
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Created by tkawata on Sep-30, 2012.
19 #include "dccontent.h"
21 #include "dccontainer.h"
22 #include "DNContainerBuilder.h"
25 #include "DNXMLElement.h"
27 #include "dccontainersaver.h"
33 DCContent::DCContent(DCCreator *creator, std::string contentPath) :
34 d_creator(creator), d_valid(false), d_container(0)
36 d_container = (DCContainer*) TKContainer::createContainer();
37 d_container->setContent(this);
39 dnGlobal()->updateRunningStatus(DNGlobal::STOPPED);
40 dnGlobal()->resetErrorStatus();
42 std::string containerRoot = contentPath;
43 containerRoot.append("/Container");
45 bool succeeded = false;
46 succeeded = parseSettingFile(contentPath.c_str());
47 if (!succeeded || !dnGlobal()->isErrorStatusNormal())
49 dnNotifyError("property.xml parse error", "failed to parse setting file /property.xml");
53 std::string dataStorePath = containerRoot;
54 dataStorePath.append("/data.db");
56 succeeded = d_container->setDataStore(dataStorePath.c_str());
59 dnNotifyError("Initialization failed","Failed to the setup data store");
63 succeeded = parseContainerFile(containerRoot.c_str());
66 dnNotifyError("Initialization failed", "Failed to parse container file");
73 DCContent::~DCContent()
83 bool DCContent::parseSettingFile(const char *contentRoot)
87 DNXML *xml = DNXML::createXMLFromFile(contentRoot, "property.xml");
91 DNXMLElement *element = xml->getRoot();
95 std::string message = "Failed to load property.xml file";
96 dnNotifyError("Initialization failed",message);
99 if (valid && element->name != "dennco")
102 std::string message = "First element of property.xml should be <dennco>";
103 dnNotifyError("Initialization failed",message);
108 DNXMLElement *e = element->inner;
111 std::string pname = upperString(e->name);
113 if (pname == "TICKINTERVALSEC")
115 std::istringstream is(e->text);
125 std::string message = "Error in property.xml. TickIntervalSec is not configured properly.";
126 dnNotifyError("Initialization failed",message);
129 else if (pname == "UIPATH")
133 else if (pname == "ENABLEHTTPSERVER")
137 else if (pname == "ENABLESERIALSERVER")
139 if ( upperString(e->text) == "YES")
148 else if (pname == "SERIALSPEED")
161 bool DCContent::parseContainerFile(const char *containerRoot)
163 DNContainerBuilder builder(d_container);
164 d_container->beganBuildContainer();
165 bool r = builder.buildContainerFromXHTML(containerRoot);
166 d_container->endedBuildContainer();
171 bool DCContent::saveAll(const QString& containerRoot)
173 DCContainerSaver saver(d_container);
174 return saver.saveAll(containerRoot);