From reebalazs at codespeak.net Tue Apr 11 15:58:15 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Tue, 11 Apr 2006 13:58:15 -0000 Subject: [Kukit-checkins] r25700 - kukit/branch/plugin/kukit Message-ID: <20060411135815.58F6E1018F@code0.codespeak.net> Author: reebalazs Date: Tue Apr 11 15:58:13 2006 New Revision: 25700 Modified: kukit/branch/plugin/kukit/kukit.js Log: Refactored request queue manager Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Tue Apr 11 15:58:13 2006 @@ -12,8 +12,8 @@ kukit.RequestManager.prototype.info = function() { return ' (RQ: ' + this.sentNr + ' OUT, ' + this.waitingQueue.size() + ' WAI)'; } -kukit.RequestManager.prototype.pushWaitingRequest = function(elem) { - this.waitingQueue.push(elem); +kukit.RequestManager.prototype.pushWaitingRequest = function(func, url) { + this.waitingQueue.push([func, url]); } kukit.RequestManager.prototype.popWaitingRequest = function() { return this.waitingQueue.pop(); @@ -21,17 +21,51 @@ kukit.RequestManager.prototype.isWaitingRequestQueueEmpty = function() { return this.waitingQueue.empty(); } -kukit.RequestManager.prototype.pushSentRequest = function(elem) { +kukit.RequestManager.prototype.pushSentRequest = function(func, url) { // we do not store the elems, since they are not needed now this.sentNr = this.sentNr + 1; } -kukit.RequestManager.prototype.popSentRequest = function(elem) { +kukit.RequestManager.prototype.popSentRequest = function() { this.sentNr = this.sentNr - 1; } -kukit.RequestManager.prototype.isSentRequestQueueFull = function(elem) { +kukit.RequestManager.prototype.isSentRequestQueueFull = function() { return (this.sentNr >= this.maxNr) } +/* request manager notification API */ + +kukit.RequestManager.prototype.notifyServer = function(func, url) { + // func must be a partial + // here url is only for the logging + if (! kukit.requestManager.isSentRequestQueueFull()) { + // can be sent if we are not over the limit. + this.pushSentRequest(func, url); + kukit.logDebug("Notify server at " + url + this.info()); + func(); + } else { + this.pushWaitingRequest(func, url); + kukit.logDebug("Queue server notification at " + url + this.info()); + } +} + +kukit.RequestManager.prototype.receivedResult = function() { + // must be called when one result arrived + // Mark that we have one less request out. + kukit.requestManager.popSentRequest(); + if (! kukit.requestManager.isWaitingRequestQueueEmpty()) { + // see if we can send another request in place of the received one + // request is waiting, send it. + var waiting = kukit.requestManager.popWaitingRequest(); + var func = waiting[0]; + var url = waiting[1]; + kukit.requestManager.pushSentRequest(func, url); + kukit.logDebug("Send queued notification to server at " + url + kukit.requestManager.info()); + func(); + } else { + kukit.logDebug("Request queue empty." + kukit.requestManager.info()); + } +} + /* simple FIFO queue */ kukit.FifoQueue = function () { @@ -446,17 +480,8 @@ return poster.join("&"); } - kukit.notifyServer = function(url, target) { - if (! kukit.requestManager.isSentRequestQueueFull()) { - // can be sent if we are not over the limit. - kukit.requestManager.pushSentRequest([url, target]); - kukit.logDebug("Notify server at " + url + kukit.requestManager.info()); - kukit.reallyNotifyServer(url, target); - } else { - kukit.requestManager.pushWaitingRequest([url, target]); - kukit.logDebug("Queue server notification at " + url + kukit.requestManager.info()); - } + kukit.requestManager.notifyServer(partial(kukit.reallyNotifyServer, url, target), url); } kukit.reallyNotifyServer = function(url, target) @@ -475,7 +500,11 @@ domDoc.send(form_data); } -kukit.notifyServerWithParams = function(url, params) +kukit.notifyServerWithParams = function(url, params) { + kukit.requestManager.notifyServer(partial(kukit.reallyNotifyServerWithParams, url, params), url); +} + +kukit.reallyNotifyServerWithParams = function(url, params) { // make a deferred callback var domDoc = new XMLHttpRequest(); @@ -500,26 +529,9 @@ } } -kukit.processResult = function(domDoc) { - // Mark that we have one less request out. - kukit.requestManager.popSentRequest(); - if (! kukit.requestManager.isWaitingRequestQueueEmpty()) { - // see if we can send another request in place of the received one - // request is waiting, send it. - var waiting = kukit.requestManager.popWaitingRequest(); - kukit.requestManager.pushSentRequest(waiting); - var url = waiting[0]; - var target = waiting[1]; - kukit.logDebug("Send queued notification to server at " + url + kukit.requestManager.info()); - kukit.reallyNotifyServer(url, target); - } else { - kukit.logDebug("Request queue empty." + kukit.requestManager.info()); - } - kukit.reallyProcessResult(domDoc); -} - -kukit.reallyProcessResult = function(domDoc) +kukit.processResult = function(domDoc) { + kukit.requestManager.receivedResult(); if (!domDoc) { kukit.logError('Error : no kukit response'); From reebalazs at codespeak.net Sat Apr 15 20:16:17 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sat, 15 Apr 2006 18:16:17 -0000 Subject: [Kukit-checkins] r25865 - kukit/branch/plugin/kukit Message-ID: <20060415181617.7A61C100B9@code0.codespeak.net> Author: reebalazs Date: Sat Apr 15 20:16:16 2006 New Revision: 25865 Modified: kukit/branch/plugin/kukit/kukit.js Log: Absolutely necessary fix, appendChildren should be done like in Sarissa, to work in IE + Moz transparently. Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sat Apr 15 20:16:16 2006 @@ -712,12 +712,19 @@ kukit.dom.appendChildren = function(nodes, parent) { var ownerDoc = parent.nodeType == Node.DOCUMENT_NODE ? parent : parent.ownerDocument; var result = new Array(); - for(var i=0;i < nodes.length;i++) { - result[i] = parent.appendChild(ownerDoc.importNode(nodes[i], true)); + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { + for(var i=0;i < nodes.length;i++) { + result[i] = parent.appendChild(ownerDoc.importNode(nodes[i], true)); + }; + }else{ + for(var i=0;i < nodes.length;i++) { + result[i] = parent.appendChild(nodes[i].cloneNode(true)); + }; }; return result; } + /* Command registry */ kukit.CommandRegistry = function () { From reebalazs at codespeak.net Sat Apr 15 23:26:28 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sat, 15 Apr 2006 21:26:28 -0000 Subject: [Kukit-checkins] r25866 - kukit/branch/plugin/kukit Message-ID: <20060415212628.704FD100CF@code0.codespeak.net> Author: reebalazs Date: Sat Apr 15 23:26:27 2006 New Revision: 25866 Modified: kukit/branch/plugin/kukit/kukit.js Log: Absolutely necessary fix, also needed to compliment r25865. fix setHtmlAsChild. Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sat Apr 15 23:26:27 2006 @@ -724,7 +724,6 @@ return result; } - /* Command registry */ kukit.CommandRegistry = function () { @@ -757,9 +756,9 @@ kukit.commandRegistry.register('setHtmlAsChild', function(node, command_data) { + var content = document.importNode(command_data['html'], true); Sarissa.clearChildNodes(node); - var childNodes = command_data['html'].childNodes; - kukit.dom.appendChildren(childNodes, node); + kukit.dom.appendChildren(content.childNodes, node); kukit.setupEvents(node); }) From reebalazs at codespeak.net Sun Apr 16 11:47:59 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sun, 16 Apr 2006 09:47:59 -0000 Subject: [Kukit-checkins] r25868 - kukit/branch/plugin/kukit Message-ID: <20060416094759.C90531009F@code0.codespeak.net> Author: reebalazs Date: Sun Apr 16 11:47:58 2006 New Revision: 25868 Modified: kukit/branch/plugin/kukit/kukit.js Log: refactoring extractFormData, make a query builder class Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sun Apr 16 11:47:58 2006 @@ -415,7 +415,46 @@ return false; }; -kukit.extractFormData = function(target) { +/* form query assembler */ + +kukit.FormQueryElem = function(name, value) { + this.name = name; + this.value = value; +} + +kukit.FormQueryElem.prototype.encode = function() { + return this.name+ "=" + encodeURIComponent(this.value); +} + +kukit.FormQuery = function() { + this.l = []; +} + +kukit.FormQuery.prototype.appendElem = function(name, value) { + var elem = new kukit.FormQueryElem(name, value); + this.l[this.l.length] = elem; +} + +kukit.FormQuery.prototype.encode = function() { + var poster = []; + for (var i=0;i < this.l.length;i++) { + poster[poster.length] = this.l[i].encode(); + } + return poster.join("&"); +} + +kukit.FormQuery.prototype.toDict = function() { + var d = {}; + for (var i=0;i < this.l.length;i++) { + var elem = this.l[i]; + d[elem.name] = elem.value; + } + return d; +} + +/* Form data extraction */ + +kukit.extractFormQuery = function(target) { if (!target) { kukit.logWarning("No target given"); return ""; @@ -435,9 +474,10 @@ return ""; } - var poster = new Array(); + var query = new kukit.FormQuery(); + // We now put isKukitRequest=1; XXX we might deprecate this! + query.appendElem("isKukitRequest", "1"); - poster[poster.length] = "isKukitRequest=1"; var elements = form.elements; for (var y=0;y < elements.length;y++) { @@ -471,15 +511,20 @@ continue; } if (element.name != "") { - var result = (element.name+ "=" + encodeURIComponent(value)); - kukit.logDebug("Form element ("+element.tagName+"): "+result); - poster[poster.length] = result; + kukit.logDebug("Form element ("+element.tagName+"): name="+element.name+", value="+value); + query.appendElem(element.name, value); } } - return poster.join("&"); + return query; } +kukit.extractFormData = function(target) { + return kukit.extractFormQuery(target).encode(); +} + +/* Server notification */ + kukit.notifyServer = function(url, target) { kukit.requestManager.notifyServer(partial(kukit.reallyNotifyServer, url, target), url); } From reebalazs at codespeak.net Mon Apr 17 13:59:35 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 17 Apr 2006 11:59:35 -0000 Subject: [Kukit-checkins] r25882 - kukit/branch/plugin/kukit Message-ID: <20060417115935.3399C10093@code0.codespeak.net> Author: reebalazs Date: Mon Apr 17 13:59:34 2006 New Revision: 25882 Modified: kukit/branch/plugin/kukit/kukit.js Log: refactoring extractFormData, bugfix Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Mon Apr 17 13:59:34 2006 @@ -455,9 +455,14 @@ /* Form data extraction */ kukit.extractFormQuery = function(target) { + + var query = new kukit.FormQuery(); + // We now put isKukitRequest=1; XXX we might deprecate this! + query.appendElem("isKukitRequest", "1"); + if (!target) { kukit.logWarning("No target given"); - return ""; + return query; } var form = kukit.findContainer(target, function(node) { if (!node.nodeName) { @@ -471,13 +476,9 @@ }); if (!form) { kukit.logWarning("No form found"); - return ""; + return query; } - var query = new kukit.FormQuery(); - // We now put isKukitRequest=1; XXX we might deprecate this! - query.appendElem("isKukitRequest", "1"); - var elements = form.elements; for (var y=0;y < elements.length;y++) { @@ -754,16 +755,16 @@ return result; } -kukit.dom.appendChildren = function(nodes, parent) { - var ownerDoc = parent.nodeType == Node.DOCUMENT_NODE ? parent : parent.ownerDocument; +kukit.dom.appendChildren = function(nodes, toNode) { + var ownerDoc = toNode.nodeType == Node.DOCUMENT_NODE ? toNode : toNode.ownerDocument; var result = new Array(); if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { for(var i=0;i < nodes.length;i++) { - result[i] = parent.appendChild(ownerDoc.importNode(nodes[i], true)); + result[i] = toNode.appendChild(ownerDoc.importNode(nodes[i], true)); }; }else{ for(var i=0;i < nodes.length;i++) { - result[i] = parent.appendChild(nodes[i].cloneNode(true)); + result[i] = toNode.appendChild(nodes[i].cloneNode(true)); }; }; return result; From reebalazs at codespeak.net Mon Apr 17 14:06:51 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 17 Apr 2006 12:06:51 -0000 Subject: [Kukit-checkins] r25883 - in kukit/branch/plugin: 3rd_party kukit Message-ID: <20060417120651.535351009C@code0.codespeak.net> Author: reebalazs Date: Mon Apr 17 14:06:49 2006 New Revision: 25883 Modified: kukit/branch/plugin/3rd_party/sarissa.js kukit/branch/plugin/kukit/kukit.js Log: Update sarissa to 0.9.6.1 - necessary to make serialize and importNode work on HTML dom docs Modified: kukit/branch/plugin/3rd_party/sarissa.js ============================================================================== --- kukit/branch/plugin/3rd_party/sarissa.js (original) +++ kukit/branch/plugin/3rd_party/sarissa.js Mon Apr 17 14:06:49 2006 @@ -2,22 +2,18 @@ * ==================================================================== * About * ==================================================================== - * Sarissa cross browser XML library - * @version 0.9.6 - * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net - * * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs. * The library supports Gecko based browsers like Mozilla and Firefox, - * Internet Explorer (5.5+ with MSXML3.0+) and, last but not least, KHTML based browsers like - * Konqueror and Safari. - * + * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera + * @version 0.9.6.1 + * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net * ==================================================================== * Licence * ==================================================================== * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 or * the GNU Lesser General Public License version 2.1 as published by - * the Free Software Foundation (your choice of the two). + * the Free Software Foundation (your choice between the two). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -31,7 +27,7 @@ * */ /** - *

Sarissa is a utility class. Provides static methods for DOMDocument and + *

Sarissa is a utility class. Provides "static" methods for DOMDocument and * XMLHTTP objects, DOM Node serializatrion to XML strings and other goodies.

* @constructor */ @@ -62,9 +58,8 @@ var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument; var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature; var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE; -var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1; +var _SARISSA_IS_SAFARI = (navigator.userAgent && navigator.vendor && (navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1 || navigator.vendor.indexOf("Apple") != -1)); var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1; - if(!window.Node || !window.Node.ELEMENT_NODE){ var Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12}; }; @@ -130,14 +125,14 @@ }; return oDoc; }; - // see non-IE version + // see non-IE version Sarissa.getParseErrorText = function (oDoc) { var parseErrorText = Sarissa.PARSED_OK; if(oDoc.parseError != 0){ - parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason + - "\nLocation: " + oDoc.parseError.url + - "\nLine Number " + oDoc.parseError.line + ", Column " + - oDoc.parseError.linepos + + parseErrorText = "XML Parsing Error: " + oDoc.parseError.reason + + "\nLocation: " + oDoc.parseError.url + + "\nLine Number " + oDoc.parseError.line + ", Column " + + oDoc.parseError.linepos + ":\n" + oDoc.parseError.srcText + "\n"; for(var i = 0; i < oDoc.parseError.linepos;i++){ @@ -151,9 +146,9 @@ Sarissa.setXpathNamespaces = function(oDoc, sNsSet) { oDoc.setProperty("SelectionLanguage", "XPath"); oDoc.setProperty("SelectionNamespaces", sNsSet); - }; + }; /** - * Basic implementation of Mozilla's XSLTProcessor for IE. + * Basic implementation of Mozilla's XSLTProcessor for IE. * Reuses the same XSLT stylesheet for multiple transforms * @constructor */ @@ -167,7 +162,7 @@ */ XSLTProcessor.prototype.importStylesheet = function(xslDoc){ // convert stylesheet to free threaded - var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID); + var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID); converted.loadXML(xslDoc.xml); this.template.stylesheet = converted; this.processor = this.template.createProcessor(); @@ -182,20 +177,11 @@ XSLTProcessor.prototype.transformToDocument = function(sourceDoc){ this.processor.input = sourceDoc; var outDoc = new ActiveXObject(_SARISSA_DOM_PROGID); - this.processor.output = outDoc; + this.processor.output = outDoc; this.processor.transform(); return outDoc; }; /** - * Not sure if this works in IE. Maybe this will allow non-well-formed - * transformation results (i.e. with no single root element) - * @argument sourceDoc The XML DOMDocument to transform - * @return The transformation result as a DOM Fragment - */ - XSLTProcessor.prototype.transformToFragment = function(sourceDoc, ownerDocument){ - return this.transformToDocument(sourceDoc); - }; - /** * Set global XSLT parameter of the imported stylesheet * @argument nsURI The parameter namespace URI * @argument name The parameter base name @@ -222,14 +208,51 @@ * @return The parameter value if reviously set by setParameter, null otherwise */ XSLTProcessor.prototype.getParameter = function(nsURI, name){ - if(this.paramsSet[""+nsURI] && this.paramsSet[""+nsURI][name]) - return this.paramsSet[""+nsURI][name]; - else + nsURI = nsURI || ""; + if(nsURI in this.paramsSet && name in this.paramsSet[nsURI]){ + return this.paramsSet[nsURI][name]; + }else{ return null; + }; }; } else{ /* end IE initialization, try to deal with real browsers now ;-) */ - if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){ + if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){ + /** + *

Ensures the document was loaded correctly, otherwise sets the + * parseError to -1 to indicate something went wrong. Internal use

+ * @private + */ + Sarissa.__handleLoad__ = function(oDoc){ + if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror") + oDoc.parseError = -1; + Sarissa.__setReadyState__(oDoc, 4); + }; + /** + *

Attached by an event handler to the load event. Internal use.

+ * @private + */ + _sarissa_XMLDocument_onload = function(){ + Sarissa.__handleLoad__(this); + }; + /** + *

Sets the readyState property of the given DOM Document object. + * Internal use.

+ * @private + * @argument oDoc the DOM Document object to fire the + * readystatechange event + * @argument iReadyState the number to change the readystate property to + */ + Sarissa.__setReadyState__ = function(oDoc, iReadyState){ + oDoc.readyState = iReadyState; + if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") + oDoc.onreadystatechange(); + }; + Sarissa.getDomDocument = function(sUri, sName){ + var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null); + oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false); + return oDoc; + }; if(window.XMLDocument){ /** *

Emulate IE's onreadystatechange attribute

@@ -254,16 +277,7 @@ // BTW the try>catch block is for 1.4; I haven't found a way to check if // the property is implemented without // causing an error and I dont want to use user agent stuff for that... - var _SARISSA_SYNC_NON_IMPLEMENTED = false; - try{ - /** - *

Emulates IE's async property for Moz versions prior to 1.4. - * It controls whether loading of remote XML files works - * synchronously or asynchronously.

- */ - XMLDocument.prototype.async = true; - _SARISSA_SYNC_NON_IMPLEMENTED = true; - }catch(e){/* trap */}; + var _SARISSA_SYNC_NON_IMPLEMENTED = false;// ("async" in XMLDocument.prototype) ? false: true; /** *

Keeps a handle to the original load() method. Internal use and only * if Mozilla version is lower than 1.4

@@ -305,50 +319,44 @@ }; return oDoc; }; - };//if(window.XMLDocument) - - /** - *

Ensures the document was loaded correctly, otherwise sets the - * parseError to -1 to indicate something went wrong. Internal use

- * @private - */ - Sarissa.__handleLoad__ = function(oDoc){ - if (!oDoc.documentElement || oDoc.documentElement.tagName == "parsererror") - oDoc.parseError = -1; - Sarissa.__setReadyState__(oDoc, 4); - }; - - /** - *

Attached by an event handler to the load event. Internal use.

- * @private - */ - _sarissa_XMLDocument_onload = function(){ - Sarissa.__handleLoad__(this); - }; - - /** - *

Sets the readyState property of the given DOM Document object. - * Internal use.

- * @private - * @argument oDoc the DOM Document object to fire the - * readystatechange event - * @argument iReadyState the number to change the readystate property to - */ - Sarissa.__setReadyState__ = function(oDoc, iReadyState){ - oDoc.readyState = iReadyState; - if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == "function") - oDoc.onreadystatechange(); - }; - /** - *

Factory method to obtain a new DOM Document object

- * @argument sUri the namespace of the root node (if any) - * @argument sUri the local name of the root node (if any) - * @returns a new DOM Document - */ - Sarissa.getDomDocument = function(sUri, sName){ - var oDoc = document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null); - oDoc.addEventListener("load", _sarissa_XMLDocument_onload, false); - return oDoc; + + + }//if(window.XMLDocument) + else if(document.implementation && document.implementation.hasFeature && document.implementation.hasFeature('LS', '3.0')){ + Document.prototype.async = true; + Document.prototype.onreadystatechange = null; + Document.prototype.parseError = 0; + Document.prototype.load = function(sURI) { + var parser = document.implementation.createLSParser(this.async ? document.implementation.MODE_ASYNCHRONOUS : document.implementation.MODE_SYNCHRONOUS, null); + if(this.async){ + var self = this; + parser.addEventListener("load", + function(e) { + self.readyState = 4; + Sarissa.copyChildNodes(e.newDocument, self.documentElement, false); + self.onreadystatechange.call(); + }, + false); + }; + try { + var oDoc = parser.parseURI(sURI); + } + catch(e){ + this.parseError = -1; + }; + if(!this.async) + Sarissa.copyChildNodes(oDoc, this.documentElement, false); + return oDoc; + }; + /** + *

Factory method to obtain a new DOM Document object

+ * @argument sUri the namespace of the root node (if any) + * @argument sUri the local name of the root node (if any) + * @returns a new DOM Document + */ + Sarissa.getDomDocument = function(sUri, sName){ + return document.implementation.createDocument(sUri?sUri:"", sName?sName:"", null); + }; }; };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT) }; @@ -356,24 +364,35 @@ // Common stuff //========================================== if(!window.DOMParser){ - /** + /* * DOMParser is a utility class, used to construct DOMDocuments from XML strings * @constructor */ DOMParser = function() { }; - /** - * Construct a new DOM Document from the given XMLstring - * @param sXml the given XML string - * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). - * @return a new DOM Document from the given XML string - */ - DOMParser.prototype.parseFromString = function(sXml, contentType){ - var doc = Sarissa.getDomDocument(); - doc.loadXML(sXml); - return doc; + if(_SARISSA_IS_SAFARI){ + /** + * Construct a new DOM Document from the given XMLstring + * @param sXml the given XML string + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). + * @return a new DOM Document from the given XML string + */ + DOMParser.prototype.parseFromString = function(sXml, contentType){ + if(contentType.toLowerCase() != "application/xml"){ + throw "Cannot handle content type: \"" + contentType + "\""; + }; + var xmlhttp = new XMLHttpRequest(); + xmlhttp.open("GET", "data:text/xml;charset=utf-8," + encodeURIComponent(str), false); + xmlhttp.send(null); + return xmlhttp.responseXML; + }; + }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && "loadXML" in Sarissa.getDomDocument()){ + DOMParser.prototype.parseFromString = function(sXml, contentType){ + var doc = Sarissa.getDomDocument(); + doc.loadXML(sXml); + return doc; + }; }; - }; if(window.XMLHttpRequest){ @@ -423,16 +442,16 @@ */ Sarissa.getParseErrorText = function (oDoc){ var parseErrorText = Sarissa.PARSED_OK; - if(oDoc.parseError != 0){ + if(oDoc && oDoc.parseError && oDoc.parseError != 0){ /*moz*/ if(oDoc.documentElement.tagName == "parsererror"){ parseErrorText = oDoc.documentElement.firstChild.data; parseErrorText += "\n" + oDoc.documentElement.firstChild.nextSibling.firstChild.data; }/*konq*/ - else if(oDoc.documentElement.tagName == "html"){ - parseErrorText = Sarissa.getText(oDoc.documentElement.getElementsByTagName("h1")[0], false) + "\n"; + else{ + parseErrorText = Sarissa.getText(oDoc.documentElement);/*.getElementsByTagName("h1")[0], false) + "\n"; parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("body")[0], false) + "\n"; - parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false); + parseErrorText += Sarissa.getText(oDoc.documentElement.getElementsByTagName("pre")[0], false);*/ }; }; return parseErrorText; @@ -446,8 +465,7 @@ var nodeType = node.nodeType; if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){ s += node.data; - } - else if(deep == true + }else if(deep == true && (nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){ @@ -462,14 +480,21 @@ * @returns the serialized Node as an XML string */ Sarissa.serialize = function(oDoc){ - return (new XMLSerializer()).serializeToString(oDoc); + var s = null; + if(oDoc){ + s = oDoc.innerHTML?oDoc.innerHTML:(new XMLSerializer()).serializeToString(oDoc); + }; + return s; }; }else{ - if((Sarissa.getDomDocument("","foo", null)).xml){ + if(Sarissa.getDomDocument && (Sarissa.getDomDocument("","foo", null)).xml){ // see non-IE version Sarissa.serialize = function(oDoc) { - // TODO: check for HTML document and return innerHTML instead - return oDoc.xml; + var s = null; + if(oDoc){ + s = oDoc.innerHTML?oDoc.innerHTML:oDoc.xml; + }; + return s; }; /** * Utility class to serialize DOM Node objects to XML strings @@ -497,19 +522,23 @@ * @argument oNode the Node to empty */ Sarissa.clearChildNodes = function(oNode) { - while(oNode.hasChildNodes()){ + // need to check for firstChild due to opera 8 bug with hasChildNodes + while(oNode.firstChild){ oNode.removeChild(oNode.firstChild); }; }; /** *

Copies the childNodes of nodeFrom to nodeTo

- *

Note: The second object's original content is deleted before + *

Note: The second object's original content is deleted before * the copy operation, unless you supply a true third parameter

* @argument nodeFrom the Node to copy the childNodes from * @argument nodeTo the Node to copy the childNodes to * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false */ Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { + if((!nodeFrom) || (!nodeTo)){ + throw "Both source and destination nodes must be provided"; + }; if(!bPreserveExisting){ Sarissa.clearChildNodes(nodeTo); }; @@ -529,41 +558,43 @@ /** *

Moves the childNodes of nodeFrom to nodeTo

- *

Note: The second object's original content is deleted before + *

Note: The second object's original content is deleted before * the move operation, unless you supply a true third parameter

* @argument nodeFrom the Node to copy the childNodes from * @argument nodeTo the Node to copy the childNodes to - * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false - */ + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is + */ Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { + if((!nodeFrom) || (!nodeTo)){ + throw "Both source and destination nodes must be provided"; + }; if(!bPreserveExisting){ Sarissa.clearChildNodes(nodeTo); }; - var nodes = nodeFrom.childNodes; // if within the same doc, just move, else copy and delete if(nodeFrom.ownerDocument == nodeTo.ownerDocument){ - nodeTo.appendChild(nodes[i]); + while(nodeFrom.firstChild){ + nodeTo.appendChild(nodeFrom.firstChild); + }; }else{ var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument; - if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { - for(var i=0;i < nodes.length;i++) { - nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); - }; - } - else{ - for(var i=0;i < nodes.length;i++) { - nodeTo.appendChild(nodes[i].cloneNode(true)); - }; + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) { + for(var i=0;i < nodes.length;i++) { + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true)); + }; + }else{ + for(var i=0;i < nodes.length;i++) { + nodeTo.appendChild(nodes[i].cloneNode(true)); + }; }; Sarissa.clearChildNodes(nodeFrom); }; - }; -/** +/** *

Serialize any object to an XML string. All properties are serialized using the property name - * as the XML element name. Array elements are rendered as array-item elements, + * as the XML element name. Array elements are rendered as array-item elements, * using their index/key as the value of the key attribute.

* @argument anyObject the object to serialize * @argument objectName a name for that object @@ -573,7 +604,7 @@ indentSpace = indentSpace?indentSpace:''; var s = indentSpace + '<' + objectName + '>'; var isLeaf = false; - if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String + if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String || anyObject instanceof Boolean || anyObject instanceof Date){ s += Sarissa.escape(""+anyObject); isLeaf = true; @@ -589,7 +620,7 @@ return s += (objectName.indexOf(' ')!=-1?"\n":"\n"); }; -/** +/** * Escape the given string chacters that correspond to the five predefined XML entities * @param sXml the string to escape */ @@ -601,8 +632,8 @@ .replace(/'/g, "'"); }; -/** - * Unescape the given string. This turns the occurences of the predefined XML +/** + * Unescape the given string. This turns the occurences of the predefined XML * entities to become the characters they represent correspond to the five predefined XML entities * @param sXml the string to unescape */ Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Mon Apr 17 14:06:49 2006 @@ -803,6 +803,9 @@ kukit.commandRegistry.register('setHtmlAsChild', function(node, command_data) { var content = document.importNode(command_data['html'], true); + alert('===' + Sarissa.serialize(command_data['html'])); + alert('***' + Sarissa.serialize(content)); + //alert('///' + content.innerHTML); Sarissa.clearChildNodes(node); kukit.dom.appendChildren(content.childNodes, node); kukit.setupEvents(node); From reebalazs at codespeak.net Mon Apr 17 14:07:46 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 17 Apr 2006 12:07:46 -0000 Subject: [Kukit-checkins] r25884 - kukit/branch/plugin/kukit Message-ID: <20060417120745.D7599100A8@code0.codespeak.net> Author: reebalazs Date: Mon Apr 17 14:07:44 2006 New Revision: 25884 Modified: kukit/branch/plugin/kukit/kukit.js Log: Update sarissa to 0.9.6.1 - ups, previous commit was too much Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Mon Apr 17 14:07:44 2006 @@ -803,9 +803,6 @@ kukit.commandRegistry.register('setHtmlAsChild', function(node, command_data) { var content = document.importNode(command_data['html'], true); - alert('===' + Sarissa.serialize(command_data['html'])); - alert('***' + Sarissa.serialize(content)); - //alert('///' + content.innerHTML); Sarissa.clearChildNodes(node); kukit.dom.appendChildren(content.childNodes, node); kukit.setupEvents(node); From reebalazs at codespeak.net Mon Apr 17 18:52:04 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Mon, 17 Apr 2006 16:52:04 -0000 Subject: [Kukit-checkins] r25912 - kukit/branch/plugin/kukit Message-ID: <20060417165204.BDC1010094@code0.codespeak.net> Author: reebalazs Date: Mon Apr 17 18:52:03 2006 New Revision: 25912 Modified: kukit/branch/plugin/kukit/kukit.js Log: Merge in from fschulze-enhancements r25911 - enhanced logging startup - little fixes - Selector registry ! - Only put in, in comments: 'A HREF' parametry hack. Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Mon Apr 17 18:52:03 2006 @@ -1,4 +1,24 @@ +/* Create kukit namespace */ +if (typeof(kukit) == 'undefined') { + var kukit = {}; +} + +/* check whether the logging stuff of MochiKit is available */ +try { + MochiKit.Logging.log('Initializing kukit'); + kukit.log = MochiKit.Logging.log; + kukit.logError = MochiKit.Logging.logError; + kukit.logDebug = MochiKit.Logging.logDebug; + kukit.logFatal = MochiKit.Logging.logFatal; + kukit.logWarning = MochiKit.Logging.logWarning; +} catch(e) { + kukit.log = function(str){}; + kukit.logError = kukit.log; + kukit.logDebug = kukit.log; + kukit.logFatal = kukit.log; + kukit.logWarning = kukit.log; +} /* Request manager */ kukit.RequestManager = function () { @@ -95,26 +115,6 @@ kukit.requestManager = new kukit.RequestManager(); -/* kukit */ - -function kukit(){}; - -/* check whether the logging stuff of MochiKit is available */ -try { - log('Initializing kukit'); - kukit.log = log; - kukit.logError = logError; - kukit.logDebug = logDebug; - kukit.logFatal = logFatal; - kukit.logWarning = logWarning; -} catch(e) { - kukit.log = function(str){}; - kukit.logError = kukit.log; - kukit.logDebug = kukit.log; - kukit.logFatal = kukit.log; - kukit.logWarning = kukit.log; -} - /* XXX this needs to be looked at it's used in CompositePack */ kukit.storedResults = new Array(); @@ -323,7 +323,7 @@ if (e.currentTarget) if (target != e.currentTarget) return;*/ - action = kukit.calculateAbsoluteURL(rule.parameters); + var action = kukit.calculateAbsoluteURL(rule.parameters); kukit.notifyServer(action, target); } @@ -356,13 +356,15 @@ } kukit.kukitEventTypes["cancelSubmitClick"] = function (rule, node) { - func = function(e) { - kukit.genericEventHandler(rule, e); - //Cancel default event - //W3C style - if (e.preventDefault) e.preventDefault(); - //MS style - try { e.returnValue = false; } catch (e) {} + var func = function(e) { + if (!e) var e=window.event; + kukit.genericEventHandler(rule, e); + // Cancel default event + // W3C style + if (e.preventDefault) + e.preventDefault(); + // MS style + try { e.returnValue = false; } catch (exc) {} } kukit.registerEventListener(node, 'click', func); } @@ -517,6 +519,28 @@ } } +/* + // XXX Hack to pass query string of link as parameters + if (target.tagName == 'A' || target.tagName == 'a') { + var parts = target.href.split('?'); + if (parts.length > 1) { + var queryparts = parts[1].split['&']; + for (var i=1; i 1) { + // XXX suppose not <= 2 though... + value = item[1]; + } + // XXX these are encoded. + // I think we would need to decode them, or else... + query.appendElem('kukitHref_' + key, value); + } + } + } +*/ + return query; } @@ -534,9 +558,9 @@ { // make a deferred callback var domDoc = new XMLHttpRequest(); - notifyServer_done = MochiKit.Base.partial(kukit.notifyServer_done, domDoc); + var notifyServer_done = MochiKit.Base.partial(kukit.notifyServer_done, domDoc); // sending form - form_data = kukit.extractFormData(target); + var form_data = kukit.extractFormData(target); var ts = new Date().getTime(); kukit.logDebug('TS: '+ts); var tsurl = url + "?kukitTimeStamp=" + ts; @@ -682,23 +706,11 @@ } } -kukit.XPATH_SELECTOR = 'xpath'; -kukit.CSS_SELECTOR = 'css'; -kukit.HTMLID_SELECTOR = 'htmlid'; - kukit.CommandProcessor.prototype.executeCommand = function(command) { kukit.logDebug('Selector type: '+command.selectorType); kukit.logDebug('Selector : '+command.selector); - if (command.selectorType == kukit.XPATH_SELECTOR) { - var xpath_res = xpathDomEval(command.selector, document); - kukit.logDebug('XPath nodes:'+xpath_res.stringValue()); - var nodes = xpath_res.nodeSetValue(); - kukit.logDebug('XPath nodes number: '+nodes.length); - } else { - var nodes = cssQuery(command.selector); - kukit.logDebug('CSS nodes number: '+nodes.length); - } + var nodes = kukit.selectors.get(command.selectorType)(command.selector); if (nodes.length == 0) { kukit.logError('Command found no nodes'); } @@ -720,6 +732,55 @@ this.params = params; } +/* selector registry */ + +kukit.selectors = {}; + +kukit.selectors._mapping = {}; + +kukit.selectors.register = function(name, func) { + kukit.selectors._mapping[name] = func; +} + +kukit.selectors.get = function(name) { + var result = kukit.selectors._mapping[name]; + if (!result && name != 'default') + return kukit.selectors.get('default'); + return result; +} + +kukit.selectors.register('htmlid', function(expr, node) { + if (!node) + node = document; + var nodes = []; + var node = node.getElementById(expr); + if (node) + nodes[nodes.length] = node; + kukit.logDebug('HTMLID nodes number: '+nodes.length); + return nodes; +}) + +kukit.selectors.register('css', function(expr, node) { + var nodes = cssQuery(expr, node); + kukit.logDebug('CSS nodes number: '+nodes.length); + return nodes; +}) + +kukit.selectors.register('xpath', function(expr, node) { + if (!node) + node = document; + var xpath_res = xpathDomEval(expr, node); + kukit.logDebug('XPath nodes:'+xpath_res.stringValue()); + var nodes = xpath_res.nodeSetValue(); + kukit.logDebug('XPath nodes number: '+nodes.length); + return nodes; +}) + +kukit.selectors.register('default', kukit.selectors.get('css')) + + +/* general dom helpers */ + kukit.dom = {} kukit.dom.getPreviousSiblingTag = function(node) { From reebalazs at codespeak.net Tue Apr 18 17:22:57 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Tue, 18 Apr 2006 15:22:57 -0000 Subject: [Kukit-checkins] r25956 - kukit/branch/plugin/kukit Message-ID: <20060418152257.3A9B51009C@code0.codespeak.net> Author: reebalazs Date: Tue Apr 18 17:22:56 2006 New Revision: 25956 Modified: kukit/branch/plugin/kukit/kukit.js Log: update request manager Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Tue Apr 18 17:22:56 2006 @@ -19,35 +19,58 @@ kukit.logFatal = kukit.log; kukit.logWarning = kukit.log; } + /* Request manager */ -kukit.RequestManager = function () { +kukit.RequestManager = function (name, maxNr) { this.waitingQueue = new kukit.FifoQueue(); this.sentNr = 0; + if (typeof(name) == undefined) { + name = null; + } + this.name = name; + var namestr = ''; + if (name != null) { + namestr = '[' + name + '] ' + } + this.namestr = namestr; + if (typeof(maxNr) != undefined && maxNr != null) { + this.maxNr = maxNr; + } } // max request nr kukit.RequestManager.prototype.maxNr = 4; -kukit.RequestManager.prototype.info = function() { - return ' (RQ: ' + this.sentNr + ' OUT, ' + this.waitingQueue.size() + ' WAI)'; +kukit.RequestManager.prototype.getInfo = function() { + return '(RQ: ' + this.sentNr + ' OUT, ' + this.waitingQueue.size() + ' WAI)'; +} + +kukit.RequestManager.prototype.log = function(txt) { + kukit.logDebug('RequestManager ' + this.namestr + txt + ' ' + this.getInfo()); } + kukit.RequestManager.prototype.pushWaitingRequest = function(func, url) { this.waitingQueue.push([func, url]); } + kukit.RequestManager.prototype.popWaitingRequest = function() { return this.waitingQueue.pop(); } + kukit.RequestManager.prototype.isWaitingRequestQueueEmpty = function() { return this.waitingQueue.empty(); } + kukit.RequestManager.prototype.pushSentRequest = function(func, url) { // we do not store the elems, since they are not needed now this.sentNr = this.sentNr + 1; } + kukit.RequestManager.prototype.popSentRequest = function() { this.sentNr = this.sentNr - 1; } + kukit.RequestManager.prototype.isSentRequestQueueFull = function() { return (this.sentNr >= this.maxNr) } @@ -55,34 +78,34 @@ /* request manager notification API */ kukit.RequestManager.prototype.notifyServer = function(func, url) { - // func must be a partial + // func must be a partial (e.g. use Mochikit or wrap up) // here url is only for the logging - if (! kukit.requestManager.isSentRequestQueueFull()) { + if (! this.isSentRequestQueueFull()) { // can be sent if we are not over the limit. this.pushSentRequest(func, url); - kukit.logDebug("Notify server at " + url + this.info()); + this.log('Notify server at ' + url); func(); } else { this.pushWaitingRequest(func, url); - kukit.logDebug("Queue server notification at " + url + this.info()); + this.log('Queue server notification at ' + url); } } kukit.RequestManager.prototype.receivedResult = function() { // must be called when one result arrived // Mark that we have one less request out. - kukit.requestManager.popSentRequest(); - if (! kukit.requestManager.isWaitingRequestQueueEmpty()) { + this.popSentRequest(); + if (! this.isWaitingRequestQueueEmpty()) { // see if we can send another request in place of the received one // request is waiting, send it. - var waiting = kukit.requestManager.popWaitingRequest(); + var waiting = this.popWaitingRequest(); var func = waiting[0]; var url = waiting[1]; - kukit.requestManager.pushSentRequest(func, url); - kukit.logDebug("Send queued notification to server at " + url + kukit.requestManager.info()); + this.pushSentRequest(func, url); + this.log("Send queued notification to server at " + url); func(); } else { - kukit.logDebug("Request queue empty." + kukit.requestManager.info()); + this.log("Request queue empty."); } } From reebalazs at codespeak.net Tue Apr 18 19:05:29 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Tue, 18 Apr 2006 17:05:29 -0000 Subject: [Kukit-checkins] r25960 - kukit/branch/plugin/kukit Message-ID: <20060418170529.79D5B10088@code0.codespeak.net> Author: reebalazs Date: Tue Apr 18 19:05:28 2006 New Revision: 25960 Modified: kukit/branch/plugin/kukit/kukit.js Log: Speed up command calling a little bit Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Tue Apr 18 19:05:28 2006 @@ -734,15 +734,18 @@ kukit.logDebug('Selector type: '+command.selectorType); kukit.logDebug('Selector : '+command.selector); var nodes = kukit.selectors.get(command.selectorType)(command.selector); + var func = null; if (nodes.length == 0) { kukit.logError('Command found no nodes'); + } else { + func = kukit.commandRegistry.getFunc(command.name); } for (var i=0;i < nodes.length;i++) { var node = nodes[i]; //XXX error handling for wrong command name kukit.logDebug('Command Name: '+command.name); - var results = kukit.commandRegistry.getFunc(command.name)(node, command.params); + var results = func(node, command.params); kukit.storeResults(results); // XXX see above } } From reebalazs at codespeak.net Wed Apr 19 22:01:08 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Wed, 19 Apr 2006 20:01:08 -0000 Subject: [Kukit-checkins] r26005 - kukit/branch/plugin/kukit Message-ID: <20060419200108.9F5FE1009C@code0.codespeak.net> Author: reebalazs Date: Wed Apr 19 22:01:07 2006 New Revision: 26005 Modified: kukit/branch/plugin/kukit/kukit.js Log: Implementing event/action plugins Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Wed Apr 19 22:01:07 2006 @@ -204,7 +204,22 @@ } } -// preprocessor +kukit.calculateAbsoluteURL = function(url) { + if (url.search("http://") == 0) { + return url; + } else { + var result = kukit.base + '/' + url; + return result; + } +} + +/* +* Preprocessor for the kukit resource +* +* This creates a set of EventRules +* with Actions +*/ + kukit.RuleProcessor = function() { this.rules = new Array(); this.href = null; @@ -219,16 +234,7 @@ return domDoc.responseXML; } -kukit.calculateAbsoluteURL = function(url) { - if (url.search("http://") == 0) { - return url; - } else { - var result = kukit.base + '/' + url; - return result; - } -} - -kukit.RuleProcessor.prototype.parseRules = function(rule_node) { +kukit.RuleProcessor.prototype.parseRule = function(rule_node) { var result = new Array(); var child_nodes = rule_node.childNodes; var selector = ""; @@ -244,31 +250,106 @@ if (event_node.nodeType != 1) continue; - var property_type = event_node.nodeName; - - var name = event_node.getAttribute("name"); - if (name == null) - name = ""; - - var parameters = ""; - if (event_node.firstChild) - parameters = event_node.firstChild.nodeValue; - + var property_type = event_node.nodeName.toLowerCase(); + var actions = []; + var params = {}; + + var event_childnodes = event_node.childNodes; + for (var i=0; i + if (params.type == 'timeout') { + var p = arg.split(' '); + if (p.length != 2) { + throw "Awaited url and timeout, got: "+arg; + } else { + arg = p[0]; + params.millis = p[1]; + } + } + } else if (property_type != "event") { + throw "Unknown property type ("+property_type+"): must be one of event, kukitevent"; + } + + // Generic action shortcut. If there is no action, a remote + // action is created by default, using the arg. + if (actions.length == 0) { + if (!arg) { + throw 'In case there are no actions, a parameter must be given'; + } + var defparams = {}; + defparams.type = 'remote'; + var action = new kukit.Action(arg, defparams); + actions[actions.length] = action; + } + + result[result.length] = new kukit.EventRule(selector, params, actions); } return result; } +kukit.RuleProcessor.prototype.parseAction = function(action_node) { + // parameters and type are in attributes + var params = {}; + var action_attributes = action_node.attributes; + for (var i=0; i 1) { From reebalazs at codespeak.net Wed Apr 19 22:28:15 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Wed, 19 Apr 2006 20:28:15 -0000 Subject: [Kukit-checkins] r26008 - kukit/branch/plugin/kukit Message-ID: <20060419202814.DF726100C1@code0.codespeak.net> Author: reebalazs Date: Wed Apr 19 22:28:13 2006 New Revision: 26008 Modified: kukit/branch/plugin/kukit/kukit.js Log: Harmonize name changes for event registry Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Wed Apr 19 22:28:13 2006 @@ -392,7 +392,7 @@ for (var y=0; y < nodes.length; y++) { var node = nodes[y]; - kukit.eventSetupRegistry.getFunc(eventrule.params.type)(eventrule, node); + kukit.eventTypeRegistry.getFunc(eventrule.params.type)(eventrule, node); } } @@ -422,17 +422,17 @@ } kukit.Action.prototype.execute = function(eventrule, node) { - kukit.actionRegistry.getFunc(this.params.type)(node, this.arg, this.parms); + kukit.eventActionRegistry.getFunc(this.params.type)(node, this.arg, this.parms); } /* Action registry */ -kukit.ActionRegistry = function () { +kukit.EventActionRegistry = function () { this.content = {}; this.nr = 0; } -kukit.ActionRegistry.prototype.register = function(name, func) { +kukit.EventActionRegistry.prototype.register = function(name, func) { if (this.content[name]) { // Do not allow redefinition kukit.logError('Error : redefinition attempt of action ' + name); @@ -442,7 +442,7 @@ this.nr = this.nr + 1; } -kukit.ActionRegistry.prototype.getFunc = function(name) { +kukit.EventActionRegistry.prototype.getFunc = function(name) { var func = this.content[name]; if (! func) { // not found @@ -451,11 +451,11 @@ return func; } -kukit.actionRegistry = new kukit.ActionRegistry(); +kukit.eventActionRegistry = new kukit.EventActionRegistry(); /* Core actions */ -kukit.actionRegistry.register("remote", function (node, arg, parms) { +kukit.eventActionRegistry.register("remote", function (node, arg, parms) { var action = kukit.calculateAbsoluteURL(arg); kukit.notifyServer(action, node); }); @@ -482,12 +482,12 @@ /* Event setup registry */ -kukit.EventSetupRegistry = function () { +kukit.EventTypeRegistry = function () { this.content = {}; this.nr = 0; } -kukit.EventSetupRegistry.prototype.register = function(name, func) { +kukit.EventTypeRegistry.prototype.register = function(name, func) { if (this.content[name]) { // Do not allow redefinition kukit.logError('Error : redefinition attempt of event setup type ' + name); @@ -497,7 +497,7 @@ this.nr = this.nr + 1; } -kukit.EventSetupRegistry.prototype.getFunc = function(name) { +kukit.EventTypeRegistry.prototype.getFunc = function(name) { var func = this.content[name]; if (! func) { // not found @@ -506,11 +506,11 @@ return func; } -kukit.eventSetupRegistry = new kukit.EventSetupRegistry(); +kukit.eventTypeRegistry = new kukit.EventTypeRegistry(); /* Core events */ -kukit.eventSetupRegistry.register('generic', function (rule, node) { +kukit.eventTypeRegistry.register('generic', function (rule, node) { func = MochiKit.Base.partial(kukit.genericEventHandler, rule); kukit.registerEventListener(node, rule.params.name, func); }); @@ -531,7 +531,7 @@ kukit.timer_event_registry = {}; -kukit.eventSetupRegistry.register("timeout", function (rule, node) { +kukit.eventTypeRegistry.register("timeout", function (rule, node) { var timeout = rule.params.millis; // XXX Timer key generation is changed. // XXX now key does not contain the methodName, @@ -549,7 +549,7 @@ } }); -kukit.eventSetupRegistry.register("cancelSubmitClick", function (rule, node) { +kukit.eventTypeRegistry.register("cancelSubmitClick", function (rule, node) { var func = function(e) { if (!e) var e=window.event; kukit.genericEventHandler(rule, e); From reebalazs at codespeak.net Wed Apr 19 23:04:15 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Wed, 19 Apr 2006 21:04:15 -0000 Subject: [Kukit-checkins] r26009 - kukit/branch/plugin/kukit Message-ID: <20060419210415.BEEE31009C@code0.codespeak.net> Author: reebalazs Date: Wed Apr 19 23:04:14 2006 New Revision: 26009 Modified: kukit/branch/plugin/kukit/kukit.js Log: Add sample action types for logging Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Wed Apr 19 23:04:14 2006 @@ -422,7 +422,7 @@ } kukit.Action.prototype.execute = function(eventrule, node) { - kukit.eventActionRegistry.getFunc(this.params.type)(node, this.arg, this.parms); + kukit.eventActionRegistry.getFunc(this.params.type)(eventrule, node, this.arg, this.params); } /* Action registry */ @@ -455,11 +455,35 @@ /* Core actions */ -kukit.eventActionRegistry.register("remote", function (node, arg, parms) { +kukit.eventActionRegistry.register("remote", function (eventrule, node, arg, params) { var action = kukit.calculateAbsoluteURL(arg); kukit.notifyServer(action, node); }); +kukit.eventActionRegistry.register("logDebug", function (eventrule, node, arg, params) { + var message = "Logging from EVENT"; + if (arg) { + message = arg; + } + kukit.logDebug(message + ', rule=#' + eventrule.nr + ', node=' + node.nodeName); +}); + +kukit.eventActionRegistry.register("log", function (eventrule, node, arg, params) { + var message = "Logging from EVENT"; + if (arg) { + message = arg; + } + kukit.log(message + ', rule=#' + eventrule.nr + ', node=' + node.nodeName); +}); + +kukit.eventActionRegistry.register("alert", function (eventrule, node, arg, params) { + var message = "Message from EVENT"; + if (arg) { + message = arg; + } + alert(message + ', rule=#' + eventrule.nr + ', node=' + node.nodeName); +}); + /* Event handling */ kukit.genericEventHandler = function(eventrule, e) { From reebalazs at codespeak.net Sat Apr 22 19:32:50 2006 From: reebalazs at codespeak.net (reebalazs at codespeak.net) Date: Sat, 22 Apr 2006 17:32:50 -0000 Subject: [Kukit-checkins] r26144 - kukit/branch/plugin/kukit Message-ID: <20060422173250.53B701007A@code0.codespeak.net> Author: reebalazs Date: Sat Apr 22 19:32:49 2006 New Revision: 26144 Modified: kukit/branch/plugin/kukit/kukit.js Log: call calculateBase implicitely, so further scripts can see kukit.base Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sat Apr 22 19:32:49 2006 @@ -182,8 +182,9 @@ } } +kukit.calculateBase(); + kukit.initializeRules = function() { - kukit.calculateBase(); var rulelinks = kukit.getRuleSheetLinks(); kukit.log("Rule Sheet Links: "+rulelinks); for (var i=0; i Author: gotcha Date: Wed Apr 26 21:18:53 2006 New Revision: 26381 Added: kukit/trunk/kukit/jrs-parser.js kukit/trunk/tests/runtests.js (contents, props changed) kukit/trunk/tests/runtests.sh (contents, props changed) kukit/trunk/tests/testJrsParser.js (contents, props changed) Modified: kukit/ (props changed) kukit/trunk/tests/ecmaunit.js kukit/trunk/tests/runner.html Log: r22897 at archipelago: fschulze | 2006-04-26 12:08:25 +0200 Added jrs parser with tests. Added: kukit/trunk/kukit/jrs-parser.js ============================================================================== --- (empty file) +++ kukit/trunk/kukit/jrs-parser.js Wed Apr 26 21:18:53 2006 @@ -0,0 +1,52 @@ +CssParser = function() { +}; + +CssParser._rule_regexp = /((\s|.)*?)\{((\s|.)*?)\}/g; +CssParser._selector_regexp = /()/; + +CssParser.trim = function(str, chars) { + if (!chars) + chars='\\s' + return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); +} + +CssParser.parse = function(src) { + var rules = {}; + + // remove comments + src = src.replace(/\/\*(\s|.)*?\*\//g, ""); + + // split into rules + var rawrules = src.split('}'); + for (var i=0; rawrules.length; i++) { + if (!rawrules[i]) + break; + // split into selector and parameters + var parts = rawrules[i].split('{'); + // clean up selector + var selector = this.trim(parts[0]); + var selectorparts = selector.split(',') + for (var k=0; k -1) { + // remove useless bit of traceback + break; + }; + if (line.charAt(0) == '(') { + line = 'function' + line; + }; + var chunks = line.split('@'); + toprint.push(chunks); + }; + toprint.reverse(); + for (var i=0; i < toprint.length; i++) { + print(' ' + toprint[i][1]); + print(' ' + toprint[i][0]); + }; + print(); +}; + +function HTMLReporter(outputelement, verbose) { + if (outputelement) { + this.outputelement = outputelement; + this.document = outputelement.ownerDocument; + this.verbose = verbose; + }; +}; + +HTMLReporter.prototype.debug = function(text) { + var msg = this.document.createTextNode(text); + var div = this.document.createElement('div'); + div.appendChild(msg); + this.outputelement.appendChild(div); +}; + +HTMLReporter.prototype.reportSuccess = function(testcase, attr) { + /* report a test success */ + // a single dot looks rather small + var dot = this.document.createTextNode('+'); + this.outputelement.appendChild(dot); +}; - this.summarize = function(numtests, time, exceptions) { - print('\n' + numtests + ' tests ran in ' + time / 1000.0 + - ' seconds\n'); - if (exceptions.length) { - for (var i=0; i < exceptions.length; i++) { - var testcase = exceptions[i][0]; - var attr = exceptions[i][1]; - var exception = exceptions[i][2]; - var raw = exceptions[i][3]; - print(testcase + '.' + attr + ', exception: ' + exception); - if (verbose) { - this._printStackTrace(raw); +HTMLReporter.prototype.reportError = function(testcase, attr, exception, raw) { + /* report a test failure */ + var f = this.document.createTextNode('F'); + this.outputelement.appendChild(f); +}; + +HTMLReporter.prototype.summarize = function(numtests, time, exceptions) { + /* write the result output to the html node */ + var p = this.document.createElement('p'); + var text = this.document.createTextNode(numtests + ' tests ran in ' + + time / 1000.0 + ' seconds'); + p.appendChild(text); + this.outputelement.appendChild(p); + if (exceptions.length) { + for (var i=0; i < exceptions.length; i++) { + var testcase = exceptions[i][0]; + var attr = exceptions[i][1]; + var exception = exceptions[i][2].toString(); + var raw = exceptions[i][3]; + var div = this.document.createElement('div'); + var lines = exception.toString().split('\n'); + var text = this.document.createTextNode( + testcase + '.' + attr + ', exception '); + div.appendChild(text); + // add some formatting for Opera: this browser displays nice + // tracebacks... + for (var j=0; j < lines.length; j++) { + var text = lines[j]; + if (j > 0) { + text = '\xa0\xa0\xa0\xa0' + text; }; + div.appendChild(this.document.createTextNode(text)); + div.appendChild(this.document.createElement('br')); + }; + div.style.color = 'red'; + this.outputelement.appendChild(div); + if (this.verbose) { + // display stack trace on Moz + this._displayStackTrace(raw); }; - print('NOT OK!'); - } else { - print('OK!'); }; + var div = this.document.createElement('div'); + var text = this.document.createTextNode('NOT OK!'); + div.appendChild(text); + div.style.backgroundColor = 'red'; + div.style.color = 'black'; + div.style.fontWeight = 'bold'; + div.style.textAlign = 'center'; + div.style.marginTop = '1em'; + this.outputelement.appendChild(div); + } else { + var div = this.document.createElement('div'); + var text = this.document.createTextNode('OK!'); + div.appendChild(text); + div.style.backgroundColor = 'lightgreen'; + div.style.color = 'black'; + div.style.fontWeight = 'bold'; + div.style.textAlign = 'center'; + div.style.marginTop = '1em'; + this.outputelement.appendChild(div); }; +}; - this._printStackTrace = function(exc) { - if (!exc.stack) { - print('no stacktrace available'); - return; +HTMLReporter.prototype._displayStackTrace = function(exc) { + /* + if (arguments.caller) { + // IE + var caller = arguments; + toprint = []; + while (caller) { + var callee = caller.callee.toString(); + callee = callee.replace('\n', '').replace(/\s+/g, ' '); + var funcsig = /(.*?)\s*\{/.exec(callee)[1]; + var args = caller.callee.arguments; + var displayargs = []; + for (var i=0; i < args.length; i++) { + displayargs.push(args[i].toString()); + }; + toprint.push((funcsig + ' - (' + displayargs + ')')); + caller = caller.caller; + }; + toprint.reverse(); + var pre = this.document.createElement('pre'); + for (var i=0; i < toprint.length; i++) { + pre.appendChild(document.createTextNode(toprint[i])); + pre.appendChild(document.createElement('br')); }; + this.outputelement.appendChild(pre); + }; + */ + if (exc.stack) { + // Moz (sometimes) var lines = exc.stack.toString().split('\n'); - var toprint = []; + var toprint = []; // need to reverse this before outputting for (var i=0; i < lines.length; i++) { var line = lines[i]; if (line.indexOf('ecmaunit.js') > -1) { // remove useless bit of traceback break; }; - if (line.charAt(0) == '(') { + if (line[0] == '(') { line = 'function' + line; }; - var chunks = line.split('@'); - toprint.push(chunks); + line = line.split('@'); + toprint.push(line); }; toprint.reverse(); + var pre = this.document.createElement('pre'); for (var i=0; i < toprint.length; i++) { - print(' ' + toprint[i][1]); - print(' ' + toprint[i][0]); - }; - print(); - }; -}; - -function HTMLReporter(outputelement, verbose) { - this.outputelement = outputelement; - this.document = outputelement.ownerDocument; - this.verbose = verbose; //XXX verbose not yet supported - - this.debug = function(text) { - var msg = this.document.createTextNode(text); - var div = this.document.createElement('div'); - div.appendChild(msg); - this.outputelement.appendChild(div); - } - this.reportSuccess = function(testcase, attr) { - /* report a test success */ - // a single dot looks rather small - var dot = this.document.createTextNode('+'); - this.outputelement.appendChild(dot); - }; - - this.reportError = function(testcase, attr, exception, raw) { - /* report a test failure */ - var f = this.document.createTextNode('F'); - this.outputelement.appendChild(f); - if (this.verbose) { - }; - }; - - this.summarize = function(numtests, time, exceptions) { - /* write the result output to the html node */ - var p = this.document.createElement('p'); - var text = this.document.createTextNode(numtests + ' tests ran in ' + - time / 1000.0 + ' seconds'); - p.appendChild(text); - this.outputelement.appendChild(p); - if (exceptions.length) { - for (var i=0; i < exceptions.length; i++) { - var testcase = exceptions[i][0]; - var attr = exceptions[i][1]; - var exception = exceptions[i][2]; - var raw = exceptions[i][3]; - var div = this.document.createElement('div'); - var lines = exception.split('\n'); - var text = this.document.createTextNode( - testcase + '.' + attr + ', exception '); - div.appendChild(text); - // add some formatting for Opera: this browser displays nice - // tracebacks... - for (var j=0; j < lines.length; j++) { - var text = lines[j]; - if (j > 0) { - text = '\xa0\xa0\xa0\xa0' + text; - }; - div.appendChild(this.document.createTextNode(text)); - div.appendChild(this.document.createElement('br')); - }; - div.style.color = 'red'; - this.outputelement.appendChild(div); - if (this.verbose) { - // display stack trace on Moz - this._displayStackTrace(raw); - }; - }; - var div = this.document.createElement('div'); - var text = this.document.createTextNode('NOT OK!'); - div.appendChild(text); - div.style.backgroundColor = 'red'; - div.style.color = 'black'; - div.style.fontWeight = 'bold'; - div.style.textAlign = 'center'; - div.style.marginTop = '1em'; - this.outputelement.appendChild(div); - } else { - var div = this.document.createElement('div'); - var text = this.document.createTextNode('OK!'); - div.appendChild(text); - div.style.backgroundColor = 'lightgreen'; - div.style.color = 'black'; - div.style.fontWeight = 'bold'; - div.style.textAlign = 'center'; - div.style.marginTop = '1em'; - this.outputelement.appendChild(div); - }; - }; - - this._displayStackTrace = function(exc) { - /* - if (arguments.caller) { - // IE - var caller = arguments; - toprint = []; - while (caller) { - var callee = caller.callee.toString(); - callee = callee.replace('\n', '').replace(/\s+/g, ' '); - var funcsig = /(.*?)\s*\{/.exec(callee)[1]; - var args = caller.callee.arguments; - var displayargs = []; - for (var i=0; i < args.length; i++) { - displayargs.push(args[i].toString()); - }; - toprint.push((funcsig + ' - (' + displayargs + ')')); - caller = caller.caller; - }; - toprint.reverse(); - var pre = this.document.createElement('pre'); - for (var i=0; i < toprint.length; i++) { - pre.appendChild(document.createTextNode(toprint[i])); - pre.appendChild(document.createElement('br')); - }; - this.outputelement.appendChild(pre); - }; - */ - if (exc.stack) { - // Moz (sometimes) - var lines = exc.stack.toString().split('\n'); - var toprint = []; // need to reverse this before outputting - for (var i=0; i < lines.length; i++) { - var line = lines[i]; - if (line.indexOf('ecmaunit.js') > -1) { - // remove useless bit of traceback - break; - }; - if (line[0] == '(') { - line = 'function' + line; - }; - line = line.split('@'); - toprint.push(line); - }; - toprint.reverse(); - var pre = this.document.createElement('pre'); - for (var i=0; i < toprint.length; i++) { - pre.appendChild( - this.document.createTextNode( - ' ' + toprint[i][1] + '\n ' + toprint[i][0] + '\n' - ) - ); - }; - pre.appendChild(document.createTextNode('\n')); - this.outputelement.appendChild(pre); + pre.appendChild( + this.document.createTextNode( + ' ' + toprint[i][1] + '\n ' + toprint[i][0] + '\n' + ) + ); }; + pre.appendChild(document.createTextNode('\n')); + this.outputelement.appendChild(pre); }; }; Modified: kukit/trunk/tests/runner.html ============================================================================== --- kukit/trunk/tests/runner.html (original) +++ kukit/trunk/tests/runner.html Wed Apr 26 21:18:53 2006 @@ -16,9 +16,11 @@ + + Added: kukit/trunk/tests/runtests.js ============================================================================== --- (empty file) +++ kukit/trunk/tests/runtests.js Wed Apr 26 21:18:53 2006 @@ -0,0 +1,24 @@ +/***************************************************************************** + * + * Copyright (c) 2003-2004 EcmaUnit Contributors. All rights reserved. + * + * This software is distributed under the terms of the EcmaUnit + * License. See LICENSE.txt for license text. For a list of EcmaUnit + * Contributors see CREDITS.txt. + * + *****************************************************************************/ + +// $Id: runtests.js 18718 2005-10-17 14:29:18Z duncan $ + +/* + Test runner for command-line environments, such as spidermonkey +*/ + +function runTests() { + var reporter = new StdoutReporter; + var testsuite = new TestSuite(reporter); + testsuite.registerTest(CssParserTestCase); + testsuite.runSuite(); +}; + +runTests(); Added: kukit/trunk/tests/runtests.sh ============================================================================== --- (empty file) +++ kukit/trunk/tests/runtests.sh Wed Apr 26 21:18:53 2006 @@ -0,0 +1 @@ +js -f ecmaunit.js -f testJrsParser.js -f ../kukit/jrs-parser.js runtests.js Added: kukit/trunk/tests/testJrsParser.js ============================================================================== --- (empty file) +++ kukit/trunk/tests/testJrsParser.js Wed Apr 26 21:18:53 2006 @@ -0,0 +1,139 @@ +function CssParserTestCase() { + this.name = 'CssParserTestCase'; + + this.setUp = function() { + /* not in use here, didn't have to define it but this might be + used as a reference + */ + }; + + this.testEmptyRule = function() { + var src = "#noneselector {}"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules) + }; + + this.testIdRule = function() { + var src = "#idselector {\n key: value; \n}\n"; + var rules = CssParser.parse(src); + this.assertTrue("#idselector" in rules); + } + + this.testSeveralSelectorRule = function() { + var src = "#noneselector {}\n\n#idselector {\n key: value; \n}\n"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules) + this.assertTrue("#idselector" in rules); + } + + this.testClassSelectorRule = function() { + var src = "#noneselector {}\n\n.classselector \n{key:value;}\n"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules); + this.assertTrue(".classselector" in rules); + } + + this.testTagSelectorRule = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n"; + var rules = CssParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testComments = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n\n/* comment outside */\n"; + var rules = CssParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testMultilineComments = function() { + var src = "/* multi\n line\n comment */tag { key: value }"; + var rules = CssParser.parse(src); + this.assertTrue("tag" in rules); + this.assertEquals(rules["tag"]["key"], "value"); + } + + this.testValidTagInComment = function() { + var src = "/*\n #commented-id {\n }\n*/"; + var rules = CssParser.parse(src); + this.assertFalse("#commented-id" in rules); + } + + this.testEmptyComment = function() { + var src = "tag/**/ {key:value}"; + var rules = CssParser.parse(src); + this.assertTrue("tag" in rules); + } + + this.testComplexComments = function() { + var src = "#property-id {\n key: value;\n key2 :value ; key3:value3;key4:/*comment*/value4;\n key5/*comment*/:value5;\n/*}*/\n key6/*fun:*/:value/*;*/6;\n}"; + var rules = CssParser.parse(src); + var rule = rules["#property-id"]; + for (var i in rule) { + switch (i) { + case "key": + this.assertEquals(rule[i], "value"); + break; + case "key2": + this.assertEquals(rule[i], "value"); + break; + case "key3": + this.assertEquals(rule[i], "value3"); + break; + case "key4": + this.assertEquals(rule[i], "value4"); + break; + case "key5": + this.assertEquals(rule[i], "value5"); + break; + case "key6": + this.assertEquals(rule[i], "value6"); + break; + default: + this.fail("unexpected property found: "+i); + } + } + } + + this.testParameterResetting = function() { + var src = ".class2 {\n key: value-old;\n key: value-new;\n}"; + var rules = CssParser.parse(src); + this.assertEquals(rules[".class2"]["key"], "value-new"); + } + + this.testMultipleSelectors = function() { + var src = "#id1, .class6, tag {\n key: value;\n}"; + var rules = CssParser.parse(src); + this.assertTrue("#id1, .class6, tag" in rules); + } + + this.testSpaceSeperatedSelectors = function() { + var src = "tag .class7 {\n key: value;\n}"; + var rules = CssParser.parse(src); + this.assertTrue("tag .class7" in rules); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class8,\n#id1 { key:value; }"; + var rules = CssParser.parse(src); + this.assertTrue("tag.class8, #id1" in rules); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class9\n,\n#id2\n{ key:value; }"; + var rules = CssParser.parse(src); + this.assertTrue("tag.class9, #id2" in rules); + } + + this.testMultipleDeclarationsSelectors = function() { + var src = "tag{key1:value1}\ntag{key2:value2}"; + var rules = CssParser.parse(src); + this.assertEquals(rules["tag"]["key1"], "value1"); + this.assertEquals(rules["tag"]["key2"], "value2"); + } +}; + +CssParserTestCase.prototype = new TestCase; + +if (typeof(testcase_registry) != 'undefined') { + testcase_registry.registerTestCase(CssParserTestCase, 'jrsparser'); +} From gotcha at codespeak.net Wed Apr 26 21:19:16 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Wed, 26 Apr 2006 19:19:16 -0000 Subject: [Kukit-checkins] r26382 - in kukit: . branch/plugin/kukit branch/plugin/tests Message-ID: <20060426191915.F247C1008A@code0.codespeak.net> Author: gotcha Date: Wed Apr 26 21:19:12 2006 New Revision: 26382 Added: kukit/branch/plugin/kukit/jrs-parser.js kukit/branch/plugin/tests/runtests.js (contents, props changed) kukit/branch/plugin/tests/runtests.sh (contents, props changed) kukit/branch/plugin/tests/testJrsParser.js (contents, props changed) Modified: kukit/ (props changed) kukit/branch/plugin/tests/ecmaunit.js kukit/branch/plugin/tests/runner.html Log: r22914 at archipelago: fschulze | 2006-04-26 19:31:03 +0200 Merged jrs parser with tests from trunk. Added: kukit/branch/plugin/kukit/jrs-parser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/jrs-parser.js Wed Apr 26 21:19:12 2006 @@ -0,0 +1,52 @@ +CssParser = function() { +}; + +CssParser._rule_regexp = /((\s|.)*?)\{((\s|.)*?)\}/g; +CssParser._selector_regexp = /()/; + +CssParser.trim = function(str, chars) { + if (!chars) + chars='\\s' + return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); +} + +CssParser.parse = function(src) { + var rules = {}; + + // remove comments + src = src.replace(/\/\*(\s|.)*?\*\//g, ""); + + // split into rules + var rawrules = src.split('}'); + for (var i=0; rawrules.length; i++) { + if (!rawrules[i]) + break; + // split into selector and parameters + var parts = rawrules[i].split('{'); + // clean up selector + var selector = this.trim(parts[0]); + var selectorparts = selector.split(',') + for (var k=0; k -1) { + // remove useless bit of traceback + break; + }; + if (line.charAt(0) == '(') { + line = 'function' + line; + }; + var chunks = line.split('@'); + toprint.push(chunks); + }; + toprint.reverse(); + for (var i=0; i < toprint.length; i++) { + print(' ' + toprint[i][1]); + print(' ' + toprint[i][0]); + }; + print(); +}; + +function HTMLReporter(outputelement, verbose) { + if (outputelement) { + this.outputelement = outputelement; + this.document = outputelement.ownerDocument; + this.verbose = verbose; + }; +}; + +HTMLReporter.prototype.debug = function(text) { + var msg = this.document.createTextNode(text); + var div = this.document.createElement('div'); + div.appendChild(msg); + this.outputelement.appendChild(div); +}; + +HTMLReporter.prototype.reportSuccess = function(testcase, attr) { + /* report a test success */ + // a single dot looks rather small + var dot = this.document.createTextNode('+'); + this.outputelement.appendChild(dot); +}; - this.summarize = function(numtests, time, exceptions) { - print('\n' + numtests + ' tests ran in ' + time / 1000.0 + - ' seconds\n'); - if (exceptions.length) { - for (var i=0; i < exceptions.length; i++) { - var testcase = exceptions[i][0]; - var attr = exceptions[i][1]; - var exception = exceptions[i][2]; - var raw = exceptions[i][3]; - print(testcase + '.' + attr + ', exception: ' + exception); - if (verbose) { - this._printStackTrace(raw); +HTMLReporter.prototype.reportError = function(testcase, attr, exception, raw) { + /* report a test failure */ + var f = this.document.createTextNode('F'); + this.outputelement.appendChild(f); +}; + +HTMLReporter.prototype.summarize = function(numtests, time, exceptions) { + /* write the result output to the html node */ + var p = this.document.createElement('p'); + var text = this.document.createTextNode(numtests + ' tests ran in ' + + time / 1000.0 + ' seconds'); + p.appendChild(text); + this.outputelement.appendChild(p); + if (exceptions.length) { + for (var i=0; i < exceptions.length; i++) { + var testcase = exceptions[i][0]; + var attr = exceptions[i][1]; + var exception = exceptions[i][2].toString(); + var raw = exceptions[i][3]; + var div = this.document.createElement('div'); + var lines = exception.toString().split('\n'); + var text = this.document.createTextNode( + testcase + '.' + attr + ', exception '); + div.appendChild(text); + // add some formatting for Opera: this browser displays nice + // tracebacks... + for (var j=0; j < lines.length; j++) { + var text = lines[j]; + if (j > 0) { + text = '\xa0\xa0\xa0\xa0' + text; }; + div.appendChild(this.document.createTextNode(text)); + div.appendChild(this.document.createElement('br')); + }; + div.style.color = 'red'; + this.outputelement.appendChild(div); + if (this.verbose) { + // display stack trace on Moz + this._displayStackTrace(raw); }; - print('NOT OK!'); - } else { - print('OK!'); }; + var div = this.document.createElement('div'); + var text = this.document.createTextNode('NOT OK!'); + div.appendChild(text); + div.style.backgroundColor = 'red'; + div.style.color = 'black'; + div.style.fontWeight = 'bold'; + div.style.textAlign = 'center'; + div.style.marginTop = '1em'; + this.outputelement.appendChild(div); + } else { + var div = this.document.createElement('div'); + var text = this.document.createTextNode('OK!'); + div.appendChild(text); + div.style.backgroundColor = 'lightgreen'; + div.style.color = 'black'; + div.style.fontWeight = 'bold'; + div.style.textAlign = 'center'; + div.style.marginTop = '1em'; + this.outputelement.appendChild(div); }; +}; - this._printStackTrace = function(exc) { - if (!exc.stack) { - print('no stacktrace available'); - return; +HTMLReporter.prototype._displayStackTrace = function(exc) { + /* + if (arguments.caller) { + // IE + var caller = arguments; + toprint = []; + while (caller) { + var callee = caller.callee.toString(); + callee = callee.replace('\n', '').replace(/\s+/g, ' '); + var funcsig = /(.*?)\s*\{/.exec(callee)[1]; + var args = caller.callee.arguments; + var displayargs = []; + for (var i=0; i < args.length; i++) { + displayargs.push(args[i].toString()); + }; + toprint.push((funcsig + ' - (' + displayargs + ')')); + caller = caller.caller; + }; + toprint.reverse(); + var pre = this.document.createElement('pre'); + for (var i=0; i < toprint.length; i++) { + pre.appendChild(document.createTextNode(toprint[i])); + pre.appendChild(document.createElement('br')); }; + this.outputelement.appendChild(pre); + }; + */ + if (exc.stack) { + // Moz (sometimes) var lines = exc.stack.toString().split('\n'); - var toprint = []; + var toprint = []; // need to reverse this before outputting for (var i=0; i < lines.length; i++) { var line = lines[i]; if (line.indexOf('ecmaunit.js') > -1) { // remove useless bit of traceback break; }; - if (line.charAt(0) == '(') { + if (line[0] == '(') { line = 'function' + line; }; - var chunks = line.split('@'); - toprint.push(chunks); + line = line.split('@'); + toprint.push(line); }; toprint.reverse(); + var pre = this.document.createElement('pre'); for (var i=0; i < toprint.length; i++) { - print(' ' + toprint[i][1]); - print(' ' + toprint[i][0]); - }; - print(); - }; -}; - -function HTMLReporter(outputelement, verbose) { - this.outputelement = outputelement; - this.document = outputelement.ownerDocument; - this.verbose = verbose; //XXX verbose not yet supported - - this.debug = function(text) { - var msg = this.document.createTextNode(text); - var div = this.document.createElement('div'); - div.appendChild(msg); - this.outputelement.appendChild(div); - } - this.reportSuccess = function(testcase, attr) { - /* report a test success */ - // a single dot looks rather small - var dot = this.document.createTextNode('+'); - this.outputelement.appendChild(dot); - }; - - this.reportError = function(testcase, attr, exception, raw) { - /* report a test failure */ - var f = this.document.createTextNode('F'); - this.outputelement.appendChild(f); - if (this.verbose) { - }; - }; - - this.summarize = function(numtests, time, exceptions) { - /* write the result output to the html node */ - var p = this.document.createElement('p'); - var text = this.document.createTextNode(numtests + ' tests ran in ' + - time / 1000.0 + ' seconds'); - p.appendChild(text); - this.outputelement.appendChild(p); - if (exceptions.length) { - for (var i=0; i < exceptions.length; i++) { - var testcase = exceptions[i][0]; - var attr = exceptions[i][1]; - var exception = exceptions[i][2]; - var raw = exceptions[i][3]; - var div = this.document.createElement('div'); - var lines = exception.split('\n'); - var text = this.document.createTextNode( - testcase + '.' + attr + ', exception '); - div.appendChild(text); - // add some formatting for Opera: this browser displays nice - // tracebacks... - for (var j=0; j < lines.length; j++) { - var text = lines[j]; - if (j > 0) { - text = '\xa0\xa0\xa0\xa0' + text; - }; - div.appendChild(this.document.createTextNode(text)); - div.appendChild(this.document.createElement('br')); - }; - div.style.color = 'red'; - this.outputelement.appendChild(div); - if (this.verbose) { - // display stack trace on Moz - this._displayStackTrace(raw); - }; - }; - var div = this.document.createElement('div'); - var text = this.document.createTextNode('NOT OK!'); - div.appendChild(text); - div.style.backgroundColor = 'red'; - div.style.color = 'black'; - div.style.fontWeight = 'bold'; - div.style.textAlign = 'center'; - div.style.marginTop = '1em'; - this.outputelement.appendChild(div); - } else { - var div = this.document.createElement('div'); - var text = this.document.createTextNode('OK!'); - div.appendChild(text); - div.style.backgroundColor = 'lightgreen'; - div.style.color = 'black'; - div.style.fontWeight = 'bold'; - div.style.textAlign = 'center'; - div.style.marginTop = '1em'; - this.outputelement.appendChild(div); - }; - }; - - this._displayStackTrace = function(exc) { - /* - if (arguments.caller) { - // IE - var caller = arguments; - toprint = []; - while (caller) { - var callee = caller.callee.toString(); - callee = callee.replace('\n', '').replace(/\s+/g, ' '); - var funcsig = /(.*?)\s*\{/.exec(callee)[1]; - var args = caller.callee.arguments; - var displayargs = []; - for (var i=0; i < args.length; i++) { - displayargs.push(args[i].toString()); - }; - toprint.push((funcsig + ' - (' + displayargs + ')')); - caller = caller.caller; - }; - toprint.reverse(); - var pre = this.document.createElement('pre'); - for (var i=0; i < toprint.length; i++) { - pre.appendChild(document.createTextNode(toprint[i])); - pre.appendChild(document.createElement('br')); - }; - this.outputelement.appendChild(pre); - }; - */ - if (exc.stack) { - // Moz (sometimes) - var lines = exc.stack.toString().split('\n'); - var toprint = []; // need to reverse this before outputting - for (var i=0; i < lines.length; i++) { - var line = lines[i]; - if (line.indexOf('ecmaunit.js') > -1) { - // remove useless bit of traceback - break; - }; - if (line[0] == '(') { - line = 'function' + line; - }; - line = line.split('@'); - toprint.push(line); - }; - toprint.reverse(); - var pre = this.document.createElement('pre'); - for (var i=0; i < toprint.length; i++) { - pre.appendChild( - this.document.createTextNode( - ' ' + toprint[i][1] + '\n ' + toprint[i][0] + '\n' - ) - ); - }; - pre.appendChild(document.createTextNode('\n')); - this.outputelement.appendChild(pre); + pre.appendChild( + this.document.createTextNode( + ' ' + toprint[i][1] + '\n ' + toprint[i][0] + '\n' + ) + ); }; + pre.appendChild(document.createTextNode('\n')); + this.outputelement.appendChild(pre); }; }; Modified: kukit/branch/plugin/tests/runner.html ============================================================================== --- kukit/branch/plugin/tests/runner.html (original) +++ kukit/branch/plugin/tests/runner.html Wed Apr 26 21:19:12 2006 @@ -16,9 +16,11 @@ + + Added: kukit/branch/plugin/tests/runtests.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/tests/runtests.js Wed Apr 26 21:19:12 2006 @@ -0,0 +1,24 @@ +/***************************************************************************** + * + * Copyright (c) 2003-2004 EcmaUnit Contributors. All rights reserved. + * + * This software is distributed under the terms of the EcmaUnit + * License. See LICENSE.txt for license text. For a list of EcmaUnit + * Contributors see CREDITS.txt. + * + *****************************************************************************/ + +// $Id: runtests.js 18718 2005-10-17 14:29:18Z duncan $ + +/* + Test runner for command-line environments, such as spidermonkey +*/ + +function runTests() { + var reporter = new StdoutReporter; + var testsuite = new TestSuite(reporter); + testsuite.registerTest(CssParserTestCase); + testsuite.runSuite(); +}; + +runTests(); Added: kukit/branch/plugin/tests/runtests.sh ============================================================================== --- (empty file) +++ kukit/branch/plugin/tests/runtests.sh Wed Apr 26 21:19:12 2006 @@ -0,0 +1 @@ +js -f ecmaunit.js -f testJrsParser.js -f ../kukit/jrs-parser.js runtests.js Added: kukit/branch/plugin/tests/testJrsParser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/tests/testJrsParser.js Wed Apr 26 21:19:12 2006 @@ -0,0 +1,139 @@ +function CssParserTestCase() { + this.name = 'CssParserTestCase'; + + this.setUp = function() { + /* not in use here, didn't have to define it but this might be + used as a reference + */ + }; + + this.testEmptyRule = function() { + var src = "#noneselector {}"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules) + }; + + this.testIdRule = function() { + var src = "#idselector {\n key: value; \n}\n"; + var rules = CssParser.parse(src); + this.assertTrue("#idselector" in rules); + } + + this.testSeveralSelectorRule = function() { + var src = "#noneselector {}\n\n#idselector {\n key: value; \n}\n"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules) + this.assertTrue("#idselector" in rules); + } + + this.testClassSelectorRule = function() { + var src = "#noneselector {}\n\n.classselector \n{key:value;}\n"; + var rules = CssParser.parse(src); + this.assertFalse("#noneselector" in rules); + this.assertTrue(".classselector" in rules); + } + + this.testTagSelectorRule = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n"; + var rules = CssParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testComments = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n\n/* comment outside */\n"; + var rules = CssParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testMultilineComments = function() { + var src = "/* multi\n line\n comment */tag { key: value }"; + var rules = CssParser.parse(src); + this.assertTrue("tag" in rules); + this.assertEquals(rules["tag"]["key"], "value"); + } + + this.testValidTagInComment = function() { + var src = "/*\n #commented-id {\n }\n*/"; + var rules = CssParser.parse(src); + this.assertFalse("#commented-id" in rules); + } + + this.testEmptyComment = function() { + var src = "tag/**/ {key:value}"; + var rules = CssParser.parse(src); + this.assertTrue("tag" in rules); + } + + this.testComplexComments = function() { + var src = "#property-id {\n key: value;\n key2 :value ; key3:value3;key4:/*comment*/value4;\n key5/*comment*/:value5;\n/*}*/\n key6/*fun:*/:value/*;*/6;\n}"; + var rules = CssParser.parse(src); + var rule = rules["#property-id"]; + for (var i in rule) { + switch (i) { + case "key": + this.assertEquals(rule[i], "value"); + break; + case "key2": + this.assertEquals(rule[i], "value"); + break; + case "key3": + this.assertEquals(rule[i], "value3"); + break; + case "key4": + this.assertEquals(rule[i], "value4"); + break; + case "key5": + this.assertEquals(rule[i], "value5"); + break; + case "key6": + this.assertEquals(rule[i], "value6"); + break; + default: + this.fail("unexpected property found: "+i); + } + } + } + + this.testParameterResetting = function() { + var src = ".class2 {\n key: value-old;\n key: value-new;\n}"; + var rules = CssParser.parse(src); + this.assertEquals(rules[".class2"]["key"], "value-new"); + } + + this.testMultipleSelectors = function() { + var src = "#id1, .class6, tag {\n key: value;\n}"; + var rules = CssParser.parse(src); + this.assertTrue("#id1, .class6, tag" in rules); + } + + this.testSpaceSeperatedSelectors = function() { + var src = "tag .class7 {\n key: value;\n}"; + var rules = CssParser.parse(src); + this.assertTrue("tag .class7" in rules); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class8,\n#id1 { key:value; }"; + var rules = CssParser.parse(src); + this.assertTrue("tag.class8, #id1" in rules); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class9\n,\n#id2\n{ key:value; }"; + var rules = CssParser.parse(src); + this.assertTrue("tag.class9, #id2" in rules); + } + + this.testMultipleDeclarationsSelectors = function() { + var src = "tag{key1:value1}\ntag{key2:value2}"; + var rules = CssParser.parse(src); + this.assertEquals(rules["tag"]["key1"], "value1"); + this.assertEquals(rules["tag"]["key2"], "value2"); + } +}; + +CssParserTestCase.prototype = new TestCase; + +if (typeof(testcase_registry) != 'undefined') { + testcase_registry.registerTestCase(CssParserTestCase, 'jrsparser'); +} From gotcha at codespeak.net Sun Apr 30 23:46:16 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:16 -0000 Subject: [Kukit-checkins] r26615 - in kukit: . branch/plugin/kukit Message-ID: <20060430214616.5B86E1007E@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:13 2006 New Revision: 26615 Modified: kukit/ (props changed) kukit/branch/plugin/kukit/kukit.js Log: r22992 at archipelago: ree | 2006-04-27 10:13:10 +0200 Adding python style method signature and definition to event types and actions. Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sun Apr 30 23:46:13 2006 @@ -39,7 +39,7 @@ } } -// max request nr +// max request number kukit.RequestManager.prototype.maxNr = 4; kukit.RequestManager.prototype.getInfo = function() { @@ -316,12 +316,11 @@ throw 'In case there are no actions, a parameter must be given'; } var defparams = {}; - defparams.type = 'remote'; - var action = new kukit.Action(arg, defparams); + var action = new kukit.Action('remote', [arg], defparams); actions[actions.length] = action; } - - result[result.length] = new kukit.EventRule(selector, params, actions); + + result[result.length] = new kukit.EventRule(params.type, selector, [], params, actions); } return result; @@ -343,12 +342,12 @@ throw "Type of action is empty!"; } // arg is optionally the text value - var arg = ''; + var args = []; if (action_node.firstChild) { - arg = action_node.firstChild.nodeValue; + args = [action_node.firstChild.nodeValue]; } // create the object - return new kukit.Action(arg, params); + return new kukit.Action(params.type, args, params); } kukit.RuleProcessor.prototype.parseRuleDom = function(domDocument) @@ -392,98 +391,156 @@ var nodes = cssQuery(eventrule.selector, node); for (var y=0; y < nodes.length; y++) { - var node = nodes[y]; - kukit.eventTypeRegistry.getFunc(eventrule.params.type)(eventrule, node); + eventrule.bind(nodes[y]); } } +/* Python-style args and parameters setup */ + +kukit.PythonMethodSignature = function(f_proto, f_defaults) { + // proto = a list of argnames + // default = a dict of default values + // + // e.g. + // sig = kukit.PythonMethodSignature(['a', 'b'], {'c': 1, 'd': 2}); + // sig.f_keywords(['x'], {'b': 'y', 'c': 'z'}) ==> {'a': 'x', 'b': 'y', 'c': 'z', 'd': 2} + // sig.f_keywords(['x', 'y', 'z'], {'b': 'y', 'c': 'z'}) ==> ERROR + // + this.f_proto = f_proto + this.f_defaults = f_defaults +} + +kukit.PythonMethodSignature.prototype.f_keywords = function(args, kw) { + var result = {}; + for (key in this.f_defaults) { + result[key] = this.f_defaults[key]; + } + for (key in kw) { + result[key] = kw[key]; + } + if (args.length < this.f_proto.length) { + for (var i = args.length; i < this.f_proto.length; i++) { + var key = this.f_proto[i]; + if (typeof(kw[key]) == 'undefined') { + throw 'Missing args in python-like method call"' + key + '"'; + } + } + } else if (args.length > this.f_proto.length) { + for (var i = this.f_proto.length; i < args.length; i++) {logDebug(i+'--'+args[i])}; + throw 'Excess args in python-like method call (' + args.length + ' > ' + this.f_proto.length + ')'; + } + for (var i = 0; i < args.length; i++) { + result[this.f_proto[i]] = args[i]; + } + return result; +} + /* EventRules and Actions: the objects that build up the rules */ kukit.EventRuleNr = 0; // just a counter -kukit.EventRule = function(selector, params, actions) +kukit.EventRule = function(type, selector, args, kw, actions) { this.nr = kukit.EventRuleNr; kukit.EventRuleNr = this.nr + 1; - kukit.logDebug("EventRule #"+this.nr+": "+selector+" "+params.name+" "+params.type+" "+params.lenght+" "+actions.length); + kukit.logDebug("EventRule #"+this.nr+": "+selector+" "+actions.length); + this.type = type; this.selector = selector; - this.params = params; + this.args = args; + this.kw = kw; this.actions = actions; } +kukit.EventRule.prototype.getNr = function() { + return this.nr; +} + +kukit.EventRule.prototype.bind = function(node) { + var entry = kukit.eventTypeRegistry.getReg(this.type); + if (typeof(entry) == 'undefined') { + throw 'Cannot lookup event rule "' + this.type + '"'; + } + entry.func(node, entry.sig.f_keywords(this.args, this.kw), this); +} + kukit.EventRule.prototype.executeActions = function(node) { for (var i=0; i Author: gotcha Date: Sun Apr 30 23:46:16 2006 New Revision: 26616 Modified: kukit/ (props changed) kukit/branch/plugin/kukit/kukit.js Log: r22994 at archipelago: ree | 2006-04-27 10:29:00 +0200 Name changes generic -> native, timeout -> millis Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sun Apr 30 23:46:16 2006 @@ -275,7 +275,7 @@ } // type is optional if (! params.type) { - params.type = 'generic'; + params.type = 'native'; } if (property_type == "") @@ -302,7 +302,7 @@ throw "Awaited url and timeout, got: "+arg; } else { arg = p[0]; - params.millis = p[1]; + params.delay = p[1]; } } } else if (property_type != "event") { @@ -544,7 +544,7 @@ /* Event handling */ -kukit.genericEventHandler = function(eventrule, e) { +kukit.nativeEventHandler = function(eventrule, e) { // this prevents the handler to be called on wrong elements, which // can happen because of propagation or bubbling // XXX this needs to be tested in all browsers @@ -596,8 +596,8 @@ /* Core events */ -kukit.eventTypeRegistry.register('generic', function (node, params, eventrule) { - func = MochiKit.Base.partial(kukit.genericEventHandler, eventrule); +kukit.eventTypeRegistry.register('native', function (node, params, eventrule) { + func = MochiKit.Base.partial(kukit.nativeEventHandler, eventrule); kukit.registerEventListener(node, params.name, func); }, new kukit.PythonMethodSignature(['name'], {}) @@ -620,7 +620,7 @@ kukit.timer_event_registry = {}; kukit.eventTypeRegistry.register("timeout", function (node, params, eventrule) { - var timeout = params.millis; + var timeout = params.delay; // XXX Timer key generation is changed. // XXX now key does not contain the methodname, // xxx instead it base on the rule itself. @@ -636,13 +636,13 @@ timer_event.func(); } }, - new kukit.PythonMethodSignature(['millis'], {}) + new kukit.PythonMethodSignature(['delay'], {}) ); kukit.eventTypeRegistry.register("cancelSubmitClick", function (node, params, eventrule) { var func = function(e) { if (!e) var e=window.event; - kukit.genericEventHandler(eventrule, e); + kukit.nativeEventHandler(eventrule, e); // Cancel default event // W3C style if (e.preventDefault) From gotcha at codespeak.net Sun Apr 30 23:46:24 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:24 -0000 Subject: [Kukit-checkins] r26617 - in kukit: . branch/plugin/kukit branch/plugin/tests Message-ID: <20060430214624.A27FE10082@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:19 2006 New Revision: 26617 Added: kukit/branch/plugin/kukit/kukit.BsParser.js kukit/branch/plugin/kukit/kukit.Parser.js kukit/branch/plugin/tests/kukit.BsParserTestCase.js (contents, props changed) Removed: kukit/branch/plugin/kukit/jrs-parser.js kukit/branch/plugin/tests/testJrsParser.js Modified: kukit/ (props changed) kukit/branch/plugin/tests/runtests.js Log: r23004 at archipelago: kaneda | 2006-04-27 18:28:55 +0200 Added the new renamed and working parser Deleted: /kukit/branch/plugin/kukit/jrs-parser.js ============================================================================== --- /kukit/branch/plugin/kukit/jrs-parser.js Sun Apr 30 23:46:19 2006 +++ (empty file) @@ -1,52 +0,0 @@ -CssParser = function() { -}; - -CssParser._rule_regexp = /((\s|.)*?)\{((\s|.)*?)\}/g; -CssParser._selector_regexp = /()/; - -CssParser.trim = function(str, chars) { - if (!chars) - chars='\\s' - return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); -} - -CssParser.parse = function(src) { - var rules = {}; - - // remove comments - src = src.replace(/\/\*(\s|.)*?\*\//g, ""); - - // split into rules - var rawrules = src.split('}'); - for (var i=0; rawrules.length; i++) { - if (!rawrules[i]) - break; - // split into selector and parameters - var parts = rawrules[i].split('{'); - // clean up selector - var selector = this.trim(parts[0]); - var selectorparts = selector.split(',') - for (var k=0; k 0) { + options.exit = parseoptions.exit; + } +} +kukit.BsParser.parseProperty = function(options) { + + var key = this.checkProperty(options.src.substring(0,options.pos)); + var properties = []; + var rest = options.src.substring(options.pos+1); + //print ("-- found property: "+key+" using rest "+rest); + parseroptions = kukit.Parser.parse(this, rest, properties, { + "(": this.parseMethodProperty, + " ": this.parseNextProperty, + ";": this.parsePropertyEnd, + "}": this.parsePropertyBlockEnd, + "\"": this.parseString, + "/*": this.parseComments + }); + //print ("-- found property: "+key+" value: "+properties); + options.src = parseroptions.src; + options.result[key] = properties; + //print("taking properties"+properties); + if (parseroptions.exit > 1) { + options.error = parseroptions.error; + options.exit = parseroptions.exit; + } +} +kukit.BsParser.parseNextProperty = function(options) { + this.addProperty(options, options.src.substring(0,options.pos)); + //print ("-- nice property:"+property); + options.src = options.src.substring(options.pos+1); +} +kukit.BsParser.parsePropertyBlockEnd = function(options) { + this.addProperty(options, options.src.substring(0,options.pos)); + //print ("-- nice property:"+property); + options.src = options.src.substring(options.pos); + options.exit = 0; +} +kukit.BsParser.parsePropertyEnd = function(options) { + //print ("-- property end by }"); + this.parseNextProperty(options); + options.exit = 0; +} +kukit.BsParser.addProperty = function(options, property) { + property = this.checkProperty(property); + if (property != "") { + options.result.push(property); + } +} +kukit.BsParser.parseMethodProperty = function(options) { + var methodName = options.src.substring(0,options.pos); + var value = [methodName]; + var properties = options.src.substring(options.pos+1); + print(methodName+" : "+properties); + parseoptions = kukit.Parser.parse(this, properties, value, { + "}": kukit.Parser.parserError("Method needs to be closed by )"), + ",": this.parseMethodPropertyEnd, + "\"": this.parseString, + "/*": this.parseComments, + ")": this.parseMethodEnd + }); + options.result.push(value); + options.src = parseoptions.src; +} +kukit.BsParser.parseMethodPropertyEnd = function(options) { + var name = kukit.Parser.trim(options.src.substring(0,options.pos)); + if (name != "") { + options.result.push(name); + } + options.src = options.src.substring(options.pos+1); +} +kukit.BsParser.parseMethodEnd = function(options) { + this.parseMethodPropertyEnd(options); + options.exit = 0; +} +kukit.BsParser.parseString = function(options) { + var content = ""; + var src = options.src.substring(options.pos+1); + var pos = src.indexOf("\""); + //print("---- string content before: "+src); + while (pos >= 0) { + content = src.substring(0, pos); + src = src.substring(pos+1); + if (src.charAt(pos-1) != "\\" || src.charAt(pos-2) != "\\") { + break; + } + content += "\""; + pos = src.indexOf("\""); + } + //print("---- string content "+content); + options.src = options.src.substring(0, options.pos)+options.src.substring(options.pos+content.length+2); + options.result.push(this.checkProperty(content)); +} +kukit.BsParser.parseBlockEnd = function(options) { + print("block end"); + options.src = options.src.substring(options.pos+1); + options.exit = 0; +} +kukit.BsParser.checkProperty = function(property) { + property = kukit.Parser.trim(property); + property = property.split("\\n").join("\n"); + property = property.split("\\t").join("\t"); + property = property.split("\\b").join("\b"); + property = property.split("\\b").join("\b"); + return property; +} Added: kukit/branch/plugin/kukit/kukit.Parser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.Parser.js Sun Apr 30 23:46:19 2006 @@ -0,0 +1,58 @@ +if(typeof kukit == "undefined") { + kukit = {}; +} +kukit.Parser = function() { +} + +kukit.Parser.trim = function(str, chars) { + if (!chars) + chars='\\s\\n\\r' + return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); +} +kukit.Parser.parse = function(scope, src, result, subparsers) { + //print("parsing "+src); + var options = {scope: scope, src:src, result:result, subparsers:subparsers, exit: -1}; + while (this.getNext(options) && options.exit == -1); + //print("end of parsing"); + return options; +} +kukit.Parser.errors = {}; +kukit.Parser.parserError = function(error) { + errormethod = this.errors[error]; + if (!errormethod) { + errormethod = function(options) { + options.error = error; + options.exit = 1; + } + } + return errormethod; +} +kukit.Parser.getNext = function(options) { + var next = -1; + var parser; + var parsername; + //print("> state"+options.exit); + for (var i in options.subparsers) { + var pos = options.src.indexOf(i); + //print("> taking parser for "+i+" at "+pos+" next is "+next); + if ((pos < next || next == -1) && pos != -1) { + next = pos; + parsername = i; + //print(">> found "+i+" at "+pos); + parser = options.subparsers[i]; + } + } + options.pos = next; + if (parser) { + //print(">> found "+parsername+" for "+options.src+" function "+parser); + options.scope["__parseMethod"]= parser; + try { + options.scope["__parseMethod"](options); + } catch(e) { + options.error = e; + options.exit = 2; + print(e); + } + } + return (next >=0); +} \ No newline at end of file Added: kukit/branch/plugin/tests/kukit.BsParserTestCase.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/tests/kukit.BsParserTestCase.js Sun Apr 30 23:46:19 2006 @@ -0,0 +1,229 @@ +if (typeof kukit == "undefined") { + kukit = {}; +} +kukit.BsParserTestCase = function() { + this.name = 'kukit.BsParserTestCase'; + + this.setUp = function() { + /* not in use here, didn't have to define it but this might be + used as a reference + */ + }; + + this.testEmptyRule = function() { + var src = "#noneselector {}"; + var rules = kukit.BsParser.parse(src); + this.assertFalse("#noneselector" in rules) + }; + + this.testIdRule = function() { + var src = "#idselector {\n key: value; \n}\n"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("#idselector" in rules); + } + + this.testSeveralSelectorRule = function() { + var src = "#noneselector {}\n\n#idselector {\n key: value; \n}\n"; + var rules = kukit.BsParser.parse(src); + this.assertFalse("#noneselector" in rules) + this.assertTrue("#idselector" in rules); + } + + this.testClassSelectorRule = function() { + var src = "#noneselector {}\n\n.classselector \n{key:value;}\n"; + var rules = kukit.BsParser.parse(src); + this.assertFalse("#noneselector" in rules); + this.assertTrue(".classselector" in rules); + } + + this.testTagSelectorRule = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testComments = function() { + var src = "tagselector{\n /* comment */\n key:value;\n}\n\n/* comment outside */\n"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("tagselector" in rules); + } + + this.testMultilineComments = function() { + var src = "/* multi\n line\n comment */tag { key: value }"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("tag" in rules); + this.assertEquals(rules["tag"]["key"][0], "value"); + } + + this.testValidTagInComment = function() { + var src = "/*\n #commented-id {\n }\n*/"; + var rules = kukit.BsParser.parse(src); + this.assertFalse("#commented-id" in rules); + } + + this.testEmptyComment = function() { + var src = "tag/**/ {key:value}"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("tag" in rules); + } + + this.testComplexComments = function() { + var src = "#property-id {\n key1: value1;\n key2 :value2 ; key3:value3;key4:/*comment*/value4;\n key5/*comment*/:value5;\n/*}*/\n key6/*fun:*/:value/*;*/6;\n}"; + var rules = kukit.BsParser.parse(src); + var rule = rules["#property-id"]; + for (var i in rule) { + switch (i) { + case "key1": + this.assertEquals(rule[i][0], "value1"); + break; + case "key2": + this.assertEquals(rule[i][0], "value2"); + break; + case "key3": + this.assertEquals(rule[i][0], "value3"); + break; + case "key4": + this.assertEquals(rule[i][0], "value4"); + break; + case "key5": + this.assertEquals(rule[i][0], "value5"); + break; + case "key6": + this.assertEquals(rule[i][0], "value6"); + break; + default: + print("FAIL: unexpected property found: "+i); + } + } + } + + this.testParameterResetting = function() { + var src = ".class2 {\n key: value-old;\n key: value-new;\n}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules[".class2"]["key"][0], "value-new"); + } + + this.testMultipleSelectors = function() { + var src = "#id1, .class6, tag {\n key: value;\n}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["#id1"]["key"][0], "value"); + this.assertEquals(rules[".class6"]["key"][0], "value"); + this.assertEquals(rules["tag"]["key"][0], "value"); + } + + this.testSpaceSeperatedSelectors = function() { + var src = "tag .class7 {\n key: value;\n}"; + var rules = kukit.BsParser.parse(src); + this.assertTrue("tag .class7" in rules); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class8,\n#id1 { key:value; }"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag.class8"]["key"][0], "value"); + this.assertEquals(rules["#id1"]["key"][0], "value"); + } + + this.testReturnSeperatedSelectors = function() { + var src = "tag.class9\n,\n#id2\n{ key:value; }"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag.class9"]["key"][0], "value"); + this.assertEquals(rules["#id2"]["key"][0], "value"); + } + + this.testMultipleDeclarationsSelectors = function() { + var src = "tag {key1:value1}\ntag{key2:value2}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key1"][0], "value1"); + this.assertEquals(rules["tag"]["key2"][0], "value2"); + } + + this.testMulitpleDeclarationsAndMultipleSelectors = function() { + var src = "tag, anotherTag{key1:value1}\ntag{key2:value2}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key1"][0], "value1"); + this.assertEquals(rules["anotherTag"]["key1"][0], "value1"); + this.assertEquals(rules["tag"]["key2"][0], "value2"); + this.assertFalse("key2" in rules["anotherTag"]); + } + + this.testMultipleValues = function() { + var src = "tag{key:value1 value2;}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0], "value1"); + this.assertEquals(rules["tag"]["key"][1], "value2"); + } + + this.testStringValue = function() { + var src = "tag{key:\"value1 is big\";}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0], "value1 is big"); + } + + this.testCommentedStringValue = function() { + var src = "tag{key:\"value1 /* is bi*/g\";}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0], "value1 /* is bi*/g"); + } + + this.testMultipleStringValues = function() { + var src = "tag{key:\"value1 is big\" value2;}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0], "value1 is big"); + this.assertEquals(rules["tag"]["key"][1], "value2"); + } + + this.testEmptyValueParameters = function() { + var src = "tag{key:value1();}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0][0], "value1"); + } + + this.testFilledValueParameters = function() { + var src = "tag{key:value1(temp1, temp2, temp3) value2;}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0][0], "value1"); + this.assertEquals(rules["tag"]["key"][0][1], "temp1"); + this.assertEquals(rules["tag"]["key"][0][2], "temp2"); + this.assertEquals(rules["tag"]["key"][1], "value2"); + } + + this.testNumberValue = function() { + var src = "tag{key:1}"; + var rules = kukit.BsParser.parse(src); + this.assertEquals(rules["tag"]["key"][0], 1); + } + + this.testTimeoutParsing = function() { + var src = "#calendar-previous a:click(cancelSubmit=True) {\n" + +" remote: kukitresponse/kukitGetPreviousMonth;\n"+ + +"}\n" + +"div#update-area:timeout(millis=2000) {\n" + +" effect: fade; \n" + +" remote: getCurrentTime;\n" + +"}\n" + +"#calendar-previous a:leave(cancelSubmit=True) {\n" + +" remote: kukitresponse/kukitPreviousMonth;\n" + +"}\" + +"button#change:startdrag {\n remote: getDivContent(fgh, foo=bar) getSlowOne(fgd);\n log: \"WE LOG from getDivContent\";}"; + var rules = kukit.BsParser.parse(src); + + this.assertEquals(rules["#calendar-previous a:click(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitGetPreviousMonth"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"]["effect"][0], "fade"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"]["remote"][0], "getCurrentTime"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitPreviousMonth"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitPreviousMonth"); + this.assertEquals(rules["button#change:startdrag"]["remote"][0][0], "getDivContent"); + this.assertEquals(rules["button#change:startdrag"]["remote"][0][1], "fgh"); + this.assertEquals(rules["button#change:startdrag"]["remote"][0][2], "foo=bar"); + this.assertEquals(rules["button#change:startdrag"]["remote"][1][0], "getSlowOne"); + this.assertEquals(rules["button#change:startdrag"]["remote"][1][1], "fgd"); + this.assertEquals(rules["button#change:startdrag"]["log"][0], "WE LOG from getDivContent"); + } +}; + +kukit.BsParserTestCase.prototype = new TestCase; + +if (typeof(testcase_registry) != 'undefined') { + testcase_registry.registerTestCase(kukit.BsParserTestCase, 'jrsparser'); +} Modified: kukit/branch/plugin/tests/runtests.js ============================================================================== --- kukit/branch/plugin/tests/runtests.js (original) +++ kukit/branch/plugin/tests/runtests.js Sun Apr 30 23:46:19 2006 @@ -17,7 +17,7 @@ function runTests() { var reporter = new StdoutReporter; var testsuite = new TestSuite(reporter); - testsuite.registerTest(CssParserTestCase); + testsuite.registerTest(kukit.BsParserTestCase); testsuite.runSuite(); }; Deleted: /kukit/branch/plugin/tests/testJrsParser.js ============================================================================== --- /kukit/branch/plugin/tests/testJrsParser.js Sun Apr 30 23:46:19 2006 +++ (empty file) @@ -1,139 +0,0 @@ -function CssParserTestCase() { - this.name = 'CssParserTestCase'; - - this.setUp = function() { - /* not in use here, didn't have to define it but this might be - used as a reference - */ - }; - - this.testEmptyRule = function() { - var src = "#noneselector {}"; - var rules = CssParser.parse(src); - this.assertFalse("#noneselector" in rules) - }; - - this.testIdRule = function() { - var src = "#idselector {\n key: value; \n}\n"; - var rules = CssParser.parse(src); - this.assertTrue("#idselector" in rules); - } - - this.testSeveralSelectorRule = function() { - var src = "#noneselector {}\n\n#idselector {\n key: value; \n}\n"; - var rules = CssParser.parse(src); - this.assertFalse("#noneselector" in rules) - this.assertTrue("#idselector" in rules); - } - - this.testClassSelectorRule = function() { - var src = "#noneselector {}\n\n.classselector \n{key:value;}\n"; - var rules = CssParser.parse(src); - this.assertFalse("#noneselector" in rules); - this.assertTrue(".classselector" in rules); - } - - this.testTagSelectorRule = function() { - var src = "tagselector{\n /* comment */\n key:value;\n}\n"; - var rules = CssParser.parse(src); - this.assertTrue("tagselector" in rules); - } - - this.testComments = function() { - var src = "tagselector{\n /* comment */\n key:value;\n}\n\n/* comment outside */\n"; - var rules = CssParser.parse(src); - this.assertTrue("tagselector" in rules); - } - - this.testMultilineComments = function() { - var src = "/* multi\n line\n comment */tag { key: value }"; - var rules = CssParser.parse(src); - this.assertTrue("tag" in rules); - this.assertEquals(rules["tag"]["key"], "value"); - } - - this.testValidTagInComment = function() { - var src = "/*\n #commented-id {\n }\n*/"; - var rules = CssParser.parse(src); - this.assertFalse("#commented-id" in rules); - } - - this.testEmptyComment = function() { - var src = "tag/**/ {key:value}"; - var rules = CssParser.parse(src); - this.assertTrue("tag" in rules); - } - - this.testComplexComments = function() { - var src = "#property-id {\n key: value;\n key2 :value ; key3:value3;key4:/*comment*/value4;\n key5/*comment*/:value5;\n/*}*/\n key6/*fun:*/:value/*;*/6;\n}"; - var rules = CssParser.parse(src); - var rule = rules["#property-id"]; - for (var i in rule) { - switch (i) { - case "key": - this.assertEquals(rule[i], "value"); - break; - case "key2": - this.assertEquals(rule[i], "value"); - break; - case "key3": - this.assertEquals(rule[i], "value3"); - break; - case "key4": - this.assertEquals(rule[i], "value4"); - break; - case "key5": - this.assertEquals(rule[i], "value5"); - break; - case "key6": - this.assertEquals(rule[i], "value6"); - break; - default: - this.fail("unexpected property found: "+i); - } - } - } - - this.testParameterResetting = function() { - var src = ".class2 {\n key: value-old;\n key: value-new;\n}"; - var rules = CssParser.parse(src); - this.assertEquals(rules[".class2"]["key"], "value-new"); - } - - this.testMultipleSelectors = function() { - var src = "#id1, .class6, tag {\n key: value;\n}"; - var rules = CssParser.parse(src); - this.assertTrue("#id1, .class6, tag" in rules); - } - - this.testSpaceSeperatedSelectors = function() { - var src = "tag .class7 {\n key: value;\n}"; - var rules = CssParser.parse(src); - this.assertTrue("tag .class7" in rules); - } - - this.testReturnSeperatedSelectors = function() { - var src = "tag.class8,\n#id1 { key:value; }"; - var rules = CssParser.parse(src); - this.assertTrue("tag.class8, #id1" in rules); - } - - this.testReturnSeperatedSelectors = function() { - var src = "tag.class9\n,\n#id2\n{ key:value; }"; - var rules = CssParser.parse(src); - this.assertTrue("tag.class9, #id2" in rules); - } - - this.testMultipleDeclarationsSelectors = function() { - var src = "tag{key1:value1}\ntag{key2:value2}"; - var rules = CssParser.parse(src); - this.assertEquals(rules["tag"]["key1"], "value1"); - this.assertEquals(rules["tag"]["key2"], "value2"); - } -}; - -CssParserTestCase.prototype = new TestCase; - -if (typeof(testcase_registry) != 'undefined') { - testcase_registry.registerTestCase(CssParserTestCase, 'jrsparser'); -} From gotcha at codespeak.net Sun Apr 30 23:46:26 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:26 -0000 Subject: [Kukit-checkins] r26618 - in kukit: . branch/plugin branch/plugin/tests Message-ID: <20060430214626.C43A710080@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:24 2006 New Revision: 26618 Added: kukit/branch/plugin/tests.bat Modified: kukit/ (props changed) kukit/branch/plugin/tests/kukit.BsParserTestCase.js Log: r23005 at archipelago: kaneda | 2006-04-27 18:40:46 +0200 * removed typo Added: kukit/branch/plugin/tests.bat ============================================================================== --- (empty file) +++ kukit/branch/plugin/tests.bat Sun Apr 30 23:46:24 2006 @@ -0,0 +1 @@ +java -cp ../rhino1_6R2/js.jar org.mozilla.javascript.tools.shell.Main -f tests/ecmaunit.js -f kukit/kukit.Parser.js -f kukit/kukit.BsParser.js -f tests/kukit.BsParserTestCase.js -f tests/runtests.js \ No newline at end of file Modified: kukit/branch/plugin/tests/kukit.BsParserTestCase.js ============================================================================== --- kukit/branch/plugin/tests/kukit.BsParserTestCase.js (original) +++ kukit/branch/plugin/tests/kukit.BsParserTestCase.js Sun Apr 30 23:46:24 2006 @@ -204,7 +204,7 @@ +"}\n" +"#calendar-previous a:leave(cancelSubmit=True) {\n" +" remote: kukitresponse/kukitPreviousMonth;\n" - +"}\" + +"}\n" +"button#change:startdrag {\n remote: getDivContent(fgh, foo=bar) getSlowOne(fgd);\n log: \"WE LOG from getDivContent\";}"; var rules = kukit.BsParser.parse(src); From gotcha at codespeak.net Sun Apr 30 23:46:29 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:29 -0000 Subject: [Kukit-checkins] r26619 - in kukit: . branch/plugin/tests Message-ID: <20060430214629.84D001008B@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:27 2006 New Revision: 26619 Modified: kukit/ (props changed) kukit/branch/plugin/tests/kukit.BsParserTestCase.js Log: r23006 at archipelago: kaneda | 2006-04-27 18:41:43 +0200 * typos ... Modified: kukit/branch/plugin/tests/kukit.BsParserTestCase.js ============================================================================== --- kukit/branch/plugin/tests/kukit.BsParserTestCase.js (original) +++ kukit/branch/plugin/tests/kukit.BsParserTestCase.js Sun Apr 30 23:46:27 2006 @@ -196,7 +196,7 @@ this.testTimeoutParsing = function() { var src = "#calendar-previous a:click(cancelSubmit=True) {\n" - +" remote: kukitresponse/kukitGetPreviousMonth;\n"+ + +" remote: kukitresponse/kukitGetPreviousMonth;\n" +"}\n" +"div#update-area:timeout(millis=2000) {\n" +" effect: fade; \n" From gotcha at codespeak.net Sun Apr 30 23:46:33 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:33 -0000 Subject: [Kukit-checkins] r26620 - in kukit: . branch/plugin branch/plugin/kukit branch/plugin/tests Message-ID: <20060430214633.3161010087@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:30 2006 New Revision: 26620 Modified: kukit/ (props changed) kukit/branch/plugin/kukit/kukit.BsParser.js kukit/branch/plugin/tests.bat kukit/branch/plugin/tests/kukit.BsParserTestCase.js Log: r23010 at archipelago: kaneda | 2006-04-28 00:05:29 +0200 * Added method support in classmanager Modified: kukit/branch/plugin/kukit/kukit.BsParser.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.BsParser.js (original) +++ kukit/branch/plugin/kukit/kukit.BsParser.js Sun Apr 30 23:46:30 2006 @@ -28,7 +28,7 @@ "/*": this.parseComments }); - print("result: "+result); + //print("result: "+result); return result; } kukit.BsParser.WHITE_SPACES = " \t"; @@ -56,13 +56,43 @@ var rawselectors = src.substring(0, options.pos).split(","); var selectors = {}; for (var i=0; i -1) { + selectorinfos.selector = rawselector.substring(0,seperatorpos); + var temp = []; + var parserresult = kukit.Parser.parse(this, rawselector.substring(seperatorpos+1), temp, { + "(": this.parseMethodProperty + }); + if(temp[0]) + temp = temp[0]; // take first element if some got found + + for (var j=0; j "+selector.toString()); + + var properties = options.result[selectorinfos.toString()]; if (!properties) { - properties = {}; + properties = selectorinfos; } - selectors[selector] = properties; - } + selectors[selectorinfos.toString()] = properties; + } //print ("- parseBlock: "+options.src+" at "+options.pos); //print ("- rawselectors: "+rawselectors); @@ -82,7 +112,7 @@ for (var i in selectors) { for (var j in content) { gotcontent = true; - selectors[i][j] = content[j]; + selectors[i].properties[j] = content[j]; } if (gotcontent) { options.result[i] = selectors[i]; @@ -146,7 +176,7 @@ var methodName = options.src.substring(0,options.pos); var value = [methodName]; var properties = options.src.substring(options.pos+1); - print(methodName+" : "+properties); + //print(methodName+" : "+properties); parseoptions = kukit.Parser.parse(this, properties, value, { "}": kukit.Parser.parserError("Method needs to be closed by )"), ",": this.parseMethodPropertyEnd, @@ -187,7 +217,7 @@ options.result.push(this.checkProperty(content)); } kukit.BsParser.parseBlockEnd = function(options) { - print("block end"); + //print("block end"); options.src = options.src.substring(options.pos+1); options.exit = 0; } Modified: kukit/branch/plugin/tests.bat ============================================================================== --- kukit/branch/plugin/tests.bat (original) +++ kukit/branch/plugin/tests.bat Sun Apr 30 23:46:30 2006 @@ -1 +1 @@ -java -cp ../rhino1_6R2/js.jar org.mozilla.javascript.tools.shell.Main -f tests/ecmaunit.js -f kukit/kukit.Parser.js -f kukit/kukit.BsParser.js -f tests/kukit.BsParserTestCase.js -f tests/runtests.js \ No newline at end of file +java -cp ../rhino1_6R2/js.jar org.mozilla.javascript.tools.shell.Main -f tests/ecmaunit.js -f kukit/kukit.Parser.js -f kukit/kukit.BsParser.js -f kukit/kukit.BsParserSelectorElement.js -f tests/kukit.BsParserTestCase.js -f tests/runtests.js \ No newline at end of file Modified: kukit/branch/plugin/tests/kukit.BsParserTestCase.js ============================================================================== --- kukit/branch/plugin/tests/kukit.BsParserTestCase.js (original) +++ kukit/branch/plugin/tests/kukit.BsParserTestCase.js Sun Apr 30 23:46:30 2006 @@ -52,7 +52,7 @@ var src = "/* multi\n line\n comment */tag { key: value }"; var rules = kukit.BsParser.parse(src); this.assertTrue("tag" in rules); - this.assertEquals(rules["tag"]["key"][0], "value"); + this.assertEquals(rules["tag"].properties["key"][0], "value"); } this.testValidTagInComment = function() { @@ -70,26 +70,26 @@ this.testComplexComments = function() { var src = "#property-id {\n key1: value1;\n key2 :value2 ; key3:value3;key4:/*comment*/value4;\n key5/*comment*/:value5;\n/*}*/\n key6/*fun:*/:value/*;*/6;\n}"; var rules = kukit.BsParser.parse(src); - var rule = rules["#property-id"]; - for (var i in rule) { + var properties = rules["#property-id"].properties; + for (var i in properties) { switch (i) { case "key1": - this.assertEquals(rule[i][0], "value1"); + this.assertEquals(properties[i][0], "value1"); break; case "key2": - this.assertEquals(rule[i][0], "value2"); + this.assertEquals(properties[i][0], "value2"); break; case "key3": - this.assertEquals(rule[i][0], "value3"); + this.assertEquals(properties[i][0], "value3"); break; case "key4": - this.assertEquals(rule[i][0], "value4"); + this.assertEquals(properties[i][0], "value4"); break; case "key5": - this.assertEquals(rule[i][0], "value5"); + this.assertEquals(properties[i][0], "value5"); break; case "key6": - this.assertEquals(rule[i][0], "value6"); + this.assertEquals(properties[i][0], "value6"); break; default: print("FAIL: unexpected property found: "+i); @@ -100,15 +100,15 @@ this.testParameterResetting = function() { var src = ".class2 {\n key: value-old;\n key: value-new;\n}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules[".class2"]["key"][0], "value-new"); + this.assertEquals(rules[".class2"].properties["key"][0], "value-new"); } this.testMultipleSelectors = function() { var src = "#id1, .class6, tag {\n key: value;\n}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["#id1"]["key"][0], "value"); - this.assertEquals(rules[".class6"]["key"][0], "value"); - this.assertEquals(rules["tag"]["key"][0], "value"); + this.assertEquals(rules["#id1"].properties["key"][0], "value"); + this.assertEquals(rules[".class6"].properties["key"][0], "value"); + this.assertEquals(rules["tag"].properties["key"][0], "value"); } this.testSpaceSeperatedSelectors = function() { @@ -120,78 +120,78 @@ this.testReturnSeperatedSelectors = function() { var src = "tag.class8,\n#id1 { key:value; }"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag.class8"]["key"][0], "value"); - this.assertEquals(rules["#id1"]["key"][0], "value"); + this.assertEquals(rules["tag.class8"].properties["key"][0], "value"); + this.assertEquals(rules["#id1"].properties["key"][0], "value"); } this.testReturnSeperatedSelectors = function() { var src = "tag.class9\n,\n#id2\n{ key:value; }"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag.class9"]["key"][0], "value"); - this.assertEquals(rules["#id2"]["key"][0], "value"); + this.assertEquals(rules["tag.class9"].properties["key"][0], "value"); + this.assertEquals(rules["#id2"].properties["key"][0], "value"); } this.testMultipleDeclarationsSelectors = function() { var src = "tag {key1:value1}\ntag{key2:value2}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key1"][0], "value1"); - this.assertEquals(rules["tag"]["key2"][0], "value2"); + this.assertEquals(rules["tag"].properties["key1"][0], "value1"); + this.assertEquals(rules["tag"].properties["key2"][0], "value2"); } this.testMulitpleDeclarationsAndMultipleSelectors = function() { var src = "tag, anotherTag{key1:value1}\ntag{key2:value2}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key1"][0], "value1"); - this.assertEquals(rules["anotherTag"]["key1"][0], "value1"); - this.assertEquals(rules["tag"]["key2"][0], "value2"); + this.assertEquals(rules["tag"].properties["key1"][0], "value1"); + this.assertEquals(rules["anotherTag"].properties["key1"][0], "value1"); + this.assertEquals(rules["tag"].properties["key2"][0], "value2"); this.assertFalse("key2" in rules["anotherTag"]); } this.testMultipleValues = function() { var src = "tag{key:value1 value2;}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0], "value1"); - this.assertEquals(rules["tag"]["key"][1], "value2"); + this.assertEquals(rules["tag"].properties["key"][0], "value1"); + this.assertEquals(rules["tag"].properties["key"][1], "value2"); } this.testStringValue = function() { var src = "tag{key:\"value1 is big\";}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0], "value1 is big"); + this.assertEquals(rules["tag"].properties["key"][0], "value1 is big"); } this.testCommentedStringValue = function() { var src = "tag{key:\"value1 /* is bi*/g\";}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0], "value1 /* is bi*/g"); + this.assertEquals(rules["tag"].properties["key"][0], "value1 /* is bi*/g"); } this.testMultipleStringValues = function() { var src = "tag{key:\"value1 is big\" value2;}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0], "value1 is big"); - this.assertEquals(rules["tag"]["key"][1], "value2"); + this.assertEquals(rules["tag"].properties["key"][0], "value1 is big"); + this.assertEquals(rules["tag"].properties["key"][1], "value2"); } this.testEmptyValueParameters = function() { var src = "tag{key:value1();}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0][0], "value1"); + this.assertEquals(rules["tag"].properties["key"][0][0], "value1"); } this.testFilledValueParameters = function() { var src = "tag{key:value1(temp1, temp2, temp3) value2;}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0][0], "value1"); - this.assertEquals(rules["tag"]["key"][0][1], "temp1"); - this.assertEquals(rules["tag"]["key"][0][2], "temp2"); - this.assertEquals(rules["tag"]["key"][1], "value2"); + this.assertEquals(rules["tag"].properties["key"][0][0], "value1"); + this.assertEquals(rules["tag"].properties["key"][0][1], "temp1"); + this.assertEquals(rules["tag"].properties["key"][0][2], "temp2"); + this.assertEquals(rules["tag"].properties["key"][1], "value2"); } this.testNumberValue = function() { var src = "tag{key:1}"; var rules = kukit.BsParser.parse(src); - this.assertEquals(rules["tag"]["key"][0], 1); + this.assertEquals(rules["tag"].properties["key"][0], 1); } this.testTimeoutParsing = function() { @@ -207,23 +207,29 @@ +"}\n" +"button#change:startdrag {\n remote: getDivContent(fgh, foo=bar) getSlowOne(fgd);\n log: \"WE LOG from getDivContent\";}"; var rules = kukit.BsParser.parse(src); - - this.assertEquals(rules["#calendar-previous a:click(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitGetPreviousMonth"); - this.assertEquals(rules["div#update-area:timeout(millis=2000)"]["effect"][0], "fade"); - this.assertEquals(rules["div#update-area:timeout(millis=2000)"]["remote"][0], "getCurrentTime"); - this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitPreviousMonth"); - this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"]["remote"][0], "kukitresponse/kukitPreviousMonth"); - this.assertEquals(rules["button#change:startdrag"]["remote"][0][0], "getDivContent"); - this.assertEquals(rules["button#change:startdrag"]["remote"][0][1], "fgh"); - this.assertEquals(rules["button#change:startdrag"]["remote"][0][2], "foo=bar"); - this.assertEquals(rules["button#change:startdrag"]["remote"][1][0], "getSlowOne"); - this.assertEquals(rules["button#change:startdrag"]["remote"][1][1], "fgd"); - this.assertEquals(rules["button#change:startdrag"]["log"][0], "WE LOG from getDivContent"); + this.assertEquals(rules["#calendar-previous a:click(cancelSubmit=True)"].type.name, "click"); + this.assertEquals(rules["#calendar-previous a:click(cancelSubmit=True)"].type.properties[0], "cancelSubmit=True"); + this.assertEquals(rules["#calendar-previous a:click(cancelSubmit=True)"].properties["remote"][0], "kukitresponse/kukitGetPreviousMonth"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"].type.name, "timeout"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"].type.properties[0], "millis=2000"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"].properties["effect"][0], "fade"); + this.assertEquals(rules["div#update-area:timeout(millis=2000)"].properties["remote"][0], "getCurrentTime"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"].type.name, "leave"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"].type.properties[0], "cancelSubmit=True"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"].properties["remote"][0], "kukitresponse/kukitPreviousMonth"); + this.assertEquals(rules["#calendar-previous a:leave(cancelSubmit=True)"].properties["remote"][0], "kukitresponse/kukitPreviousMonth"); + this.assertEquals(rules["button#change:startdrag()"].type.name, "startdrag"); + this.assertEquals(rules["button#change:startdrag()"].properties["remote"][0][0], "getDivContent"); + this.assertEquals(rules["button#change:startdrag()"].properties["remote"][0][1], "fgh"); + this.assertEquals(rules["button#change:startdrag()"].properties["remote"][0][2], "foo=bar"); + this.assertEquals(rules["button#change:startdrag()"].properties["remote"][1][0], "getSlowOne"); + this.assertEquals(rules["button#change:startdrag()"].properties["remote"][1][1], "fgd"); + this.assertEquals(rules["button#change:startdrag()"].properties["log"][0], "WE LOG from getDivContent"); } }; kukit.BsParserTestCase.prototype = new TestCase; if (typeof(testcase_registry) != 'undefined') { - testcase_registry.registerTestCase(kukit.BsParserTestCase, 'jrsparser'); + testcase_registry.registerTestCase(kukit.BsParserTestCase, 'kukit.BSParserTestCase'); } From gotcha at codespeak.net Sun Apr 30 23:46:37 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:37 -0000 Subject: [Kukit-checkins] r26621 - in kukit: . branch/plugin/kukit Message-ID: <20060430214637.7D6AF1008B@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:34 2006 New Revision: 26621 Added: kukit/branch/plugin/kukit/kukit.BsParserSelectorElement.js Modified: kukit/ (props changed) Log: r23011 at archipelago: kaneda | 2006-04-28 00:11:33 +0200 * Added class for holding selector informations Added: kukit/branch/plugin/kukit/kukit.BsParserSelectorElement.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.BsParserSelectorElement.js Sun Apr 30 23:46:34 2006 @@ -0,0 +1,29 @@ +if(typeof kukit == "undefined") { + kukit = {}; +} +kukit.BsParserSelectorElement = function() { + this.properties = {}; + this.type = {}; + this.selector = ""; +} +kukit.BsParserSelectorElement.prototype.toString = function() { + var result = this.selector; + + if (this.type.name) { + //print("name: "+this.selector); + result += ":"+this.type.name; + result += "(" + + if (this.type.properties) { + for (var i=0; i< this.type.properties.length; i++) { + + if (i != 0) + result += ","; + + result += this.type.properties[i]; + } + } + result += ")"; + } + return result +} \ No newline at end of file From gotcha at codespeak.net Sun Apr 30 23:46:45 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:45 -0000 Subject: [Kukit-checkins] r26622 - in kukit: . branch/plugin/kukit Message-ID: <20060430214645.CCD3B1009B@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:38 2006 New Revision: 26622 Modified: kukit/ (props changed) kukit/branch/plugin/kukit/kukit.js Log: r23058 at archipelago: ree | 2006-04-28 20:08:16 +0200 Adding replaceNode command + fixed notifyServerWithParams Modified: kukit/branch/plugin/kukit/kukit.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.js (original) +++ kukit/branch/plugin/kukit/kukit.js Sun Apr 30 23:46:38 2006 @@ -851,6 +851,12 @@ // make a deferred callback var domDoc = new XMLHttpRequest(); notifyServer_done = MochiKit.Base.partial(kukit.notifyServer_done, domDoc); + // convert params + var query = new kukit.FormQuery(); + for (var key in params) { + query.appendElem(key, params[key]); + } + var encoded = query.encode(); // sending form var ts = new Date().getTime(); kukit.logDebug('TS: '+ts); @@ -858,7 +864,7 @@ domDoc.open("POST", tsurl, true); domDoc.onreadystatechange = notifyServer_done; domDoc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - domDoc.send(params); + domDoc.send(encoded); } kukit.notifyServer_done = function(domDoc) @@ -1145,6 +1151,30 @@ kukit.setupEvents(node); }) +kukit.commandRegistry.register('replaceNode', function(node, command_data) + { + var childNodes = command_data['html'].childNodes; + var sourceSelector = command_data['selector'].firstChild.nodeValue || null; + var parentNode = node.parentNode; + var newNode = parentNode.cloneNode(false); + try { + kukit.dom.appendChildren(childNodes, newNode); + } catch(exc) { + newNode.innerHTML = Sarissa.serialize(command_data['html']); + } + if (sourceSelector) { + var element = cssQuery(sourceSelector, newNode)[0]; + if (element) + parentNode.replaceChild(element, node); + else + kukit.logDebug("Found no elements in response with selector '"+sourceSelector+"'."); + } else { + parentNode.replaceChild(newNode.firstChild, node); + } + kukit.setupEvents(parentNode); + } +) + kukit.commandRegistry.register('setAttribute', function(node, command_data) { From gotcha at codespeak.net Sun Apr 30 23:46:46 2006 From: gotcha at codespeak.net (gotcha at codespeak.net) Date: Sun, 30 Apr 2006 21:46:46 -0000 Subject: [Kukit-checkins] r26623 - in kukit: . branch/plugin branch/plugin/kukit branch/plugin/tests Message-ID: <20060430214646.4288510098@code0.codespeak.net> Author: gotcha Date: Sun Apr 30 23:46:41 2006 New Revision: 26623 Added: kukit/branch/plugin/kukit/kukit.BsCommentParser.js kukit/branch/plugin/kukit/kukit.BsMethodParser.js kukit/branch/plugin/kukit/kukit.BsPropertyParser.js kukit/branch/plugin/kukit/kukit.BsSelector.js kukit/branch/plugin/kukit/kukit.BsStringParser.js kukit/branch/plugin/kukit/kukit.Utils.js Removed: kukit/branch/plugin/kukit/kukit.BsParserSelectorElement.js Modified: kukit/ (props changed) kukit/branch/plugin/kukit/kukit.BsParser.js kukit/branch/plugin/kukit/kukit.Parser.js kukit/branch/plugin/tests.bat kukit/branch/plugin/tests/kukit.BsParserTestCase.js kukit/branch/plugin/tests/runtests.js Log: r23072 at archipelago: kaneda | 2006-04-28 22:37:48 +0200 * Refactored class names * Seperated code parts * Added documentation * Fixed bug in comment parsing Added: kukit/branch/plugin/kukit/kukit.BsCommentParser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.BsCommentParser.js Sun Apr 30 23:46:41 2006 @@ -0,0 +1,27 @@ +/** + * {@code kukit.BsCommentParser} removes comments from a string. + * + *

Note: Gets abused by {@code kukit.BsParser} + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsCommentParser = function() {} + +/** + * Removes from the content until the next end of the content. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsCommentParser.parse = function(options) { + var src = options.src; + var subsrc = src; + var pos = subsrc.indexOf("*/"); + var subpos = pos; + while (subsrc.charAt(subpos-1) == "\\" && subsrc.charAt(subpos-2) != "\\") { + subsrc = subsrc.substring(subpos+2); + subpos = subsrc.indexOf("*/"); + pos += subpos+2; + } + options.src = src.substring(0,options.pos)+src.substr(pos+2); +} Added: kukit/branch/plugin/kukit/kukit.BsMethodParser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.BsMethodParser.js Sun Apr 30 23:46:41 2006 @@ -0,0 +1,54 @@ +/** + * {@code kukit.BsMethodParser} parses a method as property value for {@code kukit.BsPropertyParser}. + * + *

Note: Gets abused by {@code kukit.BsParser} + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsMethodParser = function(){} + +/** + * Central parsing method + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsMethodParser.parse = function(options) { + var methodName = options.src.substring(0,options.pos); + var value = [methodName]; + var properties = options.src.substring(options.pos+1); + parseoptions = kukit.Parser.parse(this, properties, value, this.parseSettings); + options.result.push(value); + options.src = parseoptions.src; +} + +/** + * Handles if the end of the property "," occurs. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsMethodParser.parsePropertyEnd = function(options) { + var name = kukit.Utils.trim(options.src.substring(0,options.pos)); + if (name != "") + options.result.push(name); + options.src = options.src.substring(options.pos+1); +} + +/** + * Handles if the end of the method occus. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsMethodParser.parseEnd = function(options) { + this.parsePropertyEnd(options); + options.exit = 0; +} + +// Settings for the method block parsing +kukit.BsMethodParser.parseSettings = { + "}": kukit.Parser.parserError("Method needs to be closed by )"), + "\"": kukit.BsStringParser.parse, + "/*": kukit.BsCommentParser.parse, + ",": kukit.BsMethodParser.parsePropertyEnd, + ")": kukit.BsMethodParser.parseEnd +} \ No newline at end of file Modified: kukit/branch/plugin/kukit/kukit.BsParser.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.BsParser.js (original) +++ kukit/branch/plugin/kukit/kukit.BsParser.js Sun Apr 30 23:46:41 2006 @@ -1,113 +1,151 @@ -Object.prototype.toString = function() { - var result = "{"; - for (var i in this) { - result += i+":"+this[i]+", "; - } - return result.substring(0,result.length-2)+"}"; -} - -Array.prototype.toString = function() { - var result = "["; - for (var i in this) { - result += this[i]+", "; - } - return result.substring(0,result.length-2)+"]"; -} - -if (typeof kukit == "undefined") { - kukit = {}; -} -kukit.BsParser = function() { -}; +/** + * {@code BsParser} is a Parser that parses any bs string. + * + *

BS stands for "Behaviour Sheet" and is ment as format for defining + * behaviors to bind logic with html elements like css is bind styles with html + * elements. + * + *

{@code BsParser} is written to parse the CSS syntax and create a object + * model. To invoke the BsParser you just need to call: + * {@code kukit.BsParser.parse("...")} + * + *

{@code BsParser} is based on {@link kukit.Parser} mechianisms. This requires + * to have parser settings that are defined at the end of the file and refer to + * certain sub-parsermethods. + * + *

Example: + * {@code BsParser} would transform this css sytax: + * + * myselector:mytype(typearg,typearg) { + * property: value1 value2 value3(valuearg, valuearg); + * anotherproperty: "value with space"; + * } + * + * + * Javascript Object + * + * { + * myselector: { + * selector: myselector, + * type: { + * name: "mytype", + * properties: ["typearg", "typearg"] + * } + * properties: { + * property: [ + * "value1", + * "value2", + * ["value3", "valuearg", "valuearg"] + * ], + * anotherproperty: [ + * "value with space" + * ] + * } + * } + * } + * + * + *

If you define the same selector and type (including arguments) it combines + * all together to one property information like: + * + * BehaviorSheet + * + * tag { + * key1: value; + * } + * tag { + * key2: value; + * } + * + * + * JavaScript Object + * + * { + * tag: { + * key1: "value", + * key2: "value" + * } + * } + * + * + * @see kukit.Parser.parse + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsParser = function() {}; +/** + * Parses a BS string + * + * @param src source to be parsed + */ kukit.BsParser.parse = function(src) { - //print("parsing "+src); var result = {}; + // Base parsing should just recognize each block kukit.Parser.parse(this, src, result, { "{": this.parseBlock, - "/*": this.parseComments + "/*": kukit.BsCommentParser.parse // integrated without scope insurance + // for perfomance saving }); - - //print("result: "+result); return result; } + +// Definitions of white spaces to be ignored kukit.BsParser.WHITE_SPACES = " \t"; + +/** + * Removes unnecessary white spaces inside the block content. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ kukit.BsParser.parseWhiteSpaces = function(options) { var src = options.src.substring(options.pos); - //print("-/ remove space before: "+src); var whitespaces = this.WHITE_SPACES; while (whitespaces.indexOf(src.charAt(0)) != -1) { src = src.substr(1); - //print(" new src: "+src); } options.src = options.src.substring(0, options.pos)+src; - //print("-/ remove space after: "+src); } -kukit.BsParser.parseComments = function(options) { - var src = options.src; - var pos = src.indexOf("*/"); - //print("-/ remove comment before: "+src); - options.src = src.substring(0,options.pos)+src.substr(pos+2); - //print("-/ remove comment after: "+options.src); +/** + * Handles the end of a block + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsParser.parseBlockEnd = function(options) { + options.src = options.src.substring(options.pos+1); + options.exit = 0; } + +/** + * Parses the selector and passes the block content to certain sub parsers. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ kukit.BsParser.parseBlock = function(options) { var src = options.src; var rawselectors = src.substring(0, options.pos).split(","); var selectors = {}; + + // Formatting the selector and register them for (var i=0; i -1) { - selectorinfos.selector = rawselector.substring(0,seperatorpos); - var temp = []; - var parserresult = kukit.Parser.parse(this, rawselector.substring(seperatorpos+1), temp, { - "(": this.parseMethodProperty - }); - if(temp[0]) - temp = temp[0]; // take first element if some got found - - for (var j=0; j "+selector.toString()); + var infos = this.getSelectorInfos(kukit.Utils.trim(rawselectors[i])); - var properties = options.result[selectorinfos.toString()]; - if (!properties) { - properties = selectorinfos; - } - selectors[selectorinfos.toString()] = properties; - } - - //print ("- parseBlock: "+options.src+" at "+options.pos); - //print ("- rawselectors: "+rawselectors); - // TODO: Prepare the results + // Check if the selector already exists in + var properties = options.result[infos.id()]; + if (!properties) + properties = infos; + + selectors[infos.id()] = properties; + } var content = {}; var newsrc = src.substring(options.pos+1); - //print("blocksource: "+newsrc); - var parseoptions = kukit.Parser.parse(this, newsrc, content, { - ":": this.parseProperty, - "/*": this.parseComments, - "}": this.parseBlockEnd, - " ": this.parseWhiteSpaces - }); + var parseoptions = kukit.Parser.parse(this, newsrc, content, this.parserSettings); + + // The fetched properties apply to all selectors, since they might be defined + // they need to be set for every selector seperatly. var gotcontent = false; for (var i in selectors) { for (var j in content) { @@ -119,113 +157,64 @@ } } - //print("!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - //print("Result: "+selectorcontent); - options.src = parseoptions.src; - if (options.exit > 0) { - options.exit = parseoptions.exit; - } -} -kukit.BsParser.parseProperty = function(options) { - var key = this.checkProperty(options.src.substring(0,options.pos)); - var properties = []; - var rest = options.src.substring(options.pos+1); - //print ("-- found property: "+key+" using rest "+rest); - parseroptions = kukit.Parser.parse(this, rest, properties, { - "(": this.parseMethodProperty, - " ": this.parseNextProperty, - ";": this.parsePropertyEnd, - "}": this.parsePropertyBlockEnd, - "\"": this.parseString, - "/*": this.parseComments - }); - //print ("-- found property: "+key+" value: "+properties); - options.src = parseroptions.src; - options.result[key] = properties; - //print("taking properties"+properties); - if (parseroptions.exit > 1) { - options.error = parseroptions.error; - options.exit = parseroptions.exit; - } -} -kukit.BsParser.parseNextProperty = function(options) { - this.addProperty(options, options.src.substring(0,options.pos)); - //print ("-- nice property:"+property); - options.src = options.src.substring(options.pos+1); -} -kukit.BsParser.parsePropertyBlockEnd = function(options) { - this.addProperty(options, options.src.substring(0,options.pos)); - //print ("-- nice property:"+property); - options.src = options.src.substring(options.pos); - options.exit = 0; -} -kukit.BsParser.parsePropertyEnd = function(options) { - //print ("-- property end by }"); - this.parseNextProperty(options); - options.exit = 0; -} -kukit.BsParser.addProperty = function(options, property) { - property = this.checkProperty(property); - if (property != "") { - options.result.push(property); - } -} -kukit.BsParser.parseMethodProperty = function(options) { - var methodName = options.src.substring(0,options.pos); - var value = [methodName]; - var properties = options.src.substring(options.pos+1); - //print(methodName+" : "+properties); - parseoptions = kukit.Parser.parse(this, properties, value, { - "}": kukit.Parser.parserError("Method needs to be closed by )"), - ",": this.parseMethodPropertyEnd, - "\"": this.parseString, - "/*": this.parseComments, - ")": this.parseMethodEnd - }); - options.result.push(value); - options.src = parseoptions.src; -} -kukit.BsParser.parseMethodPropertyEnd = function(options) { - var name = kukit.Parser.trim(options.src.substring(0,options.pos)); - if (name != "") { - options.result.push(name); - } - options.src = options.src.substring(options.pos+1); -} -kukit.BsParser.parseMethodEnd = function(options) { - this.parseMethodPropertyEnd(options); - options.exit = 0; + // Pass the exit code if a error occured + if (options.exit > 0) + options.exit = parseoptions.exit; } -kukit.BsParser.parseString = function(options) { - var content = ""; - var src = options.src.substring(options.pos+1); - var pos = src.indexOf("\""); - //print("---- string content before: "+src); - while (pos >= 0) { - content = src.substring(0, pos); - src = src.substring(pos+1); - if (src.charAt(pos-1) != "\\" || src.charAt(pos-2) != "\\") { - break; + +/** + * Parses the selector and returns it. + * + * @param selector raw selector name + * @return {@link kukit.BsSelector} + */ +kukit.BsParser.getSelectorInfos = function(selector) { + var infos = new kukit.BsSelector(); + // : indicates type value + var typestart = selector.indexOf(":"); + if (typestart > -1) { + + infos.selector = selector.substring(0,typestart); + + var temp = []; + var parserresult = kukit.Parser.parse(this, selector.substring(typestart+1), temp, { + "(": kukit.Utils.cachedCall(kukit.BsMethodParser, "parse") + }); + + var rest = kukit.Utils.trim(parserresult.src); + + // Handling if the rest if the type arguments + if (rest != "" && !infos.type.name) { + infos.type.name = rest; + } else { + // Since the MethodParser works a different way for BsPropertyParser it + // needs to be reformatted + + if(temp[0]) + temp = temp[0]; + + for (var j=0; jProperties inside a BehaviourSheet are to complex for inline processing + * so this class handles the content used within a selector block. + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsPropertyParser = function() {} + +/** + * Parse starting with the property indiciator : + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsPropertyParser.parse = function(options) { + var key = this.checkProperty(options.src.substring(0,options.pos)); + var properties = []; + var rest = options.src.substring(options.pos+1); + parseroptions = kukit.Parser.parse(this, rest, properties, this.parseSettings); + options.src = parseroptions.src; + options.result[key] = properties; + if (parseroptions.exit > 1) { + options.error = parseroptions.error; + options.exit = parseroptions.exit; + } +} + +/** + * Parsing next value for a key indicated by the space ( ). + * + *

This is a subparser method for properties. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsPropertyParser.parseNextProperty = function(options) { + this.addProperty(options, options.src.substring(0,options.pos)); + options.src = options.src.substring(options.pos+1); +} + +/** + * Ends the processing of a block + * + *

This is a subparser method for properties. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsPropertyParser.parsePropertyBlockEnd = function(options) { + this.addProperty(options, options.src.substring(0,options.pos)); + options.src = options.src.substring(options.pos); + options.exit = 0; +} + +/** + * Finishes the processing of any property. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsPropertyParser.parsePropertyEnd = function(options) { + this.parseNextProperty(options); + options.exit = 0; +} + +/** + * Helper for adding a property to the result. + * + * @param options parseoptions passed by {@code kukit.Parser} + * @param property property + */ +kukit.BsPropertyParser.addProperty = function(options, property) { + property = this.checkProperty(property); + if (property != "") + options.result.push(property); +} + +/** + * Validates if a property matches all states. + * + * @param options parseoptions passed by {@code kukit.Parser} + * @param property property + */ +kukit.BsPropertyParser.checkProperty = function(property) { + property = kukit.Utils.trim(property); + property = property.split("\\n").join("\n"); + property = property.split("\\t").join("\t"); + property = property.split("\\b").join("\b"); + property = property.split("\\b").join("\b"); + return property; +} + +// Settings for the property parsing +kukit.BsPropertyParser.parseSettings = { + "(": kukit.Utils.cachedCall(kukit.BsMethodParser, "parse"), + "\"": kukit.BsStringParser.parse, + "/*": kukit.BsCommentParser.parse, + " ": kukit.BsPropertyParser.parseNextProperty, + ";": kukit.BsPropertyParser.parsePropertyEnd, + "}": kukit.BsPropertyParser.parsePropertyBlockEnd +} \ No newline at end of file Added: kukit/branch/plugin/kukit/kukit.BsSelector.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.BsSelector.js Sun Apr 30 23:46:41 2006 @@ -0,0 +1,38 @@ +/** + * {@code BsSelector} is a data holder for the informations including its (pseudo)class called "type" + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsSelector = function() { + this.properties = {}; // properties for the type + this.type = {}; // type informations + this.selector = ""; // selector to be used +} +/** + * Transforms the selector into a string. + * + *

This method is important for identifing a certain selector including + * its method informations. + * + * @return selector as string + */ +kukit.BsSelector.prototype.id = function() { + var result = this.selector; + + with (this.type) { + if (typeof name != "undefined") { + result += ":"+name+"("; + if (typeof properties != "undefined") { + for (var i=0; i< properties.length; i++) { + if (i != 0) + result += ","; + result += properties[i]; + } + } + result += ")"; + } + } + + return result; +} \ No newline at end of file Added: kukit/branch/plugin/kukit/kukit.BsStringParser.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.BsStringParser.js Sun Apr 30 23:46:41 2006 @@ -0,0 +1,33 @@ +/** + * {@code kukit.BsStringParser} handles the parsing of a string value + * + *

If you set a value with " you need to have different parsing. + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.BsStringParser = function() {} + +/** + * Removes the doublequotes and adds the content to the passed-in result. + * + * @param options parseoptions passed by {@code kukit.Parser} + */ +kukit.BsStringParser.parse = function(options) { + var content = ""; + var src = options.src.substring(options.pos+1); + var pos = src.indexOf("\""); + while (pos >= 0) { + content = src.substring(0, pos); + src = src.substring(pos+1); + + // Handle escaping of the doublequotes + if (src.charAt(pos-1) != "\\" || src.charAt(pos-2) != "\\") { + break; + } + content += "\""; + pos = src.indexOf("\""); + } + options.src = options.src.substring(0, options.pos)+options.src.substring(options.pos+content.length+2); + options.result.push(kukit.BsPropertyParser.checkProperty(content)); +} Modified: kukit/branch/plugin/kukit/kukit.Parser.js ============================================================================== --- kukit/branch/plugin/kukit/kukit.Parser.js (original) +++ kukit/branch/plugin/kukit/kukit.Parser.js Sun Apr 30 23:46:41 2006 @@ -1,58 +1,90 @@ -if(typeof kukit == "undefined") { - kukit = {}; -} -kukit.Parser = function() { -} +/** + * {@code kukit.Parser} is the core parser to be used by {@link kukit.BsParser}. + * + *

{@code kukit.Parser} provides a generic way of parsing text by taking + * parseMethods registered to characters. If one of the registered characters + * occurs it calls the related method together with a parsing scope. + * + *

The parsing scope contains the result and the rest of the remaining stuff + * to parse the code. + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.Parser = function() {} -kukit.Parser.trim = function(str, chars) { - if (!chars) - chars='\\s\\n\\r' - return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); -} +/** + * Parses a certain source. + * + * @param scope scope where the subparsers will be executed + * @param src src that should be parsed + * @param result result that can be accessed by each subparser + * @subparsers map of subparsers mapped to characters + * @return options to be used during execution (containing the rest string in .src) + */ kukit.Parser.parse = function(scope, src, result, subparsers) { - //print("parsing "+src); var options = {scope: scope, src:src, result:result, subparsers:subparsers, exit: -1}; - while (this.getNext(options) && options.exit == -1); - //print("end of parsing"); + while (this.nextStep(options) && options.exit == -1); return options; } + +// List of errors that occured kukit.Parser.errors = {}; -kukit.Parser.parserError = function(error) { - errormethod = this.errors[error]; - if (!errormethod) { - errormethod = function(options) { - options.error = error; - options.exit = 1; - } - } - return errormethod; -} -kukit.Parser.getNext = function(options) { + +/** + * Executes the next step of parsing. + * + * @param options options for all + * @return true if it could find something to parse + */ +kukit.Parser.nextStep = function(options) { + + // Take the next matching subparser by its identifier var next = -1; var parser; var parsername; - //print("> state"+options.exit); for (var i in options.subparsers) { var pos = options.src.indexOf(i); - //print("> taking parser for "+i+" at "+pos+" next is "+next); if ((pos < next || next == -1) && pos != -1) { next = pos; parsername = i; - //print(">> found "+i+" at "+pos); parser = options.subparsers[i]; } } options.pos = next; + + // Execute the parser to the scope if (parser) { - //print(">> found "+parsername+" for "+options.src+" function "+parser); - options.scope["__parseMethod"]= parser; + var n = "__parserMethod__" + options.scope[n] = parser; try { - options.scope["__parseMethod"](options); - } catch(e) { + options.scope[n](options); + } catch(e) { options.error = e; options.exit = 2; print(e); } + } else if(next >= 0) { + options.error = "Parser for > "+parsername+" < not found"; + options.exit = 2; + print(options.error); } return (next >=0); +} + +/** + * Util that exits parsing with a error if a character occurs. + * + * @param error Error that should be set if a character occurs + * @return parser-method to be integrated into the parser + */ +kukit.Parser.parserError = function(error) { + errormethod = this.errors[error]; + if (!errormethod) { + errormethod = function(options) { + options.error = error; + options.exit = 1; + } + } + return errormethod; } \ No newline at end of file Added: kukit/branch/plugin/kukit/kukit.Utils.js ============================================================================== --- (empty file) +++ kukit/branch/plugin/kukit/kukit.Utils.js Sun Apr 30 23:46:41 2006 @@ -0,0 +1,45 @@ +// Namespace declarations +kukit = {}; + +/** + * Collection of utils for kukit. + * + * @author Martin Heidegger + * @version 1.0 + */ +kukit.Utils = function() {} + +/** + * Creates a function that executes a method inside a scope and stores it. + * + *

In different to other scope keeper implementations, this implementation + * stores the method call in a field so its not recreated again and again. + * + * @todo integrate generic call (currently only one arguments is supported) + * + * @param scope Scope of the method call + * @param methodName Name of the method in the scope + * @return + */ +kukit.Utils.cachedCall = function(scope, methodName) { + var method = scope[methodName+"_ref"]; + if (!method) { + method = scope[methodName+"_ref"] = function(options) { + return scope.parse(options); + } + } + return method; +} + +/** + * Trims a string. + * + * @param str String to be trimmed + * @param chars Characters that should be trimmed + * @return Trimmed string + */ +kukit.Utils.trim = function(str, chars) { + if (!chars) + chars='\\s\\n\\r' + return str.replace(new RegExp("^["+chars+"]*(.*?)["+chars+"]*$"), "$1"); +} \ No newline at end of file Modified: kukit/branch/plugin/tests.bat ============================================================================== --- kukit/branch/plugin/tests.bat (original) +++ kukit/branch/plugin/tests.bat Sun Apr 30 23:46:41 2006 @@ -1 +1 @@ -java -cp ../rhino1_6R2/js.jar org.mozilla.javascript.tools.shell.Main -f tests/ecmaunit.js -f kukit/kukit.Parser.js -f kukit/kukit.BsParser.js -f kukit/kukit.BsParserSelectorElement.js -f tests/kukit.BsParserTestCase.js -f tests/runtests.js \ No newline at end of file +java -cp ../rhino1_6R2/js.jar org.mozilla.javascript.tools.shell.Main -f tests/ecmaunit.js -f kukit/kukit.Utils.js -f kukit/kukit.Parser.js -f kukit/kukit.BsStringParser.js -f kukit/kukit.BsCommentParser.js -f kukit/kukit.BsMethodParser.js -f kukit/kukit.BsPropertyParser.js -f kukit/kukit.BsParser.js -f tests/kukit.BsParserTestCase.js -f kukit/kukit.BsSelector.js -f tests/runtests.js Modified: kukit/branch/plugin/tests/kukit.BsParserTestCase.js ============================================================================== --- kukit/branch/plugin/tests/kukit.BsParserTestCase.js (original) +++ kukit/branch/plugin/tests/kukit.BsParserTestCase.js Sun Apr 30 23:46:41 2006 @@ -43,9 +43,11 @@ } this.testComments = function() { - var src = "tagselector{\n /* comment */\n key:value;\n}\n\n/* comment outside */\n"; + var src = "tag{\n /* comment\\*/key2:value; */\n key:value;\n}\n\n/* comment outside */\n"; var rules = kukit.BsParser.parse(src); - this.assertTrue("tagselector" in rules); + this.assertTrue("tag" in rules); + this.assertEquals(rules["tag"].properties["key"][0], "value"); + this.assertFalse("key2" in rules["tag"].properties); } this.testMultilineComments = function() { Modified: kukit/branch/plugin/tests/runtests.js ============================================================================== --- kukit/branch/plugin/tests/runtests.js (original) +++ kukit/branch/plugin/tests/runtests.js Sun Apr 30 23:46:41 2006 @@ -18,6 +18,7 @@ var reporter = new StdoutReporter; var testsuite = new TestSuite(reporter); testsuite.registerTest(kukit.BsParserTestCase); + //testsuite.registerTest(kukit.RuleProcessorTestCase); testsuite.runSuite(); };