FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
poco/JSON/src/TemplateCache.cpp at develop · cppfool/poco · GitHub
cppfool
/
poco
Public
forked from
pocoproject/poco
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
poco
/
JSON
/
src
/
TemplateCache.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
155 lines (128 loc) · 2.82 KB
Breadcrumbs
poco
/
JSON
/
src
/
TemplateCache.cpp
Copy path
File metadata and controls
155 lines (128 loc) · 2.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
//
TemplateCache.cpp
//
//
$Id$
//
//
Library: JSON
//
Package: JSON
//
Module: TemplateCache
//
//
Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
//
and Contributors.
//
//
SPDX-License-Identifier: BSL-1.0
//
#
include
"
Poco/File.h
"
#
include
"
Poco/JSON/TemplateCache.h
"
namespace
Poco
{
namespace
JSON
{
TemplateCache* TemplateCache::_instance =
NULL
;
TemplateCache::TemplateCache
() : _logger(
NULL
)
{
setup
();
}
TemplateCache::~TemplateCache
()
{
_instance =
NULL
;
}
void
TemplateCache::setup
()
{
poco_assert
(_instance ==
NULL
);
_instance =
this
;
}
Template::Ptr
TemplateCache::getTemplate
(
const
Path& path)
{
if
( _logger )
{
poco_trace_f1
(*_logger,
"
Trying to load %s
"
, path.
toString
());
}
Path templatePath =
resolvePath
(path);
std::string templatePathname = templatePath.
toString
();
if
( _logger )
{
poco_trace_f1
(*_logger,
"
Path resolved to %s
"
, templatePathname);
}
File
templateFile
(templatePathname);
Template::Ptr tpl;
std::map<std::string, Template::Ptr>::iterator it = _cache.
find
(templatePathname);
if
( it == _cache.
end
() )
{
if
( templateFile.
exists
() )
{
if
( _logger )
{
poco_information_f1
(*_logger,
"
Loading template %s
"
, templatePath.
toString
());
}
tpl =
new
Template
(templatePath);
try
{
tpl->
parse
();
_cache[templatePathname] = tpl;
}
catch
(JSONTemplateException& jte)
{
if
( _logger )
{
poco_error_f2
(*_logger,
"
Template %s contains an error: %s
"
, templatePath.
toString
(), jte.
message
());
}
}
}
else
{
if
( _logger )
{
poco_error_f1
(*_logger,
"
Template file %s doesn't exist
"
, templatePath.
toString
());
}
throw
FileNotFoundException
(templatePathname);
}
}
else
{
tpl = it->
second
;
if
( tpl->
parseTime
() < templateFile.
getLastModified
() )
{
if
( _logger )
{
poco_information_f1
(*_logger,
"
Reloading template %s
"
, templatePath.
toString
());
}
tpl =
new
Template
(templatePath);
try
{
tpl->
parse
();
_cache[templatePathname] = tpl;
}
catch
(JSONTemplateException& jte)
{
if
( _logger )
{
poco_error_f2
(*_logger,
"
Template %s contains an error: %s
"
, templatePath.
toString
(), jte.
message
());
}
}
}
}
return
tpl;
}
Path
TemplateCache::resolvePath
(
const
Path& path)
const
{
if
( path.
isAbsolute
() )
return
path;
for
(std::vector<Path>::const_iterator it = _includePaths.
begin
(); it != _includePaths.
end
(); ++it)
{
Path
templatePath
(*it, path);
File
templateFile
(templatePath);
if
( templateFile.
exists
() )
{
if
( _logger )
{
poco_trace_f2
(*_logger,
"
%s template file resolved to %s
"
, path.
toString
(), templatePath.
toString
());
}
return
templatePath;
}
if
( _logger )
{
poco_trace_f1
(*_logger,
"
%s doesn't exist
"
, templatePath.
toString
());
}
}
throw
FileNotFoundException
(path.
toString
());
}
} }
//
Poco::JSON
Back
|
FazBrowse Home
|
New Git URL