// Path: sd-dss-util-lib/src/main/java/it/latraccia/dss/util/util/AssertHelper.java
// public class AssertHelper {
//     public static boolean stringMustEqual(String what, String string, String equalToThis) {
//         if (!(string == null && equalToThis == null)
//                 || !string.equals(equalToThis)) {
//             System.err.println(String.format("The %s has to be \"%s\" instead of \"%s\"",
//                     what, equalToThis, string));
//             return false;
//         }
//         return true;
//     }
// 
//     public static boolean stringMustNotEqual(String what, String string, String notEqualToThis) {
//         if ((string == null && notEqualToThis == null)
//                 || string.equals(notEqualToThis)) {
//             System.err.println(String.format("The %s has to be different than \"%s\" so it can't be \"%s\"",
//                     what, notEqualToThis, string));
//             return false;
//         }
//         return true;
//     }
// 
//     public static boolean stringMustBeInList(String what, String string, String[] list) {
//         if (Util.isNullOrEmpty(string)) {
//             System.err.println(String.format("The %s must be defined.", what));
//             return false;
//         }
// 
//         if (!isStringInList(string, list)) {System.err.println(String.format(
//                 "The %s can't be \"%s\". It must be one of \"%s\"",
//                 what, string,
//                 stringifyStringArray(list)));
//             return false;
//         }
// 
//         return true;
//     }
// 
//     /**
//      * Check if a {@link String} is in a {@link String} array.
//      *
//      * @param string The {@link String} to look for
//      * @param list The array of {@link String}s to search in
//      * @return true, if the {@link String} exists, false otherwise
//      */
//     public static boolean isStringInList(String string, String[] list) {
//         if (Util.isNullOrEmpty(string)) {
//             return false;
//         }
// 
//         if (list != null) {
//             for (String s : list) {
//                 if (s.equalsIgnoreCase(string)) {
//                     return true;
//                 }
//             }
//         }
// 
//         return false;
//     }
// 
//     public static boolean packageMustBeInList(String what, SignaturePackaging packaging, SignaturePackaging[] list) {
//         if (list != null) {
//             for (SignaturePackaging e : list) {
//                 if (e == packaging) {
//                     return true;
//                 }
//             }
//         }
// 
//         HashMap<SignaturePackaging, String> packagingMap = new HashMap<SignaturePackaging, String>();
//         packagingMap.put(SignaturePackaging.DETACHED, "DETACHED");
//         packagingMap.put(SignaturePackaging.ENVELOPING, "ENVELOPING");
//         packagingMap.put(SignaturePackaging.ENVELOPED, "ENVELOPED");
// 
//         String[] valuesArray = new String[0];
//         valuesArray = packagingMap.values().toArray(valuesArray);
//         System.err.println(String.format(
//                 "The %s can't be \"%s\". It must be one of \"%s\"",
//                 what,
//                 packagingMap.get(packaging),
//                 stringifySignaturePackagingArray(list)));
//         return false;
//     }
// 
//     public static String stringifyStringArray(String[] list) {
//         String stringified = "";
//         for (String s : list) {
//             stringified += s + ", ";
//         }
//         stringified = stringified.substring(0, stringified.length() - 2);
//         return stringified;
//     }
// 
//     public static String stringifySignaturePackagingArray(SignaturePackaging[] list) {
//         String[] stringList = new String[list.length];
//         for (int i = 0; i < list.length; i++) {
//             stringList[i] = list[i].name();
//         }
//         return stringifyStringArray(stringList);
//     }
// }


import it.latraccia.dss.util.util.AssertHelper;
import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.ParameterException;
import eu.europa.ec.markt.dss.signature.SignaturePackaging;
/*
 * SD-DSS-Util, a Utility Library and a Command Line Interface for SD-DSS.
 * Copyright (C) 2013 La Traccia http://www.latraccia.it/en/
 * Developed by Francesco Pontillo
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
 */

package it.latraccia.dss.util.cli.argument.converter;


public class PackagingConverter implements IStringConverter<SignaturePackaging> {
    @Override
    public SignaturePackaging convert(String s) {
// Path: sd-dss-util-lib/src/main/java/it/latraccia/dss/util/util/AssertHelper.java
// public class AssertHelper {
//     public static boolean stringMustEqual(String what, String string, String equalToThis) {
//         if (!(string == null && equalToThis == null)
//                 || !string.equals(equalToThis)) {
//             System.err.println(String.format("The %s has to be \"%s\" instead of \"%s\"",
//                     what, equalToThis, string));
//             return false;
//         }
//         return true;
//     }
// 
//     public static boolean stringMustNotEqual(String what, String string, String notEqualToThis) {
//         if ((string == null && notEqualToThis == null)
//                 || string.equals(notEqualToThis)) {
//             System.err.println(String.format("The %s has to be different than \"%s\" so it can't be \"%s\"",
//                     what, notEqualToThis, string));
//             return false;
//         }
//         return true;
//     }
// 
//     public static boolean stringMustBeInList(String what, String string, String[] list) {
//         if (Util.isNullOrEmpty(string)) {
//             System.err.println(String.format("The %s must be defined.", what));
//             return false;
//         }
// 
//         if (!isStringInList(string, list)) {System.err.println(String.format(
//                 "The %s can't be \"%s\". It must be one of \"%s\"",
//                 what, string,
//                 stringifyStringArray(list)));
//             return false;
//         }
// 
//         return true;
//     }
// 
//     /**
//      * Check if a {@link String} is in a {@link String} array.
//      *
//      * @param string The {@link String} to look for
//      * @param list The array of {@link String}s to search in
//      * @return true, if the {@link String} exists, false otherwise
//      */
//     public static boolean isStringInList(String string, String[] list) {
//         if (Util.isNullOrEmpty(string)) {
//             return false;
//         }
// 
//         if (list != null) {
//             for (String s : list) {
//                 if (s.equalsIgnoreCase(string)) {
//                     return true;
//                 }
//             }
//         }
// 
//         return false;
//     }
// 
//     public static boolean packageMustBeInList(String what, SignaturePackaging packaging, SignaturePackaging[] list) {
//         if (list != null) {
//             for (SignaturePackaging e : list) {
//                 if (e == packaging) {
//                     return true;
//                 }
//             }
//         }
// 
//         HashMap<SignaturePackaging, String> packagingMap = new HashMap<SignaturePackaging, String>();
//         packagingMap.put(SignaturePackaging.DETACHED, "DETACHED");
//         packagingMap.put(SignaturePackaging.ENVELOPING, "ENVELOPING");
//         packagingMap.put(SignaturePackaging.ENVELOPED, "ENVELOPED");
// 
//         String[] valuesArray = new String[0];
//         valuesArray = packagingMap.values().toArray(valuesArray);
//         System.err.println(String.format(
//                 "The %s can't be \"%s\". It must be one of \"%s\"",
//                 what,
//                 packagingMap.get(packaging),
//                 stringifySignaturePackagingArray(list)));
//         return false;
//     }
// 
//     public static String stringifyStringArray(String[] list) {
//         String stringified = "";
//         for (String s : list) {
//             stringified += s + ", ";
//         }
//         stringified = stringified.substring(0, stringified.length() - 2);
//         return stringified;
//     }
// 
//     public static String stringifySignaturePackagingArray(SignaturePackaging[] list) {
//         String[] stringList = new String[list.length];
//         for (int i = 0; i < list.length; i++) {
//             stringList[i] = list[i].name();
//         }
//         return stringifyStringArray(stringList);
//     }
// }


// Path: sd-dss-util-cli/src/main/java/it/latraccia/dss/util/cli/argument/converter/PackagingConverter.java
import it.latraccia.dss.util.util.AssertHelper;
import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.ParameterException;
import eu.europa.ec.markt.dss.signature.SignaturePackaging;

/*
 * SD-DSS-Util, a Utility Library and a Command Line Interface for SD-DSS.
 * Copyright (C) 2013 La Traccia http://www.latraccia.it/en/
 * Developed by Francesco Pontillo
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
 */

package it.latraccia.dss.util.cli.argument.converter;


public class PackagingConverter implements IStringConverter<SignaturePackaging> {
    @Override
    public SignaturePackaging convert(String s) {
        if (!AssertHelper.stringMustBeInList("signature packaging", s, new String[]{"ENVELOPED", "ENVELOPING", "DETACHED"})) {