summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-09-25 22:16:24 +0000
committerAlex Rudyy <orudyy@apache.org>2013-09-25 22:16:24 +0000
commit1a1a9fe6c6fd3db2dea605242933744020ef343e (patch)
tree69932495ef96f9317fb555b8719834055ff6cd30
parent80e3697ffe3e510be76c1db898bbab94a325cb40 (diff)
downloadqpid-python-1a1a9fe6c6fd3db2dea605242933744020ef343e.tar.gz
QPID-5138: Use timezones from Broker JVM
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1526318 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java4
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java3
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java115
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js29
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js74
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js28
6 files changed, 206 insertions, 47 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java
index 9ba36bb5c2..80ce338d0a 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/HelperServlet.java
@@ -35,6 +35,7 @@ import org.apache.qpid.server.management.plugin.servlet.rest.action.ListAccessCo
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 AbstractServlet
new ListBrokerAttribute(Broker.PRODUCT_VERSION, "version"),
new ListGroupProviderAttributes(),
new ListAccessControlProviderAttributes(),
- new PluginClassProviderAction()
+ new PluginClassProviderAction(),
+ new ListTimeZones()
};
_actions = new HashMap<String, Action>();
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
index bf2a88a2c1..e77cc095f8 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/PreferencesServlet.java
@@ -101,7 +101,8 @@ public class PreferencesServlet extends AbstractServlet
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);
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java
new file mode 100644
index 0000000000..008018dba4
--- /dev/null
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/action/ListTimeZones.java
@@ -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;
+ }
+ }
+}
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js
index 287fbc9619..ddeba188e0 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/TimeZoneSelector.js
@@ -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, parser, query, Memory, _WidgetBase, regi
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");
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js
new file mode 100644
index 0000000000..bbec4f587b
--- /dev/null
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/timezone.js
@@ -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
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js
index e9552de31a..f6746dd865 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js
+++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/UserPreferences.js
@@ -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());
},