You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2013/09/24 03:24:43 UTC

svn commit: r1525763 - in /openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils: BackupImport.java TimezoneUtil.java

Author: solomax
Date: Tue Sep 24 01:24:42 2013
New Revision: 1525763

URL: http://svn.apache.org/r1525763
Log:
[OPENMEETINGS-745] timezone look while LDAP login is fixed

Modified:
    openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/BackupImport.java
    openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/TimezoneUtil.java

Modified: openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/BackupImport.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/BackupImport.java?rev=1525763&r1=1525762&r2=1525763&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/BackupImport.java (original)
+++ openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/BackupImport.java Tue Sep 24 01:24:42 2013
@@ -104,8 +104,8 @@ import org.apache.openmeetings.db.entity
 import org.apache.openmeetings.db.entity.user.PrivateMessageFolder;
 import org.apache.openmeetings.db.entity.user.State;
 import org.apache.openmeetings.db.entity.user.User;
-import org.apache.openmeetings.db.entity.user.UserContact;
 import org.apache.openmeetings.db.entity.user.User.Type;
+import org.apache.openmeetings.db.entity.user.UserContact;
 import org.apache.openmeetings.remote.red5.ScopeApplicationAdapter;
 import org.apache.openmeetings.utils.crypt.MD5Implementation;
 import org.apache.openmeetings.utils.math.CalendarPatterns;
@@ -813,7 +813,7 @@ public class BackupImport {
 				do {
 					if (u.getTimeZoneId() == null && "omTimeZone".equals(item2.getName())) {
 						String jName = item2.getValue();
-						u.setTimeZoneId(jName == null ? null : tzUtil.getTimezoneByInternalJName(jName).getID());
+						u.setTimeZoneId(jName == null ? null : tzUtil.getTimezoneByInternalJName(jName, true).getID());
 					}
 					item2 = listNode2.getNext(); //HACK to handle old om_time_zone
 				} while (item2 != null && !"user".equals(item2.getName()));

Modified: openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/TimezoneUtil.java
URL: http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/TimezoneUtil.java?rev=1525763&r1=1525762&r2=1525763&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/TimezoneUtil.java (original)
+++ openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/utils/TimezoneUtil.java Tue Sep 24 01:24:42 2013
@@ -45,7 +45,7 @@ public class TimezoneUtil {
 	private static final Logger log = Red5LoggerFactory.getLogger(TimezoneUtil.class, webAppRootKey);
 	private static final Map<String, String> ICAL_TZ_MAP = new Hashtable<String, String>();
 	private static final Map<Long, String> ID_TZ_MAP = new Hashtable<Long, String>();
-	
+
 	private static void initTimeZones() {
 		SAXReader reader = new SAXReader();
 		Document document;
@@ -55,8 +55,8 @@ public class TimezoneUtil {
 			document = reader.read(new File(getLanguagesDir(), nameOfTimeZoneFile));
 
 			Element root = document.getRootElement();
-			
-			//HACK based on the fact timezones are not changed
+
+			// HACK based on the fact timezones are not changed
 			long id = 1;
 			for (@SuppressWarnings("rawtypes")
 			Iterator it = root.elementIterator("timezone"); it.hasNext();) {
@@ -70,45 +70,40 @@ public class TimezoneUtil {
 			log.error("Unexpected error while reading old time zone list", e);
 		}
 	}
-	
+
 	@Autowired
 	private ConfigurationDao configurationDao;
-	
+
 	/**
-	 * Parameters:
-	 * ID - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or 
-	 * a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x compatibility only and 
-	 * full names should be used.
+	 * Parameters: ID - the ID for a TimeZone, either an abbreviation such as "PST", a full name such as
+	 * "America/Los_Angeles", or a custom ID such as "GMT-8:00". Note that the support of abbreviations is for JDK 1.1.x
+	 * compatibility only and full names should be used.
 	 * 
-	 * Returns:
-	 * the specified TimeZone, or the GMT zone if the given ID cannot be understood.
-	 * <br/>
-	 * <br/>
-	 * TODO: Fall-back mechanism and maybe a log output if the given timeZoneId is not found in the 
-	 * list of available TimeZones of the current java.util.TimeZone package of the Java SDK
-	 * the the user is running
+	 * Returns: the specified TimeZone, or the GMT zone if the given ID cannot be understood. <br/>
 	 * <br/>
+	 * TODO: Fall-back mechanism and maybe a log output if the given timeZoneId is not found in the list of available
+	 * TimeZones of the current java.util.TimeZone package of the Java SDK the the user is running <br/>
+	 * 
 	 * @param timeZoneId
 	 * @return
 	 */
-	
+
 	public TimeZone getTimeZone(String timeZoneId) {
-		
+
 		if (timeZoneId == null || timeZoneId.equals("")) {
 			return getDefaultTimeZone();
 		}
-		
-		//see TODO in comments
-		
+
+		// see TODO in comments
+
 		return TimeZone.getTimeZone(timeZoneId);
 	}
 
 	/**
-	 * @return The current server configured time zone in the table
-	 *         configuration key: "default.timezone"
+	 * @return The current server configured time zone in the table configuration key: "default.timezone"
 	 */
 	public TimeZone getDefaultTimeZone() {
-		
+
 		String defaultTzName = configurationDao.getConfValue("default.timezone", String.class, "Europe/Berlin");
 
 		TimeZone timeZoneByOmTimeZone = TimeZone.getTimeZone(defaultTzName);
@@ -120,12 +115,11 @@ public class TimezoneUtil {
 		// If everything fails take the servers default one
 		log.error("There is no correct time zone set in the configuration of OpenMeetings for the key default.timezone or key is missing in table, using default locale!");
 		return TimeZone.getDefault();
-		
+
 	}
 
 	/**
-	 * Returns the timezone based on the user profile, if not return the
-	 * timezone from the server
+	 * Returns the timezone based on the user profile, if not return the timezone from the server
 	 * 
 	 * @param user
 	 * @return
@@ -153,14 +147,21 @@ public class TimezoneUtil {
 	 * @return
 	 */
 	public TimeZone getTimezoneByInternalJName(String jName) {
+		return getTimezoneByInternalJName(jName, false);
+	}
+	
+	public TimeZone getTimezoneByInternalJName(String jName, boolean shouldThrow) {
 		if (ICAL_TZ_MAP.isEmpty()) {
 			initTimeZones();
 		}
 		String omTimeZone = ICAL_TZ_MAP.get(jName);
-		
+
 		if (omTimeZone == null) {
-			log.error("There is not omTimeZone for this jName: "+jName);
-			throw new RuntimeException("There is not omTimeZone for this jName: "+jName);
+			String err = String.format("There is not omTimeZone for this jName: '%s'", jName);
+			log.error(err);
+			if (shouldThrow) {
+				throw new RuntimeException(err);
+			}
 		}
 
 		TimeZone timeZone = TimeZone.getTimeZone(omTimeZone);
@@ -194,21 +195,18 @@ public class TimezoneUtil {
 		// if user has not time zone get one from the server configuration
 		return getDefaultTimeZone();
 	}
-	
+
 	/**
-	 * We ignore the fact that a Date Object is always in UTC internally and
-	 * treat it as if it contains only dd.mm.yyyy HH:mm:ss. We need to do this
-	 * cause we cannot trust the Date Object send from the client. We have the
-	 * timeZone information additional to the Date, so we use it to transform it
-	 * now to a Calendar Object.
+	 * We ignore the fact that a Date Object is always in UTC internally and treat it as if it contains only dd.mm.yyyy
+	 * HH:mm:ss. We need to do this cause we cannot trust the Date Object send from the client. We have the timeZone
+	 * information additional to the Date, so we use it to transform it now to a Calendar Object.
 	 * 
 	 * @param dateTime
 	 * @param timezone
 	 * @return
 	 */
-	public static Calendar getCalendarInTimezone(String dateTimeStr,
-			TimeZone timezone) {
-		
+	public static Calendar getCalendarInTimezone(String dateTimeStr, TimeZone timezone) {
+
 		Date dateTime = CalendarPatterns.parseImportDate(dateTimeStr);
 
 		Calendar calOrig = Calendar.getInstance();
@@ -225,7 +223,7 @@ public class TimezoneUtil {
 
 		return cal;
 	}
-	
+
 	public static long _getOffset(TimeZone timezone) {
 		Calendar cal = Calendar.getInstance();
 		cal.setTimeZone(timezone);