Skip to content

Commit

Permalink
issue #85 - added command line option for setting templateProfileDir
Browse files Browse the repository at this point in the history
  • Loading branch information
mirko.nasato committed Apr 9, 2011
1 parent 898ee71 commit 1a45c3b
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public class Convert {
public static final int STATUS_MISSING_INPUT_FILE = 1;
public static final int STATUS_INVALID_ARGUMENTS = 255;

private static final Option OPTION_OUTPUT_FORMAT = new Option("f", "output-format", true, "output format (e.g. pdf)");
private static final Option OPTION_PORT = new Option("p", "port", true, "office socket port (optional; defaults to 8100)");
private static final Option OPTION_OUTPUT_FORMAT = new Option("o", "output-format", true, "output format (e.g. pdf)");
private static final Option OPTION_PORT = new Option("p", "port", true, "office socket port (optional; defaults to 2002)");
private static final Option OPTION_REGISTRY = new Option("r", "registry", true, "document formats registry configuration file (optional)");
private static final Option OPTION_USER_PROFILE = new Option("u", "user-profile", true, "use settings from the given user installation dir (optional)");
private static final Options OPTIONS = initOptions();

private static final int DEFAULT_OFFICE_PORT = 2002;
Expand All @@ -59,6 +60,7 @@ private static Options initOptions() {
options.addOption(OPTION_OUTPUT_FORMAT);
options.addOption(OPTION_PORT);
options.addOption(OPTION_REGISTRY);
options.addOption(OPTION_USER_PROFILE);
return options;
}

Expand All @@ -78,13 +80,13 @@ public static void main(String[] arguments) throws ParseException, JSONException

String[] fileNames = commandLine.getArgs();
if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) {
String syntax = "java net.sf.jodconverter.cli.Convert [options] input-file output-file; or\n"
+ "[options] -f output-format input-file [input-file...]";
String syntax = "java -jar jodconverter-core.jar [options] input-file output-file\n"
+ "or [options] -o output-format input-file [input-file...]";
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp(syntax, OPTIONS);
System.exit(STATUS_INVALID_ARGUMENTS);
}

DocumentFormatRegistry registry;
if (commandLine.hasOption(OPTION_REGISTRY.getOpt())) {
File registryFile = new File(commandLine.getOptionValue(OPTION_REGISTRY.getOpt()));
Expand All @@ -93,7 +95,14 @@ public static void main(String[] arguments) throws ParseException, JSONException
registry = new DefaultDocumentFormatRegistry();
}

OfficeManager officeManager = new DefaultOfficeManagerConfiguration().setPortNumber(port).buildOfficeManager();
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
configuration.setPortNumber(port);
if (commandLine.hasOption(OPTION_USER_PROFILE.getOpt())) {
String templateProfileDir = commandLine.getOptionValue(OPTION_USER_PROFILE.getOpt());
configuration.setTemplateProfileDir(new File(templateProfileDir));
}

OfficeManager officeManager = configuration.buildOfficeManager();
officeManager.start();
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager, registry);
try {
Expand Down

0 comments on commit 1a45c3b

Please sign in to comment.