diff options
Diffstat (limited to 'qpid/tools/src/java/qpid-qmf2-tools')
93 files changed, 16269 insertions, 0 deletions
diff --git a/qpid/tools/src/java/qpid-qmf2-tools/README.txt b/qpid/tools/src/java/qpid-qmf2-tools/README.txt new file mode 100644 index 0000000000..cce2fcf00e --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/README.txt @@ -0,0 +1,136 @@ +************************************************ The Tools ************************************************ + +A number of Java based tools are provided, and additionally a web based GUI with underlying REST API which +are described later, utilising the components from the core API. + +There are executable shell scripts included in the tools bundle that should allow the tools to be run fairly +easily. To use them, open the bin/ directory. + +The available tools are: +QpidConfig: Is a Java port of the standard Python based qpid-config tool. This exercises most of the QMF2 API + and is probably a good bet to see how things work if you want to use the API in your own projects. +QpidCtrl: Is a Java port of the qpid-ctrl tool found in qpid/cpp/src/tests. This is a little known, but useful + little tool that lets one send low-level QMF constructs from the command line. The JavaDoc is the + best place to look for example usage (see earlier for build instructions). +QpidPrintEvents: Is a Java port of the Python qpid-printevents and illustrates the asynchronous delivery + of QMF2 notification events. +QpidQueueStats: Is a Java port of the Python qpid-queue-stats. This was written mainly to illustrate the use + of the QMF2 "QuerySubscription" API that lets one specify how to be asynchronously notified + of changes to QMF Management Objects matching a specified set of criteria. +ConnectionAudit: Is a tool that allows one to audit connections to one or more Qpid brokers. It uses QMF + Events to identify when connections have been made to a broker and if so it logs information + about the connection. A whitelist can be specified to flag connections that you don't + want to have logged (e.g. ones that you like). +ConnectionLogger: Is similar to ConnectionAudit but a bit simpler this tool just logs connections being made + the tool is mainly there to illustrate how to dereference the associations between the + various QMF Management Objects (Connection, Session, Subscription, Queue, Binding Exchange etc.) +QueueFuse: Is a tool that monitors QMF Events looking for a QueueThresholdExceeded, which occurs when a queue + gets more than 80% full. When this Event occurs the tool sends a QMF method to "purge" 10% of the + messages off the offending queue, i.e. it acts rather like a fuse. It's mainly a bit of a toy, but + it's a pretty good illustration of how to trigger QMF method invocation from QMF Events. It would + be pretty easy to modify this to redirect messages to a different queue if a particular queue fills. +QpidRestAPI: This is a Web Service that exposes QMF2 via a REST API, see "The GUI" section below for details. + + + +************************************************* The GUI ************************************************* + +Included in the tools package, there is a fairly comprehensive Web based GUI available for Qpid that works +with the C++ Broker and also the Java Broker if the QMF management plugin has been installed (see the +related plugin README.txt for more details). + +The GUI is in the form of a pure client side "single page" Web App written in JavaScript that uses the +QpidRestAPI to proxy the QMF API, and also serve up the GUI. + +There is comprehensive JavaDoc for the QpidRestAPI (see source release for build instructions), where +the most useful classes to look at are: +QpidRestAPI: This describes the various command line options available. +QpidServer: This provides documentation for the actual REST API itself, in effect the REST mapping for QMF + +QpidRestAPI provides a fairly complete REST mapping for QMF, it was primarily written as the back-end to +the GUI, but there's no reason why it couldn't be used in its own right. + +To get started, after you have extracted the tools release as described earlier, the simplest and probably +most common use case can be kicked offby changing into the bin/ directory and firing up the REST API via: +./QpidRestAPI + +This will bind the HTTP port to 8080 on the "wildcard" address (0.0.0.0). The QMF connection will default to +the host that QpidRestAPI is running on and use the default AMQP port 5672. + +If you point a Browser to <host>:8080 the GUI should start up asking for a User Name and Password, the +defaults for those are the rather "traditional" admin admin. + + +If you have a non-trivial broker set-up you'll probably see "Failed to Connect", which is most likely due +to having authentication enabled (you can check this by firing up the C++ broker using qpidd --auth no) + + +There are a few ways to configure the Brokers that you can control via the GUI: +The first way is to specify the -a (or --broker-addr) command line option e.g. +./QpidRestAPI -a guest/guest@localhost + +This option accepts the Broker Address syntax used by the standard Python tools and it also accepts the +Java ConnectionURL syntax specified here (though to be honest the syntax used by the Python tools is simpler) +http://qpid.apache.org/releases/qpid-0.24/programming/book/QpidJNDI.html#section-jms-connection-url + + +This way of specifying the AMQP address of the default broker that you want to manage is probably the best +approach, but it is possible to add as many QMF Console Connections as you like by clicking +"Add QMF Console Connection" on the GUI Settings page. The popup lets you specify the Address URL such as +"guest/guest@host:5672" - again it also accepts the JMS Connection URLs, though I only use them if I'm +doing a copy/paste of an existing Connection URL. +The Name is simply a "friendly name" that you want to use to identify a particular Broker. + + +Clearly if you want to be able to manage a number of brokers you'd probably prefer not to have to enter +them every time you fire up the GUI - particularly because the list gets wiped if you hit refresh :-) + +The good news is that the initial set of Console Connections is configurable via the file: +bin/qpid-web/web/ui/config.js + + +This is a simple JSON file and it contains example Console Connection configuration including a fairly complex one + +If you use this mechanism to configure the GUI you can quickly switch between however many Brokers +you'd like to be able to control. + + +As mentioned above the default User Name and Password are admin and admin, these are set in the file +bin/qpid-web/authentication/account.properties + + +It's worth pointing out that at the moment authentication is limited to basic uthentication. This is mainly +due to lack of time/energy/motivation to do anything fancier (I only tend to use it on a private network) +I also had a need to minimise dependencies, so the Web Server is actually based on the Java 1.6 +com.sun.net.httpserver Web Server. + + +In practice though basic authentication shouldn't be as much of a restriction as it might sound especially +if you're only managing a single Broker. + +When one fires up QpidRestAPI with the -a option the Broker connection information does not pass between the +GUI and the QpidRestAPI so it's ultimately no less secure than using say qpid-config in this case though +note that if one configures multiple Brokers via config.js the contents of that file get served to the GUI +when it gets loaded so you probably want to restrict use of the GUI to the same network you'd be happy to +run qpid-config from. + + + +*********************************************** Important!! *********************************************** +* If your Qpid C++ broker is older than 0.10 the QMF2 API won't work unless your setup is as follows: * +*********************************************** Important!! *********************************************** + +Note that if you are talking to a broker < Qpid 0.10 +you need to set "--mgmt-qmf2 yes" when you start up qpidd if you want to get QMF2 Events and heartbeats pushed. +This is particularly important to note if you are using the Qpid GUI, as in default mode its updates are +triggered by the QMF2 heartbeats. If "--mgmt-qmf2 yes" isn't set on a 0.8 broker you'll see "Broker Disconnected" +flash briefly every 30 seconds or so as timeouts occur. Creating a QMF Console Connecton in the GUI with +"Disable Events" selected uses a timed poll rather than a heartbeat so it may be better to do that for cases +where access to the broker configuration is not available. + +*********************************************************************************************************** + +Note 1: This uses QMF2 so requires that the "--mgmt-qmf2 yes" option is applied to the broker (this is + the default from Qpid 0.10 onwards) + +Note 2: In order to use QMF2 the app-id field needs to be set. This requires the Qpid 0.12+ Java client diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionAudit.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionAudit.sh new file mode 100755 index 0000000000..69894edc42 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionAudit.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.ConnectionAudit "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionLogger.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionLogger.sh new file mode 100755 index 0000000000..41bc1e5b2f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/ConnectionLogger.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.ConnectionLogger "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidConfig.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidConfig.sh new file mode 100755 index 0000000000..f6a475f5e7 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidConfig.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.QpidConfig "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidCtrl.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidCtrl.sh new file mode 100755 index 0000000000..760974a2af --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidCtrl.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.QpidCtrl "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidPrintEvents.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidPrintEvents.sh new file mode 100755 index 0000000000..52c21431f3 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidPrintEvents.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.QpidPrintEvents "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidQueueStats.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidQueueStats.sh new file mode 100755 index 0000000000..e63764058e --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidQueueStats.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.QpidQueueStats "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidRestAPI.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidRestAPI.sh new file mode 100755 index 0000000000..5a1254d632 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QpidRestAPI.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.restapi.QpidRestAPI "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/QueueFuse.sh b/qpid/tools/src/java/qpid-qmf2-tools/bin/QueueFuse.sh new file mode 100755 index 0000000000..c7c8ebed16 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/QueueFuse.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# +# 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. +# + +# Test if we're running on Cygwin. +cygwin=false; +case "`uname`" in + CYGWIN*) cygwin=true;; +esac + +WHEREAMI=`dirname $0` +if [ -z "$QMF2_HOME" ]; then + export QMF2_HOME=`cd $WHEREAMI/../ && pwd` +fi + +CLASSPATH=$QMF2_HOME/lib/*:$CLASSPATH + +# If we're on Cygwin we need to convert to Windows path. +if $cygwin; then + CLASSPATH=$(cygpath -wp $CLASSPATH) +fi + +# Get the log level from the AMQJ_LOGGING_LEVEL environment variable. +if [ -n "$AMQJ_LOGGING_LEVEL" ]; then + PROPERTIES=-Damqj.logging.level=$AMQJ_LOGGING_LEVEL +fi + +java -cp "$CLASSPATH" $PROPERTIES org.apache.qpid.qmf2.tools.QueueFuse "$@" diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/log4j.xml b/qpid/tools/src/java/qpid-qmf2-tools/bin/log4j.xml new file mode 100644 index 0000000000..434bb73259 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/log4j.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<!-- ===================================================================== --> +<!-- --> +<!-- Log4j Configuration --> +<!-- --> +<!-- ===================================================================== --> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> + <!-- ============================== --> + <!-- Append messages to the console --> + <!-- ============================== --> + <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <param name="Threshold" value="ALL"/> + + <layout class="org.apache.log4j.PatternLayout"> + <!-- The default pattern: Date Priority [Category] Message\n --> + <param name="ConversionPattern" value="%m%n"/> + </layout> + </appender> + + <!-- ======================= --> + <!-- Setup the Root category --> + <!-- ======================= --> + <root> + <priority value="FATAL" /> + <appender-ref ref="CONSOLE"/> + </root> + +</log4j:configuration> diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/authentication/account.properties b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/authentication/account.properties new file mode 100644 index 0000000000..ff30bdc55c --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/authentication/account.properties @@ -0,0 +1,23 @@ +# +# +# 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. +# +# + +guest=guest +admin=admin diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/apple-touch-icon.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/apple-touch-icon.png Binary files differnew file mode 100644 index 0000000000..ad4478ccac --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/apple-touch-icon.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/favicon.ico b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/favicon.ico Binary files differnew file mode 100644 index 0000000000..1f61b0edd2 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/favicon.ico diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/index.html b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/index.html new file mode 100755 index 0000000000..e21871b59f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/index.html @@ -0,0 +1,56 @@ +<!DOCTYPE html> +<!-- + 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. +--> + +<!-- +This page provides a "welcome" page for the Qpid REST Service it immediately redirects to ui/qmf.html +which requires authentication. The main reason for this page is to provide a "welcome" screen prior to +the browser's authentication popup appearing, which makes it more obvious that it's the Qpid REST Service +that is requesting authentication. +--> +<html> +<head> + <title>QMF Console</title> + <link rel="stylesheet" type="text/css" href="/qmf-ui/css/index.css"/> + + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + + <!-- Changes the logical window size used when displaying a page on iOS. --> + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> + + <noscript> + <meta http-equiv="refresh" content="2; URL=/ui/qmf.html"> + </noscript> + + <script> + <!-- + window.onload=function() + { // Do redirect + window.location.replace("/ui/qmf.html"); + } + //--> + </script> + +</head> + +<body> + <div class="logo"></div> +</body> + +</html> diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie6.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie6.css new file mode 100644 index 0000000000..343192efd6 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie6.css @@ -0,0 +1,323 @@ +/* + * + * 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. + * + */ + +/** + * Stylesheet to try and make things look not *too* bad in IE6 and below. Supporting IE6 really is a nightmare :-( + */ + +/* Needed to get rid of annoying "permanent" IE6 scrollbar. */ +html +{ + overflow: hidden; +} + +/* Explicitly setting height to 100% avoids some evil IE6 layout bugs */ +html, .sidebar, .main, .popup-window, .popup-container, .popup, .scroll-area +{ + height: 100%; +} + +/* Explicitly setting width to 100% avoids some evil IE6 layout bugs */ +ul.list, .popup, .scroll-area +{ + width: 100%; +} + +#sidebar-wrapper /* Make sure IE "hasLayout" is enabled by doing zoom: 1. */ +{ + zoom: 1; +} + +/* IE6 doesn't support color: inherit so we have to set it explicitly. */ +ul li.grey a /* Grey text generally used to show inactive fields */ +{ + color: #8f8f8f; +} + +ul li a +{ + color: #060606; +} + +ul li.active a +{ + color: #fff; +} + +/* IE6 form has a default non-zero margin, so we need to zero it. */ +form +{ + margin: 0; +} + +.sidebar .scroll-area +{ + border-right: 1px solid #000; +} + +ul.list li.first-child +{ + border-top: 1px groove #fff; +} + +ul.list li.last-child +{ + border-bottom: 2px groove #fff; +} + +ul.list li a p +{ + right: 0; +} + +ul.list li.arrow a p, ul.list li.multiline a div p +{ + right: 18px; +} + + +ul.list li.multiline a.icon p, ul.list li.multiline a.icon div p +{ + right: 4px; +} + +/** + * white-space: nowrap; doesn't work especially well in IE6, so we set it to normal and constrain height. + * Unfortunately with the approach below ellipses aren't displayed, but it's the lesser of the evils. + * white-space: nowrap; does seem to work with an explicit width set, but doing that breaks loads of other things. + */ +ul li a p.sub, ul li a p.title +{ + white-space: normal; +} + +ul li a p.title, ul li a p.sub +{ + height: 16px; +} + +/* For IE6 we need to use a GIF instead of a PNG to make the input background transparent but still receive events. */ +input, textarea +{ + background: url(/itablet/images/ie/transparent.gif) repeat; +} + +/** + * For IE6 button :before and :after don't work so we have to resort to some JavaScript to add extra classes and tags + * IE6 doesn't support PNG images with alpha transparency, so we use gifs, which are OK but a littly more jagged. + */ + +a.button +{ + background: url(/itablet/images/ie/button-sprite.gif) 0px -30px repeat-x; +} + +a.button .before +{ + position: absolute; + top: 0; + left: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/ie/button-sprite.gif) -18px 0; +} + +a.button .after +{ + position: absolute; + top: 0; + right: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/ie/button-sprite.gif) -13px 0; +} + +a.button:active +{ + background-color: #766d69; + background-position: 0px -60px; +} + +a.button:active .before +{ + background-position: -41px 0; +} + +a.button:active .after +{ + background-position: -36px 0; +} + +a.button.back .before +{ + position: absolute; + left: -13px; + width: 13px; + height: 30px; + background-position: 0 0; +} + +a.button.back:active .before +{ + background-position: -23px 0; +} + +a.button.blue +{ + background: url(/itablet/images/ie/blue-button-sprite.gif) 0px -30px repeat-x; +} + +a.button.blue .before +{ + background: url(/itablet/images/ie/blue-button-sprite.gif) -18px 0; +} + +a.button.blue .after +{ + background: url(/itablet/images/ie/blue-button-sprite.gif) -13px 0; +} + +a.button.blue-back .before +{ + background-position: 0 0; +} + +a.button.blue:active +{ + background-color: #6b6f76; + background-position: 0px -60px; +} + +a.button.blue:active .before +{ + background-position: -41px 0; +} + +a.button.blue:active .after +{ + background-position: -36px 0; +} + +a.button.blue-back:active .before +{ + background-position: -23px 0; +} + +.popup-window +{ + background: url(/itablet/images/ie/transparent.gif); + filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/ie/transparent.png', sizingMethod='scale'); +} + +.popup-window.smoked +{ + background: url(/itablet/images/ie/transparent.gif); + filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/ie/smoked.png', sizingMethod='scale'); +} + +div.mask +{ + background: url(/itablet/images/ie/transparent.gif); + filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/mask.png', sizingMethod='crop'); +} + +div.onoff +{ + background: url(/itablet/images/ie/transparent.gif); + filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/itablet/images/on_off.png', sizingMethod='crop'); +} + +/** + * Unfortunately AlphaImageLoader doesn't play nicely with alignment and these images need to be right aligned. + * Fortunately the single level of transparency allowed by gif images is good enough and only a little granier. + */ + +ul.list li.arrow.radio +{ + background: #f7f7f7; +} + +ul.list li.radio label +{ + padding: 0 11px 0 11px; /* top right bottom left */ +} + +ul li.active, ul.list li.radio.active, ul.list li.radio.ie6-checked-active /* Highlight in blue with white text */ +{ + background: #035de7; +} + +ul li.arrow +{ + background: url(/itablet/images/ie/chevron.gif) no-repeat right; +} + +ul.list li.arrow +{ + background: #f7f7f7 url(/itablet/images/ie/chevron.gif) no-repeat right; +} + +ul li.ie6-arrow-active, ul.list li.ie6-arrow-active +{ + background: #035de7 url(/itablet/images/ie/chevron-active.gif) no-repeat right; +} + +ul.list li.radio.checked label +{ + background: url(/itablet/images/ie/tick.gif) no-repeat right; +} + +ul.list li.radio.ie6-checked-active label +{ + background: url(/itablet/images/ie/tick-active.gif) no-repeat right; +} + +ul.list li.ie6-radio-arrow +{ + background: #f7f7f7 url(/itablet/images/ie/blue-chevron.gif) no-repeat right; +} + +ul.list li.ie6-radio-arrow label +{ + padding: 0 11px 0 32px; /* top right bottom left */ +} + +ul.list li.ie6-radio-arrow a +{ + height: 0; + width: 0; +} + +ul.list li.ie6-checked-arrow label +{ + background: url(/itablet/images/ie/tick.gif) no-repeat 11px; +} + +ul.list li.ie6-radio-arrow-active, ul.list li.ie6-checked-arrow-active +{ + background: #035de7 url(/itablet/images/ie/blue-chevron.gif) no-repeat right; +} + +ul.list li.ie6-checked-arrow-active label +{ + background: url(/itablet/images/ie/tick-active.gif) no-repeat 11px; +} + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie7.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie7.css new file mode 100644 index 0000000000..d8bd020662 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie7.css @@ -0,0 +1,214 @@ +/* + * + * 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. + * + */ + +/** + * Stylesheet to try and make things look not *too* bad in IE7. + */ + +/* Needed to get rid of annoying "permanent" IE7 scrollbar. */ +html +{ + overflow: hidden; +} + +#sidebar-wrapper /* Make sure IE "hasLayout" is enabled by doing zoom: 1. */ +{ + zoom: 1; +} + +/* IE7 doesn't correctly size the scrollbar without this, however it causes IE6 problems. */ +.page +{ + height: 100%; +} + +ul.list +{ + width: 100%; +} + +/* IE < 8 doesn't support color: inherit so we have to set it explicitly. */ +ul li.grey a /* Grey text generally used to show inactive fields */ +{ + color: #8f8f8f; +} + +ul li a +{ + color: #060606; +} + +ul li.active a +{ + color: #fff; +} + +/* IE7 gives this anchor a default size which adds extra visible padding. As the navigable radio button has */ +/* reskinned the markup around this li the anchor doesn't actually need to be visible so we can safely hide it. */ +ul.list li.arrow.radio a +{ + display: none; +} + +/* IE < 8 form has a default non-zero margin, so we need to zero it. */ +form +{ + margin: 0; +} + +/* For IE7 :before and :after don't work so we have to resort to some JavaScript to inject extra classes and tags */ +ul.list li:first-child +{ + border-top: 3px groove #fff; /* IE7 without hasLayout set doesn't show the border if it's less than 3px, why??? */ +} + +ul.list li:first-child > .fbefore, /* Use fbefore not before in case first-child and last-child apply to same element. */ +ul.list li:first-child > .fafter /* Use fafter not after in case first-child and last-child apply to same element. */ +{ + position: absolute; + top: -3px; + left: -2px; + width: 10px; + height: 10px; + z-index: 1; + background: url(/itablet/images/ie/radius-10px-sprite.png); +} + +ul.list li:first-child > .fafter /* Use fafter not after in case first-child and last-child apply to same element. */ +{ + left: auto; + right: -2px; + background-position: -10px 0; +} + +/* The fake rounded corners for the IE8 stylesheet more or less work, but the bottom offset in IE7 is different??? */ +ul.list li.last-child +{ + margin-top: -1px; /* Weird IE7 specific bug needs this set to -1px to render it as 0px!!!! */ +} + +ul.list li.last-child > .before, ul.list li.last-child > .after +{ + bottom: -1px; +} + +/* For IE7 button :before and :after don't work so we have to resort to some JavaScript to add extra classes and tags */ + +a.button .before +{ + position: absolute; + top: 0; + left: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/button-sprite.png) -18px 0; +} + +a.button .after +{ + position: absolute; + top: 0; + right: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/button-sprite.png) -13px 0; +} + +a.button:active .before +{ + background-position: -41px 0; +} + +a.button:active .after +{ + background-position: -36px 0; +} + +a.button.back .before +{ + position: absolute; + left: -13px; + width: 13px; + height: 30px; + background-position: 0 0; +} + +a.button.back:active .before +{ + background-position: -23px 0; +} + +a.button.blue .before +{ + background: url(/itablet/images/blue-button-sprite.png) -18px 0; +} + +a.button.blue .after +{ + background: url(/itablet/images/blue-button-sprite.png) -13px 0; +} + +a.button.back.blue .before +{ + background-position: 0 0; +} + +a.button.blue:active .before +{ + background-position: -41px 0; +} + +a.button.blue:active .after +{ + background-position: -36px 0; +} + +a.button.back.blue:active .before +{ + background-position: -23px 0; +} + +/* The horiz-checkbox class hasLayout set so the styles below go back to the correct values. */ +/* Unfortunately simply giving ul.list li hasLayout using zoom: 1 above causes the IE7 margin bug to trigger */ +/* so can't default to that hence the weird values for ul.list li.last-child/ul.list li.last-child > .before */ +/* ul.list li.last-child > .after There may be easier ways, but fixing one IE7 bug seems to cause other ones */ +ul.list li.horiz-checkbox:first-child, ul.list li.textarea:first-child +{ + border-top: 1px groove #fff; +} + +ul.list li.horiz-checkbox.last-child, ul.list li.textarea.last-child +{ + margin-top: 0; +} + +ul.list li.horiz-checkbox:first-child > .fbefore, ul.list li.horiz-checkbox:first-child > .fafter, +ul.list li.textarea:first-child > .fbefore, ul.list li.textarea:first-child > .fafter +{ + top: -1px; +} + +ul.list li.horiz-checkbox.last-child > .before, ul.list li.horiz-checkbox.last-child > .after, +ul.list li.textarea.last-child > .before, ul.list li.textarea.last-child > .after +{ + bottom: -2px; +} + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie8.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie8.css new file mode 100644 index 0000000000..f2cb4d8126 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie8.css @@ -0,0 +1,161 @@ +/* + * + * 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. + * + */ + +/** + * Stylesheet to try and make things look not *too* bad in IE8 and below + */ + +/** + * To handle opacity in IE < 9 we animate progid:DXImageTransform.Microsoft.gradient in itablet.js + * We use a transparent background image rather than background: transparent to block mouse events to the main page. + * progid:DXImageTransform messes with the font so we only use it for animating and use a 50% alpha png as end style. + */ +.popup-window, input, textarea +{ + background: url(/itablet/images/ie/transparent.png) repeat; +} + +.popup-window.smoked +{ + background: url(/itablet/images/ie/smoked.png) repeat; +} + +/** + * Create fake top rounded corners using images. Fortunately we can do this using pure CSS as ie8 supports + * :first-child, :before and :after so we supply the images as content. + */ + +.header:before, .header:after +{ + position: absolute; + content: ""; + top: 0; + left: 0; + width: 5px; + height: 5px; + background: url(/itablet/images/ie/radius-5px-sprite.png); +} + +.header:after +{ + left: auto; + right: 0; + background-position: -5px; +} + +ul.list li:first-child:before, ul.list li:first-child:after, +ul.horiz-checkbox li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child label.first-child:before, +ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after +{ + position: absolute; + content: ""; + top: -2px; + left: -2px; + width: 10px; + height: 10px; + background: url(/itablet/images/ie/radius-10px-sprite.png); +} + +ul.list li:first-child:after, +ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after +{ + left: auto; + right: -2px; + background-position: -10px 0; +} + +/** + * Create fake bottom rounded corners using images. Unfortunately this isn't as easy as the top corners because + * a) ie8 doesn't support :last-child and b) if we have a single list item we've already used :before and :after + * Unfortunately we have to resort to some JavaScript so itablet.js has some ie8 specific code to add a + * "last-child" class and prepend/append div elements with "before" and "after" classes. Fortunately this is + * fairly clean to do using jQuery using $("ul.list li:last-child") to find the item that we need to modify. + */ + +ul.list li.last-child +{ + border-bottom: 2px groove #fff; +} + +ul.list li.last-child > .before, ul.list li.last-child > .after +{ + position: absolute; + bottom: -2px; + left: -2px; + width: 10px; + height: 10px; + z-index: 1; + background: url(/itablet/images/ie/radius-10px-sprite.png) 0 -10px; +} + +ul.list li.last-child > .after +{ + left: auto; + right: -2px; + background-position: -10px -10px; +} + +/** + * For IE < 9 use solid background colour instead of a gradient - no bigee, it was a subtle gradient anyway. + */ +ul li.active, ul li.radio.checked.active /* Highlight in blue with white text */ +{ + background: #035de7; +} + +ul li.active.arrow +{ + background: #035de7 url(/itablet/images/chevron-active.png) no-repeat right; +} + +ul.list li.arrow.radio.active +{ + background: #035de7 url(/itablet/images/blue-chevron.png) no-repeat right; +} + +/** + * We need to apply the fake border radius to the labels in the horiz-checkbox too as child elements aren't clipped. + * Unfortunately IE8 doesn't seem to distinguish between the selectors ul.list li:first-child:before and + * ul.list li.horiz-checkbox:first-child:before when horiz-checkbox is dynamically added (though it does if it's + * placed in the static HTML) this stops the <li> fake radiused border being correctly repositioned + * for horiz-checkboxes. By adding horiz-checkbox to the <ul> too we can use a more explicit rule in the CSS. + */ + +/* First we remove the original borders that were previously added for ul.list li:first-child:before and after. */ +ul.list li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child:after +{ + content: "."; +} + +/* The we re-add them in the correct position using the more explicit rule on ul.horiz-checkbox */ +/* We need to add the rounded borders to the labels too as they are positioned above the li in the stack. */ +ul.horiz-checkbox li.horiz-checkbox:first-child:before, ul.list li.horiz-checkbox:first-child label.first-child:before, +ul.horiz-checkbox li.horiz-checkbox:first-child:after, ul.list li.horiz-checkbox:first-child label.last-child:after +{ + top: -1px; +} + +canvas /* For IE < 9 the radiused borders for the canvas are actually rendered on the canvas. */ +{ + border: 0; +} + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie9.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie9.css new file mode 100644 index 0000000000..3ad857559e --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet-ie9.css @@ -0,0 +1,45 @@ +/* + * + * 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. + * + */ + +/** + * Stylesheet to sort out IE9 specific quirks....... + */ + +/** + * For some reason radiused borders cause IE9 to eat CPU when scrolling or animating in the popup window so remove them. + */ + +.popup, .popup-container +{ + border-radius: 0; +} + +.popup .scroll-area +{ + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} + +input +{ + padding: 12px 0 12px 0; /* top right bottom left */ +} + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet.css new file mode 100644 index 0000000000..6ed4d3d7d3 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/css/itablet.css @@ -0,0 +1,993 @@ +/* + * + * 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. + * + */ + +body +{ + font: 13px/1.5 Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif; + overflow-x: hidden; /* Hide horizontal scrollbar */ + background: #dddddd; +} + +p +{ + margin: 0; + padding: 11px 0 11px 0; /* top right bottom left */ +} + +.sidebar, .main, .popup-window, .popup-container, .popup, .scroll-area +{ + -moz-user-select: -moz-none; /* Disable selection on fields other than input & textarea. */ + -webkit-user-select: none; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + background: #000; +} + +.sidebar +{ + width: 250px; + border-right: 1px solid #000; + z-index: 2; +} + +.main +{ + left: 251px; +} + +.popup-window +{ + overflow: hidden; + background-color: rgba(0, 0, 0, 0.5); + z-index: 5; +} + +.popup, .popup-container +{ + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; +} + +.popup-container +{ + top: 64px; + bottom: 64px; + left: 20%; + right: 20%; + + overflow-x: hidden; + box-shadow: 10px 10px 10px #777; +} + +.scroll-area +{ + top: 44px; + overflow-x: hidden; + overflow-y: auto; + background: #dddddd; +} + +div .mail +{ + background: #f5f5f5; +} + +.popup .scroll-area +{ + -moz-border-bottom-left-radius: 5px; + -webkit-border-bottom-left-radius: 5px; + border-bottom-left-radius: 5px; + -moz-border-bottom-right-radius: 5px; + -webkit-border-bottom-right-radius: 5px; + border-bottom-right-radius: 5px; +} + +.page +{ + padding: 31px 5% 31px 5%; /* top right bottom left */ +} + +.page h1 +{ + color: #666666; + text-shadow: #fff 0 1px 0; + text-indent: 10px; + font-size: 17px; + + margin: 0; + padding: 16px 0 4px 0; /* top right bottom left */ +} + +.page h1.first +{ + padding: 0 0 4px 0; /* top right bottom left */ +} + +.page p.note +{ + color: #717880; + text-shadow: #fff 0 1px 0; + text-align: center; + font-size: 15px; + font-weight: normal; + + margin: 0; + padding: 4px 0 16px 0; /* top right bottom left */ +} + +.page p.note.nopadding +{ + padding-bottom: 0; +} + +/*------------------------------------------- Header ------------------------------------------------*/ + +div.header +{ + left: 0; + right: 0; + height: 43px; + line-height: 43px; + + -moz-border-top-left-radius: 5px; + -webkit-border-top-left-radius: 5px; + border-top-left-radius: 5px; + -moz-border-top-right-radius: 5px; + -webkit-border-top-right-radius: 5px; + border-top-right-radius: 5px; + border-bottom: 1px solid #858b9b; + + background: #bbb url(/itablet/images/ie/header-gradient.png) repeat-x; + background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #999)); + background: -webkit-linear-gradient(top center, #fff 0%, #999 100%); + background: -moz-linear-gradient(top center, #fff 0%, #999 100%); + background: -ms-linear-gradient(top center, #fff 0%, #999 100%); + background: -o-linear-gradient(top center, #fff 0%, #999 100%); + background: linear-gradient(top center, #fff 0%, #999 100%); +} + +div.header h1 +{ + text-align: center; + font-size: 20px; + font-weight: bold; + color: #717880; + text-shadow: #fff 0 1px 0; + + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + + margin: 0 12px 0 12px; /* top right bottom left */ +} + +div.header a.back.button + h1 +{ + margin: 0 88px 0 88px; /* top right bottom left */ +} + +div.header a.cancel.button + h1 +{ + margin: 0 62px 0 62px; /* top right bottom left */ +} + +/*--------------------------------------- Header Buttons --------------------------------------------*/ + +a.button +{ + outline: none; + text-decoration: none; + text-shadow: rgba(0, 0, 0, 0.6) 0 -1px 0; + color: #ddd; + background: #777; + font-size: 12px; + font-weight: bold; + line-height: 28px; + + display: block; + position: absolute; + top: 7px; + left: 12px; + height: 30px; + + background: url(/itablet/images/button-sprite.png) 0px -30px repeat-x; +} + +a.button:before +{ + position: absolute; + content: ""; + top: 0; + left: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/button-sprite.png) -18px 0 no-repeat; +} + +a.button:after +{ + position: absolute; + content: ""; + top: 0; + right: -5px; + width: 5px; + height: 30px; + background: url(/itablet/images/button-sprite.png) -13px 0 no-repeat; +} + +a.button:active +{ + background-color: #766d69; + background-position: 0 -60px; +} + +a.button:active:before +{ + background-position: -41px 0; +} + +a.button:active:after +{ + background-position: -36px 0; +} + +a.button.back +{ + left: 20px; +} + +a.button.back:before +{ + position: absolute; + left: -13px; + width: 13px; + height: 30px; + background-position: 0 0; +} + +a.button.back:active:before +{ + background-position: -23px 0; +} + +a.button.right +{ + left: auto; + right: 12px; +} + +a.button.blue +{ + color: #fff; + background: url(/itablet/images/blue-button-sprite.png) 0px -30px repeat-x; +} + +a.button.blue:before +{ + background: url(/itablet/images/blue-button-sprite.png) -18px 0 no-repeat; +} + +a.button.blue:after +{ + background: url(/itablet/images/blue-button-sprite.png) -13px 0 no-repeat; +} + +a.button.back.blue:before +{ + background-position: 0 0; +} + +a.button.blue:active +{ + background-color: #6b6f76; + background-position: 0px -60px; +} + +a.button.blue:active:before +{ + background-position: -41px 0; +} + +a.button.blue:active:after +{ + background-position: -36px 0; +} + +a.button.back.blue:active:before +{ + background-position: -23px 0; +} + +/*----------------------------------- Toolbar and Stock Buttons -------------------------------------*/ + +span.toolbar +{ + position: absolute; + overflow: hidden; + top: 7px; + left: auto; + right: 12px; +} + +span.toolbar a +{ + outline: none; + text-decoration: none; + display: block; + float: left; + width: 32px; + height: 32px; +} + +a.delete +{ + background: url(/itablet/images/delete.png) no-repeat left; +} + +a.add +{ + background: url(/itablet/images/add.png) no-repeat left; +} + +a.home +{ + background: url(/itablet/images/home.png) no-repeat left; +} + +a.flag +{ + background: url(/itablet/images/flag.png) no-repeat left; +} + +a.move +{ + background: url(/itablet/images/move.png) no-repeat left; +} + +a.bin +{ + background: url(/itablet/images/bin.png) no-repeat left; +} + +a.action +{ + background: url(/itablet/images/action.png) no-repeat left; +} + +a.write +{ + background: url(/itablet/images/write.png) no-repeat left; +} + +/* Add a "glowing" highlight to toolbar and clickable icons */ +span.toolbar a:active:before, +ul.list li.clickable-icon a:active:before +{ + position: absolute; + content: ""; + top: 0; + left: 0; + width: 32px; + height: 100%; + background: url(/itablet/images/ie/radial-gradient.png) no-repeat left; + background: -webkit-gradient(radial, center center, 0, center center, 16, from(rgba(255,255,255,1)), to(rgba(200,200,200,0))); + background: -webkit-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%); + background: -moz-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%); + background: -ms-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%); + background: -o-radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%); + background: radial-gradient(center center, circle cover, rgba(255,255,255,1), rgba(200,200,200,0) 75%); +} + +span.toolbar a:active:before +{ + position: relative; + float: left; +} + +/*---- this is hidden for desktop browsers it is shown by the styles enabled by the media query -----*/ + +div.header a.menu +{ + display: none; +} + +/*------------------------------- Define the styles for list elements -------------------------------*/ + +ul +{ + list-style: none; + margin: 0; + padding: 0; +} + +ul li +{ + position: relative; + line-height: 42px; + padding: 1px 0 0 0; /* top right bottom left */ + + color: #060606; + font-size: 17px; + font-weight: bold; + border-bottom: 1px solid #ccc; +} + +ul.list li +{ + line-height: 21px; + padding: 11px 0 11px 0; + + background-color: #f7f7f7; + border-left: 2px groove #fff; + border-right: 2px groove #fff; +} + +ul.list li.multiline, ul.list li.icon, ul.list li.clickable-icon +{ + padding: 5px 0 5px 0; +} + +ul.list li:first-child +{ + -moz-border-top-left-radius: 10px; + -webkit-border-top-left-radius: 10px; + border-top-left-radius: 10px; + -moz-border-top-right-radius: 10px; + -webkit-border-top-right-radius: 10px; + border-top-right-radius: 10px; + border-top: 2px groove #fff; +} + +ul.list li:last-child +{ + -moz-border-bottom-left-radius: 10px; + -webkit-border-bottom-left-radius: 10px; + border-bottom-left-radius: 10px; + -moz-border-bottom-right-radius: 10px; + -webkit-border-bottom-right-radius: 10px; + border-bottom-right-radius: 10px; + border-bottom: 2px groove #fff; +} + +ul.mail li +{ + line-height: 24px; + padding-bottom: 3px; +} + +ul li.pop +{ + text-align: center; +} + +ul li.radio.checked /* Adjust text colour on selected radio item */ +{ + color: #385487; + background: #f7f7f7; +} + +ul li.grey /* Grey text generally used to show inactive fields */ +{ + color: #8f8f8f; +} + +ul li.active, ul li.radio.checked.active /* Highlight in blue with white text */ +{ + background: #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x; + background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7)); + background: -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: -o-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: linear-gradient(top center, #058cf7 0%, #035de7 100%); + color: #fff; +} + +/*------------------------------ Define the styles for anchor elements ------------------------------*/ + +input, textarea, a +{ + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); /* Hide the tap highlighting by making it transparent. */ +} + +a +{ + -webkit-touch-callout: none; + cursor: default; /* Disable the "hand" cursor over anchors. */ +} + +ul li a +{ + outline: none; + text-decoration: none; /* Hide the underline */ + color: inherit; /* Get the text colour from the item containing the anchor. */ + display: block; /* Treat anchor as a block element - needed to correctly display image. */ +} + + +ul.list li a, label, ul.list li.arrow a, ul.mail li a, ul.list li.multiline a div +{ + position: relative; + padding: 0 11px 0 11px; /* top right bottom left */ + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + +ul.list li.arrow a, ul.mail li.arrow a +{ + padding-right: 30px; /* When a list item has a chevron we need to increase anchor right padding past it. */ +} + +ul li.icon a, ul li.clickable-icon a +{ + margin-left: 5px; + text-indent: 40px; +} + +ul.list li.icon a, ul.list li.clickable-icon a +{ + margin-left: 8px; + text-indent: 30px; + + /* For icon/clickable-icon when not a multiline item we need to increase anchor top and bottom padding so + that we don't end up clipping the top and bottom off the icon. */ + padding-top: 5px; + padding-bottom: 5px; +} + +ul.mail li a +{ + left: 8px; + text-indent: 18px; /* Indents the text to the right of the image. */ +} + +ul.mail li.unread a +{ + background: url(/itablet/images/blueball.png) no-repeat left; +} + + +ul li.arrow +{ + text-align: left; /* This resets alignment in case class="pop arrow" is used because pop centre aligns. */ + background: url(/itablet/images/chevron.png) no-repeat right; +} + +ul.list li.arrow +{ + background: #f7f7f7 url(/itablet/images/chevron.png) no-repeat right; +} + +ul li.active.arrow +{ + background: url(/itablet/images/chevron-active.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x; + background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7)); + background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%); +} + +/*--------------------------- Define the styles for right justified text ----------------------------*/ + +ul li a p +{ + position: absolute; + top: 0; + right: 11px; + + padding: 0; + width: 50%; + text-align: right; + text-indent: 0; + + color: #464646; + font-weight: normal; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; +} + +ul li a p.fullwidth +{ + width: 100%; +} + +ul li a p.date +{ + color: #3078da; + font-size: 13px; +} + +ul li.arrow a p +{ + right: 30px; +} + +/*----------------------------- Define the styles for multiline items -------------------------------*/ + +ul.list li.multiline a +{ + padding-top: 0px; + padding-bottom: 0px; +} + +ul.list li.multiline a div +{ + padding: 0; +} + +ul.list li.multiline a div p +{ + right: 0; +} + +ul li a p.sub, ul li a p.title +{ + position: relative; + top: 0; + left: 0; + + width: auto; + text-align: left; + + color: gray; + font-size: 14px; + line-height: 16px; +} + +ul li a p.title +{ + color: #060606; +} + +ul.list li.icon a p.sub, ul.list li.clickable-icon a p.sub, +ul.list li.icon a p.title, ul.list li.clickable-icon a p.title +{ + margin-left: 30px; +} + +ul.mail li a p.sub, ul.mail li a p.title +{ + margin-left: 18px; +} + +ul.mail li a p.sub +{ + font-size: 12px; + height: 33px; + white-space: normal; +} + +ul li.active a p, ul.mail li.active a p +{ + color: #fff; +} + +/*------------------------------- Define the styles for input fields --------------------------------*/ + +label +{ + display: block; +} + +label.input /* Adding the input class to a label will allow overflow truncation to work */ +{ + width: 115px; +} + +input, .placeholder +{ + position: absolute; + top: 0; + left: 115px; + right: 11px; + padding: 9px 0 9px 0; /* top right bottom left */ + border: 0; + font: 17px Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif; +} + + +.placeholder.textarea +{ + left: 11px; + font-size: 12px +} + +.placeholder /* Used to fake HTML5 input placeholders in browsers that don't have native support. */ +{ + padding: 12px 0 12px 0; /* top right bottom left */ + color: #9f9f9f; +} + +input.error, textarea.error +{ + -webkit-appearance: none; + moz-box-shadow: 0 0 4px red; + webkit-box-shadow: 0 0 4px red; + box-shadow: 0 0 4px red; +} + +textarea +{ + position: relative; /* Needs to be set for fake placeholders to work properly - the z-index needs to be 1 */ + + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + + resize: vertical; + + width: 100%; + height: 100px; + + border: 0; + padding: 0 11px 0 11px; + + overflow: auto; +} + +/* + For fake placeholders to work we want to ensure the input/textarea is in the foreground and receiving events, + but we also need them to be transparent so we can see the placeholder through them. +*/ +input, textarea +{ + background: rgba(0, 0, 0, 0); + z-index: 1; +} + +/*---------------------------- Define the styles for radio button widget ----------------------------*/ + +ul.list li.radio label +{ + padding: 0 32px 0 11px; /* top right bottom left */ +} + +ul.list li.radio.checked label +{ + background: url(/itablet/images/tick.png) no-repeat right; +} + +ul.list li.radio.active.checked label +{ + background: url(/itablet/images/tick-active.png) no-repeat right; +} + +ul.list li.arrow.radio +{ + background: #f7f7f7 url(/itablet/images/blue-chevron.png) no-repeat right; +} + +ul.list li.arrow.radio.active +{ + background: url(/itablet/images/blue-chevron.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x; + background: url(/itablet/images/blue-chevron.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7)); + background: url(/itablet/images/blue-chevron.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/blue-chevron.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/blue-chevron.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/blue-chevron.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/blue-chevron.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%); +} + +ul.list li.arrow.radio label +{ + padding: 0 38px 0 32px; /* top right bottom left */ +} + +ul.list li.arrow.radio.checked label +{ + background: url(/itablet/images/tick.png) no-repeat 11px; +} + +ul.list li.arrow.radio.active.checked label +{ + background: url(/itablet/images/tick-active.png) no-repeat 11px; +} + +/*------------------------------ Define the styles for checkbox widget ------------------------------*/ + +div.checkbox +{ + position: absolute; + overflow: hidden; /* clip the child div to the size of this one */ + top: 7px; + right: 11px; + width: 77px; + height: 27px; +} + +div.mask +{ + position: absolute; + width: 100%; + height: 100%; + z-index: 1; + background: url(/itablet/images/mask.png) no-repeat; +} + +div.onoff +{ + position: absolute; + top: 0; + left: -50px; + width: 127px; + height: 27px; + background: url(/itablet/images/on_off.png) no-repeat; +} + +/*------------------------- Define the styles for horizontal checkbox widget ------------------------*/ + +ul.list li.horiz-checkbox +{ + display: block; + padding: 0; + line-height: 40px; + background: url(/itablet/images/toggle-off.png) repeat-x; +} + +ul.list li.horiz-checkbox label +{ + color: #717880; + text-shadow: #fff 0 1px 0; + + display: inline-block; + vertical-align: bottom; + text-align: center; + padding: 0; + width: 100%; + background: url(/itablet/images/toggle-off.png) repeat-x; +} + +ul.list li.horiz-checkbox label span +{ + position: absolute; + top: 0; + right: 0; + height: 100%; + border-right: 1px solid #828278; +} + +/* Use toggle-on class not checked to avoid IE6 confusing with a radio button as IE6 doesn't support multiple classes. */ +ul.list li.horiz-checkbox.toggle-on, ul.list li.horiz-checkbox label.checked +{ + color: #fff; + text-shadow: 0 0 0 #000; /* passing all the arguments will reset it to nothing */ + background: url(/itablet/images/toggle-on.png) repeat-x; +} + +ul.list li.horiz-checkbox label.checked span +{ + border-right: 0; + width: 5px; + height: 40px; + background: url(/itablet/images/toggle-on-border.png) no-repeat right; +} + +ul.list li.horiz-checkbox:first-child +{ + border-top: 1px groove #fff; +} + +/* Need to apply border radius to the labels in the horiz-checkbox too as child elements aren't clipped. */ + +ul.list li.horiz-checkbox:first-child label.first-child +{ + -moz-border-top-left-radius: 10px; + -webkit-border-top-left-radius: 10px; + border-top-left-radius: 10px; +} + +ul.list li.horiz-checkbox:first-child label.last-child +{ + -moz-border-top-right-radius: 10px; + -webkit-border-top-right-radius: 10px; + border-top-right-radius: 10px; +} + +ul.list li.horiz-checkbox:last-child label.first-child +{ + -moz-border-bottom-left-radius: 10px; + -webkit-border-bottom-left-radius: 10px; + border-bottom-left-radius: 10px; +} + +ul.list li.horiz-checkbox:last-child label.last-child +{ + -moz-border-bottom-right-radius: 10px; + -webkit-border-bottom-right-radius: 10px; + border-bottom-right-radius: 10px; +} + +/*-------------------------------- Style for the HTML5 drawing canvas -------------------------------*/ +/* N.B. By the standard, CSS does not size the canvas coordinate system, it scales the content. This */ +/* means that we can't style canvas width and height, these must be set via Javascript if we wish to */ +/* use relative sizes. */ +/*---------------------------------------------------------------------------------------------------*/ +canvas +{ + border: 2px groove #fff; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; + background-color: #f6f6f6; + display: block; +} + + + + +/*---------------------------- Detect mobile sized screen via media query ---------------------------*/ +/* +@media only screen and (max-width: 480px) +*/ + +@media only screen and (max-device-width: 480px), + only screen and (min-device-width: 640px) and (max-device-width: 1136px) and (-webkit-min-device-pixel-ratio: 2) +{ + .sidebar + { + width: 100%; + } + + .main /* We check the .main left value in JavaScript if we want to detect mobile or non-mobile */ + { + left: 0; + } + + .popup-container + { /* For some reason the Android VM I'm using isn't respecting top & bottom of zero here iPhone is fine!! */ + top: 0; + bottom: 0; + left: 0; + right: 0; + } + + /* For mobile devices display the menu back buttons */ + div.header a.menu + { + display: block; + } + + .sidebar ul li + { + background: url(/itablet/images/chevron.png) no-repeat right; + } + + .sidebar ul li.active + { + background: url(/itablet/images/chevron-active.png) no-repeat right, #035de7 url(/itablet/images/ie/active-gradient.png) repeat-x; + background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0, #058cf7), color-stop(1, #035de7)); + background: url(/itablet/images/chevron-active.png) no-repeat right, -webkit-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -moz-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -ms-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, -o-linear-gradient(top center, #058cf7 0%, #035de7 100%); + background: url(/itablet/images/chevron-active.png) no-repeat right, linear-gradient(top center, #058cf7 0%, #035de7 100%); + } +} + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/action.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/action.png Binary files differnew file mode 100644 index 0000000000..af5e0378b0 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/action.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/add.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/add.png Binary files differnew file mode 100644 index 0000000000..700d9f100e --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/add.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/bin.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/bin.png Binary files differnew file mode 100644 index 0000000000..90923898af --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/bin.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-button-sprite.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-button-sprite.png Binary files differnew file mode 100644 index 0000000000..9fedd12867 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-button-sprite.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-chevron.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-chevron.png Binary files differnew file mode 100644 index 0000000000..41e539fc10 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blue-chevron.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blueball.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blueball.png Binary files differnew file mode 100644 index 0000000000..a7c4c68349 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/blueball.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/button-sprite.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/button-sprite.png Binary files differnew file mode 100644 index 0000000000..c15b4ea217 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/button-sprite.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron-active.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron-active.png Binary files differnew file mode 100644 index 0000000000..86832ebc7b --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron-active.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron.png Binary files differnew file mode 100644 index 0000000000..6421a16762 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/chevron.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/delete.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/delete.png Binary files differnew file mode 100644 index 0000000000..74b1ff3ea1 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/delete.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/flag.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/flag.png Binary files differnew file mode 100644 index 0000000000..0baf2a9986 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/flag.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/home.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/home.png Binary files differnew file mode 100644 index 0000000000..4f359778a2 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/home.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/active-gradient.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/active-gradient.png Binary files differnew file mode 100644 index 0000000000..6cd4404965 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/active-gradient.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif Binary files differnew file mode 100644 index 0000000000..8edaddedd8 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-button-sprite.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif Binary files differnew file mode 100644 index 0000000000..bb8f3d51d6 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/blue-chevron.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/button-sprite.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/button-sprite.gif Binary files differnew file mode 100644 index 0000000000..5e920511d1 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/button-sprite.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron-active.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron-active.gif Binary files differnew file mode 100644 index 0000000000..f37329bb3b --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron-active.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron.gif Binary files differnew file mode 100644 index 0000000000..dce238269a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/chevron.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/header-gradient.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/header-gradient.png Binary files differnew file mode 100644 index 0000000000..d4e9a6c9f0 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/header-gradient.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radial-gradient.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radial-gradient.png Binary files differnew file mode 100644 index 0000000000..d9ab361add --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radial-gradient.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png Binary files differnew file mode 100644 index 0000000000..ca91770e2f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-10px-sprite.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png Binary files differnew file mode 100644 index 0000000000..c00e2194db --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/radius-5px-sprite.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/red6.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/red6.png Binary files differnew file mode 100644 index 0000000000..c1c0ba1db9 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/red6.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/smoked.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/smoked.png Binary files differnew file mode 100644 index 0000000000..ea6b7c587f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/smoked.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick-active.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick-active.gif Binary files differnew file mode 100644 index 0000000000..629f6f1eca --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick-active.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick.gif Binary files differnew file mode 100644 index 0000000000..fdbdc1eec2 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/tick.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.gif Binary files differnew file mode 100755 index 0000000000..c5b2954ac6 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.png Binary files differnew file mode 100644 index 0000000000..8ac7f64f1a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/ie/transparent.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/mask.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/mask.png Binary files differnew file mode 100644 index 0000000000..f8be0e6f36 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/mask.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/move.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/move.png Binary files differnew file mode 100644 index 0000000000..80f77eeb72 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/move.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/on_off.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/on_off.png Binary files differnew file mode 100644 index 0000000000..89243bf27d --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/on_off.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick-active.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick-active.png Binary files differnew file mode 100644 index 0000000000..16fa8ca71b --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick-active.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick.png Binary files differnew file mode 100644 index 0000000000..783b60fe9a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/tick.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-off.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-off.png Binary files differnew file mode 100644 index 0000000000..474ad3cd63 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-off.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on-border.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on-border.png Binary files differnew file mode 100644 index 0000000000..7680cd7d0a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on-border.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on.png Binary files differnew file mode 100644 index 0000000000..275aa42114 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/toggle-on.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/write.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/write.png Binary files differnew file mode 100644 index 0000000000..b7329dbf9f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/images/write.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/LICENCE b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/LICENCE new file mode 100644 index 0000000000..7d95218a1e --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/LICENCE @@ -0,0 +1,48 @@ + +/* + * jQuery JavaScript Library v1.7.1 + * http://jquery.com/ + * + * Copyright 2011, John Resig + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * Includes Sizzle.js + * http://sizzlejs.com/ + * Copyright 2011, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * + * Date: Mon Nov 21 21:11:03 2011 -0500 + */ + + +/* + * iscroll.js + * + * Copyright (c) 2011 Matteo Spinelli, http://cubiq.org/ + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/iscroll.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/iscroll.js new file mode 100644 index 0000000000..46330e51f7 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/iscroll.js @@ -0,0 +1,1117 @@ +/*! + * iScroll v4.2 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org + * Released under MIT license, http://cubiq.org/license + */ +(function(window, doc){ +var m = Math, + dummyStyle = doc.createElement('div').style, + vendor = (function () { + var vendors = 't,webkitT,MozT,msT,OT'.split(','), + t, + i = 0, + l = vendors.length; + + for ( ; i < l; i++ ) { + t = vendors[i] + 'ransform'; + if ( t in dummyStyle ) { + return vendors[i].substr(0, vendors[i].length - 1); + } + } + + return false; + })(), + cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '', + + // Style properties + transform = prefixStyle('transform'), + transitionProperty = prefixStyle('transitionProperty'), + transitionDuration = prefixStyle('transitionDuration'), + transformOrigin = prefixStyle('transformOrigin'), + transitionTimingFunction = prefixStyle('transitionTimingFunction'), + transitionDelay = prefixStyle('transitionDelay'), + + // Browser capabilities + isAndroid = (/android/gi).test(navigator.appVersion), + isIDevice = (/iphone|ipad/gi).test(navigator.appVersion), + isTouchPad = (/hp-tablet/gi).test(navigator.appVersion), + + has3d = prefixStyle('perspective') in dummyStyle, + hasTouch = 'ontouchstart' in window && !isTouchPad, + hasTransform = !!vendor, + hasTransitionEnd = prefixStyle('transition') in dummyStyle, + + RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize', + START_EV = hasTouch ? 'touchstart' : 'mousedown', + MOVE_EV = hasTouch ? 'touchmove' : 'mousemove', + END_EV = hasTouch ? 'touchend' : 'mouseup', + CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup', + WHEEL_EV = vendor == 'Moz' ? 'DOMMouseScroll' : 'mousewheel', + TRNEND_EV = (function () { + if ( vendor === false ) return false; + + var transitionEnd = { + '' : 'transitionend', + 'webkit' : 'webkitTransitionEnd', + 'Moz' : 'transitionend', + 'O' : 'oTransitionEnd', + 'ms' : 'MSTransitionEnd' + }; + + return transitionEnd[vendor]; + })(), + + nextFrame = (function() { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(callback) { return setTimeout(callback, 1); }; + })(), + cancelFrame = (function () { + return window.cancelRequestAnimationFrame || + window.webkitCancelAnimationFrame || + window.webkitCancelRequestAnimationFrame || + window.mozCancelRequestAnimationFrame || + window.oCancelRequestAnimationFrame || + window.msCancelRequestAnimationFrame || + clearTimeout; + })(), + + // Helpers + translateZ = has3d ? ' translateZ(0)' : '', + + // Constructor + iScroll = function (el, options) { + var that = this, + i; + + that.wrapper = typeof el == 'object' ? el : doc.getElementById(el); + that.wrapper.style.overflow = 'hidden'; + that.scroller = that.wrapper.children[0]; + + // Default options + that.options = { + hScroll: true, + vScroll: true, + x: 0, + y: 0, + bounce: true, + bounceLock: false, + momentum: true, + lockDirection: true, + useTransform: true, + useTransition: false, + topOffset: 0, + checkDOMChanges: false, // Experimental + handleClick: true, + + // Scrollbar + hScrollbar: true, + vScrollbar: true, + fixedScrollbar: isAndroid, + hideScrollbar: isIDevice, + fadeScrollbar: isIDevice && has3d, + scrollbarClass: '', + + // Zoom + zoom: false, + zoomMin: 1, + zoomMax: 4, + doubleTapZoom: 2, + wheelAction: 'scroll', + + // Snap + snap: false, + snapThreshold: 1, + + // Events + onRefresh: null, + onBeforeScrollStart: function (e) { e.preventDefault(); }, + onScrollStart: null, + onBeforeScrollMove: null, + onScrollMove: null, + onBeforeScrollEnd: null, + onScrollEnd: null, + onTouchEnd: null, + onDestroy: null, + onZoomStart: null, + onZoom: null, + onZoomEnd: null + }; + + // User defined options + for (i in options) that.options[i] = options[i]; + + // Set starting position + that.x = that.options.x; + that.y = that.options.y; + + // Normalize options + that.options.useTransform = hasTransform && that.options.useTransform; + that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar; + that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar; + that.options.zoom = that.options.useTransform && that.options.zoom; + that.options.useTransition = hasTransitionEnd && that.options.useTransition; + + // Helpers FIX ANDROID BUG! + // translate3d and scale doesn't work together! + // Ignoring 3d ONLY WHEN YOU SET that.options.zoom + if ( that.options.zoom && isAndroid ){ + translateZ = ''; + } + + // Set some default styles + that.scroller.style[transitionProperty] = that.options.useTransform ? cssVendor + 'transform' : 'top left'; + that.scroller.style[transitionDuration] = '0'; + that.scroller.style[transformOrigin] = '0 0'; + if (that.options.useTransition) that.scroller.style[transitionTimingFunction] = 'cubic-bezier(0.33,0.66,0.66,1)'; + + if (that.options.useTransform) that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px)' + translateZ; + else that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px'; + + if (that.options.useTransition) that.options.fixedScrollbar = true; + + that.refresh(); + + that._bind(RESIZE_EV, window); + that._bind(START_EV); + if (!hasTouch) { + that._bind('mouseout', that.wrapper); + if (that.options.wheelAction != 'none') + that._bind(WHEEL_EV); + } + + if (that.options.checkDOMChanges) that.checkDOMTime = setInterval(function () { + that._checkDOMChanges(); + }, 500); + }; + +// Prototype +iScroll.prototype = { + enabled: true, + x: 0, + y: 0, + steps: [], + scale: 1, + currPageX: 0, currPageY: 0, + pagesX: [], pagesY: [], + aniTime: null, + wheelZoomCount: 0, + + handleEvent: function (e) { + var that = this; + switch(e.type) { + case START_EV: + if (!hasTouch && e.button !== 0) return; + that._start(e); + break; + case MOVE_EV: that._move(e); break; + case END_EV: + case CANCEL_EV: that._end(e); break; + case RESIZE_EV: that._resize(); break; + case WHEEL_EV: that._wheel(e); break; + case 'mouseout': that._mouseout(e); break; + case TRNEND_EV: that._transitionEnd(e); break; + } + }, + + _checkDOMChanges: function () { + if (this.moved || this.zoomed || this.animating || + (this.scrollerW == this.scroller.offsetWidth * this.scale && this.scrollerH == this.scroller.offsetHeight * this.scale)) return; + + this.refresh(); + }, + + _scrollbar: function (dir) { + var that = this, + bar; + + if (!that[dir + 'Scrollbar']) { + if (that[dir + 'ScrollbarWrapper']) { + if (hasTransform) that[dir + 'ScrollbarIndicator'].style[transform] = ''; + that[dir + 'ScrollbarWrapper'].parentNode.removeChild(that[dir + 'ScrollbarWrapper']); + that[dir + 'ScrollbarWrapper'] = null; + that[dir + 'ScrollbarIndicator'] = null; + } + + return; + } + + if (!that[dir + 'ScrollbarWrapper']) { + // Create the scrollbar wrapper + bar = doc.createElement('div'); + + if (that.options.scrollbarClass) bar.className = that.options.scrollbarClass + dir.toUpperCase(); + else bar.style.cssText = 'position:absolute;z-index:100;' + (dir == 'h' ? 'height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px' : 'width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px'); + + bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:opacity;' + cssVendor + 'transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1'); + + that.wrapper.appendChild(bar); + that[dir + 'ScrollbarWrapper'] = bar; + + // Create the scrollbar indicator + bar = doc.createElement('div'); + if (!that.options.scrollbarClass) { + bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);' + cssVendor + 'background-clip:padding-box;' + cssVendor + 'box-sizing:border-box;' + (dir == 'h' ? 'height:100%' : 'width:100%') + ';' + cssVendor + 'border-radius:3px;border-radius:3px'; + } + bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:' + cssVendor + 'transform;' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform: translate(0,0)' + translateZ; + if (that.options.useTransition) bar.style.cssText += ';' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)'; + + that[dir + 'ScrollbarWrapper'].appendChild(bar); + that[dir + 'ScrollbarIndicator'] = bar; + } + + if (dir == 'h') { + that.hScrollbarSize = that.hScrollbarWrapper.clientWidth; + that.hScrollbarIndicatorSize = m.max(m.round(that.hScrollbarSize * that.hScrollbarSize / that.scrollerW), 8); + that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px'; + that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize; + that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX; + } else { + that.vScrollbarSize = that.vScrollbarWrapper.clientHeight; + that.vScrollbarIndicatorSize = m.max(m.round(that.vScrollbarSize * that.vScrollbarSize / that.scrollerH), 8); + that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px'; + that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize; + that.vScrollbarProp = that.vScrollbarMaxScroll / that.maxScrollY; + } + + // Reset position + that._scrollbarPos(dir, true); + }, + + _resize: function () { + var that = this; + setTimeout(function () { that.refresh(); }, isAndroid ? 200 : 0); + }, + + _pos: function (x, y) { + if (this.zoomed) return; + + x = this.hScroll ? x : 0; + y = this.vScroll ? y : 0; + + if (this.options.useTransform) { + this.scroller.style[transform] = 'translate(' + x + 'px,' + y + 'px) scale(' + this.scale + ')' + translateZ; + } else { + x = m.round(x); + y = m.round(y); + this.scroller.style.left = x + 'px'; + this.scroller.style.top = y + 'px'; + } + + this.x = x; + this.y = y; + + this._scrollbarPos('h'); + this._scrollbarPos('v'); + }, + + _scrollbarPos: function (dir, hidden) { + var that = this, + pos = dir == 'h' ? that.x : that.y, + size; + + if (!that[dir + 'Scrollbar']) return; + + pos = that[dir + 'ScrollbarProp'] * pos; + + if (pos < 0) { + if (!that.options.fixedScrollbar) { + size = that[dir + 'ScrollbarIndicatorSize'] + m.round(pos * 3); + if (size < 8) size = 8; + that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px'; + } + pos = 0; + } else if (pos > that[dir + 'ScrollbarMaxScroll']) { + if (!that.options.fixedScrollbar) { + size = that[dir + 'ScrollbarIndicatorSize'] - m.round((pos - that[dir + 'ScrollbarMaxScroll']) * 3); + if (size < 8) size = 8; + that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px'; + pos = that[dir + 'ScrollbarMaxScroll'] + (that[dir + 'ScrollbarIndicatorSize'] - size); + } else { + pos = that[dir + 'ScrollbarMaxScroll']; + } + } + + that[dir + 'ScrollbarWrapper'].style[transitionDelay] = '0'; + that[dir + 'ScrollbarWrapper'].style.opacity = hidden && that.options.hideScrollbar ? '0' : '1'; + that[dir + 'ScrollbarIndicator'].style[transform] = 'translate(' + (dir == 'h' ? pos + 'px,0)' : '0,' + pos + 'px)') + translateZ; + }, + + _start: function (e) { + var that = this, + point = hasTouch ? e.touches[0] : e, + matrix, x, y, + c1, c2; + + if (!that.enabled) return; + + if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e); + + if (that.options.useTransition || that.options.zoom) that._transitionTime(0); + + that.moved = false; + that.animating = false; + that.zoomed = false; + that.distX = 0; + that.distY = 0; + that.absDistX = 0; + that.absDistY = 0; + that.dirX = 0; + that.dirY = 0; + + // Gesture start + if (that.options.zoom && hasTouch && e.touches.length > 1) { + c1 = m.abs(e.touches[0].pageX-e.touches[1].pageX); + c2 = m.abs(e.touches[0].pageY-e.touches[1].pageY); + that.touchesDistStart = m.sqrt(c1 * c1 + c2 * c2); + + that.originX = m.abs(e.touches[0].pageX + e.touches[1].pageX - that.wrapperOffsetLeft * 2) / 2 - that.x; + that.originY = m.abs(e.touches[0].pageY + e.touches[1].pageY - that.wrapperOffsetTop * 2) / 2 - that.y; + + if (that.options.onZoomStart) that.options.onZoomStart.call(that, e); + } + + if (that.options.momentum) { + if (that.options.useTransform) { + // Very lame general purpose alternative to CSSMatrix + matrix = getComputedStyle(that.scroller, null)[transform].replace(/[^0-9\-.,]/g, '').split(','); + x = matrix[4] * 1; + y = matrix[5] * 1; + } else { + x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1; + y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1; + } + + if (x != that.x || y != that.y) { + if (that.options.useTransition) that._unbind(TRNEND_EV); + else cancelFrame(that.aniTime); + that.steps = []; + that._pos(x, y); + } + } + + that.absStartX = that.x; // Needed by snap threshold + that.absStartY = that.y; + + that.startX = that.x; + that.startY = that.y; + that.pointX = point.pageX; + that.pointY = point.pageY; + + that.startTime = e.timeStamp || Date.now(); + + if (that.options.onScrollStart) that.options.onScrollStart.call(that, e); + + that._bind(MOVE_EV); + that._bind(END_EV); + that._bind(CANCEL_EV); + }, + + _move: function (e) { + var that = this, + point = hasTouch ? e.touches[0] : e, + deltaX = point.pageX - that.pointX, + deltaY = point.pageY - that.pointY, + newX = that.x + deltaX, + newY = that.y + deltaY, + c1, c2, scale, + timestamp = e.timeStamp || Date.now(); + + if (that.options.onBeforeScrollMove) that.options.onBeforeScrollMove.call(that, e); + + // Zoom + if (that.options.zoom && hasTouch && e.touches.length > 1) { + c1 = m.abs(e.touches[0].pageX - e.touches[1].pageX); + c2 = m.abs(e.touches[0].pageY - e.touches[1].pageY); + that.touchesDist = m.sqrt(c1*c1+c2*c2); + + that.zoomed = true; + + scale = 1 / that.touchesDistStart * that.touchesDist * this.scale; + + if (scale < that.options.zoomMin) scale = 0.5 * that.options.zoomMin * Math.pow(2.0, scale / that.options.zoomMin); + else if (scale > that.options.zoomMax) scale = 2.0 * that.options.zoomMax * Math.pow(0.5, that.options.zoomMax / scale); + + that.lastScale = scale / this.scale; + + newX = this.originX - this.originX * that.lastScale + this.x, + newY = this.originY - this.originY * that.lastScale + this.y; + + this.scroller.style[transform] = 'translate(' + newX + 'px,' + newY + 'px) scale(' + scale + ')' + translateZ; + + if (that.options.onZoom) that.options.onZoom.call(that, e); + return; + } + + that.pointX = point.pageX; + that.pointY = point.pageY; + + // Slow down if outside of the boundaries + if (newX > 0 || newX < that.maxScrollX) { + newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX; + } + if (newY > that.minScrollY || newY < that.maxScrollY) { + newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY; + } + + that.distX += deltaX; + that.distY += deltaY; + that.absDistX = m.abs(that.distX); + that.absDistY = m.abs(that.distY); + + if (that.absDistX < 6 && that.absDistY < 6) { + return; + } + + // Lock direction + if (that.options.lockDirection) { + if (that.absDistX > that.absDistY + 5) { + newY = that.y; + deltaY = 0; + } else if (that.absDistY > that.absDistX + 5) { + newX = that.x; + deltaX = 0; + } + } + + that.moved = true; + that._pos(newX, newY); + that.dirX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0; + that.dirY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0; + + if (timestamp - that.startTime > 300) { + that.startTime = timestamp; + that.startX = that.x; + that.startY = that.y; + } + + if (that.options.onScrollMove) that.options.onScrollMove.call(that, e); + }, + + _end: function (e) { + if (hasTouch && e.touches.length !== 0) return; + + var that = this, + point = hasTouch ? e.changedTouches[0] : e, + target, ev, + momentumX = { dist:0, time:0 }, + momentumY = { dist:0, time:0 }, + duration = (e.timeStamp || Date.now()) - that.startTime, + newPosX = that.x, + newPosY = that.y, + distX, distY, + newDuration, + snap, + scale; + + that._unbind(MOVE_EV); + that._unbind(END_EV); + that._unbind(CANCEL_EV); + + if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e); + + if (that.zoomed) { + scale = that.scale * that.lastScale; + scale = Math.max(that.options.zoomMin, scale); + scale = Math.min(that.options.zoomMax, scale); + that.lastScale = scale / that.scale; + that.scale = scale; + + that.x = that.originX - that.originX * that.lastScale + that.x; + that.y = that.originY - that.originY * that.lastScale + that.y; + + that.scroller.style[transitionDuration] = '200ms'; + that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + that.scale + ')' + translateZ; + + that.zoomed = false; + that.refresh(); + + if (that.options.onZoomEnd) that.options.onZoomEnd.call(that, e); + return; + } + + if (!that.moved) { + if (hasTouch) { + if (that.doubleTapTimer && that.options.zoom) { + // Double tapped + clearTimeout(that.doubleTapTimer); + that.doubleTapTimer = null; + if (that.options.onZoomStart) that.options.onZoomStart.call(that, e); + that.zoom(that.pointX, that.pointY, that.scale == 1 ? that.options.doubleTapZoom : 1); + if (that.options.onZoomEnd) { + setTimeout(function() { + that.options.onZoomEnd.call(that, e); + }, 200); // 200 is default zoom duration + } + } else if (this.options.handleClick) { + that.doubleTapTimer = setTimeout(function () { + that.doubleTapTimer = null; + + // Find the last touched element + target = point.target; + while (target.nodeType != 1) target = target.parentNode; + + if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') { + ev = doc.createEvent('MouseEvents'); + ev.initMouseEvent('click', true, true, e.view, 1, + point.screenX, point.screenY, point.clientX, point.clientY, + e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, + 0, null); + ev._fake = true; + target.dispatchEvent(ev); + } + }, that.options.zoom ? 250 : 0); + } + } + + that._resetPos(200); + + if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); + return; + } + + if (duration < 300 && that.options.momentum) { + momentumX = newPosX ? that._momentum(newPosX - that.startX, duration, -that.x, that.scrollerW - that.wrapperW + that.x, that.options.bounce ? that.wrapperW : 0) : momentumX; + momentumY = newPosY ? that._momentum(newPosY - that.startY, duration, -that.y, (that.maxScrollY < 0 ? that.scrollerH - that.wrapperH + that.y - that.minScrollY : 0), that.options.bounce ? that.wrapperH : 0) : momentumY; + + newPosX = that.x + momentumX.dist; + newPosY = that.y + momentumY.dist; + + if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist:0, time:0 }; + if ((that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist:0, time:0 }; + } + + if (momentumX.dist || momentumY.dist) { + newDuration = m.max(m.max(momentumX.time, momentumY.time), 10); + + // Do we need to snap? + if (that.options.snap) { + distX = newPosX - that.absStartX; + distY = newPosY - that.absStartY; + if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) { that.scrollTo(that.absStartX, that.absStartY, 200); } + else { + snap = that._snap(newPosX, newPosY); + newPosX = snap.x; + newPosY = snap.y; + newDuration = m.max(snap.time, newDuration); + } + } + + that.scrollTo(m.round(newPosX), m.round(newPosY), newDuration); + + if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); + return; + } + + // Do we need to snap? + if (that.options.snap) { + distX = newPosX - that.absStartX; + distY = newPosY - that.absStartY; + if (m.abs(distX) < that.options.snapThreshold && m.abs(distY) < that.options.snapThreshold) that.scrollTo(that.absStartX, that.absStartY, 200); + else { + snap = that._snap(that.x, that.y); + if (snap.x != that.x || snap.y != that.y) that.scrollTo(snap.x, snap.y, snap.time); + } + + if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); + return; + } + + that._resetPos(200); + if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); + }, + + _resetPos: function (time) { + var that = this, + resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x, + resetY = that.y >= that.minScrollY || that.maxScrollY > 0 ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y; + + if (resetX == that.x && resetY == that.y) { + if (that.moved) { + that.moved = false; + if (that.options.onScrollEnd) that.options.onScrollEnd.call(that); // Execute custom code on scroll end + } + + if (that.hScrollbar && that.options.hideScrollbar) { + if (vendor == 'webkit') that.hScrollbarWrapper.style[transitionDelay] = '300ms'; + that.hScrollbarWrapper.style.opacity = '0'; + } + if (that.vScrollbar && that.options.hideScrollbar) { + if (vendor == 'webkit') that.vScrollbarWrapper.style[transitionDelay] = '300ms'; + that.vScrollbarWrapper.style.opacity = '0'; + } + + return; + } + + that.scrollTo(resetX, resetY, time || 0); + }, + + _wheel: function (e) { + var that = this, + wheelDeltaX, wheelDeltaY, + deltaX, deltaY, + deltaScale; + + if ('wheelDeltaX' in e) { + wheelDeltaX = e.wheelDeltaX / 12; + wheelDeltaY = e.wheelDeltaY / 12; + } else if('wheelDelta' in e) { + wheelDeltaX = wheelDeltaY = e.wheelDelta / 12; + } else if ('detail' in e) { + wheelDeltaX = wheelDeltaY = -e.detail * 3; + } else { + return; + } + + if (that.options.wheelAction == 'zoom') { + deltaScale = that.scale * Math.pow(2, 1/3 * (wheelDeltaY ? wheelDeltaY / Math.abs(wheelDeltaY) : 0)); + if (deltaScale < that.options.zoomMin) deltaScale = that.options.zoomMin; + if (deltaScale > that.options.zoomMax) deltaScale = that.options.zoomMax; + + if (deltaScale != that.scale) { + if (!that.wheelZoomCount && that.options.onZoomStart) that.options.onZoomStart.call(that, e); + that.wheelZoomCount++; + + that.zoom(e.pageX, e.pageY, deltaScale, 400); + + setTimeout(function() { + that.wheelZoomCount--; + if (!that.wheelZoomCount && that.options.onZoomEnd) that.options.onZoomEnd.call(that, e); + }, 400); + } + + return; + } + + deltaX = that.x + wheelDeltaX; + deltaY = that.y + wheelDeltaY; + + if (deltaX > 0) deltaX = 0; + else if (deltaX < that.maxScrollX) deltaX = that.maxScrollX; + + if (deltaY > that.minScrollY) deltaY = that.minScrollY; + else if (deltaY < that.maxScrollY) deltaY = that.maxScrollY; + + if (that.maxScrollY < 0) { + that.scrollTo(deltaX, deltaY, 0); + } + }, + + _mouseout: function (e) { + var t = e.relatedTarget; + + if (!t) { + this._end(e); + return; + } + + while (t = t.parentNode) if (t == this.wrapper) return; + + this._end(e); + }, + + _transitionEnd: function (e) { + var that = this; + + if (e.target != that.scroller) return; + + that._unbind(TRNEND_EV); + + that._startAni(); + }, + + + /** + * + * Utilities + * + */ + _startAni: function () { + var that = this, + startX = that.x, startY = that.y, + startTime = Date.now(), + step, easeOut, + animate; + + if (that.animating) return; + + if (!that.steps.length) { + that._resetPos(400); + return; + } + + step = that.steps.shift(); + + if (step.x == startX && step.y == startY) step.time = 0; + + that.animating = true; + that.moved = true; + + if (that.options.useTransition) { + that._transitionTime(step.time); + that._pos(step.x, step.y); + that.animating = false; + if (step.time) that._bind(TRNEND_EV); + else that._resetPos(0); + return; + } + + animate = function () { + var now = Date.now(), + newX, newY; + + if (now >= startTime + step.time) { + that._pos(step.x, step.y); + that.animating = false; + if (that.options.onAnimationEnd) that.options.onAnimationEnd.call(that); // Execute custom code on animation end + that._startAni(); + return; + } + + now = (now - startTime) / step.time - 1; + easeOut = m.sqrt(1 - now * now); + newX = (step.x - startX) * easeOut + startX; + newY = (step.y - startY) * easeOut + startY; + that._pos(newX, newY); + if (that.animating) that.aniTime = nextFrame(animate); + }; + + animate(); + }, + + _transitionTime: function (time) { + time += 'ms'; + this.scroller.style[transitionDuration] = time; + if (this.hScrollbar) this.hScrollbarIndicator.style[transitionDuration] = time; + if (this.vScrollbar) this.vScrollbarIndicator.style[transitionDuration] = time; + }, + + _momentum: function (dist, time, maxDistUpper, maxDistLower, size) { + var deceleration = 0.0006, + speed = m.abs(dist) / time, + newDist = (speed * speed) / (2 * deceleration), + newTime = 0, outsideDist = 0; + + // Proportinally reduce speed if we are outside of the boundaries + if (dist > 0 && newDist > maxDistUpper) { + outsideDist = size / (6 / (newDist / speed * deceleration)); + maxDistUpper = maxDistUpper + outsideDist; + speed = speed * maxDistUpper / newDist; + newDist = maxDistUpper; + } else if (dist < 0 && newDist > maxDistLower) { + outsideDist = size / (6 / (newDist / speed * deceleration)); + maxDistLower = maxDistLower + outsideDist; + speed = speed * maxDistLower / newDist; + newDist = maxDistLower; + } + + newDist = newDist * (dist < 0 ? -1 : 1); + newTime = speed / deceleration; + + return { dist: newDist, time: m.round(newTime) }; + }, + + _offset: function (el) { + var left = -el.offsetLeft, + top = -el.offsetTop; + + while (el = el.offsetParent) { + left -= el.offsetLeft; + top -= el.offsetTop; + } + + if (el != this.wrapper) { + left *= this.scale; + top *= this.scale; + } + + return { left: left, top: top }; + }, + + _snap: function (x, y) { + var that = this, + i, l, + page, time, + sizeX, sizeY; + + // Check page X + page = that.pagesX.length - 1; + for (i=0, l=that.pagesX.length; i<l; i++) { + if (x >= that.pagesX[i]) { + page = i; + break; + } + } + if (page == that.currPageX && page > 0 && that.dirX < 0) page--; + x = that.pagesX[page]; + sizeX = m.abs(x - that.pagesX[that.currPageX]); + sizeX = sizeX ? m.abs(that.x - x) / sizeX * 500 : 0; + that.currPageX = page; + + // Check page Y + page = that.pagesY.length-1; + for (i=0; i<page; i++) { + if (y >= that.pagesY[i]) { + page = i; + break; + } + } + if (page == that.currPageY && page > 0 && that.dirY < 0) page--; + y = that.pagesY[page]; + sizeY = m.abs(y - that.pagesY[that.currPageY]); + sizeY = sizeY ? m.abs(that.y - y) / sizeY * 500 : 0; + that.currPageY = page; + + // Snap with constant speed (proportional duration) + time = m.round(m.max(sizeX, sizeY)) || 200; + + return { x: x, y: y, time: time }; + }, + + _bind: function (type, el, bubble) { + (el || this.scroller).addEventListener(type, this, !!bubble); + }, + + _unbind: function (type, el, bubble) { + (el || this.scroller).removeEventListener(type, this, !!bubble); + }, + + + /** + * + * Public methods + * + */ + destroy: function () { + var that = this; + + that.scroller.style[transform] = ''; + + // Remove the scrollbars + that.hScrollbar = false; + that.vScrollbar = false; + that._scrollbar('h'); + that._scrollbar('v'); + + // Remove the event listeners + that._unbind(RESIZE_EV, window); + that._unbind(START_EV); + that._unbind(MOVE_EV); + that._unbind(END_EV); + that._unbind(CANCEL_EV); + + if (!that.options.hasTouch) { + that._unbind('mouseout', that.wrapper); + that._unbind(WHEEL_EV); + } + + if (that.options.useTransition) that._unbind(TRNEND_EV); + + if (that.options.checkDOMChanges) clearInterval(that.checkDOMTime); + + if (that.options.onDestroy) that.options.onDestroy.call(that); + }, + + refresh: function () { + var that = this, + offset, + i, l, + els, + pos = 0, + page = 0; + + if (that.scale < that.options.zoomMin) that.scale = that.options.zoomMin; + that.wrapperW = that.wrapper.clientWidth || 1; + that.wrapperH = that.wrapper.clientHeight || 1; + + that.minScrollY = -that.options.topOffset || 0; + that.scrollerW = m.round(that.scroller.offsetWidth * that.scale); + that.scrollerH = m.round((that.scroller.offsetHeight + that.minScrollY) * that.scale); + that.maxScrollX = that.wrapperW - that.scrollerW; + that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY; + that.dirX = 0; + that.dirY = 0; + + if (that.options.onRefresh) that.options.onRefresh.call(that); + + that.hScroll = that.options.hScroll && that.maxScrollX < 0; + that.vScroll = that.options.vScroll && (!that.options.bounceLock && !that.hScroll || that.scrollerH > that.wrapperH); + + that.hScrollbar = that.hScroll && that.options.hScrollbar; + that.vScrollbar = that.vScroll && that.options.vScrollbar && that.scrollerH > that.wrapperH; + + offset = that._offset(that.wrapper); + that.wrapperOffsetLeft = -offset.left; + that.wrapperOffsetTop = -offset.top; + + // Prepare snap + if (typeof that.options.snap == 'string') { + that.pagesX = []; + that.pagesY = []; + els = that.scroller.querySelectorAll(that.options.snap); + for (i=0, l=els.length; i<l; i++) { + pos = that._offset(els[i]); + pos.left += that.wrapperOffsetLeft; + pos.top += that.wrapperOffsetTop; + that.pagesX[i] = pos.left < that.maxScrollX ? that.maxScrollX : pos.left * that.scale; + that.pagesY[i] = pos.top < that.maxScrollY ? that.maxScrollY : pos.top * that.scale; + } + } else if (that.options.snap) { + that.pagesX = []; + while (pos >= that.maxScrollX) { + that.pagesX[page] = pos; + pos = pos - that.wrapperW; + page++; + } + if (that.maxScrollX%that.wrapperW) that.pagesX[that.pagesX.length] = that.maxScrollX - that.pagesX[that.pagesX.length-1] + that.pagesX[that.pagesX.length-1]; + + pos = 0; + page = 0; + that.pagesY = []; + while (pos >= that.maxScrollY) { + that.pagesY[page] = pos; + pos = pos - that.wrapperH; + page++; + } + if (that.maxScrollY%that.wrapperH) that.pagesY[that.pagesY.length] = that.maxScrollY - that.pagesY[that.pagesY.length-1] + that.pagesY[that.pagesY.length-1]; + } + + // Prepare the scrollbars + that._scrollbar('h'); + that._scrollbar('v'); + + if (!that.zoomed) { + that.scroller.style[transitionDuration] = '0'; + that._resetPos(200); + } + }, + + scrollTo: function (x, y, time, relative) { + var that = this, + step = x, + i, l; + + that.stop(); + + if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }]; + + for (i=0, l=step.length; i<l; i++) { + if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; } + that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 }); + } + + that._startAni(); + }, + + scrollToElement: function (el, time) { + var that = this, pos; + el = el.nodeType ? el : that.scroller.querySelector(el); + if (!el) return; + + pos = that._offset(el); + pos.left += that.wrapperOffsetLeft; + pos.top += that.wrapperOffsetTop; + + pos.left = pos.left > 0 ? 0 : pos.left < that.maxScrollX ? that.maxScrollX : pos.left; + pos.top = pos.top > that.minScrollY ? that.minScrollY : pos.top < that.maxScrollY ? that.maxScrollY : pos.top; + time = time === undefined ? m.max(m.abs(pos.left)*2, m.abs(pos.top)*2) : time; + + that.scrollTo(pos.left, pos.top, time); + }, + + scrollToPage: function (pageX, pageY, time) { + var that = this, x, y; + + time = time === undefined ? 400 : time; + + if (that.options.onScrollStart) that.options.onScrollStart.call(that); + + if (that.options.snap) { + pageX = pageX == 'next' ? that.currPageX+1 : pageX == 'prev' ? that.currPageX-1 : pageX; + pageY = pageY == 'next' ? that.currPageY+1 : pageY == 'prev' ? that.currPageY-1 : pageY; + + pageX = pageX < 0 ? 0 : pageX > that.pagesX.length-1 ? that.pagesX.length-1 : pageX; + pageY = pageY < 0 ? 0 : pageY > that.pagesY.length-1 ? that.pagesY.length-1 : pageY; + + that.currPageX = pageX; + that.currPageY = pageY; + x = that.pagesX[pageX]; + y = that.pagesY[pageY]; + } else { + x = -that.wrapperW * pageX; + y = -that.wrapperH * pageY; + if (x < that.maxScrollX) x = that.maxScrollX; + if (y < that.maxScrollY) y = that.maxScrollY; + } + + that.scrollTo(x, y, time); + }, + + disable: function () { + this.stop(); + this._resetPos(0); + this.enabled = false; + + // If disabled after touchstart we make sure that there are no left over events + this._unbind(MOVE_EV); + this._unbind(END_EV); + this._unbind(CANCEL_EV); + }, + + enable: function () { + this.enabled = true; + }, + + stop: function () { + if (this.options.useTransition) this._unbind(TRNEND_EV); + else cancelFrame(this.aniTime); + this.steps = []; + this.moved = false; + this.animating = false; + }, + + zoom: function (x, y, scale, time) { + var that = this, + relScale = scale / that.scale; + + if (!that.options.useTransform) return; + + that.zoomed = true; + time = time === undefined ? 200 : time; + x = x - that.wrapperOffsetLeft - that.x; + y = y - that.wrapperOffsetTop - that.y; + that.x = x - x * relScale + that.x; + that.y = y - y * relScale + that.y; + + that.scale = scale; + that.refresh(); + + that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x; + that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y; + + that.scroller.style[transitionDuration] = time + 'ms'; + that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + scale + ')' + translateZ; + that.zoomed = false; + }, + + isReady: function () { + return !this.moved && !this.zoomed && !this.animating; + } +}; + +function prefixStyle (style) { + if ( vendor === '' ) return style; + + style = style.charAt(0).toUpperCase() + style.substr(1); + return vendor + style; +} + +dummyStyle = null; // for the sake of it + +if (typeof exports !== 'undefined') exports.iScroll = iScroll; +else window.iScroll = iScroll; + +})(this, document); diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/itablet.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/itablet.js new file mode 100644 index 0000000000..c6f84bcf53 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/itablet.js @@ -0,0 +1,1516 @@ +/* + * + * 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. + * + */ + +/** + * + * This library implements a general user interface look and feel similar to a "well know tablet PC" :-) + * It provides animated page transition eye-candy but is, in essence, really just a fancy tabbed window. + * + * It has dependencies on the following: + * itablet.css + * iscroll.js + * jquery.js (jquery-1.7.1.min.js) + * + * author Fraser Adams + */ + +/** + * Create a Singleton instance of the iTablet user interface generic look and feel. + */ +var iTablet = new function() { + if (!String.prototype.trim) { // Add a String trim method if one doesn't exist (modern browsers should have it.) + String.prototype.trim = function() { + return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); + }; + } + + /** + * The Location inner class allows iTablet.location to be used similarly to window.location. + */ + var Location = function(href) { + this.href = href; + var split = href.split("?"); // Split string by query part. + this.hash = split[0]; + this.search = split.length == 2 ? "?" + split[1] : ""; + this.data = null; + + // Populate the data property with key/value pairs extracted from search part of URL. + if (split.length == 2) { + this.data = {}; + var kv = split[1].split("&"); // Split string into key/value pairs using the & is the separator. + var length = kv.length; + for (var i = 0; i < length; i++) { + var s = kv[i].split("="); + if (s.length == 2) { + var key = s[0].trim(); + var value = s[1].trim(); + this.data[key] = value; + } + } + } + + Location.prototype.toString = function() { + return this.href; + }; + + // Location.back() is mapped to the iTablet.goBack() method. + // This allows clients to explicitly return to a previous page, useful for coding submit handlers etc. + Location.prototype.back = goBack; + }; + + /** + * The TextChange inner class adds support for a textchange Event on text input and textarea tags. + * Initialise with: $.event.special.textchange = new TextChange(); + * Uses info derived from from http://benalman.com/news/2010/03/jquery-special-events/ + */ + var TextChange = function() { + /** + * Directly call the triggerIfChanged method on keyup. + */ + var handler = function() { + triggerIfChanged(this); + }; + + /** + * For cut, paste and input handlers we need to call triggerIfChanged from a timeout. + */ + var handlerWithDelay = function() { + var element = this; + setTimeout(function() { + triggerIfChanged(element); + }, 25); + }; + + /** + * Trigger textchange Event handler bound to target element if the text has changed. + */ + var triggerIfChanged = function(domElement) { + var element = $(domElement); + var current = domElement.contentEditable === "true" ? element.html() : element.val(); + if (current !== element.data("lastValue")) { + element.trigger("textchange", [element.data("lastValue")]); + element.data("lastValue", current); + } + }; + + /** + * Called by jQuery when the first event handler is bound to a particular element. + */ + this.setup = function(data) { + var jthis = $(this); + jthis.data("lastValue", this.contentEditable === 'true' ? jthis.html() : jthis.val()); + // Bind keyup, cut, paste and input handlers in the .textchange Event namespace to allow easy unbinding. + jthis.bind("keyup.textchange", handler); + jthis.bind("cut.textchange paste.textchange input.textchange", handlerWithDelay); + }; + + /** + * Called by jQuery when the last event handler is unbound from a particular element. + */ + this.teardown = function (data) { + $(this).unbind('.textchange'); // Unbind the Events linked to the .textchange Event namespace. + } + }; + +//------------------------------------------------------------------------------------------------------------------- + + var TOUCH_ENABLED = 'ontouchstart' in window && !((/hp-tablet/gi).test(navigator.appVersion)); + + // Select start, move and end events based on whether or not the user agent is a touch device. + var START_EV = (TOUCH_ENABLED) ? "touchstart" : "mousedown"; + var MOVE_EV = (TOUCH_ENABLED) ? "touchmove" : "mousemove"; + var END_EV = (TOUCH_ENABLED) ? "touchend" : "mouseup"; + + // Populated in initialiseCSSAnimations() + var ANIMATION_END_EV = "";// = "animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd"; + var TRANSITION_END_EV = "";//"transitionend webkitTransitionEnd MSTransitionEnd oTransitionEnd"; + + /** + * The general perceived wisdom is to use feature detection rather than browser sniffing, which seems a good + * aim, but as it happens *most* of the browser abstraction is happening in jQuery and CSS but there remain + * a few quirks, mostly for IE < 9. IE < 9 and Opera < 12 both appear not to trigger a change when radio or + * checkbox state changes and it's not clear how to "feature detect" this, which is the main reason for + * including the Opera version sniffing. + */ + var IS_IE = (navigator.appName == "Microsoft Internet Explorer"); + var IE_VERSION = IS_IE ? /MSIE (\d+)/.exec(navigator.userAgent)[1] : 1000000; + var IS_OPERA = (navigator.appName == "Opera") && (window.opera.version != null); + var OPERA_VERSION = IS_OPERA ? opera.version() : 1000000; + + var BODY; // jQuery object for body is used in several places so let's cache it (gets set in jQuery.ready()). + var IS_MOBILE = false; // Gets set if we detect a small display (e.g. mobile) device. + + var _mainLeft = 0; // N.B. We need to get the actual value after the DOM has loaded. + var _history = []; // URL history to enable back button behaviour. + var _scrollers = {}; + var _transitions = {}; // Map of transition names to transition functions (populate later after functions defined). + this.location = null; + + /** + * This public helper method renders an HTML list with up to <maxlength> list items using the <contents> function. + * If the length of the list is less than the number added by the contents function additional list items are + * appended, conversely if the length of the list is greater than the number added by the contents function then + * the list is truncated. + * + * The contents of the list are populated via the supplied <contents> function, which should take an index as a + * parameter and return an <li> with contents or false. If false is returned that item is skipped. + * If an HTML list is supplied without a maxlength and contents function this method will simply carry out + * reskinning of the input widgets for the supplied list (and adding radiused borders for older versions of IE). + * + * For some reason this method seems to run very sluggishly on IE6, is's especially noticable when doing a + * resize. It runs fine on every other browser. I've not noticed any obvious inefficiencies but IE6 is weird.. + * + * @param list jQuery object representing the html list (ul) we wish to populate. + * @param contents a function to populate the list contents, this function should take an index as a parameter. + * and return an <li> with the required contents or false to skip (useful if filtering is needed). + * @param maxlength the maximum number of items that we wish to populate (default is 1). + */ + this.renderList = function(list, contents, maxlength) { + // For IE 6 get the width. Have to use .main or .popup-container because list.innerWidth() may not be set yet. + var listWidth = 0; + + if (IE_VERSION < 7) { // This seems to be very slow on IE6, no idea why??? + var main = list.closest(".main"); + if (main.length == 0) { // It's a list in a popup + listWidth = Math.round(parseInt($(".popup-container").css('width'), 10) * 0.9); + } else { + listWidth = Math.round($(".main").width() * 0.9); + } + } + + var lengthChanged = false; + var items = list.children("li"); + + if (contents == null) { + maxlength = items.length; + } else if (maxlength == null) { + maxlength = 1; // If no maxlength is supplied default to calling the contents function once. + } + + var actualLength = 0; // Actual number of <li> supplied, this caters for the contents function returning false. + for (var i = 0; i < maxlength; i++) { + var li = false; + if (actualLength < items.length) { + if (contents) { // Modify list item with the new contents at index i. + var newItem = contents(i); + if (newItem) { // If the contents function didn't return false add contents to current li. + li = $(items[actualLength]); + actualLength++; + var active = li.hasClass("active") ? "active" : ""; + var newItem = $(newItem).addClass(active); + li.removeClass().addClass(newItem.attr("class")); // Remove existing classes and add new ones. + li.html(newItem.html()); + } + } else { // If contents function not present we simply reskin the current list item. + li = $(items[actualLength]); + actualLength++; + + if (IE_VERSION < 9) { + // Remove any markup used for faking :first-child, :last-child, :before, :after + li.removeClass("first-child last-child"); + li.children("div.before, div.after, div.fbefore, div.fafter").remove(); + } + } + } else { // If there are fewer items in the list than there are contents then append new list items. + var newItem = contents(i); + if (newItem) { // If the contents function didn't return false append contents as new li. + li = $(newItem); + actualLength++; + list.append(li); + lengthChanged = true; + } + } + + if (li) { + // Reskin input widgets. + Radio.reskin(li.children("input:radio")); + Checkbox.reskin(li.children("input:checkbox")); + + // Fix several quirks in early versions of IE. + if (IE_VERSION < 8) { + var anchor = li.children("a"); + anchor.attr("hideFocus", "hidefocus"); // Fix lack of outline: none; in IE < 8 + + if (IE_VERSION < 7) { // IE6 percentage widths are messed up so need to set absolute width. + // 41 comes from padding: 0 30px 0 11px; 22 comes from padding: 0 11px 0 11px; + // 34 comes from margin-left: 5px; text-indent: 40px; minus 11. + var anchorWidth = listWidth - ((li.hasClass("arrow") ? 41 : 22) + + (anchor.hasClass("icon") ? 34 : 11)); + anchor.css({"width": anchorWidth + "px"}); + + // IE6 can't cope with multiple CSS classes so we need to merge these into a single class. + if (li.is(".arrow.radio")) { + li.addClass("ie6-radio-arrow"); + if (li.hasClass("checked")) { + li.addClass("ie6-checked-arrow"); + } + } + } + } + } + } + + // If list is longer than the contents being added then trim the list so it's the same size. + if (actualLength < items.length) { + items.slice(actualLength).remove(); + lengthChanged = true; + } + + // Add radiused borders for IE8 and below. + // We have to do this after completely populating the list so first() and last() are correct. + if (IE_VERSION < 9) { + items = list.children("li"); + var last = items.last(); + last.addClass("last-child").prepend("<div class='before'></div>").append("<div class='after'></div>"); + + if (IE_VERSION < 8) { + var first = items.first(); + if (IE_VERSION == 7) { // For IE7 fake :first-child:before and :first-child:after + first.prepend("<div class='fbefore'></div>").append("<div class='fafter'></div>"); + } else if (IE_VERSION < 7) { // For IE6 fake :first-child + // We're not adding radiused borders to IE6, this class provides the proper top border colour. + first.addClass("first-child"); + } + } + } + + // If the length has changed trigger an iScroll refresh on the top level page that contains the list. + if (lengthChanged) { + list.closest(".main").trigger("refresh"); // refresh is a synthetic event handled by parents of scroll-area + } + }; + +//------------------------------------------------------------------------------------------------------------------- +// UI Widgets +//------------------------------------------------------------------------------------------------------------------- + + /** + * Create a Singleton instance of the Radio class used to reskin and manage HTML input type="radio" widgets. + */ + var Radio = new function() { + /** + * "Reskin" HTML input type="radio" items into a tablet "tick" style radio item. Note that the radio item + * needs to have a label sibling and be wrapped in a parent <li> for this to work correctly. + * e.g. <ul class="list"><li><label>test</label><input type="radio" name="test-radio" checked /></li></ul> + */ + this.reskin = function(radios) { + if (radios == null) { // if no input:radio is specified attempt to reskin every one in the document. + radios = $("input:radio"); + } + + // Add classes to container <li> based on "template" radio buttons. This "re-skins" the radio buttons. + radios.each(function() { // Iterate through each radio button. + var jthis = $(this).hide(); + if (!jthis.hasClass("reskinned")) { // If checkbox has already been reskinned move on. + var parent = jthis.parent(); + parent.addClass("radio"); + if (this.checked) { + parent.addClass("checked"); + } + jthis.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again. + } + }); + }; + + /** + * Handle radio button state changes. This method is delegated to by the main handlePointer end() method. + * Note that we are actually passing in the $("ul li.radio") jQuery object that the Event was bound to + * rather than the actual Event object as this has already been extracted by handlePointer and is more + * useful for the implementation of this method. + */ + this.handleClick = function(jthis, type) { + var checked = jthis.parent().children(".checked"); + var radio = jthis.children("input:radio"); // Select the template radio button. + + fade(jthis); // Fade out the highlighting of the selected <li> + + if (type != "click") { // If this handler wasn't triggered by a radio button click we synthesise one. + BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer. + radio.click(); // Trigger radio button's click (on modern browsers this triggers change too if changed). + BODY.click(handlePointer); + } + + // We explicitly manipulate input:radio checked attr in the following block in case a name attr wasn't + // specified in the HTML. With reskinned radio buttons the parent <ul> is the real container. + if (!jthis.is(checked)) { // If the clicked item is not the previously checked item. + // Clear any check mark on the previously selected <li> and the same on the template radio button. + checked.removeClass("checked"); + checked.children("input:radio").attr("checked", false); + + // Mark the current <li> as checked and do the same on the template radio button. + jthis.addClass("checked").change(); + jthis.children("input:radio").attr("checked", true); + + // For older IE/Opera triggering the click as done earlier won't trigger the change event so do it now. + if (IE_VERSION < 9 || OPERA_VERSION < 12) { + radio.change(); + } + } + }; + }; + + /** + * Create a Singleton instance of the Checkbox class used to reskin and manage HTML input type="checkbox" widgets. + */ + var Checkbox = new function() { + /** + * Return the input element associated with the specified label. This is used because the input element + * may be associated to the label in a number of different was (via the "for" attribute, by containment etc.) + */ + var findInputElement = function(label) { + var input = $("#" + label.attr("for")); // First check if label for points to the input. + if (input.length == 0) { // If not check if the label contains the input. + input = label.children("input"); + } + if (input.length == 0) { // Finally check if the label's next sibling is an input. + input = label.next("input"); + } + + return input; + }; + + /** + * "Reskin" HTML input type="checkbox" items into a tablet "switch" style checkbox. Note that the checkbox + * needs to have a label sibling and be wrapped in a parent <li> for this to work correctly. + * e.g. <ul class="list"><li><label>test</label><input type="checkbox" name="test-checkbox" checked /></li></ul> + * If multiple <input type="checkbox"> elements are placed in an <li> then they will automatically be + * reskinned as a "horiz-checkbox", this can also be done explicitly by doing <li class="horiz-checkbox"> + */ + this.reskin = function(checkboxes) { + if (checkboxes == null) { // if no input:checkbox is specified attempt to reskin every one in the document. + checkboxes = $("input:checkbox"); + } + + checkboxes.each(function() { // Iterate through each checkbox. + var jthis = $(this).hide(); + if (!jthis.hasClass("reskinned")) { // If checkbox has already been reskinned move on. + // If there are multiple checkboxes in a container create a horizontal checkbox by adding class + // to parent. Note that <li class="horiz-checkbox"> may also be explicitly set in the HTML. + jthis.siblings("input:checkbox").parent().addClass("horiz-checkbox"); + + // Mop up where checkbox is contained by label e.g. <label>test<input type="checkbox"/></label> + jthis.parent().siblings("label").parent().addClass("horiz-checkbox"); + + var li = jthis.closest("li"); // Find containing li. + + if (li.hasClass("horiz-checkbox")) { // Reskin horizontal checkbox. + // IE8 doesn't seem to distinguish between the selectors ul.list li:first-child:before and + // ul.list li.horiz-checkbox:first-child:before when horiz-checkbox is dynamically added + // this stops the <li> fake radiused border being correctly positioned for horiz-checkboxes. + // By adding horiz-checkbox class to the <ul> too we can use a more explicit rule in the CSS. + li.parent().addClass("horiz-checkbox"); + + // As we use inline-block for horiz-checkbox we need to remove any whitespace text nodes. + li.contents().filter(function() { + return (this.nodeType == 3 && $.trim($(this).text()).length == 0); + }).remove(); + + // For horiz-checkbox we set the width of each item and add a span containing the right border. + // The inner span is needed so the border doesn't impact the element width calculation. + li.each(function() { + var buttons = $(this).children("label"); + var width = 100/buttons.length; + + buttons.css("width", width + "%"); // Using the percentage works for browsers > IE7. + // The child span helps position the border - see css (ul.list li.horiz-checkbox label span) + buttons.filter(":not(:last)").append("<span></span>"); + buttons.first().addClass("first-child"); + buttons.last().addClass("last-child"); + + // Early IE doesn't respect the width so reduce the width of the last item a little. + if (width < 100 && (IE_VERSION < 8 )) { + buttons.last().css("width", width - 1 + "%") + } + + // Find input associated with each label and if it's checked add "checked" class to label. + buttons.each(function() { + var button = $(this); + var input = findInputElement(button); + input.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again. + if (input.attr("checked")) { + button.addClass("checked"); + if (button.is(buttons.last())) { + // Use toggle-on not checked to avoid confusing IE6. + button.parent().addClass("toggle-on"); + } + } + }); + }); + } else { // Reskin normal checkbox. + // Add markup to container <li> based on "template" checkboxes. This "re-skins" the checkboxes. + jthis.parent(). + append("<div class='checkbox'><div class='mask'></div><div class='onoff'></div></div>"); + + // If the checkbox is checked find onoff switch and change its initial position to "on". + jthis.filter(":checked").siblings(".checkbox").children(".onoff").css("left", "0px"); + jthis.addClass("reskinned"); // Mark as reskinned to avoid trying to reskin it again. + } + } + }); + }; + + /** + * Handle checkbox state changes. This method is delegated to by the main handlePointer method. + */ + this.handlePointer = function(e, type) { + // If triggered by a synthetic click the target is an input:checkbox otherwise it's a div.mask + var jthis = (type == "click") ? $(e.target).siblings("div.checkbox") : $(e.target).parent(); + var onoff = jthis.children(".onoff"); + var checkbox = jthis.parent().children("input:checkbox"); // Select the underlying <input type="checkbox"> + var offsetX = onoff.offset().left - jthis.offset().left; + var offset = -parseInt(onoff.css("left"), 10); // If we use translate we adjust by the left CSS position. + var startX = (e.pageX != null) ? e.pageX : e.originalEvent.targetTouches[0].pageX; + var clicked = true; // Set to false if move handler is called; + + var move = function(e) { + var newX = (e.pageX != null) ? e.pageX : e.originalEvent.changedTouches[0].pageX; + var diffX = offsetX + newX - startX; + clicked = false; + + if (diffX >= -50 && diffX <= 0) { + setPosition(onoff, offset, diffX); + } + e.stopPropagation(); // Prevent iScroll from trying to scroll when we drag the switch. + }; + + /** + * The pointer up handler is only bound when the pointer down has been triggered and so behaves like a click. + */ + var end = function(e) { + var pos = onoff.offset().left - jthis.offset().left; + var duration = 300; + + if (clicked) { + pos = (pos == 0) ? -50 : 0; + } else { + // Animation duration is between 150ms and 0ms based on position. + duration = (25 - Math.abs(pos + 25)) * 6; + pos = (pos < -25) ? -50 : 0; + + } + + setPosition(onoff, offset, pos, duration); + + BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer. + var currentlyChecked = checkbox[0].checked; + if ((currentlyChecked && pos == -50) || (!currentlyChecked && pos == 0)) { + if (type == "click") { + checkbox.attr("checked", !currentlyChecked); + } else { + checkbox.click(); + // For older IE/Opera triggering the click won't trigger the change event so do it now. + if (IE_VERSION < 9 || OPERA_VERSION < 12) { + checkbox.change(); + } + } + } + BODY.click(handlePointer); + + if (TOUCH_ENABLED) { + jthis.unbind(MOVE_EV + " " + END_EV); + } else { + BODY.unbind(MOVE_EV + " " + END_EV + " mouseleave"); + } + }; + + if (type == "click") { + end(e); + } else { + // Bind move, end and mouseleave events to our internal handlers. + if (TOUCH_ENABLED) { // Touch events track over the whole page by default. + jthis.bind(MOVE_EV, move).bind(END_EV, end); + } else { // Bind mouse events to body so we can track them over the whole page. + BODY.bind(MOVE_EV, move).bind(END_EV + " mouseleave", end); + } + } + }; + + /** + * Handle horiz-checkbox state changes. This method is delegated to by the main handlePointer end() method. + * Note that we are actually passing in the $("ul li.horiz-checkbox label") jQuery object that the Event was + * bound to rather than the actual Event object as this has already been extracted by handlePointer and is + * more useful for the implementation of this method. + */ + this.handleClick = function(jthis, type) { + var parent = jthis.parent(); + var lastChild = parent.children("label").last(); + + if (jthis.hasClass("checked")) { + jthis.removeClass("checked"); + if (jthis.is(lastChild)) { + parent.removeClass("toggle-on"); // Use toggle-on rather than checked to avoid confusing IE6. + } + } else { + jthis.addClass("checked"); + if (jthis.is(lastChild)) { + parent.addClass("toggle-on"); // Use toggle-on rather than checked to avoid confusing IE6. + } + } + + if (type == "click") { + var input = findInputElement(jthis); + input.attr("checked", !input.attr("checked")); + } else { // If this handler wasn't triggered by a checkbox click we synthesise one. + BODY.unbind("click", handlePointer); // Prevent the synthetic click from triggering handlePointer. + var checkbox = findInputElement(jthis); + checkbox.click(); + // For older IE/Opera triggering the click won't trigger the change event so do it now. + if (IE_VERSION < 9 || OPERA_VERSION < 9) { + checkbox.change(); + } + BODY.click(handlePointer); + } + } + }; + +//------------------------------------------------------------------------------------------------------------------- +// Main Event Handler +//------------------------------------------------------------------------------------------------------------------- + + /** + * This method handles the pointer down, move and up events. + * We handle the discrete events because mobile Safari adds a 300ms delay to the click handler, in addition + * we want to be able to un-highlight rows if we move the mouse/finger. Note that this handler is in the form + * of a delegating event handler - we actually bind the events to the html body, this is so that if we modify + * the DOM externally, e.g. via an AJAX update we will trigger from newly created elements too. + * Note that the start(), removeHighlight(), resetHighlight(), touchMove() and end() methods are private. + * This method does actually handle click events but its main job is to prevent the default navigation action + * on href, however if the click event is a synthetic click caused by a jQuery trigger the method behaves like + * a proper click handler. + */ + var handlePointer = function(e) { + // These are the *actual* selectors that we are interested in handling events for. + var selectors = "ul.contents li, ul.mail li, ul li.radio, ul li div.checkbox, ul li.horiz-checkbox label, " + + "ul li.arrow, ul li.pop, div.header a.back, div.header a.done, div.header a.cancel, " + + "div.header a.menu"; + + var target = e.target; + var jthis = $(target); + var parent; + var prev; + var href = jthis.attr("href"); + var chevronClicked = false; // Set true if we've clicked on a chevron (used for navigable radio buttons). + var scrolled; // Gets set if a page has been (touch) scrolled. + var highlighted; // Gets set if a sidebar or mail item has been selected/highlighted. + var startY; // The vertical position when a touchstart gets triggered. + + var start = function(e) { + // This block checks if the event target is one of the selectors, if not it uses jQuery closest to get the + // first element that matches the selector, start at the current element and progress up through the DOM. + if (!jthis.is(selectors)) { + jthis = jthis.closest(selectors); + } + + // If closest object doesn't match any of the selectors return true if it has an href else return false. + if (jthis.length == 0) { + return (!!href); // The href test allows the browser to add the active pseudoclass. + } + + if (jthis.hasClass("checkbox")) { // If a checkbox then delegate to the Checkbox handlePointer() handler. + Checkbox.handlePointer(e); + return false; + } + + parent = jthis.parent(); + + // prev is the previously highlighted item. We search from parent's parent as we may have multiple lists. + prev = parent.parent().find(".active"); + + href = jthis.attr("href"); // Get the href of the element matching the selector. + + var TOUCHED_SIDEBAR = TOUCH_ENABLED && parent.is(".contents, .mail"); // Is this a touch on a sidebar list? + + // If the href isn't directly present then it's an <li> that contains the anchor, so we have to look further. + if (!href) { + var ICON_WIDTH = 45; // The width of the icon image plus some padding. + var offset = Math.ceil(jthis.offset().left); + + // Get the pointer x value relative to the <li> + var x = (e.pageX != null) ? e.pageX - offset : // Mouse position. + (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos. + + // If target is a clickable-icon we return immediately thus preventing any highlighting or navigation. + if (jthis.hasClass("clickable-icon") && (x < ICON_WIDTH)) { + return false; + } + + // If target is a navigable radio button then check if chevron was clicked/tapped. + if (jthis.hasClass("radio") && jthis.hasClass("arrow") && ((jthis.outerWidth() - x) < ICON_WIDTH)) { + chevronClicked = true; + } + + e.preventDefault(); // Stop the anchor default highlighting, we'll add our own prettier highlight. + + // This block highlights the selected <li> on mousedown or touchstart. For touch enabled devices we wait + // for a short time before highlighting in case the touchstart was the start of a scroll rather than a + // selection. If it was a scroll then the scrolled flag will get set by the touchMove handler and the + // highlight is aborted when the timeout gets triggered. + if (!prev[0] || prev[0] != jthis[0]) { + if (TOUCHED_SIDEBAR && !IS_MOBILE) { + // If TOUCH_ENABLED and a sidebar or mail list wait 50ms before highlighting in case the + // touch start is really the start of a touch scroll event. + scrolled = false; + highlighted = false; + + setTimeout(function() { + if (!scrolled) { // scrolled may be set by touchMove if the list has been scrolled. + prev.removeClass("active"); + jthis.addClass("active"); // Highlight the current <li> + highlighted = true; + } + }, 50); + } else { // If not TOUCH_ENABLED or a sidebar or mail list highlight immediately. + prev.removeClass("active"); + // Navigable radio buttons don't highlight when the chevron is clicked. + if (!chevronClicked) { + jthis.addClass("active"); // Highlight the current <li> + } + } + } + + href = jthis.children("a:first").attr("href"); // Get the href from the first anchor enclosed by the <li> + href = (href == null) ? "#" : href; // Create default href of "#" if none has been specified. + href = href.replace(window.location, ""); // Fix "absolute href" bug found in IE7 and below. + } + + BODY.bind(END_EV, end).unbind(START_EV, handlePointer); + + if (parent.hasClass("list") || (TOUCHED_SIDEBAR && IS_MOBILE)) { + // For a small (e.g. mobile) displays the sidebar becomes the main menu page and touches behave + // like normal list touches and become inactive on any touch move. + BODY.bind(MOVE_EV, removeHighlight); + } else if (TOUCHED_SIDEBAR && !IS_MOBILE) { + // For a real sidebar detect touch scrolling on these items. + startY = (e.originalEvent) ? e.originalEvent.targetTouches[0].pageY : 0; + BODY.bind(MOVE_EV, touchMove); + } + }; + + /** + * If we move the mouse or finger in a list item we un-highlight and deactivate. + */ + var removeHighlight = function(e) { + BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer); + jthis.removeClass("active"); + }; + + /** + * If we move a finger up or down in a sidebar item we reinstate the previous highlight ontouchend. + */ + var resetHighlight = function(e) { + BODY.unbind(END_EV).bind(START_EV, handlePointer); + prev.addClass("active"); + }; + + /** + * This touch move handler is only bound if the initial event is a touch start event bound to a <li> + * with a <ul> parent that has a .contents or .mail class. These lists need to be touch scrollable, but + * they also need to have a persistent highlight on selected items. This method checks how many vertical + * pixels have been scrolled and if it exceeds a threshold it triggers a scrolled state. Once scrolled it removes + * any new highlighting and binds resetHighlight to touchend, which reinstates the previous highlight. + */ + var touchMove = function(e) { + var newY = e.originalEvent.changedTouches[0].pageY; + if (Math.abs(newY - startY) > 7) { // Only trigger on an up/down finger movement. + if (highlighted) { // If a new item was highlighted set the highlighting back to the previous item. + BODY.unbind(MOVE_EV + " " + END_EV).bind(END_EV, resetHighlight); + } else { + BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer); + } + + if (prev[0] != jthis[0]) { + jthis.removeClass("active"); + } + scrolled = true; + } + }; + + /** + * The pointer up handler is only bound when the pointer down has been triggered and so behaves like a click + * handler. If we have been triggered by a back selector or if we re-click an already selected sidebar entry + * that has previously transitioned the we call goBack() to transition backwards otherwise we goTo(href). + */ + var end = function(e) { + BODY.unbind(MOVE_EV + " " + END_EV).bind(START_EV, handlePointer); + + if (!IS_MOBILE && (parent.hasClass("contents") || parent.hasClass("mail"))) { + // Handle sidebar transitions. + if (_history.length == 2 && href == _history[1].href) { + goBack(); + } else { + _history = []; + goTo(href); + } + } else if (parent.is("ul")) { + if (jthis.hasClass("radio") && !chevronClicked) { // Delegate radio button state changes. + Radio.handleClick(jthis, e.type); + } else { // Handle goTo page transition. + var classes = jthis.attr("class").split(" "); + var transition = slide; // Default animation. + // Look up the transition animation based upon the item's class + for (var i in classes) { + var current = classes[i]; + var newTransition = _transitions[current]; + if (newTransition != null) { + transition = newTransition; + break; + } + } + goTo(href, transition); + } + } else if (parent.hasClass("horiz-checkbox")) { + Checkbox.handleClick(jthis); + } else if (jthis.is(".back, .done, .cancel")) { + goBack(); + } else if (jthis.hasClass("menu")) { + // For mobile devices the home button allows immediate navigation back to the main menu, which may + // be useful if several pages have been navigated through. + _history = [_history[0], {href:"#menu?", transition:null}]; + goBack(); + } + }; + + if (e.type == "click") { + e.preventDefault(); // Prevent the browser trying to navigate to the href itself onclick. + if (!e.originalEvent) { // If event is triggered by calling the jQuery click() method. + if (jthis.is("li, input:radio")) { + start(e); + end(e); + } else if (jthis.is("input:checkbox")) { + var li = jthis.closest("li.horiz-checkbox"); + + if (li.length == 0) { // For a normal checkbox add pageX to the event and delegate handlePointer() + e.pageX = 0; + Checkbox.handlePointer(e, e.type); + } else { + // It's a horiz-checkbox. We need to find the label associated with the checkbox. + var label = jthis.parent("label"); // First check if the label contains the checkbox. + if (label.length == 0) { // If not look for a label containing a for matching the checkbox ID. + label = $("label[for='" + jthis.attr("id")+"']"); + } + if (label.length == 0) { // If not assume the label is the preceding sibling (a bit fragile..). + var items = li.children(); + label = $(items[items.index(jthis) - 1]); + } + + Checkbox.handleClick(label, e.type); + } + } + } + } else { // Event type is mousedown or touchstart so call main event start handler. + start(e); + } + }; + + /** + * This method handles keyboard input. Its main purpose is to detect the return key being pressed and if it + * has this method will attempt to trigger the handler bound to the right button, which should be a done/submit. + */ + var handleKeyboard = function(e) { + if (e.which == 13) { // Handle return key; + // When the return key is pressed find any right button present in the header and trigger a click + // on it, this should have the effect of triggering the done/submit handler for the form. + var jthis = $(e.target); + var done = jthis.closest(".main, .popup").find(".header a.right.button"); + done.trigger(START_EV).trigger(END_EV); + } + }; + +//------------------------------------------------------------------------------------------------------------------- +// Page Navigation Methods +//------------------------------------------------------------------------------------------------------------------- + + /** + * This event handler handles the synthetic refresh event that may be triggered on a top level page containing + * a scroll-area. The handler uses the id of the page to index the iScroll object then calls its refresh(). + */ + var handleRefresh = function(e) { + var id = $(this).attr("id"); + if (_scrollers[id] != null) { + _scrollers[id].refresh(); + } + } + + /** + * This method transitions to a selected destination. If the destination is "#" it simply returns, if there + * is no history the destination page is shown otherwise we transition using an animation. + * The ".split("?")[0]" blocks are there to cater for the case where the destination URL contains data to + * be passed between page fragments, where the data is delimited by a "?" and separated by "&". + */ + var goTo = function(destination, transition) { + iTablet.location = new Location(destination); + var previous = (_history.length == 0) ? null : _history[0].href; + + if (destination == "#" || destination == previous) { // The second test guards against multiple clicks + return; + } else if (!IS_MOBILE && _history.length == 0) { + var pages = $(".main"); + $(pages).each(function(index) { + var jthis = $(this); + var id = jthis.attr("id"); + if (("#" + id) == destination.split("?")[0]) { + jthis.show().trigger("show").find(".active").removeClass("active"); + _scrollers[id].refresh(); // Refresh the touch scroller on the new page. + _history.unshift({href:destination, transition:null}); + } else { + jthis.hide().trigger("hide"); + } + }); + } else { + var currentPage = $(_history[0].href.split("?")[0]); + var newPage = $(destination.split("?")[0]); + transition(currentPage, newPage, false); + _scrollers[newPage.attr("id")].refresh(); // Refresh the touch scroller on the new page. + _history.unshift({href:destination, transition:transition}); + } + }; + + /** + * This method transitions back to the previous item in the history using an animation. + * The ".split("?")[0]" blocks are there to cater for the case where the fragment URLs contain data to + * be passed between page fragments, where the data is delimited by a "?" and separated by "&". + */ + var goBack = function() { + if (_history.length > 1) { + iTablet.location = new Location(_history[1].href); + var transition = _history[0].transition; + var currentPage = $(_history[0].href.split("?")[0]); + var newPage = $(_history[1].href.split("?")[0]); + transition(currentPage, newPage, true); + _scrollers[newPage.attr("id")].refresh(); // Refresh the touch scroller on the new page. + _history.shift(); + + // Hide virtual keyboard. + document.activeElement.blur(); + } + }; + +//------------------------------------------------------------------------------------------------------------------- +// Animations +//------------------------------------------------------------------------------------------------------------------- + + /** + * This method detects support for CSS3 animations and transitions and uses them if present. It will attempt + * to use translate3d if present as this is most likely to be GPU accelerated and uses translate as fallback. + * In an ideal world this would be set up in a stylesheet using media queries, but unfortunately using + * prefixes for all of the keyframes is rather verbose and untidy and media query of translate3d only seems + * to be supported in WebKit, so scripting is needed whatever. This method "injects" the relevant styles. + */ + var initialiseCSSAnimations = function() { + // TODO It'd be nicer to use feature detection but that can be hard to get right - how do we *reliably" + // detect support for animationend and transitionend events, which are essential for these animations??? + if ((/android/gi).test(navigator.appVersion) || OPERA_VERSION <= 12.01) { + // Android has poor CSS3 animation support so use jQuery. + // Opera <= 12.01 doesn't have animationend which messes up state management, what's worse is that it + // passes the animationSupported test, so just bomb out early Opera 12.01 at least fails that... + return; + } + + var domPrefixes = ["Webkit", "Moz", "O", "ms", "Khtml"]; + + // For the following lookups ensure that prefix key is forced to lower case!! + var transitionEndLookup = { // Lookup transitionend Event. Note prefixes are different to DOM prefixes + "" : "transitionend", + "webkit" : "webkitTransitionEnd", + "moz" : "transitionend", + "o" : "oTransitionEnd", + "ms" : "transitionend" + }; + + var animationEndLookup = { // Lookup transitionend Event. Note prefixes are different to DOM prefixes + "" : "animationend", + "webkit" : "webkitAnimationEnd", + "moz" : "animationend", + "o" : "oAnimationEnd", + "ms" : "transitionend" + }; + + var has3d = false; + var domPrefix = ""; + var prefix = ""; + + var style = $("<style/>"); + var styles = style[0].style; + + // We first check for animation-name and transform CSS support. + var animationSupported = styles.animationName && styles.transform ? true : false; + var animationend = "animationend"; + var transitionend = "transitionend"; + + if (!animationSupported) { // If prefix free versions not present check for prefixed versions. + var length = domPrefixes.length; + for (var i = 0; i < length; i++) { + if (styles[domPrefixes[i] + "AnimationName"] !== undefined) { + animationend = animationEndLookup[domPrefixes[i].toLowerCase()]; + transitionend = transitionEndLookup[domPrefixes[i].toLowerCase()]; + + var domPrefix = domPrefixes[i]; + prefix = "-" + domPrefix.toLowerCase() + "-"; + + if (styles[domPrefix + "Transform"] !== undefined) { + if (styles[domPrefix + "Perspective"] !== undefined) { + has3d = true; + } + animationSupported = true; + break; + } else { + return; + } + } + } + } + + ANIMATION_END_EV = animationend; + TRANSITION_END_EV = transitionend; + + if (animationSupported) { // Animating transforms is supported if this is true. + // Webkit's 3D transforms are passed off to the browser's own graphics renderer so may give a + // false positive, the test below should double check that 3d is indeed supported. + if (has3d && prefix == "-webkit-") { + has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(); + } + + var s = ".sidebar, .main, .popup, .popup-window, .popup-container, ul li {" + + prefix + "animation: 350ms ease-in-out;}"; + // Define the key animation styles. cssSlide simply adds these classes to trigger the animation. + s += ".slideIn {" + prefix + "animation-name: slideinfromright;}"; + s += ".slideOut {" + prefix + "animation-name: slideouttoleft;}"; + s += ".slideIn.reverse {" + prefix + "animation-name: slideinfromleft;}"; + s += ".slideOut.reverse {" + prefix + "animation-name: slideouttoright;}"; + s += ".fade {" + prefix + "animation-name: fadehighlight;}"; + s += ".slideUp {" + prefix + "animation-name: slideinfrombottom;}"; + s += ".slideDown {" + prefix + "animation-name: slideouttobottom;}"; + s += ".dissolveIn50 {" + prefix + "animation-name: dissolvein50;}"; + s += ".dissolveOut50 {" + prefix + "animation-name: dissolveout50;}"; + + // Helper method to render transform using translate3d if supported or translate if not. + var renderTranslate = function(val) { + return prefix + "transform: translate" + (has3d ? "3d(" : "(") + val + (has3d ? ", 0);" : ");"); + }; + + // Implement setting the left css attribute of the supplied element using css translate. + var cssSetPosition = function(element, offset, left, duration) { + // Invoked when the animation completes, resets styles. + var completeCallback = function() { + element.removeAttr("style").css("left", left + "px").unbind(TRANSITION_END_EV); + }; + + // If a duration is provided then use a transition to animate the transform. + if (duration != null) { + element.css(prefix + "transition", prefix + "transform " + duration + "ms ease-out 0ms"). + bind(TRANSITION_END_EV, completeCallback); + } + + element.css(prefix + "transform", + "translate" + (has3d ? "3d(" : "(") + (left + offset) + "px, 0" + (has3d ? ", 0)" : ")")); + }; + + var keyframes = prefix + "keyframes "; + + // Now define the keframes for the animations. + s += "@" + keyframes + "slideinfromright {"; + s += "from {" + renderTranslate("100%, 0") + "}"; + s += "to {" + renderTranslate("0, 0") + "}}"; + + s += "@" + keyframes + "slideouttoleft {"; + s += "from {" + renderTranslate("0, 0") + "}"; + s += "to {" + renderTranslate("-100%, 0") + "}}"; + + s += "@" + keyframes + "slideinfromleft {"; + s += "from {" + renderTranslate("-100%, 0") + "}"; + s += "to {" + renderTranslate("0, 0") + "}}"; + + s += "@" + keyframes + "slideouttoright {"; + s += "from {" + renderTranslate("0, 0") + "}"; + s += "to {" + renderTranslate("100%, 0") + "}}"; + + s += "@" + keyframes + "fadehighlight {"; + s += "from {background-color: #035de7; color: #ffffff;}"; + s += "to {background-color: #f7f7f7; color: #324F85;}}"; + + s += "@" + keyframes + "slideinfrombottom {"; + s += "from {" + renderTranslate("0, 100%") + "}"; + s += "to {" + renderTranslate("0, 0") + "}}"; + + s += "@" + keyframes + "slideouttobottom {"; + s += "from {" + renderTranslate("0, 0") + "}"; + s += "to {" + renderTranslate("0, 120%") + "}}"; + + s += "@" + keyframes + "dissolvein50 {"; + s += "from {background-color: rgba(0, 0, 0, 0.0);}"; + s += "to {background-color: rgba(0, 0, 0, 0.49);}}"; // Setting to 0.49 not 0.5 prevents Firefox glitch. + + s += "@" + keyframes + "dissolveout50 {"; + s += "from {background-color: rgba(0, 0, 0, 0.5);}"; + s += "to {background-color: rgba(0, 0, 0, 0.0);}}"; + + style.append(s); + $("head").append(style); // "inject" animation styles into DOM. + slide = cssSlide; // Override slide method with the cssSlide version. + fade = cssFade; // Override fade method with the cssFade version. + popup = cssPopup; // Override fade method with the cssFade version. + setPosition = cssSetPosition; + } + }; + + /** + * Implement a simple colour fade animation using a look up table to fade active colour back to background. + * This is the default fade implementation, which may be overridden if CSS3 animations are supported. + */ + var fade = function(selected) { + var table = [{"background-color": "#0360e8", "color": "#ffffff"}, + {"background-color": "#337feb", "color": "#ffffff"}, + {"background-color": "#669eef", "color": "#ffffff"}, + {"background-color": "#99b8f0", "color": "#324F85"}, + {"background-color": "#c0d7f3", "color": "#324F85"}, + {"background-color": "#f6f6f6", "color": "#324F85"}]; + + var stepCallback = function(i) { + if (i < 6) { + selected.css(table[i]); // Set style from look up table. + setTimeout(function() {stepCallback(i + 1);}, 50); // 7 steps at 50ms per step = 350ms + } else { + selected.removeAttr("style"); // When the animation ends remove the styles we've just added. + } + }; + + if (selected.is(":visible")) { // Only apply animation is element is visible. + selected.removeClass("active"); + stepCallback(0); + } else { + selected.removeClass("active"); + } + }; + + /** + * Implement a colour fade using a CSS3 animation to fade active colour back to background. + */ + var cssFade = function(selected) { + // Invoked when the animation completes, resets styles. + var completeCallback = function() { + selected.removeClass("fade").unbind(ANIMATION_END_EV); + }; + + if (selected.is(":visible")) { // Only apply animation is element is visible. + selected.removeClass("active").addClass("fade").bind(ANIMATION_END_EV, completeCallback); + } else { + selected.removeClass("active"); + } + }; + + /** + * Implement a horizontal slide from the currentPage to the newPage using jQuery animate() of the left and right + * css properies. If isReverse is true the slide is left to right otherwise the slide is right to left. + * This is the default slide implementation, which may be overridden if CSS3 animations are supported. + */ + var slide = function(currentPage, newPage, isReverse) { + var width = isReverse ? -currentPage.outerWidth() : currentPage.outerWidth(); + var left = newPage.hasClass("popup") ? 0 : _mainLeft; + + // Invoked when the animation completes, resets style and hides the old page and rebinds the START_EV. + var completeCallback = function() { + currentPage.hide(); // Hide the current page after animation completes. + currentPage.css({"left": left + "px", "right": "0"}); // Reset css back to original settings. + BODY.bind(START_EV, handlePointer); // Re-enable START_EV when transition completes. + }; + + BODY.unbind(START_EV, handlePointer); // Disable START_EV until transition completes. + currentPage.trigger("hide"); // Trigger the hide handler *before* the animation. + newPage.css({"left": left + width + "px", "right": -width + "px"}).show().trigger("show"). + animate({left: left, right: 0}, 350); + var selected = newPage.find(".active").removeClass("active"); + if (isReverse) { + fade(selected); + } + currentPage.animate({left: left - width, right: width}, 350, completeCallback); + }; + + /** + * Implement a horizontal slide from the currentPage to the newPage using a CSS3 animation. + * This should give a much smoother animation than the jQuery one and is GPU accelerated on some devices. + * If isReverse is true the slide is left to right otherwise the slide is right to left. + */ + var cssSlide = function(currentPage, newPage, isReverse) { + var width = isReverse ? -currentPage.outerWidth() : currentPage.outerWidth(); + var classes = "slideIn slideOut reverse"; + + // Invoked when the animation completes, resets styles and hides the old page and rebinds the START_EV. + var completeCallback = function() { + newPage.removeClass(classes); + currentPage.hide().removeClass(classes).unbind(ANIMATION_END_EV, completeCallback); + BODY.bind(START_EV, handlePointer); // Re-enable START_EV when transition completes. + }; + + BODY.unbind(START_EV, handlePointer); // Disable START_EV until transition completes. + + var reverse = isReverse ? " reverse" : ""; + currentPage.trigger("hide"); // Trigger the hide handler *before* the animation. + newPage.show().trigger("show").addClass("slideIn" + reverse); + var selected = newPage.find(".active").removeClass("active"); + if (isReverse) { + fade(selected); + } + currentPage.bind(ANIMATION_END_EV, completeCallback).addClass("slideOut" + reverse); + }; + + /** + * Implement a pop up to the newPage using jQuery animate() of the top, bottom and rgba css properies. + * If isReverse is true the popup slides down otherwise it slides up. + * This is the default popup implementation, which may be overridden if CSS3 animations are supported. + */ + var popup = function(currentPage, newPage, isReverse) { + fade(currentPage.find(".active")); + var height = currentPage.outerWidth(); + var background = $(".popup-window"); + var container = $(".popup-container"); + + var setOpacity = function(i) { // Animate opacity value. + if (!IS_IE || IE_VERSION > 8) { // CSS rgba is supported by modern browsers. + background.css({"background-color": "rgba(0, 0, 0, 0." + i + ")"}); + } else { // IE8 and below don't support rgba so use MS DXImageTransform filter. + // This is a bit subtle, unfortunately progid:DXImageTransform messes with the fonts so we only use + // it to animate the opacity, for the final black with 50% alpha effect we add the "smoked" style + // which uses a png image background, the combination gives fairly smooth animation and normal font. + var hexAlpha = (Math.round(25.6 * i)).toString(16); // Convert index to a hex alpha value. + hexAlpha = (hexAlpha.length < 2) ? "0" + hexAlpha : hexAlpha; // Pad to two hex digits if necessary. + hexAlpha = "#" + hexAlpha + "000000"; // Modify the alpha of a black background. + background.css({"filter": "progid:DXImageTransform.Microsoft.gradient(startColorstr=" + + hexAlpha + ",endColorstr=" + hexAlpha + ")"}); + } + }; + + var removeStyles = function(i) { + if (IE_VERSION <= 6) { // For IE6 we've added other dynamic styles, so we need to preserve those. + } else { // For every other browser we remove all dynamic styling. + background.removeAttr("style"); + } + }; + + var fadeInBackground = function(i) { // Animate rgba opacity property from 0.0 to 0.5. + if (i < 6) { + setOpacity(i); + setTimeout(function() {fadeInBackground(i + 1);}, 50); + } else { + removeStyles(); // When the animation ends remove the styles we've just added. + background.addClass("smoked"); // Only does anything for IE < 9 + } + }; + + var fadeOutBackground = function(i) { // Animate rgba opacity property from 0.5 to 0.0. + if (i >= 0) { + setOpacity(i); + setTimeout(function() {fadeOutBackground(i - 1);}, 50); + } else { + removeStyles(); // When the animation ends remove the styles we've just added. + background.hide(); + newPage.trigger("show"); + } + }; + + currentPage.trigger("hide"); // Trigger the hide handler *before* the animation. + if (isReverse) { + // Wrapping in a timeout prevents IE8 glitching button styles when returning from :active state. + setTimeout(function() { + background.removeClass("smoked"); + fadeOutBackground(5); + }, 10); + + container.css({"top": "64px", "bottom": "64px"}). + animate({top: height + "px", bottom: 128 - height + "px"}, 350); + } else { + $(".popup").hide(); + newPage.show().trigger("show"); + background.show(); + fadeInBackground(0); + container.css({"top": height + "px", "bottom": 128 - height + "px"}). + animate({top: "64px", bottom: "64px"}, 350); + } + }; + + /** + * Implement a pop up to the newPage using a CSS3 animation. + * This should give a much smoother animation than the jQuery one and is GPU accelerated on some devices. + * If isReverse is true the popup slides down otherwise it slides up. + */ + var cssPopup = function(currentPage, newPage, isReverse) { + fade(currentPage.find(".active")); + var background = $(".popup-window"); + var container = $(".popup-container"); + background.removeClass("dissolveIn50 dissolveOut50"); + container.removeClass("slideUp slideDown"); + + // Invoked when the animation completes, hides the background. + var completeCallback = function() { + background.hide(); + container.unbind(ANIMATION_END_EV, completeCallback); + newPage.trigger("show"); + }; + + currentPage.trigger("hide"); // Trigger the hide handler *before* the animation. + if (isReverse) { + background.addClass("dissolveOut50"); + container.bind(ANIMATION_END_EV, completeCallback).addClass("slideDown"); + } else { + $(".popup").hide(); + newPage.show().trigger("show"); + background.show().addClass("dissolveIn50"); + container.addClass("slideUp"); + } + }; + + /** + * Implement setting the left css attribute of the supplied element using standard jQuery css call. + */ + var setPosition = function(element, offset, left, duration) { + if (duration != null) { + element.animate({left: left}, duration); + } else { + element.css("left", left + "px"); + } + }; + +//------------------------------------------------------------------------------------------------------------------- +// Add HTML5 placeholder support to browsers that don't have native support. +//------------------------------------------------------------------------------------------------------------------- + + var addPlaceholderSupport = function(inputs) { + inputs.each(function() { + var jthis = $(this); + // Add textarea class to allow textarea placeholder to be styled differently to input placeholder. + var classes = jthis.is("textarea") ? "placeholder textarea" : "placeholder"; + + jthis.focus(function() { + jthis.siblings("span").hide(); + }).blur(function() { + if (jthis.val() == "") { + jthis.siblings("span").show(); + } + }).parent().append("<span class='" + classes + "'>" + jthis.attr("placeholder") + "</span>"); + }); + }; + +//------------------------------------------------------------------------------------------------------------------- +// Some IE specific code to manipulate additional styles to help "pretty up" earlier versions of IE. +//------------------------------------------------------------------------------------------------------------------- + + /** + * For IE6 adjust the size as it doesn't seem to be computed correctly in pure CSS. + * To be really nice we should probably compute SCROLLBAR, HEADER, PADDING but hey, it's only for IE6 :-) + */ + var adjustSize = function() { + var SCROLLBAR = 20; + var HEADER = 44; + var PADDING = 128; + var width = BODY.outerWidth() + SCROLLBAR; + var height = $(window).outerHeight(); + var mainWidth = width - _mainLeft; + $(".main").css({"width": mainWidth + "px"}); + $(".main, .sidebar").css({"height": (height - HEADER) + "px"}); + $(".popup-window").css({"width": width + "px", "height": height + "px"}); + $(".popup-container").css({"width": (width - width * 0.4) + "px", + "height": (height - (PADDING + HEADER)) + "px"}); + // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers). + $("ul.list").each(function() {iTablet.renderList($(this));}); + }; + + /** + * Among its long list of failings IE6 doesn't properly support multiple classes. The active class is used in + * several places, so this method overrides jQuery's addClass and removeClass in order to create IE6 specific + * classes when the active or checked class is added or removed. It's a messy, but fairly effective approach. + */ + var mergeClasses = function() { + // Merge blue and back classes - this only works if blue is added statically which is how it's expected to be. + $("a.blue.back.button").addClass("blue-back"); + + var addClass = jQuery.fn.addClass; // Retrieve original jQuery addClass. + jQuery.fn.addClass = function() { // Override jQuery addClass. + var jthis = $(this); + // Execute the original method and save result. + var result = addClass.apply(this, arguments); + + var length = arguments.length; + for (var i = 0; i < length; i++) { + if (arguments[i] == "checked") { + if (jthis.hasClass("arrow")) { + jthis.addClass("ie6-checked-arrow"); + } + } + + if (arguments[i] == "active") { + if (jthis.hasClass("arrow")) { + jthis.addClass("ie6-arrow-active"); + } + + if (jthis.hasClass("checked")) { + jthis.addClass("ie6-checked-active"); + } + + if (jthis.hasClass("radio") && jthis.hasClass("arrow")) { + jthis.addClass("ie6-radio-arrow-active"); + } + + if (jthis.hasClass("checked") && jthis.hasClass("arrow")) { + jthis.addClass("ie6-checked-arrow-active"); + } + } + } + + return result; + }; + + var removeClass = jQuery.fn.removeClass; // Retrieve original jQuery removeClass. + jQuery.fn.removeClass = function() { // Override jQuery removeClass. + var jthis = $(this); + // Execute the original method and save result. + var result = removeClass.apply(this, arguments); + + var length = arguments.length; + for (var i = 0; i < length; i++) { + if (arguments[i] == "checked") { + jthis.removeClass("ie6-checked-arrow"); + } + + if (arguments[i] == "active") { + jthis.removeClass("ie6-arrow-active ie6-checked-active ie6-radio-arrow-active ie6-checked-arrow-active"); + } + } + + return result; + }; + }; + + /** + * Sort out quirks for various versions of IE less than 9 - IE9 is fortunately *fairly* well behaved. + */ + var fixIEQuirks = function() { + if (IE_VERSION < 8) { // For IE7 and below. + $("textarea").parent().addClass("textarea"); // Add textarea class to parent <li> - used by IE7 CSS styles. + + // Wrapping the sidebar in another div with zoom: 1 to enable "layout mode" fixes an + // annoying page transition slide animation quirk with IE < 8. + BODY.prepend($("<div id='sidebar-wrapper'></div>")); + $("#sidebar-wrapper").append($("#menu")); + + // Sort out button styling and issue with :active not being switched off. + $("a.button").attr('hideFocus', 'hidefocus'). + append("<div class='before'></div><div class='after'></div>"). + bind("click mouseleave", function() {this.blur();}); + $("ul.contents li a").attr('hideFocus', 'hidefocus'); // Fix lack of outline: none; in IE < 8 + } + + if (IE_VERSION < 7) { // IE6 is a real drag...... + adjustSize(); // Set css width and height as it doesn't seem to be computed correctly in pure CSS. + mergeClasses(); // IE < 7 doesn't support multiple classes so merge them into IE specific class. + $(window).resize(adjustSize); + } else { // For IE7 and above just render list. + // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers). + $("ul.list").each(function() {iTablet.renderList($(this));}); + } + } + +//------------------------------------------------------------------------------------------------------------------- +// Initialise when DOM loads using (shorthand) jQuery.ready() +//------------------------------------------------------------------------------------------------------------------- + + $(function() { + /* + * These handlers help make the UI behave more like a User Interface than a web page. The selectstart handler + * disables selection on everything other than input/textarea etc. the dragstart handler disables IE image + * dragging, the touchmove handler disables mobile Safari web page "bounce" and the contextmenu handler + * disables the right click context menu. In a web page disabling this stuff might be frowned on, but in + * a web app it makes the application look and feel much more like a native app, which is rather the point. + */ + $(document).bind("selectstart contextmenu", function(e) { + return $(e.target).is('input, textarea, select, option');}); + $(document).bind("dragstart touchmove submit", function (e) {e.preventDefault();}); + $(document).bind("orientationchange", function (e) {scrollTo(0, 0);}); // Make sure position is OK + $(document).keyup(handleKeyboard); + + // jQuery object for body is used in several places so let's cache it. + BODY = $("body"); + + _mainLeft = parseInt($(".main").css("left"), 10); + + //IS_MOBILE = BODY.hasClass("mobile"); // We use the class "mobile" for mobile devices. + IS_MOBILE = (_mainLeft == 0); // For mobile devices there is no sidebar. + if (IS_MOBILE) { + _history = [{href:"#menu?", transition:null}]; + } + + // Prevent the browser trying to navigate to the href itself onclick then bind pointer Events to handlePointer. + BODY.bind(START_EV + " click", handlePointer); + + // Ensure various form fields behave correctly with iScroll. + $("input, textarea, select").bind(START_EV, function(e) {e.stopPropagation();}); + + // Detect input and textarea placeholders separately as some browsers (Opera 11) have native support for + // input placeholders but not textarea placeholders. + if (!("placeholder" in $("<input>")[0])) { // Add HTML5 input placeholder support if not natively present. + addPlaceholderSupport($("input[placeholder]")); + } + + if (!("placeholder" in $("<textarea>")[0])) { // Add HTML5 textarea placeholder support if not natively present. + addPlaceholderSupport($("textarea[placeholder]")); + } + + $.event.special.textchange = new TextChange(); // Add support for textchange Events on text input and textarea. + + // This block looks for scroll-areas and constructs an iScroll touch scroller. Note that scrollers are indexed + // by the containing "main" page not by the id of the scroll-area. The latter id is only used by iScroll itself. + $(".scroll-area").each(function(index) { + var parent = $(this).parent(); + parent.bind("refresh", handleRefresh); // Bind the synthetic refresh event to the refresh handler + var parentId = parent.attr("id"); + + if (TOUCH_ENABLED) { + _scrollers[parentId] = new iScroll(this); + } else { // Adds a dummy scroller object if not a touch device. + _scrollers[parentId] = {refresh: function() {}}; + } + }); + + initialiseCSSAnimations(); + _transitions = {"pop": popup}; + + iTablet.location = new Location("#" + $(".main").attr("id")); + + if (IS_IE) { + fixIEQuirks(); + } else { + // Render each list (this reskins checkboxes & radio buttons and adds the border radius on old browsers). + $("ul.list").each(function() {iTablet.renderList($(this));}); + } + + /* + * iOS6 safari has a number of "quirks" that seem to be related to overly aggressive caching, one of these + * these relates to attempting to reuse browser connections before the HTTP response has returned. In theory + * this may be a good thing as it allows better "pipelining" on persistent connections, but in practice + * if the "long polling" pattern is being used it can really mess things up for image "rollovers" when + * dynamic state gets changed. This usually manifests itself by the active images taking an age to appear. + * The following line works around this issue by initially adding the active state to the relevant items + * this forces the active images to be loaded, which are then subsequently cached. + */ + $("div.main ul.list li").addClass("active"); + + $(".main, .popup-window").hide(); + }); +}; + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/jquery.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/jquery.js new file mode 100644 index 0000000000..198b3ff07d --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/itablet/scripts/jquery.js @@ -0,0 +1,4 @@ +/*! jQuery v1.7.1 jquery.com | jquery.org/license */ +(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function cb(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function ca(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bE.test(a)?d(a,e):ca(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)ca(a+"["+e+"]",b[e],c,d);else d(a,b)}function b_(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function b$(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bT,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=b$(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=b$(a,c,d,e,"*",g));return l}function bZ(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bP),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function bC(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bx:by,g=0,h=e.length;if(d>0){if(c!=="border")for(;g<h;g++)c||(d-=parseFloat(f.css(a,"padding"+e[g]))||0),c==="margin"?d+=parseFloat(f.css(a,c+e[g]))||0:d-=parseFloat(f.css(a,"border"+e[g]+"Width"))||0;return d+"px"}d=bz(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0;if(c)for(;g<h;g++)d+=parseFloat(f.css(a,"padding"+e[g]))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+e[g]+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+e[g]))||0);return d+"px"}function bp(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bf,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bo(a){var b=c.createElement("div");bh.appendChild(b),b.innerHTML=a.outerHTML;return b.firstChild}function bn(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bm(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bm)}function bm(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bl(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bk(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bj(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d<e;d++)f.event.add(b,c+(i[c][d].namespace?".":"")+i[c][d].namespace,i[c][d],i[c][d].data)}h.data&&(h.data=f.extend({},h.data))}}function bi(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function U(a){var b=V.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function T(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(O.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c<d;c++)b[a[c]]=!0;return b}var c=a.document,d=a.navigator,e=a.location,f=function(){function J(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(J,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:G?function(a){return a==null?"":G.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?E.call(c,a):e.merge(c,a)}return c},inArray:function(a,b,c){var d;if(b){if(H)return H.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=F.call(arguments,2),g=function(){return a.apply(c,f.concat(F.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){I["[object "+b+"]"]=b.toLowerCase()}),z=e.uaMatch(y),z.browser&&(e.browser[z.browser]=!0,e.browser.version=z.version),e.browser.webkit&&(e.browser.safari=!0),j.test("Â ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?B=function(){c.removeEventListener("DOMContentLoaded",B,!1),e.ready()}:c.attachEvent&&(B=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",B),e.ready())});return e}(),g={};f.Callbacks=function(a){a=a?g[a]||h(a):{};var c=[],d=[],e,i,j,k,l,m=function(b){var d,e,g,h,i;for(d=0,e=b.length;d<e;d++)g=b[d],h=f.type(g),h==="array"?m(g):h==="function"&&(!a.unique||!o.has(g))&&c.push(g)},n=function(b,f){f=f||[],e=!a.memory||[b,f],i=!0,l=j||0,j=0,k=c.length;for(;c&&l<k;l++)if(c[l].apply(b,f)===!1&&a.stopOnFalse){e=!0;break}i=!1,c&&(a.once?e===!0?o.disable():c=[]:d&&d.length&&(e=d.shift(),o.fireWith(e[0],e[1])))},o={add:function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},remove:function(){if(c){var b=arguments,d=0,e=b.length;for(;d<e;d++)for(var f=0;f<c.length;f++)if(b[d]===c[f]){i&&f<=k&&(k--,f<=l&&l--),c.splice(f--,1);if(a.unique)break}}return this},has:function(a){if(c){var b=0,d=c.length;for(;b<d;b++)if(a===c[b])return!0}return!1},empty:function(){c=[];return this},disable:function(){c=d=e=b;return this},disabled:function(){return!c},lock:function(){d=b,(!e||e===!0)&&o.disable();return this},locked:function(){return!d},fireWith:function(b,c){d&&(i?a.once||d.push([b,c]):(!a.once||!e)&&n(b,c));return this},fire:function(){o.fireWith(this,arguments);return this},fired:function(){return!!e}};return o};var i=[].slice;f.extend({Deferred:function(a){var b=f.Callbacks("once memory"),c=f.Callbacks("once memory"),d=f.Callbacks("memory"),e="pending",g={resolve:b,reject:c,notify:d},h={done:b.add,fail:c.add,progress:d.add,state:function(){return e},isResolved:b.fired,isRejected:c.fired,then:function(a,b,c){i.done(a).fail(b).progress(c);return this},always:function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this},pipe:function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()},promise:function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}},i=h.promise({}),j;for(j in g)i[j]=g[j].fire,i[j+"With"]=g[j].fireWith;i.done(function(){e="resolved"},c.disable,d.lock).fail(function(){e="rejected"},b.disable,d.lock),a&&a.call(i,i);return i},when:function(a){function m(a){return function(b){e[a]=arguments.length>1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c<d;c++)b[c]&&b[c].promise&&f.isFunction(b[c].promise)?b[c].promise().then(l(c),j.reject,m(c)):--g;g||j.resolveWith(j,b)}else j!==a&&j.resolveWith(j,d?[a]:[]);return k}}),f.support=function(){var b,d,e,g,h,i,j,k,l,m,n,o,p,q=c.createElement("div"),r=c.documentElement;q.setAttribute("className","t"),q.innerHTML=" <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="<div "+n+"><div></div></div>"+"<table "+n+" cellpadding='0' cellspacing='0'>"+"<tr><td></td></tr></table>",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="<div style='width:4px;'></div>",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e<g;e++)delete d[b[e]];if(!(c?m:f.isEmptyObject)(d))return}}if(!c){delete j[k].data;if(!m(j[k]))return}f.support.deleteExpando||!j.setInterval?delete j[k]:j[k]=null,i&&(f.support.deleteExpando?delete a[h]:a.removeAttribute?a.removeAttribute(h):a[h]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d,e,g,h=null;if(typeof a=="undefined"){if(this.length){h=f.data(this[0]);if(this[0].nodeType===1&&!f._data(this[0],"parsedAttrs")){e=this[0].attributes;for(var i=0,j=e.length;i<j;i++)g=e[i].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),l(this[0],g,h[g]));f._data(this[0],"parsedAttrs",!0)}}return h}if(typeof a=="object")return this.each(function(){f.data(this,a)});d=a.split("."),d[1]=d[1]?"."+d[1]:"";if(c===b){h=this.triggerHandler("getData"+d[1]+"!",[d[0]]),h===b&&this.length&&(h=f.data(this[0],a),h=l(this[0],a,h));return h===b&&d[1]?this.data(d[0]):h}return this.each(function(){var b=f(this),e=[d[0],c];b.triggerHandler("setData"+d[1]+"!",e),f.data(this,a,c),b.triggerHandler("changeData"+d[1]+"!",e)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f.Callbacks("once memory"),!0))h++,l.add(m);m();return d.promise()}});var o=/[\n\t\r]/g,p=/\s+/,q=/\r/g,r=/^(?:button|input)$/i,s=/^(?:button|input|object|select|textarea)$/i,t=/^a(?:rea)?$/i,u=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,v=f.support.getSetAttribute,w,x,y;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(p);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(o," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(p);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(o," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c<d;c++){e=i[c];if(e.selected&&(f.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!f.nodeName(e.parentNode,"optgroup"))){b=f(e).val();if(j)return b;h.push(b)}}if(j&&!h.length&&i.length)return f(i[g]).val();return h},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h<g;h++)e=d[h],e&&(c=f.propFix[e]||e,f.attr(a,e,""),a.removeAttribute(v?e:c),u.test(e)&&c in a&&(a[c]=!1))}},attrHooks:{type:{set:function(a,b){if(r.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(w&&f.nodeName(a,"button"))return w.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(w&&f.nodeName(a,"button"))return w.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e,g,h,i=a.nodeType;if(!!a&&i!==3&&i!==8&&i!==2){h=i!==1||!f.isXMLDoc(a),h&&(c=f.propFix[c]||c,g=f.propHooks[c]);return d!==b?g&&"set"in g&&(e=g.set(a,d,c))!==b?e:a[c]=d:g&&"get"in g&&(e=g.get(a,c))!==null?e:a[c]}},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):s.test(a.nodeName)||t.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabindex=f.propHooks.tabIndex,x={get:function(a,c){var d,e=f.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},v||(y={name:!0,id:!0},w=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&(y[c]?d.nodeValue!=="":d.specified)?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.attrHooks.tabindex.set=w.set,f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})}),f.attrHooks.contenteditable={get:w.get,set:function(a,b,c){b===""&&(b="false"),w.set(a,b,c)}}),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.enctype||(f.propFix.enctype="encoding"),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")}; +f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k<c.length;k++){l=A.exec(c[k])||[],m=l[1],n=(l[2]||"").split(".").sort(),s=f.event.special[m]||{},m=(g?s.delegateType:s.bindType)||m,s=f.event.special[m]||{},o=f.extend({type:m,origType:l[1],data:e,handler:d,guid:d.guid,selector:g,quick:G(g),namespace:n.join(".")},p),r=j[m];if(!r){r=j[m]=[],r.delegateCount=0;if(!s.setup||s.setup.call(a,e,n,i)===!1)a.addEventListener?a.addEventListener(m,i,!1):a.attachEvent&&a.attachEvent("on"+m,i)}s.add&&(s.add.call(a,o),o.handler.guid||(o.handler.guid=d.guid)),g?r.splice(r.delegateCount++,0,o):r.push(o),f.event.global[m]=!0}a=null}},global:{},remove:function(a,b,c,d,e){var g=f.hasData(a)&&f._data(a),h,i,j,k,l,m,n,o,p,q,r,s;if(!!g&&!!(o=g.events)){b=f.trim(I(b||"")).split(" ");for(h=0;h<b.length;h++){i=A.exec(b[h])||[],j=k=i[1],l=i[2];if(!j){for(j in o)f.event.remove(a,j+b[h],c,d,!0);continue}p=f.event.special[j]||{},j=(d?p.delegateType:p.bindType)||j,r=o[j]||[],m=r.length,l=l?new RegExp("(^|\\.)"+l.split(".").sort().join("\\.(?:.*\\.)?")+"(\\.|$)"):null;for(n=0;n<r.length;n++)s=r[n],(e||k===s.origType)&&(!c||c.guid===s.guid)&&(!l||l.test(s.namespace))&&(!d||d===s.selector||d==="**"&&s.selector)&&(r.splice(n--,1),s.selector&&r.delegateCount--,p.remove&&p.remove.call(a,s));r.length===0&&m!==r.length&&((!p.teardown||p.teardown.call(a,l)===!1)&&f.removeEvent(a,j,g.handle),delete o[j])}f.isEmptyObject(o)&&(q=g.handle,q&&(q.elem=null),f.removeData(a,["events","handle"],!0))}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){if(!e||e.nodeType!==3&&e.nodeType!==8){var h=c.type||c,i=[],j,k,l,m,n,o,p,q,r,s;if(E.test(h+f.event.triggered))return;h.indexOf("!")>=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l<r.length&&!c.isPropagationStopped();l++)m=r[l][0],c.type=r[l][1],q=(f._data(m,"events")||{})[c.type]&&f._data(m,"handle"),q&&q.apply(m,d),q=o&&m[o],q&&f.acceptData(m)&&q.apply(m,d)===!1&&c.preventDefault();c.type=h,!g&&!c.isDefaultPrevented()&&(!p._default||p._default.apply(e.ownerDocument,d)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)&&o&&e[h]&&(h!=="focus"&&h!=="blur"||c.target.offsetWidth!==0)&&!f.isWindow(e)&&(n=e[o],n&&(e[o]=null),f.event.triggered=h,e[h](),f.event.triggered=b,n&&(e[o]=n));return c.result}},dispatch:function(c){c=f.event.fix(c||a.event);var d=(f._data(this,"events")||{})[c.type]||[],e=d.delegateCount,g=[].slice.call(arguments,0),h=!c.exclusive&&!c.namespace,i=[],j,k,l,m,n,o,p,q,r,s,t;g[0]=c,c.delegateTarget=this;if(e&&!c.target.disabled&&(!c.button||c.type!=="click")){m=f(this),m.context=this.ownerDocument||this;for(l=c.target;l!=this;l=l.parentNode||this){o={},q=[],m[0]=l;for(j=0;j<e;j++)r=d[j],s=r.selector,o[s]===b&&(o[s]=r.quick?H(l,r.quick):m.is(s)),o[s]&&q.push(r);q.length&&i.push({elem:l,matches:q})}}d.length>e&&i.push({elem:this,matches:d.slice(e)});for(j=0;j<i.length&&!c.isPropagationStopped();j++){p=i[j],c.currentTarget=p.elem;for(k=0;k<p.matches.length&&!c.isImmediatePropagationStopped();k++){r=p.matches[k];if(h||!c.namespace&&!r.namespace||c.namespace_re&&c.namespace_re.test(r.namespace))c.data=r.data,c.handleObj=r,n=((f.event.special[r.origType]||{}).handle||r.handler).apply(p.elem,g),n!==b&&(c.result=n,n===!1&&(c.preventDefault(),c.stopPropagation()))}}return c.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode);return a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,d){var e,f,g,h=d.button,i=d.fromElement;a.pageX==null&&d.clientX!=null&&(e=a.target.ownerDocument||c,f=e.documentElement,g=e.body,a.pageX=d.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=d.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?d.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0);return a}},fix:function(a){if(a[f.expando])return a;var d,e,g=a,h=f.event.fixHooks[a.type]||{},i=h.props?this.props.concat(h.props):this.props;a=f.Event(g);for(d=i.length;d;)e=i[--d],a[e]=g[e];a.target||(a.target=g.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey===b&&(a.metaKey=a.ctrlKey);return h.filter?h.filter(a,g):a},special:{ready:{setup:f.bindReady},load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=f.extend(new f.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?f.event.trigger(e,null,b):f.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},f.event.handle=f.event.dispatch,f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!(this instanceof f.Event))return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?K:J):this.type=a,b&&f.extend(this,b),this.timeStamp=a&&a.timeStamp||f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=K;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=K;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=K,this.stopPropagation()},isDefaultPrevented:J,isPropagationStopped:J,isImmediatePropagationStopped:J},f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c=this,d=a.relatedTarget,e=a.handleObj,g=e.selector,h;if(!d||d!==c&&!f.contains(c,d))a.type=e.origType,h=e.handler.apply(this,arguments),a.type=b;return h}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(){if(f.nodeName(this,"form"))return!1;f.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=f.nodeName(c,"input")||f.nodeName(c,"button")?c.form:b;d&&!d._submit_attached&&(f.event.add(d,"submit._submit",function(a){this.parentNode&&!a.isTrigger&&f.event.simulate("submit",this.parentNode,a,!0)}),d._submit_attached=!0)})},teardown:function(){if(f.nodeName(this,"form"))return!1;f.event.remove(this,"._submit")}}),f.support.changeBubbles||(f.event.special.change={setup:function(){if(z.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")f.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),f.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1,f.event.simulate("change",this,a,!0))});return!1}f.event.add(this,"beforeactivate._change",function(a){var b=a.target;z.test(b.nodeName)&&!b._change_attached&&(f.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&!a.isTrigger&&f.event.simulate("change",this.parentNode,a,!0)}),b._change_attached=!0)})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){f.event.remove(this,"._change");return z.test(this.nodeName)}}),f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){var d=0,e=function(a){f.event.simulate(b,a.target,f.event.fix(a),!0)};f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.fn.extend({on:function(a,c,d,e,g){var h,i;if(typeof a=="object"){typeof c!="string"&&(d=c,c=b);for(i in a)this.on(i,c,d,a[i],g);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=J;else if(!e)return this;g===1&&(h=e,e=function(a){f().off(a);return h.apply(this,arguments)},e.guid=h.guid||(h.guid=f.guid++));return this.each(function(){f.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on.call(this,a,b,c,d,1)},off:function(a,c,d){if(a&&a.preventDefault&&a.handleObj){var e=a.handleObj;f(a.delegateTarget).off(e.namespace?e.type+"."+e.namespace:e.type,e.selector,e.handler);return this}if(typeof a=="object"){for(var g in a)this.off(g,c,a[g]);return this}if(c===!1||typeof c=="function")d=c,c=b;d===!1&&(d=J);return this.each(function(){f.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){f(this.context).on(a,this.selector,b,c);return this},die:function(a,b){f(this.context).off(a,this.selector||"**",b);return this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a,c)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}if(j.nodeType===1){g||(j[d]=c,j.sizset=h);if(typeof b!="string"){if(j===b){k=!0;break}}else if(m.filter(b,[j]).length>0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}j.nodeType===1&&!g&&(j[d]=c,j.sizset=h);if(j.nodeName.toLowerCase()===b){k=j;break}j=j[a]}e[h]=k}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},m.matches=function(a,b){return m(a,null,null,b)},m.matchesSelector=function(a,b){return m(b,null,null,[a]).length>0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e<f;e++){h=o.order[e];if(g=o.leftMatch[h].exec(a)){i=g[1],g.splice(1,1);if(i.substr(i.length-1)!=="\\"){g[1]=(g[1]||"").replace(j,""),d=o.find[h](g,b,c);if(d!=null){a=a.replace(o.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},m.filter=function(a,c,d,e){var f,g,h,i,j,k,l,n,p,q=a,r=[],s=c,t=c&&c[0]&&m.isXML(c[0]);while(a&&c.length){for(h in o.filter)if((f=o.leftMatch[h].exec(a))!=null&&f[2]){k=o.filter[h],l=f[1],g=!1,f.splice(1,1);if(l.substr(l.length-1)==="\\")continue;s===r&&(r=[]);if(o.preFilter[h]){f=o.preFilter[h](f,s,d,r,e,t);if(!f)g=i=!0;else if(f===!0)continue}if(f)for(n=0;(j=s[n])!=null;n++)j&&(i=k(j,f,n,s),p=e^i,d&&i!=null?p?g=!0:s[n]=!1:p&&(r.push(j),g=!0));if(i!==b){d||(s=r),a=a.replace(o.match[h],"");if(!g)return[];break}}if(a===q)if(g==null)m.error(a);else break;q=a}return s},m.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)};var n=m.getText=function(a){var b,c,d=a.nodeType,e="";if(d){if(d===1||d===9){if(typeof a.textContent=="string")return a.textContent;if(typeof a.innerText=="string")return a.innerText.replace(k,"");for(a=a.firstChild;a;a=a.nextSibling)e+=n(a)}else if(d===3||d===4)return a.nodeValue}else for(b=0;c=a[b];b++)c.nodeType!==8&&(e+=n(c));return e},o=m.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!l.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&m.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&m.filter(b,a,!0)}},"":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("parentNode",b,f,a,d,c)},"~":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("previousSibling",b,f,a,d,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(j,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}m.error(e)},CHILD:function(a,b){var c,e,f,g,h,i,j,k=b[1],l=a;switch(k){case"only":case"first":while(l=l.previousSibling)if(l.nodeType===1)return!1;if(k==="first")return!0;l=a;case"last":while(l=l.nextSibling)if(l.nodeType===1)return!1;return!0;case"nth":c=b[2],e=b[3];if(c===1&&e===0)return!0;f=b[0],g=a.parentNode;if(g&&(g[d]!==f||!a.nodeIndex)){i=0;for(l=g.firstChild;l;l=l.nextSibling)l.nodeType===1&&(l.nodeIndex=++i);g[d]=f}j=a.nodeIndex-e;return c===0?j===0:j%c===0&&j/c>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c<e;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var u,v;c.documentElement.compareDocumentPosition?u=function(a,b){if(a===b){h=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(u=function(a,b){if(a===b){h=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],g=a.parentNode,i=b.parentNode,j=g;if(g===i)return v(a,b);if(!g)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return v(e[k],f[k]);return k===c?v(a,f[k],-1):v(e[k],b,1)},v=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h<i;h++)m(a,g[h],e,c);return m.filter(f,e)};m.attr=f.attr,m.selectors.attrMap={},f.find=m,f.expr=m.selectors,f.expr[":"]=f.expr.filters,f.unique=m.uniqueSort,f.text=m.getText,f.isXMLDoc=m.isXML,f.contains=m.contains}();var L=/Until$/,M=/^(?:parents|prevUntil|prevAll)/,N=/,/,O=/^.[^:#\[\.,]*$/,P=Array.prototype.slice,Q=f.expr.match.POS,R={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(T(this,a,!1),"not",a)},filter:function(a){return this.pushStack(T(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?Q.test(a)?f(a,this.context).index(this[0])>=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d<a.length;d++)f(g).is(a[d])&&c.push({selector:a[d],elem:g,level:h});g=g.parentNode,h++}return c}var i=Q.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(i?i.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|style)/i,bb=/<(?:script|object|embed|option|style)/i,bc=new RegExp("<(?:"+V+")","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*<!(?:\[CDATA\[|\-\-)/,bg={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function() +{for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bd.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bi(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,bp)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i,j=a[0];b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof j=="string"&&j.length<512&&i===c&&j.charAt(0)==="<"&&!bb.test(j)&&(f.support.checkClone||!bd.test(j))&&(f.support.html5Clone||!bc.test(j))&&(g=!0,h=f.fragments[j],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[j]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1></$2>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bn(k[i]);else bn(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||be.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.event.special,g=f.support.deleteExpando;for(var h=0,i;(i=a[h])!=null;h++){if(i.nodeName&&f.noData[i.nodeName.toLowerCase()])continue;c=i[f.expando];if(c){b=d[c];if(b&&b.events){for(var j in b.events)e[j]?f.event.remove(i,j):f.removeEvent(i,j,b.handle);b.handle&&(b.handle.elem=null)}g?delete i[f.expando]:i.removeAttribute&&i.removeAttribute(f.expando),delete d[c]}}}});var bq=/alpha\([^)]*\)/i,br=/opacity=([^)]*)/,bs=/([A-Z]|^ms)/g,bt=/^-?\d+(?:px)?$/i,bu=/^-?\d/,bv=/^([\-+])=([\-+.\de]+)/,bw={position:"absolute",visibility:"hidden",display:"block"},bx=["Left","Right"],by=["Top","Bottom"],bz,bA,bB;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bz(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bv.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bz)return bz(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return bC(a,b,d);f.swap(a,bw,function(){e=bC(a,b,d)});return e}},set:function(a,b){if(!bt.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cv(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cu("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cu("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b]&&g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:cu("show",1),slideUp:cu("hide",1),slideToggle:cu("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=cr||cs(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){e.options.hide&&f._data(e.elem,"fxshow"+e.prop)===b&&f._data(e.elem,"fxshow"+e.prop,e.start)},h()&&f.timers.push(h)&&!cp&&(cp=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=cr||cs(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cp),cp=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(["width","height"],function(a,b){f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now)+a.unit)}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cw=/^t(?:able|d|h)$/i,cx=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cy(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.support.fixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cw.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.support.fixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window);
\ No newline at end of file diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/index.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/index.css new file mode 100644 index 0000000000..0032bedca1 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/index.css @@ -0,0 +1,64 @@ +/* + * + * 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. + * + */ + +html +{ + background: black; +} + +body +{ + position: absolute; + + top: 0; + left: 0; + width: 100%; + height: 100%; + margin: 0; + + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + + background: #bbb url(/qmf-ui/images/gradient.png) repeat-x; + background: -o-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #bbb)); + background: -webkit-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -ms-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -moz-linear-gradient(top center, #fff 0%, #bbb 100%); +} + +div.logo +{ + position: absolute; + top: 5%; + left: 0; + right: 0; + height: 114px; + margin: 0 35% 0 35%; + + -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; + filter: alpha(opacity=70); + opacity: 0.7; + + background: transparent url(/qmf-ui/images/qpid-logo.png) center no-repeat; +} + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/qmf.css b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/qmf.css new file mode 100644 index 0000000000..11ca7fad12 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/css/qmf.css @@ -0,0 +1,144 @@ +/* + * + * 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. + * + */ + +a.settings +{ + background: url(/qmf-ui/images/settings.png) no-repeat left; +} + +a.brokers +{ + background: url(/qmf-ui/images/brokers.png) no-repeat left; +} + +a.connections +{ + background: url(/qmf-ui/images/connections.png) no-repeat left; +} + +a.exchanges +{ + background: url(/qmf-ui/images/exchanges.png) no-repeat left; +} + +a.queues +{ + background: url(/qmf-ui/images/queues.png) no-repeat left; +} + +a.links +{ + background: url(/qmf-ui/images/links.png) no-repeat left; +} + +a.route-topology +{ + background: url(/qmf-ui/images/route-topology.png) no-repeat left; +} + +a.events +{ + background: url(/qmf-ui/images/events.png) no-repeat left; +} + +/* This style allows a simple alert banner to be displayed */ +div.alert +{ + position: fixed; + opacity: 0.6; + + font-size: 30pt; + color: #d0d0d0; + background: red; + + top: 45.5%; + left: 10%; + width: 80%; + text-align: center; + + -o-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + -webkit-transform: rotate(-45deg); + -moz-transform: rotate(-45deg); + + box-shadow: 5px 5px 5px #888; + z-index: 5; + display: none; + + /* At it's only a few styles different just use <= IE8 css hack rather than a whole stylesheet */ + position: relative\9; + background: url(/itablet/images/ie/red6.png) repeat\9; + top: 200px\9; +} + + +#splash +{ + position: absolute; + + top: 0; + left: 0; + width: 100%; + height: 100%; + margin: 0; + + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + + background: #bbb url(/qmf-ui/images/gradient.png) repeat-x; + background: -o-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #bbb)); + background: -webkit-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -ms-linear-gradient(top center, #fff 0%, #bbb 100%); + background: -moz-linear-gradient(top center, #fff 0%, #bbb 100%); + + z-index: 100; +} + +#splash div.logo +{ + position: absolute; + top: 5%; + left: 0; + right: 0; + height: 114px; + margin: 0 35% 0 35%; + + -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; + filter: alpha(opacity=70); + opacity: 0.7; + + background: transparent url(/qmf-ui/images/qpid-logo.png) center no-repeat; +} + +#splash div.loading +{ + position: absolute; + top: 70px; + left: 0; + right: 0; + height: 32px; + + background: transparent url(/qmf-ui/images/loading.gif) center no-repeat; +} + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/brokers.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/brokers.png Binary files differnew file mode 100644 index 0000000000..72efa7ab11 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/brokers.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/connections.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/connections.png Binary files differnew file mode 100644 index 0000000000..2e1d422d0a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/connections.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/events.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/events.png Binary files differnew file mode 100644 index 0000000000..1e5a7ee5ca --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/events.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/exchanges.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/exchanges.png Binary files differnew file mode 100644 index 0000000000..5f15dbbfdc --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/exchanges.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/gradient.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/gradient.png Binary files differnew file mode 100644 index 0000000000..260a05701f --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/gradient.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/links.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/links.png Binary files differnew file mode 100644 index 0000000000..d8ad7af518 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/links.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/loading.gif b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/loading.gif Binary files differnew file mode 100644 index 0000000000..3288d1035d --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/loading.gif diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/qpid-logo.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/qpid-logo.png Binary files differnew file mode 100644 index 0000000000..d548b68245 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/qpid-logo.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/queues.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/queues.png Binary files differnew file mode 100644 index 0000000000..4f72abfe50 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/queues.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/route-topology.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/route-topology.png Binary files differnew file mode 100644 index 0000000000..c1b36d4077 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/route-topology.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/settings.png b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/settings.png Binary files differnew file mode 100644 index 0000000000..6994d4a0d4 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/images/settings.png diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/LICENCE b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/LICENCE new file mode 100644 index 0000000000..e90b016701 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/LICENCE @@ -0,0 +1,39 @@ + +/* + * excanvas.js + * + * ExplorerCanvas - provides HTML5 canvas on IE + * + * note that this is using excanvas.js from http://explorercanvas.googlecode.com/svn/trunk/ as it happens that's + * more up to date than the version https://code.google.com/p/explorercanvas/downloads/list/excanvas_r3.zip which + * is the version one gets following the obvious path. Unfortunately excanvas_r3.zip has several bugs in drawImage() + * which affect the border radius rendering for IE7 canvas, the version from trunk fixes that.... + * + * Google Open Source: + * <http://code.google.com> + * <opensource@google.com> + * + * Developers: + * Emil A Eklund <emil@eae.net> + * Erik Arvidsson <erik@eae.net> + * Glen Murphy <glen@glenmurphy.com> + * + * 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. + * + */ + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/excanvas.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/excanvas.js new file mode 100644 index 0000000000..a6d9ddf5fa --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/excanvas.js @@ -0,0 +1,1416 @@ +// Copyright 2006 Google Inc. +// +// Licensed 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. + + +// Known Issues: +// +// * Patterns only support repeat. +// * Radial gradient are not implemented. The VML version of these look very +// different from the canvas one. +// * Clipping paths are not implemented. +// * Coordsize. The width and height attribute have higher priority than the +// width and height style values which isn't correct. +// * Painting mode isn't implemented. +// * Canvas width/height should is using content-box by default. IE in +// Quirks mode will draw the canvas using border-box. Either change your +// doctype to HTML5 +// (http://www.whatwg.org/specs/web-apps/current-work/#the-doctype) +// or use Box Sizing Behavior from WebFX +// (http://webfx.eae.net/dhtml/boxsizing/boxsizing.html) +// * Non uniform scaling does not correctly scale strokes. +// * Optimize. There is always room for speed improvements. + +// Only add this code if we do not already have a canvas implementation +if (!document.createElement('canvas').getContext) { + +(function() { + + // alias some functions to make (compiled) code shorter + var m = Math; + var mr = m.round; + var ms = m.sin; + var mc = m.cos; + var abs = m.abs; + var sqrt = m.sqrt; + + // this is used for sub pixel precision + var Z = 10; + var Z2 = Z / 2; + + var IE_VERSION = +navigator.userAgent.match(/MSIE ([\d.]+)?/)[1]; + + /** + * This funtion is assigned to the <canvas> elements as element.getContext(). + * @this {HTMLElement} + * @return {CanvasRenderingContext2D_} + */ + function getContext() { + return this.context_ || + (this.context_ = new CanvasRenderingContext2D_(this)); + } + + var slice = Array.prototype.slice; + + /** + * Binds a function to an object. The returned function will always use the + * passed in {@code obj} as {@code this}. + * + * Example: + * + * g = bind(f, obj, a, b) + * g(c, d) // will do f.call(obj, a, b, c, d) + * + * @param {Function} f The function to bind the object to + * @param {Object} obj The object that should act as this when the function + * is called + * @param {*} var_args Rest arguments that will be used as the initial + * arguments when the function is called + * @return {Function} A new function that has bound this + */ + function bind(f, obj, var_args) { + var a = slice.call(arguments, 2); + return function() { + return f.apply(obj, a.concat(slice.call(arguments))); + }; + } + + function encodeHtmlAttribute(s) { + return String(s).replace(/&/g, '&').replace(/"/g, '"'); + } + + function addNamespace(doc, prefix, urn) { + if (!doc.namespaces[prefix]) { + doc.namespaces.add(prefix, urn, '#default#VML'); + } + } + + function addNamespacesAndStylesheet(doc) { + addNamespace(doc, 'g_vml_', 'urn:schemas-microsoft-com:vml'); + addNamespace(doc, 'g_o_', 'urn:schemas-microsoft-com:office:office'); + + // Setup default CSS. Only add one style sheet per document + if (!doc.styleSheets['ex_canvas_']) { + var ss = doc.createStyleSheet(); + ss.owningElement.id = 'ex_canvas_'; + ss.cssText = 'canvas{display:inline-block;overflow:hidden;' + + // default size is 300x150 in Gecko and Opera + 'text-align:left;width:300px;height:150px}'; + } + } + + // Add namespaces and stylesheet at startup. + addNamespacesAndStylesheet(document); + + var G_vmlCanvasManager_ = { + init: function(opt_doc) { + var doc = opt_doc || document; + // Create a dummy element so that IE will allow canvas elements to be + // recognized. + doc.createElement('canvas'); + doc.attachEvent('onreadystatechange', bind(this.init_, this, doc)); + }, + + init_: function(doc) { + // find all canvas elements + var els = doc.getElementsByTagName('canvas'); + for (var i = 0; i < els.length; i++) { + this.initElement(els[i]); + } + }, + + /** + * Public initializes a canvas element so that it can be used as canvas + * element from now on. This is called automatically before the page is + * loaded but if you are creating elements using createElement you need to + * make sure this is called on the element. + * @param {HTMLElement} el The canvas element to initialize. + * @return {HTMLElement} the element that was created. + */ + initElement: function(el) { + if (!el.getContext) { + el.getContext = getContext; + + // Add namespaces and stylesheet to document of the element. + addNamespacesAndStylesheet(el.ownerDocument); + + // Remove fallback content. There is no way to hide text nodes so we + // just remove all childNodes. We could hide all elements and remove + // text nodes but who really cares about the fallback content. + el.innerHTML = ''; + + // do not use inline function because that will leak memory + el.attachEvent('onpropertychange', onPropertyChange); + el.attachEvent('onresize', onResize); + + var attrs = el.attributes; + if (attrs.width && attrs.width.specified) { + // TODO: use runtimeStyle and coordsize + // el.getContext().setWidth_(attrs.width.nodeValue); + el.style.width = attrs.width.nodeValue + 'px'; + } else { + el.width = el.clientWidth; + } + if (attrs.height && attrs.height.specified) { + // TODO: use runtimeStyle and coordsize + // el.getContext().setHeight_(attrs.height.nodeValue); + el.style.height = attrs.height.nodeValue + 'px'; + } else { + el.height = el.clientHeight; + } + //el.getContext().setCoordsize_() + } + return el; + } + }; + + function onPropertyChange(e) { + var el = e.srcElement; + + switch (e.propertyName) { + case 'width': + el.getContext().clearRect(); + el.style.width = el.attributes.width.nodeValue + 'px'; + // In IE8 this does not trigger onresize. + el.firstChild.style.width = el.clientWidth + 'px'; + break; + case 'height': + el.getContext().clearRect(); + el.style.height = el.attributes.height.nodeValue + 'px'; + el.firstChild.style.height = el.clientHeight + 'px'; + break; + } + } + + function onResize(e) { + var el = e.srcElement; + if (el.firstChild) { + el.firstChild.style.width = el.clientWidth + 'px'; + el.firstChild.style.height = el.clientHeight + 'px'; + } + } + + G_vmlCanvasManager_.init(); + + // precompute "00" to "FF" + var decToHex = []; + for (var i = 0; i < 16; i++) { + for (var j = 0; j < 16; j++) { + decToHex[i * 16 + j] = i.toString(16) + j.toString(16); + } + } + + function createMatrixIdentity() { + return [ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1] + ]; + } + + function matrixMultiply(m1, m2) { + var result = createMatrixIdentity(); + + for (var x = 0; x < 3; x++) { + for (var y = 0; y < 3; y++) { + var sum = 0; + + for (var z = 0; z < 3; z++) { + sum += m1[x][z] * m2[z][y]; + } + + result[x][y] = sum; + } + } + return result; + } + + function copyState(o1, o2) { + o2.fillStyle = o1.fillStyle; + o2.lineCap = o1.lineCap; + o2.lineJoin = o1.lineJoin; + o2.lineWidth = o1.lineWidth; + o2.miterLimit = o1.miterLimit; + o2.shadowBlur = o1.shadowBlur; + o2.shadowColor = o1.shadowColor; + o2.shadowOffsetX = o1.shadowOffsetX; + o2.shadowOffsetY = o1.shadowOffsetY; + o2.strokeStyle = o1.strokeStyle; + o2.globalAlpha = o1.globalAlpha; + o2.font = o1.font; + o2.textAlign = o1.textAlign; + o2.textBaseline = o1.textBaseline; + o2.arcScaleX_ = o1.arcScaleX_; + o2.arcScaleY_ = o1.arcScaleY_; + o2.lineScale_ = o1.lineScale_; + } + + var colorData = { + aliceblue: '#F0F8FF', + antiquewhite: '#FAEBD7', + aquamarine: '#7FFFD4', + azure: '#F0FFFF', + beige: '#F5F5DC', + bisque: '#FFE4C4', + black: '#000000', + blanchedalmond: '#FFEBCD', + blueviolet: '#8A2BE2', + brown: '#A52A2A', + burlywood: '#DEB887', + cadetblue: '#5F9EA0', + chartreuse: '#7FFF00', + chocolate: '#D2691E', + coral: '#FF7F50', + cornflowerblue: '#6495ED', + cornsilk: '#FFF8DC', + crimson: '#DC143C', + cyan: '#00FFFF', + darkblue: '#00008B', + darkcyan: '#008B8B', + darkgoldenrod: '#B8860B', + darkgray: '#A9A9A9', + darkgreen: '#006400', + darkgrey: '#A9A9A9', + darkkhaki: '#BDB76B', + darkmagenta: '#8B008B', + darkolivegreen: '#556B2F', + darkorange: '#FF8C00', + darkorchid: '#9932CC', + darkred: '#8B0000', + darksalmon: '#E9967A', + darkseagreen: '#8FBC8F', + darkslateblue: '#483D8B', + darkslategray: '#2F4F4F', + darkslategrey: '#2F4F4F', + darkturquoise: '#00CED1', + darkviolet: '#9400D3', + deeppink: '#FF1493', + deepskyblue: '#00BFFF', + dimgray: '#696969', + dimgrey: '#696969', + dodgerblue: '#1E90FF', + firebrick: '#B22222', + floralwhite: '#FFFAF0', + forestgreen: '#228B22', + gainsboro: '#DCDCDC', + ghostwhite: '#F8F8FF', + gold: '#FFD700', + goldenrod: '#DAA520', + grey: '#808080', + greenyellow: '#ADFF2F', + honeydew: '#F0FFF0', + hotpink: '#FF69B4', + indianred: '#CD5C5C', + indigo: '#4B0082', + ivory: '#FFFFF0', + khaki: '#F0E68C', + lavender: '#E6E6FA', + lavenderblush: '#FFF0F5', + lawngreen: '#7CFC00', + lemonchiffon: '#FFFACD', + lightblue: '#ADD8E6', + lightcoral: '#F08080', + lightcyan: '#E0FFFF', + lightgoldenrodyellow: '#FAFAD2', + lightgreen: '#90EE90', + lightgrey: '#D3D3D3', + lightpink: '#FFB6C1', + lightsalmon: '#FFA07A', + lightseagreen: '#20B2AA', + lightskyblue: '#87CEFA', + lightslategray: '#778899', + lightslategrey: '#778899', + lightsteelblue: '#B0C4DE', + lightyellow: '#FFFFE0', + limegreen: '#32CD32', + linen: '#FAF0E6', + magenta: '#FF00FF', + mediumaquamarine: '#66CDAA', + mediumblue: '#0000CD', + mediumorchid: '#BA55D3', + mediumpurple: '#9370DB', + mediumseagreen: '#3CB371', + mediumslateblue: '#7B68EE', + mediumspringgreen: '#00FA9A', + mediumturquoise: '#48D1CC', + mediumvioletred: '#C71585', + midnightblue: '#191970', + mintcream: '#F5FFFA', + mistyrose: '#FFE4E1', + moccasin: '#FFE4B5', + navajowhite: '#FFDEAD', + oldlace: '#FDF5E6', + olivedrab: '#6B8E23', + orange: '#FFA500', + orangered: '#FF4500', + orchid: '#DA70D6', + palegoldenrod: '#EEE8AA', + palegreen: '#98FB98', + paleturquoise: '#AFEEEE', + palevioletred: '#DB7093', + papayawhip: '#FFEFD5', + peachpuff: '#FFDAB9', + peru: '#CD853F', + pink: '#FFC0CB', + plum: '#DDA0DD', + powderblue: '#B0E0E6', + rosybrown: '#BC8F8F', + royalblue: '#4169E1', + saddlebrown: '#8B4513', + salmon: '#FA8072', + sandybrown: '#F4A460', + seagreen: '#2E8B57', + seashell: '#FFF5EE', + sienna: '#A0522D', + skyblue: '#87CEEB', + slateblue: '#6A5ACD', + slategray: '#708090', + slategrey: '#708090', + snow: '#FFFAFA', + springgreen: '#00FF7F', + steelblue: '#4682B4', + tan: '#D2B48C', + thistle: '#D8BFD8', + tomato: '#FF6347', + turquoise: '#40E0D0', + violet: '#EE82EE', + wheat: '#F5DEB3', + whitesmoke: '#F5F5F5', + yellowgreen: '#9ACD32' + }; + + + function getRgbHslContent(styleString) { + var start = styleString.indexOf('(', 3); + var end = styleString.indexOf(')', start + 1); + var parts = styleString.substring(start + 1, end).split(','); + // add alpha if needed + if (parts.length != 4 || styleString.charAt(3) != 'a') { + parts[3] = 1; + } + return parts; + } + + function percent(s) { + return parseFloat(s) / 100; + } + + function clamp(v, min, max) { + return Math.min(max, Math.max(min, v)); + } + + function hslToRgb(parts){ + var r, g, b, h, s, l; + h = parseFloat(parts[0]) / 360 % 360; + if (h < 0) + h++; + s = clamp(percent(parts[1]), 0, 1); + l = clamp(percent(parts[2]), 0, 1); + if (s == 0) { + r = g = b = l; // achromatic + } else { + var q = l < 0.5 ? l * (1 + s) : l + s - l * s; + var p = 2 * l - q; + r = hueToRgb(p, q, h + 1 / 3); + g = hueToRgb(p, q, h); + b = hueToRgb(p, q, h - 1 / 3); + } + + return '#' + decToHex[Math.floor(r * 255)] + + decToHex[Math.floor(g * 255)] + + decToHex[Math.floor(b * 255)]; + } + + function hueToRgb(m1, m2, h) { + if (h < 0) + h++; + if (h > 1) + h--; + + if (6 * h < 1) + return m1 + (m2 - m1) * 6 * h; + else if (2 * h < 1) + return m2; + else if (3 * h < 2) + return m1 + (m2 - m1) * (2 / 3 - h) * 6; + else + return m1; + } + + var processStyleCache = {}; + + function processStyle(styleString) { + if (styleString in processStyleCache) { + return processStyleCache[styleString]; + } + + var str, alpha = 1; + + styleString = String(styleString); + if (styleString.charAt(0) == '#') { + str = styleString; + } else if (/^rgb/.test(styleString)) { + var parts = getRgbHslContent(styleString); + var str = '#', n; + for (var i = 0; i < 3; i++) { + if (parts[i].indexOf('%') != -1) { + n = Math.floor(percent(parts[i]) * 255); + } else { + n = +parts[i]; + } + str += decToHex[clamp(n, 0, 255)]; + } + alpha = +parts[3]; + } else if (/^hsl/.test(styleString)) { + var parts = getRgbHslContent(styleString); + str = hslToRgb(parts); + alpha = parts[3]; + } else { + str = colorData[styleString] || styleString; + } + return processStyleCache[styleString] = {color: str, alpha: alpha}; + } + + var DEFAULT_STYLE = { + style: 'normal', + variant: 'normal', + weight: 'normal', + size: 10, + family: 'sans-serif' + }; + + // Internal text style cache + var fontStyleCache = {}; + + function processFontStyle(styleString) { + if (fontStyleCache[styleString]) { + return fontStyleCache[styleString]; + } + + var el = document.createElement('div'); + var style = el.style; + try { + style.font = styleString; + } catch (ex) { + // Ignore failures to set to invalid font. + } + + return fontStyleCache[styleString] = { + style: style.fontStyle || DEFAULT_STYLE.style, + variant: style.fontVariant || DEFAULT_STYLE.variant, + weight: style.fontWeight || DEFAULT_STYLE.weight, + size: style.fontSize || DEFAULT_STYLE.size, + family: style.fontFamily || DEFAULT_STYLE.family + }; + } + + function getComputedStyle(style, element) { + var computedStyle = {}; + + for (var p in style) { + computedStyle[p] = style[p]; + } + + // Compute the size + var canvasFontSize = parseFloat(element.currentStyle.fontSize), + fontSize = parseFloat(style.size); + + if (typeof style.size == 'number') { + computedStyle.size = style.size; + } else if (style.size.indexOf('px') != -1) { + computedStyle.size = fontSize; + } else if (style.size.indexOf('em') != -1) { + computedStyle.size = canvasFontSize * fontSize; + } else if(style.size.indexOf('%') != -1) { + computedStyle.size = (canvasFontSize / 100) * fontSize; + } else if (style.size.indexOf('pt') != -1) { + computedStyle.size = fontSize / .75; + } else { + computedStyle.size = canvasFontSize; + } + + // Different scaling between normal text and VML text. This was found using + // trial and error to get the same size as non VML text. + computedStyle.size *= 0.981; + + return computedStyle; + } + + function buildStyle(style) { + return style.style + ' ' + style.variant + ' ' + style.weight + ' ' + + style.size + 'px ' + style.family; + } + + var lineCapMap = { + 'butt': 'flat', + 'round': 'round' + }; + + function processLineCap(lineCap) { + return lineCapMap[lineCap] || 'square'; + } + + /** + * This class implements CanvasRenderingContext2D interface as described by + * the WHATWG. + * @param {HTMLElement} canvasElement The element that the 2D context should + * be associated with + */ + function CanvasRenderingContext2D_(canvasElement) { + this.m_ = createMatrixIdentity(); + + this.mStack_ = []; + this.aStack_ = []; + this.currentPath_ = []; + + // Canvas context properties + this.strokeStyle = '#000'; + this.fillStyle = '#000'; + + this.lineWidth = 1; + this.lineJoin = 'miter'; + this.lineCap = 'butt'; + this.miterLimit = Z * 1; + this.globalAlpha = 1; + this.font = '10px sans-serif'; + this.textAlign = 'left'; + this.textBaseline = 'alphabetic'; + this.canvas = canvasElement; + + var cssText = 'width:' + canvasElement.clientWidth + 'px;height:' + + canvasElement.clientHeight + 'px;overflow:hidden;position:absolute'; + var el = canvasElement.ownerDocument.createElement('div'); + el.style.cssText = cssText; + canvasElement.appendChild(el); + + var overlayEl = el.cloneNode(false); + // Use a non transparent background. + overlayEl.style.backgroundColor = 'red'; + overlayEl.style.filter = 'alpha(opacity=0)'; + canvasElement.appendChild(overlayEl); + + this.element_ = el; + this.arcScaleX_ = 1; + this.arcScaleY_ = 1; + this.lineScale_ = 1; + } + + var contextPrototype = CanvasRenderingContext2D_.prototype; + contextPrototype.clearRect = function() { + if (this.textMeasureEl_) { + this.textMeasureEl_.removeNode(true); + this.textMeasureEl_ = null; + } + this.element_.innerHTML = ''; + }; + + contextPrototype.beginPath = function() { + // TODO: Branch current matrix so that save/restore has no effect + // as per safari docs. + this.currentPath_ = []; + }; + + contextPrototype.moveTo = function(aX, aY) { + var p = getCoords(this, aX, aY); + this.currentPath_.push({type: 'moveTo', x: p.x, y: p.y}); + this.currentX_ = p.x; + this.currentY_ = p.y; + }; + + contextPrototype.lineTo = function(aX, aY) { + var p = getCoords(this, aX, aY); + this.currentPath_.push({type: 'lineTo', x: p.x, y: p.y}); + + this.currentX_ = p.x; + this.currentY_ = p.y; + }; + + contextPrototype.bezierCurveTo = function(aCP1x, aCP1y, + aCP2x, aCP2y, + aX, aY) { + var p = getCoords(this, aX, aY); + var cp1 = getCoords(this, aCP1x, aCP1y); + var cp2 = getCoords(this, aCP2x, aCP2y); + bezierCurveTo(this, cp1, cp2, p); + }; + + // Helper function that takes the already fixed cordinates. + function bezierCurveTo(self, cp1, cp2, p) { + self.currentPath_.push({ + type: 'bezierCurveTo', + cp1x: cp1.x, + cp1y: cp1.y, + cp2x: cp2.x, + cp2y: cp2.y, + x: p.x, + y: p.y + }); + self.currentX_ = p.x; + self.currentY_ = p.y; + } + + contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) { + // the following is lifted almost directly from + // http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes + + var cp = getCoords(this, aCPx, aCPy); + var p = getCoords(this, aX, aY); + + var cp1 = { + x: this.currentX_ + 2.0 / 3.0 * (cp.x - this.currentX_), + y: this.currentY_ + 2.0 / 3.0 * (cp.y - this.currentY_) + }; + var cp2 = { + x: cp1.x + (p.x - this.currentX_) / 3.0, + y: cp1.y + (p.y - this.currentY_) / 3.0 + }; + + bezierCurveTo(this, cp1, cp2, p); + }; + + contextPrototype.arc = function(aX, aY, aRadius, + aStartAngle, aEndAngle, aClockwise) { + aRadius *= Z; + var arcType = aClockwise ? 'at' : 'wa'; + + var xStart = aX + mc(aStartAngle) * aRadius - Z2; + var yStart = aY + ms(aStartAngle) * aRadius - Z2; + + var xEnd = aX + mc(aEndAngle) * aRadius - Z2; + var yEnd = aY + ms(aEndAngle) * aRadius - Z2; + + // IE won't render arches drawn counter clockwise if xStart == xEnd. + if (xStart == xEnd && !aClockwise) { + xStart += 0.125; // Offset xStart by 1/80 of a pixel. Use something + // that can be represented in binary + } + + var p = getCoords(this, aX, aY); + var pStart = getCoords(this, xStart, yStart); + var pEnd = getCoords(this, xEnd, yEnd); + + this.currentPath_.push({type: arcType, + x: p.x, + y: p.y, + radius: aRadius, + xStart: pStart.x, + yStart: pStart.y, + xEnd: pEnd.x, + yEnd: pEnd.y}); + + }; + + contextPrototype.rect = function(aX, aY, aWidth, aHeight) { + this.moveTo(aX, aY); + this.lineTo(aX + aWidth, aY); + this.lineTo(aX + aWidth, aY + aHeight); + this.lineTo(aX, aY + aHeight); + this.closePath(); + }; + + contextPrototype.strokeRect = function(aX, aY, aWidth, aHeight) { + var oldPath = this.currentPath_; + this.beginPath(); + + this.moveTo(aX, aY); + this.lineTo(aX + aWidth, aY); + this.lineTo(aX + aWidth, aY + aHeight); + this.lineTo(aX, aY + aHeight); + this.closePath(); + this.stroke(); + + this.currentPath_ = oldPath; + }; + + contextPrototype.fillRect = function(aX, aY, aWidth, aHeight) { + var oldPath = this.currentPath_; + this.beginPath(); + + this.moveTo(aX, aY); + this.lineTo(aX + aWidth, aY); + this.lineTo(aX + aWidth, aY + aHeight); + this.lineTo(aX, aY + aHeight); + this.closePath(); + this.fill(); + + this.currentPath_ = oldPath; + }; + + contextPrototype.createLinearGradient = function(aX0, aY0, aX1, aY1) { + var gradient = new CanvasGradient_('gradient'); + gradient.x0_ = aX0; + gradient.y0_ = aY0; + gradient.x1_ = aX1; + gradient.y1_ = aY1; + return gradient; + }; + + contextPrototype.createRadialGradient = function(aX0, aY0, aR0, + aX1, aY1, aR1) { + var gradient = new CanvasGradient_('gradientradial'); + gradient.x0_ = aX0; + gradient.y0_ = aY0; + gradient.r0_ = aR0; + gradient.x1_ = aX1; + gradient.y1_ = aY1; + gradient.r1_ = aR1; + return gradient; + }; + + contextPrototype.drawImage = function(image, var_args) { + var dx, dy, dw, dh, sx, sy, sw, sh; + + // to find the original width we overide the width and height + var oldRuntimeWidth = image.runtimeStyle.width; + var oldRuntimeHeight = image.runtimeStyle.height; + image.runtimeStyle.width = 'auto'; + image.runtimeStyle.height = 'auto'; + + // get the original size + var w = image.width; + var h = image.height; + + // and remove overides + image.runtimeStyle.width = oldRuntimeWidth; + image.runtimeStyle.height = oldRuntimeHeight; + + if (arguments.length == 3) { + dx = arguments[1]; + dy = arguments[2]; + sx = sy = 0; + sw = dw = w; + sh = dh = h; + } else if (arguments.length == 5) { + dx = arguments[1]; + dy = arguments[2]; + dw = arguments[3]; + dh = arguments[4]; + sx = sy = 0; + sw = w; + sh = h; + } else if (arguments.length == 9) { + sx = arguments[1]; + sy = arguments[2]; + sw = arguments[3]; + sh = arguments[4]; + dx = arguments[5]; + dy = arguments[6]; + dw = arguments[7]; + dh = arguments[8]; + } else { + throw Error('Invalid number of arguments'); + } + + var d = getCoords(this, dx, dy); + + var w2 = sw / 2; + var h2 = sh / 2; + + var vmlStr = []; + + var W = 10; + var H = 10; + + // For some reason that I've now forgotten, using divs didn't work + vmlStr.push(' <g_vml_:group', + ' coordsize="', Z * W, ',', Z * H, '"', + ' coordorigin="0,0"' , + ' style="width:', W, 'px;height:', H, 'px;position:absolute;'); + + // If filters are necessary (rotation exists), create them + // filters are bog-slow, so only create them if abbsolutely necessary + // The following check doesn't account for skews (which don't exist + // in the canvas spec (yet) anyway. + + if (this.m_[0][0] != 1 || this.m_[0][1] || + this.m_[1][1] != 1 || this.m_[1][0]) { + var filter = []; + + // Note the 12/21 reversal + filter.push('M11=', this.m_[0][0], ',', + 'M12=', this.m_[1][0], ',', + 'M21=', this.m_[0][1], ',', + 'M22=', this.m_[1][1], ',', + 'Dx=', mr(d.x / Z), ',', + 'Dy=', mr(d.y / Z), ''); + + // Bounding box calculation (need to minimize displayed area so that + // filters don't waste time on unused pixels. + var max = d; + var c2 = getCoords(this, dx + dw, dy); + var c3 = getCoords(this, dx, dy + dh); + var c4 = getCoords(this, dx + dw, dy + dh); + + max.x = m.max(max.x, c2.x, c3.x, c4.x); + max.y = m.max(max.y, c2.y, c3.y, c4.y); + + vmlStr.push('padding:0 ', mr(max.x / Z), 'px ', mr(max.y / Z), + 'px 0;filter:progid:DXImageTransform.Microsoft.Matrix(', + filter.join(''), ", sizingmethod='clip');"); + + } else { + vmlStr.push('top:', mr(d.y / Z), 'px;left:', mr(d.x / Z), 'px;'); + } + + vmlStr.push(' ">' , + '<g_vml_:image src="', image.src, '"', + ' style="width:', Z * dw, 'px;', + ' height:', Z * dh, 'px"', + ' cropleft="', sx / w, '"', + ' croptop="', sy / h, '"', + ' cropright="', (w - sx - sw) / w, '"', + ' cropbottom="', (h - sy - sh) / h, '"', + ' />', + '</g_vml_:group>'); + + this.element_.insertAdjacentHTML('BeforeEnd', vmlStr.join('')); + }; + + contextPrototype.stroke = function(aFill) { + var lineStr = []; + var lineOpen = false; + + var W = 10; + var H = 10; + + lineStr.push('<g_vml_:shape', + ' filled="', !!aFill, '"', + ' style="position:absolute;width:', W, 'px;height:', H, 'px;"', + ' coordorigin="0,0"', + ' coordsize="', Z * W, ',', Z * H, '"', + ' stroked="', !aFill, '"', + ' path="'); + + var newSeq = false; + var min = {x: null, y: null}; + var max = {x: null, y: null}; + + for (var i = 0; i < this.currentPath_.length; i++) { + var p = this.currentPath_[i]; + var c; + + switch (p.type) { + case 'moveTo': + c = p; + lineStr.push(' m ', mr(p.x), ',', mr(p.y)); + break; + case 'lineTo': + lineStr.push(' l ', mr(p.x), ',', mr(p.y)); + break; + case 'close': + lineStr.push(' x '); + p = null; + break; + case 'bezierCurveTo': + lineStr.push(' c ', + mr(p.cp1x), ',', mr(p.cp1y), ',', + mr(p.cp2x), ',', mr(p.cp2y), ',', + mr(p.x), ',', mr(p.y)); + break; + case 'at': + case 'wa': + lineStr.push(' ', p.type, ' ', + mr(p.x - this.arcScaleX_ * p.radius), ',', + mr(p.y - this.arcScaleY_ * p.radius), ' ', + mr(p.x + this.arcScaleX_ * p.radius), ',', + mr(p.y + this.arcScaleY_ * p.radius), ' ', + mr(p.xStart), ',', mr(p.yStart), ' ', + mr(p.xEnd), ',', mr(p.yEnd)); + break; + } + + + // TODO: Following is broken for curves due to + // move to proper paths. + + // Figure out dimensions so we can do gradient fills + // properly + if (p) { + if (min.x == null || p.x < min.x) { + min.x = p.x; + } + if (max.x == null || p.x > max.x) { + max.x = p.x; + } + if (min.y == null || p.y < min.y) { + min.y = p.y; + } + if (max.y == null || p.y > max.y) { + max.y = p.y; + } + } + } + lineStr.push(' ">'); + + if (!aFill) { + appendStroke(this, lineStr); + } else { + appendFill(this, lineStr, min, max); + } + + lineStr.push('</g_vml_:shape>'); + + this.element_.insertAdjacentHTML('beforeEnd', lineStr.join('')); + }; + + function appendStroke(ctx, lineStr) { + var a = processStyle(ctx.strokeStyle); + var color = a.color; + var opacity = a.alpha * ctx.globalAlpha; + var lineWidth = ctx.lineScale_ * ctx.lineWidth; + + // VML cannot correctly render a line if the width is less than 1px. + // In that case, we dilute the color to make the line look thinner. + if (lineWidth < 1) { + opacity *= lineWidth; + } + + lineStr.push( + '<g_vml_:stroke', + ' opacity="', opacity, '"', + ' joinstyle="', ctx.lineJoin, '"', + ' miterlimit="', ctx.miterLimit, '"', + ' endcap="', processLineCap(ctx.lineCap), '"', + ' weight="', lineWidth, 'px"', + ' color="', color, '" />' + ); + } + + function appendFill(ctx, lineStr, min, max) { + var fillStyle = ctx.fillStyle; + var arcScaleX = ctx.arcScaleX_; + var arcScaleY = ctx.arcScaleY_; + var width = max.x - min.x; + var height = max.y - min.y; + if (fillStyle instanceof CanvasGradient_) { + // TODO: Gradients transformed with the transformation matrix. + var angle = 0; + var focus = {x: 0, y: 0}; + + // additional offset + var shift = 0; + // scale factor for offset + var expansion = 1; + + if (fillStyle.type_ == 'gradient') { + var x0 = fillStyle.x0_ / arcScaleX; + var y0 = fillStyle.y0_ / arcScaleY; + var x1 = fillStyle.x1_ / arcScaleX; + var y1 = fillStyle.y1_ / arcScaleY; + var p0 = getCoords(ctx, x0, y0); + var p1 = getCoords(ctx, x1, y1); + var dx = p1.x - p0.x; + var dy = p1.y - p0.y; + angle = Math.atan2(dx, dy) * 180 / Math.PI; + + // The angle should be a non-negative number. + if (angle < 0) { + angle += 360; + } + + // Very small angles produce an unexpected result because they are + // converted to a scientific notation string. + if (angle < 1e-6) { + angle = 0; + } + } else { + var p0 = getCoords(ctx, fillStyle.x0_, fillStyle.y0_); + focus = { + x: (p0.x - min.x) / width, + y: (p0.y - min.y) / height + }; + + width /= arcScaleX * Z; + height /= arcScaleY * Z; + var dimension = m.max(width, height); + shift = 2 * fillStyle.r0_ / dimension; + expansion = 2 * fillStyle.r1_ / dimension - shift; + } + + // We need to sort the color stops in ascending order by offset, + // otherwise IE won't interpret it correctly. + var stops = fillStyle.colors_; + stops.sort(function(cs1, cs2) { + return cs1.offset - cs2.offset; + }); + + var length = stops.length; + var color1 = stops[0].color; + var color2 = stops[length - 1].color; + var opacity1 = stops[0].alpha * ctx.globalAlpha; + var opacity2 = stops[length - 1].alpha * ctx.globalAlpha; + + var colors = []; + for (var i = 0; i < length; i++) { + var stop = stops[i]; + colors.push(stop.offset * expansion + shift + ' ' + stop.color); + } + + // When colors attribute is used, the meanings of opacity and o:opacity2 + // are reversed. + lineStr.push('<g_vml_:fill type="', fillStyle.type_, '"', + ' method="none" focus="100%"', + ' color="', color1, '"', + ' color2="', color2, '"', + ' colors="', colors.join(','), '"', + ' opacity="', opacity2, '"', + ' g_o_:opacity2="', opacity1, '"', + ' angle="', angle, '"', + ' focusposition="', focus.x, ',', focus.y, '" />'); + } else if (fillStyle instanceof CanvasPattern_) { + if (width && height) { + var deltaLeft = -min.x; + var deltaTop = -min.y; + lineStr.push('<g_vml_:fill', + ' position="', + deltaLeft / width * arcScaleX * arcScaleX, ',', + deltaTop / height * arcScaleY * arcScaleY, '"', + ' type="tile"', + // TODO: Figure out the correct size to fit the scale. + //' size="', w, 'px ', h, 'px"', + ' src="', fillStyle.src_, '" />'); + } + } else { + var a = processStyle(ctx.fillStyle); + var color = a.color; + var opacity = a.alpha * ctx.globalAlpha; + lineStr.push('<g_vml_:fill color="', color, '" opacity="', opacity, + '" />'); + } + } + + contextPrototype.fill = function() { + this.stroke(true); + }; + + contextPrototype.closePath = function() { + this.currentPath_.push({type: 'close'}); + }; + + function getCoords(ctx, aX, aY) { + var m = ctx.m_; + return { + x: Z * (aX * m[0][0] + aY * m[1][0] + m[2][0]) - Z2, + y: Z * (aX * m[0][1] + aY * m[1][1] + m[2][1]) - Z2 + }; + }; + + contextPrototype.save = function() { + var o = {}; + copyState(this, o); + this.aStack_.push(o); + this.mStack_.push(this.m_); + this.m_ = matrixMultiply(createMatrixIdentity(), this.m_); + }; + + contextPrototype.restore = function() { + if (this.aStack_.length) { + copyState(this.aStack_.pop(), this); + this.m_ = this.mStack_.pop(); + } + }; + + function matrixIsFinite(m) { + return isFinite(m[0][0]) && isFinite(m[0][1]) && + isFinite(m[1][0]) && isFinite(m[1][1]) && + isFinite(m[2][0]) && isFinite(m[2][1]); + } + + function setM(ctx, m, updateLineScale) { + if (!matrixIsFinite(m)) { + return; + } + ctx.m_ = m; + + if (updateLineScale) { + // Get the line scale. + // Determinant of this.m_ means how much the area is enlarged by the + // transformation. So its square root can be used as a scale factor + // for width. + var det = m[0][0] * m[1][1] - m[0][1] * m[1][0]; + ctx.lineScale_ = sqrt(abs(det)); + } + } + + contextPrototype.translate = function(aX, aY) { + var m1 = [ + [1, 0, 0], + [0, 1, 0], + [aX, aY, 1] + ]; + + setM(this, matrixMultiply(m1, this.m_), false); + }; + + contextPrototype.rotate = function(aRot) { + var c = mc(aRot); + var s = ms(aRot); + + var m1 = [ + [c, s, 0], + [-s, c, 0], + [0, 0, 1] + ]; + + setM(this, matrixMultiply(m1, this.m_), false); + }; + + contextPrototype.scale = function(aX, aY) { + this.arcScaleX_ *= aX; + this.arcScaleY_ *= aY; + var m1 = [ + [aX, 0, 0], + [0, aY, 0], + [0, 0, 1] + ]; + + setM(this, matrixMultiply(m1, this.m_), true); + }; + + contextPrototype.transform = function(m11, m12, m21, m22, dx, dy) { + var m1 = [ + [m11, m12, 0], + [m21, m22, 0], + [dx, dy, 1] + ]; + + setM(this, matrixMultiply(m1, this.m_), true); + }; + + contextPrototype.setTransform = function(m11, m12, m21, m22, dx, dy) { + var m = [ + [m11, m12, 0], + [m21, m22, 0], + [dx, dy, 1] + ]; + + setM(this, m, true); + }; + + /** + * The text drawing function. + * The maxWidth argument isn't taken in account, since no browser supports + * it yet. + */ + contextPrototype.drawText_ = function(text, x, y, maxWidth, stroke) { + var m = this.m_, + delta = 1000, + left = 0, + right = delta, + offset = {x: 0, y: 0}, + lineStr = []; + + var fontStyle = getComputedStyle(processFontStyle(this.font), + this.element_); + + var fontStyleString = buildStyle(fontStyle); + + var elementStyle = this.element_.currentStyle; + var textAlign = this.textAlign.toLowerCase(); + switch (textAlign) { + case 'left': + case 'center': + case 'right': + break; + case 'end': + textAlign = elementStyle.direction == 'ltr' ? 'right' : 'left'; + break; + case 'start': + textAlign = elementStyle.direction == 'rtl' ? 'right' : 'left'; + break; + default: + textAlign = 'left'; + } + + // 1.75 is an arbitrary number, as there is no info about the text baseline + switch (this.textBaseline) { + case 'hanging': + case 'top': + offset.y = fontStyle.size / 1.75; + break; + case 'middle': + break; + default: + case null: + case 'alphabetic': + case 'ideographic': + case 'bottom': + offset.y = -fontStyle.size / 2.25; + break; + } + + switch(textAlign) { + case 'right': + left = delta; + right = 0.05; + break; + case 'center': + left = right = delta / 2; + break; + } + + var d = getCoords(this, x + offset.x, y + offset.y); + + lineStr.push('<g_vml_:line from="', -left ,' 0" to="', right ,' 0.05" ', + ' coordsize="100 100" coordorigin="0 0"', + ' filled="', !stroke, '" stroked="', !!stroke, + '" style="position:absolute;width:1px;height:1px;">'); + + if (stroke) { + appendStroke(this, lineStr); + } else { + // TODO: Fix the min and max params. + appendFill(this, lineStr, {x: -left, y: 0}, + {x: right, y: fontStyle.size}); + } + + var skewM = m[0][0].toFixed(3) + ',' + m[1][0].toFixed(3) + ',' + + m[0][1].toFixed(3) + ',' + m[1][1].toFixed(3) + ',0,0'; + + var skewOffset = mr(d.x / Z) + ',' + mr(d.y / Z); + + lineStr.push('<g_vml_:skew on="t" matrix="', skewM ,'" ', + ' offset="', skewOffset, '" origin="', left ,' 0" />', + '<g_vml_:path textpathok="true" />', + '<g_vml_:textpath on="true" string="', + encodeHtmlAttribute(text), + '" style="v-text-align:', textAlign, + ';font:', encodeHtmlAttribute(fontStyleString), + '" /></g_vml_:line>'); + + this.element_.insertAdjacentHTML('beforeEnd', lineStr.join('')); + }; + + contextPrototype.fillText = function(text, x, y, maxWidth) { + this.drawText_(text, x, y, maxWidth, false); + }; + + contextPrototype.strokeText = function(text, x, y, maxWidth) { + this.drawText_(text, x, y, maxWidth, true); + }; + + contextPrototype.measureText = function(text) { + if (!this.textMeasureEl_) { + var s = '<span style="position:absolute;' + + 'top:-20000px;left:0;padding:0;margin:0;border:none;' + + 'white-space:pre;"></span>'; + this.element_.insertAdjacentHTML('beforeEnd', s); + this.textMeasureEl_ = this.element_.lastChild; + } + var doc = this.element_.ownerDocument; + this.textMeasureEl_.innerHTML = ''; + this.textMeasureEl_.style.font = this.font; + // Don't use innerHTML or innerText because they allow markup/whitespace. + this.textMeasureEl_.appendChild(doc.createTextNode(text)); + return {width: this.textMeasureEl_.offsetWidth}; + }; + + /******** STUBS ********/ + contextPrototype.clip = function() { + // TODO: Implement + }; + + contextPrototype.arcTo = function() { + // TODO: Implement + }; + + contextPrototype.createPattern = function(image, repetition) { + return new CanvasPattern_(image, repetition); + }; + + // Gradient / Pattern Stubs + function CanvasGradient_(aType) { + this.type_ = aType; + this.x0_ = 0; + this.y0_ = 0; + this.r0_ = 0; + this.x1_ = 0; + this.y1_ = 0; + this.r1_ = 0; + this.colors_ = []; + } + + CanvasGradient_.prototype.addColorStop = function(aOffset, aColor) { + aColor = processStyle(aColor); + this.colors_.push({offset: aOffset, + color: aColor.color, + alpha: aColor.alpha}); + }; + + function CanvasPattern_(image, repetition) { + assertImageIsValid(image); + switch (repetition) { + case 'repeat': + case null: + case '': + this.repetition_ = 'repeat'; + break + case 'repeat-x': + case 'repeat-y': + case 'no-repeat': + this.repetition_ = repetition; + break; + default: + throwException('SYNTAX_ERR'); + } + + this.src_ = image.src; + this.width_ = image.width; + this.height_ = image.height; + } + + function throwException(s) { + throw new DOMException_(s); + } + + function assertImageIsValid(img) { + if (!img || img.nodeType != 1 || img.tagName != 'IMG') { + throwException('TYPE_MISMATCH_ERR'); + } + if (img.readyState != 'complete') { + throwException('INVALID_STATE_ERR'); + } + } + + function DOMException_(s) { + this.code = this[s]; + this.message = s +': DOM Exception ' + this.code; + } + var p = DOMException_.prototype = new Error; + p.INDEX_SIZE_ERR = 1; + p.DOMSTRING_SIZE_ERR = 2; + p.HIERARCHY_REQUEST_ERR = 3; + p.WRONG_DOCUMENT_ERR = 4; + p.INVALID_CHARACTER_ERR = 5; + p.NO_DATA_ALLOWED_ERR = 6; + p.NO_MODIFICATION_ALLOWED_ERR = 7; + p.NOT_FOUND_ERR = 8; + p.NOT_SUPPORTED_ERR = 9; + p.INUSE_ATTRIBUTE_ERR = 10; + p.INVALID_STATE_ERR = 11; + p.SYNTAX_ERR = 12; + p.INVALID_MODIFICATION_ERR = 13; + p.NAMESPACE_ERR = 14; + p.INVALID_ACCESS_ERR = 15; + p.VALIDATION_ERR = 16; + p.TYPE_MISMATCH_ERR = 17; + + // set up externs + G_vmlCanvasManager = G_vmlCanvasManager_; + CanvasRenderingContext2D = CanvasRenderingContext2D_; + CanvasGradient = CanvasGradient_; + CanvasPattern = CanvasPattern_; + DOMException = DOMException_; +})(); + +} // if diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js new file mode 100644 index 0000000000..4c24b44dbb --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qmf-ui/scripts/qmf-ui.js @@ -0,0 +1,3333 @@ +/* + * + * 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. + * + */ + +/** + * + * This program implements the QMF Console User Interface logic for qmf.html + * + * It has dependencies on the following: + * qmf.css + * itablet.css + * iscroll.js + * jquery.js (jquery-1.7.1.min.js) + * itablet.js + * excanvas.js (for IE < 9 only) + * qpid.js + * + * author Fraser Adams + */ + +//------------------------------------------------------------------------------------------------------------------- + +// Create a new namespace for the qmfui "package". +var qmfui = {}; +qmfui.TOUCH_ENABLED = 'ontouchstart' in window && !((/hp-tablet/gi).test(navigator.appVersion)); +qmfui.END_EV = (qmfui.TOUCH_ENABLED) ? "touchend" : "mouseup"; + +//------------------------------------------------------------------------------------------------------------------- + +/** + * This class holds the history of various key statistics that may be held for some QMF + * Management Objects so we may see how the state has changes over a particular time range. + */ +qmfui.Statistics = function(description) { + this.description = description; // Array describing the contents of each stored statistic + this.short = new util.RingBuffer(60); // Statistics for a 10 minute period (10*60/REFRESH_PERIOD) + this.medium = new util.RingBuffer(60); // Statistics for a 1 hour period (Entries are updated every minute) + this.long = new util.RingBuffer(144); // Statistics for a 1 day period (Entries are updated every 10 minutes) + + /** + * Add an item to the end of each statistic buffer. + * @param item an array containing the current statistics for each property that we want to hold for a + * Management Object, the last item in the array is the Management Object's update timestamp. + * As an example for the connection Management Object we would do: + * stats.put([connection.msgsFromClient, connection.msgsToClient, connection._update_ts]); + * This approach is a little ugly and not terribly OO, but it's pretty memory efficient, which is + * important as there could be lots of Management Objects on a heavily utilised broker. + */ + this.put = function(item) { + var TIMESTAMP = item.length - 1; // The timestamp is stored as the last item of each sample. + var timestamp = item[TIMESTAMP]; + + var lastItem = this.short.getLast(); + if (lastItem == null) { + this.short.put(item); // Update the 10 minute period statistics. + } else { + var lastTimestamp = lastItem[TIMESTAMP]; + // 9000000000 is 9 seconds in nanoseconds. If the time delta is less than 9 seconds we hold off adding + // the sample otherwise the ring buffer will end up holding less than the full 10 minutes worth. + if ((timestamp - lastTimestamp) >= 9000000000) { + this.short.put(item); // Update the 10 minute period statistics. + } + } + + var lastItem = this.medium.getLast(); + if (lastItem == null) { + this.medium.put(item); // Update the 1 hour period statistics. + } else { + var lastTimestamp = lastItem[TIMESTAMP]; + // 59000000000 is 59 seconds in nanoseconds. We use 59 seconds rather than 60 seconds because the + // update period has a modest +/i variance around 10 seconds. + if ((timestamp - lastTimestamp) >= 59000000000) { + this.medium.put(item); // Update the 1 hour period statistics. + } + } + + lastItem = this.long.getLast(); + if (lastItem == null) { + this.long.put(item); // Update the 1 day period statistics. + } else { + var lastTimestamp = lastItem[TIMESTAMP]; + // 599000000000 is 599 seconds in nanoseconds (just short of 10 minutes). We use 599 seconds rather + // than 600 seconds because the update period has a modest +/ variance around 10 seconds. + if ((timestamp - lastTimestamp) >= 599000000000) { + this.long.put(item); // Update the 1 day period statistics. + } + } + }; + + /** + * This method computes the most recent instantaneous rate for the property specified by the index. + * For example for the Connection Management Object an index of 1 would represent msgsToClient as + * described in the comments for put(). Note that the rate that is returned is the most recent + * instantaneous rate, which means that it uses the samples held in the ring buffer used to hold + * the ten minute window. + * @param the index of the property that we wish to obtain the rate for. + * @return the most recent intantaneous rate in items/s + */ + this.getRate = function(index) { + var size = this.short.size(); + if (size < 2) { + return 0; + } + + var s1 = this.short.get(size - 2); + var t1 = s1[s1.length - 1]; + + var s2 = this.short.get(size - 1); + var t2 = s2[s2.length - 1]; + + var delta = (t2 == t1) ? 0.0000001 : t2 - t1; // Shouldn't happen, but this tries to avoid divide by zero. + var rate = ((s2[index] - s1[index]) * 1000000000)/delta + return rate; + }; +}; + +//------------------------------------------------------------------------------------------------------------------- +// Helper Methods to provide a consistent way to render the UI lists. +//------------------------------------------------------------------------------------------------------------------- + +/** + * This helper method renders the specified properties of the specifed JavaScript object to the specified html list. + * @param list jQuery object representing the html list (ul) we wish to populate. + * @param object the object whose properties we wish to render. + * @param props an array of properties that we wish to render. + * @param href optional string specifying URL fragment to e.g. "#graphs?connectionId=" + connectionId. + */ +qmfui.renderObject = function(list, object, props, href, useIndex) { + iTablet.renderList(list, function(i) { + var key = props[i]; + var value = object[key]; + if (value == null) { // Only show properties that are actually available. + return false; + } else { + if (href) { + var anchor = href + "&property=" + i; + return "<li class='arrow'><a href='" + anchor + "'>" + key + "<p>" + value + "</p></a></li>"; + } else { + return "<li><a href='#'>" + key + "<p>" + value + "</p></a></li>"; + } + } + }, props.length); +}; + +/** + * This helper method renders the specified list of html list items (li) to the specified html list. + * @param list jQuery object representing the html list (ul) we wish to populate. + * @param array the array of html list items (li) that we wish to render. + */ +qmfui.renderArray = function(list, array) { + iTablet.renderList(list, function(i) { + return array[i]; + }, array.length); +}; + +//------------------------------------------------------------------------------------------------------------------- +// Main Console Class +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the main Console class. + * This class contains the QMF Console and and caches the core QMF management objects. Caching the getObjects() + * results is obviously sensible and helps avoid the temptation to call getObjects() elsewhere which is rather + * inefficient as it is invoked using AMQP request/response but morever in the case of this UI is is called via + * a REST proxy. Caching getObjects() calls also helps to abstract the asynchronous nature of JavaScript as the + * cache methods can be called synchronously which "feels" a more natural way to get the data. + * + * This class is also responsible for initialising the rest of the pages when jQuery.ready() fires and updating + * them when QMF object updates occur, in other words it might be considered "Main". + * + * This class handles the QMF Console Connection lifecycle management. It's worth pointing out that it's fairly + * subtle and complex particularly due to the asynchronous nature of JavaScript. It's made even more complex + * by the fact that there are two distinct ways used to decide when to get the QMF Management Objects. The default + * way is where QMF Event delivery is enabled, in this case the onEvent() method is triggered periodically by + * the underlying QMF Console's Event dispatcher and in this case the Event dispatcher takes care of reconnection + * attempts. However if disableEvents is selected then the QMF Management Objects are retrieved via a timed + * poll. In this case this method must correctly start the pollForData() but must also let it expire if the user + * selects a new Connection that has QMF Event deliver enabled. + */ +qmfui.Console = new function() { + /** + * This is an array of QMF Console Connections that the user is interested in. It gets initiated with the + * default connection (that is to say the connection that the REST API has been configured to use if no + * explicit URL has been supplied). Using a Connection URL of "" makes the REST API use its default. + * This property has been exposed as a "public" property of qmfui.Console because then it becomes possible + * to "configure" the initial set of consoleConnections via a trivial config.js file containing: + * qmfui.Console.consoleConnections = [{name: "default", url: ""},{name: "wildcard", url: "0.0.0.0:5672", + * connectionOptions: {sasl_mechs:"ANONYMOUS"}, disableEvents: true}]; + * i.e. a JSON array of Console Connection settings. + */ + this.consoleConnections = [{name: "default", url: ""}]; + + var _objects = {}; // A map used to cache the QMF Management Object lists returned by getObjects(). + var _disableEvents = false; // Set for Connections that have Events disabled and thus refresh via timed polling. + var _polling = false; // Set when the timed polling is active so we can avoid starting it multiple times. + var _receivedData = false; // This flag is used to tell the difference between a failure to connect and a disconnect. + var _console = null; // The QMF Console used to retrieve information from the broker. + var _connection = null; + var _activeConsoleConnection = 0; // The index of the currently active QMF Console Connection. + + /** + * Resets the messages that get rendered if the REST API Server or the Qpid broker fail. + */ + var resetErrorMessages = function() { + $("#restapi-disconnected").hide(); + $("#broker-disconnected").hide(); + $("#failed-to-connect").hide(); + }; + + /** + * Show Rest API Disconnected Message, hide the others. + */ + var showRestAPIDisconnected = function() { + resetErrorMessages(); + $("#restapi-disconnected").show(); + }; + + /** + * Show Broker Disconnected Message, hide the others. + */ + var showBrokerDisconnected = function() { + resetErrorMessages(); + $("#broker-disconnected").show(); + }; + + /** + * Show Failed to Connect Message, hide the others. + */ + var showFailedToConnect = function() { + resetErrorMessages(); + $("#failed-to-connect").show(); + }; + + /** + * QMF2 EventHandler that we register with the QMF2 Console. + * @param workItem a QMF2 API WorkItem. + */ + var onEvent = function(workItem) { + if (workItem._type == "AGENT_DELETED") { + var agent = workItem._params.agent; + + if (agent._product == "qpidd" && _connection != null) { + if (_receivedData) { + showBrokerDisconnected(); + } else { + showFailedToConnect(); + } + } else if (agent._product == "qpid.restapi") { + showRestAPIDisconnected(); + } + } else { + _receivedData = true; + resetErrorMessages(); + if (workItem._type == "EVENT_RECEIVED") { + qmfui.Events.update(workItem); + } + } + + // onEvent() will be called periodically by the broker heartbeat events, so we use that fact to trigger + // a call to getAllObjects() which will itself trigger a call to updateState() when its results return. + getAllObjects(); + }; + + /** + * This method is called if startConsole() has been called with disableEvents. In this state + * the onEvent() method won't be triggered by the QMF2 callback so we need to explicitly poll via a timer. + */ + var pollForData = function() { + if (_connection != null && _disableEvents) { + _polling = true; + getAllObjects(); + setTimeout(function() { + pollForData(); + }, qmf.REFRESH_PERIOD); + } else { + _polling = false; + } + }; + + /** + * This method is called by the failure handler of getAllObjects(). If it is triggered it means there has + * been some form of Server side disconnection. If this occurs set an error banner then attempt to re-open + * the Qpid Connection. If the Connection reopens successfully updateState() will start getting called again. + * This method returns immediately if _disableEvents is false because the underlying QMF Console has its own + * reconnection logic in its Event dispatcher, which we only need to replicate if that is disabled. + * @param xhr the jQuery XHR object. + */ + var timeout = function(xhr) { + if (_disableEvents) { + if (xhr.status == 0) { + showRestAPIDisconnected(); + } else { + if (_receivedData) { + showBrokerDisconnected(); + } else { + showFailedToConnect(); + } + if (xhr.status == 404 && _connection != null && _connection.open) { + _connection.open(); + } + } + } + }; + + /** + * This method is called when getAllObjects() completes, that is to say when all of the asynchronous responses + * for the Deferred XHR objects returned by getObjects() have all returned successfully. This method triggers + * the update() method on each of the user interface pages. + */ + var updateState = function() { + _receivedData = true; + resetErrorMessages(); + + qmfui.Broker.update(); + qmfui.Connections.update(); + qmfui.Exchanges.update(); + qmfui.Queues.update(); + //qmfui.Links.update(); // TODO + //qmfui.RouteTopology.update(); // TODO + + // Update sub-pages after main pages as these may require state (such as statistics) set in the main pages. + qmfui.SelectedConnection.update(); + qmfui.SelectedQueue.update(); + qmfui.QueueSubscriptions.update(); + qmfui.ConnectionSubscriptions.update(); + qmfui.SelectedExchange.update(); + qmfui.Bindings.update(); + qmfui.Graphs.update(); + }; + + /** + * This method retrieves the QmfConsoleData Objects from the real QMF Console via AJAX calls to the REST API. + * Because the AJAX calls are all asynchronous we use jQuery.when(), which provides a way to execute callback + * functions based on one or more objects, usually Deferred objects that represent asynchronous events. + * See http://api.jquery.com/jQuery.when/ and http://api.jquery.com/deferred.then/ + */ + var getAllObjects = function() { + $.when( + _console.getObjects("broker", function(data) {_objects.broker = data;}), + _console.getObjects("queue", function(data) {_objects.queue = data;}), + _console.getObjects("exchange", function(data) {_objects.exchange = data;}), + _console.getObjects("binding", function(data) {_objects.binding = data;}), + _console.getObjects("subscription", function(data) {_objects.subscription = data;}), + _console.getObjects("connection", function(data) {_objects.connection = data;}), +// _console.getObjects("link", function(data) {_objects.link = data;}), +// _console.getObjects("bridge", function(data) {_objects.bridge = data;}), + _console.getObjects("session", function(data) {_objects.session = data;}) + ).then(updateState, timeout); + }; + + /** + * Handle the load event, triggered when the document has completely loaded. + */ + var loadHandler = function() { + qmfui.Console.startConsole(0); // Start the default QMF Console Connection. + }; + + /** + * Handle the unload event, triggered when the document unloads or we navigate off the page. It's not 100% + * reliable, which is a shame as it's the best way to clear up Server state. If it fails the Server will + * eventually clear up unused Connections after a timeout period. TODO Opera seems to be especially bad at + * firing the unloadHandler, not sure why this is, something to look into. + * @param event the event that triggered the unloadHandler. + */ + var unloadHandler = function(event) { + // For mobile Safari (at least) we get pagehide events when navigating off the page, but also when closing via + // home or locking the device. Fortunately this case has the persisted flag set as we don't want to close then. + var persisted = (event.type == "pagehide") ? event.originalEvent.persisted : false; + if (!persisted) { + qmfui.Console.stopConsole(); + } + }; + + /** + * Callback handler triggered when _console.addConnection() fails. This should only occur if an actual + * exception occurs on the REST API Server due to invalid connectionOptions. + */ + var handleConnectionFailure = function() { + qmfui.Console.stopConsole(); + showFailedToConnect(); + } + + // ******************************************* Accessor Methods ******************************************* + + /** + * Retrieve the broker Management Object, optionally as a QmfConsoleData Object (with invokeMethod attached). + * @param makeConsoleData if true attach the invokeMethod method to the returned Management Object. + * @return the QMF broker Management Object optionally as a QmfConsoleData. + */ + this.getBroker = function(makeConsoleData) { + var brokers = _objects.broker; + + if (brokers == null || brokers.length == 0) { + // Return a fake QmfConsoleData Object with an invokeMethod that calls the callback handler with a + // response object containing error_text. It is actually pretty uncommon for the brokers array to + // be empty so this approach allows us to call invokeMethod without lots of checking for broker == null. + return {invokeMethod: function(name, inArgs, handler) { + handler({"error_text" : "Could not retrieve broker Management Object"}); + }}; + } else { + var broker = brokers[0]; + if (makeConsoleData) { + _console.makeConsoleData(broker); + } + return broker; + } + }; + + /** + * These methods are basic accessors returning the cached lists of QmfData objects returned by getObjects() + */ + this.getQueues = function() { + return _objects.queue; + }; + + this.getExchanges = function() { + return _objects.exchange; + }; + + this.getBindings = function() { + return _objects.binding; + }; + + this.getSubscriptions = function() { + return _objects.subscription; + }; + + this.getConnections = function() { + return _objects.connection; + }; + + this.getSessions = function() { + return _objects.session; + }; + +/* TODO + this.getLinks = function() { + return _objects.link; + }; + + this.getBridges = function() { + return _objects.bridge; + }; +*/ + + /** + * Calls the underlying QMF Console's makeConsoleData(). This call turns a QmfData object into a QmfConsoleData + * object, which adds methods such as invokeMethod() to the object. + * @param the object that we want to turn into a QmfConsoleData. + */ + this.makeConsoleData = function(object) { + _console.makeConsoleData(object); + }; + + /** + * @return the list of QMF Console Connections that the user is interested in. The returned list is a list of + * objects containing url, name and connectionOptions properties. + */ + this.getConsoleConnectionList = function() { + return this.consoleConnections; + }; + + /** + * Note that in the following it's important to note that there is separation between adding/removing + * Console Connections and actually starting/stopping Console Connections, this is because a user may wish + * to add several QMF Console Connections to point to a number of different brokers before actually + * chosing to connect to a particular broker. Similarly a user may wish to delete a QMF Console Connection + * from the list (s)he is interested in independently from selecting a new connection. + */ + + /** + * Append a new Console Connection with the specified url, name and connectionOptions to the end of the + * list of QMF Console Connections the the user many be interested in. Note that this method *does not* + * actually start a connection to the new console for that we must call the startConsole() method. + * The name supplied in this method is simply a user friendly name and is not related to the name that + * may be applied to the Connection when it is stored on the REST API, that name is really best considered + * as an opaque "handle" and is intended to be unique for each connection. + * + * @param name a user friendly name for the Console Connection. + * @param url the broker Connection URL in one of the formats supported by the Java ConnectionHelper class + * namely an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL. + * @param connectionOptions a JSON string containing the Connection Options in the same form as used + * in the qpid::messaging API. + */ + this.addConsoleConnection = function(name, url, connectionOptions, disableEvents) { + if (disableEvents) { + this.consoleConnections.push({name: name, url: url, connectionOptions: connectionOptions, + disableEvents: true}); + } else { + this.consoleConnections.push({name: name, url: url, connectionOptions: connectionOptions}); + } + }; + + /** + * Remove the Console Connection specified by the index. Note that this method *does not* actually stop + * a connection to the console for that we must call the stopConsole() method. + * @param index the index of the Console Connection that we want to remove. + */ + this.removeConsoleConnection = function(index) { + if (_activeConsoleConnection > index) { + _activeConsoleConnection--; + } + this.consoleConnections.splice(index, 1); // remove a single array item at the specified index. + }; + + /** + * Actually start the Qpid Connection and QMF Console for the Console Connection stored at the specified index. + * When the QMF Console successfully starts it will start sending QMF Events and updating the Management + * Objects automatically, this will in turn cause the User Interface pages to refresh. + * Alternatively if QMF Event delivery is disabled this method initiates the pollForData(). + * @param index the index of the Console Connection that we wish to start. Index zero is the default Console. + */ + this.startConsole = function(index) { + var connection = this.consoleConnections[index]; + + // Using a Connection URL of "" makes the REST API use its default configured broker connection. + var factory = new qpid.ConnectionFactory(connection.url, connection.connectionOptions); + _connection = factory.createConnection(); + + // Initialise QMF Console + _console = new qmf.Console(onEvent); + if (connection.disableEvents != null) { + _disableEvents = true; + _console.disableEvents(); + } else { + _disableEvents = false; + } + + _receivedData = false; + _console.addConnection(_connection, handleConnectionFailure); + _activeConsoleConnection = index; + + // If disableEvents is set we have to use a timed poll to get the Management Objects. We check if the polling + // loop is already running, because if we try and start it multiple times we may get spurious refreshes. + if (_disableEvents && !_polling) { + pollForData(); + } + }; + + /** + * Stops the currently running Console Connection and closes the Qpid Connection. This will result in the + * underlying Connection object on the REST API Server getting properly cleaned up. It's not essential + * to call stopConsole() before a call to startConsole() as the server Connection objects will eventually + * time out, but it's good practice to do it if at all possible. + */ + this.stopConsole = function() { + if (_console) { + _console.destroy(); + } + + if (_connection) { + _connection.close(); + _connection = null; + } + }; + + /** + * @return the index of the currently active (connected) QMF Console Connection. + */ + this.getActiveConsoleConnection = function() { + return _activeConsoleConnection; + }; + + // *********************** Initialise class when the DOM loads using jQuery.ready() *********************** + $(function() { + // Create a fake logging console for browsers that don't have a real console.log - only for debugging. + if (!window.console) { + /* // A slightly hacky console.log() to help with debugging on old versions of IE. + console = window.open("", "console", "toolbar, menubar, status, width=500, height=500, scrollbars=yes"); + console.document.open("text/plain"); + console.log = function(text) {console.document.writeln(text);};*/ + + console = {log: function(text) {}}; // Dummy to avoid bad references in case logging accidentally added. + } + + // Add a default show handler. Pages that bind update() to show should remove this by doing unbind("show"). + $(".main").bind("show", function() {$("#resource-deleted").hide();}); + + // pagehide and unload each work better than the other in certain circumstances so we trigger on both. + $(window).bind("unload pagehide", unloadHandler); + + // Iterate through each page calling its initialise method if one is present. + for (var i in qmfui) { + if (qmfui[i].initialise) { + qmfui[i].initialise(); + } + } + + // Send a synthesised click event to the settings-tab element to select the settings page on startup. + // We check if the left property of the main class is zero, if it is then the sidebar has been expanded + // to become the main menu (e.g. for mobile devices) otherwise we show the settings page. + if (parseInt($(".main").css('left'), 10) != 0) { + $("#settings-tab").click(); + } + + // Hide the splash page. + $("#splash").hide(); + }); + + $(window).load(loadHandler); +}; // End of qmfui.Console definition + + +//------------------------------------------------------------------------------------------------------------------- +// Configure Settings +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Settings class managing the id="settings" page. + */ +qmfui.Settings = new function() { + /** + * Show the Settings page, rendering any dynamic content if necessary. + */ + var show = function() { + // Retrieve the currently configured QMF Console Connections. + var qmfConsoleConnections = qmfui.Console.getConsoleConnectionList(); + + iTablet.renderList($("#qmf-console-selector"), function(i) { + var qmfConsoleConnection = qmfConsoleConnections[i]; + var name = qmfConsoleConnection.name; + var url = qmfConsoleConnection.url; + url = (url == null || url == "") ? "" : " (" + url + ")"; + var label = (name == null || name == "") ? url : name + url; + var checked = (i == qmfui.Console.getActiveConsoleConnection()) ? "checked" : ""; + + return "<li class='arrow'><label for='qmf-console" + i + "'>" + label + "</label><input type='radio' id='qmf-console" + i + "' name='qmf-console-selector' value='" + i + "' " + checked + "/><a href='#selected-qmf-console-connection?index=" + i + "'></a></li>"; + }, qmfConsoleConnections.length); + + $("#qmf-console-selector input").change(changeConsole); + }; + + /** + * If the settings-hide-qmf-objects checkbox gets changed refresh the Queues and Exchanges pages to reflect this. + */ + var changeHideQmf = function() { + qmfui.Queues.update(); + qmfui.Exchanges.update(); + }; + + /** + * Handles changes to the Console selection Radio buttons. If a change occurs the Console Connection is stopped + * and the newly selected Console Connection is started (we chose based on the index into the list) + */ + var changeConsole = function() { + qmfui.Console.stopConsole(); + qmfui.Console.startConsole($(this).val()); + }; + + this.initialise = function() { + $("#settings").bind("show", show); + $("#settings-hide-qmf-objects").change(changeHideQmf); + }; +}; // End of qmfui.Settings definition + + +/** + * Create a Singleton instance of the AddConsoleConnection class managing the id="add-console-connection" page. + */ +qmfui.AddConsoleConnection = new function() { + var submit = function() { + var consoleURL = $("#console-url"); + + // Check that a URL value has been supplied. TODO Probably worth doing some validation that the supplied + // Connection URL is at least syntactically valid too. + var url = consoleURL.val(); + if (url == "") { + consoleURL.addClass("error"); + return; + } else { + consoleURL.removeClass("error"); + } + + var name = $("#console-name").val(); + try { + var connectionOptions = $.parseJSON($("#add-connection-options textarea").val()); + // TODO worth checking that the connection options are valid and in a usable format. Connection Options + // is still a bit of a work in progressed. though it seems to work fine if sensible options are used. + qmfui.Console.addConsoleConnection(name, url, connectionOptions, $("#console-disable-events")[0].checked); + iTablet.location.back(); + } catch(e) { + setTimeout(function() { + alert("Connection Options must be entered as a well-formed JSON string."); + return; + }, 0); + } + }; + + this.initialise = function() { + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#add-console-connection .right.button").bind(qmfui.END_EV, submit); + }; +}; // End of qmfui.AddConsoleConnection definition + + +/** + * Create a Singleton instance of the SelectedQMFConsoleConnection class managing the + * id="selected-qmf-console-connection" page. + */ +qmfui.SelectedQMFConsoleConnection = new function() { + var _index = null; + var _name = ""; + var _url = ""; + + /** + * This method deletes the selected QMFConsoleConnection. + */ + var deleteHandler = function() { + // Flag to check if the Console we're trying to delete is the currently selected/connected one. + var currentlySelected = ($("#qmf-console-selector input[checked]").val() == _index); + + // Text for the confirm dialogue with additional wording if it's currently connected. + var confirmText = 'Delete QMF Connection "' + _name + '" to ' + _url + '?'; + confirmText += currentlySelected ? "\nNote that this is the current active Connection, so deleting it will cause a reconnection to the default Connection." : "" + + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + setTimeout(function() { + if (confirm(confirmText) == false) { + return; + } else { + qmfui.Console.removeConsoleConnection(_index); + // If the QMF Console Connection being deleted is the currently connected one we stop the Console + // and establish a connection to the default QMF Console Connection. + if (currentlySelected) { + qmfui.Console.stopConsole(); + qmfui.Console.startConsole(0); // Start the default QMF Console Connection. + } + + iTablet.location.back(); // Navigate to the previous page. + } + }, 0); + }; + + var show = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#selected-qmf-console-connection") { + return; + } + + // Get the selected QMFConsoleConnection + _index = parseInt(data.index); // The parseInt is important! Without it the index lookup gives odd results.. + var qmfConsoleConnections = qmfui.Console.getConsoleConnectionList(); + var qmfConsoleConnection = qmfConsoleConnections[_index]; + _name = qmfConsoleConnection.name; + _url = qmfConsoleConnection.url; + var connectionOptions = qmfConsoleConnection.connectionOptions; + + var eventsDisabled = false; + if (qmfConsoleConnection.disableEvents != null) { + eventsDisabled = qmfConsoleConnection.disableEvents; + } + + // If the selected Console is the default one hide the delete button, otherwise show it. + if (_index == 0) { + $("#selected-qmf-console-connection .header a.delete").hide(); + } else { + $("#selected-qmf-console-connection .header a.delete").show(); + } + + // Populate the page header with the Console Connection name/url. + var urlText = (_url == null || _url == "") ? "" : " (" + _url + ")"; + var label = (_name == null || _name == "") ? urlText : _name + urlText; + $("#selected-qmf-console-connection .header h1").text(label); + + $("#selected-qmf-console-connection-url p").text(((_url == "") ? 'default' : _url)); + $("#selected-qmf-console-connection-name p").text(((_name == "") ? '""' : _name)); + $("#selected-qmf-console-connection-events-disabled p").text(eventsDisabled); + + if (_url == "") { + $("#selected-qmf-console-connection-default-info").show(); + } else { + $("#selected-qmf-console-connection-default-info").hide(); + } + + if (connectionOptions == "") { + $("#selected-qmf-console-connection-connection-options").hide(); + } else { + $("#selected-qmf-console-connection-connection-options textarea").val(util.stringify(connectionOptions)); + $("#selected-qmf-console-connection-connection-options").show(); + } + }; + + this.initialise = function() { + $("#selected-qmf-console-connection").unbind("show").bind("show", show); + + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#selected-qmf-console-connection .header a.delete").bind(qmfui.END_EV, deleteHandler); + }; +}; // End of qmfui.SelectedQMFConsoleConnection definition + + +//------------------------------------------------------------------------------------------------------------------- +// Broker Information +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Broker class managing the id="broker" page. + */ +qmfui.Broker = new function() { + /** + * Convert nanoseconds into hours, minutes and seconds. + */ + var convertTime = function(ns) { + var milliSecs = ns/1000000; + var msSecs = (1000); + var msMins = (msSecs * 60); + var msHours = (msMins * 60); + var numHours = Math.floor(milliSecs/msHours); + var numMins = Math.floor((milliSecs - (numHours * msHours)) / msMins); + var numSecs = Math.floor((milliSecs - (numHours * msHours) - (numMins * msMins))/ msSecs); + numSecs = numSecs < 10 ? numSecs = "0" + numSecs : numSecs; + numMins = numMins < 10 ? numMins = "0" + numMins : numMins; + + return (numHours + ":" + numMins + ":" + numSecs); + }; + + this.update = function() { + var broker = qmfui.Console.getBroker(); + broker.uptime = convertTime(broker.uptime); // Convert uptime to a more human readable value. + + qmfui.renderObject($("#broker-list"), broker, ["name", "version", "uptime", "port", "maxConns", "connBacklog", + "dataDir", "mgmtPublish", "mgmtPubInterval", "workerThreads", + /* 0.20 publishes many more stats so include them if available */ + "queueCount", "acquires", "releases", "abandoned", "abandonedViaAlt"]); + + // Render a number of 0.20 statistics in their own subsections to improve readability. + + // Render the Message Input Output Statistics. + if (broker.msgDepth == null) { + $("#broker-msgio-container").hide(); + } else { + $("#broker-msgio-container").show(); + qmfui.renderObject($("#broker-msgio"), broker, ["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"]); + } + + // Render the Byte Input Output Statistics. + if (broker.byteDepth == null) { + $("#broker-byteio-container").hide(); + } else { + $("#broker-byteio-container").show(); + qmfui.renderObject($("#broker-byteio"), broker, ["byteDepth", "byteTotalEnqueues", "byteTotalDequeues"]); + } + + var hideDetails = $("#settings-hide-details")[0].checked; + + // Render the Flow-to-disk Statistics. + if (broker.msgFtdDepth == null || hideDetails) { + $("#broker-flow-to-disk-container").hide(); + } else { + $("#broker-flow-to-disk-container").show(); + qmfui.renderObject($("#broker-flow-to-disk"), broker, ["msgFtdDepth", "msgFtdEnqueues", "msgFtdDequeues", + "byteFtdDepth", "byteFtdEnqueues", "byteFtdDequeues"]); + } + + // Render the Dequeue Details. + if (broker.discardsTtl == null || hideDetails) { + $("#broker-dequeue-container").hide(); + } else { + $("#broker-dequeue-container").show(); + qmfui.renderObject($("#broker-dequeue"), broker, ["discardsTtl", "discardsRing", "discardsLvq", + "discardsOverflow", "discardsSubscriber", "discardsPurge", "reroutes"]); + } + }; + + /** + * This click handler is triggered by a click on the broker-log-level radio button. It invokes the QMF + * setLogLevel method to set the log level of the connected broker to debug or normal. + */ + var setLogLevel = function(e) { + var level = $(e.target).val(); + + // Set to the QMF2 levels for broker debug and normal. + level = (level == "debug") ? "debug+:Broker" : "notice+"; + + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("setLogLevel", {"level": level}, function(data) { + if (data.error_text) { + alert(data.error_text); + } + }); + }; + + this.initialise = function() { + // Explicitly using a click handler rather than change as it's possible that another instance has changed + // the log level so we may want to be able to reset it by clicking the currently selected level. + $("#broker-log-level li input").click(setLogLevel); + }; +}; // End of qmfui.Broker definition + + +//------------------------------------------------------------------------------------------------------------------- +// Connection Information +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Connections class managing the id="connections" page. + */ +qmfui.Connections = new function() { + var _connectionMap = {}; // Connections indexed by ObjectId. + var _sessionMap = {}; // Sessions indexed by ObjectId. + var _subscriptionMap = {}; // Subscriptions indexed by ObjectId. + var _queueToSubscriptionAssociations = {}; // 0..* association between Queue and Subscription keyed by Queue ID. + + /** + * Return the Connection object indexed by QMF ObjectId. + */ + this.getConnection = function(oid) { + return _connectionMap[oid]; + }; + + /** + * Return the Session object indexed by QMF ObjectId. + */ + this.getSession = function(oid) { + return _sessionMap[oid]; + }; + + /** + * Return the Subscription object indexed by QMF ObjectId. + */ + this.getSubscription = function(oid) { + return _subscriptionMap[oid]; + }; + + /** + * Return the Subscription association List indexed by a queue's QMF ObjectId. + */ + this.getQueueSubscriptions = function(oid) { + var subs = _queueToSubscriptionAssociations[oid]; + return (subs == null) ? [] : subs; // If it's null set it to an empty array. + }; + + /** + * The Connections update method includes a number of subtle complexities due to the way QMF Management + * Objects are associated with each other. For example a Subscription is associated with a single + * Session however a Session may have zero or more Subscriptions, similarly a Session is associated with + * a single Connection but a Connection may have zero or more Sessions. + * + * The QMF Management Objects maintain the single unidirectional associations, which generally makes sense + * but an unfortunate side-effect of this is that if one wishes to obtain information about Sessions and + * Subscriptions related to a given Connection it's somewhat of a pain as one has to do a multi-pass dereference. + * + * This method does the dereferencing and creates a 0..* association to Session in each Connection object and + * a 0..* association to Subscription in each Session object so other pages can avoid their own dereferencing. + * N.B. these added associations are references to actual Session or Subscription objects and NOT via ObjectIds + * This is because these associations are not *really* QmfData object properties and only exist within the local + * memory space of this application, so using actual memory references avoids an additional dereference. + */ + this.update = function() { + _subscriptionMap = {}; // Clear _subscriptionMap. + _sessionMap = {}; // Clear _sessionMap. + _queueToSubscriptionAssociations = {}; // Clear _queueToSubscriptionAssociations. + + var subscriptions = qmfui.Console.getSubscriptions(); + for (var i in subscriptions) { + var subscription = subscriptions[i]; + var subscriptionId = subscription._object_id; + var sessionRef = subscription.sessionRef; + var queueRef = subscription.queueRef; + + // Create the Session->Subscriptions association array and store it keyed by the sessionRef, when we go + // to store the actual Session we can retrieve the association and store it as a property of the Session. + if (_sessionMap[sessionRef] == null) { + _sessionMap[sessionRef] = [subscription]; + } else { + _sessionMap[sessionRef].push(subscription); + } + + // Create the Queue->Subscriptions association array and store it keyed by the queueRef, when we go + // to store the actual Session we can retrieve the association and store it as a property of the Session. + if (_queueToSubscriptionAssociations[queueRef] == null) { + _queueToSubscriptionAssociations[queueRef] = [subscription]; + } else { + _queueToSubscriptionAssociations[queueRef].push(subscription); + } + + _subscriptionMap[subscriptionId] = subscription; // Index subscriptions by ObjectId. + } + + var connectionToSessionAssociations = {}; + var sessions = qmfui.Console.getSessions(); + for (var i in sessions) { + var session = sessions[i]; + var sessionId = session._object_id; + var connectionRef = session.connectionRef; + + var subs = _sessionMap[sessionId]; // Retrieve the association array and store it as a property. + subs = (subs == null) ? [] : subs; // If it's null set it to an empty array. + session._subscriptions = subs; + + // Create the Connection->Sessions association array and store it keyed by the connectionRef, when we go to + // store the actual Connection we can retrieve the association and store it as a property of the Connection. + if (connectionToSessionAssociations[connectionRef] == null) { + connectionToSessionAssociations[connectionRef] = [session]; + } else { + connectionToSessionAssociations[connectionRef].push(session); + } + _sessionMap[sessionId] = session; // Index sessions by ObjectId. + } + + // Temporary connections map, we move active connections to this so deleted connections wither and die. + var temp = {}; + var connections = qmfui.Console.getConnections(); + iTablet.renderList($("#connections-list"), function(i) { + var connection = connections[i]; + var connectionId = connection._object_id; + + // Look up the previous value for the indexed connection using its objectId. + var prev = _connectionMap[connectionId]; + var stats = (prev == null) ? new qmfui.Statistics(["msgsFromClient", "msgsToClient"]) : prev._statistics; + stats.put([connection.msgsFromClient, connection.msgsToClient, connection._update_ts]); + connection._statistics = stats; + + // Retrieve the association array and store it as a property. + var sessions = connectionToSessionAssociations[connectionId]; + sessions = (sessions == null) ? [] : sessions; // If it's null set it to an empty array. + connection._sessions = sessions; + temp[connectionId] = connection; + + // Calculate the total number of subscriptions for this connection, this is useful because a count of + // zero indicates that a connection is probably a producer only connection. + var connectionSubscriptions = 0; + for (var i in connection._sessions) { + var session = connection._sessions[i]; + connectionSubscriptions += session._subscriptions.length; + } + + var address = connection.address + " (" + connection.remoteProcessName + ")"; + if (connectionSubscriptions == 0) { + return "<li class='arrow'><a href='#selected-connection?id=" + connectionId + "'>" + address + + "<p>No Subscriptions</p></a></li>"; + } else { + return "<li class='arrow'><a href='#selected-connection?id=" + connectionId + "'>" + address + + "</a></li>"; + } + }, connections.length); + + // Replace the saved statistics with the newly populated temp instance, which only has active objects + // moved to it, this means that any deleted objects are no longer present. + _connectionMap = temp; + }; + +}; // End of qmfui.Connections definition + + +/** + * Create a Singleton instance of the SelectedConnection class managing the id="selected-connection" page. + */ +qmfui.SelectedConnection = new function() { + var _sessions = []; // Populate this with the ID of matching sessions enabling navigation to sessions. + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#selected-connection") { + return; + } + + // Get the latest statistics update of the selected connection object. + var connectionId = data.id; + var connection = qmfui.Connections.getConnection(connectionId); + if (connection == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + var name = connection.address + " (" + connection.remoteProcessName + ")"; + $("#selected-connection .header h1").text(name); + + // Populate the back button with "Subscription" or "Connections" depending on context + var backText = data.fromSubscription ? "Subscrip..." : "Connect..."; + + // Using $("#selected-connection .header a").text(backText) wipes all child elements so use the following. + $("#selected-connection .header a")[0].firstChild.nodeValue = backText; + + // Render the connection message statistics to #selected-connection-msgio + qmfui.renderObject($("#selected-connection-msgio"), connection, ["msgsFromClient", "msgsToClient"], + "#graphs?connectionId=" + connectionId); + + // Render the connection byte statistics to #selected-connection-byteio + qmfui.renderObject($("#selected-connection-byteio"), connection, ["bytesFromClient", "bytesToClient"]); + + // Render the connection frame statistics to #selected-connection-frameio + qmfui.renderObject($("#selected-connection-frameio"), connection, ["framesFromClient", "framesToClient"]); + + // Render selected general connection properties to #selected-connection-general. + qmfui.renderObject($("#selected-connection-general"), connection, ["federationLink", "SystemConnection", + "incoming", "authIdentity", "userProxyAuth", "saslMechanism", "saslSsf", "remotePid", + "shadow", "closing", "protocol"]); + + // Render links to the sessions associated with this connection. + _sessions = connection._sessions; + var subscribedSessions = $("#selected-connection-subscribed-sessions"); + var unsubscribedSessions = $("#selected-connection-unsubscribed-sessions"); + if (_sessions.length == 0) { // Show a message if there are no sessions at all + subscribedSessions.hide(); + subscribedSessions.prev().hide(); + unsubscribedSessions.show(); + unsubscribedSessions.prev().show(); + iTablet.renderList(unsubscribedSessions, function(i) { + return "<li class='grey'><a href='#'>There are currently no sessions attached to " + + name + "</a></li>"; + }); + } else { + var subscribed = []; + var unsubscribed = []; + for (var i in _sessions) { + var session = _sessions[i]; + var id = session._object_id; + var subscriptionCount = session._subscriptions.length; + if (subscriptionCount == 0) { + unsubscribed.push("<li><a href='#'>" + session.name + "</a></li>"); + } else { + var plural = subscriptionCount > 1 ? " Subscriptions" : " Subscription"; + subscribed.push("<li class='multiline arrow'><a href='#connection-subscriptions?id=" + id + "'><div>" + + session.name + "<p class='sub'>" + subscriptionCount + plural + "</p></div></a></li>"); + } + } + + if (subscribed.length > 0) { + subscribedSessions.show(); + subscribedSessions.prev().show(); + qmfui.renderArray(subscribedSessions, subscribed); + } else { + subscribedSessions.hide(); + subscribedSessions.prev().hide(); + } + + if (unsubscribed.length > 0) { + unsubscribedSessions.show(); + unsubscribedSessions.prev().show(); + qmfui.renderArray(unsubscribedSessions, unsubscribed); + } else { + unsubscribedSessions.hide(); + unsubscribedSessions.prev().hide(); + } + } + } + }; + + this.initialise = function() { + $("#selected-connection").unbind("show").bind("show", qmfui.SelectedConnection.update); + }; +}; // End of qmfui.SelectedConnection definition + + +/** + * Create a Singleton instance of the ConnectionSubscriptions class managing the id="connection-subscriptions" page. + * This page is slightly different than most of the others as there can be multiple subscriptions and thus multiple + * arbitrary lists. Most pages have tried to reuse HTML list items for efficiency but in this page we clear and + * regenerate the contents of the page div each update as it's simpler than attempting to reuse elements. + */ +qmfui.ConnectionSubscriptions = new function() { + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#connection-subscriptions") { + return; + } + + var sessionId = data.id; + var session = qmfui.Connections.getSession(sessionId); + if (session == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked; + + // Populate the page header with the session name. + $("#connection-subscriptions .header h1").text(session.name); + + var subscriptions = session._subscriptions; + var length = subscriptions.length; + + var page = $("#connection-subscriptions .page"); + page.children().remove(); // Clear the contents of the page div. + + for (var i = 0; i < length; i++) { + var subscription = subscriptions[i]; + var id = subscription.queueRef; + var queue = qmfui.Queues.getQueue(id); + + if (i == 0) { + page.append("<h1 class='first'>Subscription 1</h1>"); + } else { + page.append("<h1>Subscription " + (i + 1) + "</h1>"); + } + + var name = $("<ul id='connection-subscription-name" + i + "' class='list'></ul>"); + page.append(name); + + // Render the associated queue name to #connection-subscription-name. + var isQmfQueue = queue._isQmfQueue; + iTablet.renderList(name, function(i) { + // If the associated Queue is a QMF Queue and hideQmfObjects has been selected render the + // Queue name grey and make it non-navigable otherwise render normally. + if (isQmfQueue && hideQmfObjects) { + return "<li class='grey'><a href='#selected-queue?id=" + id + "&fromSubscriptions=true'>" + + queue.name + "</a></li>"; + } else { + return "<li class='arrow'><a href='#selected-queue?id=" + id + "&fromSubscriptions=true'>" + + queue.name + "</a></li>"; + } + }); + + page.append("<p/>"); + + var list = $("<ul id='connection-subscription" + i + "' class='list'></ul>"); + page.append(list); + + // Render the useful subscription properties to #connection-subscriptions-list. + qmfui.renderObject(list, subscription, + ["delivered", "browsing", "acknowledged", "exclusive", "creditMode"]); + } + + $("#connection-subscriptions").trigger("refresh"); // Make sure touch scroller is up-to-date. + } + }; + + this.initialise = function() { + $("#connection-subscriptions").unbind("show").bind("show", qmfui.ConnectionSubscriptions.update); + }; +}; // End of qmfui.ConnectionSubscriptions definition + + +//------------------------------------------------------------------------------------------------------------------- +// Exchange Information +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Exchanges class managing the id="exchanges" page. + */ +qmfui.Exchanges = new function() { + var QMF_EXCHANGES = {"qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true}; + var _exchangeNameMap = {}; // Exchanges indexed by name. + var _exchangeMap = {}; // Exchanges indexed by ObjectId. + + /** + * Return the Exchange object for the given QMF ObjectId. The Exchange object contains the latest update + * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period. + */ + this.getExchange = function(oid) { + return _exchangeMap[oid]; + }; + + /** + * Return the Exchange object with the given name. The Exchange object contains the latest update + * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period. + */ + this.getExchangeByName = function(name) { + return _exchangeNameMap[name]; + }; + + this.update = function() { + var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked; + + // We move active exchanges to temp so deleted exchanges wither and die. We can't just do _exchangeMap = {} + // as we need to retrieve and update statistics from any active (non-deleted) exchange. + var temp = {}; + _exchangeNameMap = {}; // We can simply clear the map of exchanges indexed by name though. + var exchanges = qmfui.Console.getExchanges(); + iTablet.renderList($("#exchanges-list"), function(i) { + var exchange = exchanges[i]; + + // Look up the previous value for the indexed exchange using its objectId. + var prev = _exchangeMap[exchange._object_id]; + var stats = (prev == null) ? new qmfui.Statistics(["msgReceives", "msgRoutes", "msgDrops"]) : + prev._statistics; + + stats.put([exchange.msgReceives, exchange.msgRoutes, exchange.msgDrops, exchange._update_ts]); + exchange._statistics = stats; + + var id = exchange._object_id; + temp[id] = exchange; + + var name = exchange.name; + name = (name == "") ? "'' (default direct)" : name; + + _exchangeNameMap[name] = exchange; + + if (QMF_EXCHANGES[name] && hideQmfObjects) { + return false; // Filter out any QMF related exchanges if the settings filter is checked. + } else { + return "<li class='arrow'><a href='#selected-exchange?id=" + id + "'>" + name + + "<p>" + exchange.type + "</p></a></li>"; + } + }, exchanges.length); + + // Replace the saved statistics with the newly populated temp instance, which only has active objects + // moved to it, this means that any deleted objects are no longer present. + _exchangeMap = temp; + }; + +}; // End of qmfui.Exchanges definition + + +/** + * Create a Singleton instance of the AddExchange class managing the id="add-exchange" page. + */ +qmfui.AddExchange = new function() { + var submit = function() { + var properties = {}; + + if ($("#exchange-durable")[0].checked) { + properties["durable"] = true; + } else { + properties["durable"] = false; + } + + if ($("#sequence")[0].checked) { + properties["qpid.msg_sequence"] = 1; + } + + if ($("#ive")[0].checked) { + properties["qpid.ive"] = 1; + } + + properties["exchange-type"] = $("#exchange-type input[checked]").val(); + + var alternateExchangeName = $("#add-exchange-additional-alternate-exchange-name p").text(); + if (alternateExchangeName != "None (default)") { + alternateExchangeName = alternateExchangeName.split(" (")[0]; // Remove the exchange type from the text. + properties["alternate-exchange"] = alternateExchangeName; + } + + var exchangeName = $("#exchange-name"); + var name = exchangeName.val(); + if (name == "") { + exchangeName.addClass("error"); + } else { + exchangeName.removeClass("error"); + + var arguments = {"type": "exchange", "name": name, "properties": properties}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("create", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }; + + var changeType = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + $("#add-exchange-exchange-type p").text(jthis.siblings("label").text()); + } + }; + + this.initialise = function() { + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#add-exchange .right.button").bind(qmfui.END_EV, submit); + $("#exchange-type input").change(changeType); + + // Always initialise to default value irrespective of browser caching. + $("#direct").click(); + }; +}; // End of qmfui.AddExchange definition + + +/** + * Create a Singleton instance of the ExchangeSelector class managing the id="exchange-selector" page. + */ +qmfui.ExchangeSelector = new function() { + // Protected Exchanges are exchanges that we don't permit binding to - default direct and the QMF exchanges. + var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true, + "qmf.default.topic": true, "qpid.management": true}; + var _id; + + /** + * This method renders dynamic content in the ExchangeSelector page. This is necessary because the set + * of exchanges to be rendered may change as exchanges are added or deleted. + */ + var show = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#exchange-selector") { + return; + } + + // We pass in the ID of the list ltem that contains the anchor with an href to exchange-selector. + _id = data.id; + + if (_id == "#add-binding-exchange-name") { + $("#exchange-selector .header a").text("Add Bin..."); + $("#exchange-selector .header h1").text("Select Exchange"); + } else if (_id == "#reroute-messages-exchange-name") { + $("#exchange-selector .header a").text("Reroute..."); + $("#exchange-selector .header h1").text("Select Exchange"); + } else { + $("#exchange-selector .header a").text("Additio..."); + $("#exchange-selector .header h1").text("Alternate Exchange"); + } + + var exchanges = qmfui.Console.getExchanges(); + var filteredExchanges = []; + var currentlySelected = $(_id + " p").text(); + + // Check the status of any Exchange that the user may have previously selected prior to hitting "Done". + if (currentlySelected != "None (default)") { + // Remove the exchange type from the text before testing. + currentlySelected = currentlySelected.split(" (")[0]; + if (qmfui.Exchanges.getExchangeByName(currentlySelected) == null) { // Check if it has been deleted. + alert('The currently selected Exchange "' + currentlySelected + '" appears to have been deleted.'); + currentlySelected = "None (default)"; + } + } + + var checked = (currentlySelected == "None (default)") ? "checked" : ""; + filteredExchanges.push("<li><label for='exchange-selector-exchangeNone'>None (default)</label><input type='radio' id='exchange-selector-exchangeNone' name='exchange-selector' value='None (default)' " + checked + "/></li>"); + + var length = exchanges.length; + for (var i = 0; i < length; i++) { + var name = exchanges[i].name; + var type = exchanges[i].type; + checked = (currentlySelected == name) ? "checked" : ""; + + // Filter out default direct and QMF exchanges as we don't want to allow binding to those. + if (!PROTECTED_EXCHANGES[name]) { + filteredExchanges.push("<li><label for='exchange-selector-exchange" + i + "'>" + name + " (" + type + ")</label><input type='radio' id='exchange-selector-exchange" + i + "' name='exchange-selector' value='" + name + "' " + checked + "/></li>"); + } + } + + qmfui.renderArray($("#exchange-selector-list"), filteredExchanges); + $("#exchange-selector-list input").change(changeExchange); + }; + + /** + * Event handler for the change event on "#exchange-selector-list input". Note that this is bound "dynamically" + * in the show handler because the exchange list is created dynamically each time the ExchangeSelector is shown. + */ + var changeExchange = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + $(_id + " p").text(jthis.siblings("label").text()); + } + }; + + this.initialise = function() { + $("#exchange-selector").unbind("show").bind("show", show); + }; +}; // End of qmfui.ExchangeSelector definition + + +/** + * Create a Singleton instance of the SelectedExchange class managing the id="selected-exchange" page. + */ +qmfui.SelectedExchange = new function() { + // System Exchanges are exchanges that should not be deleted so we hide the delete button for those Exchanges. + var SYSTEM_EXCHANGES = {"''": true, "amq.direct": true, "amq.fanout": true, "amq.match": true, "amq.topic": true, + "qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true}; + + // Protected Exchanges are exchanges that we don't binding to - default direct and the QMF exchanges. + var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true, + "qmf.default.topic": true, "qpid.management": true}; + var _name = ""; + + /** + * This method deletes the selected exchange by invoking the QMF delete method. + */ + var deleteHandler = function() { + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + setTimeout(function() { + if (confirm('Delete Exchange "' + _name + '"?') == false) { + return; + } else { + var arguments = {"type": "exchange", "name": _name}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("delete", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }, 0); + }; + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#selected-exchange") { + return; + } + + // Get the latest update of the selected exchange object. + var exchangeId = data.id; + var exchange = qmfui.Exchanges.getExchange(exchangeId); + if (exchange == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + // Populate the page header with the exchange name and type + _name = exchange.name; + _name = (_name == "") ? "''" : _name; + $("#selected-exchange .header h1").text(_name + " (" + exchange.type + ")"); + + // If the selected Exchange is a system Exchange hide the delete button, otherwise show it. + if (SYSTEM_EXCHANGES[_name]) { + $("#selected-exchange .header a.delete").hide(); + } else { + $("#selected-exchange .header a.delete").show(); + } + + // Populate the back button with "Exchanges" or "Bindings" depending on context + var backText = "Exchan..."; + if (data.bindingKey) { + backText = "Bindings"; + // Ensure that the binding that linked to this page gets correctly highlighted if we navigate back. + // If default direct add an extra "&" otherwise all ObjectIds will match in a simple string search. + qmfui.Bindings.setHighlightedBinding(exchangeId + (_name == "''" ? "&" : ""), + data.bindingKey); + } + + // Using $("#selected-exchange .header a").text(backText) wipes all child elements so use the following. + $("#selected-exchange .header a")[0].firstChild.nodeValue = backText; + + // Render the bindingCount to #selected-exchange-bindings + if (exchange.bindingCount == 0) { + // We don't allow bindings to be added to default direct or QMF Exchanges. + if (PROTECTED_EXCHANGES[_name]) { + iTablet.renderList($("#selected-exchange-bindings"), function(i) { + return "<li class='grey'><a href='#'>There are currently no bindings to " + _name + "</a></li>"; + }); + } else { + iTablet.renderList($("#selected-exchange-bindings"), function(i) { + return "<li class='pop'><a href='#add-binding?exchangeId=" + exchangeId + "'>Add Binding</a></li>"; + }); + } + } else { + iTablet.renderList($("#selected-exchange-bindings"), function(i) { + return "<li class='arrow'><a href='#bindings?exchangeId=" + exchangeId + "'>bindingCount<p>" + + exchange.bindingCount + "</p></a></li>"; + }); + } + + // Render the exchange statistics to #selected-exchange-msgio + qmfui.renderObject($("#selected-exchange-msgio"), exchange, ["msgReceives", "msgRoutes", "msgDrops"], + "#graphs?exchangeId=" + exchangeId); + + // Render the exchange statistics to #selected-exchange-byteio + qmfui.renderObject($("#selected-exchange-byteio"), exchange, ["byteReceives", "byteRoutes", "byteDrops"]); + + // Render selected general exchange properties and exchange.declare arguments to #selected-exchange-general. + keys = ["durable", "autoDelete", "producerCount"]; + var general = []; + + // Render any alternate exchange that may be attached to this exchange. Note that exchange.altExchange + // is a reference property so we need to dereference it before extracting the exchange name. + var altExchange = qmfui.Exchanges.getExchange(exchange.altExchange); + if (altExchange) { + general.push("<li><a href='#'>altExchange<p>" + altExchange.name + "</p></a></li>"); + } + + for (var i in keys) { // Populate with selected properties. + var key = keys[i]; + general.push("<li><a href='#'>" + key + "<p>" + exchange[key] + "</p></a></li>"); + } + for (var i in exchange.arguments) { // Populate with arguments. + general.push("<li><a href='#'>" + i + "<p>" + exchange.arguments[i] + "</p></a></li>"); + } + qmfui.renderArray($("#selected-exchange-general"), general); + } + }; + + this.initialise = function() { + $("#selected-exchange").unbind("show").bind("show", qmfui.SelectedExchange.update); + + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#selected-exchange .header a.delete").bind(qmfui.END_EV, deleteHandler); + }; +}; // End of qmfui.SelectedExchange definition + + +//------------------------------------------------------------------------------------------------------------------- +// Queue Information +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Queues class managing the id="queues" page. + */ +qmfui.Queues = new function() { + var QMF_EXCHANGES = { "qmf.default.direct": true, "qmf.default.topic": true, "qpid.management": true}; + var _queueNameMap = {}; // Queues indexed by name. + var _queueMap = {}; // Queues indexed by ObjectId. + + /** + * Return the Queue object for the given QMF ObjectId. The Queue object contains the latest update + * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period. + */ + this.getQueue = function(oid) { + return _queueMap[oid]; + }; + + /** + * Return the Queue object with the given name. The Queue object contains the latest update + * of the given object and a RingBuffer containing previous values of key statistics over a 24 hour period. + */ + this.getQueueByName = function(name) { + return _queueNameMap[name]; + }; + + this.update = function() { + var hideQmfObjects = $("#settings-hide-qmf-objects")[0].checked; + + // We move active queues to temp so deleted queues wither and die. We can't just do _queueMap = {} as we + // need to retrieve and update statistics from any active (non-deleted) queue. + var temp = {}; + _queueNameMap = {}; // We can simply clear the map of queues indexed by name though. + var queues = qmfui.Console.getQueues(); + iTablet.renderList($("#queues-list"), function(i) { + var queue = queues[i]; + var objectId = queue._object_id; + + // Look up the previous value for the indexed queue using its objectId. + var prev = _queueMap[objectId]; + var stats = (prev == null) ? new qmfui.Statistics(["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"]) : + prev._statistics; + + stats.put([queue.msgDepth, queue.msgTotalEnqueues, queue.msgTotalDequeues, queue._update_ts]); + + // Add statistics as an additional property of the queue object. + queue._statistics = stats; + + /* + * Check if the queue is associated with a QMF exchange. Because we need to iterate through the + * bindings in an inner loop we only want to do this once for each queue, however we can't only + * do it when the queue is missing from the _queueMap, because there's a race condition with QMF + * properties getting asynchronously returned, so it's possible for a queue to exist without a + * binding object referencing it existing for a short period, so we don't add the _isQmfQueue + * property until a binding referencing the queue actually exists. + */ + if (prev == null || prev._isQmfQueue == null) { + var bindings = qmfui.Console.getBindings(); // Get the cached list of binding objects. + for (var i in bindings) { + var b = bindings[i]; + if (b.queueRef == objectId) { + var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference the exchangeRef. + if (exchange != null) { + // If a binding referencing the queue and an exchange exists add isQmfQueue state as an + // additional property of the queue object. + if (QMF_EXCHANGES[exchange.name]) { + queue._isQmfQueue = true; + break; + } else { + queue._isQmfQueue = false; + } + } + } + } + } else { + // Add previous status of _isQmfQueue as an additional property of the queue object. + queue._isQmfQueue = prev._isQmfQueue; + } + + temp[objectId] = queue; + _queueNameMap[queue.name] = queue; + + if (queue._isQmfQueue && hideQmfObjects) { + return false; // Filter out any QMF related queues if the settings filter is checked. + } else { + return "<li class='arrow'><a href='#selected-queue?id=" + objectId + "'>" + queue.name + "</a></li>"; + } + }, queues.length); + + // Replace the saved statistics with the newly populated temp instance, which only has active objects + // moved to it, this means that any deleted objects are no longer present. + _queueMap = temp; + }; + +}; // End of qmfui.Queues definition + + +/** + * Create a Singleton instance of the AddQueue class managing the id="add-queue" page. + */ +qmfui.AddQueue = new function() { + var _properties = {}; + + var parseIntegerProperty = function(selector, name) { + var value = $(selector).removeClass("error").val(); + if (value == "") { + return true; // "" doesn't populate the property, but it's still valid so return true; + } else { + if (value.search(/[kKmMgG]/) == (value.length - 1)) { // Does it end in K/M/G + _properties[name] = value; + return true; + } else { + var integer = parseInt(value); + if (isNaN(integer)) { + $(selector).addClass("error"); + return false; + } else { + _properties[name] = integer; + return true; + } + } + } + }; + + var submit = function() { + _properties = {}; + + if (!parseIntegerProperty("#max-queue-size", "qpid.max_size")) { + return; + } else if (!parseIntegerProperty("#max-queue-count", "qpid.max_count")) { + return; + } else if (!parseIntegerProperty("#flow-stop-size", "qpid.flow_stop_size")) { + return; + } else if (!parseIntegerProperty("#flow-stop-count", "qpid.flow_stop_count")) { + return; + } else if (!parseIntegerProperty("#flow-resume-size", "qpid.flow_resume_size")) { + return; + } else if (!parseIntegerProperty("#flow-resume-count", "qpid.flow_resume_count")) { + return; + } + + if ($("#queue-durable")[0].checked) { + _properties["durable"] = true; + if (!parseIntegerProperty("#file-size", "qpid.file_size")) { + return; + } else if (!parseIntegerProperty("#file-count", "qpid.file_count")) { + return; + } + } else { + _properties["durable"] = false; + } + + var limitPolicy = $("#limit-policy input[checked]").val(); + if (limitPolicy != "none") { + _properties["qpid.policy_type"] = limitPolicy; + } + + var orderingPolicy = $("#ordering-policy input[checked]").val(); + if (orderingPolicy == "lvq") { + _properties["qpid.last_value_queue"] = 1; + } else if (orderingPolicy == "lvq-no-browse") { + _properties["qpid.last_value_queue_no_browse"] = 1; + } + + if (!parseIntegerProperty("#generate-queue-events input[checked]", "qpid.queue_event_generation")) { + return; + } + + var alternateExchangeName = $("#add-queue-additional-alternate-exchange-name p").text(); + if (alternateExchangeName != "None (default)") { + alternateExchangeName = alternateExchangeName.split(" (")[0]; // Remove the exchange type from the text. + _properties["alternate-exchange"] = alternateExchangeName; + } + + var queueName = $("#queue-name"); + var name = queueName.val(); + if (name == "") { + queueName.addClass("error"); + } else { + queueName.removeClass("error"); + + var arguments = {"type": "queue", "name": name, "properties": _properties}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("create", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }; + + var changeLimitPolicy = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + $("#add-queue-limit-policy p").text(jthis.siblings("label").text()); + } + }; + + var changeOrderingPolicy = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + var value = jthis.attr("value"); + if (value == "fifo") { + $("#add-queue-ordering-policy p").text("Fifo (default)"); + } else if (value == "lvq") { + $("#add-queue-ordering-policy p").text("LVQ"); + } else if (value == "lvq-no-browse") { + $("#add-queue-ordering-policy p").text("LVQ No Browse"); + } + } + }; + + var changeQueueEventGeneration = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + $("#add-queue-generate-queue-events p").text(jthis.siblings("label").text()); + } + }; + + var changeDurable = function(e) { + var durable = $("#queue-durable")[0].checked; + var durableList = $("#add-queue-additional-durable-list"); + var hiddenList = $("#add-queue-additional-hidden-list").hide(); + + if (durable) { + setTimeout(function() { + iTablet.renderList(durableList); + setTimeout(function() { + $("#file-size").parent().appendTo(durableList); + iTablet.renderList(durableList); + setTimeout(function() { + $("#file-count").parent().appendTo(durableList); + iTablet.renderList(durableList); + $("#add-queue-additional").trigger("refresh"); // Refresh touch scroller. + }, 30); + }, 30); + }, 30); + + $("#add-queue-additional-journal-note").show(); + } else { + setTimeout(function() { + $("#file-count").parent().appendTo(hiddenList); + setTimeout(function() { + $("#file-size").parent().appendTo(hiddenList); + setTimeout(function() { + iTablet.renderList(durableList); + $("#add-queue-additional").trigger("refresh"); // Refresh touch scroller. + }, 30); + }, 30); + }, 30); + + $("#add-queue-additional-journal-note").hide(); + } + }; + + this.initialise = function() { + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#add-queue .right.button").bind(qmfui.END_EV, submit); + $("#limit-policy input").change(changeLimitPolicy); + $("#ordering-policy input").change(changeOrderingPolicy); + $("#generate-queue-events input").change(changeQueueEventGeneration); + + // Always initialise to default value irrespective of browser caching. + $("#none").click(); + $("#fifo").click(); + $("#generate-no-events").click(); + + changeDurable(); + $("#queue-durable").change(changeDurable); + }; +}; // End of qmfui.AddQueue definition + + +/** + * Create a Singleton instance of the SelectedQueue class managing the id="selected-queue" page. + */ +qmfui.SelectedQueue = new function() { + var _name = ""; + + // The Queue depth and number of consumers are reported during the Queue delete confirmation process. + var _depth = 0; + var _consumers = 0; + + /** + * This method deletes the selected queue by invoking the QMF delete method. + */ + var deleteHandler = function() { + var plural = (_consumers == 1) ? " consumer?" : " consumers?" + + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + setTimeout(function() { + if (confirm('Delete Queue "' + _name + + '"\nwhich contains ' + _depth + " messages and has " + _consumers + plural) == false) { + return; + } else { + var arguments = {"type": "queue", "name": _name}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("delete", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }, 0); + }; + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#selected-queue") { + return; + } + + // Get the latest update of the selected queue object. + var queueId = data.id; + var queue = qmfui.Queues.getQueue(queueId); + if (queue == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + _name = queue.name; + _depth = queue.msgDepth; // Reported to user if Queue delete is selected. + _consumers = queue.consumerCount; // Reported to user if Queue delete is selected. + + // Populate the page header with the queue name. + $("#selected-queue .header h1").text(_name); + + // If the selected Queue is a QMF Queue hide the delete button, otherwise show it. + // Deleting QMF Queues is a bad thing as it will stop any QMF Consoles behaving as the should. + if (queue._isQmfQueue) { + $("#selected-queue .header a.delete").hide(); + $("#selected-queue-admin-wrapper").hide(); + } else { + $("#selected-queue .header a.delete").show(); + $("#selected-queue-admin-wrapper").show(); + } + + // Populate the back button with "Queues", "Bindings" or "Subscriptions" depending on context + var backText = "Queues"; + if (data.bindingKey) { + backText = "Bindings"; + // Ensure that the binding that linked to this page gets correctly highlighted if we navigate back. + qmfui.Bindings.setHighlightedBinding(queueId, data.bindingKey); + } else if (data.fromSubscriptions) { + backText = "Subscrip..."; + } + + // Using $("#selected-queue .header a").text(backText) wipes all child elements so use the following. + $("#selected-queue .header a")[0].firstChild.nodeValue = backText; + + // Render the bindingCount to #selected-queue-bindings + // There should always be at least one binding to a queue as the default direct exchange is always bound. + iTablet.renderList($("#selected-queue-bindings"), function(i) { + return "<li class='arrow'><a href='#bindings?queueId=" + queueId + "'>bindingCount<p>" + + queue.bindingCount + "</p></a></li>"; + }); + + // Render the queue statistics to #selected-queue-msgio + qmfui.renderObject($("#selected-queue-msgio"), queue, ["msgDepth", "msgTotalEnqueues", "msgTotalDequeues"], + "#graphs?queueId=" + queueId); + + // Render the queue statistics to #selected-queue-byteio + qmfui.renderObject($("#selected-queue-byteio"), queue, ["byteDepth", "byteTotalEnqueues", + "byteTotalDequeues"]); + + // Render selected general queue properties and queue.declare arguments to #selected-queue-general. + keys = ["durable", "autoDelete", "exclusive", "unackedMessages", "acquires", "releases", + "messageLatency", "messageLatencyAvg", "consumerCount", "flowStopped", "flowStoppedCount"]; + var general = []; + + // Render any alternate exchange that may be attached to this queue. Note that queue.altExchange + // is a reference property so we need to dereference it before extracting the exchange name. + var altExchange = qmfui.Exchanges.getExchange(queue.altExchange); + if (altExchange) { + general.push("<li><a href='#'>altExchange<p>" + altExchange.name + "</p></a></li>"); + } + + for (var i in keys) { // Populate with selected properties. + var key = keys[i]; + var value = queue[key]; + if (value != null) { + general.push("<li><a href='#'>" + key + "<p>" + value + "</p></a></li>"); + } + } + for (var i in queue.arguments) { // Populate with arguments. + general.push("<li><a href='#'>" + i + "<p>" + queue.arguments[i] + "</p></a></li>"); + } + qmfui.renderArray($("#selected-queue-general"), general); + + var hideDetails = $("#settings-hide-details")[0].checked; + + // Render the Flow-to-disk Statistics. + if (queue.msgFtdDepth == null || hideDetails) { + $("#selected-queue-flow-to-disk-container").hide(); + } else { + $("#selected-queue-flow-to-disk-container").show(); + qmfui.renderObject($("#selected-queue-flow-to-disk"), queue, ["msgFtdDepth", "msgFtdEnqueues", + "msgFtdDequeues", "byteFtdDepth", "byteFtdEnqueues", "byteFtdDequeues"]); + } + + // Render the Dequeue Details. + if (queue.discardsTtl == null || hideDetails) { + $("#selected-queue-dequeue-container").hide(); + } else { + $("#selected-queue-dequeue-container").show(); + qmfui.renderObject($("#selected-queue-dequeue"), queue, ["discardsTtl", "discardsRing", "discardsLvq", + "discardsOverflow", "discardsSubscriber", "discardsPurge", "reroutes"]); + } + + // Render links to the subscriptions associated with this queue to #selected-queue-subscriptions. + // Unfortunately the subscription name isn't especially useful so find the associated connection + // and display the connection address instead. + var subscriptions = qmfui.Connections.getQueueSubscriptions(queueId); + if (subscriptions.length == 0) { + iTablet.renderList($("#selected-queue-subscriptions"), function(i) { + return "<li class='grey'><a href='#'>There are currently no subscriptions to " + _name + "</a></li>"; + }); + } else { + iTablet.renderList($("#selected-queue-subscriptions"), function(i) { + var subscription = subscriptions[i]; + var id = subscription._object_id; + + // The subscription.sessionRef really should be present, but the Java Broker does not yet correctly + // populate the association between Subscription and Session so we need this defensive block. + if (subscription.sessionRef != null) { + var session = qmfui.Connections.getSession(subscription.sessionRef); + var connection = qmfui.Connections.getConnection(session.connectionRef); + var address = connection.address + " (" + connection.remoteProcessName + ")"; + return "<li class='arrow'><a href='#queue-subscriptions?id=" + id + "'>" + address + "</a></li>"; + } else { + return "<li class='arrow'><a href='#queue-subscriptions?id=" + id + "'>" + subscription.name + "</a></li>"; + } + }, subscriptions.length); + } + + // We have to dynamically render the admin list so that we can attach the queueId to the URL. + var admin = []; + admin.push("<li class='arrow pop'><a href='#purge-queue?queueId=" + queueId + "'>Purge</a></li>"); + admin.push("<li class='arrow pop'><a href='#reroute-messages?queueId=" + queueId + "'>Reroute Messages</a></li>"); + admin.push("<li class='arrow pop'><a href='#move-messages?queueId=" + queueId + "'>Move Messages</a></li>"); + qmfui.renderArray($("#selected-queue-admin"), admin); + } + }; + + this.initialise = function() { + $("#selected-queue").unbind("show").bind("show", qmfui.SelectedQueue.update); + + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#selected-queue .header a.delete").bind(qmfui.END_EV, deleteHandler); + }; +}; // End of qmfui.SelectedQueue definition + + +/** + * Create a Singleton instance of the QueueSubscriptions class managing the id="queue-subscriptions" page. + */ +qmfui.QueueSubscriptions = new function() { + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#queue-subscriptions") { + return; + } + + var subscriptionId = data.id; + var subscription = qmfui.Connections.getSubscription(subscriptionId); + if (subscription == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + var session = qmfui.Connections.getSession(subscription.sessionRef); + session = session ? session : {}; + var connection = qmfui.Connections.getConnection(session.connectionRef); + connection = connection ? connection : {}; + + // The connection.address should be present but for the 0.20 Java Broker it is not yet populated + // so we need to do some defensive code to check if it's set and if not render subscription.name. + var name = connection.address ? connection.address + " (" + connection.remoteProcessName + ")" : + subscription.name; + + var connectionId = connection._object_id; + + // Populate the page header with the address of the connection associated with the subscription. + $("#queue-subscriptions .header h1").text(name); + + iTablet.renderList($("#queue-subscriptions-connection"), function(i) { + if (connectionId) { + return "<li class='arrow'><a href='#selected-connection?id=" + connectionId + + "&fromSubscription=true'>" + name + "</a></li>"; + } else { + return "<li><a href='#'>Connection is Unknown</a></li>"; + } + }); + + // subscription.sessionRef should be present but for the 0.20 Java Broker it is not yet populated + // so we need to do some defensive code to check if it's set and if not render "Session is Unknown". + if (subscription.sessionRef) { + // Render the useful session properties to #queue-subscriptions-session + qmfui.renderObject($("#queue-subscriptions-session"), session, ["name", "framesOutstanding", + "unackedMessages", "channelId", "maxClientRate", "clientCredit"]); + } else { + iTablet.renderList($("#queue-subscriptions-session"), function(i) { + return "<li><a href='#'>Session is Unknown</a></li>"; + }); + } + + // Render the useful subscription properties to #queue-subscriptions-subscription + qmfui.renderObject($("#queue-subscriptions-subscription"), subscription, ["name", "delivered", "browsing", + "acknowledged", "exclusive", "creditMode"]); + } + }; + + this.initialise = function() { + $("#queue-subscriptions").unbind("show").bind("show", qmfui.QueueSubscriptions.update); + }; +}; // End of qmfui.QueueSubscriptions definition + + +//------------------------------------------------------------------------------------------------------------------- +// Queue Admin +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the PurgeQueue class managing the id="purge-queue" page. + */ +qmfui.PurgeQueue = new function() { + /** + * Actually purge the messages using the QMF purge method on the Queue Management Object. + */ + var submit = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#purge-queue") { + return; + } + + var selector = $("#purge-queue-request-number"); + var value = selector.val(); + var messageCount = 0; + if (value != "") { + messageCount = parseInt(value); + if (isNaN(messageCount)) { + selector.addClass("error"); + return false; + } + } + + selector.removeClass("error"); + + var queueId = data.queueId; + var queue = qmfui.Queues.getQueue(queueId); + qmfui.Console.makeConsoleData(queue); // Make queue a QmfConsoleData object with an invokeMethod method. + + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + var countText = (messageCount == 0) ? "all" : messageCount; + setTimeout(function() { + if (confirm('Purge ' + countText + ' messages from "' + queue.name + '"?') == false) { + return; + } else { + var arguments = {"request": messageCount}; + + queue.invokeMethod("purge", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }, 0); + }; + + this.initialise = function() { + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#purge-queue .right.button").bind(qmfui.END_EV, submit); + }; +}; // End of qmfui.PurgeQueue definition + + +/** + * Create a Singleton instance of the RerouteMessages class managing the id="reroute-messages" page. + */ +qmfui.RerouteMessages = new function() { + /** + * Actually reroute the messages using the QMF reroute method on the Queue Management Object. + */ + var submit = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#reroute-messages") { + return; + } + + var selector = $("#reroute-messages-request-number"); + var value = selector.val(); + var messageCount = 0; + if (value != "") { + messageCount = parseInt(value); + if (isNaN(messageCount)) { + selector.addClass("error"); + return false; + } + } + + selector.removeClass("error"); + + var queueId = data.queueId; + var queue = qmfui.Queues.getQueue(queueId); + qmfui.Console.makeConsoleData(queue); // Make queue a QmfConsoleData object with an invokeMethod method. + + var useAltExchange = $("#reroute-messages-use-alternate-exchange")[0].checked; + var countText = (messageCount == 0) ? "all" : messageCount; + + var exchangeName = $("#reroute-messages-exchange-name p").text(); + if (exchangeName != "None (default)") { + exchangeName = exchangeName.split(" (")[0]; // Remove the exchange type from the text. + } + + var exchangeText = useAltExchange ? "Alternate Exchange?" : exchangeName + "?"; + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + setTimeout(function() { + if (confirm('Reroute ' + countText + ' messages from "' + queue.name + '" to ' + exchangeText) == false) { + return; + } else { + var arguments = {"request": messageCount, "useAltExchange": useAltExchange}; + if (!useAltExchange) { + arguments["exchange"] = exchangeName; + } + + queue.invokeMethod("reroute", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }, 0); + }; + + /** + * This method is the change handler for the use alternate exchange switch, it is used to show or hide the + * exchange selector widget. This handler is also bound to "show" because the state of the alternate exchange + * switch is cached in some browsers so triggering on change alone wouldn't handle that. + */ + var changeUseAlternateExchange = function() { + if ($("#reroute-messages-use-alternate-exchange")[0].checked) { + $("#reroute-messages-use-selected-exchange").hide(); + } else { + $("#reroute-messages-use-selected-exchange").show(); + } + }; + + this.initialise = function() { + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#reroute-messages .right.button").bind(qmfui.END_EV, submit); + $("#reroute-messages-use-alternate-exchange").change(changeUseAlternateExchange); + $("#reroute-messages").unbind("show").bind("show", changeUseAlternateExchange); + }; +}; // End of qmfui.RerouteMessages definition + + +/** + * Create a Singleton instance of the RerouteMessages class managing the id="move-messages" page. + */ +qmfui.MoveMessages = new function() { + var _sourceQueueName = ""; + var _destinationQueueName = ""; + var _sourceQueue = {}; + + /** + * Actually reroute the messages using the QMF reroute method on the Queue Management Object. + */ + var submit = function() { + // The queueMoveMessages method returns an InvalidParameter Exception if called when srcQueue has msgDepth == 0 + // This is pretty confusing as the parameters *are* actually OK. https://issues.apache.org/jira/browse/QPID-4543 + // has been raised on this but the following is some defensive logic to provide a more helpful warning. + if (_sourceQueue.msgDepth == 0) { + setTimeout(function() { + alert("Can't call Move Messages on a queue with a msgDepth of zero"); + return false; + }, 0); + } else { + var selector = $("#move-messages-request-number"); + var value = selector.val(); + var messageCount = 0; + if (value != "") { + messageCount = parseInt(value); + if (isNaN(messageCount)) { + selector.addClass("error"); + return false; + } + } + + selector.removeClass("error"); + + // Wrap in a timeout call because confirm doesn't play nicely with touchend and causes it to trigger twice. + // Calling confirm within a timeout ensures things are placed correctly onto the event queue. + var countText = (messageCount == 0) ? "all" : messageCount; + setTimeout(function() { + if (confirm('Move ' + countText + ' messages from "' + _sourceQueueName + '" to "' + _destinationQueueName + '"?') == false) { + return; + } else { + var arguments = {"srcQueue": _sourceQueueName, "destQueue": _destinationQueueName, "qty": messageCount}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("queueMoveMessages", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + }, 0); + } + }; + + /** + * This method renders the main move-messages page when it is made visible by the show event being triggered. + */ + var show = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#move-messages") { + return; + } + + var queueId = data.queueId; + _sourceQueue = qmfui.Queues.getQueue(queueId); + _sourceQueueName = (_sourceQueue == null) ? "" : _sourceQueue.name; + _destinationQueueName = $("#move-messages-queue-name p").text(); + + if (_sourceQueueName == _destinationQueueName) { + $("#move-messages-queue-name p").text("None (default)"); + } else { + $("#move-messages-queue-name p").text(_destinationQueueName); + } + }; + + this.getSourceQueueName = function() { + return _sourceQueueName; + }; + + this.initialise = function() { + $("#move-messages").unbind("show").bind("show", show); + + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#move-messages .right.button").bind(qmfui.END_EV, submit); + }; +}; // End of qmfui.MoveMessages definition + + +//------------------------------------------------------------------------------------------------------------------- +// Generic Bindings Rendering Page +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Bindings class managing the id="bindings" page. + */ +qmfui.Bindings = new function() { + // Protected Exchanges are exchanges that we don't permit unbinding from - default direct and the QMF exchanges. + var PROTECTED_EXCHANGES = {"": true, "''": true, "qmf.default.direct": true, + "qmf.default.topic": true, "qpid.management": true}; + var _highlightedObject = null; + var _highlightedObjectKey = null; + + /** + * This method is used to render the binding information for headers and XML exchanges which need a little + * bit more effort than just rendering the binding key. We use <p class="title"> and <p class="sub"> + * to give fairly neat formatting. + * + * @param exchange the exchange that the binding is bound to. + * @param binding the binding that we wish to render. + */ + var render = function(exchange, binding) { + if (exchange.type == "headers") { + // Arguments *should* be returned, but set to empty object if not to protect subsequent code. + var arguments = binding.arguments ? binding.arguments : {"x-match": "any"}; + var headers = "<p class='title'>x-match: " + arguments["x-match"] + "</p>"; + for (var key in arguments) { + if (key != "x-match") { + headers = headers + "<p class='sub'>" + key + ": " + arguments[key] + "</p>"; + } + } + return headers; + } else if (exchange.type == "xml") { + var arguments = binding.arguments; + var xquery = "<p class='title'>xquery:</p>"; + xquery = xquery + "<p class='sub'>" + arguments["xquery"] + "</p>"; + return xquery; + } else { + return " "; + } + }; + + /** + * This method confirms the unbind request and invokes the QMF delete binding method on the broker. + * + * @param exchangeName the exchange that we wish to unbind from. + * @param queueName the queue that we wish to unbind from. + * @param bindingKey the binding key that we wish to unbind from. + */ + var unbind = function(exchangeName, queueName, bindingKey) { + var bindingIdentifier = exchangeName + "/" + queueName; + if (bindingKey != "") { + bindingIdentifier = bindingIdentifier + "/" + bindingKey; + } + + if (confirm('Delete Binding "' + bindingIdentifier + '"?') == false) { + return; + } else { + var arguments = {"type": "binding", "name": bindingIdentifier}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("delete", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } + }); + } + }; + + /** + * This handler is triggered by clicking a <li class="clickable-icon">. Unfortunately there's bit more work + * to do because we only want to respond if the actual icon has been clicked so we need to work out the + * mouse or tap position within the li and check it's less than the icon width. + * Once we're happy that we've clicked the icon we need to work out which binding the <li> relates to. The + * approach to this is a little messy and involves scraping some of the html associated with the <li> + */ + var clickHandler = function(e) { + var target = e.target; + var jthis = $(target).closest("ul li.clickable-icon"); + + if (jthis.length != 0) { + var ICON_WIDTH = 45; // The width of the icon image plus some padding. + var offset = Math.ceil(jthis.offset().left); + var x = (e.pageX != null) ? e.pageX - offset : // Mouse position. + (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos. + + if (x < ICON_WIDTH) { + var bindingKey = jthis.text().split("]")[0]; + bindingKey = bindingKey.split("[")[1]; + var href = jthis.children("a:first").attr("href"); + href = href.replace(window.location, ""); + + if (href.indexOf("#selected-exchange") == 0) { + var queue = $("#bindings .header h1").text().split(" bindings")[0]; + var exchange = jthis.find("p:last").text(); + unbind(exchange, queue, bindingKey); + + } else { + var queue = jthis.find("p:last").text(); + var exchange = $("#bindings .header h1").text().split(" bindings")[0]; + unbind(exchange, queue, bindingKey); + } + } + } + }; + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#bindings") { + return; + } + + // Get the latest update of the selected object. + var queueId = data.queueId; + var exchangeId = data.exchangeId; + var object = queueId ? qmfui.Queues.getQueue(queueId) : qmfui.Exchanges.getExchange(exchangeId); + + if (object == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + var name = object.name; + name = (name == "") ? "''" : name; + + // Populate the page header with the object name. + $("#bindings .header h1").text(name + " bindings"); + + // Populate the back button with "Queues" or "Bindings" depending on context + var backText = "Exchange"; + + if (queueId) { + backText = "Queue"; + $("#bindings").addClass("queue"); + } else { + $("#bindings").removeClass("queue"); + } + + // Using $("#bindings .header a").text(backText) wipes all child elements so use the following. + $("#bindings .header a")[0].firstChild.nodeValue = backText; + + // Ensure the correct item on the previous page is set active so it gets highlighted when we slide back. + if (queueId) { + $("#selected-queue-bindings").children("li").addClass("active"); + $("#selected-exchange-bindings").children("li").removeClass("active"); + + // Add queueId to add-binding URL so add-binding page can automatically populate the queue name. + iTablet.renderList($("#bindings-add-binding"), function(i) { + return "<li class='pop'><a href='#add-binding?queueId=" + queueId + "'>Add Binding</a></li>"; + }); + } else { + $("#selected-queue-bindings").children("li").removeClass("active"); + $("#selected-exchange-bindings").children("li").addClass("active"); + + // Add exchangeId to add-binding URL so add-binding page can automatically populate the exchange name. + iTablet.renderList($("#bindings-add-binding"), function(i) { + return "<li class='pop'><a href='#add-binding?exchangeId=" + exchangeId + "'>Add Binding</a></li>"; + }); + } + + // Note that we don't allow bindings to be added to the default direct exchange, QMF exchanges or + // queues that are bound to QMF exchanges as doing so may have undesired consequenses. + if (PROTECTED_EXCHANGES[name] || object._isQmfQueue) { + $("#bindings-add-binding").hide(); + $("#bindings .page h1").addClass("first"); + } else { + $("#bindings-add-binding").show(); + $("#bindings .page h1").removeClass("first"); + } + + // Render selected queue's bindings to #queue-details-bindings. + var bindings = qmfui.Console.getBindings(); + var binding = []; + for (var i in bindings) { + var b = bindings[i]; + if (b.queueRef == queueId) { + var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference exchangeRef + if (exchange != null) { + var ename = exchange.name; + if (ename == "") { + // Note that we don't allow bindings to be deleted from default direct exchange. + binding.push("<li class='arrow'><a href='#selected-exchange?id=" + + b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" + + "bind [" + b.bindingKey + "] => <p>''</p></a></li>"); + } else { + var text = render(exchange, b); + + // Note that we don't allow bindings to be deleted from QMF exchanges. + if (PROTECTED_EXCHANGES[ename]) { + binding.push("<li class='multiline arrow'><a href='#selected-exchange?id=" + + b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" + + "<div>bind [" + b.bindingKey + "] =></div>" + + "<div>" + text + "<p>" + ename + "</p></div></a></li>"); + } else { + binding.push("<li class='multiline arrow clickable-icon'><a class='delete' href='#selected-exchange?id=" + + b.exchangeRef + "&bindingKey=" + b.bindingKey + "'>" + + "<div>bind [" + b.bindingKey + "] =></div>" + + "<div>" + text + "<p>" + ename + "</p></div></a></li>"); + } + } + } + } else if (b.exchangeRef == exchangeId) { + var queue = qmfui.Queues.getQueue(b.queueRef); // Dereference queueRef + if (queue != null) { + var qname = queue.name; + var ename = object.name; // object is actually exchange in this case. + var text = render(object, b); + + // Note that we don't allow bindings to be deleted from default direct or QMF exchanges. + if (PROTECTED_EXCHANGES[ename]) { + binding.push("<li class='multiline arrow'><a href='#selected-queue?id=" + + b.queueRef + "&bindingKey=" + b.bindingKey + "'>" + + "<div>bind [" + b.bindingKey + "] =></div>" + + "<div>" + text + "<p class='fullwidth'>" + qname + "</p></div></a></li>"); + + } else { + binding.push("<li class='multiline arrow clickable-icon'><a class='delete' href='#selected-queue?id=" + + b.queueRef + "&bindingKey=" + b.bindingKey + "'>" + + "<div>bind [" + b.bindingKey + "] =></div>" + + "<div>" + text + "<p class='fullwidth'>" + qname + "</p></div></a></li>"); + } + } + } + } + + if (binding.length == 0) { + iTablet.renderList($("#bindings-list"), function(i) { + return "<li class='grey'><a href='#'>There are currently no bindings to " + name + "</a></li>"; + }); + } else { + qmfui.renderArray($("#bindings-list"), binding); + + // If _highlightedObject has been set by qmfui.SelectedQueue or qmfui.SelectedExchange search for + // the list item that would have caused navigation to that page and set it active, which causes + // it to be given a highlight that fades as we navigate back to qmfui.Bindings. + if (_highlightedObject) { + $("#bindings-list li").each(function() { + var li = $(this); + // Find the HTML that contains the highlightedObject string and highlightedObjectKey string. + var html = li.html(); + if (html.search(_highlightedObject) != -1 && html.search(_highlightedObjectKey) != -1) { + li.addClass("active"); + } + }); + + _highlightedObject = null; + _highlightedObjectKey = null; + } + } + } + }; + + /** + * This method is called by qmfui.SelectedQueue or qmfui.SelectedExchange to allow qmfui.Bindings to set the + * correct list item highlighting to allow it to fade out as we navigate back to qmfui.Bindings. This is necessary + * because we maintain a singleton qmfui.Bindings page and as such its state will get modified as we navigate + * through multiple queue->binding->exchange->binding etc. Setting the name of the most recent page navigated + * to in this method allows the fading to be handled correctly. + */ + this.setHighlightedBinding = function(name, bindingKey) { + _highlightedObject = name; + _highlightedObjectKey = "bindingKey=" + bindingKey; // Binding keys are always rendered within square braces. + }; + + this.initialise = function() { + $("#bindings").unbind("show").bind("show", qmfui.Bindings.update); + + // Using a click handler here doesn't seem to have the 300ms delay that occurs when using click handlers + // attached to anchors (hence why those use END_EV). It's *probably* because this is a delegating handler. + // JavaScript alert() can interfere with touchend so it's generally better to use click() if it's possible + // to do so without it causing that irritating delay!! + $("#bindings-list").click(clickHandler); + }; +}; // End of qmfui.Bindings definition + + +/** + * Create a Singleton instance of the AddBinding class managing the id="add-binding" page. + */ +qmfui.AddBinding = new function() { + var _queueName = ""; + var _exchangeName = ""; + var _exchangeType = ""; + var _properties = {}; + + /** + * Actually add the new binding using the QMF create method. + */ + var submit = function() { + if (_exchangeType == "headers") { + _properties["x-match"] = $("#x-match input[checked]").val(); + } else if (_exchangeType == "xml") { + _properties = {}; + var textarea = $("#add-xml-binding textarea"); + var xquery = textarea.val(); + if (xquery == "") { + textarea.addClass("error"); + return; + } else { + textarea.removeClass("error"); + _properties["xquery"] = xquery; + } + } else { + _properties = {}; + } + + var bindingKey = $("#add-binding-key-name").val(); + var bindingIdentifier = _exchangeName + "/" + _queueName; + if (bindingKey != "") { + bindingIdentifier = bindingIdentifier + "/" + bindingKey; + } + + // Before we actually add the new binding check to see if a binding with specified bindingIdentifier currently + // exists. It's a slight faff, but the Qpid broker doesn't currently detect this condition. + var duplicateKey = false; + var bindings = qmfui.Console.getBindings(); + for (var i in bindings) { + var b = bindings[i]; + // If a binding with the chosen key is found check if the queue and exchange names match. + if (b.bindingKey == bindingKey) { + var exchange = qmfui.Exchanges.getExchange(b.exchangeRef); // Dereference the exchangeRef. + if (exchange != null && exchange.name == _exchangeName) { + var queue = qmfui.Queues.getQueue(b.queueRef); // Dereference the queueRef. + if (queue != null && queue.name == _queueName) { + duplicateKey = true; + break; + } + } + } + } + + if (duplicateKey) { + alert('A binding with the identifier "' + bindingIdentifier + '" aleady exists.'); + } else { + var arguments = {"type": "binding", "name": bindingIdentifier, "properties": _properties}; + var broker = qmfui.Console.getBroker(true); // Retrieve broker QmfConsoleData object. + broker.invokeMethod("create", arguments, function(data) { + if (data.error_text) { + alert(data.error_text); + } else { + iTablet.location.back(); + } + }); + } + + // Delete the x-match and xquery properties. Note that the other properties are retained, this is + // deliberate because it's quite often the case that one may wish to add several headers bindings + // that may only differ slightly, it's pretty quick to delete match values that aren't needed. + delete _properties["x-match"]; + delete _properties["xquery"]; + }; + + /** + * This method renders the main add-binding page when it is made visible by the show event being triggered. + * It tries to be fairly clever by populating either the queue name or exchange name depending on where + * add-binding was navigated from. If a queueId or exchangeId isn't available navigation is added to the + * queue-selector or exchange-selector page by adding the arrow class to add-binding-queue-name or + * add-binding-exchange-name. This method then checks the exchange type and provides additional rendering + * necessary for XML or Headers exchanges. + */ + var show = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#add-binding") { + return; + } + + var queueId = data.queueId; + var exchangeId = data.exchangeId; + + if (queueId) { + var queue = qmfui.Queues.getQueue(queueId); + _queueName = (queue == null) ? "" : queue.name; + _exchangeName = $("#add-binding-exchange-name p").text(); + if (_exchangeName != "None (default)") { + _exchangeName = _exchangeName.split(" (")[0]; // Remove the exchange type from the text. + } + + var exchange = qmfui.Exchanges.getExchangeByName(_exchangeName); + _exchangeType = (exchange == null) ? "" : exchange.type; + + $("#add-binding-queue-name").removeClass("arrow"); + $("#add-binding-exchange-name").addClass("arrow"); + } else { + _queueName = $("#add-binding-queue-name p").text(); + var exchange = qmfui.Exchanges.getExchange(exchangeId); + _exchangeName = (exchange == null) ? "" : exchange.name; + _exchangeType = (exchange == null) ? "" : exchange.type; + + $("#add-binding-queue-name").addClass("arrow"); + $("#add-binding-exchange-name").removeClass("arrow"); + } + + var typeText = (_exchangeType == "") ? "" : " (" + _exchangeType + ")"; + + $("#add-binding-queue-name p").text(_queueName); + $("#add-binding-exchange-name p").text(_exchangeName + typeText); + + if (_exchangeType == "headers") { + // Render the properties and navigation needed to populate Headers bindings. These are dynamically + // populated and updated as Headers key/value properties get added or deleted. + $("#add-binding div.page h1").show().text("Headers"); + $("#add-headers-binding").show(); + $("#add-xml-binding").hide(); + + var list = []; + list.push("<li class='arrow'><a href='#x-match'>Match<p>" + $("#x-match input[checked]").val() + "</p></a></li>"); + + for (var i in _properties) { + var key = i; + var value = _properties[i]; + // Note we add key/value to the query part of the URL too to let showHeaderMatch() populate the values. + list.push("<li class='arrow clickable-icon'><a class='delete' href='#add-header-match?key=" + key + "&value=" + value + "'>" + key + "<p>" + value + "</p></a></li>"); + } + + list.push("<li class='arrow'><a href='#add-header-match'>Add...</a></li>"); + qmfui.renderArray($("#add-headers-binding"), list); + } else if (_exchangeType == "xml") { + $("#add-binding div.page h1").show().text("XML"); + $("#add-xml-binding").show(); + $("#add-headers-binding").hide(); + } else { + $("#add-binding div.page h1").hide(); + $("#add-headers-binding").hide(); + $("#add-xml-binding").hide(); + } + }; + + /** + * This method renders the add-header-match page when its show event is triggered. This page + * needs a show handler because it needs to be dynamically updated with any previously selected key/value pairs. + */ + var showHeaderMatch = function() { + var location = iTablet.location; + var data = location.data; + var key = ""; + var value = ""; + + if (data != null && location.hash == "#add-header-match") { + key = data.key; + value = data.value; + } + + $("#header-match-key").val(key); + $("#header-match-value").val(value); + }; + + /** + * Adds a a header match value from the binding being populated. + * This is triggered by the "Done" button on the add-header-match page. There's some validation logic + * in place to ensure that a key and value are both supplied. + */ + var addHeaderMatch = function() { + var key = $("#header-match-key"); + var keyVal = key.val(); + var value = $("#header-match-value"); + var valueVal = value.val(); + + if (keyVal == "") { + key.addClass("error"); + } else { + key.removeClass("error"); + } + + if (valueVal == "") { + value.addClass("error"); + } else { + value.removeClass("error"); + } + + if (keyVal != "" && valueVal != "") { + _properties[keyVal] = valueVal; + iTablet.location.back(); + } + }; + + /** + * Removes a header match value from the binding being populated. + * This handler is triggered by clicking a <li class="clickable-icon">. Unfortunately there's bit more work + * to do because we only want to respond if the actual icon has been clicked so we need to work out the + * mouse or tap position within the li and check it's less than the icon width. + * Once we're happy that we've clicked the icon we need to work out which binding the <li> relates to. The + * approach to this is a little messy and involves scraping some of the html associated with the <li> + */ + var removeHeaderMatch = function(e) { + var target = e.target; + var jthis = $(target).closest("ul li.clickable-icon"); + + if (jthis.length != 0) { + var ICON_WIDTH = 45; // The width of the icon image plus some padding. + var offset = Math.ceil(jthis.offset().left); + var x = (e.pageX != null) ? e.pageX - offset : // Mouse position. + (e.originalEvent != null) ? e.originalEvent.targetTouches[0].pageX - offset : 0; // Touch pos. + + if (x < ICON_WIDTH) { + var key = jthis.children("a:first")[0].firstChild.nodeValue; + delete _properties[key]; + $("#add-binding").trigger("show"); + } + } + }; + + this.initialise = function() { + $("#add-binding").unbind("show").bind("show", show); + $("#add-header-match").unbind("show").bind("show", showHeaderMatch); + + // Using END_EV avoids the 300ms delay responding to anchor click events that occurs on mobile browsers. + $("#add-binding .right.button").bind(qmfui.END_EV, submit); + $("#add-header-match .right.button").bind(qmfui.END_EV, addHeaderMatch); + + // Always initialise to default value irrespective of browser caching. + $("#x-match-all").click(); + + // Using a click handler here doesn't seem to have the 300ms delay that occurs when using click handlers + // attached to anchors (hence why those use END_EV). It's *probably* because this is a delegating handler. + // JavaScript alert() can interfere with touchend so it's generally better to use click() if it's possible + // to do so without it causing that irritating delay!! + $("#add-headers-binding").click(removeHeaderMatch); + }; +}; // End of qmfui.AddBinding definition + + +/** + * Create a Singleton instance of the QueueSelector class managing the id="queue-selector" page. + */ +qmfui.QueueSelector = new function() { + var _id; + + /** + * This method renders dynamic content in the ExchangeSelector page. This is necessary because the set + * of exchanges to be rendered may change as exchanges are added or deleted. + */ + var show = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#queue-selector") { + return; + } + + // We pass in the ID of the list ltem that contains the anchor with an href to exchange-selector. + _id = data.id; + + var sourceQueueName = ""; + if (_id == "#add-binding-queue-name") { + $("#queue-selector .header a").text("Add Bin..."); + } else if (_id == "#move-messages-queue-name") { + $("#queue-selector .header a").text("Move Me..."); + sourceQueueName = qmfui.MoveMessages.getSourceQueueName(); // Use this to filter out that queue name. + } + + var queues = qmfui.Console.getQueues(); + var filteredQueues = []; + var currentlySelected = $(_id + " p").text(); + + // Check the status of any Queue that the user may have previously selected prior to hitting "Done". + if (currentlySelected != "None (default)") { + if (qmfui.Queues.getQueueByName(currentlySelected) == null) { // Check if it has been deleted. + alert('The currently selected Queue "' + currentlySelected + '" appears to have been deleted.'); + currentlySelected = "None (default)"; + } + } + + var checked = (currentlySelected == "None (default)") ? "checked" : ""; + filteredQueues.push("<li><label for='queue-selector-queueNone'>None (default)</label><input type='radio' id='queue-selector-queueNone' name='queue-selector' value='None (default)' " + checked + "/></li>"); + + var length = queues.length; + for (var i = 0; i < length; i++) { + var name = queues[i].name; + // We do getQueueByName(name) because the _isQmfQueue property is a "fake" property added by the + // qmfui.Queues class, it's only stored in QMF objects held in the getQueueByName() and getQueue() caches. + var isQmfQueue = qmfui.Queues.getQueueByName(name)._isQmfQueue; + checked = (currentlySelected == name) ? "checked" : ""; + + // Filter out queues bound to QMF exchanges as we don't want to allow additional binding to those. + if (!isQmfQueue && (name != sourceQueueName)) { + filteredQueues.push("<li><label for='queue-selector-queue" + i + "'>" + name + "</label><input type='radio' id='queue-selector-queue" + i + "' name='queue-selector' value='" + name + "' " + checked + "/></li>"); + } + } + + qmfui.renderArray($("#queue-selector-list"), filteredQueues); + $("#queue-selector-list input").change(changeQueue); + }; + + /** + * Event handler for the change event on "#queue-selector-list input". Note that this is bound "dynamically" + * in the show handler because the queue list is created dynamically each time the QueueSelector is shown. + */ + var changeQueue = function(e) { + var jthis = $(e.target); + if (jthis.attr("checked")) { + $(_id + " p").text(jthis.siblings("label").text()); + } + }; + + this.initialise = function() { + $("#queue-selector").unbind("show").bind("show", show); + }; +}; // End of qmfui.QueueSelector definition. + + +//------------------------------------------------------------------------------------------------------------------- +// Generic Graph Rendering Page +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Graphs class managing the id="graphs" page. + */ +qmfui.Graphs = new function() { + var IS_IE = (navigator.appName == "Microsoft Internet Explorer"); + var IE_VERSION = IS_IE ? /MSIE (\d+)/.exec(navigator.userAgent)[1] : -1; + + var SECONDS_AS_NANOS = 1000000000; // One second represented in nanoseconds. + var MILLIS_AS_NANOS = 1000000; // One millisecond represented in nanoseconds. + var HEIGHT = 300; // Canvas height (including radiused borders). + var BORDER = 10; + + var _ctx = null; + + var _radius = new Image(); + _radius.src = "/itablet/images/ie/radius-10px-sprite.png"; + + /** + * qmfui is pretty much browser neutral as browser quirks have been taken care of by jQuery and the + * iTablet framework but canvas support is an edge case. Wrapping a canvas in a <li> doesn't seem to + * work (<li> is where most of the fake border radius stuff is done), so for canvas we simply use the + * canvas rendering itself and use drawImage() to render radius-10px-sprite.png. We use IE_VERSION + * from iTablet to detect the IE version as we only draw borders for IE 7 & 8 as IE9 has fake border-radius + * support and for IE6 radiused borders haven't been done at all because life is too short...... + */ + var drawBorderRadius = function(context) { + if (IE_VERSION == 8 || IE_VERSION == 7) { + var width = context.canvas.width; + var height = context.canvas.height; + + // Draw the border lines. + context.beginPath(); + // Drawing mid point of a pixel e.g. starting at 0.5 is important for getting one pixel lines. + context.rect(0.5, 0.5, width - 2, height - 2); + context.strokeStyle = "black"; + context.stroke(); // Draw new path + + // Render the radiused borders from the radius-10px-sprite.png sprite using canvas drawImage(). + context.drawImage(_radius, 0, 0, 10, 10, 0, 0, 10, 10); + context.drawImage(_radius, 0, 10, 10, 10, 0, height - 10, 10, 10); + context.drawImage(_radius, 10, 0, 10, 10, width - 10, 0, 10, 10); + context.drawImage(_radius, 10, 10, 10, 10, width - 10, height - 10, 10, 10); + } + }; + + + /** + * Aaaargh. Another IE edge case!! + * IE7 has very quirky behaviour - using $("#graphs-time-selector").innerWidth() is unreliable, it + * fails when page is initially shown and calling it also seems to cause the page to take a long + * time to re-render on resize. Using the width of body doesn't have that issue but getting the + * css left value of graphs is unreliable too!!! so I've just coded the values of LEFT & PAGE_WIDTH. + */ + var getWidth = function() { + if (IE_VERSION == 7) { + var LEFT = 251; // .main css left, + var PAGE_WIDTH = 0.9; // .page 100% - padding left + right + var width = $("body").outerWidth(); + width = Math.floor((width - LEFT) * PAGE_WIDTH - 0.5); + return width; + } else { + return ($("#graphs-time-selector").innerWidth() - 2); // The -2 compensates for the border width. + } + }; + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#graphs") { + return; + } + + // Get the latest update of the selected object and populate the text of the back button. + var object = null; + var backText = "Unknown"; + + if (data.queueId) { + object = qmfui.Queues.getQueue(data.queueId); + backText = "Queue"; + $("#graphs").removeClass("exchange connection"); + } else if (data.exchangeId) { + object = qmfui.Exchanges.getExchange(data.exchangeId); + backText = "Exchange"; + $("#graphs").addClass("exchange").removeClass("connection"); + } else if (data.connectionId) { + object = qmfui.Connections.getConnection(data.connectionId); + backText = "Connect..."; + $("#graphs").addClass("connection").removeClass("exchange"); + } + + if (object == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + var property = data.property; // An index to the particular property to be displayed. + var statistics = object._statistics; + + if (statistics == null) { + return; + } + + var description = statistics.description[property]; // Lookup the description of the property. + var isRate = (description == "msgDepth") ? false : true; // Is the statistic a rate. + + // Populate the page header with the property being graphed. + var header = (object.name == null) ? object.address + " " + description : object.name + " " + description; + $("#graphs .header h1").text(header); + + // Using $("#graphs .header a").text(backText) wipes all child elements so use the following. + $("#graphs .header a")[0].firstChild.nodeValue = backText; + + // Populate the graph title with the property being graphed. + if (isRate) { + description += " " + statistics.getRate(property).toFixed(2) + "/sec" + } else if (!statistics.short.isEmpty()) { + description += " " + statistics.short.getLast()[property]; + } + $("#graphs .page h1").text(description); + + var width = getWidth(); + if (_ctx) { + if (width != _ctx.canvas.width) { + _ctx.canvas.width = width; + } + + _ctx.clearRect(0, 0, width, HEIGHT); // Clear previous image. + drawBorderRadius(_ctx); // Draw fake border radius on old versions of IE. + + _ctx.beginPath(); // Start drawing path for grid. + for (var i = BORDER + 0.5; i < width; i += ((width - (BORDER*2))/10)) { // Draw vertical lines + _ctx.moveTo(i, BORDER); + _ctx.lineTo(i, HEIGHT - BORDER); + } + + for (var i = BORDER + 0.5; i < HEIGHT; i += ((HEIGHT - (BORDER*2))/10)) { // Draw horizontal lines + _ctx.moveTo(BORDER, i); + _ctx.lineTo(width - BORDER, i); + } + _ctx.strokeStyle = "#dddddd"; + _ctx.stroke(); // Draw grid. + } + + var stats = statistics.short; // 10 mins + var period = 600*SECONDS_AS_NANOS; // 600 seconds (ten minutes) in nanoseconds. + var interval = $("#graphs-time-selector input:radio[checked]").val(); + if (interval == "oneHour") { + stats = statistics.medium; // 1 hr + period = 3600*SECONDS_AS_NANOS; // 3600 seconds (one hour) in nanoseconds. + + } else if (interval == "oneDay") { + stats = statistics.long; // 1 day + period = 24*3600*SECONDS_AS_NANOS; // 24*3600 seconds (one day) in nanoseconds. + } + + var size = stats.size(); + var isMinimumSize = isRate ? size > 1 : size > 0; + + if (isMinimumSize && _ctx) { + /* + * For reasons of memory efficiency statistics are stored in ring buffers and attached to certain + * management objects (queue, exchange & connection) we only record statistics for certain properties + * of these management objects. For efficiency each item stored in the ring buffer is an array + * containing the statistics for each stored property with the last array item being the update + * timestamp of the management object. Thus the timestamp for each statistic sample is the last + * item (length - 1) of the array. Getting the length of any item held in the stats ring buffer + * gives us the index to use to lookup the timestamp, we use getLast() for convenience get(0) would + * be fine too. The isMinimumSize test ensures we have at least one item in the stats ring buffer. + */ + var TIMESTAMP = stats.getLast().length - 1; + + var curtime = (+new Date() * MILLIS_AS_NANOS); // Current time represented in nanoseconds. + var minimumTimestamp = curtime - period; // Items with timestamps less than this aren't in this period. + var limit = isRate ? size - 1 : size; // Maximum number of sample points. + var graph = [limit]; // Create an array to hold the data we'll put into the graph plot. + var count = 0; // This will be the actual number of sample points that fall within this period. + var i = 0; // Index into statistics circular buffer. + + // Skip over statistics older than the graph period. Mostly this won't happen, but for things like + // iOS where the browser may sleep/hibernate there may be a considerable gap between samples. + while ((i < limit) && (stats.get(i)[TIMESTAMP] < minimumTimestamp)) i++; + + var maxValue = 0; + for (;i < limit; i++, count++) { // i starts with the minimum index, count starts at zero. + var sample = stats.get(i); // Get each statistic sample from the circular buffer. + var value = sample[property]; // Get the sample value. + var timestamp = sample[TIMESTAMP]; // Get the sample timestamp. + + if (isRate) { + var sample1 = stats.get(i + 1); // Get the next sample so we can calculate the rate. + var value1 = sample1[property]; // Get the next sample's value. + var timestamp1 = sample1[TIMESTAMP];// Get the next sample's timestamp. + value = ((value1 - value)*SECONDS_AS_NANOS)/(timestamp1 - timestamp); // Rate in items/s + } + + var x = width + (timestamp - curtime)*(width/period); + graph[count] = {x: x, y: value}; + + if (value > maxValue) { + maxValue = value; + } + } + + var heightNormaliser = (HEIGHT - (2*BORDER))/maxValue; + + _ctx.beginPath(); // Start drawing path for main graph. + var sample = graph[0]; + _ctx.moveTo(sample.x, (maxValue - sample.y)*heightNormaliser + BORDER); + + for (i = 1; i < count; i++) { + sample = graph[i]; + _ctx.lineTo(sample.x, (maxValue - sample.y)*heightNormaliser + BORDER); + } + _ctx.strokeStyle = "black"; + _ctx.stroke(); // Draw main graph. + + // Draw grid text + _ctx.font = "15px Helvetica, Arial, 'Liberation Sans', FreeSans, sans-serif"; + _ctx.fillStyle = "red"; + _ctx.textBaseline = "middle"; + _ctx.textAlign = "right"; + _ctx.fillText(maxValue.toFixed(2), width - BORDER, BORDER); + _ctx.fillText((maxValue/2).toFixed(2), width - BORDER, HEIGHT/2); + _ctx.fillText("0.00", width - BORDER, HEIGHT - BORDER); + } + } + }; + + this.initialise = function() { + $(document).bind("orientationchange", qmfui.Graphs.update); + $(window).resize(qmfui.Graphs.update); + $("#graphs").unbind("show").bind("show", qmfui.Graphs.update); + $("#graphs-time-selector input").change(qmfui.Graphs.update); + + var canvas = $("#graphs-canvas")[0]; + if (canvas != null) { + // The following "shouldn't" be necessary as the graphs-canvas is part of the static markup and it + // works in the author's IE8 XP and Win7 test VMs without it, however getContext("2d") doesn't seem + // to be working on some IE8 deployments so it's added experimentally to see if it fixes the problem. + if (IS_IE && IE_VERSION == 8 && typeof(G_vmlCanvasManager) != "undefined") { + G_vmlCanvasManager.initElement(canvas); + } + + canvas.height = HEIGHT; + if (canvas.getContext) { // Is canvas supported? + _ctx = canvas.getContext("2d"); + } + } + }; +}; // End of qmfui.Graphs definition + + +//------------------------------------------------------------------------------------------------------------------- + + +/** + * Create a Singleton instance of the Links class managing the id="links" page. + * TODO Add link/bridge features. + */ +qmfui.Links = new function() { + + this.update = function() { + + }; + + this.initialise = function() { + }; +}; // End of qmfui.Links definition + + +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the RouteTopology class managing the id="route-topology" page. + * TODO Add link/bridge features. The idea of the route topology page is to "discover" federated brokers linked + * to a "seed" broker. Not sure if this is actually possible, but it'd be pretty cool. + */ +qmfui.RouteTopology = new function() { + + this.initialise = function() { + }; +}; // End of qmfui.RouteTopology definition + + +//------------------------------------------------------------------------------------------------------------------- + +/** + * Create a Singleton instance of the Events class managing the id="events" page. + */ +qmfui.Events = new function() { + var _events = new util.RingBuffer(20); // Store the Event history in a circular buffer. + + this.getEvent = function(index) { + return _events.get(index); + }; + + this.update = function(workItem) { + if (workItem._type == "EVENT_RECEIVED") { + var params = workItem._params; + var agent = params.agent; + + if (agent._product == "qpidd") { // Only log events from the broker ManagementAgent + _events.put(params.event); + iTablet.renderList($("#events-list"), function(i) { + var event = _events.get(i); + var name = event._schema_id._class_name; + var timestamp = new Date(event._timestamp/1000000).toLocaleString(); + var text = name; + + return "<li class='multiline arrow'><a href='#selected-event?index=" + i + "'>" + i + " " + text + + "<p class='sub'>" + timestamp + "</p></a></li>"; + }, _events.size()); + } + } + }; +}; // End of qmfui.Events definition + +/** + * Create a Singleton instance of the SelectedEvent class managing the id="selected-event" page. + */ +qmfui.SelectedEvent = new function() { + var _severities = ["emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"]; + + this.update = function() { + var location = iTablet.location; + var data = location.data; + if (data == null || location.hash != "#selected-event") { + return; + } + + // Get the latest update of the selected event object. + var index = parseInt(data.index); // The parseInt is important! Without it the index lookup gives odd results.. + var event = qmfui.Events.getEvent(index); + + if (event == null) { + $("#resource-deleted").show(); + } else { + $("#resource-deleted").hide(); + + // Populate the page header with the event name. + var name = event._schema_id._package_name + ":" + event._schema_id._class_name; + $("#selected-event .header h1").text(name); + + var general = []; + var timestamp = new Date(event._timestamp/1000000).toLocaleString(); + general.push("<li><a href='#'>timestamp<p>" + timestamp + "</p></a></li>"); + general.push("<li><a href='#'>severity<p>" + _severities[event._severity] + "</p></a></li>"); + qmfui.renderArray($("#selected-event-list"), general); + + var values = []; + for (var i in event._values) { // Populate with event _values properties. + var value = event._values[i]; + if (i == "args" || i == "properties") { // If there are any args try and display them. + value = util.stringify(value); + } + values.push("<li><a href='#'>" + i + "<p>" + value + "</p></a></li>"); + } + qmfui.renderArray($("#selected-event-values"), values); + } + }; + + this.initialise = function() { + $("#selected-event").unbind("show").bind("show", qmfui.SelectedEvent.update); + }; +}; // End of qmfui.SelectedEvent definition + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/LICENCE b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/LICENCE new file mode 100644 index 0000000000..e62925ae88 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/LICENCE @@ -0,0 +1,23 @@ +/* + * qpid.js + * + * 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. + * + */ + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/qpid.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/qpid.js new file mode 100644 index 0000000000..f1ad4711f2 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/qpid/scripts/qpid.js @@ -0,0 +1,745 @@ +/** + * http://www.apache.org/licenses/LICENSE-2.0 + * + * This library provides a JavaScript implementation of the QMF2 API (and TODO qpid::messaging - some code is in place + * for Connection as necessary to implement the QMF2 API the rest will follow in due course. + * + * This implementation of the QMF2 API relies on the Qpid REST API as a back end server and the QMF2 API methods + * are basically proxies by the Qpid REST API to a real QMF2 Console implemented on the back end. Note that this + * implementation uses AJAX/REST over pure HTTP which results in some inefficiencies, in particular the mechanism + * used to retrieve QMF2 Events (getWorkItem()) uses the AJAX long-polling pattern. It should be possible to + * provide an alternative implementation using WebSockets, the main two reasons that this hasn't been done are. + * 1) The author lacks familiarity with WebSockets.... + * 2) WebSockets have much poorer cross-browser support, though to be fair that could be mitigated using a + * WebSocket JavaScript library that could fall back to using HTTP if browser/server support was unavaiable. + * + * This library also includes a utility package providing a number of useful classes and helper functions. These + * aren't strictly part of qpid/qmf JavaScript but stringify() and randomUUID() are used by qpid.js so including + * the util package in this library avoids adding yet another dependency. + * + * It has dependencies on the following: + * jquery.js (> 1.5) + * + * author Fraser Adams + */ + +//------------------------------------------------------------------------------------------------------------------- + +// Create a new namespace for the util "package". +var util = {}; + +/** + * This debug method lists the properties of the specified JavaScript object. + * @param obj the object that we wish to list the properties for. + " @return a string containing the list of the object's properties pretty printed. + */ +util.displayProperties = function(obj) { + var result = obj + "\n\n"; + var count = 0; + for (var i in obj) { + result += i + ", "; + if (count % 4 == 3) result += "\n"; + count++; + } + result = result.substring(0, result.lastIndexOf(",")); + return result; +}; + +/** + * Stringify an Object into JSON. Uses JSON.stringify if present and if not it uses a quick and dirty serialiser. + * @param obj the object that we wish to stringify into JSON. + * @return the JSON representation of the specified object. + */ +util.stringify = function(obj) { + var fromObject = function(obj) { + if (Object.prototype.toString.apply(obj) === '[object Array]') { + var string = ""; + var length = obj.length; + for (var i = 0; i < length; i++) { + string += fromObject(obj[i]); + if (i < length - 1) { + string += ","; + } + } + + string = "[" + string + "]"; + return string; + } else if (typeof obj == "object") { // Check if the value part is an ObjectId and serialise appropriately + if (!obj) { + return "null"; + } + + var string = ""; + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + if (string != "") { + string += ","; + } + string += '"' + i + '":' + fromObject(obj[i]); + } + } + + string = "{" + string + "}"; + return string; + } else if (typeof obj == "string") { + return '"' + obj + '"'; + } else { + return obj.toString(); + } + }; + + if (obj == null) { + return ""; + } if (window.JSON && JSON.stringify && typeof JSON.stringify == "function") { + return JSON.stringify(obj); + } else { + var string = fromObject(obj); + return string; + } +}; + +/** + * Compact rfc4122v4 UUID from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript + * @return an rfc4122v4 UUID. + */ +util.randomUUID = function() { + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { + var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); + return v.toString(16); + }); +}; + +/** + * This is a JavaScript port of the "fill count" example from http://en.wikipedia.org/wiki/Circular_buffer + * @param size maximum size of the RingBuffer that we want to construct, when items are added beyond this size + * they will wrap around. + */ +util.RingBuffer = function(size) { + var _size = size; + var _start = 0; + var _count = 0; + var _elems = new Array(size); + + /** + * @return the maximum size of the RingBuffer. + */ + this.capacity = function() { + return _size; + }; + + /** + * @return the number of items currently stored in the RingBuffer. + */ + this.size = function() { + return _count; + }; + + /** + * @return true if the buffer is full otherwise return false. + */ + this.isFull = function() { + return _count == _size; + }; + + /** + * @return true if the buffer is empty otherwise return false. + */ + this.isEmpty = function() { + return _count == 0; + }; + + /** + * Add an item to the end of the buffer, overwriting oldest element if buffer is full. + * A client can choose to avoid the overwrite by checking IsFull(). + * @param the item that we wish to add to the end of the ring buffer. + */ + this.put = function(item) { + var end = (_start + _count) % _size; + _elems[end] = item; + if (_count == _size) { + _start = (_start + 1) % _size; // full, overwrite + } else { + ++_count; + } + }; + + /** + * Read and remove oldest item from buffer. N.B. clients must ensure !isEmpty() first. + * @return the oldest item from the ring buffer. + */ + this.take = function() { + var item = _elems[_start]; + _start = (_start + 1) % _size; + --_count; + return item; + }; + + /** + * Read the item at the specified (circular) index non-destructively e.g. index 0 is the first item held in + * the ring buffer index size() - 1 is the last item (which is the equivalent of getLast()). + * @return the specified ring buffer item. + */ + this.get = function(index) { + index = (_start + index) % _size; + return _elems[index]; + }; + + /** + * @return the last item, or null if no entries are present. + */ + this.getLast = function() { + if (_count == 0) { + return null; + } else { + return this.get(_count - 1); + } + }; +}; + + +//------------------------------------------------------------------------------------------------------------------- +/** + * This package is a proxy to the Qpid REST API, which is itself a proxy to a real Qpid API. + * It attempts to mimic the Qpid Messaging API where possible (given the asynchronous constraints of JavaScript). + */ + +// Create a new namespace for the qpid "package". +var qpid = {}; + +/** + * This factory class will attempt to create a Connection object and creates an opaque handle to it internally + * which will be used in the URI of subsequent Qpid/QMF calls to the Qpid REST API. + * + * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL. + * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging Connection class. + * @return a Connection object which is a proxy to the Qpid REST API, which is itself a proxy to a real Qpid API. + */ +qpid.ConnectionFactory = function(url, connectionOptions) { + + /** + * This class is a proxy to the Qpid REST API PUT method for creating Connections. + * @param url an AMQP 0.10 URL, an extended AMQP 0-10 URL, a Broker URL or a Java Connection URL. + * @param opts a String containing the options encoded using the same form as the C++ qpid::messaging Connection. + */ + var Connection = function(url, connectionOptions) { + var _disableEvents = false; + var _available = false; + var _url = url; + var _handle = util.randomUUID(); + var _defaultCallback = function(connection) {}; + var _callback = _defaultCallback; + var _failureCallback = _defaultCallback; + + /** + * The success callback method for the AJAX call invoked by putConnection(). This method marks the + * Connection as available and calls the callback method registered by the call to open(). + */ + var putConnectionSucceeded = function() { + _available = true; + _callback(this); + }; + + /** + * The failure callback method for the AJAX call invoked by putConnection(). This method calls the callback + * method registered by the call to open(). + */ + var putConnectionFailed = function(xhr) { + _available = false; + _failureCallback(this); + }; + + /** + * Create a Connection object on the REST API via an asynchronous HTTP PUT method. + */ + var putConnection = function() { + var data = {url: _url}; + if (connectionOptions != null && connectionOptions != "") { + data.connectionOptions = connectionOptions; + } + + if (_disableEvents) { + data.disableEvents = true; + } + + // Serialise the data Object into a JSON String. + data = util.stringify(data); + + $.ajax({ + type: "PUT", + url: "../qpid/connection/" + _handle, + cache: false, + contentType: "application/json", + data: data, + timeout: 10000, + success: putConnectionSucceeded, + error: putConnectionFailed + }); + }; + + /** + * Remove a Connection object on the REST API via a synchronous HTTP DELETE method. + */ + var deleteConnection = function() { + //console.log("**** calling qpid.Connection deleteConnection() ****"); + /** + * Explicitly retrieve the XmlHttpRequest and send the DELETE via a low-level synchronous call because + * JQuery 1.8 has deprecated the async: false setting on $.ajax. There's some debate about this - see + * http://bugs.jquery.com/ticket/11013 the gist is that synchronous requests can prevent the rest of + * the $.ajax plumbing and dependencies from being fixed. In an ideal world asynchronous requests + * are almost always preferable, however in mobile Safari (at least) asynchronous calls won't get + * fired from onpagehide handlers, which messes up some useful garbage collection when navigating away. + * TODO I wonder how delete onpageunload is going to work if I want to use JSONP...... + */ + var xhr = $.ajaxSettings.xhr(); // At least we can get the XMLHttpRequest in a platform neutral way. + xhr.open("DELETE", "../qpid/connection/" + _handle, false); // Low level synchronous DELETE. + xhr.send(null); + }; + + /** + * Calling this method results in a QMF2 Console being created that can only perform synchronous calls such + * as getObjects() and can't do asynchronous things like receive Agent updates and QMF2 Events. + * + * This method must be called besfore addConnection() in order to take effect. + */ + this.disableEvents = function() { + _disableEvents = true; + } + + /** + * Open the Connection object for use. + * @param successCallback a handler to be called when open() has successfully established the Qpid Connection. + * we include the callback method because JavaScript networking is fundamentally asynchronous so open() + * won't block as it would with other languages, the callback provides a way to defer execution of subsequent + * code until the Connection is established. + * @param failureCallback a handler to be called when open() has failed to established the Qpid Connection. + * Note that this will only be called if creating the connection is impossible, that is to say an exception + * got thrown by the REST API PUT mothod. If the broker is simply down the Connection proxy will get created + * on the server side and the successCallback will be called. + */ + this.open = function(successCallback, failureCallback) { + if (successCallback != null) { + _callback = successCallback; + } + + if (failureCallback != null) { + _failureCallback = failureCallback; + } + + _available = false; + putConnection(); + }; + + /** + * Close the Connection object. + */ + this.close = function() { + deleteConnection(); + _available = false; + }; + + /** + * Identify whether the Connection is open for use. + * @return true if the Connection is open, otherwise returns false. + */ + this.isAvailable = function() { + return _available; + }; + + /** + * Retrieve the Connection's "handle" which is used as part of its URI on the REST API. + * @return a String containing the handle UUID. + */ + this.toString = function() { + return _handle; + }; + }; + + /** + * Factory method used to construct a new Connection object. + * @return a new Connection object. + */ + this.createConnection = function() { + return new Connection(url, connectionOptions); + }; +}; + +//------------------------------------------------------------------------------------------------------------------- + +// Create a new namespace for the qmf "package". +var qmf = {}; +qmf.REFRESH_PERIOD = 10000; + +/** + * This class is a proxy to the QMF REST API, which is itself a proxy to a real QMF2 Console. + * It attempts to mimic the QMF2 API where possible however there are a few deviations because of the entirely + * asynchronous nature of JavaScript and AJAX. + * + * Constructor that provides defaults for name and domain and takes a Notifier/Listener. + * @param onEvent a QMFEventListener. + */ +qmf.Console = function(onEvent) { + var _disableEvents = false; + var _connection = null; + var _url = "../qpid/connection/"; + var _qmfEventListenerXHR; // Retain JQuery XHR object for QmfEventListener so we can abort request if needed. + + /** + * Send and "AGENT_DELETED" WorkItem for qpidd to the registered Event Listener. + */ + var sendBrokerDisconnectedEvent = function() { + var agent = {_vendor: "apache.org", _product: "qpidd", _instance: "1234", + _name: "apache.org:qpidd:1234", _epoch: 1, _heartbeat_interval: 10}; + onEvent({_type: "AGENT_DELETED", _params: {agent: agent}}); + }; + + /** + * Send and "AGENT_DELETED" WorkItem for qpid.restapi to the registered Event Listener. + */ + var sendRestApiDisconnectedEvent = function() { + var agent = {_vendor: "apache.org", _product: "qpid.restapi", _instance: "1234", + _name: "apache.org:qpid.restapi:1234", _epoch: 1, _heartbeat_interval: 10}; + onEvent({_type: "AGENT_DELETED", _params: {agent: agent}}); + }; + + /** + * Retrieve QMF2 WorkItems via the QMF2 REST API, note that this call may block (on the server). + */ + var dispatchEvents = function() { + if (_connection != null) { + _qmfEventListenerXHR = $.ajax({ + url: _url + "/console/nextWorkItem", + cache: false, + dataType: "json", + timeout: 3*qmf.REFRESH_PERIOD, + success: handleDispatchEventsSuccess, + error: handleDispatchEventsFailure + }); + } + }; + + /** + * Success callback method for dispatchEvents. When WorkItems are available they are delivered to the attached + * eventListener onEvent callback and dispatchEvents is called again to wait for the next WorkItem. + * @param data the QMF2 WorkItem data. + */ + var handleDispatchEventsSuccess = function(data) { + if (_connection != null) { + onEvent(data); + dispatchEvents(); + } + }; + + /** + * Failure callback method for dispatchEvents. This method sends "AGENT_DELETED" WorkItems to the registered + * Event Listener and attempts to re-establish a connection to the REST API and via the the broker. + * @param xhr the jQuery XHR object. + */ + var handleDispatchEventsFailure = function(xhr) { + //console.log("handleDispatchEventsFailure " + xhr.status + " " + xhr.statusText); + if (xhr.status == 0 || xhr.status == 12029) { // For some reason IE7 sends 12029?? + if (xhr.statusText == "timeout") { // If AJAX calls have timed out it's likely due to a failed broker. + sendBrokerDisconnectedEvent(); + } else { + sendRestApiDisconnectedEvent(); // If the status is 0 for another reason the server is probabbly down. + } + } else if (xhr.status == 404) { + // HTTP Not Found. This is most likely to mean that the Console has timed out and been garbage collected + // on the REST API Server so we simply attempt to re-open the Qpid Connection. + if (_connection != null && _connection.open) { + _connection.open(); + } + } else if (xhr.status == 500) { + // HTTP Internal Error. Sent by the REST API Server when it knows that the broker has disconnected. + sendBrokerDisconnectedEvent(); + } + + // If the failure wasn't caused by an abort we retry after a timeout. + if (xhr.statusText != "abort" && _connection != null) { + setTimeout(dispatchEvents, qmf.REFRESH_PERIOD); + } + }; + + /** + * Helper method to allow us to get the data from a specified resource from the REST API in the /console/ sub-path + * Most of the core QMF2 API mehods can make use of this. + * @param resourceName the name of the resource on the REST Server. This is the part of the resource after + * the connection e.g. "/console/objects/" + className for the getObjects() call. + * @param handler the callback handler if the AJAX GET is successful. + * @return the jQuery XHR Object. + */ + var getResource = function(resourceName, handler) { + return $.ajax({ + url: _url + resourceName, + cache: false, + dataType: "json", + timeout: 3*qmf.REFRESH_PERIOD, + success: handler + }); + }; + + // ******** QmfConsoleData Methods that will be attached to QmfData Objects via makeConsoleData()********** + + /** + * Invoke the named method using the supplied inArgs, the response occurs asynchronously and triggers the + * named handler method, the outArgs are sent as JSON to the data parameter of the handler method. + * Note that this method is intended to be attached to a QmfData JavaScript object. It will use the ObjectId + * of the QmfData object to determine the URL resource to POST the data to. + */ + var invokeMethod = function(name, inArgs, handler) { + //console.log("calling invokeMethod: " + name + ", oid: " + this._object_id); + var defaultHandler = function(data) {}; + + var postFailed = function(xhr) { + var error = xhr.responseText; + if (xhr.status != 500) { + error = (xhr.status == 0) ? "POST failed to return correctly." : xhr.statusText; + } + + handler({"error_text" : error}); + }; + + inArgs = (inArgs == null || typeof inArgs == "string") ? inArgs : util.stringify(inArgs); + handler = (handler == null) ? defaultHandler : handler; + + var data = (inArgs == null) ? '{"_method_name":"' + name + '"}' : + '{"_method_name":"' + name + '","_arguments":' + inArgs + '}'; + + $.ajax({ + type: "POST", + url: _url + "/object/" + this._object_id, + cache: false, + headers : {"cache-control": "no-cache"}, // Curtails iOS6 overly aggressive (incorrect!) caching. + contentType: "application/json", + data: data, + timeout: 10000, + success: handler, + error: postFailed + }); + }; + + /** + * Request that the Agent updates the value of this object's contents. + * @param handler a callback method to handle the asynchronously delivered object refresh. + * One slight quirk of the JavaScript implementation is that the state update occurs asynchronously which will + * affect code that tries to use the state immediately after a call to object.refresh(). The optional handler + * parameter allows client code to defer its code to a callback that gets triggered after the state update. + */ + var refresh = function(handler) { + var self = this; // So we use the correct this in the update method.... + + var update = function(data) { + // Save these timestamps from the original object as they are not correctly populated by the ManagementAgent. + var savedCreateTime = self._create_ts; + var savedDeleteTime = self._delete_ts; + + if (handler == null) { + // If no handler is supplied we update the state of the object itself. + + // Replace all of the current properties with the ones from the JSON response object. + for (var i in data) { + self[i] = data[i] + } + + // Restore the correct timestamps. + self._create_ts = savedCreateTime; + self._delete_ts = savedDeleteTime; + } else { + // If a handler is supplied we pass the JSON object returned from the query having set the correct + // timestamps and turned back into a QmfConsoleData. + // Restore the correct timestamps. + data._create_ts = savedCreateTime; + data._delete_ts = savedDeleteTime; + data.invokeMethod = self.invokeMethod; + data.refresh = self.refresh; + handler(data); + } + }; + + return getResource("/object/" + this._object_id, update); + } + + // ******************************************** Public Methods ******************************************** + + /** + * Calling this method results in a QMF2 Console being created that can only perform synchronous calls such + * as getObjects() and can't do asynchronous things like receive Agent updates and QMF2 Events. + * Note that "asynchronous" here relates to the underlying QMF Console created on the Server, as this is a + * JavaScript API things like getObjects() results still arrive asynchronously. + * + * This method must be called besfore addConnection() in order to take effect. + */ + this.disableEvents = function() { + _disableEvents = true; + } + + /** + * Connect the console to the AMQP cloud. + * + * @param connection a JavaScript qpid.Connection object. Alternatively if the handle string to the Connection + * object on the server is known this string can be supplied instead. This is most likely to be the case where + * the default QMF Console on the REST API Server is used e.g. by doing _console.addConnection("default"); + * @param failureCallback a handler to be called when addConnection() has failed to established the Qpid Connection. + * Note that this will *only* be called if creating the connection is impossible, that is to say an exception + * got thrown by the REST API PUT mothod. If the broker is simply down the Connection proxy will get created + * on the server side and the successCallback will be called. + */ + this.addConnection = function(connection, failureCallback) { + _connection = connection; + _url = _url + _connection.toString(); + + if (_connection.open) { + if (_disableEvents) { + _connection.disableEvents(); + _connection.open(null, failureCallback); + } else { + _connection.open(dispatchEvents, failureCallback); + } + } else { // Use this case if the connection that is passed in is just a string "handle" to the connection + dispatchEvents(); + } + }; + + /** + * Remove the AMQP connection from the console. Un-does the addConnection() operation. Note that because this + * API implementation is really a proxy removeConnection() just aborts any AJAX calls for the console. + * + * @param connection a JavaScript qpid.Connection object + */ + this.removeConnection = function(connection) { + if (_connection == connection) { + _connection = null; + + if (_qmfEventListenerXHR) { + _qmfEventListenerXHR.abort(); + } + } + }; + + /** + * Release the Console's resources. + */ + this.destroy = function() { + //console.log("Console.destroy()"); + this.removeConnection(_connection); + }; + + /** + * Perform a query for QmfData objects. In a difference to the specified QMF2 API rather than returning a list + * (possibly empty) of matching objects this JavaScript version triggers a callback, the data parameter of + * which contains the list of matching objects. Usage example: + * _console.getObjects("broker", function(data) {_objects.broker = data;}); + * + * @param className the class name QMF Management Objects that we wish to retrieve. + * TODO packageName and agentName. + * @param handler a handler to be called when getObjects() has successfully retrieved the specified objects. + * we include the callback method because JavaScript networking is fundamentally asynchronous so getObjects() + * won't block as it would with other languages, the callback provides a way to defer execution of subsequent + * code until the objects have been returned. + * @return returns the jQuery XHR object. In particular the reson for returning this is that it is a "Deferred" + * object, what this means is that is can be used to wait until the results from several getObjects() calls + * have returned before executing an overall callback. + */ + this.getObjects = function(className, handler) { + // TODO allow options to specify Package name and Agent name. + return getResource("/console/objects/" + className, handler); + }; + + /** + * The items returned by getObjects are really pure QmfData (really QmfManaged) Objects, they are data Objects + * with no methods. This is normally OK because most applications simply want to retrieve the properties/stats + * but there are occasions where some of the QmfConsoleData methods are useful. Rather than add the methods + * universally this method enables them to be added to specific QmfData instances. This approach is more + * efficient as the QmfData objects are created by the browser deserialising JSON and it seems a bit wasteful + * to iterate through turning the JSON data into full QmfConsoleData Objects when the methods are rarely used. + * @param data the QmfData object that we want to turn into a QmfConsoleData. + */ + this.makeConsoleData = function(data) { + data.invokeMethod = invokeMethod; + data.refresh = refresh; + }; + + /** + * Get the AMQP address this Console is listening to. + * + * @param handler a callback method to handle the asynchronously delivered response. + * the data passed to the handler contains the console's replyTo address. Note that there are actually two, + * there's a synchronous one which is the return address for synchronous request/response type invocations and + * there's an asynchronous address with a ".async" suffix which is the return address for asynchronous invocations. + * @return returns the jQuery XHR object. See getObjects() documentation for more details on why. + * + * _console.getAddress(function(data) {console.log(data)}); // Example usage. + */ + this.getAddress = function(handler) { + return getResource("/console/address", handler); + }; + + /** + * Gets a list of all known Agents. + * + * @param handler a callback method to handle the asynchronously delivered response. + * the data passed to the handler contains a list of all known Agents as a JSON array each item in the array is + * a QMF Agent object in JSON form. + * @return returns the jQuery XHR object. See getObjects() documentation for more details on why. + * + * _console.getAgents(function(data) {console.log(data)}); // Example usage. + */ + this.getAgents = function(handler) { + return getResource("/console/agents", handler); + }; + + /** + * Gets the named Agent, if known. + * + * @param agentName the name of the Agent to be returned. + * @param handler a callback method to handle the asynchronously delivered response. + * the data passed to the handler is the QMF Agent object in JSON form. + * @return returns the jQuery XHR object. See getObjects() documentation for more details on why. + * + * _console.getAgent("qpidd", function(data) {console.log(data)}); // Example usage. + */ + this.getAgent = function(agentName, handler) { + return getResource("/console/agent/" + agentName, handler); + }; + + /** + * In this implementation findAgent() is a synonym for getAgent(). + */ + this.findAgent = function(agentName, handler) { + return getResource("/console/agent/" + agentName, handler); + }; + + /** + * Gets a list of all known Packages. + * @param handler a callback method to handle the asynchronously delivered response. + * the data passed to the handler is a list of all available packages as a JSON array. + * @return returns the jQuery XHR object. See getObjects() documentation for more details on why. + * + * _console.getPackages(function(data) {console.log(data)}); // Example usage. + */ + this.getPackages = function(handler) { + // TODO handle getPackages() for specified Agent. + return getResource("/console/packages", handler); + }; + + /** + * Gets a List of SchemaClassId for all available Schema. + * @param handler a callback method to handle the asynchronously delivered response. + * the data passed to the handler is a list of all available classes as a JSON array of SchemaClassId. + * @return returns the jQuery XHR object. See getObjects() documentation for more details on why. + * + * _console.getClasses(function(data) {console.log(data)}); // Example usage. + */ + this.getClasses = function(handler) { + // TODO handle getClasses() for specified Agent + return getResource("/console/classes", handler); + }; + + /** + * TODO + * getSchema() - should be easy as the REST API supports it. + * createSubscription() - harder as the REST API doesn't yet support it. + * refreshSubscription() - harder as the REST API doesn't yet support it. + * cancelSubscription() - harder as the REST API doesn't yet support it. + */ +}; + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/config.js b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/config.js new file mode 100644 index 0000000000..a37de988ca --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/config.js @@ -0,0 +1,37 @@ +/* + * + * 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. + * + */ + +/** + * This file allows the initial set of Console Connections to be configured and delivered to the client. + * The format is as a JSON array of JSON objects containing a url property and optional name, connectionOptions and + * disableEvents properties. The connectionOptions property has a value that is itself a JSON object containing + * the connectionOptions supported by the qpid::messaging API. + */ + +/* +// Example Console Connection Configuration. +qmfui.Console.consoleConnections = [ + {name: "default", url: ""}, + {name: "localhost", url: "localhost:5672"}, + {name: "wildcard", url: "anonymous/@0.0.0.0:5672", connectionOptions: {sasl_mechs:"ANONYMOUS"}, disableEvents: true} +]; +*/ + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/qmf.html b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/qmf.html new file mode 100644 index 0000000000..60977fbad0 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/qpid-web/web/ui/qmf.html @@ -0,0 +1,1208 @@ +<!DOCTYPE html> + +<!-- + 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. +--> + +<html> +<head> + <title>QMF Console</title> + <link rel="stylesheet" type="text/css" href="/itablet/css/itablet.css"/> + <link rel="stylesheet" type="text/css" href="/qmf-ui/css/qmf.css"/> +<!--[if IE 9]> + <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie9.css" /> +<![endif]--> +<!--[if (lte IE 8) & (gt IE 6)]> + <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie8.css" /> +<![endif]--> +<!--[if IE 7]> + <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie7.css" /> +<![endif]--> +<!--[if lte IE 6]> + <link rel="stylesheet" type="text/css" href="/itablet/css/itablet-ie6.css" /> +<![endif]--> + + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + + <!-- Changes the logical window size used when displaying a page on iOS. --> + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/> + + <!-- Sets whether a web application runs in full-screen mode. --> + <meta name="apple-mobile-web-app-capable" content="yes"/> + <meta name="apple-mobile-web-app-status-bar-style" content="black"/> + + <!-- Sets home screen icon. --> + <link rel="apple-touch-icon" href="/apple-touch-icon.png" /> + + + <!-- Sets home screen icon. --> +<!-- + <link rel="apple-touch-startup-image" href="/startup-landscape.png" /> +--> + + <script src="/itablet/scripts/jquery.js"></script> + <script src="/itablet/scripts/iscroll.js"></script> + <script src="/itablet/scripts/itablet.js"></script> + <script src="/qpid/scripts/qpid.js"></script> + <script src="/qmf-ui/scripts/qmf-ui.js"></script> + <script src="/ui/config.js"></script> +<!--[if lte IE 8]> + <script type="text/javascript" src="/qmf-ui/scripts/excanvas.js"></script> +<![endif]--> + +</head> + + +<body> + +<!-- display simple splash screen as app loads --> +<div id="splash"> + <div class="logo"> + <div class="loading"> + </div> + </div> +</div> <!-- End of splash --> + +<!-- The blocks provide banner style displays when an error occurs --> +<div id="resource-deleted" class="alert">Resource Deleted</div> +<div id="broker-disconnected" class="alert">Broker Disconnected</div> +<div id="restapi-disconnected" class="alert">RestAPI Disconnected</div> +<div id="failed-to-connect" class="alert">Failed to Connect</div> + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Menu/Sidebar --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="menu" class="sidebar"> + <div class="header"> + <h1>QMF Console</h1> + </div> + + <div id="sidebar-scroller" class="scroll-area"> + <ul class="contents"> + <li id="settings-tab" class="icon"><a class="settings" href="#settings">Settings</a></li> + <li id="broker-tab" class="icon"><a class="brokers" href="#broker">Broker</a></li> + <li id="connections-tab" class="icon"><a class="connections" href="#connections">Connections</a></li> + <li id="exchanges-tab" class="icon"><a class="exchanges" href="#exchanges">Exchanges</a></li> + <li id="queues-tab" class="icon"><a class="queues" href="#queues">Queues</a></li> +<!-- TODO add link/bridge features a la qpid-route + <li id="links-tab" class="icon"><a class="links" href="#links">Links</a></li> + <li id="route-topology-tab" class="icon"><a class="route-topology" href="#route-topology">Route Topology</a></li> +--> + <li id="events-tab" class="icon"><a class="events" href="#events">Events</a></li> + </ul> + </div> +</div> + + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Settings --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="settings" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Settings</h1> + </div> + + <div id="settings-scroller" class="scroll-area"> + <div class="page"> + + <ul id="settings-add-console" class="list"> + <li class="pop"><a href="#add-console-connection">Add QMF Console Connection</a></li> + </ul> + + <h1>Available Brokers</h1> + <ul id="qmf-console-selector" class="list"> + <li class="arrow"> + <label for="qmf-console0">default</label> + <input type="radio" id="qmf-console0" name="qmf-console-selector" checked /> + <a href="#selected-qmf-console-connection"></a> + </li> + </ul> + <p class="note">Note that selecting a new Broker Connection will clear statistics/graphs.</p> + + <ul class="list"> + <li> + <label for="settings-hide-qmf-objects">Hide QMF Objects</label> + <input type="checkbox" id="settings-hide-qmf-objects" /> + </li> + </ul> + <p class="note">Hide Exchanges and Queues that relate to QMF.</p> + + <div id="settings-hide-details-container"> + <ul class="list"> + <li> + <label for="settings-hide-details">Hide Details</label> + <input type="checkbox" id="settings-hide-details" checked /> + </li> + </ul> + </div> + <p class="note">Hide Flow to Disk & Dequeue Details.</p> + </div> <!-- End of page --> + </div> <!-- End of settings-scroller --> +</div> <!-- End of settings --> + +<div id="selected-qmf-console-connection" class="main"> + <div class="header"> + <a class="back button" href="#">Settings</a> + <h1>QMF Console Connection</h1> + + <span class="toolbar"> + <a class="delete" href="#"></a> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="selected-qmf-console-connection-scroller" class="scroll-area"> + <div class="page"> + <ul class="list"> + <li id="selected-qmf-console-connection-url"><a href="#">URL<p>url</p></a></li> + <li id="selected-qmf-console-connection-name"><a href="#">Name<p>name</p></a></li> + <li id="selected-qmf-console-connection-events-disabled"><a href="#">Events Disabled<p>false</p></a></li> + </ul> + <p id="selected-qmf-console-connection-default-info" class="note nopadding">A default URL means that the Connection URL configured on the QpidRestAPI server is being used.</p> + + <div id="selected-qmf-console-connection-connection-options"> + <h1>Connection Options</h1> + <ul class="list"> + <li><textarea readonly></textarea></li> + </ul> + </div> + </div> <!-- End of page --> + </div> <!-- End of selected-qmf-console-connection-scroller --> +</div> <!-- End of selected-qmf-console-connection --> + + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Broker Information --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="broker" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Broker</h1> + </div> + + <div id="broker-scroller" class="scroll-area"> + <div class="page"> + <ul id="broker-list" class="list"> + <li class><a href="#">Broker row 1</a></li> + </ul> + + <div id="broker-msgio-container"> + <h1>Message Input/Output</h1> + <ul id="broker-msgio" class="list"> + <li><a href="#">Broker row 1</a></li> + </ul> + </div> + + <div id="broker-byteio-container"> + <h1>Byte Input/Output</h1> + <ul id="broker-byteio" class="list"> + <li><a href="#">Broker row 1</a></li> + </ul> + </div> + + <div id="broker-flow-to-disk-container"> + <h1>Flow to Disk</h1> + <ul id="broker-flow-to-disk" class="list"> + <li><a href="#">Broker row 1</a></li> + </ul> + </div> + + <div id="broker-dequeue-container"> + <h1>Dequeue Details</h1> + <ul id="broker-dequeue" class="list"> + <li><a href="#">Broker row 1</a></li> + </ul> + </div> + + <h1>Set Log Level</h1> + <ul id="broker-log-level" class="list"> + <li> + <label for="broker-log-normal">Normal</label> + <input type="radio" id="broker-log-normal" name="broker-log-level" value="normal" checked /> + </li> + <li> + <label for="broker-log-debug">Debug</label> + <input type="radio" id="broker-log-debug" name="broker-log-level" value="debug"/> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of broker-scroller --> +</div> <!-- End of broker --> + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Connection Information --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="connections" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Connections</h1> + </div> + + <div id="connections-scroller" class="scroll-area"> + <div class="page"> + <ul id="connections-list" class="list"> + <li class="arrow"><a href="#selected-connection">Dummy Connection</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of connections-scroller --> +</div> <!-- End of connections --> + +<div id="selected-connection" class="main"> + <div class="header"> + <a class="back button" href="#">Connect...</a> + <h1>Selected Connection</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="selected-connection-scroller" class="scroll-area"> + <div class="page"> + <h1 class="first">Message Input/Output</h1> + <ul id="selected-connection-msgio" class="list"> + <li class="arrow"><a href="#graphs">Selected Connection row 1</a></li> + </ul> + + <h1>Byte Input/Output</h1> + <ul id="selected-connection-byteio" class="list"> + <li><a href="#">Selected Connection row 1</a></li> + </ul> + + <h1>Frame Input/Output</h1> + <ul id="selected-connection-frameio" class="list"> + <li><a href="#">Selected Connection row 1</a></li> + </ul> + + <h1>General</h1> + <ul id="selected-connection-general" class="list"> + <li><a href="#">Selected Connection row 1</a></li> + </ul> + + <h1>Subscribed Sessions</h1> + <ul id="selected-connection-subscribed-sessions" class="list"> + <li class="arrow"><a href="#connection-sessions">Selected Connection Session 1</a></li> + </ul> + + <h1>Unsubscribed Sessions</h1> + <ul id="selected-connection-unsubscribed-sessions" class="list"> + <li><a href="#connection-sessions">Selected Connection Session 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of selected-connection-scroller --> +</div> <!-- End of selected-connection --> + +<div id="connection-subscriptions" class="main"> + <div class="header"> + <a class="back button" href="#">Connect...</a> + <h1>Connection Subscriptions</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="connection-subscriptions-scroller" class="scroll-area"> + <div class="page"> + <h1>Subscription</h1> + <ul id="connection-subscriptions-list" class="list"> + <li><a href="#">Selected Subscription row 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of connection-subscriptions-scroller --> +</div> <!-- End of connection-subscriptions --> + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Exchange Information --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="exchanges" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Exchanges</h1> + </div> + + <div id="exchanges-scroller" class="scroll-area"> + <div class="page"> + <ul id="exchanges-add-exchange" class="list"> + <li class="pop"><a href="#add-exchange">Add Exchange</a></li> + </ul> + <p/> + + <ul id="exchanges-list" class="list"> + <li class="arrow"><a href="#selected-exchange">Dummy Exchange</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of exchanges-scroller --> +</div> <!-- End of exchanges --> + +<div id="selected-exchange" class="main"> + <div class="header"> + <a class="back button" href="#">Exchan...</a> + <h1>Selected Exchange</h1> + + <span class="toolbar"> + <a class="delete" href="#"></a> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="selected-exchange-scroller" class="scroll-area"> + <div class="page"> + <ul id="selected-exchange-bindings" class="list"> + <li class="arrow"><a href="#bindings">Bindings</a></li> + </ul> + + <h1>Message Input/Output</h1> + <ul id="selected-exchange-msgio" class="list"> + <li class="arrow" ><a href="#graphs">Selected Exchange row 1</a></li> + </ul> + + <h1>Byte Input/Output</h1> + <ul id="selected-exchange-byteio" class="list"> + <li><a href="#">Selected Exchange row 1</a></li> + </ul> + + <h1>General</h1> + <ul id="selected-exchange-general" class="list"> + <li><a href="#">Selected Exchange row 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of selected-exchange-scroller --> +</div> <!-- End of selected-exchange --> + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Queue Information --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="queues" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Queues</h1> + </div> + + <div id="queues-scroller" class="scroll-area"> + <div class="page"> + <ul id="queues-add-queue" class="list"> + <li class="pop"><a href="#add-queue">Add Queue</a></li> + </ul> + <p/> + + <ul id="queues-list" class="list"> + <li class="arrow"><a href="#selected-queue">Dummy Queue</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of queues-scroller --> +</div> <!-- End of queues --> + +<div id="selected-queue" class="main"> + <div class="header"> + <a class="back button" href="#">Queues</a> + <h1>Selected Queue</h1> + + <span class="toolbar"> + <a class="delete" href="#"></a> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="selected-queue-scroller" class="scroll-area"> + <div class="page"> + <ul id="selected-queue-bindings" class="list"> + <li class="arrow"><a href="#bindings">Bindings</a></li> + </ul> + + <h1>Message Input/Output</h1> + <ul id="selected-queue-msgio" class="list"> + <li class="arrow"><a href="#graphs">Selected Queue row 1</a></li> + </ul> + + <h1>Byte Input/Output</h1> + <ul id="selected-queue-byteio" class="list"> + <li><a href="#">Selected Queue row 1</a></li> + </ul> + + <h1>General</h1> + <ul id="selected-queue-general" class="list"> + <li><a href="#">Selected Queue row 1</a></li> + </ul> + + <div id="selected-queue-flow-to-disk-container"> + <h1>Flow to Disk</h1> + <ul id="selected-queue-flow-to-disk" class="list"> + <li><a href="#">Selected Queue row 1</a></li> + </ul> + </div> + + <div id="selected-queue-dequeue-container"> + <h1>Dequeue Details</h1> + <ul id="selected-queue-dequeue" class="list"> + <li><a href="#">Selected Queue row 1</a></li> + </ul> + </div> + + <h1>Subscriptions</h1> + <ul id="selected-queue-subscriptions" class="list"> + <li class="arrow"><a href="#queue-subscriptions">Selected Queue Subscription 1</a></li> + </ul> + + <!-- This wrapper div makes it easy to hide these admin functions on QMF queues --> + <div id="selected-queue-admin-wrapper"> + <h1>Admin</h1> + <ul id="selected-queue-admin" class="list"> + <li class="arrow pop"><a href="#purge-queue">Purge</a></li> + <li class="arrow pop"><a href="#reroute-messages">Reroute Messages</a></li> + <li class="arrow pop"><a href="#move-messages">Move Messages</a></li> + </ul> + </div> + </div> <!-- End of page --> + </div> <!-- End of selected-queue-scroller --> +</div> <!-- End of selected-queue --> + +<div id="queue-subscriptions" class="main"> + <div class="header"> + <a class="back button" href="#">Queue</a> + <h1>Selected Subscription</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="queue-subscriptions-scroller" class="scroll-area"> + <div class="page"> + <h1 class="first">Connection</h1> + <ul id="queue-subscriptions-connection" class="list"> + <li class="arrow"><a href="#">Selected Subscription row 1</a></li> + </ul> + + <h1>Session</h1> + <ul id="queue-subscriptions-session" class="list"> + <li><a href="#">Selected Subscription row 1</a></li> + </ul> + + <h1>Subscription</h1> + <ul id="queue-subscriptions-subscription" class="list"> + <li><a href="#">Selected Subscription row 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of queue-subscriptions-scroller --> +</div> <!-- End of queue-subscriptions --> + +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="bindings" class="main"> + <div class="header"> + <a class="back button" href="#">Queue</a> + <h1>Bindings</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="bindings-scroller" class="scroll-area"> + <div class="page"> + <ul id="bindings-add-binding" class="list"> + <li class="pop"><a href="#add-binding">Add Binding</a></li> + </ul> + + <h1 class="first">Bindings</h1> + <ul id="bindings-list" class="list"> + <li class="arrow"><a href="#">Binding 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of bindings-scroller --> +</div> <!-- End of bindings --> + +<div id="graphs" class="main"> + <div class="header"> + <a class="back button" href="#">Back</a> + <h1>Graphs</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="graphs-scroller" class="scroll-area"> + <div class="page"> + + <ul id="graphs-time-selector" class="list"> + <li> + <label>10 minutes</label><input type="radio" value="tenMinutes" name="graphs-time-selector" checked /> + </li> + <li> + <label>1 hour</label><input type="radio" value="oneHour" name="graphs-time-selector" /> + </li> + <li> + <label>1 day</label><input type="radio" value="oneDay" name="graphs-time-selector" /> + </li> + </ul> + + <h1>Graph Title</h1> + <canvas id="graphs-canvas"> + Your browser does not support the canvas element. + </canvas> + </div> <!-- End of page --> + </div> <!-- End of graphs-scroller --> +</div> <!-- End of graphs --> + +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="links" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Links</h1> + </div> + + <div id="links-scroller" class="scroll-area"> + <div class="page"> + <ul id="links-list" class="list"> + <li class="arrow"><a href="#">Not Yet Supported</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of links-scroller --> +</div> <!-- End of links --> + +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="route-topology" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Route Topology</h1> + </div> + + <div id="route-topology-scroller" class="scroll-area"> + <div class="page"> + <ul id="route-topology-list" class="list"> + <li class="arrow"><a href="#">Not Yet Supported</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of route-topology-scroller --> +</div> <!-- End of route-topology --> + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Asynchronous Broker Events --> +<!-----------------------------------------------------------------------------------------------------------------> + +<div id="events" class="main"> + <div class="header"> + <a class="menu back button" href="#">QMF Con...</a> + <h1>Events</h1> + </div> + + <div id="events-scroller" class="scroll-area"> + <div class="page"> + <ul id="events-list" class="list"> + <li class="grey"><a href="#">There are currently no events available</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of events-scroller --> +</div> <!-- End of events --> + +<div id="selected-event" class="main"> + <div class="header"> + <a class="back button" href="#">Events</a> + <h1>Selected Event</h1> + + <span class="toolbar"> + <a class="menu home" href="#"></a> + </span> + </div> + + <div id="selected-event-scroller" class="scroll-area"> + <div class="page"> + <ul id="selected-event-list" class="list"> + <li><a href="#">Selected Event row 1</a></li> + </ul> + <p/> + <ul id="selected-event-values" class="list"> + <li><a href="#">Selected Event row 1</a></li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of selected-event-scroller --> +</div> <!-- End of selected-event --> + + + +<!-----------------------------------------------------------------------------------------------------------------> +<!-- Popup Form Windows --> +<!-----------------------------------------------------------------------------------------------------------------> + +<!-- +<div class="popup-window"> and <div class="popup-container"> act as the container elements for all popup windows +these are used to enable a semi-transparent "smoked glass" background behind the actual popup. +--> +<div class="popup-window"> + <div class="popup-container"> + + + <div id="add-console-connection" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Add QMF Console Connection</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="add-console-connection-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="console-url">URL</label> + <input type="text" id="console-url" placeholder="guest/guest@host:5672" required /> + </li> + <li> + <label for="console-name">Name</label> + <input type="text" id="console-name" placeholder="Operational Broker" /> + </li> + </ul> + <p class="note">URL may be any AMQP URL format, Name is a name used to identify the Broker.</p> + + <ul class="list"> + <li> + <label for="console-disable-events">Disable Events</label> + <input type="checkbox" id="console-disable-events" /> + </li> + </ul> + <p class="note nopadding">Disable QMF2 Events, use polling to update state instead.</p> + + <h1>Connection Options</h1> + <ul id="add-connection-options" class="list"> + <li> + <textarea placeholder='{"sasl_mechanisms": "GSSAPI", "protocol": "ssl"}'></textarea> + </li> + </ul> + <p class="note">Connection Options are not required for most QMF Connections, but may be needed in some authentication edge cases.</p> + </form> + </div> <!-- End of page --> + </div> <!-- End of add-console-connection-scroller --> + </div> <!-- End of add-console-connection --> + +<!-----------------------------------------------------------------------------------------------------------------> + + <div id="add-exchange" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Add Exchange</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="add-exchange-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="exchange-name">Name</label> + <input type="text" id="exchange-name" placeholder="Exchange Name" required /> + </li> + </ul> + <p/> + <ul class="list"> + <li id="add-exchange-exchange-type" class="arrow"> + <a href="#exchange-type">Exchange Type<p>direct</p></a> + </li> + <li class="arrow"><a href="#add-exchange-additional">Additional Options</a></li> + </ul> + </form> + </div> <!-- End of page --> + </div> <!-- End of add-exchange-scroller --> + </div> <!-- End of add-exchange --> + + <div id="exchange-type" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Exc...</a> + <h1>Exchange Type</h1> + </div> + + <div id="exchange-type-scroller" class="scroll-area"> + <div class="page"> + <ul class="list"> + <li> + <label for="direct">direct</label> + <input type="radio" id="direct" name="exchange-type" value="direct" checked /> + </li> + <li> + <label for="fanout">fanout</label> + <input type="radio" id="fanout" name="exchange-type" value="fanout" /> + </li> + <li> + <label for="topic">topic</label> + <input type="radio" id="topic" name="exchange-type" value="topic" /> + </li> + <li> + <label for="headers">headers</label> + <input type="radio" id="headers" name="exchange-type" value="headers" /> + </li> + <li> + <label for="xml">xml</label> + <input type="radio" id="xml" name="exchange-type" value="xml" /> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of exchange-type-scroller --> + </div> <!-- End of exchange-type --> + + <div id="add-exchange-additional" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Exc...</a> + <h1>Additional Options</h1> + </div> + + <div id="add-exchange-additional-scroller" class="scroll-area"> + <div class="page"> + <h1 class="first">Alternate Exchange</h1> + <ul class="list"> + <li id="add-exchange-additional-alternate-exchange-name" class="arrow"> + <a href="#exchange-selector?id=#add-exchange-additional-alternate-exchange-name">Exchange<p>None (default)</p></a> + </li> + </ul> + <p class="note">Route messages here if this exchange is unable to route them elsewhere.</p> + + <ul class="list"> + <li> + <label for="exchange-durable">Durable</label> + <input type="checkbox" id="exchange-durable"/> + </li> + <li> + <label for="sequence">Sequence Number</label> + <input type="checkbox" id="sequence"/> + </li> + <li> + <label for="ive">Initial Value Exchange</label> + <input type="checkbox" id="ive"/> + </li> + </ul> + <p class="note">An Initial Value Exchange will keep a reference to the last message forwarded and enqueue that message to newly bound queues.</p> + </div> <!-- End of page --> + </div> <!-- End of add-exchange-additional-scroller --> + </div> <!-- End of add-exchange-additional --> + + <div id="exchange-selector" class="popup"> + <div class="header"> + <a class="back button" href="#">Additio...</a> + <h1>Alternate Exchange</h1> + </div> + + <div id="exchange-selector-scroller" class="scroll-area"> + <div class="page"> + <ul id="exchange-selector-list" class="list"> + <li> + <label for="exchange-selector-exchangeNone">None (default)</label> + <input type="radio" id="exchange-selector-exchangeNone" + name="exchange-selector" value="None (default)" checked /> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of exchange-selector-scroller --> + </div> <!-- End of exchange-selector --> + +<!-----------------------------------------------------------------------------------------------------------------> + + <div id="add-queue" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Add Queue</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="add-queue-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="queue-name">Name</label> + <input type="text" id="queue-name" placeholder="Queue Name" required /> + </li> + </ul> + + <h1>Maximum In-memory Queue Size</h1> + <ul class="list"> + <li> + <label for="max-queue-size">Max Size</label> + <input type="text" id="max-queue-size" placeholder="Size (bytes) [K|M|G]"/> + </li> + <li> + <label for="max-queue-count">Max Count</label> + <input type="text" id="max-queue-count" placeholder="Size (messages)"/> + </li> + </ul> + <p class="note">Queue sizes are optional, if not specified broker defaults will be used.</p> + + <ul class="list"> + <li id="add-queue-limit-policy" class="arrow"> + <a href="#limit-policy">Limit Policy<p>None (default)</p></a> + </li> + <li id="add-queue-ordering-policy" class="arrow"> + <a href="#ordering-policy">Order Policy<p>Fifo (default)</p></a> + </li> + <li class="arrow"><a href="#add-queue-additional">Additional Options</a></li> + </ul> + </form> + </div> <!-- End of page --> + </div> <!-- End of add-queue-scroller --> + </div> <!-- End of add-queue --> + + <div id="limit-policy" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Queue</a> + <h1>Limit Policy</h1> + </div> + + <div id="limit-policy-scroller" class="scroll-area"> + <div class="page"> + <ul class="list"> + <li> + <label for="none">None (default)</label> + <input type="radio" id="none" name="limit-policy" value="none" checked /> + </li> + <li> + <label for="reject">Reject</label> + <input type="radio" id="reject" name="limit-policy" value="reject" /> + </li> + <li> + <label for="flow-to-disc">Flow to Disc</label> + <input type="radio" id="flow-to-disc" name="limit-policy" value="flow_to_disk" /> + </li> + <li> + <label for="ring">Ring</label> + <input type="radio" id="ring" name="limit-policy" value="ring" /> + </li> + <li> + <label for="ring-strict">Ring Strict</label> + <input type="radio" id="ring-strict" name="limit-policy" value="ring_strict" /> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of limit-policy-scroller --> + </div> <!-- End of limit-policy --> + + <div id="ordering-policy" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Queue</a> + <h1>Order Policy</h1> + </div> + + <div id="ordering-policy-scroller" class="scroll-area"> + <div class="page"> + <ul class="list"> + <li> + <label for="fifo">Fifo (default)</label> + <input type="radio" id="fifo" name="ordering-policy" value="fifo" checked /> + </li> + <li> + <label for="lvq">LVQ</label> + <input type="radio" id="lvq" name="ordering-policy" value="lvq" /> + </li> + <li> + <label for="lvq-no-browse">LVQ No Browse</label> + <input type="radio" id="lvq-no-browse" name="ordering-policy" value="lvq-no-browse" /> + </li> + </ul> + <p class="note">Fifo or Last Value Queue.</p> + </div> <!-- End of page --> + </div> <!-- End of ordering-policy-scroller --> + </div> <!-- End of ordering-policy --> + + <div id="add-queue-additional" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Que...</a> + <h1>Additional Options</h1> + </div> + + <div id="add-queue-additional-scroller" class="scroll-area"> + <div class="page"> + <h1 class="first">Alternate Exchange</h1> + <ul class="list"> + <li id="add-queue-additional-alternate-exchange-name" class="arrow"> + <a href="#exchange-selector?id=#add-queue-additional-alternate-exchange-name">Exchange<p>None (default)</p></a> + </li> + </ul> + <p class="note">Route messages here if rejected by a subscriber or orphaned by queue deletion.</p> + + <ul id="add-queue-additional-durable-list" class="list"> + <li> + <label for="queue-durable">Durable</label> + <input type="checkbox" id="queue-durable"/> + </li> + <li> + <label for="file-size">File Size</label> + <input type="text" id="file-size" placeholder="24"/> + </li> + <li> + <label for="file-count">File Count</label> + <input type="text" id="file-count" placeholder="8"/> + </li> + </ul> + + <ul id="add-queue-additional-hidden-list" class="list"> + hidden list + </ul> + + <p id="add-queue-additional-journal-note" class="note nopadding"> + Journal sizes are optional, if not specified defaults will be used. + </p> + + <h1>Flow Control</h1> + <ul class="list"> + <li> + <label for="flow-stop-size">Stop Size</label> + <input type="text" id="flow-stop-size" placeholder="0 (bytes)"/> + </li> + <li> + <label for="flow-stop-count">Stop Count</label> + <input type="text" id="flow-stop-count" placeholder="0 (messages)"/> + </li> + <li> + <label for="flow-resume-size">Start Size</label> + <input type="text" id="flow-resume-size" placeholder="0 (bytes)"/> + </li> + <li> + <label for="flow-resume-count">Start Count</label> + <input type="text" id="flow-resume-count" placeholder="0 (messages)"/> + </li> + </ul> + <p class="note">When one of the stop thresholds are exceeded producer flow control is enabled until the flow drops below one of the start thresholds</p> + </div> <!-- End of page --> + </div> <!-- End of add-queue-additional-scroller --> + </div> <!-- End of add-queue-additional --> + +<!-----------------------------------------------------------------------------------------------------------------> + + <div id="purge-queue" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Purge Queue</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="purge-queue-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="purge-queue-request-number">Number</label> + <input type="text" id="purge-queue-request-number" placeholder="Message Count" /> + </li> + </ul> + <p class="note">Discards all or some messages from this queue. A value of 0 (default) discards all messages otherwise use the specified number.</p> + </form> + </div> <!-- End of page --> + </div> <!-- End of purge-queue-scroller --> + </div> <!-- End of purge-queue --> + + + <div id="reroute-messages" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Reroute Messages</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="reroute-messages-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="reroute-messages-request-number">Number</label> + <input type="text" id="reroute-messages-request-number" placeholder="Message Count" /> + </li> + </ul> + <p class="note">Remove all or some messages from this queue and route them to an exchange. A value of 0 (default) reroutes all messages otherwise use the specified number.</p> + + <ul class="list"> + <li> + <label for="reroute-messages-use-alternate-exchange">Alternate Exchange</label> + <input type="checkbox" id="reroute-messages-use-alternate-exchange"/> + </li> + </ul> + <p class="note">Use the queue's configured alternate exchange.</p> + <!-- reroute-messages-use-selected-exchange div is used to show/hide the following --> + <ul id="reroute-messages-use-selected-exchange" class="list"> + <li id="reroute-messages-exchange-name" class="arrow"> + <a href="#exchange-selector?id=#reroute-messages-exchange-name">Exchange<p>None (default)</p></a> + </li> + </ul> + </form> + </div> <!-- End of page --> + </div> <!-- End of reroute-messages-scroller --> + </div> <!-- End of reroute-messages --> + + + <div id="move-messages" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Move Messages</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="move-messages-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="move-messages-request-number">Number</label> + <input type="text" id="move-messages-request-number" placeholder="Message Count" /> + </li> + </ul> + <p class="note">Move messages from this queue to another. A value of 0 (default) moves all messages otherwise use the specified number.</p> + + <ul class="list"> + <li id="move-messages-queue-name" class="arrow"> + <a href="#queue-selector?id=#move-messages-queue-name">Queue<p>None (default)</p></a> + <!--<a href="#move-messages-select-queue">Queue<p>None (default)</p></a>--> + </li> + </ul> + <p class="note">Destination Queue.</p> + </form> + </div> <!-- End of page --> + </div> <!-- End of move-messages-scroller --> + </div> <!-- End of move-messages --> + +<!-----------------------------------------------------------------------------------------------------------------> + + <div id="add-binding" class="popup"> + <div class="header"> + <a class="cancel button" href="#">Cancel</a> + <h1>Add Binding</h1> + <a class="blue right button" href="#">Done</a> + </div> + + <div id="add-binding-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li id="add-binding-exchange-name" class="arrow"> + <a href="#exchange-selector?id=#add-binding-exchange-name">Exchange<p>None (default)</p></a> + </li> + <li id="add-binding-queue-name" class="arrow"> + <a href="#queue-selector?id=#add-binding-queue-name">Queue<p>None (default)</p></a> + </li> + <li> + <label for="add-binding-key-name">Key</label> + <input type="text" id="add-binding-key-name" placeholder="Binding Key"/> + </li> + </ul> + <p class="note nopadding"> + Key is optional, but without it the Binding cannot be explicitly deleted. + </p> + + <h1>Headers</h1> + <ul id="add-headers-binding" class="list"> + <li id="add-headers-binding-x-match" class="arrow"> + <a href="#x-match">Match<p>all</p></a> + </li> + <li class="arrow"> + <a href="#add-header-match">Add...</a> + </li> + </ul> + + <ul id="add-xml-binding" class="list"> + <li> + <textarea placeholder="Add XQuery here"></textarea> + </li> + </ul> + </form> + </div> <!-- End of page --> + </div> <!-- End of add-binding-scroller --> + </div> <!-- End of add-binding --> + + <div id="queue-selector" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Bind...</a> + <h1>Select Queue</h1> + </div> + + <div id="queue-selector-scroller" class="scroll-area"> + <div class="page"> + <ul id="queue-selector-list" class="list"> + <li> + <label for="queue-selector-queueNone">None (default)</label> + <input type="radio" id="queue-selector-queueNone" + name="queue-selector" value="None (default)" checked /> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of queue-selector-scroller --> + </div> <!-- End of queue-selector --> + + <div id="x-match" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Binding</a> + <h1>Match</h1> + </div> + + <div id="x-match-scroller" class="scroll-area"> + <div class="page"> + <ul class="list"> + <li> + <label for="x-match-all">all</label> + <input type="radio" id="x-match-all" name="x-match" value="all" checked /> + </li> + <li> + <label for="x-match-any">any</label> + <input type="radio" id="x-match-any" name="x-match" value="any" /> + </li> + </ul> + </div> <!-- End of page --> + </div> <!-- End of x-match-scroller --> + </div> <!-- End of x-match --> + + <div id="add-header-match" class="popup"> + <div class="header"> + <a class="back button" href="#">Add Bind...</a> + <h1>Header Match</h1> + <a class="blue right button" href="#">Add</a> + </div> + + <div id="add-header-match-scroller" class="scroll-area"> + <div class="page"> + <form action="#"> + <ul class="list"> + <li> + <label for="header-match-key">Key</label> + <input type="text" id="header-match-key" placeholder="Header Name"/> + </li> + <li> + <label for="header-match-value">Value</label> + <input type="text" id="header-match-value" placeholder="Match Value"/> + </li> + </ul> + <p class="note"> + Specify a Header name and a value to match the Header against. + </p> + </form> + </div> <!-- End of page --> + </div> <!-- End of add-header-match-scroller --> + </div> <!-- End of add-header-match --> + + + </div> <!-- End of popup-container --> +</div> <!-- End of popup-window --> + + +<!-----------------------------------------------------------------------------------------------------------------> + +</body> +</html> diff --git a/qpid/tools/src/java/qpid-qmf2-tools/bin/whitelist.xml b/qpid/tools/src/java/qpid-qmf2-tools/bin/whitelist.xml new file mode 100644 index 0000000000..5c39c50d43 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/bin/whitelist.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + 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. +--> + +<whitelist> + <exchangeWhitelist> + <exchange>qmf.default.topic</exchange> + <exchange>qmf.default.direct</exchange> + <exchange>qpid.management</exchange> + <exchange>amq.direct</exchange> + <exchange></exchange> + </exchangeWhitelist> + <queueWhitelist> + <queue>testqueue1</queue> + </queueWhitelist> +</whitelist> diff --git a/qpid/tools/src/java/qpid-qmf2-tools/pom.xml b/qpid/tools/src/java/qpid-qmf2-tools/pom.xml new file mode 100644 index 0000000000..a83cae1cf5 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/pom.xml @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.qpid</groupId> + <artifactId>qpid-qmf2-parent</artifactId> + <version>0.32-SNAPSHOT</version> + </parent> + + <artifactId>qpid-qmf2-tools</artifactId> + <name>Qpid QMF2 Tools</name> + <description>QMF2 Tools</description> + + <properties> + <dependency-change-verification>true</dependency-change-verification> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.qpid</groupId> + <artifactId>qpid-qmf2</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.qpid</groupId> + <artifactId>qpid-qmf2-rest</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j-version}</version> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>${slf4j-version}</version> + <scope>runtime</scope> + </dependency> + + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>${log4j-version}</version> + <scope>runtime</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <!--version specified in qpid-parent pluginManagement --> + <configuration> + <descriptors> + <descriptor>src/main/assembly/qpid-qmf2-tools-bin.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>create-qmf2-tools-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/LICENSE b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/LICENSE new file mode 100644 index 0000000000..ec8bdec6e5 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/LICENSE @@ -0,0 +1,292 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + +############################################### +# Third Party Dependency Licensing Information: +############################################### + +bin/qpid-web/web/itablet/scripts/jquery.js + +The QMF2 tools GUI bundles jquery.js which is under the MIT licence: + + +Copyright (c) 2011 John Resig, http://jquery.com/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +############################################### + +bin/qpid-web/web/itablet/scripts/iscroll.js + +The QMF2 tools GUI bundles iscroll.js which is under the MIT licence: + + +Copyright (c) 2012 Matteo Spinelli, http://cubiq.org/ + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +############################################### + +This product bundles the slf4j-api and slf4j-log4j jars which are under +the MIT licence: + +Copyright (c) 2004-2013 QOS.ch + All rights reserved. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +############################################### diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/NOTICE b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/NOTICE new file mode 100644 index 0000000000..49bf4f36af --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/NOTICE @@ -0,0 +1,10 @@ +Apache Qpid QMF2 Tools +Copyright 2012-2014 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +############################################### + +Apache Geronimo JMS 1.1 Spec +Copyright 2003-2008 The Apache Software Foundation diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE new file mode 100644 index 0000000000..424f175b33 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE @@ -0,0 +1,50 @@ +# +# 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. +# + +#// ------------------------------------------------------------------ +# TRIMMED 3RD PARTY DEPENDENCY INFORMATION FOR MODIFICATION CHECKS +#// ------------------------------------------------------------------ + + + +From: 'Apache Software Foundation' (http://www.apache.org) + - Apache Log4j (http://logging.apache.org/log4j/1.2/) log4j:log4j:bundle:1.2.16 + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + - JMS 1.1 (http://geronimo.apache.org/specs/geronimo-jms_1.1_spec) org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1 + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + +From: 'QOS.ch' (http://www.qos.ch) + - SLF4J API Module (http://www.slf4j.org) org.slf4j:slf4j-api:jar:1.6.4 + License: MIT License (http://www.opensource.org/licenses/mit-license.php) + - SLF4J LOG4J-12 Binding (http://www.slf4j.org) org.slf4j:slf4j-log4j12:jar:1.6.4 + License: MIT License (http://www.opensource.org/licenses/mit-license.php) + +From: 'The Apache Software Foundation' (http://www.apache.org/) + - Qpid AMQP 0-x JMS Client (http://qpid.apache.org/qpid-java-build/qpid-client) org.apache.qpid:qpid-client:jar + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + - Qpid Common (http://qpid.apache.org/qpid-java-build/qpid-common) org.apache.qpid:qpid-common:jar + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + - Qpid QMF2 (http://qpid.apache.org/qpid-qmf2-parent/qpid-qmf2) org.apache.qpid:qpid-qmf2:jar + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + - Qpid QMF2 REST (http://qpid.apache.org/qpid-qmf2-parent/qpid-qmf2-rest) org.apache.qpid:qpid-qmf2-rest:jar + License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt) + + + + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/qpid-qmf2-tools-bin.xml b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/qpid-qmf2-tools-bin.xml new file mode 100644 index 0000000000..cce56c0725 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/assembly/qpid-qmf2-tools-bin.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + <id>bin</id> + <formats> + <format>tar.gz</format> + </formats> + <baseDirectory>qpid-qmf2-tools/${project.version}</baseDirectory> + <fileSets> + <fileSet> + <outputDirectory>/</outputDirectory> + <includes> + <include>README.txt</include> + </includes> + <fileMode>0644</fileMode> + <directoryMode>0755</directoryMode> + </fileSet> + <fileSet> + <directory>${basedir}/src/main/assembly/</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>LICENSE</include> + <include>NOTICE</include> + </includes> + <fileMode>0644</fileMode> + <directoryMode>0755</directoryMode> + </fileSet> + <fileSet> + <directory>${project.basedir}</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>bin/</include> + </includes> + <fileMode>0755</fileMode> + <directoryMode>0755</directoryMode> + </fileSet> + </fileSets> + <dependencySets> + <dependencySet> + <outputDirectory>/lib</outputDirectory> + <useProjectArtifact>true</useProjectArtifact> + </dependencySet> + </dependencySets> +</assembly> + diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java new file mode 100644 index 0000000000..7f6109cb7a --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionAudit.java @@ -0,0 +1,474 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +// For DOM parsing the whitelist +import org.w3c.dom.*; +import javax.xml.parsers.*; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfEvent; +import org.apache.qpid.qmf2.common.QmfEventListener; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.common.WorkItem; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.AgentRestartedWorkItem; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.EventReceivedWorkItem; +import org.apache.qpid.qmf2.console.QmfConsoleData; +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +/** + * Audits connections to one or more Qpid message brokers. + * <pre> + * Exchange and Queue names are checked against a whitelist and if no match is found an alert is generated. + * + * If no broker-addr is supplied, ConnectionAudit connects to 'localhost:5672'. + * + * [broker-addr] syntax: + * + * [username/password@] hostname + * ip-address [:<port>] + * + * Examples: + * + * $ ConnectionAudit localhost:5672 + * $ ConnectionAudit 10.1.1.7:10000 + * $ ConnectionAudit guest/guest@broker-host:10000 + * + * Options: + * -h, --help show this help message and exit + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * --whitelist=<whitelist XML document> + * The fully qualified name of the whitelist XML file, + * default is ./whitelist.xml + * + * </pre> + * An example whitelist is illustrated below, note that in this example the exchanges associated with management + * have been whitelisted to remove spurious alerts caused by the temporary management queues. + * <pre> + *<?xml version="1.0" encoding="UTF-8"?> + *<whitelist> + * <exchangeWhitelist> + * <exchange>qmf.default.topic</exchange> + * <exchange>qmf.default.direct</exchange> + * <exchange>qpid.management</exchange> + * <exchange>amq.direct</exchange> + * <exchange></exchange> + * </exchangeWhitelist> + * <queueWhitelist> + * <queue>testqueue</queue> + * </queueWhitelist> + *</whitelist> + * </pre> + + * @author Fraser Adams + */ +public final class ConnectionAudit implements QmfEventListener +{ + private static final String _usage = + "Usage: ConnectionAudit [options] [broker-addr]...\n"; + + private static final String _description = + "Audits connections to one or more Qpid message brokers.\n" + + "Exchange and Queue names are checked against a whitelist and if no match is found an alert is generated.\n" + + "\n" + + "If no broker-addr is supplied, ConnectionAudit connects to 'localhost:5672'.\n" + + "\n" + + "[broker-addr] syntax:\n" + + "\n" + + "[username/password@] hostname\n" + + "ip-address [:<port>]\n" + + "\n" + + "Examples:\n" + + "\n" + + "$ ConnectionAudit localhost:5672\n" + + "$ ConnectionAudit 10.1.1.7:10000\n" + + "$ ConnectionAudit guest/guest@broker-host:10000\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n" + + " --whitelist=<whitelist XML document>\n" + + " The fully qualified name of the whitelist XML file,\n" + + " default is ./whitelist.xml\n"; + + + private final String _url; + private final String _whitelist; + private long _whitelistLastModified = 0; + private Console _console; + + // The sets to be used as the whitelists. + private Set<String> _exchangeWhitelist = new HashSet<String>(); + private Set<String> _queueWhitelist = new HashSet<String>(); + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the connection URL. + * @param connectionOptions the options String to pass to ConnectionHelper. + * @param whitelist the path name of the whitelist XML file. + */ + public ConnectionAudit(final String url, final String connectionOptions, final String whitelist) + { + System.out.println("Connecting to " + url); + _url = url; + _whitelist = whitelist; + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(this); + _console.addConnection(connection); + checkExistingSubscriptions(); + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in ConnectionAudit constructor"); + } + } + + /** + * When we start up we need to check any subscriptions that already exist against the whitelist. + * Subsequent checks are made only when we receive new subscribe events. + */ + private void checkExistingSubscriptions() + { + readWhitelist(); + List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription"); + for (QmfConsoleData subscription : subscriptions) + { + QmfConsoleData queue = dereference(subscription.getRefValue("queueRef")); + QmfConsoleData session = dereference(subscription.getRefValue("sessionRef")); + QmfConsoleData connection = dereference(session.getRefValue("connectionRef")); + + String queueName = queue.getStringValue("name"); + String address = connection.getStringValue("address"); + String timestamp = new Date(subscription.getCreateTime()/1000000l).toString(); + validateQueue(queueName, address, timestamp); + } + } + + /** + * Dereferences an ObjectId returning a QmfConsoleData. + * @param ref the ObjectId to be dereferenced. + * @return the dereferenced QmfConsoleData object or null if the object can't be found. + */ + private QmfConsoleData dereference(final ObjectId ref) + { + List<QmfConsoleData> data = _console.getObjects(ref); + if (data.size() == 1) + { + return data.get(0); + } + return null; + } + + /** + * Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue() + * @param queueName the name of the queue that we want to check against the whitelists. + * @param exchangeName the name of the exchange that the queue we want to check against the whitelists is bound to. + * @param binding the binding associating queue "queueName" with exchange "exchangeName". + * @param address the connection address information for the subscription. + * @param timestamp the timestamp of the subscription. + */ + private void validateQueue(final String queueName, String exchangeName, final QmfConsoleData binding, + final String address, final String timestamp) + { + if (_exchangeWhitelist.contains(exchangeName)) + { // Check exchangeName against the exchangeWhitelist and if it's in there we simply return. + return; + } + + if (_queueWhitelist.contains(queueName)) + { // Check queueName against the queueWhitelist and if it's in there we simply return. + return; + } + + if (exchangeName.equals("")) + { // Make exchangeName render more prettily if necessary. + exchangeName = "''"; + } + + String bindingKey = binding.getStringValue("bindingKey"); + Map arguments = (Map)binding.getValue("arguments"); + if (arguments.isEmpty()) + { + System.out.printf("%s ALERT ConnectionAudit.validateQueue() validation failed for queue: %s with binding[%s] => %s from address: %s with connection timestamp %s\n\n", new Date().toString(), queueName, bindingKey, exchangeName, address, timestamp); + } + else + { // If there are binding arguments then it's a headers exchange so display accordimgly. + System.out.printf("%s ALERT ConnectionAudit.validateQueue() validation failed for queue: %s with binding[%s] => %s %s from address: %s with connection timestamp %s\n\n", new Date().toString(), queueName, bindingKey, exchangeName, arguments, address, timestamp); + } + } + + /** + * Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue() + * @param queueName the name of the queue that we want to check against the whitelists. + * @param address the connection address information for the subscription. + * @param timestamp the timestamp of the subscription. + */ + private void validateQueue(final String queueName, final String address, final String timestamp) + { + ObjectId queueId = null; + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + for (QmfConsoleData queue : queues) + { // We first have to find the ObjectId of the queue called queueName. + if (queue.getStringValue("name").equals(queueName)) + { + queueId = queue.getObjectId(); + break; + } + } + + if (queueId == null) + { + System.out.printf("%s ERROR ConnectionAudit.validateQueue() %s reference couldn't be found\n", + new Date().toString(), queueName); + } + else + { // If we've got the queue's ObjectId we then find the binding that references it. + List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding"); + for (QmfConsoleData binding : bindings) + { + ObjectId queueRef = binding.getRefValue("queueRef"); + if (queueRef.equals(queueId)) + { // We've found a binding that matches queue queueName so look up the associated exchange and validate. + QmfConsoleData exchange = dereference(binding.getRefValue("exchangeRef")); + String exchangeName = exchange.getStringValue("name"); + validateQueue(queueName, exchangeName, binding, address, timestamp); + } + } + } + } + + /** + * Handles WorkItems delivered by the Console. + * <p> + * If we receive an EventReceivedWorkItem check if it is a subscribe event. If it is we check if the whitelist has + * changed, and if it has we re-read it. We then extract the queue name, exchange name, binding, connection address + * and timestamp and validate with the whitelsist. + * <p> + * If we receive an AgentRestartedWorkItem we revalidate all subscriptions as it's possible that a client connection + * could have been made to the broker before ConnectionAudit has successfully re-established its own connections. + * @param wi a QMF2 WorkItem object + */ + public void onEvent(final WorkItem wi) + { + if (wi instanceof EventReceivedWorkItem) + { + EventReceivedWorkItem item = (EventReceivedWorkItem)wi; + QmfEvent event = item.getEvent(); + String className = event.getSchemaClassId().getClassName(); + if (className.equals("subscribe")) + { + readWhitelist(); + String queueName = event.getStringValue("qName"); + String address = event.getStringValue("rhost"); + String timestamp = new Date(event.getTimestamp()/1000000l).toString(); + validateQueue(queueName, address, timestamp); + } + } + else if (wi instanceof AgentRestartedWorkItem) + { + checkExistingSubscriptions(); + } + } + + /** + * This method first checks if the whitelist file exists, if not it clears the sets used as whitelists + * so that no whitelisting is applied. If the whitelist file does exist it is parsed by a DOM parser. + * <p> + * We look for all exchange and queue elements and populate the respective whitelist sets with their + * contents. Note that we check the whitelist file update time to avoid reading it if it hasn't been changed + */ + private void readWhitelist() + { + File file = new File(_whitelist); + if (file.exists()) + { + long mtime = file.lastModified(); + if (mtime != _whitelistLastModified) + { + _whitelistLastModified = mtime; + _exchangeWhitelist.clear(); + _queueWhitelist.clear(); + + try + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(file); + + Element whitelist = doc.getDocumentElement(); + if (whitelist.getNodeName().equals("whitelist")) + { + NodeList children = whitelist.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) + { + Node child = children.item(i); + if (child.getNodeName().equals("exchangeWhitelist")) + { + NodeList exchanges = child.getChildNodes(); + for (int j = 0; j < exchanges.getLength(); j++) + { + Node node = exchanges.item(j); + if (node.getNodeName().equals("exchange")) + { + if (node.hasChildNodes()) + { + String exchange = node.getFirstChild().getNodeValue(); + _exchangeWhitelist.add(exchange); + } + else + { + _exchangeWhitelist.add(""); + } + } + } + } + else if (child.getNodeName().equals("queueWhitelist")) + { + NodeList queues = child.getChildNodes(); + for (int j = 0; j < queues.getLength(); j++) + { + Node node = queues.item(j); + if (node.getNodeName().equals("queue")) + { + if (node.hasChildNodes()) + { + String queue = node.getFirstChild().getNodeValue(); + _queueWhitelist.add(queue); + } + } + } + } + } + } + } + catch (Exception e) + { // Failed to parse correctly. + System.out.println("Exception " + e + " while reading " + _whitelist); + System.out.println(new Date().toString() + " WARN ConnectionAudit.readWhitelist() " + + _whitelist + " failed: " + e.getMessage()); + return; + } + } + } + else + { // If whitelist file doesn't exist log a warning and clear the whitelists. + System.out.println(new Date().toString() + " WARN ConnectionAudit.readWhitelist() " + + _whitelist + " doesn't exist"); + _exchangeWhitelist.clear(); + _queueWhitelist.clear(); + } + } // End of readWhitelist() + + /** + * Runs ConnectionAudit. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + String[] longOpts = {"help", "whitelist=", "sasl-mechanism="}; + try + { + String connectionOptions = "{reconnect: true}"; + String whitelist = "./whitelist.xml"; + GetOpt getopt = new GetOpt(args, "h", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_description); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("--whitelist")) + { + whitelist = opt[1]; + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + int nargs = cargs.length; + if (nargs == 0) + { + cargs = new String[] {"localhost"}; + } + + for (String url : cargs) + { + ConnectionAudit eventPrinter = new ConnectionAudit(url, connectionOptions, whitelist); + } + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.exit(1); + } + + try + { // Block here + Thread.currentThread().join(); + } + catch (InterruptedException ie) + { + } + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java new file mode 100644 index 0000000000..f9364b4069 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/ConnectionLogger.java @@ -0,0 +1,383 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.Map; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfEvent; +import org.apache.qpid.qmf2.common.QmfEventListener; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.common.WorkItem; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem; +import org.apache.qpid.qmf2.console.AgentRestartedWorkItem; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.EventReceivedWorkItem; +import org.apache.qpid.qmf2.console.QmfConsoleData; +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +/** + * ConnectionLogger is a QMF2 class used to provide information about connections made to a broker. + * <p> + * In default mode ConnectionLogger lists the connections made to a broker along with information about sessions + * such as whether any subscriptions are associated with the session (if a session has no subscriptions then it's + * quite likely to be a "producer only" session, so this knowledge is quite useful). + * <p> + * In "log queue and binding" mode the information provided is very similar to qpid-config -b queues but with + * additional connection related information provided as with default mode. + * + * <pre> + * Usage: ConnectionLogger [options] + * + * Options: + * -h, --help show this help message and exit + * -q log queue and binding information for consumer connection + * -a <address>, --broker-address=<address> + * broker-addr is in the form: [username/password@] + * hostname | ip-address [:<port>] ex: localhost, + * 10.1.1.7:10000, broker-host:10000, + * guest/guest@localhost + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * </pre> + * @author Fraser Adams + */ +public final class ConnectionLogger implements QmfEventListener +{ + private static final String _usage = + "Usage: ConnectionLogger [options]\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " -q log queue and binding information for consumer connections\n" + + " -a <address>, --broker-address=<address>\n" + + " broker-addr is in the form: [username/password@]\n" + + " hostname | ip-address [:<port>] ex: localhost,\n" + + " 10.1.1.7:10000, broker-host:10000,\n" + + " guest/guest@localhost\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n"; + + private Console _console; + private boolean _logQueues; + + // If any queues get added or deleted we set this to flag that we need to re-log connections on next heartbeat. + private boolean _stateChanged = false; + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the connection URL. + * @param connectionOptions the options String to pass to ConnectionHelper. + * @param logQueues flags whether queue & binding information is logged as well as connection info. + */ + public ConnectionLogger(final String url, final String connectionOptions, final boolean logQueues) + { + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(this); + _console.addConnection(connection); + _logQueues = logQueues; + System.out.println("Hit Return to exit"); + logConnectionInformation(); + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in ConnectionLogger constructor"); + } + } + + /** + * Finds a QmfConsoleData in a List of QMF Objects that matches a given ObjectID + * + * More or less a direct Java port of findById from qpid-config + * + * @param items the List of QMF Objects to search + * @param id the ObjectId we're searching the List for + * @return return the found object as a QmfConsoleData else return null + */ + private QmfConsoleData findById(final List<QmfConsoleData> items, final ObjectId id) + { + for (QmfConsoleData item : items) + { + if (item.getObjectId().equals(id)) + { + return item; + } + } + + return null; + } + + /** + * For every queue list the bindings (equivalent of qpid-config -b queues) + * + * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues + * + * @param ref If ref is null list info about all queues else list info about queue referenced by ObjectID + */ + private void logQueueInformation(final ObjectId ref) + { + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding"); + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + + for (QmfConsoleData queue : queues) + { + ObjectId queueId = queue.getObjectId(); + + if (ref == null || ref.equals(queueId)) + { + System.out.printf(" Queue '%s'\n", queue.getStringValue("name")); + System.out.println(" arguments " + (Map)queue.getValue("arguments")); + + for (QmfConsoleData binding : bindings) + { + ObjectId queueRef = binding.getRefValue("queueRef"); + + if (queueRef.equals(queueId)) + { + ObjectId exchangeRef = binding.getRefValue("exchangeRef"); + QmfConsoleData exchange = findById(exchanges, exchangeRef); + + String exchangeName = "<unknown>"; + if (exchange != null) + { + exchangeName = exchange.getStringValue("name"); + if (exchangeName.equals("")) + { + exchangeName = "''"; + } + } + + String bindingKey = binding.getStringValue("bindingKey"); + Map arguments = (Map)binding.getValue("arguments"); + if (arguments.isEmpty()) + { + System.out.printf(" bind [%s] => %s\n", bindingKey, exchangeName); + } + else + { + // If there are binding arguments then it's a headers exchange + System.out.printf(" bind [%s] => %s %s\n", bindingKey, exchangeName, arguments); + } + } + } + } + } + } + + /** + * Logs audit information about each connection made to the broker + * + * Obtains connection, session and subscription objects and iterates in turn through these comparing + * references to find the subscriptions association with sessions and sessions associated with + * connections. Ultimately it then uses logQueueInformation to display the queues associated with + * each subscription. + */ + private void logConnectionInformation() + { + System.out.println("\n\n**** ConnectionLogger: Logging current connection information ****"); + + List<QmfConsoleData> connections = _console.getObjects("org.apache.qpid.broker", "connection"); + List<QmfConsoleData> sessions = _console.getObjects("org.apache.qpid.broker", "session"); + List<QmfConsoleData> subscriptions = _console.getObjects("org.apache.qpid.broker", "subscription"); + + for (QmfConsoleData connection : connections) + { + System.out.printf("\nConnection '%s'\n", connection.getStringValue("address")); + + String[] properties = {"authIdentity","remoteProcessName", "federationLink"}; + for (String p : properties) + { + System.out.println(p + ": " + connection.getStringValue(p)); + } + + System.out.println("createTimestamp: " + new Date(connection.getCreateTime()/1000000l)); + + ObjectId connectionId = connection.getObjectId(); + for (QmfConsoleData session : sessions) + { // Iterate through all session objects + ObjectId connectionRef = session.getRefValue("connectionRef"); + if (connectionRef.equals(connectionId)) + { // But only select sessions that are associated with the connection under consideration. + System.out.printf("Session '%s'\n", session.getStringValue("name")); + int subscriptionCount = 0; + ObjectId sessionId = session.getObjectId(); + for (QmfConsoleData subscription : subscriptions) + { // Iterate through all subscription objects + ObjectId sessionRef = subscription.getRefValue("sessionRef"); + if (sessionRef.equals(sessionId)) + { // But only select subscriptions that are associated with the session under consideration. + subscriptionCount++; + ObjectId queueRef = subscription.getRefValue("queueRef"); + if (_logQueues) + { + logQueueInformation(queueRef); + } + } + } + if (subscriptionCount == 0) + { + System.out.println(" ** No Subscriptions for this Session - probably a producer only Session **"); + } + } + } + } + } + + /** + * Listener for QMF2 WorkItems + * <p> + * This method looks for clientConnect or clientDisconnect Events and uses these as a trigger to log the new + * connection state when the next Heartbeat occurs. + * <p> + * There are a couple of reasons for using this approach rather than just calling logConnectionInformation() + * as soon as we see the clientConnect or clientDisconnect Event. + * <p> + * 1. We could potentially have lots of connection Events and redisplaying all of the connections for each + * Event is likely to be confusing. + * <p> + * 2. When a clientConnect Event occurs we don't have all of the informatin that we might need, for example this + * application checks the Session and Subscription information and also optionally Queue and Binding information. + * Creating Sessions/Subscriptions won't generally occur until some (possibly small, but possibly not) time + * after the Connection has been made. The approach taken here reduces spurious assertions that a Session is + * probably a "producer only" Session. As one of the use-cases for this tool is to attempt to flag up "producer + * only" Sessions we want to try and make it as reliable as possible. + * + * @param wi a QMF2 WorkItem object + */ + public void onEvent(final WorkItem wi) + { + if (wi instanceof EventReceivedWorkItem) + { + EventReceivedWorkItem item = (EventReceivedWorkItem)wi; + Agent agent = item.getAgent(); + QmfEvent event = item.getEvent(); + + String className = event.getSchemaClassId().getClassName(); + if (className.equals("clientConnect") || + className.equals("clientDisconnect")) + { + _stateChanged = true; + } + } + else if (wi instanceof AgentRestartedWorkItem) + { + _stateChanged = true; + } + else if (wi instanceof AgentHeartbeatWorkItem) + { + AgentHeartbeatWorkItem item = (AgentHeartbeatWorkItem)wi; + Agent agent = item.getAgent(); + + if (_stateChanged && agent.getName().contains("qpidd")) + { + logConnectionInformation(); + _stateChanged = false; + } + } + } + + /** + * Runs ConnectionLogger. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + String[] longOpts = {"help", "broker-address=", "sasl-mechanism="}; + try + { + String host = "localhost"; + String connectionOptions = "{reconnect: true}"; + boolean logQueues = false; + + GetOpt getopt = new GetOpt(args, "ha:q", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) + { + host = opt[1]; + } + else if (opt[0].equals("-q")) + { + logQueues = true; + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + ConnectionLogger logger = new ConnectionLogger(host, connectionOptions, logQueues); + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.out.println(e.getMessage()); + System.exit(1); + } + + BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in)); + try + { // Blocks here until return is pressed + String s = commandLine.readLine(); + System.exit(0); + } + catch (IOException e) + { + System.out.println ("ConnectionLogger main(): IOException: " + e.getMessage()); + } + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java new file mode 100644 index 0000000000..e4262b0577 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidConfig.java @@ -0,0 +1,1517 @@ +/* + * + * 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.qmf2.tools; + +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStreamReader; +import java.io.IOException; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicInteger; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfData; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.QmfConsoleData; +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +/** + * QpidConfig is a fairly "literal" Java port of the python qpid-config tool. + * <p> + * It's vaguely pointless, as the python qpid-config is the "canonical" qpid-config :-) + * Nonetheless, it's a useful intellectual exercise to illustrate using QMF2 from Java. + * <p> + * QpidConfig (unlike the python qpid-config) uses pure QMF2 for adding/deleting queues, exchanges & bindings + * this provides useful illustration of how to do these things using the ManagementAgent method calls. + * <p> + * N.B. "create" and "delete" broker ManagementAgent methods were added in Qpid version 0.10, unfortunately these + * calls won't work for earlier versions of Qpid. + * <pre> + * Usage: qpid-config [OPTIONS] + * qpid-config [OPTIONS] exchanges [filter-string] + * qpid-config [OPTIONS] queues [filter-string] + * qpid-config [OPTIONS] add exchange <type> <name> [AddExchangeOptions] + * qpid-config [OPTIONS] del exchange <name> + * qpid-config [OPTIONS] add queue <name> [AddQueueOptions] + * qpid-config [OPTIONS] del queue <name> [DelQueueOptions] + * qpid-config [OPTIONS] bind <exchange-name> <queue-name> [binding-key] + * <for type xml> [-f -|filename] + * <for type header> [all|any] k1=v1 [, k2=v2...] + * qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key] + * + * ADDRESS syntax: + * + * [username/password@] hostname + * ip-address [:<port>] + * + * Examples: + * + * $ qpid-config add queue q + * $ qpid-config add exchange direct d localhost:5672 + * $ qpid-config exchanges 10.1.1.7:10000 + * $ qpid-config queues guest/guest@broker-host:10000 + * + * Add Exchange <type> values: + * + * direct Direct exchange for point-to-point communication + * fanout Fanout exchange for broadcast communication + * topic Topic exchange that routes messages using binding keys with wildcards + * headers Headers exchange that matches header fields against the binding keys + * xml XML Exchange - allows content filtering using an XQuery + * + * + * Queue Limit Actions + * + * none (default) - Use broker's default policy + * reject - Reject enqueued messages + * flow-to-disk - Page messages to disk + * ring - Replace oldest unacquired message with new + * ring-strict - Replace oldest message, reject if oldest is acquired + * + * Queue Ordering Policies + * + * fifo (default) - First in, first out + * lvq - Last Value Queue ordering, allows queue browsing + * lvq-no-browse - Last Value Queue ordering, browsing clients may lose data + * + * Options: + * -h, --help show this help message and exit + * + * General Options: + * -t <secs>, --timeout=<secs> + * Maximum time to wait for broker connection (in + * seconds) + * -b, --bindings Show bindings in queue or exchange list + * -a <address>, --broker-addr=<address> + * Maximum time to wait for broker connection (in + * seconds) + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * + * Options for Adding Exchanges and Queues: + * --alternate-exchange=<aexname> + * Name of the alternate-exchange for the new queue or + * exchange. Exchanges route messages to the alternate + * exchange if they are unable to route them elsewhere. + * Queues route messages to the alternate exchange if + * they are rejected by a subscriber or orphaned by queue + * deletion. + * --passive, --dry-run + * Do not actually add the exchange or queue, ensure that + * all parameters and permissions are correct and would + * allow it to be created. + * --durable The new queue or exchange is durable. + * + * Options for Adding Queues: + * --file-count=<n> Number of files in queue's persistence journal + * --file-size=<n> File size in pages (64Kib/page) + * --max-queue-size=<n> + * Maximum in-memory queue size as bytes + * --max-queue-count=<n> + * Maximum in-memory queue size as a number of messages + * --limit-policy=<policy> + * Action to take when queue limit is reached + * --order=<ordering> Queue ordering policy + * --flow-stop-size=<n> + * Turn on sender flow control when the number of queued + * bytes exceeds this value. + * --flow-resume-size=<n> + * Turn off sender flow control when the number of queued + * bytes drops below this value. + * --flow-stop-count=<n> + * Turn on sender flow control when the number of queued + * messages exceeds this value. + * --flow-resume-count=<n> + * Turn off sender flow control when the number of queued + * messages drops below this value. + * --argument=<NAME=VALUE> + * Specify a key-value pair to add to queue arguments + * + * Options for Adding Exchanges: + * --sequence Exchange will insert a 'qpid.msg_sequence' field in + * the message header + * --ive Exchange will behave as an 'initial-value-exchange', + * keeping a reference to the last message forwarded and + * enqueuing that message to newly bound queues. + * + * Options for Deleting Queues: + * --force Force delete of queue even if it's currently used or + * it's not empty + * --force-if-not-empty + * Force delete of queue even if it's not empty + * --force-if-not-used + * Force delete of queue even if it's currently used + * + * Options for Declaring Bindings: + * -f <file.xq>, --file=<file.xq> + * For XML Exchange bindings - specifies the name of a + * file containing an XQuery. + * + * </pre> + * @author Fraser Adams + */ +public final class QpidConfig +{ + private static final String _usage = + "Usage: qpid-config [OPTIONS]\n" + + " qpid-config [OPTIONS] exchanges [filter-string]\n" + + " qpid-config [OPTIONS] queues [filter-string]\n" + + " qpid-config [OPTIONS] add exchange <type> <name> [AddExchangeOptions]\n" + + " qpid-config [OPTIONS] del exchange <name>\n" + + " qpid-config [OPTIONS] add queue <name> [AddQueueOptions]\n" + + " qpid-config [OPTIONS] del queue <name> [DelQueueOptions]\n" + + " qpid-config [OPTIONS] bind <exchange-name> <queue-name> [binding-key]\n" + + " <for type xml> [-f -|filename]\n" + + " <for type header> [all|any] k1=v1 [, k2=v2...]\n" + + " qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key]\n"; + + private static final String _description = + "ADDRESS syntax:\n" + + "\n" + + " [username/password@] hostname\n" + + " ip-address [:<port>]\n" + + "\n" + + "Examples:\n" + + "\n" + + "$ qpid-config add queue q\n" + + "$ qpid-config add exchange direct d localhost:5672\n" + + "$ qpid-config exchanges 10.1.1.7:10000\n" + + "$ qpid-config queues guest/guest@broker-host:10000\n" + + "\n" + + "Add Exchange <type> values:\n" + + "\n" + + " direct Direct exchange for point-to-point communication\n" + + " fanout Fanout exchange for broadcast communication\n" + + " topic Topic exchange that routes messages using binding keys with wildcards\n" + + " headers Headers exchange that matches header fields against the binding keys\n" + + " xml XML Exchange - allows content filtering using an XQuery\n" + + "\n" + + "\n" + + "Queue Limit Actions\n" + + "\n" + + " none (default) - Use broker's default policy\n" + + " reject - Reject enqueued messages\n" + + " flow-to-disk - Page messages to disk\n" + + " ring - Replace oldest unacquired message with new\n" + + " ring-strict - Replace oldest message, reject if oldest is acquired\n" + + "\n" + + "Queue Ordering Policies\n" + + "\n" + + " fifo (default) - First in, first out\n" + + " lvq - Last Value Queue ordering, allows queue browsing\n" + + " lvq-no-browse - Last Value Queue ordering, browsing clients may lose data\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + "\n" + + " General Options:\n" + + " -t <secs>, --timeout=<secs>\n" + + " Maximum time to wait for broker connection (in\n" + + " seconds)\n" + + " -b, --bindings Show bindings in queue or exchange list\n" + + " -a <address>, --broker-addr=<address>\n" + + " Maximum time to wait for broker connection (in\n" + + " seconds)\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n" + + "\n" + + " Options for Adding Exchanges and Queues:\n" + + " --alternate-exchange=<aexname>\n" + + " Name of the alternate-exchange for the new queue or\n" + + " exchange. Exchanges route messages to the alternate\n" + + " exchange if they are unable to route them elsewhere.\n" + + " Queues route messages to the alternate exchange if\n" + + " they are rejected by a subscriber or orphaned by queue\n" + + " deletion.\n" + + " --passive, --dry-run\n" + + " Do not actually add the exchange or queue, ensure that\n" + + " all parameters and permissions are correct and would\n" + + " allow it to be created.\n" + + " --durable The new queue or exchange is durable.\n" + + "\n" + + " Options for Adding Queues:\n" + + " --file-count=<n> Number of files in queue's persistence journal\n" + + " --file-size=<n> File size in pages (64Kib/page)\n" + + " --max-queue-size=<n>\n" + + " Maximum in-memory queue size as bytes\n" + + " --max-queue-count=<n>\n" + + " Maximum in-memory queue size as a number of messages\n" + + " --limit-policy=<policy>\n" + + " Action to take when queue limit is reached\n" + + " --order=<ordering> Queue ordering policy\n" + + " --flow-stop-size=<n>\n" + + " Turn on sender flow control when the number of queued\n" + + " bytes exceeds this value.\n" + + " --flow-resume-size=<n>\n" + + " Turn off sender flow control when the number of queued\n" + + " bytes drops below this value.\n" + + " --flow-stop-count=<n>\n" + + " Turn on sender flow control when the number of queued\n" + + " messages exceeds this value.\n" + + " --flow-resume-count=<n>\n" + + " Turn off sender flow control when the number of queued\n" + + " messages drops below this value.\n" + + " --argument=<NAME=VALUE>\n" + + " Specify a key-value pair to add to queue arguments\n" + + "\n" + + " Options for Adding Exchanges:\n" + + " --sequence Exchange will insert a 'qpid.msg_sequence' field in\n" + + " the message header\n" + + " --ive Exchange will behave as an 'initial-value-exchange',\n" + + " keeping a reference to the last message forwarded and\n" + + " enqueuing that message to newly bound queues.\n" + + "\n" + + " Options for Deleting Queues:\n" + + " --force Force delete of queue even if it's currently used or\n" + + " it's not empty\n" + + " --force-if-not-empty\n" + + " Force delete of queue even if it's not empty\n" + + " --force-if-not-used\n" + + " Force delete of queue even if it's currently used\n" + + "\n" + + " Options for Declaring Bindings:\n" + + " -f <file.xq>, --file=<file.xq>\n" + + " For XML Exchange bindings - specifies the name of a\n" + + " file containing an XQuery.\n"; + + private Console _console; + private QmfConsoleData _broker; + + private boolean _recursive = false; + private String _host = "localhost"; + private int _connTimeout = 10; + private String _altExchange = null; + private boolean _passive = false; + private boolean _durable = false; + private boolean _ifEmpty = true; + private boolean _ifUnused = true; + private long _fileCount = 8; + private long _fileSize = 24; + private long _maxQueueSize = 0; + private long _maxQueueCount = 0; + private String _limitPolicy = "none"; + private String _order = "fifo"; + private boolean _msgSequence = false; + private boolean _ive = false; + private String _file = null; + + // New to Qpid 0.10 qpid-config + private String _saslMechanism = null; + private long _flowStopCount = 0; + private long _flowResumeCount = 0; + private long _flowStopSize = 0; + private long _flowResumeSize = 0; + private List<String> extraArguments = new ArrayList<String>(); + + private static final String FILECOUNT = "qpid.file_count"; + private static final String FILESIZE = "qpid.file_size"; + private static final String MAX_QUEUE_SIZE = "qpid.max_size"; + private static final String MAX_QUEUE_COUNT = "qpid.max_count"; + private static final String POLICY_TYPE = "qpid.policy_type"; + private static final String LVQ = "qpid.last_value_queue"; + private static final String LVQNB = "qpid.last_value_queue_no_browse"; + private static final String MSG_SEQUENCE = "qpid.msg_sequence"; + private static final String IVE = "qpid.ive"; + private static final String FLOW_STOP_COUNT = "qpid.flow_stop_count"; + private static final String FLOW_RESUME_COUNT = "qpid.flow_resume_count"; + private static final String FLOW_STOP_SIZE = "qpid.flow_stop_size"; + private static final String FLOW_RESUME_SIZE = "qpid.flow_resume_size"; + + // There are various arguments to declare that have specific program options in this utility. + // However there is now a generic mechanism for passing arguments as well. The SPECIAL_ARGS + // set contains the arguments for which there are specific program options defined i.e. the + // arguments for which there is special processing on add and list. + private static HashSet<String> SPECIAL_ARGS = new HashSet<String>(); + + static + { + SPECIAL_ARGS.add(FILECOUNT); + SPECIAL_ARGS.add(FILESIZE); + SPECIAL_ARGS.add(MAX_QUEUE_SIZE); + SPECIAL_ARGS.add(MAX_QUEUE_COUNT); + SPECIAL_ARGS.add(POLICY_TYPE); + SPECIAL_ARGS.add(LVQ); + SPECIAL_ARGS.add(LVQNB); + SPECIAL_ARGS.add(MSG_SEQUENCE); + SPECIAL_ARGS.add(IVE); + SPECIAL_ARGS.add(FLOW_STOP_COUNT); + SPECIAL_ARGS.add(FLOW_RESUME_COUNT); + SPECIAL_ARGS.add(FLOW_STOP_SIZE); + SPECIAL_ARGS.add(FLOW_RESUME_SIZE); + } + + /** + * Display long-form QpidConfig usage. + */ + private void usage() + { + System.out.println(_usage); + System.exit(1); + } + + /** + * Display QpidConfig options. + */ + private void options() + { + System.out.println(_usage); + System.out.println(_description); + System.out.println(_options); + System.exit(1); + } + + /** + * Finds a QmfConsoleData instance in a List of QMF Objects that matches a given ObjectID. + * + * More or less a direct Java port of findById from qpid-config. + * + * @param items the List of QMF Objects to search. + * @param id the ObjectId we're searching the List for. + * @return return the found object as a QmfConsoleData else return null. + */ + private QmfConsoleData findById(final List<QmfConsoleData> items, final ObjectId id) + { + for (QmfConsoleData item : items) + { + if (item.getObjectId().equals(id)) + { + return item; + } + } + + return null; + } + + /** + * Provide a basic overview of the number and type of queues and exchanges. + */ + private void overview() + { + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + + System.out.printf("Total Exchanges: %d\n", exchanges.size()); + + Map<String, AtomicInteger> etype = new HashMap<String, AtomicInteger>(); + for (QmfConsoleData exchange : exchanges) + { + String exchangeType = exchange.getStringValue("type"); + AtomicInteger n = etype.get(exchangeType); + if (n == null) + { + etype.put(exchangeType, new AtomicInteger(1)); + } + else + { + n.getAndIncrement(); + } + } + + for (Map.Entry<String, AtomicInteger> entry : etype.entrySet()) + { + System.out.printf("%15s: %s\n", entry.getKey(), entry.getValue()); + } + + System.out.println(); + System.out.printf(" Total Queues: %d\n", queues.size()); + + int durable = 0; + for (QmfConsoleData queue : queues) + { + boolean isDurable = queue.getBooleanValue("durable"); + if (isDurable) + { + durable++; + } + } + + System.out.printf(" durable: %d\n", durable); + System.out.printf(" non-durable: %d\n", queues.size() - durable); + } + + /** + * For every exchange list detailed info (equivalent of qpid-config exchanges). + * + * More or less a direct Java port of ExchangeList in qpid-config, which handles qpid-config exchanges. + * + * @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange. + */ + private void exchangeList(final String filter) + { + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + + String caption1 = "Type "; + String caption2 = "Exchange Name"; + int maxNameLen = caption2.length(); + + for (QmfConsoleData exchange : exchanges) + { + String name = exchange.getStringValue("name"); + if (filter.equals("") || filter.equals(name)) + { + if (name.length() > maxNameLen) + { + maxNameLen = name.length(); + } + } + } + + System.out.printf("%s%-" + maxNameLen + "s Attributes\n", caption1, caption2); + + StringBuilder buf = new StringBuilder(); + for (int i = 0; i < (((maxNameLen + caption1.length()) / 5) + 5); i++) + { + buf.append("====="); + } + String line = buf.toString(); + System.out.println(line); + + for (QmfConsoleData exchange : exchanges) + { + String name = exchange.getStringValue("name"); + if (filter.equals("") || filter.equals(name)) + { + System.out.printf("%-10s%-" + maxNameLen + "s ", exchange.getStringValue("type"), name); + Map args = (Map)exchange.getValue("arguments"); + args = (args == null) ? Collections.EMPTY_MAP : args; + + if (exchange.getBooleanValue("durable")) + { + System.out.printf("--durable "); + } + + if (args.containsKey(MSG_SEQUENCE) && QmfData.getLong(args.get(MSG_SEQUENCE)) == 1) + { + System.out.printf("--sequence "); + } + + if (args.containsKey(IVE) && QmfData.getLong(args.get(IVE)) == 1) + { + System.out.printf("--ive "); + } + + if (exchange.hasValue("altExchange")) + { + ObjectId altExchangeRef = exchange.getRefValue("altExchange"); + QmfConsoleData altExchange = findById(exchanges, altExchangeRef); + if (altExchange != null) + { + System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name")); + } + } + + System.out.println(); + } + } + } + + /** + * For every exchange list the bindings (equivalent of qpid-config -b exchanges). + * + * More or less a direct Java port of ExchangeListRecurse in qpid-config, which handles qpid-config -b exchanges. + * + * @param filter specifies the exchange name to display info for, if set to "" displays info for every exchange. + */ + private void exchangeListRecurse(final String filter) + { + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding"); + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + + for (QmfConsoleData exchange : exchanges) + { + ObjectId exchangeId = exchange.getObjectId(); + String name = exchange.getStringValue("name"); + + if (filter.equals("") || filter.equals(name)) + { + System.out.printf("Exchange '%s' (%s)\n", name, exchange.getStringValue("type")); + for (QmfConsoleData binding : bindings) + { + ObjectId exchangeRef = binding.getRefValue("exchangeRef"); + + if (exchangeRef.equals(exchangeId)) + { + ObjectId queueRef = binding.getRefValue("queueRef"); + QmfConsoleData queue = findById(queues, queueRef); + + String queueName = "<unknown>"; + if (queue != null) + { + queueName = queue.getStringValue("name"); + if (queueName.equals("")) + { + queueName = "''"; + } + } + + String bindingKey = binding.getStringValue("bindingKey"); + Map arguments = (Map)binding.getValue("arguments"); + if (arguments == null || arguments.isEmpty()) + { + System.out.printf(" bind [%s] => %s\n", bindingKey, queueName); + } + else + { + // If there are binding arguments then it's a headers exchange + System.out.printf(" bind [%s] => %s %s\n", bindingKey, queueName, arguments); + } + } + } + } + } + } + + /** + * For every queue list detailed info (equivalent of qpid-config queues). + * + * More or less a direct Java port of QueueList in qpid-config, which handles qpid-config queues. + * + * @param filter specifies the queue name to display info for, if set to "" displays info for every queue. + */ + private void queueList(final String filter) + { + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + + String caption = "Queue Name"; + int maxNameLen = caption.length(); + + for (QmfConsoleData queue : queues) + { + String name = queue.getStringValue("name"); + if (filter.equals("") || filter.equals(name)) + { + if (name.length() > maxNameLen) + { + maxNameLen = name.length(); + } + } + } + + System.out.printf("%-" + maxNameLen + "s Attributes\n", caption); + + StringBuilder buf = new StringBuilder(); + for (int i = 0; i < ((maxNameLen / 5) + 5); i++) + { + buf.append("====="); + } + String line = buf.toString(); + System.out.println(line); + + for (QmfConsoleData queue : queues) + { + String name = queue.getStringValue("name"); + if (filter.equals("") || filter.equals(name)) + { + System.out.printf("%-" + maxNameLen + "s ", name); + Map<String, Object> args = queue.<Map<String, Object>>getValue("arguments"); + args = (args == null) ? Collections.EMPTY_MAP : args; +/*System.out.println(args); +for (Map.Entry<String, Object> entry : args.entrySet()) { + System.out.println(entry.getKey() + " " + entry.getValue().getClass().getCanonicalName()); +}*/ + if (queue.getBooleanValue("durable")) + { + System.out.printf("--durable "); + } + + if (queue.getBooleanValue("autoDelete")) + { + System.out.printf("auto-del "); + } + + if (queue.getBooleanValue("exclusive")) + { + System.out.printf("excl "); + } + + if (args.containsKey(FILESIZE)) + { + System.out.printf("--file-size=%d ", QmfData.getLong(args.get(FILESIZE))); + } + + if (args.containsKey(FILECOUNT)) + { + System.out.printf("--file-count=%d ", QmfData.getLong(args.get(FILECOUNT))); + } + + if (args.containsKey(MAX_QUEUE_SIZE)) + { + System.out.printf("--max-queue-size=%d ", QmfData.getLong(args.get(MAX_QUEUE_SIZE))); + } + + if (args.containsKey(MAX_QUEUE_COUNT)) + { + System.out.printf("--max-queue-count=%d ", QmfData.getLong(args.get(MAX_QUEUE_COUNT))); + } + + if (args.containsKey(POLICY_TYPE)) + { + System.out.printf("--limit-policy=%s ", (QmfData.getString(args.get(POLICY_TYPE))).replace("_", "-")); + } + + if (args.containsKey(LVQ) && QmfData.getLong(args.get(LVQ)) == 1) + { + System.out.printf("--order lvq "); + } + + if (args.containsKey(LVQNB) && QmfData.getLong(args.get(LVQNB)) == 1) + { + System.out.printf("--order lvq-no-browse "); + } + + if (queue.hasValue("altExchange")) + { + ObjectId altExchangeRef = queue.getRefValue("altExchange"); + List<QmfConsoleData> altExchanges = _console.getObjects(altExchangeRef); + if (altExchanges.size() == 1) + { + QmfConsoleData altExchange = altExchanges.get(0); + System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name")); + } + } + + if (args.containsKey(FLOW_STOP_SIZE)) + { + System.out.printf("--flow-stop-size=%d ", QmfData.getLong(args.get(FLOW_STOP_SIZE))); + } + + if (args.containsKey(FLOW_RESUME_SIZE)) + { + System.out.printf("--flow-resume-size=%d ", QmfData.getLong(args.get(FLOW_RESUME_SIZE))); + } + + if (args.containsKey(FLOW_STOP_COUNT)) + { + System.out.printf("--flow-stop-count=%d ", QmfData.getLong(args.get(FLOW_STOP_COUNT))); + } + + if (args.containsKey(FLOW_RESUME_COUNT)) + { + System.out.printf("--flow-resume-count=%d ", QmfData.getLong(args.get(FLOW_RESUME_COUNT))); + } + + for (Map.Entry<String, Object> entry : args.entrySet()) + { // Display generic queue arguments + if (!SPECIAL_ARGS.contains(entry.getKey())) + { + System.out.printf("--argument %s=%s ", entry.getKey(), entry.getValue()); + } + } + + System.out.println(); + } + } + } + + /** + * For every queue list the bindings (equivalent of qpid-config -b queues). + * + * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues. + * + * @param filter specifies the queue name to display info for, if set to "" displays info for every queue. + */ + private void queueListRecurse(final String filter) + { + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding"); + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + + for (QmfConsoleData queue : queues) + { + ObjectId queueId = queue.getObjectId(); + String name = queue.getStringValue("name"); + + if (filter.equals("") || filter.equals(name)) + { + System.out.printf("Queue '%s'\n", name); + + for (QmfConsoleData binding : bindings) + { + ObjectId queueRef = binding.getRefValue("queueRef"); + + if (queueRef.equals(queueId)) + { + ObjectId exchangeRef = binding.getRefValue("exchangeRef"); + QmfConsoleData exchange = findById(exchanges, exchangeRef); + + String exchangeName = "<unknown>"; + if (exchange != null) + { + exchangeName = exchange.getStringValue("name"); + if (exchangeName.equals("")) + { + exchangeName = "''"; + } + } + + String bindingKey = binding.getStringValue("bindingKey"); + Map arguments = (Map)binding.getValue("arguments"); + if (arguments == null || arguments.isEmpty()) + { + System.out.printf(" bind [%s] => %s\n", bindingKey, exchangeName); + } + else + { + // If there are binding arguments then it's a headers exchange + System.out.printf(" bind [%s] => %s %s\n", bindingKey, exchangeName, arguments); + } + } + } + } + } + } + + /** + * Add an exchange using the QMF "create" method. + * @param args the exchange type is the first argument and the exchange name is the second argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void addExchange(final String[] args) + { + if (args.length < 2) + { + usage(); + } + + Map<String, Object> properties = new HashMap<String, Object>(); + if (_durable) + { + properties.put("durable", true); + } + + properties.put("exchange-type", args[0]); + + if (_msgSequence) + { + properties.put(MSG_SEQUENCE, 1l); + } + + if (_ive) + { + properties.put(IVE, 1l); + } + + if (_altExchange != null) + { + properties.put("alternate-exchange", _altExchange); + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "exchange"); + arguments.setValue("name", args[1]); + arguments.setValue("properties", properties); + + try + { + _broker.invokeMethod("create", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + // passive exchange creation not implemented yet (not sure how to do it using QMF2) + } + + /** + * Add a queue using the QMF "create" method. + * @param args the queue name is the first argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void addQueue(final String[] args) + { + if (args.length < 1) + { + usage(); + } + + Map<String, Object> properties = new HashMap<String, Object>(); + + for (String a : extraArguments) + { + String[] r = a.split("="); + String value = r.length == 2 ? r[1] : null; + properties.put(r[0], value); + } + + if (_durable) + { + properties.put("durable", true); + properties.put(FILECOUNT, _fileCount); + properties.put(FILESIZE, _fileSize); + } + + if (_maxQueueSize > 0) + { + properties.put(MAX_QUEUE_SIZE, _maxQueueSize); + } + + if (_maxQueueCount > 0) + { + properties.put(MAX_QUEUE_COUNT, _maxQueueCount); + } + + if (_limitPolicy.equals("reject")) + { + properties.put(POLICY_TYPE, "reject"); + } + else if (_limitPolicy.equals("flow-to-disk")) + { + properties.put(POLICY_TYPE, "flow_to_disk"); + } + else if (_limitPolicy.equals("ring")) + { + properties.put(POLICY_TYPE, "ring"); + } + else if (_limitPolicy.equals("ring-strict")) + { + properties.put(POLICY_TYPE, "ring_strict"); + } + + if (_order.equals("lvq")) + { + properties.put(LVQ, 1l); + } + else if (_order.equals("lvq-no-browse")) + { + properties.put(LVQNB, 1l); + } + + if (_altExchange != null) + { + properties.put("alternate-exchange", _altExchange); + } + + if (_flowStopSize > 0) + { + properties.put(FLOW_STOP_SIZE, _flowStopSize); + } + + if (_flowResumeSize > 0) + { + properties.put(FLOW_RESUME_SIZE, _flowResumeSize); + } + + if (_flowStopCount > 0) + { + properties.put(FLOW_STOP_COUNT, _flowStopCount); + } + + if (_flowResumeCount > 0) + { + properties.put(FLOW_RESUME_COUNT, _flowResumeCount); + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "queue"); + arguments.setValue("name", args[0]); + arguments.setValue("properties", properties); + + try + { + _broker.invokeMethod("create", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + // passive queue creation not implemented yet (not sure how to do it using QMF2) + } + + /** + * Remove an exchange using the QMF "delete" method. + * @param args the exchange name is the first argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void delExchange(final String[] args) + { + if (args.length < 1) + { + usage(); + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "exchange"); + arguments.setValue("name", args[0]); + + try + { + _broker.invokeMethod("delete", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + } + + /** + * Remove a queue using the QMF "delete" method. + * @param args the queue name is the first argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void delQueue(final String[] args) + { + if (args.length < 1) + { + usage(); + } + + if (_ifEmpty || _ifUnused) + { // Check the selected queue object to see if it is not empty or is in use + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + for (QmfConsoleData queue : queues) + { + ObjectId queueId = queue.getObjectId(); + String name = queue.getStringValue("name"); + if (name.equals(args[0])) + { + long msgDepth = queue.getLongValue("msgDepth"); + if (_ifEmpty == true && msgDepth > 0) + { + System.out.println("Cannot delete queue " + name + "; queue not empty"); + return; + } + + long consumerCount = queue.getLongValue("consumerCount"); + if (_ifUnused == true && consumerCount > 0) + { + System.out.println("Cannot delete queue " + name + "; queue in use"); + return; + } + } + } + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "queue"); + arguments.setValue("name", args[0]); + + try + { + _broker.invokeMethod("delete", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + } + + /** + * Add a binding using the QMF "create" method. + * @param args the exchange name is the first argument, the queue name is the second argument and the binding key + * is the third argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void bind(final String[] args) + { + if (args.length < 2) + { + usage(); + } + + // Look up exchange objects to find the type of the selected exchange + String exchangeType = null; + List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange"); + for (QmfConsoleData exchange : exchanges) + { + String name = exchange.getStringValue("name"); + if (args[0].equals(name)) + { + exchangeType = exchange.getStringValue("type"); + break; + } + } + + if (exchangeType == null) + { + System.out.println("Exchange " + args[0] + " is invalid"); + return; + } + + Map<String, Object> properties = new HashMap<String, Object>(); + if (exchangeType.equals("xml")) + { + if (_file == null) + { + System.out.println("Invalid args to bind xml: need an input file or stdin"); + return; + } + + String xquery = null; + if (_file.equals("-")) + { // Read xquery off stdin + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + try + { + StringBuilder buf = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) // read until eof + { + buf.append(line + "\n"); + } + xquery = buf.toString(); + } + catch (IOException ioe) + { + System.out.println("Exception " + ioe + " while reading stdin"); + return; + } + } + else + { // Read xquery from input file + File file = new File(_file); + try + { + FileInputStream fin = new FileInputStream(file); + try + { + byte content[] = new byte[(int)file.length()]; + fin.read(content); + xquery = new String(content); + } + finally + { + fin.close(); + } + } + catch (FileNotFoundException e) + { + System.out.println("File " + _file + " not found"); + return; + } + catch (IOException ioe) + { + System.out.println("Exception " + ioe + " while reading " + _file); + return; + } + } + properties.put("xquery", xquery); + } + else if (exchangeType.equals("headers")) + { + if (args.length < 5) + { + System.out.println("Invalid args to bind headers: need 'any'/'all' plus conditions"); + return; + } + String op = args[3]; + if (op.equals("all") || op.equals("any")) + { + properties.put("x-match", op); + String[] bindings = Arrays.copyOfRange(args, 4, args.length); + for (String binding : bindings) + { + if (binding.contains("=")) + { + binding = binding.split(",")[0]; + String[] kv = binding.split("="); + properties.put(kv[0], kv[1]); + } + } + } + else + { + System.out.println("Invalid condition arg to bind headers, need 'any' or 'all', not '" + op + "'"); + return; + } + } + + String bindingIdentifier = args[0] + "/" + args[1]; + if (args.length > 2) + { + bindingIdentifier = bindingIdentifier + "/" + args[2]; + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "binding"); + arguments.setValue("name", bindingIdentifier); + arguments.setValue("properties", properties); + + try + { + _broker.invokeMethod("create", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + } + + /** + * Remove a binding using the QMF "delete" method. + * @param args the exchange name is the first argument, the queue name is the second argument and the binding key + * is the third argument. + * The remaining QMF method properties are populated form config parsed from the command line. + */ + private void unbind(final String[] args) + { + if (args.length < 2) + { + usage(); + } + + String bindingIdentifier = args[0] + "/" + args[1]; + if (args.length > 2) + { + bindingIdentifier = bindingIdentifier + "/" + args[2]; + } + + QmfData arguments = new QmfData(); + arguments.setValue("type", "binding"); + arguments.setValue("name", bindingIdentifier); + + try + { + _broker.invokeMethod("delete", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + } + + /** + * Create an instance of QpidConfig. + * + * @param args the command line arguments. + */ + public QpidConfig(final String[] args) + { + String[] longOpts = {"help", "durable", "bindings", "broker-addr=", "file-count=", + "file-size=", "max-queue-size=", "max-queue-count=", "limit-policy=", + "order=", "sequence", "ive", "force", "force-if-not-empty", + "force-if-used", "alternate-exchange=", "passive", "timeout=", "file=", "flow-stop-size=", + "flow-resume-size=", "flow-stop-count=", "flow-resume-count=", "argument="}; + + try + { + GetOpt getopt = new GetOpt(args, "ha:bf:", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + + //System.out.println("optList"); + for (String[] opt : optList) + { + //System.out.println(opt[0] + ":" + opt[1]); + + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + options(); + } + + if (opt[0].equals("-b") || opt[0].equals("--bindings")) + { + _recursive = true; + } + + if (opt[0].equals("-a") || opt[0].equals("--broker-addr")) + { + _host = opt[1]; + } + + if (opt[0].equals("-f") || opt[0].equals("--file")) + { + _file = opt[1]; + } + + if (opt[0].equals("--timeout")) + { + _connTimeout = Integer.parseInt(opt[1]); + } + + if (opt[0].equals("--alternate-exchange")) + { + _altExchange = opt[1]; + } + + if (opt[0].equals("--passive")) + { + _passive = true; + } + + if (opt[0].equals("--durable")) + { + _durable = true; + } + + if (opt[0].equals("--file-count")) + { + _fileCount = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--file-size")) + { + _fileSize = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--max-queue-size")) + { + _maxQueueSize = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--max-queue-count")) + { + _maxQueueCount = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--limit-policy")) + { + _limitPolicy = opt[1]; + } + + if (opt[0].equals("--flow-stop-size")) + { + _flowStopSize = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--flow-resume-size")) + { + _flowResumeSize = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--flow-stop-count")) + { + _flowStopCount = Long.parseLong(opt[1]); + } + + if (opt[0].equals("--flow-resume-count")) + { + _flowResumeCount = Long.parseLong(opt[1]); + } + + boolean validPolicy = false; + String[] validPolicies = {"none", "reject", "flow-to-disk", "ring", "ring-strict"}; + for (String i : validPolicies) + { + if (_limitPolicy.equals(i)) + { + validPolicy = true; + break; + } + } + + if (!validPolicy) + { + System.err.println("Error: Invalid --limit-policy argument"); + System.exit(1); + } + + if (opt[0].equals("--order")) + { + _order = opt[1]; + } + + boolean validOrder = false; + String[] validOrders = {"fifo", "lvq", "lvq-no-browse"}; + for (String i : validOrders) + { + if (_order.equals(i)) + { + validOrder = true; + break; + } + } + + if (!validOrder) + { + System.err.println("Error: Invalid --order argument"); + System.exit(1); + } + + if (opt[0].equals("--sequence")) + { + _msgSequence = true; + } + + if (opt[0].equals("--ive")) + { + _ive = true; + } + + if (opt[0].equals("--force")) + { + _ifEmpty = false; + _ifUnused = false; + } + + if (opt[0].equals("--force-if-not-empty")) + { + _ifEmpty = false; + } + + if (opt[0].equals("--force-if-used")) + { + _ifUnused = false; + } + + if (opt[0].equals("--argument")) + { + extraArguments.add(opt[1]); + } + } + + Connection connection = ConnectionHelper.createConnection(_host, "{reconnect: true}"); + _console = new Console(); + _console.disableEvents(); // Optimisation, as we're only doing getObjects() calls. + _console.addConnection(connection); + List<QmfConsoleData> brokers = _console.getObjects("org.apache.qpid.broker", "broker"); + if (brokers.isEmpty()) + { + System.out.println("No broker QmfConsoleData returned"); + System.exit(1); + } + + _broker = brokers.get(0); + + int nargs = cargs.length; + if (nargs == 0) + { + overview(); + } + else + { + String cmd = cargs[0]; + String modifier = ""; + + if (nargs > 1) + { + modifier = cargs[1]; + } + + if (cmd.equals("exchanges")) + { + if (_recursive) + { + exchangeListRecurse(modifier); + } + else + { + exchangeList(modifier); + } + } + else if (cmd.equals("queues")) + { + if (_recursive) + { + queueListRecurse(modifier); + } + else + { + queueList(modifier); + } + } + else if (cmd.equals("add")) + { + if (modifier.equals("exchange")) + { + addExchange(Arrays.copyOfRange(cargs, 2, cargs.length)); + } + else if (modifier.equals("queue")) + { + addQueue(Arrays.copyOfRange(cargs, 2, cargs.length)); + } + else + { + usage(); + } + } + else if (cmd.equals("del")) + { + if (modifier.equals("exchange")) + { + delExchange(Arrays.copyOfRange(cargs, 2, cargs.length)); + } + else if (modifier.equals("queue")) + { + delQueue(Arrays.copyOfRange(cargs, 2, cargs.length)); + } + else + { + usage(); + } + } + else if (cmd.equals("bind")) + { + bind(Arrays.copyOfRange(cargs, 1, cargs.length)); + } + else if (cmd.equals("unbind")) + { + unbind(Arrays.copyOfRange(cargs, 1, cargs.length)); + } + else + { + usage(); + } + } + } + catch (QmfException e) + { + System.err.println(e.toString()); + usage(); + } + catch (IllegalArgumentException e) + { + System.err.println(e.toString()); + usage(); + } + } + + /** + * Runs QpidConfig. + * @param args the command line arguments. + */ + public static void main(String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting. + // Setting the following property to true makes it a Daemon Thread. + System.setProperty("qpid.jms.daemon.dispatcher", "true"); + + QpidConfig qpidConfig = new QpidConfig(args); + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java new file mode 100644 index 0000000000..fa06b06519 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidCtrl.java @@ -0,0 +1,358 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.util.Arrays; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfData; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.MethodResult; +import org.apache.qpid.qmf2.console.QmfConsoleData; + +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +// Reuse this class as it provides a handy mechanism to parse an args String into a Map +import org.apache.qpid.messaging.util.AddressParser; + +/** + * A tool to allow QMF2 methods to be invoked from the command line. + * <pre> + * Usage: QpidCtrl [options] command [args] + * The args need to be in a Stringified Map format (similar to an Address String) + * e.g. to set broker log level: QpidCtrl setLogLevel "{level:\"debug+:Broker\"}" + * The listValues command lists property names and values of the specified object. + * The listObjects command lists all objects of the specified package and class. + * + * Options: + * -h, --help show this help message and exit + * -v enable logging + * -a <address>, --broker-address=<address> + * broker-addr is in the form: [username/password@] + * hostname | ip-address [:<port>] ex: localhost, + * 10.1.1.7:10000, broker-host:10000, + * guest/guest@localhost + * -c <class>, --class=<class> + * class of object on which command is being invoked + * (default broker) + * -p <package>, --package=<package> + * package of object on which command is being invoked + * (default org.apache.qpid.broker) + * -i <id>, --id=<id> identifier of object on which command is being invoked + * (default amqp-broker) + * --agent=<agent name> + * The name of the Agent to which commands will be sent + * This will try to match <agent name> against the Agent name + * the Agent product name and will also check if the Agent name + * contains the <agent name> String + * (default qpidd) + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * </pre> + * Examples (Note the quotes and escaped quotes are significant!): + * <p> + * Get the current broker log level: + * <pre>QpidCtrl getLogLevel</pre> + * + * Set the current broker log level to notice+: + * <pre>QpidCtrl setLogLevel "{level:\"notice+\"}"</pre> + * + * Set the current broker log level to debug+ for all Management Objects: + * <pre>QpidCtrl setLogLevel "{level:\"debug+\"}"</pre> + * + * Set the current broker log level to debug+ for just the Broker Management Object: + * <pre>QpidCtrl setLogLevel "{level:\"debug+:Broker\"}"</pre> + * + * List the properties of the qmf.default.direct exchange: + * <pre>QpidCtrl -c exchange -i qmf.default.direct listValues</pre> + * + * Create a queue called test with a flow-to-disk limit policy: + * <pre>QpidCtrl create "{type:queue,name:test,properties:{'qpid.policy_type':ring}}"</pre> + * + * Delete a queue called test: + * <pre>QpidCtrl delete "{type:queue,name:test}"</pre> + * + * Create a binding called bind1 between the amq.match exchange and the test queue matching the headers name=fadams + * and gender=male: + * <pre>QpidCtrl create "{type:binding,name:'amq.match/test/bind1',properties:{x-match:all,name:fadams,gender:male}}"</pre> + * + * Delete the binding called bind1 between the amq.match exchange and the test queue: + * <pre>QpidCtrl delete "{type:binding,name:'amq.match/test/bind1'}"</pre> + * + * Get the broker to echo a message: + * <pre>QpidCtrl echo "{sequence:1234,body:'Peaches En Regalia'}"</pre> + * + * Invoke the event method on the gizmo Agent (launch gizmo Agent via AgentTest): + * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo event</pre> + * + * Invoke the create_child method on the gizmo Agent (launch gizmo Agent via AgentTest): + * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo create_child "{name:monkeyBoy}"</pre> + * + * Invoke the stop method on the gizmo Agent (launch gizmo Agent via AgentTest): + * <pre>QpidCtrl -p com.profitron.gizmo -c control -i OPERATIONAL --agent=gizmo stop "{message:'Will I dream?'}"</pre> + * + * @author Fraser Adams + */ +public final class QpidCtrl +{ + private static final String _usage = + "Usage: QpidCtrl [options] command [args]\n" + + "The args need to be in a Stringified Map format (similar to an Address String)\n" + + "e.g. to set broker log level: QpidCtrl setLogLevel \"{level:\\\"debug+:Broker\\\"}\"\n" + + "The listValues command lists property names and values of the specified object.\n" + + "The listObjects command lists all objects of the specified package and class.\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " -v enable logging\n" + + " -a <address>, --broker-address=<address>\n" + + " broker-addr is in the form: [username/password@]\n" + + " hostname | ip-address [:<port>] ex: localhost,\n" + + " 10.1.1.7:10000, broker-host:10000,\n" + + " guest/guest@localhost\n" + + " -c <class>, --class=<class>\n" + + " class of object on which command is being invoked\n" + + " (default broker)\n" + + " -p <package>, --package=<package>\n" + + " package of object on which command is being invoked\n" + + " (default org.apache.qpid.broker)\n" + + " -i <id>, --id=<id> identifier of object on which command is being invoked\n" + + " (default amqp-broker)\n" + + " --agent=<agent name>\n" + + " The name of the Agent to which commands will be sent\n" + + " This will try to match <agent name> against the Agent name,\n" + + " the Agent product name and will also check if the Agent name\n" + + " contains the <agent name> String\n" + + " (default qpidd)\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n"; + + private Console _console; + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the Connection URL. + * @param connectionOptions the connection options String to pass to ConnectionHelper. + * @param pkg the package name of the object we're invoking the method on. + * @param cls the class name of the object we're invoking the method on. + * @param id the ObjectId name of the object we're invoking the method on. + * @param agentName the name of the Agent to invoke the QMF method on. + * @param command the QMF method we're invoking. + * @param args the Stringified Map form of the method arguments. + */ + public QpidCtrl(final String url, final String connectionOptions, final String pkg, final String cls, + final String id, final String agentName, final String command, final String args) + { + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(); + _console.addConnection(connection); + + // Find the specified Agent + Agent agent = _console.findAgent(agentName); + if (agent == null) + { + System.out.println("Agent " + agentName + " not found"); + System.exit(1); + } + + List<Agent> agentList = Arrays.asList(new Agent[] {agent}); + List<QmfConsoleData> objects = _console.getObjects(pkg, cls, agentList); + + // Parse the args String + QmfData inArgs = (args == null) ? new QmfData() : new QmfData(new AddressParser(args).map()); + + // Find the required QmfConsoleData object and invoke the specified command + MethodResult results = null; + for (QmfConsoleData object : objects) + { + String objectName = object.getObjectId().getObjectName(); + if (command.equals("listObjects")) + { + System.out.println(objectName); + } + else + { + if (objectName.contains(id)) + { // Use contains as ObjectNames may comprise other identifiers tha make using equals impractical + if (command.equals("listValues")) + { + object.listValues(); + System.exit(1); + } + else + { + results = object.invokeMethod(command, inArgs); + } + break; + } + } + } + + if (results == null) + { + if (objects.size() == 0) + { + System.out.println("getObjects(" + pkg + ", " + cls + ", " + agentName + ") returned no objects."); + } + else + { + System.out.println("Id " + id + " not found in " + pkg + ":" + cls); + } + } + else + { + if (results.succeeded()) + { + results.listValues(); + } + else + { + System.err.println ("QmfException " + results.getQmfException().getMessage() + + " returned from " + command + " method"); + } + } + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidCtrl constructor"); + } + } + + /** + * Runs QpidCtrl. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + // As of Qpid 0.16 the Session Dispatcher Thread is non-Daemon so the JVM gets prevented from exiting. + // Setting the following property to true makes it a Daemon Thread. + System.setProperty("qpid.jms.daemon.dispatcher", "true"); + + String[] longOpts = {"help", "broker-address=", "class=", "package=", "id=", "agent=", "sasl-mechanism="}; + try + { + String host = "localhost"; + String connectionOptions = "{reconnect: true}"; + String cls = "broker"; + String pkg = "org.apache.qpid.broker"; + String id = "amqp-broker"; + String agentName = "qpidd"; + String command = null; + String arg = null; + + GetOpt getopt = new GetOpt(args, "ha:c:p:i:v", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) + { + host = opt[1]; + } + else if (opt[0].equals("-c") || opt[0].equals("--class")) + { + cls = opt[1]; + } + else if (opt[0].equals("-p") || opt[0].equals("--package")) + { + pkg = opt[1]; + } + else if (opt[0].equals("-i") || opt[0].equals("--id")) + { + id = opt[1]; + } + else if (opt[0].equals("--agent")) + { + agentName = opt[1]; + } + else if (opt[0].equals("-v")) + { + System.setProperty("amqj.logging.level", "DEBUG"); + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + if (cargs.length < 1 || cargs.length > 2) + { + System.out.println(Arrays.asList(cargs)); + System.out.println(_usage); + System.exit(1); + } + + command = cargs[0]; + + if (cargs.length == 2) + { + arg = cargs[1]; + if (!arg.startsWith("{") || !arg.endsWith("}")) + { + System.out.println("Incorrect format for args."); + System.out.println("This needs to be in a Stringified Map format similar to an Address String"); + System.exit(1); + } + } + + QpidCtrl qpidCtrl = new QpidCtrl(host, connectionOptions, pkg, cls, id, agentName, command, arg); + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.out.println(e.getMessage()); + System.exit(1); + } + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java new file mode 100644 index 0000000000..34a38bf8d7 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidPrintEvents.java @@ -0,0 +1,210 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.Map; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfEvent; +import org.apache.qpid.qmf2.common.QmfEventListener; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.common.WorkItem; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.EventReceivedWorkItem; +import org.apache.qpid.qmf2.console.QmfConsoleData; +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; +import static org.apache.qpid.qmf2.common.WorkItem.WorkItemType.*; + +/** + * Collect and print events from one or more Qpid message brokers. + * <pre> + * If no broker-addr is supplied, QpidPrintEvents connects to 'localhost:5672'. + * + * [broker-addr] syntax: + * + * [username/password@] hostname + * ip-address [:<port>] + * + * Examples: + * + * $ QpidPrintEvents localhost:5672 + * $ QpidPrintEvents 10.1.1.7:10000 + * $ QpidPrintEvents guest/guest@broker-host:10000 + * + * Options: + * -h, --help show this help message and exit + * --heartbeats Use heartbeats. + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * </pre> + * @author Fraser Adams + */ +public final class QpidPrintEvents implements QmfEventListener +{ + private static final String _usage = + "Usage: QpidPrintEvents [options] [broker-addr]...\n"; + + private static final String _description = + "Collect and print events from one or more Qpid message brokers.\n" + + "\n" + + "If no broker-addr is supplied, QpidPrintEvents connects to 'localhost:5672'.\n" + + "\n" + + "[broker-addr] syntax:\n" + + "\n" + + "[username/password@] hostname\n" + + "ip-address [:<port>]\n" + + "\n" + + "Examples:\n" + + "\n" + + "$ QpidPrintEvents localhost:5672\n" + + "$ QpidPrintEvents 10.1.1.7:10000\n" + + "$ QpidPrintEvents guest/guest@broker-host:10000\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " --heartbeats Use heartbeats.\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n"; + + private final String _url; + private Console _console; + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the connection URL. + * @param connectionOptions the options String to pass to ConnectionHelper. + */ + public QpidPrintEvents(final String url, final String connectionOptions) + { + System.out.println("Connecting to " + url); + _url = url; + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(this); + _console.addConnection(connection); + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidPrintEvents constructor"); + } + } + + /** + * Checks if the WorkItem is an EventReceivedWorkItem and if it is extracts and renders the QmfEvent. + * @param wi a QMF2 WorkItem object + */ + public void onEvent(final WorkItem wi) + { + if (wi instanceof EventReceivedWorkItem) + { + EventReceivedWorkItem item = (EventReceivedWorkItem)wi; + QmfEvent event = item.getEvent(); + System.out.println(event + " broker=" + _url); + } + } + + /** + * Runs QpidPrintEvents. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + String[] longOpts = {"help", "heartbeats", "sasl-mechanism="}; + try + { + String connectionOptions = "{reconnect: true}"; + GetOpt getopt = new GetOpt(args, "h", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_description); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("--heartbeats")) + { + // Ignore Java uses heartbeats by default + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + int nargs = cargs.length; + if (nargs == 0) + { + cargs = new String[] {"localhost"}; + } + + for (String url : cargs) + { + QpidPrintEvents eventPrinter = new QpidPrintEvents(url, connectionOptions); + } + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.exit(1); + } + + BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in)); + try + { // Blocks here until return is pressed + System.out.println("Hit Return to exit"); + String s = commandLine.readLine(); + System.exit(0); + } + catch (IOException e) + { + System.out.println ("QpidPrintEvents main(): IOException: " + e.getMessage()); + } + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java new file mode 100644 index 0000000000..4ac434dc17 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QpidQueueStats.java @@ -0,0 +1,374 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfEvent; +import org.apache.qpid.qmf2.common.QmfEventListener; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.common.QmfQuery; +import org.apache.qpid.qmf2.common.QmfQueryTarget; +import org.apache.qpid.qmf2.common.SchemaClassId; +import org.apache.qpid.qmf2.common.WorkItem; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem; +import org.apache.qpid.qmf2.console.AgentRestartedWorkItem; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.QmfConsoleData; + +import org.apache.qpid.qmf2.console.SubscribeIndication; +import org.apache.qpid.qmf2.console.SubscribeParams; +import org.apache.qpid.qmf2.console.SubscriptionIndicationWorkItem; + +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +/** + * Collect and print queue statistics. + * <pre> + * Usage: QpidQueueStats [options] + * + * Options: + * -h, --help show this help message and exit + * -a <address>, --broker-address=<address> + * broker-addr is in the form: [username/password@] + * hostname | ip-address [:<port>] ex: localhost, + * 10.1.1.7:10000, broker-host:10000, + * guest/guest@localhost + * -f <filter>, --filter=<filter> + * a list of comma separated queue names (regex are + * accepted) to show + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * </pre> + * @author Fraser Adams + */ +public final class QpidQueueStats implements QmfEventListener +{ + private final class Stats + { + private final String _name; + private QmfConsoleData _data; + + public Stats(final String name, final QmfConsoleData data) + { + _name = name; + _data = data; + } + + public String getName() + { + return _name; + } + + public QmfConsoleData getData() + { + return _data; + } + + public void setData(final QmfConsoleData data) + { + _data = data; + } + } + + private static final String _usage = + "Usage: QpidQueueStats [options]\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " -a <address>, --broker-address=<address>\n" + + " broker-addr is in the form: [username/password@]\n" + + " hostname | ip-address [:<port>] ex: localhost,\n" + + " 10.1.1.7:10000, broker-host:10000,\n" + + " guest/guest@localhost\n" + + " -f <filter>, --filter=<filter>\n" + + " a list of comma separated queue names (regex are\n" + + " accepted) to show\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n"; + + private final String _url; + private final List<Pattern> _filter; + private Agent _broker; + private Console _console; + private Map<ObjectId, Stats> _objects = new HashMap<ObjectId, Stats>(); + private String _subscriptionId = null; + private long _subscriptionDuration; + private long _startTime; + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the connection URL. + * @param connectionOptions the options String to pass to ConnectionHelper. + * @param filter a list of regex Patterns used to choose the queues we wish to display. + */ + public QpidQueueStats(final String url, final String connectionOptions, final List<Pattern> filter) + { + System.out.println("Connecting to " + url); + if (filter.size() > 0) + { + System.out.println("Filter = " + filter); + } + _url = url; + _filter = filter; + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(this); + _console.addConnection(connection); + + // Wait until the broker Agent has been discovered + _broker = _console.findAgent("broker"); + if (_broker != null) + { + createQueueSubscription(); + } + + System.out.println("Hit Return to exit"); + System.out.println( + "Queue Name Sec Depth Enq Rate Deq Rate"); + System.out.println( + "============================================================================================="); + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidQueueStats constructor"); + } + } + + /** + * Create a Subscription to query for all queue objects + */ + private void createQueueSubscription() + { + try + { // This QmfQuery simply does an ID query for objects with the className "queue" + QmfQuery query = new QmfQuery(QmfQueryTarget.OBJECT, new SchemaClassId("queue")); + SubscribeParams params = _console.createSubscription(_broker, query, "queueStatsHandle"); + _subscriptionId = params.getSubscriptionId(); + _subscriptionDuration = params.getLifetime() - 10; // Subtract 10 as we want to refresh before it times out + _startTime = System.currentTimeMillis(); + } + catch (QmfException qmfe) + { + } + } + + /** + * Main Event handler. Checks if the WorkItem is a SubscriptionIndicationWorkItem, if it is it stores the object + * in a Map and uses this to maintain state so we can record deltas such as enqueue and dequeue rates. + * <p> + * The AgentHeartbeatWorkItem is used to periodically compare the elapsed time against the Subscription duration + * so that we can refresh the Subscription (or create a new one if necessary) in order to continue receiving + * queue Management Object data from the broker. + * <p> + * When the AgentRestartedWorkItem is received we clear the state to remove any stale queue Management Objects. + * @param wi a QMF2 WorkItem object + */ + public void onEvent(final WorkItem wi) + { + if (wi instanceof AgentHeartbeatWorkItem && _subscriptionId != null) + { + long elapsed = (long)Math.round((System.currentTimeMillis() - _startTime)/1000.0f); + if (elapsed > _subscriptionDuration) + { + try + { + _console.refreshSubscription(_subscriptionId); + _startTime = System.currentTimeMillis(); + } + catch (QmfException qmfe) + { + System.err.println ("QmfException " + qmfe.getMessage() + " caught in QpidQueueStats onEvent"); + createQueueSubscription(); + } + } + } + else if (wi instanceof AgentRestartedWorkItem) + { + _objects.clear(); + } + else if (wi instanceof SubscriptionIndicationWorkItem) + { + SubscriptionIndicationWorkItem item = (SubscriptionIndicationWorkItem)wi; + SubscribeIndication indication = item.getSubscribeIndication(); + String correlationId = indication.getConsoleHandle(); + if (correlationId.equals("queueStatsHandle")) + { // If it is (and it should be!!) then it's our queue object Subscription + List<QmfConsoleData> data = indication.getData(); + for (QmfConsoleData record : data) + { + ObjectId id = record.getObjectId(); + if (record.isDeleted()) + { // If the object was deleted by the Agent we remove it from out Map + _objects.remove(id); + } + else + { + if (_objects.containsKey(id)) + { // If the object is already in the Map it's likely to be a statistics push from the broker. + Stats stats = _objects.get(id); + String name = stats.getName(); + + boolean matches = false; + for (Pattern x : _filter) + { // Check the queue name against the regexes in the filter List (if any) + Matcher m = x.matcher(name); + if (m.find()) + { + matches = true; + break; + } + } + + if (_filter.isEmpty() || matches) + { // If there's no filter enabled or the filter matches the queue name we display statistics. + QmfConsoleData lastSample = stats.getData(); + stats.setData(record); + + float deltaTime = record.getUpdateTime() - lastSample.getUpdateTime(); + if (deltaTime > 1000000000.0f) + { + float deltaEnqueues = record.getLongValue("msgTotalEnqueues") - + lastSample.getLongValue("msgTotalEnqueues"); + float deltaDequeues = record.getLongValue("msgTotalDequeues") - + lastSample.getLongValue("msgTotalDequeues"); + long msgDepth = record.getLongValue("msgDepth"); + float enqueueRate = deltaEnqueues/(deltaTime/1000000000.0f); + float dequeueRate = deltaDequeues/(deltaTime/1000000000.0f); + + System.out.printf("%-46s%10.2f%11d%13.2f%13.2f\n", + name, deltaTime/1000000000, msgDepth, enqueueRate, dequeueRate); + } + } + } + else + { // If the object isn't in the Map it's likely to be a properties push from the broker. + if (!record.hasValue("name")) + { // This probably won't happen, but if it does we refresh the object to get its full state. + try + { + record.refresh(); + } + catch (QmfException qmfe) + { + } + } + String queueName = record.getStringValue("name"); + _objects.put(id, new Stats(queueName, record)); + } + } + } + } + } + } + + /** + * Runs QpidQueueStats. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + String[] longOpts = {"help", "broker-address=", "filter=", "sasl-mechanism="}; + try + { + String host = "localhost"; + String connectionOptions = "{reconnect: true}"; + List<Pattern> filter = new ArrayList<Pattern>(); + GetOpt getopt = new GetOpt(args, "ha:f:", longOpts); + List<String[]> optList = getopt.getOptList(); + + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("-a") || opt[0].equals("--broker-address")) + { + host = opt[1]; + } + else if (opt[0].equals("-f") || opt[0].equals("--filter")) + { + String[] split = opt[1].split(","); + for (String s : split) + { + Pattern p = Pattern.compile(s); + filter.add(p); + } + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + QpidQueueStats queueStats = new QpidQueueStats(host, connectionOptions, filter); + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.out.println(e.getMessage()); + System.exit(1); + } + + BufferedReader commandLine = new BufferedReader(new InputStreamReader(System.in)); + try + { // Blocks here until return is pressed + String s = commandLine.readLine(); + System.exit(0); + } + catch (IOException e) + { + System.out.println ("QpidQueueStats main(): IOException: " + e.getMessage()); + } + } +} diff --git a/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java new file mode 100644 index 0000000000..31368ed242 --- /dev/null +++ b/qpid/tools/src/java/qpid-qmf2-tools/src/main/java/org/apache/qpid/qmf2/tools/QueueFuse.java @@ -0,0 +1,364 @@ +/* + * + * 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.qmf2.tools; + +// JMS Imports +import javax.jms.Connection; + +// Misc Imports +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +// QMF2 Imports +import org.apache.qpid.qmf2.common.ObjectId; +import org.apache.qpid.qmf2.common.QmfData; +import org.apache.qpid.qmf2.common.QmfEvent; +import org.apache.qpid.qmf2.common.QmfEventListener; +import org.apache.qpid.qmf2.common.QmfException; +import org.apache.qpid.qmf2.common.SchemaClassId; +import org.apache.qpid.qmf2.common.WorkItem; +import org.apache.qpid.qmf2.console.Agent; +import org.apache.qpid.qmf2.console.Console; +import org.apache.qpid.qmf2.console.EventReceivedWorkItem; +import org.apache.qpid.qmf2.console.QmfConsoleData; + +import org.apache.qpid.qmf2.util.ConnectionHelper; +import org.apache.qpid.qmf2.util.GetOpt; + +/** + * QueueFuse provides protection to message producers from consumers who can't consume messages fast enough. + * <p> + * With the default "reject" limit policy when a queue exceeds its capacity an exception is thrown to the + * producer. This behaviour is unfortunate, because if there happen to be multiple consumers consuming + * messages from a given producer it is possible for a single slow consumer to cause message flow to be + * stopped to <u>all</u> consumers, in other words a de-facto denial of service may take place. + * <p> + * In an Enterprise environment it is likely that this sort of behaviour is unwelcome, so QueueFuse makes it + * possible for queueThresholdExceeded Events to be detected and for the offending queues to have messages + * purged, thus protecting the other consumers by preventing an exception being thrown to the message producer. + * <p> + * The original intention with this class was to unbind bindings to queues that exceed the threshold. This method + * works, but it has a number of disadvantages. In particular there is no way to unbind from (and thus protect) + * queues bound to the default direct exchange, in addition in order to unbind it is necessary to retrieve + * binding and exchange information, both of which require further exchanges with the broker (which is not + * desirable as when the queueThresholdExceeded occurs we need to act pretty quickly). Finally as it happens + * it is also necessary to purge some messages after unbinding anyway as if this is not done the queue remains + * in the flowStopped state and producers will eventually time out and throw an exception if this is not cleared. + * So all in all simply purging each time we cross the threshold is simpler and has the additional advantage that + * if and when the consumer speeds up message delivery will eventually return to normal. + * + * <pre> + * Usage: QueueFuse [options] [broker-addr]... + * + * Monitors one or more Qpid message brokers for queueThresholdExceeded Events. + * + * If a queueThresholdExceeded Event occurs messages are purged from the queue, + * in other words this class behaves rather like a fuse 'blowing' if the + * threshold gets exceeded. + * + * If no broker-addr is supplied, QueueFuse connects to 'localhost:5672'. + * + * [broker-addr] syntax: + * + * [username/password@] hostname + * ip-address [:<port>] + * + * Examples: + * + * $ QueueFuse localhost:5672 + * $ QueueFuse 10.1.1.7:10000 + * $ QueueFuse guest/guest@broker-host:10000 + * + * Options: + * -h, --help show this help message and exit + * -f <filter>, --filter=<filter> + * a list of comma separated queue names (regex are + * accepted) to protect (default is to protect all). + * -p <PERCENT>, --purge=<PERCENT>\n" + + * The percentage of messages to purge when the queue\n" + + * threshold gets exceeded (default = 20%).\n" + + * N.B. if this gets set too low the fuse may not blow.\n" + + * --sasl-mechanism=<mech> + * SASL mechanism for authentication (e.g. EXTERNAL, + * ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL + * automatically picks the most secure available + * mechanism - use this option to override. + * </pre> + * @author Fraser Adams + */ +public final class QueueFuse implements QmfEventListener +{ + private static final String _usage = + "Usage: QueueFuse [options] [broker-addr]...\n"; + + private static final String _description = + "Monitors one or more Qpid message brokers for queueThresholdExceeded Events.\n" + + "\n" + + "If a queueThresholdExceeded Event occurs messages are purged from the queue,\n" + + "in other words this class behaves rather like a fuse 'blowing' if the\n" + + "threshold gets exceeded.\n" + + "\n" + + "If no broker-addr is supplied, QueueFuse connects to 'localhost:5672'.\n" + + "\n" + + "[broker-addr] syntax:\n" + + "\n" + + "[username/password@] hostname\n" + + "ip-address [:<port>]\n" + + "\n" + + "Examples:\n" + + "\n" + + "$ QueueFuse localhost:5672\n" + + "$ QueueFuse 10.1.1.7:10000\n" + + "$ QueueFuse guest/guest@broker-host:10000\n"; + + private static final String _options = + "Options:\n" + + " -h, --help show this help message and exit\n" + + " -f <filter>, --filter=<filter>\n" + + " a list of comma separated queue names (regex are\n" + + " accepted) to protect (default is to protect all).\n" + + " -p <PERCENT>, --purge=<PERCENT>\n" + + " The percentage of messages to purge when the queue\n" + + " threshold gets exceeded (default = 20%).\n" + + " N.B. if this gets set too low the fuse may not blow.\n" + + " --sasl-mechanism=<mech>\n" + + " SASL mechanism for authentication (e.g. EXTERNAL,\n" + + " ANONYMOUS, PLAIN, CRAM-MD5, DIGEST-MD5, GSSAPI). SASL\n" + + " automatically picks the most secure available\n" + + " mechanism - use this option to override.\n"; + + private final String _url; + private final List<Pattern> _filter; + private final float _purge; + private Map<String, QmfConsoleData> _queueCache = new HashMap<String, QmfConsoleData>(50); + private Console _console; + + /** + * Basic constructor. Creates JMS Session, Initialises Destinations, Producers & Consumers and starts connection. + * @param url the connection URL. + * @param connectionOptions the options String to pass to ConnectionHelper. + * @param filter a list of regex Patterns used to choose the queues we wish to protect. + * @param purge the ratio of messages that we wish to purge if the threshold gets exceeded. + */ + public QueueFuse(final String url, final String connectionOptions, final List<Pattern> filter, final float purge) + { + System.out.println("QueueFuse Connecting to " + url); + if (filter.size() > 0) + { + System.out.println("Filter = " + filter); + } + _url = url; + _filter = filter; + _purge = purge; + try + { + Connection connection = ConnectionHelper.createConnection(url, connectionOptions); + _console = new Console(this); + _console.addConnection(connection); + updateQueueCache(); + } + catch (QmfException qmfe) + { + System.err.println("QmfException " + qmfe.getMessage() + " caught in QueueFuse constructor"); + } + } + + /** + * Looks up queue objects and stores them in _queueCache keyed by the queue name + */ + private void updateQueueCache() + { + _queueCache.clear(); + List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue"); + for (QmfConsoleData queue : queues) + { + String queueName = queue.getStringValue("name"); + _queueCache.put(queueName, queue); + } + } + + /** + * Look up a queue object with the given name and if it's not a ring queue invoke the queue's purge method. + * @param queueName the name of the queue to purge + * @param msgDepth the number of messages on the queue, used to determine how many messages to purge. + */ + private void purgeQueue(final String queueName, long msgDepth) + { + QmfConsoleData queue = _queueCache.get(queueName); + + if (queue == null) + { + System.out.printf("%s ERROR QueueFuse.disconnectQueue() %s reference couldn't be found\n", + new Date().toString(), queueName); + } + else + { // If we've found a queue called queueName we then find the bindings that reference it. + + Map args = (Map)queue.getValue("arguments"); + String policyType = (String)args.get("qpid.policy_type"); + if (policyType != null && policyType.equals("ring")) + { // If qpid.policy_type=ring we return. + return; + } + + try + { + QmfData arguments = new QmfData(); + arguments.setValue("request", (long)(_purge*msgDepth)); + queue.invokeMethod("purge", arguments); + } + catch (QmfException e) + { + System.out.println(e.getMessage()); + } + } + } + + /** + * Main Event handler. + * @param wi a QMF2 WorkItem object + */ + public void onEvent(final WorkItem wi) + { + if (wi instanceof EventReceivedWorkItem) + { + EventReceivedWorkItem item = (EventReceivedWorkItem)wi; + Agent agent = item.getAgent(); + QmfEvent event = item.getEvent(); + String className = event.getSchemaClassId().getClassName(); + + if (className.equals("queueDeclare")) + { + updateQueueCache(); + } + else if (className.equals("queueThresholdExceeded")) + { + String queueName = event.getStringValue("qName"); + boolean matches = false; + for (Pattern x : _filter) + { // Check the queue name against the regexes in the filter List (if any) + Matcher m = x.matcher(queueName); + if (m.find()) + { + matches = true; + break; + } + } + + if (_filter.isEmpty() || matches) + { // If there's no filter enabled or the filter matches the queue name we call purgeQueue(). + long msgDepth = event.getLongValue("msgDepth"); + purgeQueue(queueName, msgDepth); + } + } + } + } + + /** + * Runs QueueFuse. + * @param args the command line arguments. + */ + public static void main(final String[] args) + { + String logLevel = System.getProperty("amqj.logging.level"); + logLevel = (logLevel == null) ? "FATAL" : logLevel; // Set default log level to FATAL rather than DEBUG. + System.setProperty("amqj.logging.level", logLevel); + + String[] longOpts = {"help", "filter=", "purge=", "sasl-mechanism="}; + try + { + boolean includeRingQueues = false; + String connectionOptions = "{reconnect: true}"; + List<Pattern> filter = new ArrayList<Pattern>(); + float purge = 0.2f; + GetOpt getopt = new GetOpt(args, "hf:p:", longOpts); + List<String[]> optList = getopt.getOptList(); + String[] cargs = {}; + cargs = getopt.getEncArgs().toArray(cargs); + for (String[] opt : optList) + { + if (opt[0].equals("-h") || opt[0].equals("--help")) + { + System.out.println(_usage); + System.out.println(_description); + System.out.println(_options); + System.exit(1); + } + else if (opt[0].equals("-f") || opt[0].equals("--filter")) + { + String[] split = opt[1].split(","); + for (String s : split) + { + Pattern p = Pattern.compile(s); + filter.add(p); + } + } + else if (opt[0].equals("-p") || opt[0].equals("--purge")) + { + int percent = Integer.parseInt(opt[1]); + if (percent < 0 || percent > 100) + { + System.out.println(_usage); + System.exit(1); + } + purge = percent/100.0f; + } + else if (opt[0].equals("--sasl-mechanism")) + { + connectionOptions = "{reconnect: true, sasl_mechs: " + opt[1] + "}"; + } + } + + int nargs = cargs.length; + if (nargs == 0) + { + cargs = new String[] {"localhost"}; + } + + for (String url : cargs) + { + QueueFuse queueFuse = new QueueFuse(url, connectionOptions, filter, purge); + } + } + catch (IllegalArgumentException e) + { + System.out.println(_usage); + System.out.println(e.getMessage()); + System.exit(1); + } + + try + { // Block here + Thread.currentThread().join(); + } + catch (InterruptedException ie) + { + } + } +} |