001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.gwt.client.util;
029
030import com.google.gwt.core.client.JavaScriptObject;
031
032/**
033 * Class to create native JSON maps.<p>
034 *
035 * @since 8.0.0
036 */
037public final class CmsJSONMap extends JavaScriptObject {
038
039    /**
040     * Not directly instantiable. All subclasses must also define a protected, empty, no-arg constructor.<p>
041     */
042    protected CmsJSONMap() {
043
044        // empty
045    }
046
047    /**
048     * Creates a native javascript object to be used as a JSON map.<p>
049     *
050     * @return the JSON map
051     */
052    public static native CmsJSONMap createJSONMap() /*-{
053                                                    return {};
054                                                    }-*/;
055
056    /**
057     * Returns if the given key is present in the map.<p>
058     *
059     * @param key the key
060     *
061     * @return <code>true</code> if the map contains the key
062     */
063    public native boolean containsKey(String key) /*-{
064                                                  for (var _key in this){
065                                                  if (_key==key){
066                                                  return true;
067                                                  }
068                                                  }
069                                                  return false;
070                                                  }-*/;
071
072    /**
073     * Returns the value to the given key.<p>
074     *
075     * @param key the key
076     *
077     * @return the value
078     */
079    public native boolean getBoolean(String key) /*-{
080                                                 return this[key];
081                                                 }-*/;
082
083    /**
084     * Returns the value to the given key.<p>
085     *
086     * @param key the key
087     *
088     * @return the value
089     */
090    public native boolean[] getBooleanArray(String key) /*-{
091                                                        return this[key];
092                                                        }-*/;
093
094    /**
095     * Returns the value to the given key.<p>
096     *
097     * @param key the key
098     *
099     * @return the value
100     */
101    public native double getDouble(String key) /*-{
102                                               return this[key];
103                                               }-*/;
104
105    /**
106     * Returns the value to the given key.<p>
107     *
108     * @param key the key
109     *
110     * @return the value
111     */
112    public native double[] getDoubleArray(String key) /*-{
113                                                      return this[key];
114                                                      }-*/;
115
116    /**
117     * Returns the value to the given key.<p>
118     *
119     * @param key the key
120     *
121     * @return the value
122     */
123    public native int getInt(String key) /*-{
124                                         return this[key];
125                                         }-*/;
126
127    /**
128     * Returns the value to the given key.<p>
129     *
130     * @param key the key
131     *
132     * @return the value
133     */
134    public native int[] getIntArray(String key) /*-{
135                                                return this[key];
136                                                }-*/;
137
138    /**
139     * Returns the value to the given key.<p>
140     *
141     * @param key the key
142     *
143     * @return the value
144     */
145    public native JavaScriptObject getJavaScriptObject(String key) /*-{
146                                                                   return this[key];
147                                                                   }-*/;
148
149    /**
150     * Returns the value to the given key.<p>
151     *
152     * @param key the key
153     *
154     * @return the value
155     */
156    public native JavaScriptObject[] getJavaScriptObjectArray(String key) /*-{
157                                                                          return this[key];
158                                                                          }-*/;
159
160    /**
161     * Returns the value to the given key.<p>
162     *
163     * @param key the key
164     *
165     * @return the value
166     */
167    public native String getString(String key) /*-{
168                                               return this[key];
169                                               }-*/;
170
171    /**
172     * Returns the value to the given key.<p>
173     *
174     * @param key the key
175     *
176     * @return the value
177     */
178    public native String[] getStringArray(String key) /*-{
179                                                      return this[key];
180                                                      }-*/;
181
182    /**
183     * Puts the value into the map.<p>
184     *
185     * @param key the key
186     * @param value the value
187     */
188    public native void put(String key, boolean value) /*-{
189                                                      this[key]=value;
190                                                      }-*/;
191
192    /**
193     * Puts the value into the map.<p>
194     *
195     * @param key the key
196     * @param value the value
197     */
198    public native void put(String key, boolean[] value) /*-{
199                                                        this[key]=value;
200                                                        }-*/;
201
202    /**
203     * Puts the value into the map.<p>
204     *
205     * @param key the key
206     * @param value the value
207     */
208    public native void put(String key, double value) /*-{
209                                                     this[key]=value;
210                                                     }-*/;
211
212    /**
213     * Puts the value into the map.<p>
214     *
215     * @param key the key
216     * @param value the value
217     */
218    public native void put(String key, double[] value) /*-{
219                                                       this[key]=value;
220                                                       }-*/;
221
222    /**
223     * Puts the value into the map.<p>
224     *
225     * @param key the key
226     * @param value the value
227     */
228    public native void put(String key, int value) /*-{
229                                                  this[key]=value;
230                                                  }-*/;
231
232    /**
233     * Puts the value into the map.<p>
234     *
235     * @param key the key
236     * @param value the value
237     */
238    public native void put(String key, int[] value) /*-{
239                                                    this[key]=value;
240                                                    }-*/;
241
242    /**
243     * Puts the value into the map.<p>
244     *
245     * @param key the key
246     * @param value the value
247     */
248    public native void put(String key, JavaScriptObject value) /*-{
249                                                               this[key]=value;
250                                                               }-*/;
251
252    /**
253     * Puts the value into the map.<p>
254     *
255     * @param key the key
256     * @param value the value
257     */
258    public native void put(String key, JavaScriptObject[] value) /*-{
259                                                                 this[key]=value;
260                                                                 }-*/;
261
262    /**
263     * Puts the value into the map.<p>
264     *
265     * @param key the key
266     * @param value the value
267     */
268    public native void put(String key, String value) /*-{
269                                                     this[key]=value;
270                                                     }-*/;
271
272    /**
273     * Puts the value into the map.<p>
274     *
275     * @param key the key
276     * @param value the value
277     */
278    public native void put(String key, String[] value) /*-{
279                                                       this[key]=value;
280                                                       }-*/;
281}