// Path: src/main/java/com/openstego/desktop/util/LabelUtil.java
// public class LabelUtil {
//     /**
//      * Static variable to hold the map of labels loaded from resource files
//      */
//     private static final Map<String, ResourceBundle> map = new HashMap<>();
// 
//     /**
//      * Static variable to store the namespace map
//      */
//     private static final Map<String, LabelUtil> namespaceMap = new HashMap<>();
// 
//     /**
//      * Method to add new namespace using resource bundle
//      *
//      * @param namespace Namespace for the labels
//      * @param bundle    Resource bundle name
//      */
//     public static void addNamespace(String namespace, String bundle) {
//         map.put(namespace, ResourceBundle.getBundle(bundle, Locale.getDefault()));
//     }
// 
//     /**
//      * Method to get instance of LabelUtil based on the namespace
//      *
//      * @param namespace Namespace for the labels
//      * @return Instance of LabelUtil
//      */
//     public static LabelUtil getInstance(String namespace) {
//         LabelUtil util;
// 
//         util = namespaceMap.get(namespace);
//         if (util == null) {
//             util = new LabelUtil(namespace);
//             namespaceMap.put(namespace, util);
//         }
// 
//         return util;
//     }
// 
//     /**
//      * Variable to store the current namespace
//      */
//     private final String namespace;
// 
//     /**
//      * Constructor is protected
//      *
//      * @param namespace Namespace for the label
//      */
//     protected LabelUtil(String namespace) {
//         this.namespace = namespace;
//     }
// 
//     /**
//      * Method to get label value for the given label key
//      *
//      * @param key Key for the label
//      * @return Display value for the label
//      */
//     public String getString(String key) {
//         return (map.get(this.namespace)).getString(key);
//     }
// 
//     /**
//      * Method to get label value for the given label key (using optional parameters)
//      *
//      * @param key        Key for the label
//      * @param parameters Parameters to pass for a parameterized label
//      * @return Display value for the label
//      */
//     public String getString(String key, Object... parameters) {
//         return MessageFormat.format(getString(key), parameters);
//     }
// }


import com.openstego.desktop.util.LabelUtil;
import java.util.HashMap;
import java.util.Map;
/*
 * Steganography utility to hide messages into cover files
 * Author: Samir Vaidya (mailto:syvaidya@gmail.com)
 * Copyright (c) Samir Vaidya
 */

package com.openstego.desktop;



/**
 * Custom exception class for OpenStego
 */
public class OpenStegoException extends Exception {
    private static final long serialVersionUID = 668241029491685413L;

    /**
     * Error Code - Unhandled exception
     */
    static final int UNHANDLED_EXCEPTION = 0;

    /**
     * Map to store error code to message key mapping
     */
    private static final Map<String, String> errMsgKeyMap = new HashMap<>();

    /**
     * Error code for the exception
     */
    private final int errorCode;

    /**
     * Namespace for the exception
     */
    private final String namespace;

    /**
     * Constructor using default namespace for unhandled exceptions
     *
     * @param cause Original exception which caused this exception to be raised
     */
    public OpenStegoException(Throwable cause) {
        this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null);
    }

    /**
     * Default constructor
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode) {
        this(cause, namespace, errorCode, (Object[]) null);
    }

    /**
     * Constructor with a single parameter for the message
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     * @param param     Parameter for exception message
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) {
        this(cause, namespace, errorCode, new Object[]{param});
    }

    /**
     * Constructor which takes object array for parameters for the message
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     * @param params    Parameters for exception message
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) {
        super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString()
// Path: src/main/java/com/openstego/desktop/util/LabelUtil.java
// public class LabelUtil {
//     /**
//      * Static variable to hold the map of labels loaded from resource files
//      */
//     private static final Map<String, ResourceBundle> map = new HashMap<>();
// 
//     /**
//      * Static variable to store the namespace map
//      */
//     private static final Map<String, LabelUtil> namespaceMap = new HashMap<>();
// 
//     /**
//      * Method to add new namespace using resource bundle
//      *
//      * @param namespace Namespace for the labels
//      * @param bundle    Resource bundle name
//      */
//     public static void addNamespace(String namespace, String bundle) {
//         map.put(namespace, ResourceBundle.getBundle(bundle, Locale.getDefault()));
//     }
// 
//     /**
//      * Method to get instance of LabelUtil based on the namespace
//      *
//      * @param namespace Namespace for the labels
//      * @return Instance of LabelUtil
//      */
//     public static LabelUtil getInstance(String namespace) {
//         LabelUtil util;
// 
//         util = namespaceMap.get(namespace);
//         if (util == null) {
//             util = new LabelUtil(namespace);
//             namespaceMap.put(namespace, util);
//         }
// 
//         return util;
//     }
// 
//     /**
//      * Variable to store the current namespace
//      */
//     private final String namespace;
// 
//     /**
//      * Constructor is protected
//      *
//      * @param namespace Namespace for the label
//      */
//     protected LabelUtil(String namespace) {
//         this.namespace = namespace;
//     }
// 
//     /**
//      * Method to get label value for the given label key
//      *
//      * @param key Key for the label
//      * @return Display value for the label
//      */
//     public String getString(String key) {
//         return (map.get(this.namespace)).getString(key);
//     }
// 
//     /**
//      * Method to get label value for the given label key (using optional parameters)
//      *
//      * @param key        Key for the label
//      * @param parameters Parameters to pass for a parameterized label
//      * @return Display value for the label
//      */
//     public String getString(String key, Object... parameters) {
//         return MessageFormat.format(getString(key), parameters);
//     }
// }


// Path: src/main/java/com/openstego/desktop/OpenStegoException.java
import com.openstego.desktop.util.LabelUtil;
import java.util.HashMap;
import java.util.Map;

/*
 * Steganography utility to hide messages into cover files
 * Author: Samir Vaidya (mailto:syvaidya@gmail.com)
 * Copyright (c) Samir Vaidya
 */

package com.openstego.desktop;



/**
 * Custom exception class for OpenStego
 */
public class OpenStegoException extends Exception {
    private static final long serialVersionUID = 668241029491685413L;

    /**
     * Error Code - Unhandled exception
     */
    static final int UNHANDLED_EXCEPTION = 0;

    /**
     * Map to store error code to message key mapping
     */
    private static final Map<String, String> errMsgKeyMap = new HashMap<>();

    /**
     * Error code for the exception
     */
    private final int errorCode;

    /**
     * Namespace for the exception
     */
    private final String namespace;

    /**
     * Constructor using default namespace for unhandled exceptions
     *
     * @param cause Original exception which caused this exception to be raised
     */
    public OpenStegoException(Throwable cause) {
        this(cause, OpenStego.NAMESPACE, UNHANDLED_EXCEPTION, (Object[]) null);
    }

    /**
     * Default constructor
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode) {
        this(cause, namespace, errorCode, (Object[]) null);
    }

    /**
     * Constructor with a single parameter for the message
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     * @param param     Parameter for exception message
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode, String param) {
        this(cause, namespace, errorCode, new Object[]{param});
    }

    /**
     * Constructor which takes object array for parameters for the message
     *
     * @param cause     Original exception which caused this exception to be raised
     * @param namespace Namespace of the error
     * @param errorCode Error code for the exception
     * @param params    Parameters for exception message
     */
    public OpenStegoException(Throwable cause, String namespace, int errorCode, Object... params) {
        super((OpenStego.NAMESPACE.equals(namespace) && errorCode == UNHANDLED_EXCEPTION) ? cause.toString()
                : LabelUtil.getInstance(namespace).getString(errMsgKeyMap.get(namespace + errorCode), params), cause);