[richfaces-svn-commits] JBoss Rich Faces SVN: r5178 - in branches/3.1.x/ui/calendar/src/main: java/org/richfaces/component and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Jan 8 09:15:30 EST 2008


Author: akushunin
Date: 2008-01-08 09:15:30 -0500 (Tue, 08 Jan 2008)
New Revision: 5178

Modified:
   branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
   branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
   branches/3.1.x/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
Log:
RF-1675

Modified: branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml
===================================================================
--- branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml	2008-01-08 13:45:14 UTC (rev 5177)
+++ branches/3.1.x/ui/calendar/src/main/config/component/calendar.xml	2008-01-08 14:15:30 UTC (rev 5178)
@@ -60,9 +60,9 @@
 				disabled
 			</description>
 		</property>
-		<property elonly="true">
+		<property>
 			<name>locale</name>
-			<classname>java.util.Locale</classname>
+			<classname>java.lang.Object</classname>
 			<description>Used for locale definition</description>
 			<defaultvalue>getDefaultLocale()</defaultvalue>
 		</property>

Modified: branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java
===================================================================
--- branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java	2008-01-08 13:45:14 UTC (rev 5177)
+++ branches/3.1.x/ui/calendar/src/main/java/org/richfaces/component/UICalendar.java	2008-01-08 14:15:30 UTC (rev 5178)
@@ -30,10 +30,12 @@
 import java.util.TimeZone;
 
 import javax.faces.FacesException;
+import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIInput;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
 import javax.faces.convert.DateTimeConverter;
 import javax.faces.el.MethodBinding;
@@ -74,9 +76,9 @@
 
 	private final static Log log = LogFactory.getLog(UICalendar.class);
 
-	public abstract Locale getLocale();
+	public abstract Object getLocale();
 
-	public abstract void setLocale(Locale locale);
+	public abstract void setLocale(Object locale);
 
 	public abstract TimeZone getTimeZone();
 
@@ -205,7 +207,7 @@
 	// currentDate processing -------------------------------------------------
 
 	public Calendar getCalendar() {
-		return Calendar.getInstance(getTimeZone(), getLocale());
+		return Calendar.getInstance(getTimeZone(), getAsLocale(getLocale()));
 	}
 
 	public Date getConvertedValue(FacesContext context, String currentDateString)
@@ -241,9 +243,10 @@
 			if (vb != null) {
 				if(vb.getType(context).equals(String.class)){
 					DateTimeConverter convert = new DateTimeConverter();
-					convert.setLocale(getLocale());
+					convert.setLocale(getAsLocale(getLocale()));
 					convert.setPattern(getDatePattern());
-					vb.setValue(context,convert.getAsString(context, this, currentDate));
+					vb.setValue(context, convert.getAsString(context, this,
+							currentDate));
 					return;
 				}else if(vb.getType(context).equals(Calendar.class)){
 					Calendar c = Calendar.getInstance();
@@ -301,7 +304,7 @@
 				if (date instanceof String) {
 					DateTimeConverter converter = new DateTimeConverter();
 					converter.setPattern(this.getDatePattern());
-					converter.setLocale(this.getLocale());
+					converter.setLocale(getAsLocale(this.getLocale()));
 					converter.setTimeZone(this.getTimeZone());
 					FacesContext context = FacesContext.getCurrentInstance();
 					return (Date) converter.getAsObject(context, this,
@@ -331,7 +334,7 @@
 	}
 
 	protected Date getDefaultPreloadBegin(Date date) {
-		Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
+		Calendar calendar = Calendar.getInstance(getTimeZone(), getAsLocale(getLocale()));
 		calendar.setTime(date);
 		calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
 		/*
@@ -342,7 +345,7 @@
 	}
 
 	protected Date getDefaultPreloadEnd(Date date) {
-		Calendar calendar = Calendar.getInstance(getTimeZone(), getLocale());
+		Calendar calendar = Calendar.getInstance(getTimeZone(), getAsLocale(getLocale()));
 		calendar.setTime(date);
 		calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
 		/*
@@ -514,8 +517,7 @@
 
 			List dates = new ArrayList();
 
-			Calendar calendar = Calendar.getInstance(this.getTimeZone(), this
-					.getLocale());
+			Calendar calendar = Calendar.getInstance(this.getTimeZone(), getAsLocale(this.getLocale()));
 			Calendar calendar2 = (Calendar) calendar.clone();
 			calendar.setTime(dateRangeBegin);
 			calendar2.setTime(dateRangeEnd);
@@ -542,4 +544,63 @@
 		removeFacesListener(listener);
 	}
 
+	 /**
+	  *Parse Locale from String.
+	  *String must be represented as Locale.toString(); xx_XX_XXXX
+     */
+	
+	public Locale parseLocale(String localeStr){
+		
+		int length = localeStr.length();
+		if(null==localeStr||length<2){
+			return Locale.getDefault();
+		}
+		
+		//Lookup index of first '_' in string locale representation.
+		int index1 = localeStr.indexOf("_");
+		//Get first charters (if exist) from string
+		String language = null; 
+		if(index1!=-1){
+			language = localeStr.substring(0, index1);
+		}else{
+			return new Locale(localeStr);
+		}
+		//Lookup index of second '_' in string locale representation.
+		int index2 = localeStr.indexOf("_", index1+1);
+		String country = null;
+		if(index2!=-1){
+			country = localeStr.substring(index1+1, index2);
+			String variant = localeStr.substring(index2+1);
+			return new Locale(language, country, variant);
+		}else{
+			country = localeStr.substring(index1+1);
+			return new Locale(language, country);
+		}		
+	}
+	
+	public Locale getAsLocale(Object locale) {
+
+		if (locale instanceof Locale) {
+
+			return (Locale) locale;
+
+		} else if (locale instanceof String) {
+
+			return parseLocale((String) locale);
+
+		} else {
+
+			FacesContext context = FacesContext.getCurrentInstance();
+			Application application = context.getApplication();
+			Converter converter = application
+					.createConverter(locale.getClass());
+			if (null != converter) {
+				return parseLocale(converter.getAsString(context, this, locale));
+			} else {
+				throw new FacesException(
+						"Wrong locale attibute type or there is no converter for custom attibute type");
+			}
+		}
+	}
+
 }

Modified: branches/3.1.x/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
--- branches/3.1.x/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2008-01-08 13:45:14 UTC (rev 5177)
+++ branches/3.1.x/ui/calendar/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java	2008-01-08 14:15:30 UTC (rev 5178)
@@ -118,7 +118,7 @@
 		} else {
 			DateTimeConverter converter = new DateTimeConverter();
 			converter.setPattern(calendar.getDatePattern());
-			converter.setLocale(calendar.getLocale());
+			converter.setLocale(calendar.getAsLocale(calendar.getLocale()));
 			converter.setTimeZone(calendar.getTimeZone());
 			return converter.getAsObject(context, component,
 					(String) submittedValue);
@@ -170,7 +170,7 @@
 		String styleClass = (String) calendar.getAttributes().get("styleClass");
 		if (styleClass != null && styleClass.length() != 0) {
 			ResponseWriter writer = context.getResponseWriter();
-			writer.writeText(",\n className: " + styleClass, null);
+			writer.writeText(",\n className: '" + styleClass + "'", null);
 		}
 	}
 
@@ -354,7 +354,8 @@
 
 		DateTimeConverter converter = new DateTimeConverter();
 		converter.setPattern(input.getDatePattern());
-		converter.setLocale(input.getLocale());
+		Object locale = input.getLocale();
+		converter.setLocale(input.getAsLocale(locale));
 		converter.setTimeZone(input.getTimeZone());
 		if (value == null) {
 			return converter.getAsString(context, input, curVal);
@@ -397,7 +398,7 @@
 	protected Map getSymbolsMap(FacesContext facesContext, UICalendar calendar) {
 		Map map = new HashMap();
 
-		Locale locale = calendar.getLocale();
+		Locale locale = calendar.getAsLocale(calendar.getLocale());
 		Calendar cal = calendar.getCalendar();
 		int maximum = cal.getActualMaximum(Calendar.DAY_OF_WEEK);
 		int minimum = cal.getActualMinimum(Calendar.DAY_OF_WEEK);




More information about the richfaces-svn-commits mailing list