Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/main/java/de/upb/docgen/graphviz/StateMachineToGraphviz.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -131,17 +133,23 @@ private static String getShortName(CrySLMethod label) {
}

public static void toPNG(String name) {
try { MutableGraph g = new Parser().read(new File("dotFSMs\\" + name +".dot"));
Graphviz.fromGraph(g).render(Format.SVG).toFile(new File("dotFSMs/" +name +".svg"));
try {
Path dot = Paths.get("dotFSMs", name + ".dot");
MutableGraph g = new Parser().read(dot.toFile());
Path svg = Paths.get("dotFSMs", name + ".svg");
Graphviz.fromGraph(g).render(Format.SVG).toFile(svg.toFile());

} catch (IOException e) {
e.printStackTrace();
}
}
//reads the dot translation and creates a png file that is later used by the FTL template
public static void toPNG(String name, String pathToRootpage) {
try { MutableGraph g = new Parser().read(new File(pathToRootpage+"\\"+"dotFSMs\\" + name +".dot"));
Graphviz.fromGraph(g).render(Format.SVG).toFile(new File(pathToRootpage+"/"+"dotFSMs/" +name +".svg"));
try {
Path dotPath = Paths.get(pathToRootpage, "dotFSMs", name + ".dot");
MutableGraph g = new Parser().read(dotPath.toFile());
Path svgPath = Paths.get(pathToRootpage, "dotFSMs", name + ".svg");
Graphviz.fromGraph(g).render(Format.SVG).toFile(svgPath.toFile());

} catch (IOException e) {
e.printStackTrace();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/de/upb/docgen/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

/**
Expand Down Expand Up @@ -143,7 +145,8 @@ public static Map<String, List<Map<String, List<String>>>> mapPredicates(Map<Str


public static char[] getTemplatesText(String templateName) throws IOException {
File file = new File(DocSettings.getInstance().getLangTemplatesPath()+"\\"+templateName);
Path template = Paths.get(DocSettings.getInstance().getLangTemplatesPath(), templateName);
File file = template.toFile();
StringBuilder stringBuffer = new StringBuilder();
Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
char[] buff = new char[500];
Expand All @@ -156,7 +159,8 @@ public static char[] getTemplatesText(String templateName) throws IOException {
}

public static String getTemplatesTextString(String templateName) throws IOException {
File file = new File(DocSettings.getInstance().getLangTemplatesPath()+"\\"+templateName);
Path template = Paths.get(DocSettings.getInstance().getLangTemplatesPath(), templateName);
File file = template.toFile();
BufferedReader br = new BufferedReader(new FileReader(file));
String strLine = "";
String strD = "";
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/de/upb/docgen/writer/FreeMarkerWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.awt.*;
import java.io.*;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.List;

Expand All @@ -30,7 +32,8 @@ public static void createSidebar(List<ComposedRule> composedRuleList, Configurat
Map<String, Object> input = new HashMap<String, Object>();
input.put("title", "Sidebar");
input.put("rules", composedRuleList);
Template template = cfg.getTemplate(Utils.pathForTemplates(DocSettings.getInstance().getFtlTemplatesPath() + "/"+ "sidebar.ftl"));
Path sidebarFilePath = Paths.get(DocSettings.getInstance().getFtlTemplatesPath(),"sidebar.ftl");
Template template = cfg.getTemplate(sidebarFilePath.toFile().getName());
// 2.3. Generate the output
try (Writer fileWriter = new FileWriter(new File(DocSettings.getInstance().getReportDirectory() + File.separator+"navbar.html"))) {
template.process(input, fileWriter);
Expand Down Expand Up @@ -71,7 +74,8 @@ public static void createSinglePage(List<ComposedRule> composedRuleList, Configu
input.put("booleanF", f);

// 2.2. Get the template
Template template = cfg.getTemplate(Utils.pathForTemplates(DocSettings.getInstance().getFtlTemplatesPath() + "/"+"singleclass.ftl"));
File templateFile = new File(DocSettings.getInstance().getFtlTemplatesPath() + "/"+ "singleclass.ftl");
Template template = cfg.getTemplate(templateFile.getName());

//create composedRules directory where single pages are stored
new File(DocSettings.getInstance().getReportDirectory()+"/"+"composedRules/").mkdir();
Expand All @@ -88,7 +92,7 @@ public static void createSinglePage(List<ComposedRule> composedRuleList, Configu
*/
public static void setupFreeMarker(Configuration cfg) {
// setup freemarker to load absolute paths
cfg.setTemplateLoader(new TemplateAbsolutePathLoader());
//cfg.setTemplateLoader(new TemplateAbsolutePathLoader());
// Some other recommended settings:
cfg.setDefaultEncoding("UTF-8");
cfg.setLocale(Locale.ENGLISH);
Expand All @@ -103,18 +107,21 @@ public static void setupFreeMarker(Configuration cfg) {
*/
public static void createCogniCryptLayout(Configuration cfg) throws IOException, TemplateException {
Map<String, Object> input = new HashMap<String, Object>();
/* Not used anymore
Template headerTemplate = cfg.getTemplate(Utils.pathForTemplates(DocSettings.getInstance().getFtlTemplatesPath() + "/"+ "header.ftl"));
try (Writer fileWriter = new FileWriter(new File(DocSettings.getInstance().getReportDirectory() + File.separator+"header.html"))) {
headerTemplate.process(input, fileWriter);
}

*/
Template frontpageTemplate = cfg.getTemplate(Utils.pathForTemplates(DocSettings.getInstance().getFtlTemplatesPath() + "/"+ "frontpage.ftl"));
Path frontpageFilePath = Paths.get(DocSettings.getInstance().getFtlTemplatesPath(),"frontpage.ftl");
File frontpageFile = frontpageFilePath.toFile();
File templateDir = frontpageFile.getParentFile();
if ( null == templateDir ){
templateDir = new File("./");
}
cfg.setDirectoryForTemplateLoading(templateDir);
Template frontpageTemplate = cfg.getTemplate(frontpageFile.getName());
try (Writer fileWriter = new FileWriter(new File(DocSettings.getInstance().getReportDirectory() + File.separator+"frontpage.html"))) {
frontpageTemplate.process(input, fileWriter);
}
Template rootpageTemplate = cfg.getTemplate(Utils.pathForTemplates(DocSettings.getInstance().getFtlTemplatesPath() + "/"+ "rootpage.ftl"));

Path rootpageFilePath = Paths.get(DocSettings.getInstance().getFtlTemplatesPath(),"rootpage.ftl");
Template rootpageTemplate = cfg.getTemplate(rootpageFilePath.toFile().getName());
try (Writer fileWriter = new FileWriter(new File(DocSettings.getInstance().getReportDirectory() + File.separator+"rootpage.html"))) {
rootpageTemplate.process(input, fileWriter);
}
Expand Down