Skip to content
Permalink
Browse files

Add encoding attribute to ABLDuck

Issue #388
  • Loading branch information
clement-brodu authored and gquerret committed Dec 12, 2019
1 parent 3d4cd17 commit 5b4c8288f199cd9dc03a5824e5ce60bef05477d3
Showing with 62 additions and 23 deletions.
  1. +62 −23 src/java/za/co/mip/ablduck/ABLDuck.java
@@ -18,10 +18,14 @@

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -89,6 +93,8 @@
private Boolean dataFilesOnly = false;
private List<FileSet> filesets = new ArrayList<>();
protected Path propath = null;
private String encoding = null;
private Charset inputCharset = null;

public ABLDuck() {
super();
@@ -121,6 +127,15 @@ public void setTitle(String title) {
this.title = title;
}

/**
* Codepage to use when reading files
*
* @param encoding String
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
}

/**
* Set the propath to be used when running the procedure
*
@@ -213,25 +228,30 @@ public void execute() {
String ext = file.getName().substring(extPos);
boolean isClass = ".cls".equalsIgnoreCase(ext);

ICompilationUnit root = astMgr.createAST(file, astContext, monitor,
IASTManager.EXPAND_ON, IASTManager.DLEVEL_FULL);
if (isClass) {
ABLDuckClassVisitor visitor = new ABLDuckClassVisitor(pp);
log("Executing AST ClassVisitor " + file.getAbsolutePath(),
Project.MSG_VERBOSE);
root.accept(visitor);

CompilationUnit cu = visitor.getCompilationUnit();
classes.put(cu.name, cu);
} else {

ABLDuckProcedureVisitor visitor = new ABLDuckProcedureVisitor(dsfiles[i]);
log("Executing AST ProcedureVisitor " + file.getAbsolutePath(),
Project.MSG_VERBOSE);
root.accept(visitor);

CompilationUnit cu = visitor.getCompilationUnit();
procedures.put(cu.name, cu);
try (InputStream input = new FileInputStream(file);
Reader fsr = new InputStreamReader(input, getCharset())) {
ICompilationUnit root = astMgr.createAST(fsr, astContext, monitor,
IASTManager.EXPAND_ON, IASTManager.DLEVEL_FULL);
if (isClass) {
ABLDuckClassVisitor visitor = new ABLDuckClassVisitor(pp);
log("Executing AST ClassVisitor " + file.getAbsolutePath(),
Project.MSG_VERBOSE);
root.accept(visitor);

CompilationUnit cu = visitor.getCompilationUnit();
classes.put(cu.name, cu);
} else {

ABLDuckProcedureVisitor visitor = new ABLDuckProcedureVisitor(dsfiles[i]);
log("Executing AST ProcedureVisitor " + file.getAbsolutePath(),
Project.MSG_VERBOSE);
root.accept(visitor);

CompilationUnit cu = visitor.getCompilationUnit();
procedures.put(cu.name, cu);
}
} catch (IOException e) {
log(e.getMessage(), Project.MSG_WARN);
}
}
}
@@ -342,7 +362,8 @@ public void execute() {
}

File outputFile = new File(baseDir, cu.name + ".js");
try (FileWriter file = new FileWriter(outputFile.toString())) {
try (OutputStreamWriter file = new OutputStreamWriter(
new FileOutputStream(outputFile.toString()), StandardCharsets.UTF_8)) {
file.write("Ext.data.JsonP." + cu.name.replace(".", "_") + "(" + gson.toJson(cu)
+ ");");
} catch (IOException ex) {
@@ -362,7 +383,8 @@ public void execute() {

String filename = cu.name.replace(".", "_").replace("/", "_");
File outputFile = new File(baseDir, filename + ".js");
try (FileWriter file = new FileWriter(outputFile.toString())) {
try (OutputStreamWriter file = new OutputStreamWriter(
new FileOutputStream(outputFile.toString()), StandardCharsets.UTF_8)) {
file.write("Ext.data.JsonP." + filename + "(" + gson.toJson(cu) + ");");
} catch (IOException ex) {
throw new BuildException(ex);
@@ -502,13 +524,30 @@ public void createSearch(CompilationUnit cu) {
+ member.name;
search.icon = ICON_PREFIX + member.tagname;
search.url = "#!/" + cu.tagname + "/"
+ ("procedure".equals(cu.tagname) ? cu.name : member.owner) + "-" + member.tagname
+ "-" + member.name;
+ ("procedure".equals(cu.tagname) ? cu.name : member.owner) + "-"
+ member.tagname + "-" + member.name;
search.sort = 3;
search.meta = member.meta;

data.search.add(search);
}
}

/**
* Get the Charset from encoding parameter
*
* @return Charset
*/
protected Charset getCharset() {
if (inputCharset == null) {
try {
inputCharset = Charset.forName(this.encoding);
} catch (IllegalArgumentException caught) {
inputCharset = Charset.defaultCharset();
}
}

return inputCharset;
}

}

0 comments on commit 5b4c828

Please sign in to comment.
You can’t perform that action at this time.