You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2013/09/26 00:16:24 UTC

svn commit: r1526318 - in /qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java: org/apache/qpid/server/management/plugin/servlet/rest/ org/apache/qpid/server/management/plugin/servlet/rest/action/ resources/js/qpid/common/ resources/js/qp...

Author: orudyy
Date: Wed Sep 25 22:16:24 2013
New Revision: 1526318

URL: http://svn.apache.org/r1526318
Log:
QPID-5138: Use timezones from Broker JVM

Added:
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js
Modified:
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js
    qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java?rev=1526318&r1=1526317&r2=1526318&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java Wed Sep 25 22:16:24 2013
@@ -35,6 +35,7 @@ import org.apache.qpid.server.management
 import org.apache.qpid.server.management.plugin.servlet.rest.action.ListAuthenticationProviderAttributes;
 import org.apache.qpid.server.management.plugin.servlet.rest.action.ListBrokerAttribute;
 import org.apache.qpid.server.management.plugin.servlet.rest.action.ListGroupProviderAttributes;
+import org.apache.qpid.server.management.plugin.servlet.rest.action.ListTimeZones;
 import org.apache.qpid.server.model.Broker;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.SerializationConfig;
@@ -61,7 +62,8 @@ public class HelperServlet extends Abstr
                 new ListBrokerAttribute(Broker.PRODUCT_VERSION, "version"),
                 new ListGroupProviderAttributes(),
                 new ListAccessControlProviderAttributes(),
-                new PluginClassProviderAction()
+                new PluginClassProviderAction(),
+                new ListTimeZones()
         };
 
         _actions = new HashMap<String, Action>();

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java?rev=1526318&r1=1526317&r2=1526318&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java Wed Sep 25 22:16:24 2013
@@ -101,7 +101,8 @@ public class PreferencesServlet extends 
         PreferencesProvider preferencesProvider = getPreferencesProvider(request);
         if (preferencesProvider == null)
         {
-            throw new IllegalStateException("Preferences provider is not configured");
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Preferences provider is not configured");
+            return;
         }
         String userName = getAuthenticatedUserName(request);
 

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java?rev=1526318&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java Wed Sep 25 22:16:24 2013
@@ -0,0 +1,115 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.server.management.plugin.servlet.rest.action;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.apache.qpid.server.management.plugin.servlet.rest.Action;
+import org.apache.qpid.server.model.Broker;
+
+public class ListTimeZones implements Action
+{
+
+    private static final String[] TIMEZONE_REGIONS = { "Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia",
+            "Europe", "Indian", "Pacific" };
+
+    @Override
+    public String getName()
+    {
+        return ListTimeZones.class.getSimpleName();
+    }
+
+    @Override
+    public Object perform(Map<String, Object> request, Broker broker)
+    {
+        List<TimeZoneDetails> timeZoneDetails = new ArrayList<TimeZoneDetails>();
+        String[] ids = TimeZone.getAvailableIDs();
+        long currentTime = System.currentTimeMillis();
+        for (String id : ids)
+        {
+            int cityPos = id.indexOf("/");
+            if (cityPos > 0 && cityPos < id.length() - 1)
+            {
+                String region = id.substring(0, cityPos);
+                for (int i = 0; i < TIMEZONE_REGIONS.length; i++)
+                {
+                    if (region.equals(TIMEZONE_REGIONS[i]))
+                    {
+                        TimeZone tz = TimeZone.getTimeZone(id);
+                        int offset = tz.getOffset(currentTime)/60000;
+                        String city = id.substring(cityPos + 1).replace('_', ' ');
+                        timeZoneDetails.add(new TimeZoneDetails(id, tz.getDisplayName(), offset, city, region));
+                        break;
+                    }
+                }
+            }
+        }
+        return timeZoneDetails;
+    }
+
+    public static class TimeZoneDetails
+    {
+        private String id;
+        private String name;
+        private int offset;
+        private String city;
+        private String region;
+
+        public TimeZoneDetails(String id, String name, int offset, String city, String region)
+        {
+            super();
+            this.id = id;
+            this.name = name;
+            this.offset = offset;
+            this.city = city;
+            this.region = region;
+        }
+
+        public String getId()
+        {
+            return id;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public int getOffset()
+        {
+            return offset;
+        }
+
+        public String getCity()
+        {
+            return city;
+        }
+
+        public String getRegion()
+        {
+            return region;
+        }
+    }
+}

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js?rev=1526318&r1=1526317&r2=1526318&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js Wed Sep 25 22:16:24 2013
@@ -28,39 +28,16 @@ define([
         "dijit/_WidgetBase",
         "dijit/registry",
         "dojo/text!common/TimeZoneSelector.html",
+        "qpid/common/timezone",
         "dijit/form/ComboBox",
         "dijit/form/FilteringSelect",
-        "dojox/date/timezone",
         "dojox/validate/us",
         "dojox/validate/web",
         "dojo/domReady!"],
-function (declare, array, domConstruct, parser, query, Memory, _WidgetBase, registry, template) {
+function (declare, array, domConstruct, parser, query, Memory, _WidgetBase, registry, template, timezone) {
 
   var preferencesRegions = ["Africa","America","Antarctica","Arctic","Asia","Atlantic","Australia","Europe","Indian","Pacific"];
 
-  function initSupportedTimeZones()
-  {
-    var supportedTimeZones = [];
-    var allTimeZones = dojox.date.timezone.getAllZones();
-    for(var i = 0; i < allTimeZones.length; i++)
-    {
-      var timeZone = allTimeZones[i];
-      var elements = timeZone.split("/");
-      if (elements.length > 1)
-      {
-        for(var j = 0; j<preferencesRegions.length; j++)
-        {
-          if (elements[0] == preferencesRegions[j])
-          {
-            supportedTimeZones.push({id: timeZone, region: elements[0], city: elements.slice(1).join("/").replace("_", " ") })
-            break;
-          }
-        }
-      }
-    }
-    return supportedTimeZones;
-  }
-
   function initSupportedRegions()
   {
     var supportedRegions = [{"id": "undefined", "name": "Undefined"}];
@@ -91,7 +68,7 @@ function (declare, array, domConstruct, 
     postCreate: function(){
       this.inherited(arguments);
 
-      var supportedTimeZones = initSupportedTimeZones();
+      var supportedTimeZones = timezone.getAllTimeZones();
 
       this._citySelector = registry.byNode(query(".timezoneCity", this.domNode)[0]);
       this._citySelector.set("searchAttr", "city");

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js?rev=1526318&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js Wed Sep 25 22:16:24 2013
@@ -0,0 +1,74 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+define(["dojo/_base/xhr"], function (xhr) {
+
+    var timezones = {};
+
+    function loadTimezones()
+    {
+      xhr.get({
+        url: "rest/helper?action=ListTimeZones",
+        sync: true,
+        handleAs: "json",
+        load: function(zones)
+        {
+          timezones.data = zones;
+        },
+        error: function(error)
+        {
+          if (console && console.error)
+          {
+            console.error(error);
+          }
+        }
+      });
+    }
+
+    return {
+      getAllTimeZones: function()
+      {
+        if (!timezones.data)
+        {
+          loadTimezones();
+        }
+        return timezones.data;
+      },
+      getTimeZoneInfo: function(timeZone) {
+        var tzi = timezones[timeZone];
+        if (!tzi)
+        {
+          var data = this.getAllTimeZones();
+          for(var i = 0; i < data.length; i++)
+          {
+            var zone = data[i];
+            if (zone.id == timeZone)
+            {
+              tzi = zone;
+              timezones[timeZone] = zone;
+              break;
+            }
+          }
+        }
+        return tzi;
+      }
+    };
+});
\ No newline at end of file

Modified: qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js?rev=1526318&r1=1526317&r2=1526318&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js (original)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js Wed Sep 25 22:16:24 2013
@@ -23,10 +23,9 @@ define(["dojo/_base/xhr",
         "dojo/date",
         "dojo/date/locale",
         "dojo/number",
-        "dojox/date/timezone"], function (xhr, json, date, locale, number) {
+        "qpid/common/timezone"], function (xhr, json, date, locale, number, timezone) {
 
   var listeners = [];
-  var userTimeZones = {};
 
   var UserPreferences = {
 
@@ -156,21 +155,13 @@ define(["dojo/_base/xhr",
         return null;
       }
 
-      var timeZoneInfo = userTimeZones[timeZoneName];
-      if (timeZoneInfo)
-      {
-        return timeZoneInfo;
-      }
-
-      timeZoneInfo = dojox.date.timezone.getTzInfo(new Date(), timeZoneName);
-      userTimeZones[timeZoneName] = timeZoneInfo;
-      return timeZoneInfo;
+      return timezone.getTimeZoneInfo(timeZoneName);
     },
 
     addTimeZoneOffsetToUTC : function(utcTimeInMilliseconds, timeZone)
     {
       var tzi = null;
-      if (timeZone && timeZone.hasOwnProperty("tzOffset"))
+      if (timeZone && timeZone.hasOwnProperty("offset"))
       {
         tzi = timeZone;
       }
@@ -181,8 +172,8 @@ define(["dojo/_base/xhr",
 
       if (tzi)
       {
-        var browserTimeZoneOffsetInMinues = new Date().getTimezoneOffset();
-        return utcTimeInMilliseconds - (tzi.tzOffset - browserTimeZoneOffsetInMinues) * 60000;
+        var browserTimeZoneOffsetInMinutes = -new Date().getTimezoneOffset();
+        return utcTimeInMilliseconds + ( tzi.offset - browserTimeZoneOffsetInMinutes ) * 60000;
       }
       return utcTimeInMilliseconds;
     },
@@ -190,7 +181,7 @@ define(["dojo/_base/xhr",
     getTimeZoneDescription : function(timeZone)
     {
       var tzi = null;
-      if (timeZone && timeZone.hasOwnProperty("tzOffset"))
+      if (timeZone && timeZone.hasOwnProperty("offset"))
       {
         tzi = timeZone;
       }
@@ -201,12 +192,11 @@ define(["dojo/_base/xhr",
 
       if (tzi)
       {
-        var timeZoneOfsetInMinutes = -tzi.tzOffset;
-        var timeZoneCode = tzi.tzAbbr;
-        return (timeZoneOfsetInMinutes>=0? "+" : "-")
+        var timeZoneOfsetInMinutes = tzi.offset;
+        return (timeZoneOfsetInMinutes>0? "+" : "")
           + number.format(timeZoneOfsetInMinutes/60, {pattern: "00"})
           + ":" + number.format(timeZoneOfsetInMinutes%60, {pattern: "00"})
-          + " " + timeZoneCode;
+          + " " + tzi.name;
       }
       return date.getTimezoneName(new Date());
     },



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org