Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
HtmlFile.cxx
1/*
2 * HalHtmlFile.cxx
3 *
4 * Created on: 8 paź 2020
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "HtmlFile.h"
10
11#include <TRegexp.h>
12#include <TString.h>
13#include <TSystem.h>
14#include <fstream>
15
16#include "Std.h"
17#include "StdString.h"
18namespace Hal {
19 HtmlFile::~HtmlFile() {}
20
21 HtmlFile::HtmlFile(TString path, Bool_t mainFile) : fPath(path), fBody(""), fSaved(kFALSE), fMainFile(mainFile) {
22 HtmlCore* core = HtmlCore::Instance(); // to prevent overwriting instance
23 core->FixAddress(fPath);
24 Int_t last = fPath.Last('/');
25 if (last > 0) {
26 fDir = fPath(0, last);
27 if (fMainFile) HtmlCore::SetMainDir(fDir);
28 fRelativePath = HtmlCore::GetRelativePath(fDir);
29 } else {
30 fDir = "";
31 if (fMainFile) HtmlCore::SetMainDir(fDir);
32 fRelativePath = "";
33 }
34 }
35
36 void HtmlFile::Save() {
37 if (fSaved) return;
38 // Core::Instance();
39 if (fMainFile) {
41 HtmlCore::CopyJs(fDir);
42 }
43 std::ofstream file;
44 file.open(fPath);
45 file << " <meta charset=\"UTF-8\"> \n";
46 file << "<html>\n";
47 file << "<head>\n";
48 file << "<link rel=\"stylesheet\" href=\"" << fRelativePath << "table.css\" type=\"text/css\"/>\n";
49 if (HtmlCore::IsOnline()) {
50 file << "<script src=\"http://jsroot.gsi.de/latest/scripts/JSRoot.core.js\" "
51 "type=\"text/javascript\"></script>\n";
52 } else {
53 if (Hal::Std::GetJsRootVer() == 5) {
54 file << "<script src=\"" << fRelativePath
55 << "hal_js/scripts/JSRootCore.js\" "
56 "type=\"text/javascript\"></script>\n";
57 } else {
58 file << "<script src=\"" << fRelativePath
59 << "hal_js/scripts/JSRoot.core.js\" "
60 "type=\"text/javascript\"></script>\n";
61 }
62 }
63 file << "<script src=\"" << fRelativePath << "hal_js.js\" type=\"text/javascript\"></script>\n";
64 file << "</head>\n";
65 file << "<body>\n";
66
67 file << fBody;
68
69 file << "</body></html>" << std::endl;
70 file.close();
71 fSaved = kTRUE;
72 }
73} // namespace Hal
static TString GetRelativePath(TString path)
Definition HtmlCore.cxx:184
static void CopyCss(TString dir, TString css_name="table.css")
Definition HtmlCore.cxx:33
static void SetMainDir(TString name)
Definition HtmlCore.cxx:89
static void FixAddress(TString &address)
Definition HtmlCore.cxx:101
static Bool_t IsOnline()
Definition HtmlCore.h:108
static void CopyJs(TString dir)
Definition HtmlCore.cxx:41
static HtmlCore * Instance()
Definition HtmlCore.cxx:81
HtmlFile(TString filename="", Bool_t mainFile=kFALSE)
Definition HtmlFile.cxx:21