/**
 * Copyright (c) 2015, German Neuroinformatics Node (G-Node)
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted under the terms of the BSD License. See
 * LICENSE file in the root of the Project.
 */

package org.g_node.converter;

import java.util.Set;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.log4j.Logger;
import org.g_node.Controller;
import org.g_node.srv.RDFService;

/**
 * Command class for the RDF to RDF converter.
 *
 * @author Michael Sonntag (sonntag@bio.lmu.de)
 */
public class ConvController implements Controller {
    /**
     * Access to the main LOGGER.
     */
    private static final Logger LOGGER = Logger.getLogger(ConvController.class.getName());
    /**
     * ArrayList containing all messages that occurred while converting the input file.
     */
    //private ArrayList<String> parserErrorMsg = new ArrayList<>(0);

    /**
     * Method returning the commandline options of the RDF to RDF converter.
     * @param regTools Set of all registered tools.
     * @return Available commandline options.
     */
    public final Options options(final Set<String> regTools) {
        final Options options = new Options();

        final Option opHelp = new Option("h", "help", false, "Print this message");

        final Option opIn = Option.builder("i")
                .longOpt("in-file")
                .desc("Input RDF file that's supposed to be converted into a different RDF format.")
                .required()
                .hasArg()
                .valueSeparator()
                .build();

        final Option opOut = Option.builder("o")
                .longOpt("out-file")
                .desc(
                        String.join(
                                "", "Optional: Path and name of the output file. ",
                                "Files with the same name will be overwritten. ",
                                "Default file name uses format [inputFileName]_out"
                        )
                )
                .hasArg()
                .valueSeparator()
                .build();

        final Option opFormat = Option.builder("f")
                .longOpt("out-format")
                .desc(
                        String.join(
                                "", "Optional: format of the RDF file that will be written.\n",
                                "Supported file formats: ", RDFService.RDF_FORMAT_MAP.keySet().toString(),
                                "\nDefault setting is the Turtle (TTL) format."
                        )
                )
                .hasArg()
                .valueSeparator()
                .build();

        options.addOption(opHelp);
        options.addOption(opIn);
        options.addOption(opOut);
        options.addOption(opFormat);

        return options;
    }

    /**
     * Method to convert an input RDF file to an RDF file of a different supported RDF format.
     * @param cmd Commandline input provided by the user
     */
    public final void run(final CommandLine cmd) {

        ConvController.LOGGER.info("Checking input RDF file...");

    }
}

@@ -309,16 +309,41 @@
 erter;%0A%0A
+import java.util.Locale;%0A
 import j
@@ -356,16 +356,16 @@
 il.Set;%0A
-
 import o
@@ -534,24 +534,59 @@
 Controller;%0A
+import org.g_node.srv.FileService;%0A
 import org.g
@@ -812,24 +812,24 @@
 ER.%0A     */%0A
+
     private 
@@ -911,182 +911,8 @@
 ));%0A
-    /**%0A     * ArrayList containing all messages that occurred while converting the input file.%0A     */%0A    //private ArrayList%3CString%3E parserErrorMsg = new ArrayList%3C%3E(0);%0A%0A
     
@@ -3089,63 +3089,1527 @@
     
-ConvController.LOGGER.info(%22Checking input RDF file...%22
+//TODO The following partially overlaps with code in the LKTController. Check if this can be unified somehow.%0A        ConvController.LOGGER.info(%22Checking input file...%22);%0A        final String inputFile = cmd.getOptionValue(%22i%22);%0A        if (!FileService.checkFile(inputFile)) %7B%0A            ConvController.LOGGER.error(%0A                    String.join(%22%22, %22Input file %22, inputFile, %22 does not exist.%22)%0A            );%0A            return;%0A        %7D%0A%0A        ConvController.LOGGER.info(%22Checking output format...%22);%0A        final String outputFormat = cmd.getOptionValue(%22f%22, %22TTL%22).toUpperCase(Locale.ENGLISH);%0A        if (!RDFService.RDF_FORMAT_MAP.containsKey(outputFormat)) %7B%0A            ConvController.LOGGER.error(%0A                    String.join(%22%22,%0A                            %22Unsupported output format: '%22, outputFormat, %22'%22,%0A                            %22%5Cn Please use one of the following: %22,%0A                            RDFService.RDF_FORMAT_MAP.keySet().toString()%0A                    )%0A            );%0A            return;%0A        %7D%0A%0A        final int i = inputFile.lastIndexOf('.');%0A        final String defaultOutputFile = String.join(%22%22, inputFile.substring(0, i), %22_out%22);%0A%0A        String outputFile = cmd.getOptionValue(%22o%22, defaultOutputFile);%0A%0A        if (!outputFile.toLowerCase().endsWith(RDFService.RDF_FORMAT_EXTENSION.get(outputFormat))) %7B%0A            outputFile = String.join(%22%22, outputFile, %22.%22, RDFService.RDF_FORMAT_EXTENSION.get(outputFormat));%0A        %7D%0A%0A        System.out.println(outputFile
 );%0A%0A

add cli options and checks to controller