diff options
author | John Ahlroos <john@vaadin.com> | 2012-09-17 11:30:57 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-09-17 11:30:57 +0300 |
commit | 250e7beab06b185aebe3e97e2d5f7102d1e1b270 (patch) | |
tree | a3de6edfdaf711721cb10b09025dee3f60a807b9 /server | |
parent | ff56225f04d1ca67923fb2b05d37adc4907678da (diff) | |
parent | 800efdee9d891fb07343b18bca7cd543ffebb615 (diff) | |
download | vaadin-framework-250e7beab06b185aebe3e97e2d5f7102d1e1b270.tar.gz vaadin-framework-250e7beab06b185aebe3e97e2d5f7102d1e1b270.zip |
Merge branch 'master' into html5-doctype
Diffstat (limited to 'server')
52 files changed, 497 insertions, 4011 deletions
diff --git a/server/ivy.xml b/server/ivy.xml index acc384ea30..5ef49db80a 100644 --- a/server/ivy.xml +++ b/server/ivy.xml @@ -25,9 +25,9 @@ <!-- Liferay Portal Service --> <dependency org="com.liferay.portal" name="portal-service" rev="6.0.2" conf="build-provided,ide -> default" /> - <!--Servlet API version 2.5 --> + <!--Servlet API version 2.4 --> <dependency org="javax.servlet" name="servlet-api" - rev="2.5" conf="build-provided,ide,tests -> default" /> + rev="2.4" conf="build-provided,ide,tests -> default" /> <!--Portlet API version 2.0 (JSR-286) --> <dependency org="javax.portlet" name="portlet-api" @@ -43,6 +43,8 @@ <!-- Project modules --> <dependency org="com.vaadin" name="vaadin-shared" rev="${vaadin.version}" conf="build,tests" /> + <dependency org="com.vaadin" name="vaadin-theme-compiler" + rev="${vaadin.version}" conf="build,tests" /> <!-- Jsoup for BootstrapHandler --> <dependency org="org.jsoup" name="jsoup" rev="1.6.3" diff --git a/server/src/com/vaadin/LegacyApplication.java b/server/src/com/vaadin/LegacyApplication.java index a1aeb037fd..3a6ffaa39c 100644 --- a/server/src/com/vaadin/LegacyApplication.java +++ b/server/src/com/vaadin/LegacyApplication.java @@ -26,6 +26,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.vaadin.server.AbstractUIProvider; +import com.vaadin.server.DefaultErrorListener; import com.vaadin.server.Terminal.ErrorEvent; import com.vaadin.server.Terminal.ErrorListener; import com.vaadin.server.VaadinSession; @@ -100,24 +101,23 @@ public abstract class LegacyApplication extends AbstractUIProvider implements } @Override - public UI createInstance(Class<? extends UI> type, WrappedRequest request) { + public UI createInstance(WrappedRequest request, Class<? extends UI> type) { return getUIInstance(request); } @Override - public String getThemeForUI(WrappedRequest request, - Class<? extends UI> uiClass) { + public String getTheme(WrappedRequest request, Class<? extends UI> uiClass) { return theme; } @Override - public String getPageTitleForUI(WrappedRequest request, + public String getPageTitle(WrappedRequest request, Class<? extends UI> uiClass) { UI uiInstance = getUIInstance(request); if (uiInstance != null) { return uiInstance.getCaption(); } else { - return super.getPageTitleForUI(request, uiClass); + return super.getPageTitle(request, uiClass); } } @@ -282,7 +282,7 @@ public abstract class LegacyApplication extends AbstractUIProvider implements @Override public void terminalError(ErrorEvent event) { - VaadinSession.getCurrent().getErrorHandler().terminalError(event); + DefaultErrorListener.doDefault(event); } public VaadinSession getContext() { diff --git a/server/src/com/vaadin/data/validator/DateRangeValidator.java b/server/src/com/vaadin/data/validator/DateRangeValidator.java index 44c0d1e929..51eaa2e59b 100644 --- a/server/src/com/vaadin/data/validator/DateRangeValidator.java +++ b/server/src/com/vaadin/data/validator/DateRangeValidator.java @@ -17,7 +17,7 @@ package com.vaadin.data.validator; import java.util.Date; -import com.vaadin.ui.DateField.Resolution; +import com.vaadin.shared.ui.datefield.Resolution; /** * Validator for validating that a Date is inside a given range. diff --git a/server/src/com/vaadin/event/MouseEvents.java b/server/src/com/vaadin/event/MouseEvents.java index e287055c2b..37c6d665b5 100644 --- a/server/src/com/vaadin/event/MouseEvents.java +++ b/server/src/com/vaadin/event/MouseEvents.java @@ -19,6 +19,7 @@ package com.vaadin.event; import java.lang.reflect.Method; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.MouseEventDetails.MouseButton; import com.vaadin.ui.Component; import com.vaadin.util.ReflectTools; @@ -44,10 +45,21 @@ public interface MouseEvents { * @since 6.2 */ public static class ClickEvent extends Component.Event { - public static final int BUTTON_LEFT = MouseEventDetails.BUTTON_LEFT; - public static final int BUTTON_MIDDLE = MouseEventDetails.BUTTON_MIDDLE; - public static final int BUTTON_RIGHT = MouseEventDetails.BUTTON_RIGHT; - + /** + * @deprecated use {@link Button#LEFT} instead. + */ + @Deprecated + public static final MouseButton BUTTON_LEFT = MouseButton.LEFT; + /** + * @deprecated use {@link Button#MIDDLE} instead. + */ + @Deprecated + public static final MouseButton BUTTON_MIDDLE = MouseButton.MIDDLE; + /** + * @deprecated use {@link Button#RIGHT} instead. + */ + @Deprecated + public static final MouseButton BUTTON_RIGHT = MouseButton.RIGHT; private MouseEventDetails details; public ClickEvent(Component source, MouseEventDetails mouseEventDetails) { @@ -57,13 +69,13 @@ public interface MouseEvents { /** * Returns an identifier describing which mouse button the user pushed. - * Compare with {@link #BUTTON_LEFT},{@link #BUTTON_MIDDLE}, - * {@link #BUTTON_RIGHT} to find out which butten it is. + * Compare with {@link MouseButton#LEFT},{@link MouseButton#MIDDLE}, + * {@link Button#RIGHT} to find out which button it is. * - * @return one of {@link #BUTTON_LEFT}, {@link #BUTTON_MIDDLE}, - * {@link #BUTTON_RIGHT}. + * @return one of {@link MouseButton#LEFT}, {@link MouseButton#MIDDLE}, + * {@link MouseButton#RIGHT}. */ - public int getButton() { + public MouseButton getButton() { return details.getButton(); } diff --git a/server/src/com/vaadin/external/json/JSONArray.java b/server/src/com/vaadin/external/json/JSONArray.java deleted file mode 100644 index 2307749ffc..0000000000 --- a/server/src/com/vaadin/external/json/JSONArray.java +++ /dev/null @@ -1,963 +0,0 @@ -package com.vaadin.external.json; - -/* - Copyright (c) 2002 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -import java.io.IOException; -import java.io.Serializable; -import java.io.Writer; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; - -/** - * A JSONArray is an ordered sequence of values. Its external text form is a - * string wrapped in square brackets with commas separating the values. The - * internal form is an object having <code>get</code> and <code>opt</code> - * methods for accessing the values by index, and <code>put</code> methods for - * adding or replacing values. The values can be any of these types: - * <code>Boolean</code>, <code>JSONArray</code>, <code>JSONObject</code>, - * <code>Number</code>, <code>String</code>, or the - * <code>JSONObject.NULL object</code>. - * <p> - * The constructor can convert a JSON text into a Java object. The - * <code>toString</code> method converts to JSON text. - * <p> - * A <code>get</code> method returns a value if one can be found, and throws an - * exception if one cannot be found. An <code>opt</code> method returns a - * default value instead of throwing an exception, and so is useful for - * obtaining optional values. - * <p> - * The generic <code>get()</code> and <code>opt()</code> methods return an - * object which you can cast or query for type. There are also typed - * <code>get</code> and <code>opt</code> methods that do type checking and type - * coercion for you. - * <p> - * The texts produced by the <code>toString</code> methods strictly conform to - * JSON syntax rules. The constructors are more forgiving in the texts they will - * accept: - * <ul> - * <li>An extra <code>,</code> <small>(comma)</small> may appear just - * before the closing bracket.</li> - * <li>The <code>null</code> value will be inserted when there is <code>,</code> - * <small>(comma)</small> elision.</li> - * <li>Strings may be quoted with <code>'</code> <small>(single - * quote)</small>.</li> - * <li>Strings do not need to be quoted at all if they do not begin with a quote - * or single quote, and if they do not contain leading or trailing spaces, and - * if they do not contain any of these characters: - * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and - * if they are not the reserved words <code>true</code>, <code>false</code>, or - * <code>null</code>.</li> - * <li>Values can be separated by <code>;</code> <small>(semicolon)</small> as - * well as by <code>,</code> <small>(comma)</small>.</li> - * <li>Numbers may have the <code>0x-</code> <small>(hex)</small> prefix.</li> - * </ul> - * - * @author JSON.org - * @version 2011-08-25 - */ -public class JSONArray implements Serializable { - - /** - * The arrayList where the JSONArray's properties are kept. - */ - private ArrayList myArrayList; - - /** - * Construct an empty JSONArray. - */ - public JSONArray() { - myArrayList = new ArrayList(); - } - - /** - * Construct a JSONArray from a JSONTokener. - * - * @param x - * A JSONTokener - * @throws JSONException - * If there is a syntax error. - */ - public JSONArray(JSONTokener x) throws JSONException { - this(); - if (x.nextClean() != '[') { - throw x.syntaxError("A JSONArray text must start with '['"); - } - if (x.nextClean() != ']') { - x.back(); - for (;;) { - if (x.nextClean() == ',') { - x.back(); - myArrayList.add(JSONObject.NULL); - } else { - x.back(); - myArrayList.add(x.nextValue()); - } - switch (x.nextClean()) { - case ';': - case ',': - if (x.nextClean() == ']') { - return; - } - x.back(); - break; - case ']': - return; - default: - throw x.syntaxError("Expected a ',' or ']'"); - } - } - } - } - - /** - * Construct a JSONArray from a source JSON text. - * - * @param source - * A string that begins with <code>[</code> <small>(left - * bracket)</small> and ends with <code>]</code> - * <small>(right bracket)</small>. - * @throws JSONException - * If there is a syntax error. - */ - public JSONArray(String source) throws JSONException { - this(new JSONTokener(source)); - } - - /** - * Construct a JSONArray from a Collection. - * - * @param collection - * A Collection. - */ - public JSONArray(Collection collection) { - myArrayList = new ArrayList(); - if (collection != null) { - Iterator iter = collection.iterator(); - while (iter.hasNext()) { - myArrayList.add(JSONObject.wrap(iter.next())); - } - } - } - - /** - * Construct a JSONArray from an array - * - * @throws JSONException - * If not an array. - */ - public JSONArray(Object array) throws JSONException { - this(); - if (array.getClass().isArray()) { - int length = Array.getLength(array); - for (int i = 0; i < length; i += 1) { - this.put(JSONObject.wrap(Array.get(array, i))); - } - } else { - throw new JSONException( - "JSONArray initial value should be a string or collection or array."); - } - } - - /** - * Get the object value associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return An object value. - * @throws JSONException - * If there is no value for the index. - */ - public Object get(int index) throws JSONException { - Object object = opt(index); - if (object == null) { - throw new JSONException("JSONArray[" + index + "] not found."); - } - return object; - } - - /** - * Get the boolean value associated with an index. The string values "true" - * and "false" are converted to boolean. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The truth. - * @throws JSONException - * If there is no value for the index or if the value is not - * convertible to boolean. - */ - public boolean getBoolean(int index) throws JSONException { - Object object = get(index); - if (object.equals(Boolean.FALSE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("false"))) { - return false; - } else if (object.equals(Boolean.TRUE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("true"))) { - return true; - } - throw new JSONException("JSONArray[" + index + "] is not a boolean."); - } - - /** - * Get the double value associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - * @throws JSONException - * If the key is not found or if the value cannot be converted - * to a number. - */ - public double getDouble(int index) throws JSONException { - Object object = get(index); - try { - return object instanceof Number ? ((Number) object).doubleValue() - : Double.parseDouble((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - /** - * Get the int value associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - * @throws JSONException - * If the key is not found or if the value is not a number. - */ - public int getInt(int index) throws JSONException { - Object object = get(index); - try { - return object instanceof Number ? ((Number) object).intValue() - : Integer.parseInt((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - /** - * Get the JSONArray associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return A JSONArray value. - * @throws JSONException - * If there is no value for the index. or if the value is not a - * JSONArray - */ - public JSONArray getJSONArray(int index) throws JSONException { - Object object = get(index); - if (object instanceof JSONArray) { - return (JSONArray) object; - } - throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); - } - - /** - * Get the JSONObject associated with an index. - * - * @param index - * subscript - * @return A JSONObject value. - * @throws JSONException - * If there is no value for the index or if the value is not a - * JSONObject - */ - public JSONObject getJSONObject(int index) throws JSONException { - Object object = get(index); - if (object instanceof JSONObject) { - return (JSONObject) object; - } - throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); - } - - /** - * Get the long value associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - * @throws JSONException - * If the key is not found or if the value cannot be converted - * to a number. - */ - public long getLong(int index) throws JSONException { - Object object = get(index); - try { - return object instanceof Number ? ((Number) object).longValue() - : Long.parseLong((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - /** - * Get the string associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return A string value. - * @throws JSONException - * If there is no string value for the index. - */ - public String getString(int index) throws JSONException { - Object object = get(index); - if (object instanceof String) { - return (String) object; - } - throw new JSONException("JSONArray[" + index + "] not a string."); - } - - /** - * Determine if the value is null. - * - * @param index - * The index must be between 0 and length() - 1. - * @return true if the value at the index is null, or if there is no value. - */ - public boolean isNull(int index) { - return JSONObject.NULL.equals(opt(index)); - } - - /** - * Make a string from the contents of this JSONArray. The - * <code>separator</code> string is inserted between each element. Warning: - * This method assumes that the data structure is acyclical. - * - * @param separator - * A string that will be inserted between the elements. - * @return a string. - * @throws JSONException - * If the array contains an invalid number. - */ - public String join(String separator) throws JSONException { - int len = length(); - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < len; i += 1) { - if (i > 0) { - sb.append(separator); - } - sb.append(JSONObject.valueToString(myArrayList.get(i))); - } - return sb.toString(); - } - - /** - * Get the number of elements in the JSONArray, included nulls. - * - * @return The length (or size). - */ - public int length() { - return myArrayList.size(); - } - - /** - * Get the optional object value associated with an index. - * - * @param index - * The index must be between 0 and length() - 1. - * @return An object value, or null if there is no object at that index. - */ - public Object opt(int index) { - return (index < 0 || index >= length()) ? null : myArrayList.get(index); - } - - /** - * Get the optional boolean value associated with an index. It returns false - * if there is no value at that index, or if the value is not Boolean.TRUE - * or the String "true". - * - * @param index - * The index must be between 0 and length() - 1. - * @return The truth. - */ - public boolean optBoolean(int index) { - return optBoolean(index, false); - } - - /** - * Get the optional boolean value associated with an index. It returns the - * defaultValue if there is no value at that index or if it is not a Boolean - * or the String "true" or "false" (case insensitive). - * - * @param index - * The index must be between 0 and length() - 1. - * @param defaultValue - * A boolean default. - * @return The truth. - */ - public boolean optBoolean(int index, boolean defaultValue) { - try { - return getBoolean(index); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get the optional double value associated with an index. NaN is returned - * if there is no value for the index, or if the value is not a number and - * cannot be converted to a number. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - */ - public double optDouble(int index) { - return optDouble(index, Double.NaN); - } - - /** - * Get the optional double value associated with an index. The defaultValue - * is returned if there is no value for the index, or if the value is not a - * number and cannot be converted to a number. - * - * @param index - * subscript - * @param defaultValue - * The default value. - * @return The value. - */ - public double optDouble(int index, double defaultValue) { - try { - return getDouble(index); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get the optional int value associated with an index. Zero is returned if - * there is no value for the index, or if the value is not a number and - * cannot be converted to a number. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - */ - public int optInt(int index) { - return optInt(index, 0); - } - - /** - * Get the optional int value associated with an index. The defaultValue is - * returned if there is no value for the index, or if the value is not a - * number and cannot be converted to a number. - * - * @param index - * The index must be between 0 and length() - 1. - * @param defaultValue - * The default value. - * @return The value. - */ - public int optInt(int index, int defaultValue) { - try { - return getInt(index); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get the optional JSONArray associated with an index. - * - * @param index - * subscript - * @return A JSONArray value, or null if the index has no value, or if the - * value is not a JSONArray. - */ - public JSONArray optJSONArray(int index) { - Object o = opt(index); - return o instanceof JSONArray ? (JSONArray) o : null; - } - - /** - * Get the optional JSONObject associated with an index. Null is returned if - * the key is not found, or null if the index has no value, or if the value - * is not a JSONObject. - * - * @param index - * The index must be between 0 and length() - 1. - * @return A JSONObject value. - */ - public JSONObject optJSONObject(int index) { - Object o = opt(index); - return o instanceof JSONObject ? (JSONObject) o : null; - } - - /** - * Get the optional long value associated with an index. Zero is returned if - * there is no value for the index, or if the value is not a number and - * cannot be converted to a number. - * - * @param index - * The index must be between 0 and length() - 1. - * @return The value. - */ - public long optLong(int index) { - return optLong(index, 0); - } - - /** - * Get the optional long value associated with an index. The defaultValue is - * returned if there is no value for the index, or if the value is not a - * number and cannot be converted to a number. - * - * @param index - * The index must be between 0 and length() - 1. - * @param defaultValue - * The default value. - * @return The value. - */ - public long optLong(int index, long defaultValue) { - try { - return getLong(index); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get the optional string value associated with an index. It returns an - * empty string if there is no value at that index. If the value is not a - * string and is not null, then it is coverted to a string. - * - * @param index - * The index must be between 0 and length() - 1. - * @return A String value. - */ - public String optString(int index) { - return optString(index, ""); - } - - /** - * Get the optional string associated with an index. The defaultValue is - * returned if the key is not found. - * - * @param index - * The index must be between 0 and length() - 1. - * @param defaultValue - * The default value. - * @return A String value. - */ - public String optString(int index, String defaultValue) { - Object object = opt(index); - return JSONObject.NULL.equals(object) ? object.toString() - : defaultValue; - } - - /** - * Append a boolean value. This increases the array's length by one. - * - * @param value - * A boolean value. - * @return this. - */ - public JSONArray put(boolean value) { - put(value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a JSONArray which - * is produced from a Collection. - * - * @param value - * A Collection value. - * @return this. - */ - public JSONArray put(Collection value) { - put(new JSONArray(value)); - return this; - } - - /** - * Append a double value. This increases the array's length by one. - * - * @param value - * A double value. - * @throws JSONException - * if the value is not finite. - * @return this. - */ - public JSONArray put(double value) throws JSONException { - Double d = new Double(value); - JSONObject.testValidity(d); - put(d); - return this; - } - - /** - * Append an int value. This increases the array's length by one. - * - * @param value - * An int value. - * @return this. - */ - public JSONArray put(int value) { - put(new Integer(value)); - return this; - } - - /** - * Append an long value. This increases the array's length by one. - * - * @param value - * A long value. - * @return this. - */ - public JSONArray put(long value) { - put(new Long(value)); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a JSONObject which - * is produced from a Map. - * - * @param value - * A Map value. - * @return this. - */ - public JSONArray put(Map value) { - put(new JSONObject(value)); - return this; - } - - /** - * Append an object value. This increases the array's length by one. - * - * @param value - * An object value. The value should be a Boolean, Double, - * Integer, JSONArray, JSONObject, Long, or String, or the - * JSONObject.NULL object. - * @return this. - */ - public JSONArray put(Object value) { - myArrayList.add(value); - return this; - } - - /** - * Put or replace a boolean value in the JSONArray. If the index is greater - * than the length of the JSONArray, then null elements will be added as - * necessary to pad it out. - * - * @param index - * The subscript. - * @param value - * A boolean value. - * @return this. - * @throws JSONException - * If the index is negative. - */ - public JSONArray put(int index, boolean value) throws JSONException { - put(index, value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a JSONArray which - * is produced from a Collection. - * - * @param index - * The subscript. - * @param value - * A Collection value. - * @return this. - * @throws JSONException - * If the index is negative or if the value is not finite. - */ - public JSONArray put(int index, Collection value) throws JSONException { - put(index, new JSONArray(value)); - return this; - } - - /** - * Put or replace a double value. If the index is greater than the length of - * the JSONArray, then null elements will be added as necessary to pad it - * out. - * - * @param index - * The subscript. - * @param value - * A double value. - * @return this. - * @throws JSONException - * If the index is negative or if the value is not finite. - */ - public JSONArray put(int index, double value) throws JSONException { - put(index, new Double(value)); - return this; - } - - /** - * Put or replace an int value. If the index is greater than the length of - * the JSONArray, then null elements will be added as necessary to pad it - * out. - * - * @param index - * The subscript. - * @param value - * An int value. - * @return this. - * @throws JSONException - * If the index is negative. - */ - public JSONArray put(int index, int value) throws JSONException { - put(index, new Integer(value)); - return this; - } - - /** - * Put or replace a long value. If the index is greater than the length of - * the JSONArray, then null elements will be added as necessary to pad it - * out. - * - * @param index - * The subscript. - * @param value - * A long value. - * @return this. - * @throws JSONException - * If the index is negative. - */ - public JSONArray put(int index, long value) throws JSONException { - put(index, new Long(value)); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a JSONObject that - * is produced from a Map. - * - * @param index - * The subscript. - * @param value - * The Map value. - * @return this. - * @throws JSONException - * If the index is negative or if the the value is an invalid - * number. - */ - public JSONArray put(int index, Map value) throws JSONException { - put(index, new JSONObject(value)); - return this; - } - - /** - * Put or replace an object value in the JSONArray. If the index is greater - * than the length of the JSONArray, then null elements will be added as - * necessary to pad it out. - * - * @param index - * The subscript. - * @param value - * The value to put into the array. The value should be a - * Boolean, Double, Integer, JSONArray, JSONObject, Long, or - * String, or the JSONObject.NULL object. - * @return this. - * @throws JSONException - * If the index is negative or if the the value is an invalid - * number. - */ - public JSONArray put(int index, Object value) throws JSONException { - JSONObject.testValidity(value); - if (index < 0) { - throw new JSONException("JSONArray[" + index + "] not found."); - } - if (index < length()) { - myArrayList.set(index, value); - } else { - while (index != length()) { - put(JSONObject.NULL); - } - put(value); - } - return this; - } - - /** - * Remove an index and close the hole. - * - * @param index - * The index of the element to be removed. - * @return The value that was associated with the index, or null if there - * was no value. - */ - public Object remove(int index) { - Object o = opt(index); - myArrayList.remove(index); - return o; - } - - /** - * Produce a JSONObject by combining a JSONArray of names with the values of - * this JSONArray. - * - * @param names - * A JSONArray containing a list of key strings. These will be - * paired with the values. - * @return A JSONObject, or null if there are no names or if this JSONArray - * has no values. - * @throws JSONException - * If any of the names are null. - */ - public JSONObject toJSONObject(JSONArray names) throws JSONException { - if (names == null || names.length() == 0 || length() == 0) { - return null; - } - JSONObject jo = new JSONObject(); - for (int i = 0; i < names.length(); i += 1) { - jo.put(names.getString(i), opt(i)); - } - return jo; - } - - /** - * Make a JSON text of this JSONArray. For compactness, no unnecessary - * whitespace is added. If it is not possible to produce a syntactically - * correct JSON text then null will be returned instead. This could occur if - * the array contains an invalid number. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @return a printable, displayable, transmittable representation of the - * array. - */ - @Override - public String toString() { - try { - return '[' + join(",") + ']'; - } catch (Exception e) { - return null; - } - } - - /** - * Make a prettyprinted JSON text of this JSONArray. Warning: This method - * assumes that the data structure is acyclical. - * - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return a printable, displayable, transmittable representation of the - * object, beginning with <code>[</code> <small>(left - * bracket)</small> and ending with <code>]</code> - * <small>(right bracket)</small>. - * @throws JSONException - */ - public String toString(int indentFactor) throws JSONException { - return toString(indentFactor, 0); - } - - /** - * Make a prettyprinted JSON text of this JSONArray. Warning: This method - * assumes that the data structure is acyclical. - * - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @param indent - * The indention of the top level. - * @return a printable, displayable, transmittable representation of the - * array. - * @throws JSONException - */ - String toString(int indentFactor, int indent) throws JSONException { - int len = length(); - if (len == 0) { - return "[]"; - } - int i; - StringBuffer sb = new StringBuffer("["); - if (len == 1) { - sb.append(JSONObject.valueToString(myArrayList.get(0), - indentFactor, indent)); - } else { - int newindent = indent + indentFactor; - sb.append('\n'); - for (i = 0; i < len; i += 1) { - if (i > 0) { - sb.append(",\n"); - } - for (int j = 0; j < newindent; j += 1) { - sb.append(' '); - } - sb.append(JSONObject.valueToString(myArrayList.get(i), - indentFactor, newindent)); - } - sb.append('\n'); - for (i = 0; i < indent; i += 1) { - sb.append(' '); - } - } - sb.append(']'); - return sb.toString(); - } - - /** - * Write the contents of the JSONArray as JSON text to a writer. For - * compactness, no whitespace is added. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @return The writer. - * @throws JSONException - */ - public Writer write(Writer writer) throws JSONException { - try { - boolean b = false; - int len = length(); - - writer.write('['); - - for (int i = 0; i < len; i += 1) { - if (b) { - writer.write(','); - } - Object v = myArrayList.get(i); - if (v instanceof JSONObject) { - ((JSONObject) v).write(writer); - } else if (v instanceof JSONArray) { - ((JSONArray) v).write(writer); - } else { - writer.write(JSONObject.valueToString(v)); - } - b = true; - } - writer.write(']'); - return writer; - } catch (IOException e) { - throw new JSONException(e); - } - } -}
\ No newline at end of file diff --git a/server/src/com/vaadin/external/json/JSONException.java b/server/src/com/vaadin/external/json/JSONException.java deleted file mode 100644 index 21663c1e37..0000000000 --- a/server/src/com/vaadin/external/json/JSONException.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.vaadin.external.json; - -/** - * The JSONException is thrown by the JSON.org classes when things are amiss. - * - * @author JSON.org - * @version 2010-12-24 - */ -public class JSONException extends Exception { - private static final long serialVersionUID = 0; - private Throwable cause; - - /** - * Constructs a JSONException with an explanatory message. - * - * @param message - * Detail about the reason for the exception. - */ - public JSONException(String message) { - super(message); - } - - public JSONException(Throwable cause) { - super(cause.getMessage()); - this.cause = cause; - } - - @Override - public Throwable getCause() { - return cause; - } -} diff --git a/server/src/com/vaadin/external/json/JSONObject.java b/server/src/com/vaadin/external/json/JSONObject.java deleted file mode 100644 index ba772933be..0000000000 --- a/server/src/com/vaadin/external/json/JSONObject.java +++ /dev/null @@ -1,1693 +0,0 @@ -package com.vaadin.external.json; - -/* - Copyright (c) 2002 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -import java.io.IOException; -import java.io.Serializable; -import java.io.Writer; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -/** - * A JSONObject is an unordered collection of name/value pairs. Its external - * form is a string wrapped in curly braces with colons between the names and - * values, and commas between the values and names. The internal form is an - * object having <code>get</code> and <code>opt</code> methods for accessing the - * values by name, and <code>put</code> methods for adding or replacing values - * by name. The values can be any of these types: <code>Boolean</code>, - * <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>, - * <code>String</code>, or the <code>JSONObject.NULL</code> object. A JSONObject - * constructor can be used to convert an external form JSON text into an - * internal form whose values can be retrieved with the <code>get</code> and - * <code>opt</code> methods, or to convert values into a JSON text using the - * <code>put</code> and <code>toString</code> methods. A <code>get</code> method - * returns a value if one can be found, and throws an exception if one cannot be - * found. An <code>opt</code> method returns a default value instead of throwing - * an exception, and so is useful for obtaining optional values. - * <p> - * The generic <code>get()</code> and <code>opt()</code> methods return an - * object, which you can cast or query for type. There are also typed - * <code>get</code> and <code>opt</code> methods that do type checking and type - * coercion for you. The opt methods differ from the get methods in that they do - * not throw. Instead, they return a specified value, such as null. - * <p> - * The <code>put</code> methods add or replace values in an object. For example, - * - * <pre> - * myString = new JSONObject().put("JSON", "Hello, World!").toString(); - * </pre> - * - * produces the string <code>{"JSON": "Hello, World"}</code>. - * <p> - * The texts produced by the <code>toString</code> methods strictly conform to - * the JSON syntax rules. The constructors are more forgiving in the texts they - * will accept: - * <ul> - * <li>An extra <code>,</code> <small>(comma)</small> may appear just - * before the closing brace.</li> - * <li>Strings may be quoted with <code>'</code> <small>(single - * quote)</small>.</li> - * <li>Strings do not need to be quoted at all if they do not begin with a quote - * or single quote, and if they do not contain leading or trailing spaces, and - * if they do not contain any of these characters: - * <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and - * if they are not the reserved words <code>true</code>, <code>false</code>, or - * <code>null</code>.</li> - * <li>Keys can be followed by <code>=</code> or <code>=></code> as well as by - * <code>:</code>.</li> - * <li>Values can be followed by <code>;</code> <small>(semicolon)</small> as - * well as by <code>,</code> <small>(comma)</small>.</li> - * <li>Numbers may have the <code>0x-</code> <small>(hex)</small> prefix.</li> - * </ul> - * - * @author JSON.org - * @version 2011-10-16 - */ -public class JSONObject implements Serializable { - - /** - * JSONObject.NULL is equivalent to the value that JavaScript calls null, - * whilst Java's null is equivalent to the value that JavaScript calls - * undefined. - */ - private static final class Null implements Serializable { - - /** - * There is only intended to be a single instance of the NULL object, so - * the clone method returns itself. - * - * @return NULL. - */ - @Override - protected final Object clone() { - return this; - } - - /** - * A Null object is equal to the null value and to itself. - * - * @param object - * An object to test for nullness. - * @return true if the object parameter is the JSONObject.NULL object or - * null. - */ - @Override - public boolean equals(Object object) { - return object == null || object == this; - } - - /** - * Get the "null" string value. - * - * @return The string "null". - */ - @Override - public String toString() { - return "null"; - } - } - - /** - * The map where the JSONObject's properties are kept. - */ - private Map map; - - /** - * It is sometimes more convenient and less ambiguous to have a - * <code>NULL</code> object than to use Java's <code>null</code> value. - * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>. - * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>. - */ - public static final Object NULL = new Null(); - - /** - * Construct an empty JSONObject. - */ - public JSONObject() { - map = new HashMap(); - } - - /** - * Construct a JSONObject from a subset of another JSONObject. An array of - * strings is used to identify the keys that should be copied. Missing keys - * are ignored. - * - * @param jo - * A JSONObject. - * @param names - * An array of strings. - * @throws JSONException - * @exception JSONException - * If a value is a non-finite number or if a name is - * duplicated. - */ - public JSONObject(JSONObject jo, String[] names) { - this(); - for (int i = 0; i < names.length; i += 1) { - try { - putOnce(names[i], jo.opt(names[i])); - } catch (Exception ignore) { - } - } - } - - /** - * Construct a JSONObject from a JSONTokener. - * - * @param x - * A JSONTokener object containing the source string. - * @throws JSONException - * If there is a syntax error in the source string or a - * duplicated key. - */ - public JSONObject(JSONTokener x) throws JSONException { - this(); - char c; - String key; - - if (x.nextClean() != '{') { - throw x.syntaxError("A JSONObject text must begin with '{'"); - } - for (;;) { - c = x.nextClean(); - switch (c) { - case 0: - throw x.syntaxError("A JSONObject text must end with '}'"); - case '}': - return; - default: - x.back(); - key = x.nextValue().toString(); - } - - // The key is followed by ':'. We will also tolerate '=' or '=>'. - - c = x.nextClean(); - if (c == '=') { - if (x.next() != '>') { - x.back(); - } - } else if (c != ':') { - throw x.syntaxError("Expected a ':' after a key"); - } - putOnce(key, x.nextValue()); - - // Pairs are separated by ','. We will also tolerate ';'. - - switch (x.nextClean()) { - case ';': - case ',': - if (x.nextClean() == '}') { - return; - } - x.back(); - break; - case '}': - return; - default: - throw x.syntaxError("Expected a ',' or '}'"); - } - } - } - - /** - * Construct a JSONObject from a Map. - * - * @param map - * A map object that can be used to initialize the contents of - * the JSONObject. - * @throws JSONException - */ - public JSONObject(Map map) { - this.map = new HashMap(); - if (map != null) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); - Object value = e.getValue(); - if (value != null) { - this.map.put(e.getKey(), wrap(value)); - } - } - } - } - - /** - * Construct a JSONObject from an Object using bean getters. It reflects on - * all of the public methods of the object. For each of the methods with no - * parameters and a name starting with <code>"get"</code> or - * <code>"is"</code> followed by an uppercase letter, the method is invoked, - * and a key and the value returned from the getter method are put into the - * new JSONObject. - * - * The key is formed by removing the <code>"get"</code> or <code>"is"</code> - * prefix. If the second remaining character is not upper case, then the - * first character is converted to lower case. - * - * For example, if an object has a method named <code>"getName"</code>, and - * if the result of calling <code>object.getName()</code> is - * <code>"Larry Fine"</code>, then the JSONObject will contain - * <code>"name": "Larry Fine"</code>. - * - * @param bean - * An object that has getter methods that should be used to make - * a JSONObject. - */ - public JSONObject(Object bean) { - this(); - populateMap(bean); - } - - /** - * Construct a JSONObject from an Object, using reflection to find the - * public members. The resulting JSONObject's keys will be the strings from - * the names array, and the values will be the field values associated with - * those keys in the object. If a key is not found or not visible, then it - * will not be copied into the new JSONObject. - * - * @param object - * An object that has fields that should be used to make a - * JSONObject. - * @param names - * An array of strings, the names of the fields to be obtained - * from the object. - */ - public JSONObject(Object object, String names[]) { - this(); - Class c = object.getClass(); - for (int i = 0; i < names.length; i += 1) { - String name = names[i]; - try { - putOpt(name, c.getField(name).get(object)); - } catch (Exception ignore) { - } - } - } - - /** - * Construct a JSONObject from a source JSON text string. This is the most - * commonly used JSONObject constructor. - * - * @param source - * A string beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> - * <small>(right brace)</small>. - * @exception JSONException - * If there is a syntax error in the source string or a - * duplicated key. - */ - public JSONObject(String source) throws JSONException { - this(new JSONTokener(source)); - } - - /** - * Construct a JSONObject from a ResourceBundle. - * - * @param baseName - * The ResourceBundle base name. - * @param locale - * The Locale to load the ResourceBundle for. - * @throws JSONException - * If any JSONExceptions are detected. - */ - public JSONObject(String baseName, Locale locale) throws JSONException { - this(); - ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, - Thread.currentThread().getContextClassLoader()); - - // Iterate through the keys in the bundle. - - Enumeration keys = bundle.getKeys(); - while (keys.hasMoreElements()) { - Object key = keys.nextElement(); - if (key instanceof String) { - - // Go through the path, ensuring that there is a nested - // JSONObject for each - // segment except the last. Add the value using the last - // segment's name into - // the deepest nested JSONObject. - - String[] path = ((String) key).split("\\."); - int last = path.length - 1; - JSONObject target = this; - for (int i = 0; i < last; i += 1) { - String segment = path[i]; - JSONObject nextTarget = target.optJSONObject(segment); - if (nextTarget == null) { - nextTarget = new JSONObject(); - target.put(segment, nextTarget); - } - target = nextTarget; - } - target.put(path[last], bundle.getString((String) key)); - } - } - } - - /** - * Accumulate values under a key. It is similar to the put method except - * that if there is already an object stored under the key then a JSONArray - * is stored under the key to hold all of the accumulated values. If there - * is already a JSONArray, then the new value is appended to it. In - * contrast, the put method replaces the previous value. - * - * If only one value is accumulated that is not a JSONArray, then the result - * will be the same as using put. But if multiple values are accumulated, - * then the result will be like append. - * - * @param key - * A key string. - * @param value - * An object to be accumulated under the key. - * @return this. - * @throws JSONException - * If the value is an invalid number or if the key is null. - */ - public JSONObject accumulate(String key, Object value) throws JSONException { - testValidity(value); - Object object = opt(key); - if (object == null) { - put(key, value instanceof JSONArray ? new JSONArray().put(value) - : value); - } else if (object instanceof JSONArray) { - ((JSONArray) object).put(value); - } else { - put(key, new JSONArray().put(object).put(value)); - } - return this; - } - - /** - * Append values to the array under a key. If the key does not exist in the - * JSONObject, then the key is put in the JSONObject with its value being a - * JSONArray containing the value parameter. If the key was already - * associated with a JSONArray, then the value parameter is appended to it. - * - * @param key - * A key string. - * @param value - * An object to be accumulated under the key. - * @return this. - * @throws JSONException - * If the key is null or if the current value associated with - * the key is not a JSONArray. - */ - public JSONObject append(String key, Object value) throws JSONException { - testValidity(value); - Object object = opt(key); - if (object == null) { - put(key, new JSONArray().put(value)); - } else if (object instanceof JSONArray) { - put(key, ((JSONArray) object).put(value)); - } else { - throw new JSONException("JSONObject[" + key - + "] is not a JSONArray."); - } - return this; - } - - /** - * Produce a string from a double. The string "null" will be returned if the - * number is not finite. - * - * @param d - * A double. - * @return A String. - */ - public static String doubleToString(double d) { - if (Double.isInfinite(d) || Double.isNaN(d)) { - return "null"; - } - - // Shave off trailing zeros and decimal point, if possible. - - String string = Double.toString(d); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 - && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - - /** - * Get the value object associated with a key. - * - * @param key - * A key string. - * @return The object associated with the key. - * @throws JSONException - * if the key is not found. - */ - public Object get(String key) throws JSONException { - if (key == null) { - throw new JSONException("Null key."); - } - Object object = opt(key); - if (object == null) { - throw new JSONException("JSONObject[" + quote(key) + "] not found."); - } - return object; - } - - /** - * Get the boolean value associated with a key. - * - * @param key - * A key string. - * @return The truth. - * @throws JSONException - * if the value is not a Boolean or the String "true" or - * "false". - */ - public boolean getBoolean(String key) throws JSONException { - Object object = get(key); - if (object.equals(Boolean.FALSE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("false"))) { - return false; - } else if (object.equals(Boolean.TRUE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("true"))) { - return true; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a Boolean."); - } - - /** - * Get the double value associated with a key. - * - * @param key - * A key string. - * @return The numeric value. - * @throws JSONException - * if the key is not found or if the value is not a Number - * object and cannot be converted to a number. - */ - public double getDouble(String key) throws JSONException { - Object object = get(key); - try { - return object instanceof Number ? ((Number) object).doubleValue() - : Double.parseDouble((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not a number."); - } - } - - /** - * Get the int value associated with a key. - * - * @param key - * A key string. - * @return The integer value. - * @throws JSONException - * if the key is not found or if the value cannot be converted - * to an integer. - */ - public int getInt(String key) throws JSONException { - Object object = get(key); - try { - return object instanceof Number ? ((Number) object).intValue() - : Integer.parseInt((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not an int."); - } - } - - /** - * Get the JSONArray value associated with a key. - * - * @param key - * A key string. - * @return A JSONArray which is the value. - * @throws JSONException - * if the key is not found or if the value is not a JSONArray. - */ - public JSONArray getJSONArray(String key) throws JSONException { - Object object = get(key); - if (object instanceof JSONArray) { - return (JSONArray) object; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a JSONArray."); - } - - /** - * Get the JSONObject value associated with a key. - * - * @param key - * A key string. - * @return A JSONObject which is the value. - * @throws JSONException - * if the key is not found or if the value is not a JSONObject. - */ - public JSONObject getJSONObject(String key) throws JSONException { - Object object = get(key); - if (object instanceof JSONObject) { - return (JSONObject) object; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a JSONObject."); - } - - /** - * Get the long value associated with a key. - * - * @param key - * A key string. - * @return The long value. - * @throws JSONException - * if the key is not found or if the value cannot be converted - * to a long. - */ - public long getLong(String key) throws JSONException { - Object object = get(key); - try { - return object instanceof Number ? ((Number) object).longValue() - : Long.parseLong((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not a long."); - } - } - - /** - * Get an array of field names from a JSONObject. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(JSONObject jo) { - int length = jo.length(); - if (length == 0) { - return null; - } - Iterator iterator = jo.keys(); - String[] names = new String[length]; - int i = 0; - while (iterator.hasNext()) { - names[i] = (String) iterator.next(); - i += 1; - } - return names; - } - - /** - * Get an array of field names from an Object. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(Object object) { - if (object == null) { - return null; - } - Class klass = object.getClass(); - Field[] fields = klass.getFields(); - int length = fields.length; - if (length == 0) { - return null; - } - String[] names = new String[length]; - for (int i = 0; i < length; i += 1) { - names[i] = fields[i].getName(); - } - return names; - } - - /** - * Get the string associated with a key. - * - * @param key - * A key string. - * @return A string which is the value. - * @throws JSONException - * if there is no string value for the key. - */ - public String getString(String key) throws JSONException { - Object object = get(key); - if (object instanceof String) { - return (String) object; - } - throw new JSONException("JSONObject[" + quote(key) + "] not a string."); - } - - /** - * Determine if the JSONObject contains a specific key. - * - * @param key - * A key string. - * @return true if the key exists in the JSONObject. - */ - public boolean has(String key) { - return map.containsKey(key); - } - - /** - * Increment a property of a JSONObject. If there is no such property, - * create one with a value of 1. If there is such a property, and if it is - * an Integer, Long, Double, or Float, then add one to it. - * - * @param key - * A key string. - * @return this. - * @throws JSONException - * If there is already a property with this name that is not an - * Integer, Long, Double, or Float. - */ - public JSONObject increment(String key) throws JSONException { - Object value = opt(key); - if (value == null) { - put(key, 1); - } else if (value instanceof Integer) { - put(key, ((Integer) value).intValue() + 1); - } else if (value instanceof Long) { - put(key, ((Long) value).longValue() + 1); - } else if (value instanceof Double) { - put(key, ((Double) value).doubleValue() + 1); - } else if (value instanceof Float) { - put(key, ((Float) value).floatValue() + 1); - } else { - throw new JSONException("Unable to increment [" + quote(key) + "]."); - } - return this; - } - - /** - * Determine if the value associated with the key is null or if there is no - * value. - * - * @param key - * A key string. - * @return true if there is no value associated with the key or if the value - * is the JSONObject.NULL object. - */ - public boolean isNull(String key) { - return JSONObject.NULL.equals(opt(key)); - } - - /** - * Get an enumeration of the keys of the JSONObject. - * - * @return An iterator of the keys. - */ - public Iterator keys() { - return map.keySet().iterator(); - } - - /** - * Get the number of keys stored in the JSONObject. - * - * @return The number of keys in the JSONObject. - */ - public int length() { - return map.size(); - } - - /** - * Produce a JSONArray containing the names of the elements of this - * JSONObject. - * - * @return A JSONArray containing the key strings, or null if the JSONObject - * is empty. - */ - public JSONArray names() { - JSONArray ja = new JSONArray(); - Iterator keys = keys(); - while (keys.hasNext()) { - ja.put(keys.next()); - } - return ja.length() == 0 ? null : ja; - } - - /** - * Produce a string from a Number. - * - * @param number - * A Number - * @return A String. - * @throws JSONException - * If n is a non-finite number. - */ - public static String numberToString(Number number) throws JSONException { - if (number == null) { - throw new JSONException("Null pointer"); - } - testValidity(number); - - // Shave off trailing zeros and decimal point, if possible. - - String string = number.toString(); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 - && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - - /** - * Get an optional value associated with a key. - * - * @param key - * A key string. - * @return An object which is the value, or null if there is no value. - */ - public Object opt(String key) { - return key == null ? null : map.get(key); - } - - /** - * Get an optional boolean associated with a key. It returns false if there - * is no such key, or if the value is not Boolean.TRUE or the String "true". - * - * @param key - * A key string. - * @return The truth. - */ - public boolean optBoolean(String key) { - return optBoolean(key, false); - } - - /** - * Get an optional boolean associated with a key. It returns the - * defaultValue if there is no such key, or if it is not a Boolean or the - * String "true" or "false" (case insensitive). - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return The truth. - */ - public boolean optBoolean(String key, boolean defaultValue) { - try { - return getBoolean(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional double associated with a key, or NaN if there is no such - * key or if its value is not a number. If the value is a string, an attempt - * will be made to evaluate it as a number. - * - * @param key - * A string which is the key. - * @return An object which is the value. - */ - public double optDouble(String key) { - return optDouble(key, Double.NaN); - } - - /** - * Get an optional double associated with a key, or the defaultValue if - * there is no such key or if its value is not a number. If the value is a - * string, an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public double optDouble(String key, double defaultValue) { - try { - return getDouble(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional int value associated with a key, or zero if there is no - * such key or if the value is not a number. If the value is a string, an - * attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @return An object which is the value. - */ - public int optInt(String key) { - return optInt(key, 0); - } - - /** - * Get an optional int value associated with a key, or the default if there - * is no such key or if the value is not a number. If the value is a string, - * an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public int optInt(String key, int defaultValue) { - try { - return getInt(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional JSONArray associated with a key. It returns null if there - * is no such key, or if its value is not a JSONArray. - * - * @param key - * A key string. - * @return A JSONArray which is the value. - */ - public JSONArray optJSONArray(String key) { - Object o = opt(key); - return o instanceof JSONArray ? (JSONArray) o : null; - } - - /** - * Get an optional JSONObject associated with a key. It returns null if - * there is no such key, or if its value is not a JSONObject. - * - * @param key - * A key string. - * @return A JSONObject which is the value. - */ - public JSONObject optJSONObject(String key) { - Object object = opt(key); - return object instanceof JSONObject ? (JSONObject) object : null; - } - - /** - * Get an optional long value associated with a key, or zero if there is no - * such key or if the value is not a number. If the value is a string, an - * attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @return An object which is the value. - */ - public long optLong(String key) { - return optLong(key, 0); - } - - /** - * Get an optional long value associated with a key, or the default if there - * is no such key or if the value is not a number. If the value is a string, - * an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public long optLong(String key, long defaultValue) { - try { - return getLong(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional string associated with a key. It returns an empty string - * if there is no such key. If the value is not a string and is not null, - * then it is converted to a string. - * - * @param key - * A key string. - * @return A string which is the value. - */ - public String optString(String key) { - return optString(key, ""); - } - - /** - * Get an optional string associated with a key. It returns the defaultValue - * if there is no such key. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return A string which is the value. - */ - public String optString(String key, String defaultValue) { - Object object = opt(key); - return NULL.equals(object) ? defaultValue : object.toString(); - } - - private void populateMap(Object bean) { - Class klass = bean.getClass(); - - // If klass is a System class then set includeSuperClass to false. - - boolean includeSuperClass = klass.getClassLoader() != null; - - Method[] methods = (includeSuperClass) ? klass.getMethods() : klass - .getDeclaredMethods(); - for (int i = 0; i < methods.length; i += 1) { - try { - Method method = methods[i]; - if (Modifier.isPublic(method.getModifiers())) { - String name = method.getName(); - String key = ""; - if (name.startsWith("get")) { - if (name.equals("getClass") - || name.equals("getDeclaringClass")) { - key = ""; - } else { - key = name.substring(3); - } - } else if (name.startsWith("is")) { - key = name.substring(2); - } - if (key.length() > 0 - && Character.isUpperCase(key.charAt(0)) - && method.getParameterTypes().length == 0) { - if (key.length() == 1) { - key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { - key = key.substring(0, 1).toLowerCase() - + key.substring(1); - } - - Object result = method.invoke(bean, (Object[]) null); - if (result != null) { - map.put(key, wrap(result)); - } - } - } - } catch (Exception ignore) { - } - } - } - - /** - * Put a key/boolean pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A boolean which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, boolean value) throws JSONException { - put(key, value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONArray which is produced from a Collection. - * - * @param key - * A key string. - * @param value - * A Collection value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, Collection value) throws JSONException { - put(key, new JSONArray(value)); - return this; - } - - /** - * Put a key/double pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A double which is the value. - * @return this. - * @throws JSONException - * If the key is null or if the number is invalid. - */ - public JSONObject put(String key, double value) throws JSONException { - put(key, new Double(value)); - return this; - } - - /** - * Put a key/int pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * An int which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, int value) throws JSONException { - put(key, new Integer(value)); - return this; - } - - /** - * Put a key/long pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A long which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, long value) throws JSONException { - put(key, new Long(value)); - return this; - } - - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONObject which is produced from a Map. - * - * @param key - * A key string. - * @param value - * A Map value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, Map value) throws JSONException { - put(key, new JSONObject(value)); - return this; - } - - /** - * Put a key/value pair in the JSONObject. If the value is null, then the - * key will be removed from the JSONObject if it is present. - * - * @param key - * A key string. - * @param value - * An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. - * @return this. - * @throws JSONException - * If the value is non-finite number or if the key is null. - */ - public JSONObject put(String key, Object value) throws JSONException { - if (key == null) { - throw new JSONException("Null key."); - } - if (value != null) { - testValidity(value); - map.put(key, value); - } else { - remove(key); - } - return this; - } - - /** - * Put a key/value pair in the JSONObject, but only if the key and the value - * are both non-null, and only if there is not already a member with that - * name. - * - * @param key - * @param value - * @return his. - * @throws JSONException - * if the key is a duplicate - */ - public JSONObject putOnce(String key, Object value) throws JSONException { - if (key != null && value != null) { - if (opt(key) != null) { - throw new JSONException("Duplicate key \"" + key + "\""); - } - put(key, value); - } - return this; - } - - /** - * Put a key/value pair in the JSONObject, but only if the key and the value - * are both non-null. - * - * @param key - * A key string. - * @param value - * An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. - * @return this. - * @throws JSONException - * If the value is a non-finite number. - */ - public JSONObject putOpt(String key, Object value) throws JSONException { - if (key != null && value != null) { - put(key, value); - } - return this; - } - - /** - * Produce a string in double quotes with backslash sequences in all the - * right places. A backslash will be inserted within </, producing <\/, - * allowing JSON text to be delivered in HTML. In JSON text, a string cannot - * contain a control character or an unescaped quote or backslash. - * - * @param string - * A String - * @return A String correctly formatted for insertion in a JSON text. - */ - public static String quote(String string) { - if (string == null || string.length() == 0) { - return "\"\""; - } - - char b; - char c = 0; - String hhhh; - int i; - int len = string.length(); - StringBuffer sb = new StringBuffer(len + 4); - - sb.append('"'); - for (i = 0; i < len; i += 1) { - b = c; - c = string.charAt(i); - switch (c) { - case '\\': - case '"': - sb.append('\\'); - sb.append(c); - break; - case '/': - if (b == '<') { - sb.append('\\'); - } - sb.append(c); - break; - case '\b': - sb.append("\\b"); - break; - case '\t': - sb.append("\\t"); - break; - case '\n': - sb.append("\\n"); - break; - case '\f': - sb.append("\\f"); - break; - case '\r': - sb.append("\\r"); - break; - default: - if (c < ' ' || (c >= '\u0080' && c < '\u00a0') - || (c >= '\u2000' && c < '\u2100')) { - hhhh = "000" + Integer.toHexString(c); - sb.append("\\u" + hhhh.substring(hhhh.length() - 4)); - } else { - sb.append(c); - } - } - } - sb.append('"'); - return sb.toString(); - } - - /** - * Remove a name and its value, if present. - * - * @param key - * The name to be removed. - * @return The value that was associated with the name, or null if there was - * no value. - */ - public Object remove(String key) { - return map.remove(key); - } - - /** - * Try to convert a string into a number, boolean, or null. If the string - * can't be converted, return the string. - * - * @param string - * A String. - * @return A simple JSON value. - */ - public static Object stringToValue(String string) { - Double d; - if (string.equals("")) { - return string; - } - if (string.equalsIgnoreCase("true")) { - return Boolean.TRUE; - } - if (string.equalsIgnoreCase("false")) { - return Boolean.FALSE; - } - if (string.equalsIgnoreCase("null")) { - return JSONObject.NULL; - } - - /* - * If it might be a number, try converting it. We support the - * non-standard 0x- convention. If a number cannot be produced, then the - * value will just be a string. Note that the 0x-, plus, and implied - * string conventions are non-standard. A JSON parser may accept - * non-JSON forms as long as it accepts all correct JSON forms. - */ - - char b = string.charAt(0); - if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { - if (b == '0' && string.length() > 2 - && (string.charAt(1) == 'x' || string.charAt(1) == 'X')) { - try { - return new Integer( - Integer.parseInt(string.substring(2), 16)); - } catch (Exception ignore) { - } - } - try { - if (string.indexOf('.') > -1 || string.indexOf('e') > -1 - || string.indexOf('E') > -1) { - d = Double.valueOf(string); - if (!d.isInfinite() && !d.isNaN()) { - return d; - } - } else { - Long myLong = new Long(string); - if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); - } else { - return myLong; - } - } - } catch (Exception ignore) { - } - } - return string; - } - - /** - * Throw an exception if the object is a NaN or infinite number. - * - * @param o - * The object to test. - * @throws JSONException - * If o is a non-finite number. - */ - public static void testValidity(Object o) throws JSONException { - if (o != null) { - if (o instanceof Double) { - if (((Double) o).isInfinite() || ((Double) o).isNaN()) { - throw new JSONException( - "JSON does not allow non-finite numbers."); - } - } else if (o instanceof Float) { - if (((Float) o).isInfinite() || ((Float) o).isNaN()) { - throw new JSONException( - "JSON does not allow non-finite numbers."); - } - } - } - } - - /** - * Produce a JSONArray containing the values of the members of this - * JSONObject. - * - * @param names - * A JSONArray containing a list of key strings. This determines - * the sequence of the values in the result. - * @return A JSONArray of values. - * @throws JSONException - * If any of the values are non-finite numbers. - */ - public JSONArray toJSONArray(JSONArray names) throws JSONException { - if (names == null || names.length() == 0) { - return null; - } - JSONArray ja = new JSONArray(); - for (int i = 0; i < names.length(); i += 1) { - ja.put(opt(names.getString(i))); - } - return ja; - } - - /** - * Make a JSON text of this JSONObject. For compactness, no whitespace is - * added. If this would not result in a syntactically correct JSON text, - * then null will be returned instead. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> <small>(right - * brace)</small>. - */ - @Override - public String toString() { - try { - Iterator keys = keys(); - StringBuffer sb = new StringBuffer("{"); - - while (keys.hasNext()) { - if (sb.length() > 1) { - sb.append(','); - } - Object o = keys.next(); - sb.append(quote(o.toString())); - sb.append(':'); - sb.append(valueToString(map.get(o))); - } - sb.append('}'); - return sb.toString(); - } catch (Exception e) { - return null; - } - } - - /** - * Make a prettyprinted JSON text of this JSONObject. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> <small>(right - * brace)</small>. - * @throws JSONException - * If the object contains an invalid number. - */ - public String toString(int indentFactor) throws JSONException { - return toString(indentFactor, 0); - } - - /** - * Make a prettyprinted JSON text of this JSONObject. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @param indent - * The indentation of the top level. - * @return a printable, displayable, transmittable representation of the - * object, beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> <small>(right - * brace)</small>. - * @throws JSONException - * If the object contains an invalid number. - */ - String toString(int indentFactor, int indent) throws JSONException { - int i; - int length = length(); - if (length == 0) { - return "{}"; - } - Iterator keys = keys(); - int newindent = indent + indentFactor; - Object object; - StringBuffer sb = new StringBuffer("{"); - if (length == 1) { - object = keys.next(); - sb.append(quote(object.toString())); - sb.append(": "); - sb.append(valueToString(map.get(object), indentFactor, indent)); - } else { - while (keys.hasNext()) { - object = keys.next(); - if (sb.length() > 1) { - sb.append(",\n"); - } else { - sb.append('\n'); - } - for (i = 0; i < newindent; i += 1) { - sb.append(' '); - } - sb.append(quote(object.toString())); - sb.append(": "); - sb.append(valueToString(map.get(object), indentFactor, - newindent)); - } - if (sb.length() > 1) { - sb.append('\n'); - for (i = 0; i < indent; i += 1) { - sb.append(' '); - } - } - } - sb.append('}'); - return sb.toString(); - } - - /** - * Make a JSON text of an Object value. If the object has an - * value.toJSONString() method, then that method will be used to produce the - * JSON text. The method is required to produce a strictly conforming text. - * If the object does not contain a toJSONString method (which is the most - * common case), then a text will be produced by other means. If the value - * is an array or Collection, then a JSONArray will be made from it and its - * toJSONString method will be called. If the value is a MAP, then a - * JSONObject will be made from it and its toJSONString method will be - * called. Otherwise, the value's toString method will be called, and the - * result will be quoted. - * - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @param value - * The value to be serialized. - * @return a printable, displayable, transmittable representation of the - * object, beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> <small>(right - * brace)</small>. - * @throws JSONException - * If the value is or contains an invalid number. - */ - public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { - return "null"; - } - if (value instanceof JSONString) { - Object object; - try { - object = ((JSONString) value).toJSONString(); - } catch (Exception e) { - throw new JSONException(e); - } - if (object instanceof String) { - return (String) object; - } - throw new JSONException("Bad value from toJSONString: " + object); - } - if (value instanceof Number) { - return numberToString((Number) value); - } - if (value instanceof Boolean || value instanceof JSONObject - || value instanceof JSONArray) { - return value.toString(); - } - if (value instanceof Map) { - return new JSONObject((Map) value).toString(); - } - if (value instanceof Collection) { - return new JSONArray((Collection) value).toString(); - } - if (value.getClass().isArray()) { - return new JSONArray(value).toString(); - } - return quote(value.toString()); - } - - /** - * Make a prettyprinted JSON text of an object value. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @param value - * The value to be serialized. - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @param indent - * The indentation of the top level. - * @return a printable, displayable, transmittable representation of the - * object, beginning with <code>{</code> <small>(left - * brace)</small> and ending with <code>}</code> <small>(right - * brace)</small>. - * @throws JSONException - * If the object contains an invalid number. - */ - static String valueToString(Object value, int indentFactor, int indent) - throws JSONException { - if (value == null || value.equals(null)) { - return "null"; - } - try { - if (value instanceof JSONString) { - Object o = ((JSONString) value).toJSONString(); - if (o instanceof String) { - return (String) o; - } - } - } catch (Exception ignore) { - } - if (value instanceof Number) { - return numberToString((Number) value); - } - if (value instanceof Boolean) { - return value.toString(); - } - if (value instanceof JSONObject) { - return ((JSONObject) value).toString(indentFactor, indent); - } - if (value instanceof JSONArray) { - return ((JSONArray) value).toString(indentFactor, indent); - } - if (value instanceof Map) { - return new JSONObject((Map) value).toString(indentFactor, indent); - } - if (value instanceof Collection) { - return new JSONArray((Collection) value).toString(indentFactor, - indent); - } - if (value.getClass().isArray()) { - return new JSONArray(value).toString(indentFactor, indent); - } - return quote(value.toString()); - } - - /** - * Wrap an object, if necessary. If the object is null, return the NULL - * object. If it is an array or collection, wrap it in a JSONArray. If it is - * a map, wrap it in a JSONObject. If it is a standard property (Double, - * String, et al) then it is already wrapped. Otherwise, if it comes from - * one of the java packages, turn it into a string. And if it doesn't, try - * to wrap it in a JSONObject. If the wrapping fails, then null is returned. - * - * @param object - * The object to wrap - * @return The wrapped value - */ - public static Object wrap(Object object) { - try { - if (object == null) { - return NULL; - } - if (object instanceof JSONObject || object instanceof JSONArray - || NULL.equals(object) || object instanceof JSONString - || object instanceof Byte || object instanceof Character - || object instanceof Short || object instanceof Integer - || object instanceof Long || object instanceof Boolean - || object instanceof Float || object instanceof Double - || object instanceof String) { - return object; - } - - if (object instanceof Collection) { - return new JSONArray((Collection) object); - } - if (object.getClass().isArray()) { - return new JSONArray(object); - } - if (object instanceof Map) { - return new JSONObject((Map) object); - } - Package objectPackage = object.getClass().getPackage(); - String objectPackageName = objectPackage != null ? objectPackage - .getName() : ""; - if (objectPackageName.startsWith("java.") - || objectPackageName.startsWith("javax.") - || object.getClass().getClassLoader() == null) { - return object.toString(); - } - return new JSONObject(object); - } catch (Exception exception) { - return null; - } - } - - /** - * Write the contents of the JSONObject as JSON text to a writer. For - * compactness, no whitespace is added. - * <p> - * Warning: This method assumes that the data structure is acyclical. - * - * @return The writer. - * @throws JSONException - */ - public Writer write(Writer writer) throws JSONException { - try { - boolean commanate = false; - Iterator keys = keys(); - writer.write('{'); - - while (keys.hasNext()) { - if (commanate) { - writer.write(','); - } - Object key = keys.next(); - writer.write(quote(key.toString())); - writer.write(':'); - Object value = map.get(key); - if (value instanceof JSONObject) { - ((JSONObject) value).write(writer); - } else if (value instanceof JSONArray) { - ((JSONArray) value).write(writer); - } else { - writer.write(valueToString(value)); - } - commanate = true; - } - writer.write('}'); - return writer; - } catch (IOException exception) { - throw new JSONException(exception); - } - } -}
\ No newline at end of file diff --git a/server/src/com/vaadin/external/json/JSONString.java b/server/src/com/vaadin/external/json/JSONString.java deleted file mode 100644 index cc7e4d8c07..0000000000 --- a/server/src/com/vaadin/external/json/JSONString.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.vaadin.external.json; - -import java.io.Serializable; - -/** - * The <code>JSONString</code> interface allows a <code>toJSONString()</code> - * method so that a class can change the behavior of - * <code>JSONObject.toString()</code>, <code>JSONArray.toString()</code>, and - * <code>JSONWriter.value(</code>Object<code>)</code>. The - * <code>toJSONString</code> method will be used instead of the default behavior - * of using the Object's <code>toString()</code> method and quoting the result. - */ -public interface JSONString extends Serializable { - /** - * The <code>toJSONString</code> method allows a class to produce its own - * JSON serialization. - * - * @return A strictly syntactically correct JSON text. - */ - public String toJSONString(); -} diff --git a/server/src/com/vaadin/external/json/JSONStringer.java b/server/src/com/vaadin/external/json/JSONStringer.java deleted file mode 100644 index b5917222b1..0000000000 --- a/server/src/com/vaadin/external/json/JSONStringer.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.vaadin.external.json; - -/* - Copyright (c) 2006 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -import java.io.StringWriter; - -/** - * JSONStringer provides a quick and convenient way of producing JSON text. The - * texts produced strictly conform to JSON syntax rules. No whitespace is added, - * so the results are ready for transmission or storage. Each instance of - * JSONStringer can produce one JSON text. - * <p> - * A JSONStringer instance provides a <code>value</code> method for appending - * values to the text, and a <code>key</code> method for adding keys before - * values in objects. There are <code>array</code> and <code>endArray</code> - * methods that make and bound array values, and <code>object</code> and - * <code>endObject</code> methods which make and bound object values. All of - * these methods return the JSONWriter instance, permitting cascade style. For - * example, - * - * <pre> - * myString = new JSONStringer().object().key("JSON").value("Hello, World!") - * .endObject().toString(); - * </pre> - * - * which produces the string - * - * <pre> - * {"JSON":"Hello, World!"} - * </pre> - * <p> - * The first method called must be <code>array</code> or <code>object</code>. - * There are no methods for adding commas or colons. JSONStringer adds them for - * you. Objects and arrays can be nested up to 20 levels deep. - * <p> - * This can sometimes be easier than using a JSONObject to build a string. - * - * @author JSON.org - * @version 2008-09-18 - */ -public class JSONStringer extends JSONWriter { - /** - * Make a fresh JSONStringer. It can be used to build one JSON text. - */ - public JSONStringer() { - super(new StringWriter()); - } - - /** - * Return the JSON text. This method is used to obtain the product of the - * JSONStringer instance. It will return <code>null</code> if there was a - * problem in the construction of the JSON text (such as the calls to - * <code>array</code> were not properly balanced with calls to - * <code>endArray</code>). - * - * @return The JSON text. - */ - @Override - public String toString() { - return mode == 'd' ? writer.toString() : null; - } -} diff --git a/server/src/com/vaadin/external/json/JSONTokener.java b/server/src/com/vaadin/external/json/JSONTokener.java deleted file mode 100644 index c3531cae1d..0000000000 --- a/server/src/com/vaadin/external/json/JSONTokener.java +++ /dev/null @@ -1,451 +0,0 @@ -package com.vaadin.external.json; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.Serializable; -import java.io.StringReader; - -/* - Copyright (c) 2002 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -/** - * A JSONTokener takes a source string and extracts characters and tokens from - * it. It is used by the JSONObject and JSONArray constructors to parse JSON - * source strings. - * - * @author JSON.org - * @version 2010-12-24 - */ -public class JSONTokener implements Serializable { - - private int character; - private boolean eof; - private int index; - private int line; - private char previous; - private Reader reader; - private boolean usePrevious; - - /** - * Construct a JSONTokener from a Reader. - * - * @param reader - * A reader. - */ - public JSONTokener(Reader reader) { - this.reader = reader.markSupported() ? reader : new BufferedReader( - reader); - eof = false; - usePrevious = false; - previous = 0; - index = 0; - character = 1; - line = 1; - } - - /** - * Construct a JSONTokener from an InputStream. - */ - public JSONTokener(InputStream inputStream) throws JSONException { - this(new InputStreamReader(inputStream)); - } - - /** - * Construct a JSONTokener from a string. - * - * @param s - * A source string. - */ - public JSONTokener(String s) { - this(new StringReader(s)); - } - - /** - * Back up one character. This provides a sort of lookahead capability, so - * that you can test for a digit or letter before attempting to parse the - * next number or identifier. - */ - public void back() throws JSONException { - if (usePrevious || index <= 0) { - throw new JSONException("Stepping back two steps is not supported"); - } - index -= 1; - character -= 1; - usePrevious = true; - eof = false; - } - - /** - * Get the hex value of a character (base16). - * - * @param c - * A character between '0' and '9' or between 'A' and 'F' or - * between 'a' and 'f'. - * @return An int between 0 and 15, or -1 if c was not a hex digit. - */ - public static int dehexchar(char c) { - if (c >= '0' && c <= '9') { - return c - '0'; - } - if (c >= 'A' && c <= 'F') { - return c - ('A' - 10); - } - if (c >= 'a' && c <= 'f') { - return c - ('a' - 10); - } - return -1; - } - - public boolean end() { - return eof && !usePrevious; - } - - /** - * Determine if the source string still contains characters that next() can - * consume. - * - * @return true if not yet at the end of the source. - */ - public boolean more() throws JSONException { - next(); - if (end()) { - return false; - } - back(); - return true; - } - - /** - * Get the next character in the source string. - * - * @return The next character, or 0 if past the end of the source string. - */ - public char next() throws JSONException { - int c; - if (usePrevious) { - usePrevious = false; - c = previous; - } else { - try { - c = reader.read(); - } catch (IOException exception) { - throw new JSONException(exception); - } - - if (c <= 0) { // End of stream - eof = true; - c = 0; - } - } - index += 1; - if (previous == '\r') { - line += 1; - character = c == '\n' ? 0 : 1; - } else if (c == '\n') { - line += 1; - character = 0; - } else { - character += 1; - } - previous = (char) c; - return previous; - } - - /** - * Consume the next character, and check that it matches a specified - * character. - * - * @param c - * The character to match. - * @return The character. - * @throws JSONException - * if the character does not match. - */ - public char next(char c) throws JSONException { - char n = next(); - if (n != c) { - throw syntaxError("Expected '" + c + "' and instead saw '" + n - + "'"); - } - return n; - } - - /** - * Get the next n characters. - * - * @param n - * The number of characters to take. - * @return A string of n characters. - * @throws JSONException - * Substring bounds error if there are not n characters - * remaining in the source string. - */ - public String next(int n) throws JSONException { - if (n == 0) { - return ""; - } - - char[] chars = new char[n]; - int pos = 0; - - while (pos < n) { - chars[pos] = next(); - if (end()) { - throw syntaxError("Substring bounds error"); - } - pos += 1; - } - return new String(chars); - } - - /** - * Get the next char in the string, skipping whitespace. - * - * @throws JSONException - * @return A character, or 0 if there are no more characters. - */ - public char nextClean() throws JSONException { - for (;;) { - char c = next(); - if (c == 0 || c > ' ') { - return c; - } - } - } - - /** - * Return the characters up to the next close quote character. Backslash - * processing is done. The formal JSON format does not allow strings in - * single quotes, but an implementation is allowed to accept them. - * - * @param quote - * The quoting character, either <code>"</code> - * <small>(double quote)</small> or <code>'</code> - * <small>(single quote)</small>. - * @return A String. - * @throws JSONException - * Unterminated string. - */ - public String nextString(char quote) throws JSONException { - char c; - StringBuffer sb = new StringBuffer(); - for (;;) { - c = next(); - switch (c) { - case 0: - case '\n': - case '\r': - throw syntaxError("Unterminated string"); - case '\\': - c = next(); - switch (c) { - case 'b': - sb.append('\b'); - break; - case 't': - sb.append('\t'); - break; - case 'n': - sb.append('\n'); - break; - case 'f': - sb.append('\f'); - break; - case 'r': - sb.append('\r'); - break; - case 'u': - sb.append((char) Integer.parseInt(next(4), 16)); - break; - case '"': - case '\'': - case '\\': - case '/': - sb.append(c); - break; - default: - throw syntaxError("Illegal escape."); - } - break; - default: - if (c == quote) { - return sb.toString(); - } - sb.append(c); - } - } - } - - /** - * Get the text up but not including the specified character or the end of - * line, whichever comes first. - * - * @param delimiter - * A delimiter character. - * @return A string. - */ - public String nextTo(char delimiter) throws JSONException { - StringBuffer sb = new StringBuffer(); - for (;;) { - char c = next(); - if (c == delimiter || c == 0 || c == '\n' || c == '\r') { - if (c != 0) { - back(); - } - return sb.toString().trim(); - } - sb.append(c); - } - } - - /** - * Get the text up but not including one of the specified delimiter - * characters or the end of line, whichever comes first. - * - * @param delimiters - * A set of delimiter characters. - * @return A string, trimmed. - */ - public String nextTo(String delimiters) throws JSONException { - char c; - StringBuffer sb = new StringBuffer(); - for (;;) { - c = next(); - if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { - if (c != 0) { - back(); - } - return sb.toString().trim(); - } - sb.append(c); - } - } - - /** - * Get the next value. The value can be a Boolean, Double, Integer, - * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. - * - * @throws JSONException - * If syntax error. - * - * @return An object. - */ - public Object nextValue() throws JSONException { - char c = nextClean(); - String string; - - switch (c) { - case '"': - case '\'': - return nextString(c); - case '{': - back(); - return new JSONObject(this); - case '[': - back(); - return new JSONArray(this); - } - - /* - * Handle unquoted text. This could be the values true, false, or null, - * or it can be a number. An implementation (such as this one) is - * allowed to also accept non-standard forms. - * - * Accumulate characters until we reach the end of the text or a - * formatting character. - */ - - StringBuffer sb = new StringBuffer(); - while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) { - sb.append(c); - c = next(); - } - back(); - - string = sb.toString().trim(); - if (string.equals("")) { - throw syntaxError("Missing value"); - } - return JSONObject.stringToValue(string); - } - - /** - * Skip characters until the next character is the requested character. If - * the requested character is not found, no characters are skipped. - * - * @param to - * A character to skip to. - * @return The requested character, or zero if the requested character is - * not found. - */ - public char skipTo(char to) throws JSONException { - char c; - try { - int startIndex = index; - int startCharacter = character; - int startLine = line; - reader.mark(Integer.MAX_VALUE); - do { - c = next(); - if (c == 0) { - reader.reset(); - index = startIndex; - character = startCharacter; - line = startLine; - return c; - } - } while (c != to); - } catch (IOException exc) { - throw new JSONException(exc); - } - - back(); - return c; - } - - /** - * Make a JSONException to signal a syntax error. - * - * @param message - * The error message. - * @return A JSONException object, suitable for throwing - */ - public JSONException syntaxError(String message) { - return new JSONException(message + toString()); - } - - /** - * Make a printable string of this JSONTokener. - * - * @return " at {index} [character {character} line {line}]" - */ - @Override - public String toString() { - return " at " + index + " [character " + character + " line " + line - + "]"; - } -}
\ No newline at end of file diff --git a/server/src/com/vaadin/external/json/JSONWriter.java b/server/src/com/vaadin/external/json/JSONWriter.java deleted file mode 100644 index 5f9ddeeae2..0000000000 --- a/server/src/com/vaadin/external/json/JSONWriter.java +++ /dev/null @@ -1,355 +0,0 @@ -package com.vaadin.external.json; - -import java.io.IOException; -import java.io.Serializable; -import java.io.Writer; - -/* - Copyright (c) 2006 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -/** - * JSONWriter provides a quick and convenient way of producing JSON text. The - * texts produced strictly conform to JSON syntax rules. No whitespace is added, - * so the results are ready for transmission or storage. Each instance of - * JSONWriter can produce one JSON text. - * <p> - * A JSONWriter instance provides a <code>value</code> method for appending - * values to the text, and a <code>key</code> method for adding keys before - * values in objects. There are <code>array</code> and <code>endArray</code> - * methods that make and bound array values, and <code>object</code> and - * <code>endObject</code> methods which make and bound object values. All of - * these methods return the JSONWriter instance, permitting a cascade style. For - * example, - * - * <pre> - * new JSONWriter(myWriter).object().key("JSON").value("Hello, World!") - * .endObject(); - * </pre> - * - * which writes - * - * <pre> - * {"JSON":"Hello, World!"} - * </pre> - * <p> - * The first method called must be <code>array</code> or <code>object</code>. - * There are no methods for adding commas or colons. JSONWriter adds them for - * you. Objects and arrays can be nested up to 20 levels deep. - * <p> - * This can sometimes be easier than using a JSONObject to build a string. - * - * @author JSON.org - * @version 2011-11-14 - */ -public class JSONWriter implements Serializable { - private static final int maxdepth = 200; - - /** - * The comma flag determines if a comma should be output before the next - * value. - */ - private boolean comma; - - /** - * The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k' - * (key), 'o' (object). - */ - protected char mode; - - /** - * The object/array stack. - */ - private final JSONObject stack[]; - - /** - * The stack top index. A value of 0 indicates that the stack is empty. - */ - private int top; - - /** - * The writer that will receive the output. - */ - protected Writer writer; - - /** - * Make a fresh JSONWriter. It can be used to build one JSON text. - */ - public JSONWriter(Writer w) { - comma = false; - mode = 'i'; - stack = new JSONObject[maxdepth]; - top = 0; - writer = w; - } - - /** - * Append a value. - * - * @param string - * A string value. - * @return this - * @throws JSONException - * If the value is out of sequence. - */ - private JSONWriter append(String string) throws JSONException { - if (string == null) { - throw new JSONException("Null pointer"); - } - if (mode == 'o' || mode == 'a') { - try { - if (comma && mode == 'a') { - writer.write(','); - } - writer.write(string); - } catch (IOException e) { - throw new JSONException(e); - } - if (mode == 'o') { - mode = 'k'; - } - comma = true; - return this; - } - throw new JSONException("Value out of sequence."); - } - - /** - * Begin appending a new array. All values until the balancing - * <code>endArray</code> will be appended to this array. The - * <code>endArray</code> method must be called to mark the array's end. - * - * @return this - * @throws JSONException - * If the nesting is too deep, or if the object is started in - * the wrong place (for example as a key or after the end of the - * outermost array or object). - */ - public JSONWriter array() throws JSONException { - if (mode == 'i' || mode == 'o' || mode == 'a') { - push(null); - append("["); - comma = false; - return this; - } - throw new JSONException("Misplaced array."); - } - - /** - * End something. - * - * @param mode - * Mode - * @param c - * Closing character - * @return this - * @throws JSONException - * If unbalanced. - */ - private JSONWriter end(char mode, char c) throws JSONException { - if (this.mode != mode) { - throw new JSONException(mode == 'a' ? "Misplaced endArray." - : "Misplaced endObject."); - } - pop(mode); - try { - writer.write(c); - } catch (IOException e) { - throw new JSONException(e); - } - comma = true; - return this; - } - - /** - * End an array. This method most be called to balance calls to - * <code>array</code>. - * - * @return this - * @throws JSONException - * If incorrectly nested. - */ - public JSONWriter endArray() throws JSONException { - return end('a', ']'); - } - - /** - * End an object. This method most be called to balance calls to - * <code>object</code>. - * - * @return this - * @throws JSONException - * If incorrectly nested. - */ - public JSONWriter endObject() throws JSONException { - return end('k', '}'); - } - - /** - * Append a key. The key will be associated with the next value. In an - * object, every value must be preceded by a key. - * - * @param string - * A key string. - * @return this - * @throws JSONException - * If the key is out of place. For example, keys do not belong - * in arrays or if the key is null. - */ - public JSONWriter key(String string) throws JSONException { - if (string == null) { - throw new JSONException("Null key."); - } - if (mode == 'k') { - try { - stack[top - 1].putOnce(string, Boolean.TRUE); - if (comma) { - writer.write(','); - } - writer.write(JSONObject.quote(string)); - writer.write(':'); - comma = false; - mode = 'o'; - return this; - } catch (IOException e) { - throw new JSONException(e); - } - } - throw new JSONException("Misplaced key."); - } - - /** - * Begin appending a new object. All keys and values until the balancing - * <code>endObject</code> will be appended to this object. The - * <code>endObject</code> method must be called to mark the object's end. - * - * @return this - * @throws JSONException - * If the nesting is too deep, or if the object is started in - * the wrong place (for example as a key or after the end of the - * outermost array or object). - */ - public JSONWriter object() throws JSONException { - if (mode == 'i') { - mode = 'o'; - } - if (mode == 'o' || mode == 'a') { - append("{"); - push(new JSONObject()); - comma = false; - return this; - } - throw new JSONException("Misplaced object."); - - } - - /** - * Pop an array or object scope. - * - * @param c - * The scope to close. - * @throws JSONException - * If nesting is wrong. - */ - private void pop(char c) throws JSONException { - if (top <= 0) { - throw new JSONException("Nesting error."); - } - char m = stack[top - 1] == null ? 'a' : 'k'; - if (m != c) { - throw new JSONException("Nesting error."); - } - top -= 1; - mode = top == 0 ? 'd' : stack[top - 1] == null ? 'a' : 'k'; - } - - /** - * Push an array or object scope. - * - * @param c - * The scope to open. - * @throws JSONException - * If nesting is too deep. - */ - private void push(JSONObject jo) throws JSONException { - if (top >= maxdepth) { - throw new JSONException("Nesting too deep."); - } - stack[top] = jo; - mode = jo == null ? 'a' : 'k'; - top += 1; - } - - /** - * Append either the value <code>true</code> or the value <code>false</code> - * . - * - * @param b - * A boolean. - * @return this - * @throws JSONException - */ - public JSONWriter value(boolean b) throws JSONException { - return append(b ? "true" : "false"); - } - - /** - * Append a double value. - * - * @param d - * A double. - * @return this - * @throws JSONException - * If the number is not finite. - */ - public JSONWriter value(double d) throws JSONException { - return this.value(new Double(d)); - } - - /** - * Append a long value. - * - * @param l - * A long. - * @return this - * @throws JSONException - */ - public JSONWriter value(long l) throws JSONException { - return append(Long.toString(l)); - } - - /** - * Append an object value. - * - * @param object - * The object to append. It can be null, or a Boolean, Number, - * String, JSONObject, or JSONArray, or an object that implements - * JSONString. - * @return this - * @throws JSONException - * If the value is out of sequence. - */ - public JSONWriter value(Object object) throws JSONException { - return append(JSONObject.valueToString(object)); - } -} diff --git a/server/src/com/vaadin/external/json/README b/server/src/com/vaadin/external/json/README deleted file mode 100644 index ca6dc11764..0000000000 --- a/server/src/com/vaadin/external/json/README +++ /dev/null @@ -1,68 +0,0 @@ -JSON in Java [package org.json] - -Douglas Crockford -douglas@crockford.com - -2011-02-02 - - -JSON is a light-weight, language independent, data interchange format. -See http://www.JSON.org/ - -The files in this package implement JSON encoders/decoders in Java. -It also includes the capability to convert between JSON and XML, HTTP -headers, Cookies, and CDL. - -This is a reference implementation. There is a large number of JSON packages -in Java. Perhaps someday the Java community will standardize on one. Until -then, choose carefully. - -The license includes this restriction: "The software shall be used for good, -not evil." If your conscience cannot live with that, then choose a different -package. - -The package compiles on Java 1.2 thru Java 1.4. - - -JSONObject.java: The JSONObject can parse text from a String or a JSONTokener -to produce a map-like object. The object provides methods for manipulating its -contents, and for producing a JSON compliant object serialization. - -JSONArray.java: The JSONObject can parse text from a String or a JSONTokener -to produce a vector-like object. The object provides methods for manipulating -its contents, and for producing a JSON compliant array serialization. - -JSONTokener.java: The JSONTokener breaks a text into a sequence of individual -tokens. It can be constructed from a String, Reader, or InputStream. - -JSONException.java: The JSONException is the standard exception type thrown -by this package. - - -JSONString.java: The JSONString interface requires a toJSONString method, -allowing an object to provide its own serialization. - -JSONStringer.java: The JSONStringer provides a convenient facility for -building JSON strings. - -JSONWriter.java: The JSONWriter provides a convenient facility for building -JSON text through a writer. - - -CDL.java: CDL provides support for converting between JSON and comma -delimited lists. - -Cookie.java: Cookie provides support for converting between JSON and cookies. - -CookieList.java: CookieList provides support for converting between JSON and -cookie lists. - -HTTP.java: HTTP provides support for converting between JSON and HTTP headers. - -HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. - -XML.java: XML provides support for converting between JSON and XML. - -JSONML.java: JSONML provides support for converting between JSONML and XML. - -XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text.
\ No newline at end of file diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index f05d3678a5..d3098903c5 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -31,16 +31,17 @@ import com.vaadin.ui.CssLayout; import com.vaadin.ui.CustomComponent; /** - * Navigator utility that allows switching of views in a part of an application. - * + * A navigator utility that allows switching of views in a part of an + * application. + * <p> * The view switching can be based e.g. on URI fragments containing the view * name and parameters to the view. There are two types of parameters for views: * an optional parameter string that is included in the fragment (may be * bookmarkable). - * + * <p> * Views can be explicitly registered or dynamically generated and listening to * view changes is possible. - * + * <p> * Note that {@link Navigator} is not a component itself but comes with * {@link SimpleViewDisplay} which is a component that displays the selected * view as its contents. @@ -90,7 +91,7 @@ public class Navigator implements Serializable { private final Navigator navigator; /** - * Create a new URIFragmentManager and attach it to listen to URI + * Creates a new URIFragmentManager and attach it to listen to URI * fragment changes of a {@link Page}. * * @param page @@ -128,13 +129,13 @@ public class Navigator implements Serializable { } /** - * View display that is a component itself and replaces its contents with + * A ViewDisplay that is a component itself and replaces its contents with * the view. - * + * <p> * This display only supports views that are {@link Component}s themselves. * Attempting to display a view that is not a component causes an exception * to be thrown. - * + * <p> * By default, the view display has full size. */ public static class SimpleViewDisplay extends CustomComponent implements @@ -160,12 +161,12 @@ public class Navigator implements Serializable { } /** - * View display that replaces the contents of a {@link ComponentContainer} + * A ViewDisplay that replaces the contents of a {@link ComponentContainer} * with the active {@link View}. - * + * <p> * All components of the container are removed before adding the new view to * it. - * + * <p> * This display only supports views that are {@link Component}s themselves. * Attempting to display a view that is not a component causes an exception * to be thrown. @@ -195,7 +196,7 @@ public class Navigator implements Serializable { } /** - * View provider which supports mapping a single view name to a single + * A ViewProvider which supports mapping a single view name to a single * pre-initialized view instance. * * For most cases, ClassBasedViewProvider should be used instead of this. @@ -205,7 +206,8 @@ public class Navigator implements Serializable { private final View view; /** - * Create a new view provider which returns a pre-created view instance. + * Creates a new view provider which returns a pre-created view + * instance. * * @param viewName * name of the view (not null) @@ -249,12 +251,12 @@ public class Navigator implements Serializable { } /** - * View provider which maps a single view name to a class to instantiate for - * the view. - * + * A ViewProvider which maps a single view name to a class to instantiate + * for the view. + * <p> * Note that the view class must be accessible by the class loader used by * the provider. This may require its visibility to be public. - * + * <p> * This class is primarily for internal use by {@link Navigator}. */ public static class ClassBasedViewProvider implements ViewProvider { @@ -336,26 +338,21 @@ public class Navigator implements Serializable { private List<ViewProvider> providers = new LinkedList<ViewProvider>(); /** - * Create a navigator that is tracking the active view using URI fragments + * Creates a navigator that is tracking the active view using URI fragments * of the current {@link Page} and replacing the contents of a * {@link ComponentContainer} with the active view. - * + * <p> * In case the container is not on the current page, use another * {@link Navigator#Navigator(Page, ViewDisplay)} with an explicitly created * {@link ComponentContainerViewDisplay}. - * + * <p> * All components of the container are removed each time before adding the * active {@link View}. Views must implement {@link Component} when using * this constructor. - * * <p> * After all {@link View}s and {@link ViewProvider}s have been registered, * the application should trigger navigation to the current fragment using - * e.g. - * - * <pre> - * navigator.navigateTo(Page.getCurrent().getFragment()); - * </pre> + * {@link #navigate()}. * * @param container * ComponentContainer whose contents should be replaced with the @@ -367,16 +364,11 @@ public class Navigator implements Serializable { } /** - * Create a navigator that is tracking the active view using URI fragments. - * + * Creates a navigator that is tracking the active view using URI fragments. * <p> * After all {@link View}s and {@link ViewProvider}s have been registered, * the application should trigger navigation to the current fragment using - * e.g. - * - * <pre> - * navigator.navigateTo(Page.getCurrent().getFragment()); - * </pre> + * {@link #navigate()}. * * @param page * whose URI fragments are used @@ -389,14 +381,15 @@ public class Navigator implements Serializable { } /** - * Create a navigator. - * + * Creates a navigator. + * <p> * When a custom navigation state manager is not needed, use the constructor * {@link #Navigator(Page, ViewDisplay)} which uses a URI fragment based * state manager. - * - * Note that navigation to the initial view must be performed explicitly by - * the application after creating a Navigator using this constructor. + * <p> + * After all {@link View}s and {@link ViewProvider}s have been registered, + * the application should trigger navigation to the current fragment using + * {@link #navigate()}. * * @param stateManager * {@link NavigationStateManager} keeping track of the active @@ -411,20 +404,29 @@ public class Navigator implements Serializable { } /** - * Navigate to a view and initialize the view with given parameters. - * + * Navigates to the current navigation state. This method should be called + * when all required {@link View}s, {@link ViewProvider}s, and + * {@link ViewChangeListener}s have been added to the navigator. + */ + public void navigate() { + navigateTo(getStateManager().getState()); + } + + /** + * Navigates to a view and initialize the view with given parameters. + * <p> * The view string consists of a view name optionally followed by a slash * and a parameters part that is passed as-is to the view. ViewProviders are * used to find and create the correct type of view. - * + * <p> * If multiple providers return a matching view, the view with the longest * name is selected. This way, e.g. hierarchies of subviews can be * registered like "admin/", "admin/users", "admin/settings" and the longest * match is used. - * + * <p> * If the view being deactivated indicates it wants a confirmation for the * navigation operation, the user is asked for the confirmation. - * + * <p> * Registered {@link ViewChangeListener}s are called upon successful view * change. * @@ -460,7 +462,7 @@ public class Navigator implements Serializable { /** * Internal method activating a view, setting its parameters and calling * listeners. - * + * <p> * This method also verifies that the user is allowed to perform the * navigation operation. * @@ -475,7 +477,7 @@ public class Navigator implements Serializable { protected void navigateTo(View view, String viewName, String parameters) { ViewChangeEvent event = new ViewChangeEvent(this, currentView, view, viewName, parameters); - if (!isViewChangeAllowed(event)) { + if (!fireBeforeViewChange(event)) { return; } @@ -496,15 +498,16 @@ public class Navigator implements Serializable { display.showView(view); } - fireViewChange(event); + fireAfterViewChange(event); } /** - * Check whether view change is allowed. - * - * All related listeners are called. The view change is blocked if any of - * them wants to block the navigation operation. - * + * Fires an event before an imminent view change. + * <p> + * Listeners are called in registration order. If any listener returns + * <code>false</code>, the rest of the listeners are not called and the view + * change is blocked. + * <p> * The view change listeners may also e.g. open a warning or question dialog * and save the parameters to re-initiate the navigation operation upon user * action. @@ -514,9 +517,9 @@ public class Navigator implements Serializable { * @return true if the view change should be allowed, false to silently * block the navigation operation */ - protected boolean isViewChangeAllowed(ViewChangeEvent event) { + protected boolean fireBeforeViewChange(ViewChangeEvent event) { for (ViewChangeListener l : listeners) { - if (!l.isViewChangeAllowed(event)) { + if (!l.beforeViewChange(event)) { return false; } } @@ -545,20 +548,22 @@ public class Navigator implements Serializable { } /** - * Fire an event when the current view has changed. + * Fires an event after the current view has changed. + * <p> + * Listeners are called in registration order. * * @param event * view change event (not null) */ - protected void fireViewChange(ViewChangeEvent event) { + protected void fireAfterViewChange(ViewChangeEvent event) { for (ViewChangeListener l : listeners) { - l.navigatorViewChanged(event); + l.afterViewChange(event); } } /** - * Register a static, pre-initialized view instance for a view name. - * + * Registers a static, pre-initialized view instance for a view name. + * <p> * Registering another view with a name that is already registered * overwrites the old registration of the same type. * @@ -580,8 +585,8 @@ public class Navigator implements Serializable { } /** - * Register for a view name a view class. - * + * Register a view class for a view name. + * <p> * Registering another view with a name that is already registered * overwrites the old registration of the same type. * @@ -606,8 +611,8 @@ public class Navigator implements Serializable { } /** - * Remove view from navigator. - * + * Removes a view from navigator. + * <p> * This method only applies to views registered using * {@link #addView(String, View)} or {@link #addView(String, Class)}. * @@ -633,8 +638,8 @@ public class Navigator implements Serializable { } /** - * Register a view provider (factory). - * + * Registers a view provider (factory). + * <p> * Providers are called in order of registration until one that can handle * the requested view name is found. * @@ -656,19 +661,19 @@ public class Navigator implements Serializable { } /** - * Listen to changes of the active view. - * + * Adds a listener for listening to changes of the active view. + * <p> * The listener will get notified after the view has changed. * * @param listener - * Listener to invoke after view changes. + * Listener to invoke during a view change. */ public void addViewChangeListener(ViewChangeListener listener) { listeners.add(listener); } /** - * Remove a view change listener. + * Removes a view change listener. * * @param listener * Listener to remove. diff --git a/server/src/com/vaadin/navigator/ViewChangeListener.java b/server/src/com/vaadin/navigator/ViewChangeListener.java index aa09f64ad8..f3671821a5 100644 --- a/server/src/com/vaadin/navigator/ViewChangeListener.java +++ b/server/src/com/vaadin/navigator/ViewChangeListener.java @@ -102,29 +102,32 @@ public interface ViewChangeListener extends Serializable { } /** - * Check whether changing the view is permissible. - * - * This method may also e.g. open a "save" dialog or question about the - * change, which may re-initiate the navigation operation after user action. - * + * Invoked before the view is changed. + * <p> + * This method may e.g. open a "save" dialog or question about the change, + * which may re-initiate the navigation operation after user action. + * <p> * If this listener does not want to block the view change (e.g. does not * know the view in question), it should return true. If any listener - * returns false, the view change is not allowed. + * returns false, the view change is not allowed and + * <code>afterViewChange()</code> methods are not called. * * @param event * view change event * @return true if the view change should be allowed or this listener does * not care about the view change, false to block the change */ - public boolean isViewChangeAllowed(ViewChangeEvent event); + public boolean beforeViewChange(ViewChangeEvent event); /** - * Invoked after the view has changed. Be careful for deadlocks if you - * decide to change the view again in the listener. + * Invoked after the view is changed. If a <code>beforeViewChange</code> + * method blocked the view change, this method is not called. Be careful of + * unbounded recursion if you decide to change the view again in the + * listener. * * @param event * view change event */ - public void navigatorViewChanged(ViewChangeEvent event); + public void afterViewChange(ViewChangeEvent event); }
\ No newline at end of file diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 4c22a96782..0f42c0a28f 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -31,8 +31,9 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.logging.Logger; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.communication.SharedState; diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index c2a5377e12..32800506a3 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -56,11 +56,12 @@ import java.util.logging.Logger; import javax.servlet.http.HttpServletResponse; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.annotations.JavaScript; import com.vaadin.annotations.StyleSheet; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; import com.vaadin.server.ComponentSizeValidator.InvalidLayout; import com.vaadin.server.RpcManager.RpcInvocationException; import com.vaadin.server.StreamVariable.StreamingEndEvent; diff --git a/server/src/com/vaadin/server/AbstractUIProvider.java b/server/src/com/vaadin/server/AbstractUIProvider.java index 321ca75f65..5208997a65 100644 --- a/server/src/com/vaadin/server/AbstractUIProvider.java +++ b/server/src/com/vaadin/server/AbstractUIProvider.java @@ -27,8 +27,8 @@ import com.vaadin.ui.UI; public abstract class AbstractUIProvider implements UIProvider { @Override - public UI createInstance(Class<? extends UI> type, - WrappedRequest request) { + public UI createInstance(WrappedRequest request, + Class<? extends UI> type) { try { return type.newInstance(); } catch (InstantiationException e) { @@ -75,7 +75,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getThemeForUI(WrappedRequest request, + public String getTheme(WrappedRequest request, Class<? extends UI> uiClass) { Theme uiTheme = getAnnotationFor(uiClass, Theme.class); if (uiTheme != null) { @@ -86,7 +86,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getWidgetsetForUI(WrappedRequest request, + public String getWidgetset(WrappedRequest request, Class<? extends UI> uiClass) { Widgetset uiWidgetset = getAnnotationFor(uiClass, Widgetset.class); if (uiWidgetset != null) { @@ -97,7 +97,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public boolean isUiPreserved(WrappedRequest request, + public boolean isPreservedOnRefresh(WrappedRequest request, Class<? extends UI> uiClass) { PreserveOnRefresh preserveOnRefresh = getAnnotationFor(uiClass, PreserveOnRefresh.class); @@ -105,7 +105,7 @@ public abstract class AbstractUIProvider implements UIProvider { } @Override - public String getPageTitleForUI(WrappedRequest request, + public String getPageTitle(WrappedRequest request, Class<? extends UI> uiClass) { Title titleAnnotation = getAnnotationFor(uiClass, Title.class); if (titleAnnotation == null) { diff --git a/server/src/com/vaadin/server/AddonContext.java b/server/src/com/vaadin/server/AddonContext.java index ddb8394468..edddf1fe1f 100644 --- a/server/src/com/vaadin/server/AddonContext.java +++ b/server/src/com/vaadin/server/AddonContext.java @@ -104,7 +104,7 @@ public class AddonContext implements Serializable { public void destroy() { AddonContextEvent event = new AddonContextEvent(this); for (AddonContextListener listener : initedListeners) { - listener.contextDestoryed(event); + listener.contextDestroyed(event); } } diff --git a/server/src/com/vaadin/server/AddonContextListener.java b/server/src/com/vaadin/server/AddonContextListener.java index a5d9e8c5c9..504062c039 100644 --- a/server/src/com/vaadin/server/AddonContextListener.java +++ b/server/src/com/vaadin/server/AddonContextListener.java @@ -48,5 +48,5 @@ public interface AddonContextListener extends EventListener { * @param event * the add-on context event */ - public void contextDestoryed(AddonContextEvent event); + public void contextDestroyed(AddonContextEvent event); } diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 7103ca86ae..44e22925f9 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -29,6 +29,8 @@ import java.util.Set; import javax.servlet.http.HttpServletResponse; +import org.json.JSONException; +import org.json.JSONObject; import org.jsoup.nodes.DataNode; import org.jsoup.nodes.Document; import org.jsoup.nodes.DocumentType; @@ -36,8 +38,6 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.parser.Tag; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Version; import com.vaadin.ui.UI; @@ -222,7 +222,7 @@ public abstract class BootstrapHandler implements RequestHandler { String title = context.getVaadinSession() .getUiProvider(context.getRequest(), context.getUIClass()) - .getPageTitleForUI(context.getRequest(), context.getUIClass()); + .getPageTitle(context.getRequest(), context.getUIClass()); if (title != null) { head.appendElement("title").appendText(title); } @@ -275,7 +275,7 @@ public abstract class BootstrapHandler implements RequestHandler { String widgetset = context.getVaadinSession() .getUiProvider(context.getRequest(), context.getUIClass()) - .getWidgetsetForUI(context.getRequest(), context.getUIClass()); + .getWidgetset(context.getRequest(), context.getUIClass()); if (widgetset == null) { widgetset = request.getVaadinService().getConfiguredWidgetset( request); @@ -499,7 +499,7 @@ public abstract class BootstrapHandler implements RequestHandler { public String getThemeName(BootstrapContext context) { return context.getVaadinSession() .getUiProvider(context.getRequest(), context.getUIClass()) - .getThemeForUI(context.getRequest(), context.getUIClass()); + .getTheme(context.getRequest(), context.getUIClass()); } /** diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 3a340c2d7d..65c0ca366a 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -19,8 +19,9 @@ import java.io.IOException; import java.util.Collection; import java.util.List; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; import com.vaadin.ui.Component; @@ -188,7 +189,7 @@ public interface ClientConnector extends Connector, RpcTarget { * features. * <p> * This method must not alter the component hierarchy in any way. Calling - * requestRepaint() from this method will have no effect. + * {@link #markAsDirty()} from this method will have no effect. * </p> * * @param initial diff --git a/server/src/com/vaadin/server/CombinedRequest.java b/server/src/com/vaadin/server/CombinedRequest.java index 3de5067a20..2364527a65 100644 --- a/server/src/com/vaadin/server/CombinedRequest.java +++ b/server/src/com/vaadin/server/CombinedRequest.java @@ -24,9 +24,9 @@ import java.util.Iterator; import java.util.Locale; import java.util.Map; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; /** * A {@link WrappedRequest} with path and parameters from one request and diff --git a/server/src/com/vaadin/server/DefaultErrorListener.java b/server/src/com/vaadin/server/DefaultErrorListener.java index 46f96272fd..f007bdad63 100644 --- a/server/src/com/vaadin/server/DefaultErrorListener.java +++ b/server/src/com/vaadin/server/DefaultErrorListener.java @@ -26,11 +26,15 @@ import com.vaadin.ui.AbstractComponent; public class DefaultErrorListener implements Terminal.ErrorListener { @Override public void terminalError(ErrorEvent event) { + doDefault(event); + } + + public static void doDefault(ErrorEvent event) { final Throwable t = event.getThrowable(); if (t instanceof SocketException) { // Most likely client browser closed socket - getLogger() - .info("SocketException in CommunicationManager." + getLogger().info( + "SocketException in CommunicationManager." + " Most likely client (browser) closed socket."); return; } @@ -45,16 +49,15 @@ public class DefaultErrorListener implements Terminal.ErrorListener { // Shows the error in AbstractComponent if (owner instanceof AbstractComponent) { - ((AbstractComponent) owner) - .setComponentError(AbstractErrorMessage - .getErrorMessageForException(t)); + ((AbstractComponent) owner).setComponentError(AbstractErrorMessage + .getErrorMessageForException(t)); } // also print the error on console getLogger().log(Level.SEVERE, "Terminal error:", t); } - private Logger getLogger() { + private static Logger getLogger() { return Logger.getLogger(DefaultErrorListener.class.getName()); } }
\ No newline at end of file diff --git a/server/src/com/vaadin/server/DragAndDropService.java b/server/src/com/vaadin/server/DragAndDropService.java index 3e7de5c9a2..2d0a9e73e9 100644 --- a/server/src/com/vaadin/server/DragAndDropService.java +++ b/server/src/com/vaadin/server/DragAndDropService.java @@ -23,6 +23,9 @@ import java.util.List; import java.util.Map; import java.util.logging.Logger; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.event.Transferable; import com.vaadin.event.TransferableImpl; import com.vaadin.event.dd.DragAndDropEvent; @@ -32,8 +35,6 @@ import com.vaadin.event.dd.DropTarget; import com.vaadin.event.dd.TargetDetails; import com.vaadin.event.dd.TargetDetailsImpl; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.ui.dd.DragEventType; diff --git a/server/src/com/vaadin/server/JavaScriptCallbackHelper.java b/server/src/com/vaadin/server/JavaScriptCallbackHelper.java index d17ae71114..35fe4bd26c 100644 --- a/server/src/com/vaadin/server/JavaScriptCallbackHelper.java +++ b/server/src/com/vaadin/server/JavaScriptCallbackHelper.java @@ -24,8 +24,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; +import org.json.JSONArray; +import org.json.JSONException; + import com.vaadin.shared.JavaScriptConnectorState; import com.vaadin.ui.AbstractJavaScriptComponent; import com.vaadin.ui.JavaScript.JavaScriptCallbackRpc; diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java index 689ffe034e..72bd1e78f8 100644 --- a/server/src/com/vaadin/server/JsonCodec.java +++ b/server/src/com/vaadin/server/JsonCodec.java @@ -39,9 +39,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.shared.Connector; import com.vaadin.shared.JsonConstants; import com.vaadin.shared.communication.UidlValue; @@ -700,9 +701,9 @@ public class JsonCodec implements Serializable { throw new RuntimeException( "Can't encode " + value.getClass().getName() - + " as it has multiple fields with the name " + + " as it has multiple properties with the name " + fieldName.toLowerCase() - + ". This can happen if only casing distinguishes one property name from another."); + + ". This can happen if there are getters and setters for a public field (the framework can't know which to ignore) or if there are properties with only casing distinguishing between the names (e.g. getFoo() and getFOO())"); } Object fieldReference; diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index ccc400341e..bfbfe53429 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -211,21 +211,21 @@ public class Page implements Serializable { "browserWindowResized", BrowserWindowResizeEvent.class); /** - * A border style used for opening resources in a window without a border. + * @deprecated from 7.0, use {@link BorderStyle#NONE} instead. */ @Deprecated public static final BorderStyle BORDER_NONE = BorderStyle.NONE; /** - * A border style used for opening resources in a window with a minimal - * border. + * @deprecated from 7.0, use {@link BorderStyle#MINIMAL} instead. */ + @Deprecated public static final BorderStyle BORDER_MINIMAL = BorderStyle.MINIMAL; /** - * A border style that indicates that the default border style should be - * used when opening resources. + * @deprecated from 7.0, use {@link BorderStyle#DEFAULT} instead. */ + @Deprecated public static final BorderStyle BORDER_DEFAULT = BorderStyle.DEFAULT; /** diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index 15f0d4e4f1..c307c50348 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -26,8 +26,9 @@ import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.ResourceURL; -import com.vaadin.external.json.JSONException; -import com.vaadin.external.json.JSONObject; +import org.json.JSONException; +import org.json.JSONObject; + import com.vaadin.shared.ApplicationConstants; import com.vaadin.ui.UI; diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java index 752da3aafc..a15a50a42a 100644 --- a/server/src/com/vaadin/server/UIProvider.java +++ b/server/src/com/vaadin/server/UIProvider.java @@ -22,10 +22,10 @@ import com.vaadin.ui.UI; public interface UIProvider { public Class<? extends UI> getUIClass(WrappedRequest request); - public UI createInstance(Class<? extends UI> type, - WrappedRequest request); + public UI createInstance(WrappedRequest request, + Class<? extends UI> type); - public String getPageTitleForUI(WrappedRequest request, + public String getPageTitle(WrappedRequest request, Class<? extends UI> uiClass); /** @@ -40,7 +40,7 @@ public interface UIProvider { * @return <code>true</code>if the same UI instance should be reused e.g. * when the browser window is refreshed. */ - public boolean isUiPreserved(WrappedRequest request, + public boolean isPreservedOnRefresh(WrappedRequest request, Class<? extends UI> uiClass); /** @@ -58,7 +58,7 @@ public interface UIProvider { * widgetset should be used * */ - public String getWidgetsetForUI(WrappedRequest request, + public String getWidgetset(WrappedRequest request, Class<? extends UI> uiClass); /** @@ -73,7 +73,7 @@ public interface UIProvider { * should be used * */ - public String getThemeForUI(WrappedRequest request, + public String getTheme(WrappedRequest request, Class<? extends UI> uiClass); /** @@ -85,7 +85,7 @@ public interface UIProvider { * <p> * If no UI provider returns an existing UI, the framework does also check * the window.name for an existing instance with - * {@link #isUiPreserved(WrappedRequest, Class)} before falling back to + * {@link #isPreservedOnRefresh(WrappedRequest, Class)} before falling back to * bootstrapping and creating a new UI instance. * * @param request diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 026873a04d..940a4925c8 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -862,12 +862,6 @@ public class VaadinPortlet extends GenericPortlet implements Constants { WrappedPortletRequest request) throws PortletException { VaadinPortletSession newApplication = createApplication(); - try { - ServletPortletHelper.checkUiProviders(newApplication); - } catch (ApplicationClassException e) { - throw new PortletException(e); - } - newApplication.storeInSession(new WrappedPortletSession(request .getPortletRequest().getPortletSession())); diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index a0f6a28ea6..9372a08e10 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -45,6 +45,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.vaadin.DefaultDeploymentConfiguration; +import com.vaadin.sass.ScssStylesheet; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.server.ServletPortletHelper.ApplicationClassException; import com.vaadin.server.VaadinSession.SessionStartEvent; @@ -824,11 +825,8 @@ public class VaadinServlet extends HttpServlet implements Constants { try { SystemMessages ci = getVaadinService().getSystemMessages(); - if (getRequestType(request) != RequestType.UIDL) { - // 'plain' http req - e.g. browser reload; - // just go ahead redirect the browser - response.sendRedirect(ci.getSessionExpiredURL()); - } else { + RequestType requestType = getRequestType(request); + if (requestType == RequestType.UIDL) { /* * Invalidate session (weird to have session if we're saying * that it's expired, and worse: portal integration will fail @@ -845,6 +843,13 @@ public class VaadinServlet extends HttpServlet implements Constants { ci.getSessionExpiredMessage(), null, ci.getSessionExpiredURL()); + } else if (requestType == RequestType.HEARTBEAT) { + response.sendError(HttpServletResponse.SC_GONE, + "Session expired"); + } else { + // 'plain' http req - e.g. browser reload; + // just go ahead redirect the browser + response.sendRedirect(ci.getSessionExpiredURL()); } } catch (SystemMessageException ee) { throw new ServletException(ee); @@ -866,11 +871,8 @@ public class VaadinServlet extends HttpServlet implements Constants { try { SystemMessages ci = getVaadinService().getSystemMessages(); - if (getRequestType(request) != RequestType.UIDL) { - // 'plain' http req - e.g. browser reload; - // just go ahead redirect the browser - response.sendRedirect(ci.getCommunicationErrorURL()); - } else { + RequestType requestType = getRequestType(request); + if (requestType == RequestType.UIDL) { // send uidl redirect criticalNotification(request, response, ci.getCommunicationErrorCaption(), @@ -881,6 +883,14 @@ public class VaadinServlet extends HttpServlet implements Constants { * since the session is not created by the portal. */ request.getSession().invalidate(); + + } else if (requestType == RequestType.HEARTBEAT) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, + "Forbidden"); + } else { + // 'plain' http req - e.g. browser reload; + // just go ahead redirect the browser + response.sendRedirect(ci.getCommunicationErrorURL()); } } catch (SystemMessageException ee) { throw new ServletException(ee); @@ -941,16 +951,14 @@ public class VaadinServlet extends HttpServlet implements Constants { throws IOException, ServletException { final ServletContext sc = getServletContext(); - URL resourceUrl = sc.getResource(filename); - if (resourceUrl == null) { - // try if requested file is found from classloader - - // strip leading "/" otherwise stream from JAR wont work - filename = filename.substring(1); - resourceUrl = getVaadinService().getClassLoader().getResource( - filename); + URL resourceUrl = findResourceURL(filename, sc); - if (resourceUrl == null) { + if (resourceUrl == null) { + // File not found, if this was a css request we still look for a + // scss file with the same name + if (serveOnTheFlyCompiledScss(filename, request, response, sc)) { + return; + } else { // cannot serve requested file getLogger() .info("Requested resource [" @@ -958,19 +966,19 @@ public class VaadinServlet extends HttpServlet implements Constants { + "] not found from filesystem or through class loader." + " Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder."); response.setStatus(HttpServletResponse.SC_NOT_FOUND); - return; } + return; + } - // security check: do not permit navigation out of the VAADIN - // directory - if (!isAllowedVAADINResourceUrl(request, resourceUrl)) { - getLogger() - .info("Requested resource [" - + filename - + "] not accessible in the VAADIN directory or access to it is forbidden."); - response.setStatus(HttpServletResponse.SC_FORBIDDEN); - return; - } + // security check: do not permit navigation out of the VAADIN + // directory + if (!isAllowedVAADINResourceUrl(request, resourceUrl)) { + getLogger() + .info("Requested resource [" + + filename + + "] not accessible in the VAADIN directory or access to it is forbidden."); + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + return; } // Find the modification timestamp @@ -1046,6 +1054,82 @@ public class VaadinServlet extends HttpServlet implements Constants { is.close(); } + private URL findResourceURL(String filename, ServletContext sc) + throws MalformedURLException { + URL resourceUrl = sc.getResource(filename); + if (resourceUrl == null) { + // try if requested file is found from classloader + + // strip leading "/" otherwise stream from JAR wont work + if (filename.startsWith("/")) { + filename = filename.substring(1); + } + + resourceUrl = getVaadinService().getClassLoader().getResource( + filename); + } + return resourceUrl; + } + + private boolean serveOnTheFlyCompiledScss(String filename, + HttpServletRequest request, HttpServletResponse response, + ServletContext sc) throws IOException { + if (getVaadinService().getDeploymentConfiguration().isProductionMode()) { + // This is not meant for production mode. + return false; + } + + if (!filename.endsWith(".css")) { + return false; + } + + String scssFilename = filename.substring(0, filename.length() - 4) + + ".scss"; + URL scssUrl = findResourceURL(scssFilename, sc); + if (scssUrl == null) { + // Is a css request but no scss file was found + return false; + } + // security check: do not permit navigation out of the VAADIN + // directory + if (!isAllowedVAADINResourceUrl(request, scssUrl)) { + getLogger() + .info("Requested resource [" + + filename + + "] not accessible in the VAADIN directory or access to it is forbidden."); + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + // Handled, return true so no further processing is done + return true; + } + String realFilename = sc.getRealPath(scssFilename); + ScssStylesheet scss = ScssStylesheet.get(realFilename); + if (scss == null) { + getLogger() + .warning( + "Scss file " + + scssFilename + + " exists but ScssStylesheet was not able to find it"); + return false; + } + try { + getLogger() + .fine("Compiling " + realFilename + " for request to " + + filename); + scss.compile(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + // This is for development mode only so instruct the browser to never + // cache it + response.setHeader("Cache-Control", "no-cache"); + final String mimetype = getVaadinService().getMimeType(filename); + writeResponse(response, mimetype, scss.toString()); + + return true; + } + /** * Check whether a URL obtained from a classloader refers to a valid static * resource in the directory VAADIN. diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java index a91c011ddf..35a53fc6db 100644 --- a/server/src/com/vaadin/server/VaadinSession.java +++ b/server/src/com/vaadin/server/VaadinSession.java @@ -716,7 +716,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { protected <T extends UI> T createUIInstance(WrappedRequest request, Class<T> uiClass) { UIProvider uiProvider = getUiProvider(request, uiClass); - return uiClass.cast(uiProvider.createInstance(uiClass, request)); + return uiClass.cast(uiProvider.createInstance(request, uiClass)); } /** @@ -1027,7 +1027,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { ui.doInit(request, uiId.intValue()); - if (getUiProvider(request, uiClass).isUiPreserved(request, uiClass)) { + if (getUiProvider(request, uiClass).isPreservedOnRefresh(request, + uiClass)) { // Remember this UI String windowName = request.getBrowserDetails().getWindowName(); if (windowName == null) { @@ -1067,15 +1068,10 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { /** * Gets all the UIs of this session. This includes UIs that have been - * requested but not yet initialized. Please note, that UIs are not - * automatically removed e.g. if the browser window is closed and that there - * is no way to manually remove a UI. Inactive UIs will thus not be released - * for GC until the entire application is released when the session has - * timed out (unless there are dangling references). Improved support for - * releasing unused uIs is planned for an upcoming alpha release of Vaadin - * 7. + * requested but not yet initialized. UIs that receive no heartbeat requests + * from the client are eventually removed from the session. * - * @return a collection of uIs belonging to this application + * @return a collection of UIs belonging to this application * * @since 7.0 */ @@ -1190,7 +1186,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { i.remove(); retainOnRefreshUIs.values().remove(ui.getUIId()); ui.fireCloseEvent(); - getLogger().info( + getLogger().fine( "Closed UI #" + ui.getUIId() + " due to inactivity"); } } @@ -1248,6 +1244,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable { * * @since 7.0.0 * + * @deprecated Might be refactored or removed before 7.0.0 + * * @param ui * The UI whose status to check * @return true if the UI is alive, false if it could be removed. diff --git a/server/src/com/vaadin/ui/AbstractEmbedded.java b/server/src/com/vaadin/ui/AbstractEmbedded.java index 5c72141ef9..7dcf7ca091 100644 --- a/server/src/com/vaadin/ui/AbstractEmbedded.java +++ b/server/src/com/vaadin/ui/AbstractEmbedded.java @@ -19,7 +19,7 @@ import com.vaadin.shared.ui.AbstractEmbeddedState; public abstract class AbstractEmbedded extends AbstractComponent { @Override - public AbstractEmbeddedState getState() { + protected AbstractEmbeddedState getState() { return (AbstractEmbeddedState) super.getState(); } diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 4de3f90d15..45df42a9be 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -45,6 +45,7 @@ import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; +import com.vaadin.shared.ui.combobox.FilteringMode; import com.vaadin.shared.ui.dd.VerticalDropLocation; /** @@ -154,15 +155,28 @@ public abstract class AbstractSelect extends AbstractField<Object> implements /** * Interface for option filtering, used to filter options based on user * entered value. The value is matched to the item caption. - * <code>FILTERINGMODE_OFF</code> (0) turns the filtering off. - * <code>FILTERINGMODE_STARTSWITH</code> (1) matches from the start of the - * caption. <code>FILTERINGMODE_CONTAINS</code> (1) matches anywhere in the + * <code>FilteringMode.OFF</code> (0) turns the filtering off. + * <code>FilteringMode.STARTSWITH</code> (1) matches from the start of the + * caption. <code>FilteringMode.CONTAINS</code> (1) matches anywhere in the * caption. */ public interface Filtering extends Serializable { - public static final int FILTERINGMODE_OFF = 0; - public static final int FILTERINGMODE_STARTSWITH = 1; - public static final int FILTERINGMODE_CONTAINS = 2; + + /** + * @deprecated from 7.0, use {@link FilteringMode#OFF} instead + */ + @Deprecated + public static final FilteringMode FILTERINGMODE_OFF = FilteringMode.OFF; + /** + * @deprecated from 7.0, use {@link FilteringMode#STARTSWITH} instead + */ + @Deprecated + public static final FilteringMode FILTERINGMODE_STARTSWITH = FilteringMode.STARTSWITH; + /** + * @deprecated from 7.0, use {@link FilteringMode#CONTAINS} instead + */ + @Deprecated + public static final FilteringMode FILTERINGMODE_CONTAINS = FilteringMode.CONTAINS; /** * Sets the option filtering mode. @@ -170,30 +184,15 @@ public abstract class AbstractSelect extends AbstractField<Object> implements * @param filteringMode * the filtering mode to use */ - public void setFilteringMode(int filteringMode); + public void setFilteringMode(FilteringMode filteringMode); /** * Gets the current filtering mode. * * @return the filtering mode in use */ - public int getFilteringMode(); - - } - - /** - * Multi select modes that controls how multi select behaves. - */ - public enum MultiSelectMode { - /** - * The default behavior of the multi select mode - */ - DEFAULT, + public FilteringMode getFilteringMode(); - /** - * The previous more simple behavior of the multselect - */ - SIMPLE } /** diff --git a/server/src/com/vaadin/ui/BrowserFrame.java b/server/src/com/vaadin/ui/BrowserFrame.java new file mode 100644 index 0000000000..e79e03c2dd --- /dev/null +++ b/server/src/com/vaadin/ui/BrowserFrame.java @@ -0,0 +1,51 @@ +package com.vaadin.ui; + +import com.vaadin.server.Resource; +import com.vaadin.shared.ui.browserframe.BrowserFrameState; + +/** + * A component displaying an embedded web page. Implemented as a HTML + * <code>iframe</code> element. + * + * @author Vaadin Ltd. + * @version + * @VERSION@ + * @since 7.0 + */ +public class BrowserFrame extends AbstractEmbedded { + + /** + * Creates a new empty browser frame. + */ + public BrowserFrame() { + + } + + /** + * Creates a new empty browser frame with the given caption. + * + * @param caption + * The caption for the component + */ + public BrowserFrame(String caption) { + setCaption(caption); + } + + /** + * Creates a new browser frame with the given caption and content. + * + * @param caption + * The caption for the component. + * @param source + * A Resource representing the Web page that should be displayed. + */ + public BrowserFrame(String caption, Resource source) { + this(caption); + setSource(source); + } + + @Override + protected BrowserFrameState getState() { + return (BrowserFrameState) super.getState(); + } +} diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index 4f852c2b7b..4987d69fdd 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -34,6 +34,7 @@ import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.ui.combobox.ComboBoxConstants; +import com.vaadin.shared.ui.combobox.FilteringMode; /** * A filtering dropdown single-select. Suitable for newItemsAllowed, but it's @@ -60,7 +61,7 @@ public class ComboBox extends AbstractSelect implements // Current page when the user is 'paging' trough options private int currentPage = -1; - private int filteringMode = Filtering.FILTERINGMODE_STARTSWITH; + private FilteringMode filteringMode = FilteringMode.STARTSWITH; private String filterstring; private String prevfilterstring; @@ -186,7 +187,7 @@ public class ComboBox extends AbstractSelect implements target.addAttribute("pagelength", pageLength); - target.addAttribute("filteringmode", getFilteringMode()); + target.addAttribute("filteringmode", getFilteringMode().toString()); // Paints the options and create array of selected id keys int keyIndex = 0; @@ -201,7 +202,7 @@ public class ComboBox extends AbstractSelect implements boolean nullFilteredOut = filterstring != null && !"".equals(filterstring) - && filteringMode != Filtering.FILTERINGMODE_OFF; + && filteringMode != FilteringMode.OFF; // null option is needed and not filtered out, even if not on current // page boolean nullOptionVisible = needNullSelectOption && !nullFilteredOut; @@ -411,18 +412,19 @@ public class ComboBox extends AbstractSelect implements * @param filteringMode * @return */ - protected Filter buildFilter(String filterString, int filteringMode) { + protected Filter buildFilter(String filterString, + FilteringMode filteringMode) { Filter filter = null; if (null != filterString && !"".equals(filterString)) { switch (filteringMode) { - case Filtering.FILTERINGMODE_OFF: + case OFF: break; - case Filtering.FILTERINGMODE_STARTSWITH: + case STARTSWITH: filter = new SimpleStringFilter(getItemCaptionPropertyId(), filterString, true, true); break; - case Filtering.FILTERINGMODE_CONTAINS: + case CONTAINS: filter = new SimpleStringFilter(getItemCaptionPropertyId(), filterString, true, false); break; @@ -576,7 +578,7 @@ public class ComboBox extends AbstractSelect implements */ protected List<?> getFilteredOptions() { if (null == filterstring || "".equals(filterstring) - || Filtering.FILTERINGMODE_OFF == filteringMode) { + || FilteringMode.OFF == filteringMode) { prevfilterstring = null; filteredOptions = new LinkedList<Object>(getItemIds()); return filteredOptions; @@ -605,12 +607,12 @@ public class ComboBox extends AbstractSelect implements caption = caption.toLowerCase(); } switch (filteringMode) { - case Filtering.FILTERINGMODE_CONTAINS: + case CONTAINS: if (caption.indexOf(filterstring) > -1) { filteredOptions.add(itemId); } break; - case Filtering.FILTERINGMODE_STARTSWITH: + case STARTSWITH: default: if (caption.startsWith(filterstring)) { filteredOptions.add(itemId); @@ -686,12 +688,12 @@ public class ComboBox extends AbstractSelect implements } @Override - public void setFilteringMode(int filteringMode) { + public void setFilteringMode(FilteringMode filteringMode) { this.filteringMode = filteringMode; } @Override - public int getFilteringMode() { + public FilteringMode getFilteringMode() { return filteringMode; } diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index 401eafe6e9..172258a5fe 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -228,6 +228,11 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { @Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); + + // This is an obsolete hack that was required before Map<Conenctor, ?> + // was supported. The workaround is to instead use a Map<String, ?> with + // the connector id as the key, but that can only be used once the + // connector has been attached. getState().childCss.clear(); for (Iterator<Component> ci = getComponentIterator(); ci.hasNext();) { Component child = ci.next(); diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index f54959fb0a..39230bf662 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -17,12 +17,10 @@ package com.vaadin.ui; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; -import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; @@ -40,6 +38,7 @@ import com.vaadin.server.LegacyComponent; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.ui.datefield.DateFieldConstants; +import com.vaadin.shared.ui.datefield.Resolution; /** * <p> @@ -64,71 +63,6 @@ public class DateField extends AbstractField<Date> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, LegacyComponent { /** - * Resolutions for DateFields - * - * @author Vaadin Ltd. - * @since 7.0 - */ - public enum Resolution { - SECOND(Calendar.SECOND), MINUTE(Calendar.MINUTE), HOUR( - Calendar.HOUR_OF_DAY), DAY(Calendar.DAY_OF_MONTH), MONTH( - Calendar.MONTH), YEAR(Calendar.YEAR); - - private int calendarField; - - private Resolution(int calendarField) { - this.calendarField = calendarField; - } - - /** - * Returns the field in {@link Calendar} that corresponds to this - * resolution. - * - * @return one of the field numbers used by Calendar - */ - public int getCalendarField() { - return calendarField; - } - - /** - * Returns the resolutions that are higher or equal to the given - * resolution, starting from the given resolution. In other words - * passing DAY to this methods returns DAY,MONTH,YEAR - * - * @param r - * The resolution to start from - * @return An iterable for the resolutions higher or equal to r - */ - public static Iterable<Resolution> getResolutionsHigherOrEqualTo( - Resolution r) { - List<Resolution> resolutions = new ArrayList<DateField.Resolution>(); - Resolution[] values = Resolution.values(); - for (int i = r.ordinal(); i < values.length; i++) { - resolutions.add(values[i]); - } - return resolutions; - } - - /** - * Returns the resolutions that are lower than the given resolution, - * starting from the given resolution. In other words passing DAY to - * this methods returns HOUR,MINUTE,SECOND. - * - * @param r - * The resolution to start from - * @return An iterable for the resolutions lower than r - */ - public static List<Resolution> getResolutionsLowerThan(Resolution r) { - List<Resolution> resolutions = new ArrayList<DateField.Resolution>(); - Resolution[] values = Resolution.values(); - for (int i = r.ordinal() - 1; i >= 0; i--) { - resolutions.add(values[i]); - } - return resolutions; - } - }; - - /** * Resolution identifier: seconds. * * @deprecated As of 7.0, use {@link Resolution#SECOND} @@ -212,7 +146,7 @@ public class DateField extends AbstractField<Date> implements private TimeZone timeZone = null; - private static Map<Resolution, String> variableNameForResolution = new HashMap<DateField.Resolution, String>(); + private static Map<Resolution, String> variableNameForResolution = new HashMap<Resolution, String>(); { variableNameForResolution.put(Resolution.SECOND, "sec"); variableNameForResolution.put(Resolution.MINUTE, "min"); @@ -372,7 +306,7 @@ public class DateField extends AbstractField<Date> implements // Gets the new date in parts boolean hasChanges = false; - Map<Resolution, Integer> calendarFieldChanges = new HashMap<DateField.Resolution, Integer>(); + Map<Resolution, Integer> calendarFieldChanges = new HashMap<Resolution, Integer>(); for (Resolution r : Resolution .getResolutionsHigherOrEqualTo(resolution)) { diff --git a/server/src/com/vaadin/ui/Embedded.java b/server/src/com/vaadin/ui/Embedded.java index 3bcd7a26a0..d61fd44292 100644 --- a/server/src/com/vaadin/ui/Embedded.java +++ b/server/src/com/vaadin/ui/Embedded.java @@ -34,9 +34,14 @@ import com.vaadin.shared.ui.embedded.EmbeddedServerRpc; /** * Component for embedding external objects. * <p> - * As of Vaadin 7.0, the {@link Image}, {@link Flash}, and - * {@link EmbeddedBrowser} components should be used instead of - * <code>Embedded</code> whenever appropriate. + * As of Vaadin 7.0, the {@link Image}, {@link Flash}, and {@link BrowserFrame} + * components should be used instead of <code>Embedded</code> for displaying + * images, Adobe Flash objects, and embedded web pages, respectively. + * <code>Embedded</code> is still useful for displaying other multimedia content + * such as applets and PDF documents. + * + * @see Video + * @see Audio * * @author Vaadin Ltd. * @since 3.0 @@ -60,7 +65,7 @@ public class Embedded extends AbstractComponent implements LegacyComponent { /** * Browser ("iframe") type. * - * @deprecated As of 7.0, use the {@link EmbeddedBrowser} component instead. + * @deprecated As of 7.0, use the {@link BrowserFrame} component instead. */ @Deprecated public static final int TYPE_BROWSER = 2; diff --git a/server/src/com/vaadin/ui/EmbeddedBrowser.java b/server/src/com/vaadin/ui/EmbeddedBrowser.java deleted file mode 100644 index 4e2ae18de8..0000000000 --- a/server/src/com/vaadin/ui/EmbeddedBrowser.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.vaadin.ui; - -import com.vaadin.shared.ui.embeddedbrowser.EmbeddedBrowserState; - -/** - * Component for embedding browser "iframe". - * - * @author Vaadin Ltd. - * @version - * @VERSION@ - * @since 7.0 - */ -public class EmbeddedBrowser extends AbstractEmbedded { - - @Override - public EmbeddedBrowserState getState() { - return (EmbeddedBrowserState) super.getState(); - } -} diff --git a/server/src/com/vaadin/ui/Flash.java b/server/src/com/vaadin/ui/Flash.java index 430018289a..726b6c21c4 100644 --- a/server/src/com/vaadin/ui/Flash.java +++ b/server/src/com/vaadin/ui/Flash.java @@ -6,10 +6,11 @@ package com.vaadin.ui; import java.util.HashMap; +import com.vaadin.server.Resource; import com.vaadin.shared.ui.flash.FlashState; /** - * Component for embedding flash objects. + * A component for displaying Adobe® Flash® content. * * @author Vaadin Ltd. * @version @@ -19,8 +20,39 @@ import com.vaadin.shared.ui.flash.FlashState; @SuppressWarnings("serial") public class Flash extends AbstractEmbedded { + /** + * Creates a new empty Flash component. + */ + public Flash() { + + } + + /** + * Creates a new empty Flash component with the given caption + * + * @param caption + * The caption for the component + */ + public Flash(String caption) { + setCaption(caption); + } + + /** + * Creates a new Flash component with the given caption and content. + * + * @param caption + * The caption for the component + * @param source + * A Resource representing the Flash content that should be + * displayed + */ + public Flash(String caption, Resource source) { + this(caption); + setSource(source); + } + @Override - public FlashState getState() { + protected FlashState getState() { return (FlashState) super.getState(); } diff --git a/server/src/com/vaadin/ui/Image.java b/server/src/com/vaadin/ui/Image.java index 178e557cf3..c1b27704d4 100644 --- a/server/src/com/vaadin/ui/Image.java +++ b/server/src/com/vaadin/ui/Image.java @@ -61,7 +61,7 @@ public class Image extends AbstractEmbedded { } @Override - public ImageState getState() { + protected ImageState getState() { return (ImageState) super.getState(); } diff --git a/server/src/com/vaadin/ui/JavaScript.java b/server/src/com/vaadin/ui/JavaScript.java index f9324ba321..3782ead85a 100644 --- a/server/src/com/vaadin/ui/JavaScript.java +++ b/server/src/com/vaadin/ui/JavaScript.java @@ -19,8 +19,9 @@ package com.vaadin.ui; import java.util.HashMap; import java.util.Map; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; +import org.json.JSONArray; +import org.json.JSONException; + import com.vaadin.server.AbstractExtension; import com.vaadin.server.Page; import com.vaadin.shared.communication.ServerRpc; diff --git a/server/src/com/vaadin/ui/JavaScriptFunction.java b/server/src/com/vaadin/ui/JavaScriptFunction.java index ebb5e2c073..b0963ff0f4 100644 --- a/server/src/com/vaadin/ui/JavaScriptFunction.java +++ b/server/src/com/vaadin/ui/JavaScriptFunction.java @@ -18,8 +18,9 @@ package com.vaadin.ui; import java.io.Serializable; -import com.vaadin.external.json.JSONArray; -import com.vaadin.external.json.JSONException; +import org.json.JSONArray; +import org.json.JSONException; + import com.vaadin.server.AbstractJavaScriptExtension; /** diff --git a/server/src/com/vaadin/ui/Link.java b/server/src/com/vaadin/ui/Link.java index a2737e4483..6e286174a5 100644 --- a/server/src/com/vaadin/ui/Link.java +++ b/server/src/com/vaadin/ui/Link.java @@ -34,15 +34,21 @@ import com.vaadin.shared.ui.link.LinkConstants; @SuppressWarnings("serial") public class Link extends AbstractComponent implements LegacyComponent { - /* Target window border type constant: No window border */ + /** + * @deprecated from 7.0, use {@link BorderStyle#NONE} instead + */ @Deprecated public static final BorderStyle TARGET_BORDER_NONE = BorderStyle.NONE; - /* Target window border type constant: Minimal window border */ + /** + * @deprecated from 7.0, use {@link BorderStyle#MINIMAL} instead + */ @Deprecated public static final BorderStyle TARGET_BORDER_MINIMAL = BorderStyle.MINIMAL; - /* Target window border type constant: Default window border */ + /** + * @deprecated from 7.0, use {@link BorderStyle#DEFAULT} instead + */ @Deprecated public static final BorderStyle TARGET_BORDER_DEFAULT = BorderStyle.DEFAULT; diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 87962d5d15..d9e1403a03 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -59,6 +59,7 @@ import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.table.TableConstants; /** diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java index 44a1208cf8..1ba011dd00 100644 --- a/server/src/com/vaadin/ui/Tree.java +++ b/server/src/com/vaadin/ui/Tree.java @@ -54,6 +54,7 @@ import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.dd.VerticalDropLocation; import com.vaadin.shared.ui.tree.TreeConstants; import com.vaadin.util.ReflectTools; @@ -519,7 +520,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, : "single")); if (isMultiSelect()) { target.addAttribute("multiselectmode", - multiSelectMode.ordinal()); + multiSelectMode.toString()); } } else { target.addAttribute("selectmode", "none"); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index adb2a63c2e..7f0710c813 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -981,7 +981,7 @@ public abstract class UI extends AbstractComponentContainer implements throw new IllegalStateException("UI id has already been defined"); } this.uiId = uiId; - theme = getSession().getUiProvider(request, getClass()).getThemeForUI( + theme = getSession().getUiProvider(request, getClass()).getTheme( request, getClass()); getPage().init(request); @@ -1120,6 +1120,18 @@ public abstract class UI extends AbstractComponentContainer implements } /** + * Adds a close listener to the UI. Close listeners are invoked when the UI + * is removed from the session due to UI or session expiration. + * + * @param listener + * The CloseListener that should be added. + */ + public void addCloseListener(CloseListener listener) { + addListener(CloseEvent.CLOSE_EVENT_IDENTIFIER, CloseEvent.class, + listener, CloseListener.closeMethod); + } + + /** * @deprecated Since 7.0, replaced by * {@link #addClickListener(ClickListener)} **/ @@ -1141,6 +1153,18 @@ public abstract class UI extends AbstractComponentContainer implements } /** + * Removes a close listener from the UI, if previously added with + * {@link #addCloseListener(CloseListener)}. + * + * @param listener + * The CloseListener that should be removed + */ + public void removeCloseListener(CloseListener listener) { + removeListener(CloseEvent.CLOSE_EVENT_IDENTIFIER, CloseEvent.class, + listener); + } + + /** * @deprecated Since 7.0, replaced by * {@link #removeClickListener(ClickListener)} **/ diff --git a/server/tests/src/com/vaadin/tests/server/component/datefield/ResolutionTest.java b/server/tests/src/com/vaadin/tests/server/component/datefield/ResolutionTest.java index 00b5c60dad..ae72f9c743 100644 --- a/server/tests/src/com/vaadin/tests/server/component/datefield/ResolutionTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/datefield/ResolutionTest.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import junit.framework.TestCase; +import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.util.TestUtil; -import com.vaadin.ui.DateField.Resolution; public class ResolutionTest extends TestCase { diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TestMultipleSelection.java b/server/tests/src/com/vaadin/tests/server/component/table/TestMultipleSelection.java index 767b651b68..ff80cdb3c3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/table/TestMultipleSelection.java +++ b/server/tests/src/com/vaadin/tests/server/component/table/TestMultipleSelection.java @@ -7,7 +7,7 @@ import junit.framework.TestCase; import com.vaadin.data.Container; import com.vaadin.data.util.IndexedContainer; -import com.vaadin.ui.AbstractSelect.MultiSelectMode; +import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.ui.Table; public class TestMultipleSelection extends TestCase { diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java index 9ee4ffe6e7..679c288586 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import com.vaadin.LegacyApplication; +import com.vaadin.server.VaadinSession; import com.vaadin.ui.UI; import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Window; @@ -24,6 +25,7 @@ public class AddRemoveSubWindow { @Test public void addSubWindow() { + VaadinSession.setCurrent(new VaadinSession()); TestApp app = new TestApp(); app.init(); Window subWindow = new Window("Sub window"); diff --git a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java index bcc4c83b1e..a78c76cb70 100644 --- a/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java +++ b/server/tests/src/com/vaadin/tests/server/navigator/NavigatorTest.java @@ -135,14 +135,14 @@ public class NavigatorTest extends TestCase { } @Override - public boolean isViewChangeAllowed(ViewChangeEvent event) { + public boolean beforeViewChange(ViewChangeEvent event) { if (referenceEvents.isEmpty()) { - fail("Unexpected call to isViewChangeAllowed()"); + fail("Unexpected call to beforeViewChange()"); } ViewChangeEvent reference = referenceEvents.remove(); Boolean isCheck = referenceIsCheck.remove(); if (!isCheck) { - fail("Expected navigatorViewChanged(), received isViewChangeAllowed()"); + fail("Expected afterViewChange(), received beforeViewChange()"); } // here to make sure exactly the correct values are removed from // each queue @@ -154,14 +154,14 @@ public class NavigatorTest extends TestCase { } @Override - public void navigatorViewChanged(ViewChangeEvent event) { + public void afterViewChange(ViewChangeEvent event) { if (referenceEvents.isEmpty()) { - fail("Unexpected call to navigatorViewChanged()"); + fail("Unexpected call to afterViewChange()"); } ViewChangeEvent reference = referenceEvents.remove(); Boolean isCheck = referenceIsCheck.remove(); if (isCheck) { - fail("Expected isViewChangeAllowed(), received navigatorViewChanged()"); + fail("Expected beforeViewChange(), received afterViewChange()"); } if (!equalsReferenceEvent(event, reference)) { fail("View change event does not match reference event"); |