source: branches/work_304/output/WebPage.cpp @ 432

Revision 432, 7.6 KB checked in by jls17, 6 years ago (diff)
  • removed global reference to jquery.address.js; it is already referenced on a per page basis
Line 
1//Copyright (C) 2009 Stefan Nerlich | stefan.nerlich@hotmail.com
2//
3//This file is part of ARInside.
4//
5//    ARInside is free software: you can redistribute it and/or modify
6//    it under the terms of the GNU General Public License as published by
7//    the Free Software Foundation, version 2 of the License.
8//
9//    ARInside is distributed in the hope that it will be useful,
10//    but WITHOUT ANY WARRANTY; without even the implied warranty of
11//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12//    GNU General Public License for more details.
13//
14//    You should have received a copy of the GNU General Public License
15//    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
16
17#include "stdafx.h"
18#include "WebPage.h"
19#include "WebUtil.h"
20#include "../ARInside.h"
21#include "../gzstream.h"
22#include "webpage/HtmlReferenceListImpl.h"
23
24using namespace OUTPUT;
25using namespace OUTPUT::WebPage;
26
27extern int nFilesCreated;
28
29// TODO: replace fileName parameter with CPageParams obj and use IFileStructure internal to get fileName, folder and dirLevel
30CWebPage::CWebPage(const string &fileName, const string &title, int dirLevel, const AppConfig &appConfig)
31: appConfig(appConfig)
32{
33        this->fileName = fileName;     
34        this->title = title;
35        this->rootLevel = dirLevel;
36        this->htmlReferences = NULL;
37}
38
39CWebPage::~CWebPage(void)
40{
41        if (htmlReferences != NULL)
42                delete htmlReferences;
43}
44
45void CWebPage::SetNavigation(const string &nav)
46{
47        navContent = nav;
48}
49
50void CWebPage::AddContent(const string &content)
51{
52        this->bodyContent.push_back(content);
53}
54
55void CWebPage::AddContentHead(const string &description, const string &rightInfo)
56{
57        AddContent("<div id='locLeft'>");
58        AddContent(description);
59        AddContent("</div><div id='locRight'>");
60        AddContent(( !rightInfo.empty() ? rightInfo : "&nbsp;"));
61        AddContent("</div>");
62}
63
64void CWebPage::PageHeader(ostream &strm)
65{
66        strm << "<?xml version=\"1.0\" ?>" << endl;
67        strm << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" << endl;
68        strm << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" << endl;
69        strm << "<!-- saved from url=(0025)http://arinside.org/ -->" << endl;
70        strm << "<head>" << endl;
71        strm << "<title>" << title << "</title>" << endl;
72        strm << "<meta http-equiv=\"content-language\" content=\"EN\" />" << endl;
73        strm << "<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />" << endl;
74        strm << "<meta http-equiv=\"expires\" content=\"-1\" />" << endl;
75        strm << "<meta name=\"author\" content=\"ARInside\" />" << endl;
76        strm << GetReferenceManager() << endl;
77        strm << "</head>" << endl;
78}
79
80void CWebPage::DynamicHeaderText(ostream &strm)
81{
82        strm << "<table>" << endl;
83        strm << "<tr>" << endl;
84        strm << "<td>" << CWebUtil::Link("Main", CWebUtil::RootPath(rootLevel)+ CWebUtil::DocName("index"), "server.gif", rootLevel) << "</td>" << endl;
85        strm << "<td>" << " (Server: " << CWebUtil::Link(appConfig.serverName, CPageParams(PAGE_SERVER_INFO), "", rootLevel) << "</td>" << endl;
86        strm << "<td>" << "@" << "</td>" << endl;
87        strm << "<td>" << "<a href=\"" << appConfig.companyUrl << "\" target=\"_blank\">" << appConfig.companyName << "</a>" << ")" << "</td>" << endl;
88        strm << "</tr>" << endl;
89        strm << "</table>" << endl;     
90}
91
92string CWebPage::CurrentDateTime()
93{
94        return CUtil::CurrentDateTimeToHTMLString();
95}
96
97void CWebPage::DynamicFooterText(ostream &strm)
98{
99        strm << "<table><tr>" << endl;
100        strm << "<td>" << CWebUtil::Link("Main", CWebUtil::RootPath(rootLevel) + CWebUtil::DocName("index"), "next.gif", rootLevel)<< "</td>" << endl;
101        strm << "<td>&nbsp;</td>" << endl;
102        strm << "<td>" << CWebUtil::Link("Top", "#top", "up.gif", rootLevel)<< "</td>" << endl;
103        strm << "<td>&nbsp;</td>" << endl;
104#if ARINSIDE_TEST_SUPPORT
105        if (appConfig.testMode)
106                strm << "<td>&nbsp;</td>";
107        else
108#endif
109                strm << "<td>(Page created " << CurrentDateTime() << " by <a href=\"http://arinside.org\" target=\"_blank\">ARInside v" << AppVersion <<"</a>)</td>";
110        strm << "</tr></table>" << endl;
111}
112
113void CWebPage::ContentOpen(ostream &strm)
114{
115        strm << "<body>" << endl;
116        strm << "<a name=\"top\"></a>" << endl;
117        strm << "<table class=\"TblMain\">" << endl;
118        strm << "<tr><td class=\"TdMainHeader\" colspan=\"3\">" << endl;
119        DynamicHeaderText(strm);
120        strm << "</td></tr><tr><td class=\"TdMainMenu\">" << endl;
121        if (!navContent.empty())
122        {
123                strm << "<div id=\"form_navigation\" class=\"form_navigation\">" << endl;
124                strm << navContent << endl;
125                strm << "</div>" << endl;
126        }
127        strm << "<iframe id=\"IFrameMenu\" src=\"" << CWebUtil::RootPath(rootLevel) << "template/navigation." << CWebUtil::WebPageSuffix() << "\" name=\"Navigation\" frameborder=\"0\">" << endl;
128        strm << "<p>IFrame not supported by this browser.</p></iframe></td><td class=\"TdMainContent\">" << endl;
129}
130
131void CWebPage::ContentClose(ostream &strm)
132{
133        strm << "</td>" << endl;
134        strm << "<td></td>" << endl;    // TODO: this column isn't used at all. Remove it completely from the table.
135
136        strm << "</tr><tr><td class=\"TdMainButtom\" colspan=\"3\">" << endl;
137        DynamicFooterText(strm);
138        strm << endl << "</td></tr></table></body></html>" << endl;
139}
140
141
142
143void CWebPage::WriteContent(ostream &strm)
144{       
145        PageHeader(strm);
146        ContentOpen(strm);
147       
148        vector<string>::iterator curIt = bodyContent.begin();
149        vector<string>::iterator endIt = bodyContent.end();
150        for (; curIt != endIt; ++curIt) strm << *curIt;
151
152        ContentClose(strm);
153}
154
155
156int CWebPage::SaveInFolder(const string &path)
157{
158        int result = 0;
159
160        stringstream strm;
161        if(!path.empty())
162                strm << this->appConfig.targetFolder << "/" << path << "/" << CWebUtil::DocName(this->fileName);
163        else
164                strm << this->appConfig.targetFolder << "/" << CWebUtil::DocName(this->fileName);
165
166        try
167        {
168                string fileName = strm.str();
169                LOG << "Save file '" << fileName;
170
171                ostream *outStream;
172#ifdef ARINSIDE_ENABLE_ZLIB_SUPPORT
173                if (CARInside::GetInstance()->appConfig.bGZCompression)
174                        outStream = new ogzstream(fileName.c_str(), ios::out);
175                else
176#endif
177                        outStream = new ofstream(fileName.c_str(), ios::out);
178
179                ostream &fout = *outStream;
180
181                WriteContent(fout);
182
183                fout.flush();
184                delete outStream;
185
186                LOG << "' [OK]" << endl;
187
188                nFilesCreated++;
189                result = 1;
190        }
191        catch(exception& e)
192        {               
193                stringstream erStrm;
194                erStrm << "Error saving file '" << strm.str() << "' to disk. Error: " << e.what();
195                throw(AppException(erStrm.str(), "undefined", "FileIo"));
196        }
197
198        return result;
199}
200
201void CWebPage::AddScriptReference(std::ostream &strm, const std::string &scriptPath)
202{
203        strm << "<script src=\"" << CWebUtil::RootPath(rootLevel) << scriptPath << "\" type=\"text/javascript\"></script>" << endl;
204}
205
206void CWebPage::AddStyleSheetReference(std::ostream &strm, const std::string &cssPath)
207{
208        strm << "<link rel=\"stylesheet\" type=\"text/css\" href=\"" << CWebUtil::RootPath(rootLevel) << cssPath << "\" />" << endl;
209}
210
211HtmlReferenceList& CWebPage::GetReferenceManager()
212{
213        if (htmlReferences == NULL)
214        {
215                htmlReferences = new HtmlReferenceListImpl(rootLevel);
216                SetupDefaultReferences(*htmlReferences);
217        }
218        return *htmlReferences;
219}
220
221void CWebPage::SetupDefaultReferences(WebPage::HtmlReferenceList &inst)
222{
223        inst.AddStyleSheetReference("img/style.css");
224        inst.AddStyleSheetReference("img/jquery-ui-custom.css");
225        inst.AddScriptReference("img/sortscript.js");
226        inst.AddScriptReference("img/tabscript.js");
227        inst.AddScriptReference("img/jquery.js");
228        inst.AddScriptReference("img/jquery-ui.js");
229        inst.AddScriptReference("img/arshelper.js");
230}
Note: See TracBrowser for help on using the repository browser.