You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jc...@apache.org on 2008/10/05 21:28:58 UTC

svn commit: r701865 - /wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java

Author: jcompagner
Date: Sun Oct  5 12:28:57 2008
New Revision: 701865

URL: http://svn.apache.org/viewvc?rev=701865&view=rev
Log:
try to use java 6 method WICKET-1692

Modified:
    wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java

Modified: wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java
URL: http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java?rev=701865&r1=701864&r2=701865&view=diff
==============================================================================
--- wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java (original)
+++ wicket/branches/wicket-1.3.x/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DatePicker.java Sun Oct  5 12:28:57 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.wicket.extensions.yui.calendar;
 
+import java.lang.reflect.Method;
 import java.text.DateFormat;
 import java.text.DateFormatSymbols;
 import java.text.SimpleDateFormat;
@@ -59,19 +60,34 @@
  * only be used with components that either implement {@link ITextFormatProvider} or that use
  * {@link DateConverter} configured with an instance of {@link SimpleDateFormat} (like Wicket's
  * default configuration has).<br/>
- *
+ * 
  * To use, simply add a new instance to your component, which would typically a TextField, like
  * {@link DateTextField}.<br/>
- *
+ * 
  * The CalendarNavigator can be configured by overriding {@link #configure(Map)} and setting the
  * property or by returning <code>true</code> for {@link #enableMonthYearSelection()}.
- *
+ * 
  * @see http://developer.yahoo.com/yui/calendar/
- *
+ * 
  * @author eelcohillenius
  */
 public class DatePicker extends AbstractBehavior implements IHeaderContributor
 {
+	private static Method GETINSTANCEMETHOD = null;
+	static
+	{
+		try
+		{
+			GETINSTANCEMETHOD = DateFormatSymbols.class.getMethod("getInstance",
+					new Class[] { Locale.class });
+		}
+		catch (Exception e)
+		{
+			// ignore
+		}
+
+	}
+
 	/**
 	 * Exception thrown when the bound component does not produce a format this date picker can work
 	 * with.
@@ -285,7 +301,7 @@
 	 * Check that this behavior can get a date format out of the component it is coupled to. It
 	 * checks whether {@link #getDatePattern()} produces a non-null value. If that method returns
 	 * null, and exception will be thrown
-	 *
+	 * 
 	 * @param component
 	 *            the component this behavior is being coupled to
 	 * @throws UnableToDetermineFormatException
@@ -301,7 +317,7 @@
 
 	/**
 	 * Set widget property if the array is null and has a length greater than 0.
-	 *
+	 * 
 	 * @param widgetProperties
 	 * @param key
 	 * @param array
@@ -316,7 +332,7 @@
 
 	/**
 	 * Whether to position the date picker relative to the trigger icon.
-	 *
+	 * 
 	 * @return If true, the date picker is aligned with the left position of the icon, and with the
 	 *         top right under. If false, the date picker will skip positioning and will let you do
 	 *         the positioning yourself. Returns true by default.
@@ -330,7 +346,7 @@
 	 * Append javascript to the initialization function for the YUI widget. Can be used by
 	 * subclasses to conveniently extend configuration without having to write a separate
 	 * contribution.
-	 *
+	 * 
 	 * @param markupId
 	 *            The markup id of the calendar component
 	 * @param javascriptId
@@ -349,11 +365,10 @@
 	 * Gives overriding classes the option of adding (or even changing/ removing) configuration
 	 * properties for the javascript widget. See <a
 	 * href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for the
-	 * available options. If you want to override/ remove properties, you should call
-	 * {@link super#setWidgetProperties(Properties)} first. If you don't call that, be aware that
-	 * you will have to call {@link #localize(Map)} manually if you like localized strings to be
-	 * added.
-	 *
+	 * available options. If you want to override/ remove properties, you should call {@link
+	 * super#setWidgetProperties(Properties)} first. If you don't call that, be aware that you will
+	 * have to call {@link #localize(Map)} manually if you like localized strings to be added.
+	 * 
 	 * @param widgetProperties
 	 *            the current widget properties
 	 */
@@ -386,7 +401,7 @@
 	/**
 	 * Filter all empty elements (workaround for {@link DateFormatSymbols} returning arrays with
 	 * empty elements).
-	 *
+	 * 
 	 * @param array
 	 *            array to filter
 	 * @return filtered array (without null or empty string elements)
@@ -410,7 +425,7 @@
 
 	/**
 	 * Gets the id of the component that the calendar widget will get attached to.
-	 *
+	 * 
 	 * @return The DOM id of the component
 	 */
 	protected final String getComponentMarkupId()
@@ -420,7 +435,7 @@
 
 	/**
 	 * Gets the date pattern to use for putting selected values in the coupled component.
-	 *
+	 * 
 	 * @return The date pattern
 	 */
 	protected String getDatePattern()
@@ -450,7 +465,7 @@
 	/**
 	 * Gets the escaped DOM id that the calendar widget will get attached to. All non word
 	 * characters (\W) will be removed from the string.
-	 *
+	 * 
 	 * @return The DOM id of the calendar widget - same as the component's markup id + 'Dp'}
 	 */
 	protected final String getEscapedComponentMarkupId()
@@ -460,7 +475,7 @@
 
 	/**
 	 * Gets the id of the icon that triggers the popup.
-	 *
+	 * 
 	 * @return The id of the icon
 	 */
 	protected final String getIconId()
@@ -470,7 +485,7 @@
 
 	/**
 	 * Gets the style of the icon that triggers the popup.
-	 *
+	 * 
 	 * @return The style of the icon, e.g. 'cursor: point' etc.
 	 */
 	protected String getIconStyle()
@@ -480,7 +495,7 @@
 
 	/**
 	 * Gets the url for the popup button. Users can override to provide their own icon URL.
-	 *
+	 * 
 	 * @return the url to use for the popup button/ icon
 	 */
 	protected CharSequence getIconUrl()
@@ -490,7 +505,7 @@
 
 	/**
 	 * Gets the locale that should be used to configure this widget.
-	 *
+	 * 
 	 * @return By default the locale of the bound component.
 	 */
 	protected Locale getLocale()
@@ -515,13 +530,30 @@
 	 * href="http://developer.yahoo.com/yui/examples/calendar/japan/1.html">Japanese</a> examples
 	 * for more info.
 	 * </p>
-	 *
+	 * 
 	 * @param widgetProperties
 	 *            the current widget properties
 	 */
 	protected void localize(Map widgetProperties)
 	{
-		DateFormatSymbols dfSymbols = new DateFormatSymbols(getLocale());
+		DateFormatSymbols dfSymbols = null;
+		if (GETINSTANCEMETHOD != null)
+		{
+			// try to use JDK 6 DateFormatSymbols.getInstance(Locale)
+			try
+			{
+				dfSymbols = (DateFormatSymbols)GETINSTANCEMETHOD.invoke(null,
+						new Object[] { getLocale() });
+			}
+			catch (Exception e)
+			{
+				// ignore
+			}
+		}
+		if (dfSymbols == null)
+		{
+			dfSymbols = new DateFormatSymbols(getLocale());
+		}
 		if (Locale.SIMPLIFIED_CHINESE.equals(getLocale()))
 		{
 			dfSymbols.setShortWeekdays(new String[] { "", "\u65E5", "\u4E00", "\u4E8C", "\u4E09",
@@ -546,7 +578,7 @@
 	 * calling the associated component's onchange Javascript event handler. You can for instance
 	 * attach an {@link AjaxEventBehavior} to that component to get a call back to the server. The
 	 * default is true.
-	 *
+	 * 
 	 * @return if true, notifies the associated component when a date is selected
 	 */
 	protected boolean notifyComponentOnDateSelected()
@@ -557,7 +589,7 @@
 	/**
 	 * Makes a copy of the provided array and for each element copy the substring 0..len to the new
 	 * array
-	 *
+	 * 
 	 * @param array
 	 *            array to copy from
 	 * @param len
@@ -592,9 +624,10 @@
 	/**
 	 * Indicates whether plain text is rendered or two select boxes are used to allow direct
 	 * selection of month and year.
-	 *
+	 * 
 	 * @return <code>true</code> if select boxes should be rendered to allow month and year
-	 *         selection.<br/><code>false</code> to render just plain text.
+	 *         selection.<br/>
+	 *         <code>false</code> to render just plain text.
 	 */
 	protected boolean enableMonthYearSelection()
 	{
@@ -603,10 +636,9 @@
 
 	/**
 	 * Indicates whether the calendar should be hidden after a date was selected.
-	 *
-	 * @return <code>true</code> (default) if the calendar should be hidden after the date
-	 *         selection <br/><code>false</code> if the calendar should remain visible after the
-	 *         date selection.
+	 * 
+	 * @return <code>true</code> (default) if the calendar should be hidden after the date selection <br/>
+	 *         <code>false</code> if the calendar should remain visible after the date selection.
 	 */
 	protected boolean hideOnSelect()
 	{
@@ -615,9 +647,9 @@
 
 	/**
 	 * Indicates whether the calendar should be rendered after it has been loaded.
-	 *
-	 * @return <code>true</code> if the calendar should be rendered after it has been loaded.<br/><code>false</code>
-	 *         (default) if it's initially hidden.
+	 * 
+	 * @return <code>true</code> if the calendar should be rendered after it has been loaded.<br/>
+	 *         <code>false</code> (default) if it's initially hidden.
 	 */
 	protected boolean renderOnLoad()
 	{
@@ -627,19 +659,21 @@
 	/**
 	 * Override this method to further customize the YUI Calendar with additional Javascript code.
 	 * The code returned by this method is executed right after the Calendar has been constructed
-	 * and initialized. To refer to the actual Calendar DOM object, use <code>${calendar}</code>
-	 * in your code.<br/>See <a href="http://developer.yahoo.com/yui/calendar/">the widget's
-	 * documentation</a> for more information about the YUI Calendar.<br/> Example:
-	 *
+	 * and initialized. To refer to the actual Calendar DOM object, use <code>${calendar}</code> in
+	 * your code.<br/>
+	 * See <a href="http://developer.yahoo.com/yui/calendar/">the widget's documentation</a> for
+	 * more information about the YUI Calendar.<br/>
+	 * Example:
+	 * 
 	 * <pre>
 	 * protected String getAdditionalJavascript()
 	 * {
 	 * 	return &quot;${calendar}.addRenderer(\&quot;10/3\&quot;, ${calendar}.renderCellStyleHighlight1);&quot;;
 	 * }
 	 * </pre>
-	 *
+	 * 
 	 * @return a String containing additional Javascript code
-	 *
+	 * 
 	 */
 	protected String getAdditionalJavascript()
 	{