/**
 *  Cette classe est utilisé afin d'avoir la possibilité d'obtenir les fonction-
 *  nalité d'un ResourcesBundle. Le tout est basé sur le modèle de Struts.
 *
 *  Cette classe est une classe de base, afin de récupérer la liste des String
 *  il faut implémenté la structure Ajax.
 */
function Bundle (bundleValues) {
    this.keysAndValue = new Map(bundleValues);
}

Bundle.prototype.getString = function(key) {  
   
    var value = this.keysAndValue.getValue(key);
    
    if (value == null) {
        return "???" + key + "???";
    }
    
    return value;
}

Bundle.prototype.getLangue = function() {
    return this.langue;
}


/**
 *  Cette classe représente une Map basé sur le modèle Java
 */
function Map(bundleValues) {
    this.arrayKeys = new Array();
    this.arrayValue = new Array();
    
    arrayBundleValues = bundleValues.split("|");
    
    for (var i = 0; i < arrayBundleValues.length; i++) {
        var element = arrayBundleValues[i];
        var pair = element.split("=");
        this.setValue(pair[0], pair[1]);
    }
}

Map.prototype.getValue = function(key) {
        
    for (var i = 0; i < this.arrayKeys.length; i++) {
        
        if (this.arrayKeys[i] == key) {
            return this.arrayValue[i];
        }
    }
    
    return null;
}

Map.prototype.setValue = function(key, value) {
    
    if (!this.arrayKeys.contains(key)) {
        this.arrayKeys.push(key);
        this.arrayValue.push(value);
    }
}

Map.prototype.removeKey = function(key) {
    
    var newArrayKeys = new Array();
    var newArrayValue = new Array();
    
    for (var i = 0; i < this.arrayKeys.length; i++) {
        
        if (this.arrayKeys[i] != key) {
            newArrayKeys.push(this.arrayKeys[i]);
            newArrayValue.push(this.arrayValue[i]);
        }        
    }
    
    this.arrayKeys = newArrayKeys;
    this.arrayValue = newArrayValue;
    
    delete newArrayKeys;
    delete newArrayValue;
}

/**
 *  Ceci est une extension de l'objet Array afin de 
 */
Array.prototype.contains = function(search) {
    
    for (var i = 0; i < this.length; i++) {
        
        if (this[i] == search) {
            return true;
        }
    }
    
    return false;
}

