Upgrade to jetty 6.0.0beta14

factored out web demo into activemq-web-demo
made activemq-web just produce a jar
added amq.js as a resource to the jar
added AjaxServlet to extend MessageListenerServlet with the ability to serve amq.js
cleaned up m2 build and dependencies
added jetty6:run plugin to run the demo.




git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@392913 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gregory John Wilkins 2006-04-10 10:26:17 +00:00
parent b792f11767
commit 8cb2141080
30 changed files with 305 additions and 2490 deletions

View File

@ -69,11 +69,7 @@
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>jetty</groupId>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
@ -132,4 +128,4 @@
</plugins>
</build>
</project>
</project>

7
activemq-web-demo/README.txt Executable file
View File

@ -0,0 +1,7 @@
This web app demostrates the ability of the activemq-web jar.
To run the webapp, the jetty plugin may be used:
mvn jetty6:run

108
activemq-web-demo/pom.xml Executable file
View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2005-2006 The Apache Software Foundation
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.
-->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>incubator-activemq</groupId>
<artifactId>activemq</artifactId>
<version>4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>activemq-web-demo</artifactId>
<packaging>war</packaging>
<name>ActiveMQ :: Web</name>
<description>Web Demo for REST API and Streamlets support</description>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty6-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- activemq -->
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-web</artifactId>
</dependency>
<!-- TODO this should not be needed, but transitive dependencies are not working -->
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<!-- web container -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<scope>test</scope>
</dependency>
<!-- For Spring servlet -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</dependency>
<!-- for custom XML parsing -->
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
</dependency>
<dependency>
<groupId>xmlpull</groupId>
<artifactId>xmlpull</artifactId>
</dependency>
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<!-- used for testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Derby SQL DB used for testing JDBC message store -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -42,8 +42,8 @@
<!-- the subscription REST servlet -->
<servlet>
<servlet-name>MessageListenerServlet</servlet-name>
<servlet-class>org.apache.activemq.web.MessageListenerServlet</servlet-class>
<servlet-name>AjaxServlet</servlet-name>
<servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
@ -61,7 +61,7 @@
</servlet>
<servlet-mapping>
<servlet-name>MessageListenerServlet</servlet-name>
<servlet-name>AjaxServlet</servlet-name>
<url-pattern>/amq/*</url-pattern>
</servlet-mapping>

View File

@ -1,7 +1,8 @@
<html>
<head>
<title>Chat</title>
<script type="text/javascript" src="../js/default.js"></script>
<script type="text/javascript" src="amq/amq.js"></script>
<script type="text/javascript">amq.uri='amq';</script>
<script type="text/javascript" src="chat.js"></script>
<link rel="stylesheet" href="chat.css" type="text/css">
<link rel="stylesheet" href="style.css" type="text/css">

View File

@ -2,7 +2,8 @@
<head>
<title>My Portfolio</title>
<link rel="stylesheet" type="text/css" href="../style.css"></link>
<script type="text/javascript" src="../js/default.js"></script>
<script type="text/javascript" src="../amq/amq.js"></script>
<script type="text/javascript">amq.uri='../amq';</script>
<script type="text/javascript" src="portfolio.js"></script>
<style>
.stocks { border: 1 solid black; }

View File

@ -1,2 +1,7 @@
Here be the home of the web-module.
The demonstration webapp has been moved to the activemq-web-demo module.
This module now onlu builds the jar for activemq-web.
The javascript modules needed for the AJAX interface are included as
resources and served my the MessageListenerServlet

View File

@ -31,12 +31,11 @@
</parent>
<artifactId>activemq-web</artifactId>
<packaging>war</packaging>
<packaging>jar</packaging>
<name>ActiveMQ :: Web</name>
<description>Web Connector for REST API and Streamlets support</description>
<dependencies>
<!-- activemq -->
<dependency>
<groupId>${pom.groupId}</groupId>
@ -45,48 +44,38 @@
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-core-test</artifactId>
</dependency>
<!-- Optional used fo in-web container testing -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jsp_2.0_spec</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<!-- Rome RSS Reader -->
<dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
<scope>test</scope>
</dependency>
<!-- web container -->
<dependency>
<groupId>jetty</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
</dependency>
<dependency>
<groupId>jetty</groupId>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<scope>test</scope>
</dependency>
<!-- For Spring servlet -->
<!-- Rome RSS Reader -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
</dependency>
<!-- for custom XML parsing -->
<!-- XML -->
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
@ -95,25 +84,20 @@
<dependency>
<groupId>xmlpull</groupId>
<artifactId>xmlpull</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>xstream</groupId>
<artifactId>xstream</artifactId>
</dependency>
<!-- used for testing -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Derby SQL DB used for testing JDBC message store -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,91 @@
//========================================================================
//Copyright 2006 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//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.
//========================================================================
package org.apache.activemq.web;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/* ------------------------------------------------------------ */
/** AjaxServlet.
* The AjaxServlet extends the {@link MessageListenerServlet} with the capability to
* server the <code>amq.js</code> script and associated scripts from resources
* within the activemq-web jar. The amq.js script is the client side companion to
* the MessageListenerServlet and supports sending messages and long polling for
* receiving messages (Also called Comet style Ajax).
*
*/
public class AjaxServlet extends MessageListenerServlet {
private Map jsCache = new HashMap();
private long jsLastModified = 1000*(System.currentTimeMillis()/1000);
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (request.getPathInfo()!=null && request.getPathInfo().endsWith(".js"))
doJavaScript(request,response);
else
super.doGet(request, response);
}
protected void doJavaScript(HttpServletRequest request, HttpServletResponse response)throws IOException {
String resource="org/apache/activemq/web"+request.getPathInfo();
synchronized(jsCache){
byte[] data = (byte[])jsCache.get(resource);
if (data==null) {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
if (in!=null)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf=new byte[4096];
int len=in.read(buf);
while (len>=0) {
out.write(buf, 0, len);
len=in.read(buf);
}
in.close();
out.close();
data=out.toByteArray();
jsCache.put(resource, data);
}
}
if (data!=null){
long if_modified = request.getDateHeader("If-Modified-Since");
if (if_modified == jsLastModified) {
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
}
else {
response.setContentType("application/x-javascript");
response.setContentLength(data.length);
response.setDateHeader("Last-Modified",jsLastModified);
response.getOutputStream().write(data);
}
}
else
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
}

View File

@ -20,10 +20,7 @@ package org.apache.activemq.web;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -43,7 +40,6 @@ import org.apache.activemq.MessageAvailableConsumer;
import org.apache.activemq.MessageAvailableListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.jetty.RetryRequest;
import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;
@ -56,7 +52,8 @@ import org.mortbay.util.ajax.ContinuationSupport;
* block for.
*
* The servlet can be configured with the following init parameters:<dl>
* <dt>defaultReadTimeout</dt><dd>The default time in ms to wait for messages. May be overridden by a request using the 'timeout' parameter</dd>
* <dt>defaultReadTimeout</dt><dd>The default time in ms to wait for messages.
* May be overridden by a request using the 'timeout' parameter</dd>
* <dt>maximumReadTimeout</dt><dd>The maximum value a request may specify for the 'timeout' parameter</dd>
* <dt>maximumMessages</dt><dd>maximum messages to send per response</dd>
* <dt></dt><dd></dd>
@ -75,7 +72,7 @@ public class MessageListenerServlet extends MessageServletSupport {
private long maximumReadTimeout = 25000;
private int maximumMessages = 100;
public void init() throws ServletException {
ServletConfig servletConfig = getServletConfig();
String name = servletConfig.getInitParameter("defaultReadTimeout");
@ -105,6 +102,7 @@ public class MessageListenerServlet extends MessageServletSupport {
// lets turn the HTTP post into a JMS Message
WebClient client = getWebClient(request);
String message_ids="";
synchronized (client) {
@ -166,10 +164,10 @@ public class MessageListenerServlet extends MessageServletSupport {
TextMessage message = client.getSession().createTextMessage(messages[i]);
// TODO sent message parameters
client.send(destination, message);
message_ids+=message.getJMSMessageID()+"\n";
if (log.isDebugEnabled()) {
log.debug("Sent "+messages[i]+" to "+destination);
}
// TODO return message ID.
}
else
log.warn("unknown type "+type);
@ -185,6 +183,7 @@ public class MessageListenerServlet extends MessageServletSupport {
{
try
{
// TODO return message IDs
doMessages(client,request,response);
}
catch (JMSException e)
@ -192,31 +191,30 @@ public class MessageListenerServlet extends MessageServletSupport {
throw new ServletException("JMS problem: " + e, e);
}
}
else
else
{
// lets assume a simple POST of a message
/*
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().print("<ajax-response></ajax-response>");
*/
try {
Destination destination=getDestination(client, request);
String body = getPostedMessageBody(request);
TextMessage message = client.getSession().createTextMessage(body );
client.send(destination, message);
if (log.isDebugEnabled()) {
log.debug("Sent to destination: " + destination + " body: " + body);
// handle simple POST of a message
if (request.getContentLength()!=0 &&
(request.getContentType()==null || !request.getContentType().toLowerCase().startsWith("application/x-www-form-urlencoded")))
{
try {
Destination destination=getDestination(client, request);
String body = getPostedMessageBody(request);
TextMessage message = client.getSession().createTextMessage(body );
client.send(destination, message);
if (log.isDebugEnabled()) {
log.debug("Sent to destination: " + destination + " body: " + body);
}
message_ids+=message.getJMSMessageID()+"\n";
}
catch (JMSException e) {
throw new ServletException(e);
}
response.setContentType("text");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().print(message.getJMSMessageID());
}
catch (JMSException e) {
throw new ServletException(e);
}
response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().print(message_ids);
}
}
@ -225,13 +223,12 @@ public class MessageListenerServlet extends MessageServletSupport {
* from a queue
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
WebClient client = getWebClient(request);
if (log.isDebugEnabled()) {
log.debug("GET client="+client+" session="+request.getSession().getId()+" uri="+request.getRequestURI()+" query="+request.getQueryString());
}
doMessages(client, request, response);
}
catch (JMSException e) {
@ -239,6 +236,7 @@ public class MessageListenerServlet extends MessageServletSupport {
}
}
/**
* Reads a message from a destination up to some specific timeout period
*

View File

@ -2,15 +2,15 @@
// Technique borrowed from scriptaculous to do includes.
var DefaultJS = {
Version: 'AMQ default JS',
Version: 'AMQ JS',
script: function(libraryName) {
document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
},
load: function() {
var scriptTags = document.getElementsByTagName("script");
for(var i=0;i<scriptTags.length;i++) {
if(scriptTags[i].src && scriptTags[i].src.match(/default\.js$/)) {
var path = scriptTags[i].src.replace(/default\.js$/,'');
if(scriptTags[i].src && scriptTags[i].src.match(/amq\.js$/)) {
var path = scriptTags[i].src.replace(/amq\.js$/,'');
this.script(path + 'prototype.js');
this.script(path + 'behaviour.js');
this.script(path + '_amq.js');
@ -24,161 +24,3 @@ var DefaultJS = {
DefaultJS.load();
// AMQ Ajax handler
// This class provides the main API for using the Ajax features of AMQ. It
// allows JMS messages to be sent and received from javascript when used
// with the org.apache.activemq.web.MessageListenerServlet
//
var amq =
{
// The URI of the MessageListenerServlet
uri: '/amq',
// Polling. Set to true (default) if waiting poll for messages is needed
poll: true,
_first: true,
_pollEvent: function(first) {},
_handlers: new Array(),
_messages:0,
_messageQueue: '',
_queueMessages: false,
_messageHandler: function(request)
{
try
{
if (request.status == 200)
{
var response = request.responseXML.getElementsByTagName("ajax-response");
if (response != null && response.length == 1)
{
for ( var i = 0 ; i < response[0].childNodes.length ; i++ )
{
var responseElement = response[0].childNodes[i];
// only process nodes of type element.....
if ( responseElement.nodeType != 1 )
continue;
var id = responseElement.getAttribute('id');
var handler = amq._handlers[id];
if (handler!=null)
{
for (var j = 0; j < responseElement.childNodes.length; j++)
{
var child = responseElement.childNodes[j]
if (child.nodeType == 1)
{
handler(child);
}
}
}
}
}
}
}
catch(e)
{
alert(e);
}
},
_pollHandler: function(request)
{
amq._queueMessages=true;
try
{
amq._messageHandler(request);
amq._pollEvent(amq._first);
amq._first=false;
}
catch(e)
{
alert(e);
}
amq._queueMessages=false;
if (amq._messages==0)
{
if (amq.poll)
new Ajax.Request(amq.uri, { method: 'get', onSuccess: amq._pollHandler });
}
else
{
var body = amq._messageQueue+'&poll='+amq.poll;
amq._messageQueue='';
amq._messages=0;
new Ajax.Request(amq.uri, { method: 'post', onSuccess: amq._pollHandler, postBody: body });
}
},
// Add a function that gets called on every poll response, after all received
// messages have been handled. The poll handler is past a boolean that indicates
// if this is the first poll for the page.
addPollHandler : function(func)
{
var old = amq._pollEvent;
amq._pollEvent = function(first)
{
old(first);
func(first);
}
},
// Send a JMS message to a destination (eg topic://MY.TOPIC). Message should be xml or encoded
// xml content.
sendMessage : function(destination,message)
{
amq._sendMessage(destination,message,'send');
},
// Listen on a channel or topic. handler must be a function taking a message arguement
addListener : function(id,destination,handler)
{
amq._handlers[id]=handler;
amq._sendMessage(destination,id,'listen');
},
// remove Listener from channel or topic.
removeListener : function(id,destination)
{
amq._handlers[id]=null;
amq._sendMessage(destination,id,'unlisten');
},
_sendMessage : function(destination,message,type)
{
if (amq._queueMessages)
{
amq._messageQueue+=(amq._messages==0?'destination=':'&destination=')+destination+'&message='+message+'&type='+type;
amq._messages++;
}
else
{
new Ajax.Request(amq.uri, { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
}
},
_startPolling : function()
{
if (amq.poll)
new Ajax.Request(amq.uri, { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler });
}
};
Behaviour.addLoadEvent(amq._startPolling);
function getKeyCode(ev)
{
var keyc;
if (window.event)
keyc=window.event.keyCode;
else
keyc=ev.keyCode;
return keyc;
}

View File

@ -1,160 +0,0 @@
// AMQ Ajax handler
// This class provides the main API for using the Ajax features of AMQ. It
// allows JMS messages to be sent and received from javascript when used
// with the org.apache.activemq.web.MessageListenerServlet
//
var amq =
{
// The URI of the MessageListenerServlet
uri: '/amq',
// Polling. Set to true (default) if waiting poll for messages is needed
poll: true,
_first: true,
_pollEvent: function(first) {},
_handlers: new Array(),
_messages:0,
_messageQueue: '',
_queueMessages: false,
_messageHandler: function(request)
{
try
{
if (request.status == 200)
{
var response = request.responseXML.getElementsByTagName("ajax-response");
if (response != null && response.length == 1)
{
for ( var i = 0 ; i < response[0].childNodes.length ; i++ )
{
var responseElement = response[0].childNodes[i];
// only process nodes of type element.....
if ( responseElement.nodeType != 1 )
continue;
var id = responseElement.getAttribute('id');
var handler = amq._handlers[id];
if (handler!=null)
{
for (var j = 0; j < responseElement.childNodes.length; j++)
{
var child = responseElement.childNodes[j]
if (child.nodeType == 1)
{
handler(child);
}
}
}
}
}
}
}
catch(e)
{
alert(e);
}
},
_pollHandler: function(request)
{
amq._queueMessages=true;
try
{
amq._messageHandler(request);
amq._pollEvent(amq._first);
amq._first=false;
}
catch(e)
{
alert(e);
}
amq._queueMessages=false;
if (amq._messages==0)
{
if (amq.poll)
new Ajax.Request(amq.uri, { method: 'get', onSuccess: amq._pollHandler });
}
else
{
var body = amq._messageQueue+'&poll='+amq.poll;
amq._messageQueue='';
amq._messages=0;
new Ajax.Request(amq.uri, { method: 'post', onSuccess: amq._pollHandler, postBody: body });
}
},
// Add a function that gets called on every poll response, after all received
// messages have been handled. The poll handler is past a boolean that indicates
// if this is the first poll for the page.
addPollHandler : function(func)
{
var old = amq._pollEvent;
amq._pollEvent = function(first)
{
old(first);
func(first);
}
},
// Send a JMS message to a destination (eg topic://MY.TOPIC). Message should be xml or encoded
// xml content.
sendMessage : function(destination,message)
{
amq._sendMessage(destination,message,'send');
},
// Listen on a channel or topic. handler must be a function taking a message arguement
addListener : function(id,destination,handler)
{
amq._handlers[id]=handler;
amq._sendMessage(destination,id,'listen');
},
// remove Listener from channel or topic.
removeListener : function(id,destination)
{
amq._handlers[id]=null;
amq._sendMessage(destination,id,'unlisten');
},
_sendMessage : function(destination,message,type)
{
if (amq._queueMessages)
{
amq._messageQueue+=(amq._messages==0?'destination=':'&destination=')+destination+'&message='+message+'&type='+type;
amq._messages++;
}
else
{
new Ajax.Request(amq.uri, { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
}
},
_startPolling : function()
{
if (amq.poll)
new Ajax.Request(amq.uri, { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler });
}
};
Behaviour.addLoadEvent(amq._startPolling);
function getKeyCode(ev)
{
var keyc;
if (window.event)
keyc=window.event.keyCode;
else
keyc=ev.keyCode;
return keyc;
}

View File

@ -1,254 +0,0 @@
/*
Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
of Simon Willison (see comments by Simon below).
Description:
Uses css selectors to apply javascript behaviours to enable
unobtrusive javascript in html documents.
Usage:
var myrules = {
'b.someclass' : function(element){
element.onclick = function(){
alert(this.innerHTML);
}
},
'#someid u' : function(element){
element.onmouseover = function(){
this.innerHTML = "BLAH!";
}
}
};
Behaviour.register(myrules);
// Call Behaviour.apply() to re-apply the rules (if you
// update the dom, etc).
License:
This file is entirely BSD licensed.
More information:
http://ripcord.co.nz/behaviour/
*/
var Behaviour = {
list : new Array,
register : function(sheet){
Behaviour.list.push(sheet);
},
start : function(){
Behaviour.addLoadEvent(function(){
Behaviour.apply();
});
},
apply : function(){
for (h=0;sheet=Behaviour.list[h];h++){
for (selector in sheet){
list = document.getElementsBySelector(selector);
if (!list){
continue;
}
for (i=0;element=list[i];i++){
sheet[selector](element);
}
}
}
},
addLoadEvent : function(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
}
Behaviour.start();
/*
The following code is Copyright (C) Simon Willison 2004.
document.getElementsBySelector(selector)
- returns an array of element objects from the current document
matching the CSS selector. Selectors can contain element names,
class names and ids and can be nested. For example:
elements = document.getElementsBySelect('div#main p a.external')
Will return an array of all 'a' elements with 'external' in their
class attribute that are contained inside 'p' elements that are
contained inside the 'div' element which has id="main"
New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
See http://www.w3.org/TR/css3-selectors/#attribute-selectors
Version 0.4 - Simon Willison, March 25th 2003
-- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
-- Opera 7 fails
*/
function getAllChildren(e) {
// Returns all children of element. Workaround required for IE5/Windows. Ugh.
return e.all ? e.all : e.getElementsByTagName('*');
}
document.getElementsBySelector = function(selector) {
// Attempt to fail gracefully in lesser browsers
if (!document.getElementsByTagName) {
return new Array();
}
// Split selector in to tokens
var tokens = selector.split(' ');
var currentContext = new Array(document);
for (var i = 0; i < tokens.length; i++) {
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
if (token.indexOf('#') > -1) {
// Token is an ID selector
var bits = token.split('#');
var tagName = bits[0];
var id = bits[1];
var element = document.getElementById(id);
if (tagName && element.nodeName.toLowerCase() != tagName) {
// tag with that ID not found, return false
return new Array();
}
// Set currentContext to contain just this element
currentContext = new Array(element);
continue; // Skip to next token
}
if (token.indexOf('.') > -1) {
// Token contains a class selector
var bits = token.split('.');
var tagName = bits[0];
var className = bits[1];
if (!tagName) {
tagName = '*';
}
// Get elements matching tag, filter them for class selector
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
currentContext[currentContextIndex++] = found[k];
}
}
continue; // Skip to next token
}
// Code to deal with attribute selectors
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
var tagName = RegExp.$1;
var attrName = RegExp.$2;
var attrOperator = RegExp.$3;
var attrValue = RegExp.$4;
if (!tagName) {
tagName = '*';
}
// Grab all of the tagName elements within current context
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
var checkFunction; // This function will be used to filter the elements
switch (attrOperator) {
case '=': // Equality
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
break;
case '~': // Match one of space seperated words
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
break;
case '|': // Match start with value followed by optional hyphen
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
break;
case '^': // Match starts with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
break;
case '$': // Match ends with value - fails with "Warning" in Opera 7
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
break;
case '*': // Match ends with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
break;
default :
// Just test for existence of attribute
checkFunction = function(e) { return e.getAttribute(attrName); };
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (checkFunction(found[k])) {
currentContext[currentContextIndex++] = found[k];
}
}
// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
continue; // Skip to next token
}
if (!currentContext[0]){
return;
}
// If we get here, token is JUST an element (not a class or ID selector)
tagName = token;
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements = currentContext[h].getElementsByTagName(tagName);
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = found;
}
return currentContext;
}
/* That revolting regular expression explained
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
\---/ \---/\-------------/ \-------/
| | | |
| | | The value
| | ~,|,^,$,* or =
| Attribute
Tag
*/

View File

@ -1,24 +0,0 @@
// Technique borrowed from scriptaculous to do includes.
var DefaultJS = {
Version: 'AMQ default JS',
script: function(libraryName) {
document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
},
load: function() {
var scriptTags = document.getElementsByTagName("script");
for(var i=0;i<scriptTags.length;i++) {
if(scriptTags[i].src && scriptTags[i].src.match(/default\.js$/)) {
var path = scriptTags[i].src.replace(/default\.js$/,'');
this.script(path + 'prototype.js');
this.script(path + 'behaviour.js');
// this.script(path + 'scriptaculous.js');
this.script(path + 'amq.js');
break;
}
}
}
}
DefaultJS.load();

File diff suppressed because it is too large Load Diff

View File

@ -162,13 +162,8 @@
<artifactId>spring</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>jetty</groupId>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
</dependency>
<dependency>
@ -267,4 +262,4 @@
</plugins>
</build>
</project>
</project>

View File

@ -146,7 +146,7 @@ geronimo_core_version=1.0-SNAPSHOT
commons_httpclient_version=2.0.1
#servlet_api_version=2.5-6.0-SNAPSHOT
servlet_api_version=2.5-6.0.0beta6
jetty_version=6.0.0beta12
jetty_version=6.0.0beta14
tomcat_version=5.0.28
xercesImpl_version=2.6.2

36
pom.xml
View File

@ -126,6 +126,7 @@
<module>activemq-console</module>
<module>activemq-ra</module>
<module>activemq-web</module>
<module>activemq-web-demo</module>
<module>activemq-optional</module>
<module>activemq-gbean</module>
<module>activemq-gbean-management</module>
@ -178,6 +179,16 @@
<artifactId>activemq-jaas</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-web</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-web-demo</artifactId>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-gbean-management</artifactId>
@ -492,15 +503,21 @@
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5-6.0.0beta6</version>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
<version>6.0.0beta14</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>6.0.0beta14</version>
</dependency>
<dependency>
<groupId>jetty</groupId>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.0.0beta6</version>
<version>6.0.0beta14</version>
</dependency>
<dependency>
@ -701,13 +718,6 @@
<target>1.4</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>bin</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -727,4 +737,4 @@
</plugins>
</reporting>
</project>
</project>