Repository navigation
Expand file tree
/
Copy pathTemplate.java
More file actions
83 lines (58 loc) · 2.28 KB
/
Copy pathTemplate.java
File metadata and controls
83 lines (58 loc) · 2.28 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package code2code.core.generator;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import code2code.core.templateengine.TemplateEngine;
import code2code.core.templateengine.TemplateEngineFactory;
public class Template {
private boolean selectedToGenerate = true;
private boolean overwriteAllowed = false;
private String userChoosenResult;
private String userChoosenDestination;
private final String templateName;
private final TemplatesConfig templatesConfig;
private final String initialDestination;
public Template(TemplatesConfig templatesConfig, String templateName, String initialDestination) {
this.templatesConfig = templatesConfig;
this.templateName = templateName;
this.initialDestination = initialDestination;
}
public String getTemplateName() {
return templateName;
}
public InputStream calculateResult() throws Exception {
if(userChoosenResult!=null){
return new ByteArrayInputStream(userChoosenResult.getBytes());
}
TemplateEngine templateEngine = TemplateEngineFactory.forFileName(templateName);
if(templateEngine != null){
return new ByteArrayInputStream(templateEngine.processTemplate(templatesConfig.getGenerator(), templateName, templatesConfig.getGenerator().calculateContext()).getBytes());
}else{
return templatesConfig.getGenerator().getGeneratorFolder().getFile(templateName).getContents();
}
}
public String calculateDestination() throws Exception {
if(userChoosenDestination != null){
return userChoosenDestination;
}else{
return templatesConfig.getTemplateEngine().processString(templatesConfig.getGenerator(), initialDestination, templatesConfig.getGenerator().calculateContext());
}
}
public boolean isSelectedToGenerate() {
return selectedToGenerate;
}
public void setSelectedToGenerate(boolean selectedToGenerate) {
this.selectedToGenerate = selectedToGenerate;
}
public boolean isOverwriteAllowed() {
return overwriteAllowed;
}
public void setOverwriteAllowed(boolean overwriteAllowed) {
this.overwriteAllowed=overwriteAllowed;
}
public void setUserChoosenResult(String userChoosenResult) {
this.userChoosenResult = userChoosenResult;
}
public void setUserChoosenDestination(String userChoosenDestination) {
this.userChoosenDestination = userChoosenDestination;
}
}