in freemarker-core/src/main/java/freemarker/ext/dom/Transform.java [113:185]
static Transform transformFromArgs(String[] args) throws IOException {
int i = 0;
String input = null, output = null, ftl = null, loc = null, enc = null;
while (i < args.length) {
String dashArg = args[i++];
if (i >= args.length) {
throw new IllegalArgumentException("");
}
String arg = args[i++];
if (dashArg.equals("-in")) {
if (input != null) {
throw new IllegalArgumentException("The input file should only be specified once");
}
input = arg;
} else if (dashArg.equals("-ftl")) {
if (ftl != null) {
throw new IllegalArgumentException("The ftl file should only be specified once");
}
ftl = arg;
} else if (dashArg.equals("-out")) {
if (output != null) {
throw new IllegalArgumentException("The output file should only be specified once");
}
output = arg;
} else if (dashArg.equals("-locale")) {
if (loc != null) {
throw new IllegalArgumentException("The locale should only be specified once");
}
loc = arg;
} else if (dashArg.equals("-encoding")) {
if (enc != null) {
throw new IllegalArgumentException("The encoding should only be specified once");
}
enc = arg;
} else {
throw new IllegalArgumentException("Unknown input argument: " + dashArg);
}
}
if (input == null) {
throw new IllegalArgumentException("No input file specified.");
}
if (ftl == null) {
throw new IllegalArgumentException("No ftl file specified.");
}
File inputFile = new File(input).getAbsoluteFile();
File ftlFile = new File(ftl).getAbsoluteFile();
if (!inputFile.exists()) {
throw new IllegalArgumentException("Input file does not exist: " + input);
}
if (!ftlFile.exists()) {
throw new IllegalArgumentException("FTL file does not exist: " + ftl);
}
if (!inputFile.isFile() || !inputFile.canRead()) {
throw new IllegalArgumentException("Input file must be a readable file: " + input);
}
if (!ftlFile.isFile() || !ftlFile.canRead()) {
throw new IllegalArgumentException("FTL file must be a readable file: " + ftl);
}
File outputFile = null;
if (output != null) {
outputFile = new File(output).getAbsoluteFile();
File outputDirectory = outputFile.getParentFile();
if (!outputDirectory.exists() || !outputDirectory.canWrite()) {
throw new IllegalArgumentException("The output directory must exist and be writable: "
+ outputDirectory);
}
}
Locale locale = Locale.getDefault();
if (loc != null) {
locale = localeFromString(loc);
}
return new Transform(inputFile, ftlFile, outputFile, locale, enc);
}