/**
 *
 * Copyright 2003-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package javax.mail.internet;

import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;

// Represents lists in things like
// Content-Type: text/plain;charset=klingon
//
// The ;charset=klingon is the parameter list, may have more of them with ';'

/**
 * @version $Rev$ $Date$
 */
public class ParameterList {
    private Map _parameters = new HashMap();

    public ParameterList() {
    }

    public ParameterList(String list) throws ParseException {
        if (list == null) {
            return;
        } else {
            StringTokenizer tokenizer = new StringTokenizer(list, ";");
            while (tokenizer.hasMoreTokens()) {
                String parameter = tokenizer.nextToken();
                int eq = parameter.indexOf("=");
                if (eq == -1) {
                    throw new ParseException(parameter);
                } else {
                    String name = parameter.substring(0, eq);
                    String value = parameter.substring(eq + 1).trim();
                    if (value.charAt(0) == '"') {
                        int end = value.lastIndexOf('"');
                        value = value.substring(1, end);
                    }
                    set(name, value);
                }
            }
        }
    }

    public int size() {
        return _parameters.size();
    }

    public String get(String name) {
        return (String) _parameters.get(name);
    }

    public void set(String name, String value) {
        _parameters.put(name.trim(), value.trim());
    }

    public void remove(String name) {
        _parameters.remove(name);
    }

    public Enumeration getNames() {
        return Collections.enumeration(_parameters.keySet());
    }

    public String toString() {
        Iterator it = _parameters.entrySet().iterator();
        StringBuffer result = new StringBuffer();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            result.append(";");
            result.append(entry.getKey());
            result.append("=");
            result.append(entry.getValue());
        }
        return result.toString();
        // TODO Return in same list as parsed format
    }

    public String toString(int lineBreak) {
        // figure out where to break the line
        String answer = toString();
        if (answer.length() > lineBreak) {
            // convert it to substring
            // TODO Implement
            return "";
        } else {
            return answer;
        }
    }
}

@@ -824,17 +824,66 @@
 enizer;%0A
-%0A
+import java.util.List;%0Aimport java.util.ArrayList;
 // Repre
@@ -1059,15 +1059,71 @@
 $Rev
-$ $Date
+: 179695 $ $Date: 2005-06-02 21:45:02 -0400 (Thu, 02 Jun 2005) 
 $%0A *
@@ -1384,59 +1384,34 @@
 ring
-Tokenizer tokenizer = new StringTokenizer
+%5B%5D tokens = split
 (list,
- %22;%22
+';'
 );%0A 
@@ -1425,40 +1425,58 @@
     
-while (tokenizer.hasMoreTokens()
+for (int i=0;tokens != null && i%3Ctokens.length;i++
 ) %7B%0A
@@ -1519,24 +1519,12 @@
 oken
-izer.nextToken()
+s%5Bi%5D
 ;%0A  
@@ -2950,32 +2950,32 @@
 ult.toString();%0A
-
         // TODO 
@@ -3010,32 +3010,1188 @@
 d format%0A    %7D%0A%0A
+    public static String%5B%5D split(String str, char separatorChar) %7B%0A        if (str == null) %7B%0A            return null;%0A        %7D%0A        int len = str.length();%0A        if (len == 0) %7B%0A            return new String%5B0%5D;%0A        %7D%0A        List list = new ArrayList();%0A        int i = 0, start = 0;%0A        boolean match = false;%0A        while (i %3C len) %7B%0A            char ch = str.charAt(i);%0A            // Skip any separatorChar within quotes%0A            if(ch == '%5C%22') %7B%0A                i++;%0A                while(i %3C len && str.charAt(i) != '%5C%22')%7B%0A                    i++;%0A                %7D%0A                if(i %3C len)%7B%0A                    i++;%0A                    continue;%0A                %7D%0A            %7D%0A            if (ch == separatorChar) %7B%0A                if (match) %7B%0A                    list.add(str.substring(start, i));%0A                    match = false;%0A                %7D%0A                start = ++i;%0A                continue;%0A            %7D%0A            match = true;%0A            i++;%0A        %7D%0A        if (match) %7B%0A            list.add(str.substring(start, i));%0A        %7D%0A        return (String%5B%5D) list.toArray(new String%5Blist.size()%5D);%0A    %7D%0A%0A
     public Strin

Fix parsing problem GERONIMO-764