forked from OpenIntegrationEngine/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicCodeTemplateProperties.java
More file actions
67 lines (53 loc) · 1.86 KB
/
BasicCodeTemplateProperties.java
File metadata and controls
67 lines (53 loc) · 1.86 KB
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
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
package com.mirth.connect.model.codetemplates;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
import com.mirth.connect.donkey.util.purge.PurgeUtil;
public class BasicCodeTemplateProperties extends CodeTemplateProperties {
private String code;
public BasicCodeTemplateProperties(CodeTemplateType type, String code, String description) {
this(type, addComment(code, description));
}
public BasicCodeTemplateProperties(CodeTemplateType type, String code) {
super(type);
setCode(code);
}
@Override
public String getPluginPointName() {
return getType().toString();
}
@Override
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
updateDocumentation();
}
private static String addComment(String code, String description) {
if (StringUtils.isNotBlank(description)) {
return new StringBuilder("/**\n\t").append(WordUtils.wrap(description, 80, "\n\t", false)).append("\n*/\n").append(code).toString();
}
return code;
}
@Override
public CodeTemplateProperties clone() {
return new BasicCodeTemplateProperties(getType(), code);
}
@Override
public Map<String, Object> getPurgedProperties() {
Map<String, Object> purgedProperties = new HashMap<String, Object>();
purgedProperties.put("type", getType());
purgedProperties.put("codeLines", PurgeUtil.countLines(code));
return purgedProperties;
}
}