Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ADITO_Update_Upgrade
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xrm
ADITO_Update_Upgrade
Commits
78817caa
Commit
78817caa
authored
5 years ago
by
Johannes Hörmann
Browse files
Options
Downloads
Patches
Plain Diff
bugfixes in replacement logic
parent
757a42f1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
process/DocumentTemplate_lib/process.js
+55
-25
55 additions, 25 deletions
process/DocumentTemplate_lib/process.js
with
55 additions
and
25 deletions
process/DocumentTemplate_lib/process.js
+
55
−
25
View file @
78817caa
...
...
@@ -59,10 +59,12 @@ DocumentTemplate.prototype.toString = function ()
{
if
(
this
.
_stringCache
==
null
)
{
var
content
=
this
.
_getTemplatedContent
();
if
(
this
.
type
==
DocumentTemplate
.
types
.
PLAIN
)
this
.
_stringCache
=
this
.
content
;
this
.
_stringCache
=
content
;
else
this
.
_stringCache
=
text
.
parseDocument
(
this
.
content
);
this
.
_stringCache
=
text
.
parseDocument
(
content
);
}
return
this
.
_stringCache
;
}
...
...
@@ -83,7 +85,8 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
var
templates
=
[];
// then load the possible replacement names
if
(
this
.
type
==
DocumentTemplate
.
types
.
PLAIN
||
this
.
type
==
DocumentTemplate
.
types
.
TXT
)
// 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
()
.
andPrepare
(
"
DOCUMENTTEMPLATE.KIND
"
,
$KeywordRegistry
.
documentTemplateType
$textModular
())
...
...
@@ -91,12 +94,13 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
.
buildSql
(
"
select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE
"
));
}
else
if
(
this
.
type
==
DocumentTemplate
.
types
.
HTML
)
if
(
this
.
type
==
DocumentTemplate
.
types
.
HTML
)
{
templates
=
db
.
table
(
SqlCondition
.
begin
()
templates
.
concat
(
db
.
table
(
SqlCondition
.
begin
()
.
andPrepare
(
"
DOCUMENTTEMPLATE.KIND
"
,
$KeywordRegistry
.
documentTemplateType
$textModular
())
.
andPrepare
(
"
DOCUMENTTEMPLATE.CLASSIFICATION
"
,
$KeywordRegistry
.
documentTemplateTypeCategory
$htmlTemplate
())
.
buildSql
(
"
select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE
"
));
.
buildSql
(
"
select DOCUMENTTEMPLATEID, REPLACEMENTNAME from DOCUMENTTEMPLATE
"
))
)
;
}
var
alias
=
SqlUtils
.
getSystemAlias
();
...
...
@@ -116,10 +120,28 @@ DocumentTemplate.prototype._resolveEmbeddedTemplate = function ()
replacedContent
=
replacedContent
.
replace
(
"
{@
"
+
pPlaceholder
[
0
]
+
"
@}
"
,
pPlaceholder
[
1
],
"
g
"
)
},
this
);
this
.
_subtemplatedContent
=
util
.
encodeBase64String
(
replacedContent
);
if
(
this
.
type
==
DocumentTemplate
.
types
.
PLAIN
)
this
.
_subtemplatedContent
=
replacedContent
;
else
this
.
_subtemplatedContent
=
util
.
encodeBase64String
(
replacedContent
);
}
}
DocumentTemplate
.
prototype
.
_getTemplatedContent
=
function
()
{
var
content
;
if
(
this
.
_subtemplatedContent
!=
null
&&
pWithSubtemplates
)
content
=
this
.
_subtemplatedContent
;
else
content
=
this
.
content
;
if
(
this
.
type
==
DocumentTemplate
.
types
.
PLAIN
)
return
content
;
else
return
util
.
decodeBase64String
(
content
);
}
/**
* The types a DocumentTemplate can have. Depending on the type,
* the correct method for replacing the placeholders can be chosen
...
...
@@ -442,37 +464,45 @@ TemplateHelper._replaceText = function (pText, pReplacements, pSpecialCharFilter
}
/**
* @param {DocumentTemplate} pTemplate
* @return {Object[]} all placeholders needed in this template
* @private
*/
TemplateHelper
.
_getRequiredPlaceholders
=
function
(
pTemplate
)
{
// if there exists a _subtemplatedContent we use it because then I assume that the replacements are already based on content + subtemplates
var
content
;
if
(
pTemplate
.
_subtemplatedContent
==
null
)
content
=
pTemplate
.
c
ontent
;
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
.
_getTemplatedC
ontent
()
;
else
content
=
pTemplate
.
_subtemplatedContent
;
if
(
pTemplate
.
type
!=
DocumentTemplate
.
types
.
PLAIN
)
{
content
=
util
.
decodeBase64String
(
content
);
}
content
=
pTemplate
.
toString
();
// get special regexp (e.g. to filter '=' in emls)
var
filterRegexpPart
=
TemplateHelper
.
_getSpecialRegexp
(
pTemplate
);
var
placeholders
=
PlaceholderUtils
.
getPlaceholders
();
var
placeholderCleanRegexp
=
new
RegExp
(
filterRegexpPart
,
"
gi
"
);
var
foundPlaceholders
=
content
.
match
(
new
RegExp
(
PlaceholderUtils
.
getRegexpMatchAll
(
TemplateHelper
.
_getSpecialRegexp
(
pTemplate
)),
"
gi
"
)).
map
(
function
(
pFound
)
{
return
pFound
.
replace
(
placeholderCleanRegexp
,
""
);
});
placeholders
=
placeholders
.
filter
(
function
(
pPlaceholder
)
// get all placeholders which matches the placeholder pattern
var
foundPlaceholders
=
content
.
match
(
new
RegExp
(
PlaceholderUtils
.
getRegexpMatchAll
(
TemplateHelper
.
_getSpecialRegexp
(
pTemplate
)),
"
gi
"
));
if
(
foundPlaceholders
!=
null
)
{
return
foundPlaceholders
.
indexOf
(
pPlaceholder
.
placeholderName
)
!=
-
1
;
});
return
placeholders
;
// clean placeholder from the spechial strings (e.g. to filter '=' in emls)
foundPlaceholders
=
foundPlaceholders
.
map
(
function
(
pFound
)
{
return
pFound
.
replace
(
placeholderCleanRegexp
,
""
);
});
// filter the possible placeholders by all placeholders found
placeholders
=
placeholders
.
filter
(
function
(
pPlaceholder
)
{
return
foundPlaceholders
.
indexOf
(
pPlaceholder
.
placeholderName
)
!=
-
1
;
});
logging
.
log
(
JSON
.
stringify
([
placeholders
],
null
,
"
\t
"
))
return
placeholders
;
}
return
[];
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment