Skip to content
Snippets Groups Projects
Commit a9845917 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

bugfixes in replacement logic

parent 78817caa
No related branches found
No related tags found
No related merge requests found
......@@ -55,12 +55,12 @@ function DocumentTemplate(pTemplateContent, pType, pFilename, pResolveSubtemplat
/**
* @return {String} the text of the content
*/
DocumentTemplate.prototype.toString = function ()
DocumentTemplate.prototype.toString = function (pWithSubtemplates)
{
if (this._stringCache == null)
{
var content = this._getTemplatedContent();
var content = this._getTemplatedContent(pWithSubtemplates);
logging.log(JSON.stringify([content], null, "\t"))
if (this.type == DocumentTemplate.types.PLAIN)
this._stringCache = content;
else
......@@ -71,21 +71,13 @@ DocumentTemplate.prototype.toString = function ()
DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
{
if (this.content != null && (this.type == DocumentTemplate.types.PLAIN || this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.HTML))
// currently we support only txt and html as others would need special caution.
if (this.content != null && (this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.HTML))
{
var replacedContent = "";
if (this.type == DocumentTemplate.types.PLAIN)
{
replacedContent = this.content;
}
else
{
replacedContent = util.decodeBase64String(this.content);
}
var replacedContent = util.decodeBase64String(this.content);
var templates = [];
// then load the possible replacement names
// currently we support only txt and html as others would need special caution.
if (this.type == DocumentTemplate.types.TXT || this.type == DocumentTemplate.types.HTML)
{
templates = db.table(SqlCondition.begin()
......@@ -120,24 +112,15 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
replacedContent = replacedContent.replace("{@" + pPlaceholder[0] + "@}", pPlaceholder[1], "g")
}, this);
if (this.type == DocumentTemplate.types.PLAIN)
this._subtemplatedContent = replacedContent;
else
this._subtemplatedContent = util.encodeBase64String(replacedContent);
this._subtemplatedContent = util.encodeBase64String(replacedContent);
}
}
DocumentTemplate.prototype._getTemplatedContent = function () {
var content;
DocumentTemplate.prototype._getTemplatedContent = function (pWithSubtemplates) {
if (this._subtemplatedContent != null && pWithSubtemplates)
content = this._subtemplatedContent;
else
content = this.content;
if (this.type == DocumentTemplate.types.PLAIN)
return content;
return this._subtemplatedContent;
else
return util.decodeBase64String(content);
return this.content;
}
......@@ -473,9 +456,9 @@ TemplateHelper._getRequiredPlaceholders = function (pTemplate)
var content = "";
// for eml search the whole file not just the body text as placeholders could be anywhere (e.g. subject)
if (pTemplate.type == DocumentTemplate.types.EML)
content = pTemplate._getTemplatedContent();
content = pTemplate._getTemplatedContent(true);
else
content = pTemplate.toString();
content = pTemplate.toString(true);
// get special regexp (e.g. to filter '=' in emls)
var filterRegexpPart = TemplateHelper._getSpecialRegexp(pTemplate);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment