DCL 3.7.4
Loading...
Searching...
No Matches
TextTemplate Class Reference

#include <TextTemplate.h>

Inheritance diagram for TextTemplate:
Object HtmlView ClassListView DataSourceDetailView DataSourceListView DialogWrapper ErrorView FormView GroupDetailView GroupListView HeadView MenuView MessageView PageDetailView PageListView PermDeniedView UserActivityView UserDetailView UserListView ZipCodeListView

Protected Member Functions

virtual String onSQLFieldValue (_CONST SQLField &_field, const String &_fieldIsNullValue)
void parseHelper (const char_t *_begin, const char_t *_end)
void parse (const char_t *_begin, const char_t *_end)
int append (const char_t *_name, const String &_value, bool _clearExists)
int append (const char_t *_name, const TextTemplate &_template, bool _clearExists)
int append (const StringStringArray &_nameToValues, bool _clearExists)
int append (_CONST SQLFields &_fields, const String &_fieldIsNullValue, bool _clearExists)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

void * __textList
void * __subTemplateMap

Additional Inherited Members

Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Detailed Description

Definition at line 21 of file TextTemplate.h.

Member Function Documentation

◆ append() [1/4]

int TextTemplate::append ( _CONST SQLFields & _fields,
const String & _fieldIsNullValue,
bool _clearExists )
protected

Definition at line 260 of file TextTemplate.cpp.

262{
263 int nCount = 0;
264 for(size_t i = 0; i < _fields.count(); i++) {
265 _CONST SQLField& field = _fields[i];
266 nCount += append(
267 field.name(),
268 onSQLFieldValue(field, _fieldIsNullValue),
269 _clearExists
270 );
271 }
272 return nCount;
273}
#define _CONST
Definition Config.h:325
virtual String onSQLFieldValue(_CONST SQLField &_field, const String &_fieldIsNullValue)

◆ append() [2/4]

int TextTemplate::append ( const char_t * _name,
const String & _value,
bool _clearExists )
protected

Definition at line 175 of file TextTemplate.cpp.

179{
180 int nCount = 0;
181 TextList::Iterator it = TEXT_LIST()->begin();
182 if (_name != NULL) {
183 for( ; it != TEXT_LIST()->end(); it++) {
184 if ((*it).name == _name) {
185 if (_clearExists && !(*it).values.isEmpty())
186 (*it).values.clear();
187
188 (*it).values.addTail(_value);
189 nCount++;
190 }
191 }
192 }
193 else {
194 for(; it != TEXT_LIST()->end(); it++) {
195 if (!(*it).name.isEmpty()) {
196 if (_clearExists && !(*it).values.isEmpty())
197 (*it).values.clear();
198
199 (*it).values.addTail(_value);
200 nCount++;
201 }
202 }
203 }
204 return nCount;
205}
#define NULL
Definition Config.h:312
#define TEXT_LIST()

◆ append() [3/4]

int TextTemplate::append ( const char_t * _name,
const TextTemplate & _template,
bool _clearExists )
protected

Definition at line 207 of file TextTemplate.cpp.

211{
212 __DCL_ASSERT(_name != NULL);
213 __DCL_ASSERT(&_template != this);
214
215 int nCount = 0;
216
217 for(TextList::Iterator it = TEXT_LIST()->begin();
218 it != TEXT_LIST()->end(); it++
219 ) {
220 if ((*it).name == _name) {
221 if (_clearExists && !(*it).values.isEmpty())
222 (*it).values.clear();
223
224 for(TextList::ConstIterator itSrc =
225 ((const TextList*)_template.__textList)->begin();
226 itSrc != ((const TextList*)_template.__textList)->end(); itSrc++
227 ) {
228 if (!(*itSrc).values.isEmpty()) {
229 (*it).values.insert(
230 (*it).values.end(),
231 (*itSrc).values.begin(),
232 (*itSrc).values.end()
233 );
234 }
235#ifdef __DCL_DEBUG
236 else {
237 __DCL_ASSERT(!((*itSrc).name.isEmpty()));
238 if (_template.__showEmptyName) {
239 String name = L'$' + (*itSrc).name;
240 (*it).values.addTail(name);
241 }
242 }
243#endif
244 }
245 nCount++;
246 }
247 }
248 return nCount;
249}
#define __DCL_ASSERT(expr)
Definition Object.h:394
List< TextNode > TextList
void * __textList

◆ append() [4/4]

int TextTemplate::append ( const StringStringArray & _nameToValues,
bool _clearExists )
protected

Definition at line 251 of file TextTemplate.cpp.

253{
254 int nCount = 0;
255 for(size_t i = 0; i < _nameToValues.size(); i++)
256 nCount += append(_nameToValues[i].key, _nameToValues[i].value, _clearExists);
257 return nCount;
258}

◆ onSQLFieldValue()

String TextTemplate::onSQLFieldValue ( _CONST SQLField & _field,
const String & _fieldIsNullValue )
protectedvirtual

Definition at line 275 of file TextTemplate.cpp.

277{
278 if (_field.isNull() || _field.dataSize() == 0)
279 return _fieldIsNullValue;
280
281 return _field.asString();
282}

◆ parse()

void TextTemplate::parse ( const char_t * _begin,
const char_t * _end )
protected

Definition at line 409 of file TextTemplate.cpp.

410{
411 try
412 {
413 Regex reBegin(
414 __T("<!--[\t\v\f ]*\\$[a-zA-Z0-9_]+[\t\v\f ]*-->[\t\v\f \r\n]*")
415 );
416
417 Regex::MatchResults matchBegin;
418 while (_begin < _end && reBegin.search(_begin, _end, matchBegin)) {
419 __DCL_ASSERT(matchBegin.size() > 0 && matchBegin[0].matched);
420
421 // sub 템플릿의 시작을 찾았다.
422 String _name = __getName(matchBegin[0].first, matchBegin[0].second);
423 String strEndPattern =
424 __T("<!--[\t\v\f ]*/[\t\v\f ]*\\$")
425 + _name
426 + __T("[\t\v\f ]*-->[\t\v\f \r\n]*");
427
428 Regex reEnd(strEndPattern);
429 Regex::MatchResults matchEnd;
430// __DCL_TRACE1(L"%lc\n", *(psz + matchBegin.rm_eo));
431 if (reEnd.search(matchBegin[0].second, _end, matchEnd)) {
432 // sub 블록 이전에 대하여 템플릿을 구성한다.
433 if (_begin < matchBegin[0].first) {
434 parseHelper(_begin, matchBegin[0].first);
435 }
436
437 // _name 템플릿을 구성한다.
438 // sub 템플릿에 같은 이름을 사용하는 템플릿이 있으면
439 // 기존의 템플릿의 내용을 삭제한다.
440#ifdef __DCL_DEBUG
441 SubTemplateMap::Iterator itMap = SUB_TEMPLATE_MAP()->find(_name);
442 if (itMap != SUB_TEMPLATE_MAP()->end()) {
444 __T("Warning - exists %ls ==> replaced\n"),
445 _name.data()
446 );
447 }
448#endif
449 SUB_TEMPLATE_MAP()->erase(_name);
450
451 TextNode node;
452 node.name = _name;
453 TEXT_LIST()->addTail(node);
454
455 TextTemplate& sub = (*SUB_TEMPLATE_MAP())[_name];
456// __DCL_TRACE2("%ls: %d\n", _name.data(), matchEnd.rm_so);
457 if (matchBegin[0].second < matchEnd[0].first) {
458 sub.parse(matchBegin[0].second, matchEnd[0].first);
459 }
460
461 _begin = matchEnd[0].second;
462// __DCL_TRACE1(L"%ls\n", psz);
463 }
464 else {
465 _begin = matchBegin[0].second;
466 }
467 }
468
469 if (_begin < _end) {
470 // 남은 데이터가 있다
471 parseHelper(_begin, _end);
472 }
473 }
474 catch(RegexException* e) {
475 __DCL_TRACE1(__T("%ls\n"), e->toString().data());
476 e->destroy();
477 __DCL_ASSERT(false);
478 }
479}
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define __T(str)
Definition Object.h:60
#define SUB_TEMPLATE_MAP()
virtual void destroy()
Definition Exception.cpp:74
size_t size() const
Definition Regex.h:57
void parseHelper(const char_t *_begin, const char_t *_end)
String name

◆ parseHelper()

void TextTemplate::parseHelper ( const char_t * _begin,
const char_t * _end )
protected

Definition at line 355 of file TextTemplate.cpp.

356{
357 try {
358 Regex re(__T("\\$[a-zA-Z0-9_]+"));
359 Regex::MatchResults results;
360 while(_begin < _end && re.search(_begin, _end, results)) {
361 if (results[0].matched && results[0].first < results[0].second) {
362 // $NAME 이전에 텍스트가 있다.
363 if (_begin < results[0].first) {
364 String text(_begin, results[0].first);
365 TextNode node;
366 node.values.addTail(text);
367 TEXT_LIST()->addTail(node);
368 }
369
370 // '$' 는 제외한다.
371 String name(results[0].first + 1, results[0].second);
372 TextNode node;
373 node.name = name;
374 TEXT_LIST()->addTail(node);
375
376 _begin = results[0].second;
377 }
378 }
379
380 if (_begin < _end) {
381 // $NAME 이후에 텍스트가 있다.
382 String text(_begin, _end);
383 TextNode node;
384 node.values.addTail(text);
385 TEXT_LIST()->addTail(node);
386 }
387 }
388 catch(RegexException* e) {
389 __DCL_TRACE1(__T("%ls\n"), e->toString().data());
390 e->destroy();
391 __DCL_ASSERT(false);
392 }
393}
StringList values

Member Data Documentation

◆ __subTemplateMap

void* TextTemplate::__subTemplateMap
protected

Definition at line 74 of file TextTemplate.h.

◆ __textList

void* TextTemplate::__textList
protected

Definition at line 73 of file TextTemplate.h.


The documentation for this class was generated from the following files: