Refactoring: Removing old helper function in favor of JDK 7 Paths functionality
@@ -33,7 +33,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -227,11 +226,9 @@ public class SchemaToTemplate {
f.getLineNumber(),
targetDirPath + File.separator,
// receives the path attribute from the Velocity template
- getTargetFileName(f.getAttribute("path"))
+ Paths.get(f.getAttribute("path")).normalize()
});
- LOG.info("By Paths: " + Paths.get(f.getAttribute("path")).normalize());
-
String contextAttrValue = f.getAttribute("contextNode");
if (contextAttrValue != null) {
context.put("contextNode", contextAttrValue);
@@ -244,7 +241,7 @@ public class SchemaToTemplate {
}
File out =
- new File(targetDirPath + File.separator + getTargetFileName(f.getAttribute("path")))
+ new File(targetDirPath + File.separator + Paths.get(f.getAttribute("path")).normalize())
.getCanonicalFile();
ensureParentFolders(out);
try (FileWriter fileout = new FileWriter(out)) {
@@ -254,22 +251,6 @@ public class SchemaToTemplate {
}
}
- // receives the path attribute from the Velocity template, replacing each ':' with '_', expecting
- // Linux separators
- private static String getTargetFileName(String rawName) {
- String retFilePath = null;
- StringTokenizer toktok = new StringTokenizer(rawName.replaceAll(":", "_"), "/");
- if (toktok.hasMoreTokens()) {
- File retfile = null;
- retfile = new File(toktok.nextToken());
- while (toktok.hasMoreTokens()) {
- retfile = new File(retfile, toktok.nextToken());
- }
- retFilePath = retfile.getPath();
- }
- return retFilePath;
- }
-
private static void ensureParentFolders(File newFile) {
File parent = newFile.getParentFile();
if (parent != null && !parent.exists()) {
