Java Properties Parse parseHtmlProperties(String s)

Here you can find the source of parseHtmlProperties(String s)

Description

Parse HTML Properties

License

Open Source License

Parameter

Parameter Description
s the string

Return

a hashtable of properties

Declaration

public static Hashtable parseHtmlProperties(String s) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**//from ww w.  ja v  a 2s.c om
     * Parse HTML Properties
     *
     * @param s the string
     * @return a hashtable of properties
     */
    public static Hashtable parseHtmlProperties(String s) {
        //        boolean debug = true;
        boolean debug = false;
        Hashtable properties = new Hashtable();
        //        debug = true;
        if (debug) {
            System.err.println("Source:" + s);
        }

        while (true) {
            if (debug) {
                System.err.println("S:" + s);
            }
            int idx = s.indexOf("=");
            if (idx < 0) {
                s = s.trim();
                if (s.length() > 0) {
                    if (debug) {
                        System.err.println("\tsingle name:" + s + ":");
                    }
                    properties.put(s, "");
                }
                break;
            }
            String name = s.substring(0, idx).trim();
            s = s.substring(idx + 1).trim();
            if (s.length() == 0) {
                if (debug) {
                    System.err.println("\tsingle name=" + name);
                }
                properties.put(name, "");
                break;
            }
            if (s.charAt(0) == '\"') {
                s = s.substring(1);
                idx = s.indexOf("\"");
                if (idx < 0) {
                    //no closing "="
                    properties.put(name, s);
                    break;
                }
                String value = s.substring(0, idx);
                if (debug) {
                    System.err.println("\tname=" + name);
                }
                if (debug) {
                    System.err.println("\tvalue=" + value);
                }
                properties.put(name, value);
                s = s.substring(idx + 1);
            } else {
                idx = s.indexOf(" ");
                if (idx < 0) {
                    if (debug) {
                        System.err.println("\tname=" + name);
                    }
                    if (debug) {
                        System.err.println("\tvalue=" + s);
                    }
                    properties.put(name, s);
                    break;
                }
                String value = s.substring(0, idx);
                properties.put(name, value);
                if (debug) {
                    System.err.println("\tname=" + name);
                }
                if (debug) {
                    System.err.println("\tvalue=" + value);
                }
                s = s.substring(idx + 1);

            }

        }
        if (debug) {
            System.err.println("props:" + properties);
        }

        return properties;
    }
}

Related

  1. parseBooleanProperty(Properties props, String keyword, boolean defaultValue)
  2. parseProperties(final String string)
  3. parsePropertiesString(String s)
  4. parseProps(Properties p)