All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wicketstuff.jwicket.JsMap Maven / Gradle / Ivy

Go to download

WicketJQuery by Stefan Lindner has been renamed to jWicket, mavenized, and migrated to WicketStuff. This Wicketstuff version supercedes the original version which was available at http://subversion.visionet.de/project/WicketJQuery/wiki

There is a newer version: 9.7.0
Show newest version
package org.wicketstuff.jwicket;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;


public class JsMap extends HashMap implements Serializable {

	private static final long serialVersionUID = 1L;

	public JsMap() {
		super();
	}


	public String toString(final String rawOptions) {
		if (isEmpty()) {
			return "";
		}
		StringBuffer buffer = new StringBuffer();
		toString(buffer, rawOptions);
		return buffer.toString();
	}

	public void toString(final StringBuffer buffer, final String rawOptions) {
		boolean first = true;
		for (Iterator iter = keySet().iterator(); iter.hasNext();) {
			if (!first)
				buffer.append(",");
			else
				first = false;

			String key = iter.next();
			Object value = get(key);

			buffer.append(key);
			buffer.append(":");
			if (value instanceof CharSequence) {
				buffer.append("'");
				buffer.append(value);
				buffer.append("'");
			}
			else if (value instanceof JsScript) {
				buffer.append(value.toString());
			}
			else if (value instanceof JsOption[]) {
				boolean firstOption = true;
				buffer.append("{");
				for (JsOption o : ((JsOption[])value)) {
					if (!firstOption)
						buffer.append(",");
					else
						firstOption = false;
					buffer.append(o);
				}
				buffer.append("}");
			}
			else if (value instanceof JsOption) {
				buffer.append("{");
				buffer.append((JsOption)value);
				buffer.append("}");
			}
			else if (value instanceof Object[]) {
				boolean firstOption = true;
				buffer.append("[");
				for (Object o : ((Object[])value)) {
					if (!firstOption)
						buffer.append(",");
					else
						firstOption = false;
					if (o instanceof CharSequence) {
						buffer.append("'");
						buffer.append(o);
						buffer.append("'");
					}
					else
						buffer.append(o);
				}
				buffer.append("]");
			}
			else
				buffer.append(value);
		}
		if (rawOptions != null) {
			buffer.append(",");
			buffer.append(rawOptions);
		}
	}

	public void put(final String key, JsOption...options) {
		super.put(key, options);
	}

	public void put(final String key, Object...options) {
		super.put(key, options);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy