package net.sf.jpluck.apps.cmdline;
import net.sf.jpluck.VersionInfo;
import net.sf.jpluck.apps.*;
import net.sf.jpluck.jxl.JXL;
import net.sf.jpluck.plucker.IniFile;
import net.sf.jpluck.plucker.IniFile.Document;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Options;
import org.w3c.dom.Element;
import java.io.File;
public class INI2JXL {
public static void main(String[] arguments) throws Exception {
Options options = OptionsUtil.createGeneric();
CommandLine cl = new GnuParser().parse(options, arguments);
if (cl.hasOption("help")) {
OptionsUtil.printHelp("java -jar ini2jxl.jar [options] <ini file> <jxl file>",
"Converts Plucker Desktop INI to JXL format.", options);
System.exit(ExitCodes.OK);
}
if (cl.hasOption("version")) {
OptionsUtil.printVersion("Plucker Desktop INI converter", VersionInfo.VERSION, VersionInfo.RELEASE_DATE);
System.exit(ExitCodes.OK);
}
String[] args = cl.getArgs();
if (args.length!=2) {
System.err.println("ERROR: invalid number of arguments: " + args.length);
System.exit(ExitCodes.ERROR_INVALID_NUMBER_OF_ARGUMENTS);
}
JXL jxl = new JXL();
File file = new File(args[0]);
System.out.println("Reading Plucker INI: " + file.getAbsolutePath());
IniFile ini = new IniFile(file);
Document[] documents = ini.getDocuments();
for (int i = 0; i < documents.length; i++) {
if (documents[i].getURL().startsWith("http://")) {
// Only imports HTTP URLs for now
Element site = jxl.createSiteElement();
documents[i].toJXLFormat(site);
jxl.add(site);
}
}
String s = args[1];
if (!s.endsWith(".jxl")) {
s+=".jxl";
}
File jxlFile = new File(s);
System.out.println("Writing JXL: " + jxlFile.getAbsolutePath());
jxl.save(jxlFile);
System.out.println("Done!");
}
}