public PSDictionary parseDictionary()

in src/main/java/org/apache/xmlgraphics/ps/PSDictionary.java [185:235]


        public PSDictionary parseDictionary(String str) throws PSDictionaryFormatException {
            PSDictionary dictionary = new PSDictionary();
            str = stripBraces(str.trim(), BRACES[DICTIONARY]);
            // length of dictionary string
            final int len = str.length();

            Token keyToken;
            for (int currIndex = 0; (keyToken = nextToken(str, currIndex)) != null
                    && currIndex <= len;) {
                if (keyToken.value == null) {
                    throw new PSDictionaryFormatException("Failed to parse object key");
                }
                Token valueToken = nextToken(str, keyToken.endIndex + 1);
                String[] braces = null;
                for (String[] brace : BRACES) {
                    if (valueToken.value.startsWith(brace[OPENING])) {
                        braces = brace;
                        break;
                    }
                }
                Object obj = null;
                if (braces != null) {
                    // find closing brace
                    valueToken.endIndex = indexOfMatchingBrace(str, braces,
                        valueToken.startIndex)
                        + braces[OPENING].length();
                    if (valueToken.endIndex < 0) {
                        throw new PSDictionaryFormatException("Closing value brace '"
                            + braces[CLOSING] + "' not found for key '"
                            + keyToken.value + "'");
                    }
                    valueToken.value = str.substring(valueToken.startIndex, valueToken.endIndex);
                }
                if (braces == null || braces == BRACES[PROCEDURE] || braces == BRACES[STRING]) {
                    obj = valueToken.value;
                } else if (BRACES[ARRAY] == braces) {
                    List objList = new java.util.ArrayList();
                    String objString = stripBraces(valueToken.value, braces);
                    StringTokenizer tokenizer = new StringTokenizer(objString, ",");
                    while (tokenizer.hasMoreTokens()) {
                        objList.add(tokenizer.nextToken());
                    }
                    obj = objList;
                } else if (BRACES[DICTIONARY] == braces) {
                    obj = parseDictionary(valueToken.value);
                }
                dictionary.put(keyToken.value, obj);
                currIndex = valueToken.endIndex + 1;
            }
            return dictionary;
        }