Removed dependency on rico and program directly to the prototype.js API.

simplified the amq.js API.



git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@373509 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gregory John Wilkins 2006-01-30 13:18:18 +00:00
parent d193ad048a
commit 92b9d864e5
10 changed files with 1244 additions and 3524 deletions

View File

@ -41,6 +41,7 @@ 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;
@ -61,7 +62,7 @@ public class MessageListenerServlet extends MessageServletSupport {
private long defaultReadTimeout = -1;
private long maximumReadTimeout = 20000;
private long maximumReadTimeout = 10000;
private int maximumMessages = 100;
@ -90,44 +91,85 @@ public class MessageListenerServlet extends MessageServletSupport {
* @throws IOException
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// lets turn the HTTP post into a JMS Message
try {
WebClient client = getWebClient(request);
// System.err.println("POST client="+client+"
// session="+request.getSession().getId()+"
// info="+request.getPathInfo()+" query="+request.getQueryString());
String text = getPostedMessageBody(request);
WebClient client = getWebClient(request);
// lets create the destination from the URI?
Destination destination = getDestination(client, request);
if (destination == null)
throw new NoDestinationSuppliedException();
synchronized (client) {
if (log.isDebugEnabled()) {
log.debug("Sending message to: " + destination + " with text: " + text);
// System.err.println("POST client="+client+" session="+request.getSession().getId()+" info="+request.getPathInfo()+" contentType="+request.getContentType());
String[] destinations = request.getParameterValues("destination");
String[] messages = request.getParameterValues("message");
String[] types = request.getParameterValues("type");
if (destinations.length!=messages.length || messages.length!=types.length)
{
// System.err.println("ERROR destination="+destinations.length+" message="+messages.length+" type="+types.length);
response.sendError(HttpServletResponse.SC_BAD_REQUEST,"missmatched destination, message or type");
return;
}
TextMessage message = client.getSession().createTextMessage(text);
appendParametersToMessage(request, message);
client.send(destination, message);
for (int i=0;i<types.length;i++)
{
try {
// System.err.println(i+" destination="+destinations[i]+" message="+messages[i]+" type="+types[i]);
// lets return a unique URI for reliable messaging
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
// System.err.println("Sent "+message+" to "+destination);
/*
* StringWriter swriter = new StringWriter(); PrintWriter writer =
* new PrintWriter(swriter);
*
* writer.println("<ajax-response><response type='object'
* id='amqSend'><amq jmsid='"+message.getJMSMessageID()+"'/></response></ajax-response>");
* writer.flush(); String m=swriter.toString();
* System.err.println(m); response.getWriter().write(m);
* response.getWriter().flush();
*/
} catch (JMSException e) {
throw new ServletException("Could not post JMS message: " + e, e);
String type=types[i];
Destination destination=getDestination(client,request,destinations[i]);
if ("listen".equals(type))
{
Listener listener = getListener(request);
Map consumerIdMap = getConsumerIdMap(request);
MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
consumer.setAvailableListener(listener);
consumerIdMap.put(consumer, messages[i]);
// System.err.println("Subscribed: "+consumer+" to "+destination+" id="+messages[i]);
}
else if ("unlisten".equals(type))
{
Map consumerIdMap = getConsumerIdMap(request);
MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
// TODO should we destroy consumer on unsubscribe?
consumer.setAvailableListener(null);
consumerIdMap.remove(consumer);
// System.err.println("Unsubscribed: "+consumer);
}
else if ("send".equals(type))
{
TextMessage message = client.getSession().createTextMessage(messages[i]);
// TODO sent message parameters
client.send(destination, message);
// System.err.println("Sent "+messages[i]+" to "+destination);
// TODO return message ID.
}
else
log.warn("unknown type "+type);
}
catch (JMSException e) {
log.warn("jms", e);
}
}
}
if ("true".equals(request.getParameter("poll")))
{
try
{
doMessages(client,request,response);
}
catch (JMSException e)
{
throw new ServletException("JMS problem: " + e, e);
}
}
// System.err.println("==");
}
/**
@ -136,22 +178,25 @@ public class MessageListenerServlet extends MessageServletSupport {
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String end="--";
try {
WebClient client = getWebClient(request);
// System.err.println("GET client="+client+"
// session="+request.getSession().getId()+"
// info="+request.getPathInfo()+" query="+request.getQueryString());
// System.err.println("GET client="+client+" session="+request.getSession().getId()+" uri="+request.getRequestURI()+" query="+request.getQueryString());
Destination destination = getDestination(client, request);
if (destination != null)
doSubscription(client, destination, request, response);
else
doMessages(client, request, response);
doMessages(client, request, response);
}
catch(RetryRequest r)
{
end="??";
throw r;
}
catch (JMSException e) {
throw new ServletException("JMS problem: " + e, e);
}
finally
{
// System.err.println(end);
}
}
@ -171,6 +216,7 @@ public class MessageListenerServlet extends MessageServletSupport {
// This is a poll for any messages
long timeout = getReadTimeout(request);
// System.err.println("doMessage timeout="+timeout);
Continuation continuation = null;
Message message = null;
@ -220,9 +266,9 @@ public class MessageListenerServlet extends MessageServletSupport {
// Send any message we already have
if (message != null) {
String id = (String) consumerIdMap.get(consumer);
writer.print("<response type='object' id='");
writer.print("<response id='");
writer.print(id);
writer.print("'>\n");
writer.print("'>");
writeMessageResponse(writer, message);
writer.println("</response>");
messages++;
@ -238,9 +284,8 @@ public class MessageListenerServlet extends MessageServletSupport {
message = consumer.receiveNoWait();
// System.err.println("received "+message+" from "+consumer);
while (message != null && messages < maximumMessages) {
Destination destination = message.getJMSDestination();
String id = (String) consumerIdMap.get(consumer);
writer.print("<response type='object' id='");
writer.print("<response id='");
writer.print(id);
writer.print("'>");
writeMessageResponse(writer, message);
@ -251,13 +296,13 @@ public class MessageListenerServlet extends MessageServletSupport {
}
// Add poll message
writer.println("<response type='object' id='amqPoll'><ok/></response>");
writer.println("</ajax-response>");
// writer.println("<response type='object' id='amqPoll'><ok/></response>");
writer.print("</ajax-response>");
writer.flush();
String m = swriter.toString();
// System.err.println(m);
response.getWriter().write(m);
response.getWriter().println(m);
}
}
@ -273,6 +318,7 @@ public class MessageListenerServlet extends MessageServletSupport {
*/
protected void doSubscription(WebClient client, Destination destination, HttpServletRequest request, HttpServletResponse response) throws JMSException, ServletException, IOException {
// System.err.println("doSubscription destination="+destination);
String s = request.getParameter("listen");
if (s == null || s.length() == 0) {
log.warn("No listen paramenter for subscribe");

View File

@ -156,13 +156,16 @@ public abstract class MessageServletSupport extends HttpServlet {
*/
protected Destination getDestinationFromURI(WebClient client, HttpServletRequest request) throws JMSException {
String uri = request.getPathInfo();
if (uri == null) {
if (uri == null)
return null;
}
// replace URI separator with JMS destination separator
if (uri.startsWith("/")) {
uri = uri.substring(1);
if (uri.length()==0)
return null;
}
uri = uri.replace('/', '.');
System.err.println("destination uri="+uri);
return getDestination(client, request, uri);
@ -172,7 +175,24 @@ public abstract class MessageServletSupport extends HttpServlet {
* @return the Destination object for the given destination name
*/
protected Destination getDestination(WebClient client, HttpServletRequest request, String destinationName) throws JMSException {
if (isTopic(request)) {
// TODO cache destinations ???
boolean is_topic=defaultTopicFlag;
if (destinationName.startsWith("topic://"))
{
is_topic=true;
destinationName=destinationName.substring(8);
}
else if (destinationName.startsWith("channel://"))
{
is_topic=true;
destinationName=destinationName.substring(10);
}
else
is_topic=isTopic(request);
if (is_topic) {
return client.getSession().createTopic(destinationName);
}
else {
@ -202,7 +222,7 @@ public abstract class MessageServletSupport extends HttpServlet {
*/
protected String getPostedMessageBody(HttpServletRequest request) throws IOException {
String answer = request.getParameter(bodyParameter);
if (answer == null) {
if (answer == null && "text/xml".equals(request.getContentType())) {
// lets read the message body instead
BufferedReader reader = request.getReader();
StringBuffer buffer = new StringBuffer();

View File

@ -4,8 +4,8 @@
var connection = null;
var chatTopic = "CHAT.DEMO";
var chatMembership = "CHAT.DEMO";
var chatTopic = "topic://CHAT.DEMO";
var chatMembership = "topic://CHAT.DEMO";
@ -40,10 +40,9 @@ var room =
{
username=name;
amq.addTopicListener('chat',chatTopic,room);
// amq.sendMessage(chatSubscription, "<subscribe>" + username + "</subscribe>");
// switch the input form
$('join').className='hidden';
Behaviour.apply();
amq.addListener('chat',chatTopic,this._chat);
$('join').className='hidden';
$('joined').className='';
$('phrase').focus();
@ -76,7 +75,7 @@ var room =
}
},
amqMessage: function(message)
_chat: function(message)
{
var chat=$('chat');
var type=message.attributes['type'].value;

View File

@ -14,6 +14,8 @@ normal HTTP POST and to receive messages from a destination using a
HTTP GET.
</p>
<p><b><font color="red">Currently only working with firefox!</font></b></p>
<h2>Market data example</h2>
<p>

View File

@ -3,13 +3,87 @@
// AMQ handler
var amq =
{
first: true,
pollEvent: function(first) {},
_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)
{
this._queueMessages=true;
try
{
amq._messageHandler(request);
amq._pollEvent(amq._first);
amq._first=false;
}
catch(e)
{
alert(e);
}
this._queueMessages=false;
if (this._messages==0)
new Ajax.Request('/amq', { method: 'get', onSuccess: amq._pollHandler });
else
{
var body = this._messageQueue+'&poll=true';
this._messageQueue='';
this._messages=0;
new Ajax.Request('/amq', { method: 'post', onSuccess: amq._pollHandler, postBody: body });
}
},
addPollHandler : function(func)
{
var old = this.pollEvent;
this.pollEvent = function(first)
var old = this._pollEvent;
this._pollEvent = function(first)
{
old(first);
func(first);
@ -18,63 +92,37 @@ var amq =
sendMessage : function(destination,message)
{
ajaxEngine.sendRequestWithData('amqSend', message, 'destination='+destination);
this._sendMessage(destination,message,'send');
},
// Listen on a topic. handler must have a amqMessage method taking a message arguement
addTopicListener : function(id,topic,handler)
// Listen on a channel or topic. handler must be a function taking a message arguement
addListener : function(id,destination,handler)
{
var ajax2amq = { ajaxUpdate: function(msg) { handler.amqMessage(amqFirstElement(msg)) } };
ajaxEngine.registerAjaxObject(id, ajax2amq);
ajaxEngine.sendRequest('amqListen', 'destination='+topic+'&topic=true&id='+id+'&listen=true');
amq._handlers[id]=handler;
this._sendMessage(destination,id,'listen');
},
// Listen on a channel. handler must have a amqMessage method taking a message arguement
addChannelListener: function(id,channel,handler)
// remove Listener from channel or topic.
removeListener : function(destination)
{
var ajax2amq = { ajaxUpdate: function(msg) { handler.amqMessage(amqFirstElement(msg)) } };
ajaxEngine.registerAjaxObject(id, ajax2amq);
ajaxEngine.sendRequest('amqListen', 'destination='+channel+'&topic=false&id='+id+'&listen=true');
this._sendMessage(destination,'','unlisten');
},
_sendMessage : function(destination,message,type)
{
if (this._queueMessages)
{
this._messageQueue+=(this._messages==0?'destination=':'&destination=')+destination+'&message='+message+'&type='+type;
this._messages++;
}
else
{
new Ajax.Request('/amq', { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
}
}
};
function initAMQ()
{
// Register URLs. All the same at the moment and params are used to distinguish types
ajaxEngine.registerRequest('amqListen','/amq');
ajaxEngine.registerRequest('amqPoll', '/amq');
ajaxEngine.registerRequest('amqSend', '/amq');
Behaviour.addLoadEvent(function(){new Ajax.Request('/amq', { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler });});
var pollHandler = {
ajaxUpdate: function(ajaxResponse)
{
// Poll again for events
amq.pollEvent(amq.first);
amq.first=false;
ajaxEngine.sendRequest('amqPoll');
}
};
ajaxEngine.registerAjaxObject('amqPoll', pollHandler);
var sendHandler = {
ajaxUpdate: function(ajaxResponse)
{
}
};
ajaxEngine.registerAjaxObject('amqSend', sendHandler);
ajaxEngine.sendRequest('amqPoll',"timeout=0"); // first poll to establish polling session ID
}
Behaviour.addLoadEvent(initAMQ);
function amqFirstElement(t) {
for (i = 0; i < t.childNodes.length; i++) {
var child = t.childNodes[i]
if (child.nodeType == 1) {
return child
}
}
return null
}

View File

@ -12,13 +12,7 @@ var DefaultJS = {
var path = scriptTags[i].src.replace(/default\.js$/,'');
this.script(path + 'prototype.js');
this.script(path + 'behaviour.js');
/* Ignore non-UI parts of Rico
this.script(path + 'rico.js');
*/
this.script(path + 'ricoAjax.js');
this.script(path + 'scriptaculous.js');
// this.script(path + 'scriptaculous.js');
this.script(path + 'amq.js');
break;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,469 +0,0 @@
/**
*
* Copyright 2005 Sabre Airline Solutions
*
* 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.
**/
//-------------------- rico.js
var Rico = {
Version: '1.1-beta2'
}
Rico.ArrayExtensions = new Array();
if (Object.prototype.extend) {
// in prototype.js...
Rico.ArrayExtensions[ Rico.ArrayExtensions.length ] = Object.prototype.extend;
}
if (Array.prototype.push) {
// in prototype.js...
Rico.ArrayExtensions[ Rico.ArrayExtensions.length ] = Array.prototype.push;
}
if (!Array.prototype.remove) {
Array.prototype.remove = function(dx) {
if( isNaN(dx) || dx > this.length )
return false;
for( var i=0,n=0; i<this.length; i++ )
if( i != dx )
this[n++]=this[i];
this.length-=1;
};
Rico.ArrayExtensions[ Rico.ArrayExtensions.length ] = Array.prototype.remove;
}
if (!Array.prototype.removeItem) {
Array.prototype.removeItem = function(item) {
for ( var i = 0 ; i < this.length ; i++ )
if ( this[i] == item ) {
this.remove(i);
break;
}
};
Rico.ArrayExtensions[ Rico.ArrayExtensions.length ] = Array.prototype.removeItem;
}
if (!Array.prototype.indices) {
Array.prototype.indices = function() {
var indexArray = new Array();
for ( index in this ) {
var ignoreThis = false;
for ( var i = 0 ; i < Rico.ArrayExtensions.length ; i++ ) {
if ( this[index] == Rico.ArrayExtensions[i] ) {
ignoreThis = true;
break;
}
}
if ( !ignoreThis )
indexArray[ indexArray.length ] = index;
}
return indexArray;
}
Rico.ArrayExtensions[ Rico.ArrayExtensions.length ] = Array.prototype.indices;
}
// Create the loadXML method and xml getter for Mozilla
if ( window.DOMParser &&
window.XMLSerializer &&
window.Node && Node.prototype && Node.prototype.__defineGetter__ ) {
if (!Document.prototype.loadXML) {
Document.prototype.loadXML = function (s) {
var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
while (this.hasChildNodes())
this.removeChild(this.lastChild);
for (var i = 0; i < doc2.childNodes.length; i++) {
this.appendChild(this.importNode(doc2.childNodes[i], true));
}
};
}
Document.prototype.__defineGetter__( "xml",
function () {
return (new XMLSerializer()).serializeToString(this);
}
);
}
document.getElementsByTagAndClassName = function(tagName, className) {
if ( tagName == null )
tagName = '*';
var children = document.getElementsByTagName(tagName) || document.all;
var elements = new Array();
if ( className == null )
return children;
for (var i = 0; i < children.length; i++) {
var child = children[i];
var classNames = child.className.split(' ');
for (var j = 0; j < classNames.length; j++) {
if (classNames[j] == className) {
elements.push(child);
break;
}
}
}
return elements;
}
//-------------------- ricoAjaxEngine.js
Rico.AjaxEngine = Class.create();
Rico.AjaxEngine.prototype = {
initialize: function() {
this.ajaxElements = new Array();
this.ajaxObjects = new Array();
this.requestURLS = new Array();
},
registerAjaxElement: function( anId, anElement ) {
if ( arguments.length == 1 )
anElement = $(anId);
this.ajaxElements[anId] = anElement;
},
registerAjaxObject: function( anId, anObject ) {
this.ajaxObjects[anId] = anObject;
},
registerRequest: function (requestLogicalName, requestURL) {
this.requestURLS[requestLogicalName] = requestURL;
},
sendRequest: function(requestName) {
var requestURL = this.requestURLS[requestName];
if ( requestURL == null )
return;
var queryString = "";
if ( arguments.length > 1 )
queryString = this._createQueryString(arguments, 1);
new Ajax.Request(requestURL, this._requestOptions(queryString));
},
sendRequestWithData: function(requestName, xmlDocument) {
var requestURL = this.requestURLS[requestName];
if ( requestURL == null )
return;
var queryString = "";
if ( arguments.length > 2 )
queryString = this._createQueryString(arguments, 2);
new Ajax.Request(requestURL + (requestURL.indexOf("?")<0?"?":"&") + queryString, this._requestOptions(null,xmlDocument));
},
sendRequestAndUpdate: function(requestName,container,options) {
var requestURL = this.requestURLS[requestName];
if ( requestURL == null )
return;
var queryString = "";
if ( arguments.length > 3 )
queryString = this._createQueryString(arguments, 3);
var updaterOptions = this._requestOptions(queryString);
updaterOptions.onComplete = null;
updaterOptions.extend(options);
new Ajax.Updater(container, requestURL, updaterOptions);
},
sendRequestWithDataAndUpdate: function(requestName,xmlDocument,container,options) {
var requestURL = this.requestURLS[requestName];
if ( requestURL == null )
return;
var queryString = "";
if ( arguments.length > 4 )
queryString = this._createQueryString(arguments, 4);
var updaterOptions = this._requestOptions(queryString,xmlDocument);
updaterOptions.onComplete = null;
updaterOptions.extend(options);
new Ajax.Updater(container, requestURL + (requestURL.indexOf("?")<0?"?":"&") + queryString, updaterOptions);
},
// Private -- not part of intended engine API --------------------------------------------------------------------
_requestOptions: function(queryString,xmlDoc) {
var self = this;
var requestHeaders = ['X-Rico-Version', Rico.Version ];
var sendMethod = "post"
if ( arguments[1] )
requestHeaders.push( 'Content-type', 'text/xml' );
else
sendMethod = "get";
return { requestHeaders: requestHeaders,
parameters: queryString,
postBody: arguments[1] ? xmlDoc : null,
method: sendMethod,
onComplete: self._onRequestComplete.bind(self) };
},
_createQueryString: function( theArgs, offset ) {
var queryString = ""
for ( var i = offset ; i < theArgs.length ; i++ ) {
if ( i != offset )
queryString += "&";
var anArg = theArgs[i];
if ( anArg.name != undefined && anArg.value != undefined ) {
queryString += anArg.name + "=" + escape(anArg.value);
}
else {
var ePos = anArg.indexOf('=');
var argName = anArg.substring( 0, ePos );
var argValue = anArg.substring( ePos + 1 );
queryString += argName + "=" + escape(argValue);
}
}
return queryString;
},
_onRequestComplete : function(request) {
//!!TODO: error handling infrastructure??
if (request.status != 200)
return;
var response = request.responseXML.getElementsByTagName("ajax-response");
if (response == null || response.length != 1)
return;
this._processAjaxResponse( response[0].childNodes );
},
_processAjaxResponse: function( xmlResponseElements ) {
for ( var i = 0 ; i < xmlResponseElements.length ; i++ ) {
var responseElement = xmlResponseElements[i];
// only process nodes of type element.....
if ( responseElement.nodeType != 1 )
continue;
var responseType = responseElement.getAttribute("type");
var responseId = responseElement.getAttribute("id");
if ( responseType == "object" )
this._processAjaxObjectUpdate( this.ajaxObjects[ responseId ], responseElement );
else if ( responseType == "element" )
this._processAjaxElementUpdate( this.ajaxElements[ responseId ], responseElement );
else
alert('unrecognized AjaxResponse type : ' + responseType );
}
},
_processAjaxObjectUpdate: function( ajaxObject, responseElement ) {
ajaxObject.ajaxUpdate( responseElement );
},
_processAjaxElementUpdate: function( ajaxElement, responseElement ) {
if (ajaxElement) {
ajaxElement.innerHTML = RicoUtil.getContentAsString(responseElement);
}
}
}
var ajaxEngine = new Rico.AjaxEngine();
//-------------------- ricoUtil.js
var RicoUtil = {
getElementsComputedStyle: function ( htmlElement, cssProperty, mozillaEquivalentCSS) {
if ( arguments.length == 2 )
mozillaEquivalentCSS = cssProperty;
var el = $(htmlElement);
if ( el.currentStyle )
return el.currentStyle[cssProperty];
else
return document.defaultView.getComputedStyle(el, null).getPropertyValue(mozillaEquivalentCSS);
},
createXmlDocument : function() {
if (document.implementation && document.implementation.createDocument) {
var doc = document.implementation.createDocument("", "", null);
if (doc.readyState == null) {
doc.readyState = 1;
doc.addEventListener("load", function () {
doc.readyState = 4;
if (typeof doc.onreadystatechange == "function")
doc.onreadystatechange();
}, false);
}
return doc;
}
if (window.ActiveXObject)
return Try.these(
function() { return new ActiveXObject('MSXML2.DomDocument') },
function() { return new ActiveXObject('Microsoft.DomDocument')},
function() { return new ActiveXObject('MSXML.DomDocument') },
function() { return new ActiveXObject('MSXML3.DomDocument') }
) || false;
return null;
},
getContentAsString: function( parentNode ) {
return parentNode.xml != undefined ?
this._getContentAsStringIE(parentNode) :
this._getContentAsStringMozilla(parentNode);
},
_getContentAsStringIE: function(parentNode) {
var contentStr = "";
for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
contentStr += parentNode.childNodes[i].xml;
return contentStr;
},
_getContentAsStringMozilla: function(parentNode) {
var xmlSerializer = new XMLSerializer();
var contentStr = "";
for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
contentStr += xmlSerializer.serializeToString(parentNode.childNodes[i]);
return contentStr;
},
toViewportPosition: function(element) {
return this._toAbsolute(element,true);
},
toDocumentPosition: function(element) {
return this._toAbsolute(element,false);
},
/**
* Compute the elements position in terms of the window viewport
* so that it can be compared to the position of the mouse (dnd)
* This is additions of all the offsetTop,offsetLeft values up the
* offsetParent hierarchy, ...taking into account any scrollTop,
* scrollLeft values along the way...
*
* IE has a bug reporting a correct offsetLeft of elements within a
* a relatively positioned parent!!!
**/
_toAbsolute: function(element,accountForDocScroll) {
if ( navigator.userAgent.toLowerCase().indexOf("msie") == -1 )
return this._toAbsoluteMozilla(element,accountForDocScroll);
var x = 0;
var y = 0;
var parent = element;
while ( parent ) {
var borderXOffset = 0;
var borderYOffset = 0;
if ( parent != element ) {
var borderXOffset = parseInt(this.getElementsComputedStyle(parent, "borderLeftWidth" ));
var borderYOffset = parseInt(this.getElementsComputedStyle(parent, "borderTopWidth" ));
borderXOffset = isNaN(borderXOffset) ? 0 : borderXOffset;
borderYOffset = isNaN(borderYOffset) ? 0 : borderYOffset;
}
x += parent.offsetLeft - parent.scrollLeft + borderXOffset;
y += parent.offsetTop - parent.scrollTop + borderYOffset;
parent = parent.offsetParent;
}
if ( accountForDocScroll ) {
x -= this.docScrollLeft();
y -= this.docScrollTop();
}
return { x:x, y:y };
},
/**
* Mozilla did not report all of the parents up the hierarchy via the
* offsetParent property that IE did. So for the calculation of the
* offsets we use the offsetParent property, but for the calculation of
* the scrollTop/scrollLeft adjustments we navigate up via the parentNode
* property instead so as to get the scroll offsets...
*
**/
_toAbsoluteMozilla: function(element,accountForDocScroll) {
var x = 0;
var y = 0;
var parent = element;
while ( parent ) {
x += parent.offsetLeft;
y += parent.offsetTop;
parent = parent.offsetParent;
}
parent = element;
while ( parent &&
parent != document.body &&
parent != document.documentElement ) {
if ( parent.scrollLeft )
x -= parent.scrollLeft;
if ( parent.scrollTop )
y -= parent.scrollTop;
parent = parent.parentNode;
}
if ( accountForDocScroll ) {
x -= this.docScrollLeft();
y -= this.docScrollTop();
}
return { x:x, y:y };
},
docScrollLeft: function() {
if ( window.pageXOffset )
return window.pageXOffset;
else if ( document.documentElement && document.documentElement.scrollLeft )
return document.documentElement.scrollLeft;
else if ( document.body )
return document.body.scrollLeft;
else
return 0;
},
docScrollTop: function() {
if ( window.pageYOffset )
return window.pageYOffset;
else if ( document.documentElement && document.documentElement.scrollTop )
return document.documentElement.scrollTop;
else if ( document.body )
return document.body.scrollTop;
else
return 0;
}
};

View File

@ -3,7 +3,7 @@
var priceHandler =
{
amqMessage: function(message)
_price: function(message)
{
if (message != null) {
@ -36,7 +36,7 @@ function portfolioPoll(first)
{
if (first)
{
amq.addTopicListener('stocks','STOCKS.*',priceHandler);
amq.addListener('stocks','topic://STOCKS.*',priceHandler._price);
}
}