String hostName = null;
String username = null;
String password = null;
int portNum = 0;
boolean isValidateOnly = true;
FedoraClient fc = null;
try {
if (args.length < 6 || args.length > 8) {
AutoModify
.showUsage("You must provide either 6, 7 or 8 arguments.");
} else {
String[] hostPort = args[0].split(":");
if (hostPort.length != 2) {
AutoModify
.showUsage("First argument must contain target"
+ " Fedora server hostname and port using the syntax"
+ " \"hostname:port\"");
}
hostName = hostPort[0];
portNum = Integer.parseInt(hostPort[1]);
username = args[1];
password = args[2];
directivesFilePath = args[3];
logFilePath = args[4];
protocol = args[5];
if (args.length >= 7) {
isValidateOnly = false;
} else {
isValidateOnly = true;
}
String context = Constants.FEDORA_DEFAULT_APP_CONTEXT;
if (args.length == 8 && !args[7].equals("")){
context = args[7];
}
if (new File(directivesFilePath).exists()) {
System.out.println("\nCONNECTING to Fedora server....");
// ******************************************
// NEW: use new client utility class
String baseURL =
protocol + "://" + hostName + ":" + portNum
+ "/" + context;
fc = new FedoraClient(baseURL, username, password);
APIA = fc.getAPIAMTOM();
APIM = fc.getAPIMMTOM();
//*******************************************
AutoModify am =
new AutoModify(APIA,
APIM,
protocol,
hostName,
portNum,
context,
username,
password);
if (isValidateOnly) {
System.out
.println("\n----- VALIDATING DIRECTIVES FILE ONLY -----\n");
} else {
System.out
.println("\n----- PROCESSING DIRECTIVES FILE -----\n");
}
am.modify(directivesFilePath, logFilePath, isValidateOnly);
} else {
AutoModify
.showUsage("Directives input file does not exist: "
+ directivesFilePath + " .");
}
}
} catch (Exception e) {
AutoModify.showUsage(e.getClass().getName()
+ " - "
+ (e.getMessage() == null ? "(no detail provided)" : e
.getMessage()));
} finally {
if (fc != null) {
fc.shutdown();
}
}
}