Index: /trunk/autoquest-htmlmonitor/pom.xml
===================================================================
--- /trunk/autoquest-htmlmonitor/pom.xml	(revision 878)
+++ /trunk/autoquest-htmlmonitor/pom.xml	(revision 879)
@@ -53,4 +53,9 @@
     </dependencies>
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/js</directory>
+            </resource>
+        </resources>
         <extensions>
             <extension>
Index: /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServer.java
===================================================================
--- /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServer.java	(revision 878)
+++ /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServer.java	(revision 879)
@@ -9,8 +9,9 @@
 /**
  * <p>
- * this is the web server, that receives the client messages. It is initialized with a port on
- * which it shall listen, as well as a message listener to forward the received messages to.
- * Internally it starts a jetty web server with a single {@link HtmlMonitorServlet} to receive
- * the messages.
+ * this is the web server, that receives the client messages. It also provides the java script
+ * that is used by the client via the URL /script/autoquest-htmlmonitor.js. It is initialized
+ * with a port on which it shall listen, as well as a message listener to forward the received
+ * messages to. Internally it starts a jetty web server with a single {@link HtmlMonitorServlet}
+ * to receive the messages as well as a .
  * </p>
  * 
Index: /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java
===================================================================
--- /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java	(revision 878)
+++ /trunk/autoquest-htmlmonitor/src/main/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServlet.java	(revision 879)
@@ -1,6 +1,9 @@
 package de.ugoe.cs.autoquest.htmlmonitor;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.PrintWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -24,8 +27,9 @@
 /**
  * <p>
- * the servlet deployed in the web server that receives all client messages. The messages are
- * parsed, validated, and forwarded to the provided message listener. If a message is not valid,
- * it is discarded. If an event in a message is not valid, it is discarded. Messages are only
- * received via the POST HTTP method.
+ * the servlet deployed in the web server that receives all client messages and returns the client
+ * java script. The messages are parsed, validated, and forwarded to the provided message listener.
+ * If a message is not valid, it is discarded. If an event in a message is not valid, it is
+ * discarded. Messages are only received via the POST HTTP method. The GET HTTP method is only
+ * implemented for returning the client java script.
  * </p>
  * 
@@ -37,4 +41,7 @@
     private static final long serialVersionUID = 1L;
     
+    /**  */
+    private static final boolean DO_TRACE = false;
+    
     /**
      * the message listener to forward received messages to.
@@ -51,4 +58,47 @@
     HtmlMonitorServlet(HtmlMonitorMessageListener messageListener) {
         this.messageListener = messageListener;
+    }
+
+    /* (non-Javadoc)
+     * @see org.mortbay.jetty.servlet.DefaultServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response)
+        throws ServletException, IOException
+    {
+        if ((request.getPathInfo() != null) &&
+            (request.getPathInfo().endsWith("/script/autoquest-htmlmonitor.js")))
+        {
+            InputStream script = null;
+            
+            try {
+                script = this.getClass().getClassLoader().getResourceAsStream
+                     ("autoquest-htmlmonitor.js");
+            
+                if (script == null) {
+                    Console.printerrln("could not read autoquest-htmlmonitor.js from classpath");
+                }
+                else {
+                    BufferedReader reader = new BufferedReader(new InputStreamReader(script));
+                    PrintWriter output = response.getWriter();
+                    String line;
+                    
+                    while ((line = reader.readLine()) != null) {
+                        output.println(line);
+                    }
+                    
+                    output.close();
+                }
+            }
+            catch (Exception e) {
+                Console.printerrln("could not read autoquest-htmlmonitor.js from classpath: " + e);
+                Console.logException(e);
+            }
+            finally {
+                if (script != null) {
+                    script.close();
+                }
+            }
+        }
     }
 
@@ -87,5 +137,7 @@
      */
     private void handleJSONObject(JSONObject object) {
-        dumpJSONObject(object, "");
+        if (DO_TRACE) {
+            dumpJSONObject(object, "");
+        }
         
         JSONObject message = assertValue(object, "message", JSONObject.class);
Index: /trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js
===================================================================
--- /trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js	(revision 878)
+++ /trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js	(revision 879)
@@ -25,10 +25,10 @@
  * the server to send the recorded data to
  */
-var destination = "http://localhost:8090"; // change to the location of your server
+var autoquestDestination;
 
 /**
  * the maximum number of recorded events to be put into one package sent to the server
  */
-var packageSize = 10;
+var autoquestPackageSize = 10;
 
 /**
@@ -36,5 +36,5 @@
  * event handling action to be monitored
  */
-var actionConfig = [
+var autoquestActionConfig = [
     { "tag": "body", "actions": [ "onunload", "onscroll" ] },
     { "tag": "a", "actions": [ "onclick", "ondblclick", "onfocus" ] },
@@ -45,5 +45,5 @@
  * a possibility to trace, what is going on
  */
-var doLog = false;
+var autoquestDoLog = false;
 
 /*var matchedTags = ["A", "ABBR", "ACRONYM", "ADDRESS", "AREA", "B", "BIG", "BLOCKQUOTE", "BODY",
@@ -61,5 +61,5 @@
  * stores events, which were recorded but not sent to the server yet
  */
-var recordedEvents = [];
+var autoquestRecordedEvents = [];
 
 /**
@@ -77,4 +77,5 @@
     if (document.body) {
         log("adding event handling attributes");
+        determineDestination();
         addEventHandlingAttributes(document.documentElement, "");
         
@@ -90,5 +91,25 @@
 
 /**
- * traverses the DOM-structure of the HTML-site, and adds event handling attributes to each
+ * traverses the DOM-structure of the HTML-site and determines the URL of this script. Based on
+ * this URL, it calculates the destination to which the traced interactions must be sent
+ */
+function determineDestination() {
+    var scriptElements = document.getElementsByTagName("script");
+    var i;
+    var index;
+    
+    for (i = 0; i < scriptElements.length; i++) {
+        if ((scriptElements[i].type === "text/javascript") && (scriptElements[i].src)) {
+            index = scriptElements[i].src.lastIndexOf("script/autoquest-htmlmonitor.js");
+            if (index > -1) {
+                autoquestDestination = scriptElements[i].src.substring(0, index - 1);
+                log("using destination " + autoquestDestination);
+            }
+        }
+    }
+}
+
+/**
+ * traverses the DOM-structure of the HTML-site and adds event handling attributes to each
  * relevant node
  * 
@@ -105,17 +126,18 @@
     
     if (node.nodeType === Node.ELEMENT_NODE) {
-        for (i = 0; i < actionConfig.length; i++) {
-            if (node.tagName.toLowerCase() === actionConfig[i].tag.toLowerCase()) {
-                for (k = 0; k < actionConfig[i].actions.length; k++) {
-                    value = "handleEvent('" + actionConfig[i].actions[k] + "', '" + nodePath +
-                        "', event);";
-
-                    if (!node.getAttribute(actionConfig[i].actions[k])) {
-                        node.setAttribute(actionConfig[i].actions[k], value);
+        for (i = 0; i < autoquestActionConfig.length; i++) {
+            if (node.tagName.toLowerCase() === autoquestActionConfig[i].tag.toLowerCase()) {
+                for (k = 0; k < autoquestActionConfig[i].actions.length; k++) {
+                    value = "handleEvent('" + autoquestActionConfig[i].actions[k] + "', '" +
+                        nodePath + "', event);";
+
+                    if (!node.getAttribute(autoquestActionConfig[i].actions[k])) {
+                        node.setAttribute(autoquestActionConfig[i].actions[k], value);
                     }
                     else {
-                        var oldValue = node.getAttribute(actionConfig[i].actions[k]);
+                        var oldValue = node.getAttribute(autoquestActionConfig[i].actions[k]);
                         if (oldValue.indexOf(value) < 0) {
-                            node.setAttribute(actionConfig[i].actions[k], value + ' ' + oldValue);
+                            node.setAttribute(autoquestActionConfig[i].actions[k],
+                                              value + ' ' + oldValue);
                         }
                     }
@@ -189,7 +211,7 @@
  * of the nodes. These attributes are generated by the
  * {@link #addEventHandlingAttributes(node,parentPath)} function. It creates a new Event object and
- * add it to the list of <code>recordedEvents</code>. If this list achieves the maximum
- * <code>packageSize</code> the events in the list are sent to the server asynchronously through
- * calling {@link #sendRequest()}.
+ * add it to the list of <code>autoquestRecordedEvents</code>. If this list achieves the maximum
+ * <code>autoquestPackageSize</code> the events in the list are sent to the server asynchronously
+ * through calling {@link #sendRequest()}.
  * 
  * @param eventName the name of the event, e.g. onscroll
@@ -198,12 +220,19 @@
  */
 function handleEvent(eventName, nodePath, event) {
+    log("handling event " + eventName);
+    
+    if (!autoquestDestination) {
+        // do nothing if we have no destination to send data to
+        return;
+    }
+    
     var eventType = eventName.toLowerCase();
     
-    var eventObj = recordedEvents.pop();
+    var eventObj = autoquestRecordedEvents.pop();
     
     // reuse previous on scroll events to prevent too many events
     if ((eventName !== "onscroll") || (!eventObj) || (eventObj.type !== "onscroll")) {
         if (eventObj) {
-            recordedEvents.push(eventObj);
+            autoquestRecordedEvents.push(eventObj);
         }
         eventObj = new Event(eventType, nodePath);
@@ -224,9 +253,15 @@
     }
 
-    recordedEvents.push(eventObj);
-
-    if ((recordedEvents.length >= packageSize) || (eventType === "onunload")) {
+    log("storing event " + eventName);
+    autoquestRecordedEvents.push(eventObj);
+
+    if (autoquestRecordedEvents.length >= autoquestPackageSize) {
+        log("initiating sending events");
         setTimeout(sendRequest, 100);
     }
+    else if (eventType === "onunload") {
+        log("initiating sending events");
+        sendRequest();
+    }
 
 }
@@ -234,5 +269,6 @@
 /**
  * sends the collected data to the server, named in the destination-variable. For this it generates
- * a JSON formatted message and uses Ajax and the <code>destination</code> to send it to the server
+ * a JSON formatted message and uses Ajax and the <code>autoquestDestination</code> to send it to
+ * the server
  */
 function sendRequest() {
@@ -243,7 +279,8 @@
     var request;
     
-    if (recordedEvents.length > 0) {
-        eventList = recordedEvents;
-        recordedEvents = [];
+    if (autoquestRecordedEvents.length > 0) {
+        log("creating message");
+        eventList = autoquestRecordedEvents;
+        autoquestRecordedEvents = [];
         
         message = "{\"message\":{\"clientInfos\":{";
@@ -283,5 +320,6 @@
         }
         
-        request.open("POST", destination, true);
+        log("sending message");
+        request.open("POST", autoquestDestination, true);
 
         log("sending " + message);
@@ -434,5 +472,5 @@
  */
 function log(text) {
-    if (doLog) {
+    if (autoquestDoLog) {
         var loggingInfo = document.getElementById("loggingInfoParagraph");
         
