Changeset 204
- Timestamp:
- 12/27/09 07:26:39 (8 months ago)
- Location:
- xmvc/branches/remove-namespaces
- Files:
-
- 1 added
- 11 modified
-
example.html (modified) (2 diffs)
-
example.js (modified) (3 diffs)
-
example.xml (modified) (3 diffs)
-
src/main/javascript/compat/nodetypes.js (added)
-
src/main/javascript/compat/sarissa_ieemu_xpath.js (modified) (4 diffs)
-
src/main/javascript/joice/Context.js (modified) (3 diffs)
-
src/main/javascript/joice/ContextConfiguration.js (modified) (7 diffs)
-
src/main/javascript/joice/Loader.js (modified) (2 diffs)
-
src/main/javascript/string/format.js (modified) (1 diff)
-
src/main/javascript/util/ScriptLoader.js (modified) (2 diffs)
-
src/main/javascript/xmvc/Configuration.js (modified) (7 diffs)
-
src/main/javascript/xmvc/Transformer.js (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
xmvc/branches/remove-namespaces/example.html
r201 r204 2 2 <head> 3 3 <title>A Joice Example</title> 4 <!-- 4 5 <script type="text/javascript" src="everything.js"></script> 5 <!--6 --> 6 7 <script type="text/javascript" src="src/main/javascript/compat/jdc-1.0.3.js"></script> 7 8 <script type="text/javascript" src="src/main/javascript/compat/javeline_xpath.js"></script> 8 9 <script type="text/javascript" src="src/main/javascript/compat/javeline_xslt.js"></script> 9 10 <script type="text/javascript" src="src/main/javascript/compat/sarissa.js"></script> 11 <script type="text/javascript" src="src/main/javascript/compat/sarissa_ieemu_xpath.js"></script> 12 <script type="text/javascript" src="src/main/javascript/compat/nodetypes.js"></script> 10 13 <script type="text/javascript" src="src/main/javascript/contrib/jitloader.js"></script> 11 14 <script type="text/javascript" src="src/main/javascript/string/format.js"></script> 15 <script type="text/javascript" src="src/main/javascript/string/sprintf.js"></script> 12 16 <script type="text/javascript" src="src/main/javascript/array/each.js"></script> 13 17 <script type="text/javascript" src="src/main/javascript/util/HttpClient.js"></script> … … 21 25 <script type="text/javascript" src="src/main/javascript/joice/Loader.js"></script> 22 26 <script type="text/javascript" src="src/main/javascript/joice/Bootstrap.js"></script> 23 -->24 27 25 28 <!-- -
xmvc/branches/remove-namespaces/example.js
r201 r204 14 14 15 15 this.feature = function () { 16 window.alert("And you can also: \f".format("click"))16 window.alert("And you can also: %s".sprintf(this.test)) 17 17 } 18 18 } … … 28 28 } 29 29 30 /* 30 31 var hello = document.getElementById("hello") 31 32 … … 41 42 baz.print() 42 43 } 44 */ 43 45 44 46 function Greeter () { -
xmvc/branches/remove-namespaces/example.xml
r201 r204 4 4 <!-- text/javascript;debug runs the IE-incompatible jit loader which keeps 5 5 track of the actual source location... --> 6 <script type="text/javascript " src="src/main/javascript/xmvc/ControllerScope.js"/>7 <script type="text/javascript " src="src/main/javascript/xmvc/Transformer.js"/>8 <script type="text/javascript " src="src/main/javascript/xmvc/Configuration.js"/>6 <script type="text/javascript;debug" src="src/main/javascript/xmvc/ControllerScope.js"/> 7 <script type="text/javascript;debug" src="src/main/javascript/xmvc/Transformer.js"/> 8 <script type="text/javascript;debug" src="src/main/javascript/xmvc/Configuration.js"/> 9 9 10 10 <script type="text/javascript;debug" src="example.js"/> … … 34 34 </object> 35 35 36 <object id="controller" constructor=" Controller" initialization="eager">36 <object id="controller" constructor="XMLController" initialization="eager"> 37 37 <argument> 38 38 <xml> 39 39 <controller> 40 <node id="hello"> 41 <action type="click" object="foo" method="hello"/> 42 </node> 43 44 <node id="list"> 45 <action type="click" object="baz" method="print"/> 46 </node> 47 48 <!-- 40 49 <node id="ping"> 41 50 <action type="click" object="greeter" handler="hello"> 42 <transform ertype="xslt" path="//body" behavior="append"51 <transform type="xslt" path="//body" behavior="append" 43 52 src="example.xsl"> 44 53 <param name="message" value="Hello, world"/> … … 50 59 <action type="click" object="greeter" handler="goodbye"/> 51 60 </node> 61 --> 52 62 </controller> 53 63 </xml> -
xmvc/branches/remove-namespaces/src/main/javascript/compat/sarissa_ieemu_xpath.js
r94 r204 135 135 * @throws An error if no namespace URI is found for the given prefix. 136 136 */ 137 HTMLDocument.prototype.selectNodes = 137 138 XMLDocument.prototype.selectNodes = function(sExpr, contextNode, returnSingle){ 138 139 var nsDoc = this; … … 181 182 * available to XML Elements. 182 183 */ 184 HTMLElement.prototype.selectNodes = 183 185 Element.prototype.selectNodes = function(sExpr){ 184 186 var doc = this.ownerDocument; … … 197 199 * @returns the result of the XPath search as an (Sarissa)NodeList 198 200 */ 201 HTMLDocument.prototype.selectSingleNode = 199 202 XMLDocument.prototype.selectSingleNode = function(sExpr, contextNode){ 200 203 var ctx = contextNode?contextNode:null; … … 208 211 * available to XML Elements. 209 212 */ 213 HTMLElement.prototype.selectSingleNode = 210 214 Element.prototype.selectSingleNode = function(sExpr){ 211 215 var doc = this.ownerDocument; -
xmvc/branches/remove-namespaces/src/main/javascript/joice/Context.js
r201 r204 109 109 110 110 for (var i = 0; i < argumentCount; i++) { 111 params.push("arguments[ \f]".format(i))112 } 113 114 var code = "return new \f(\f)".format(methodName, params.join(","))111 params.push("arguments[%d]".sprintf(i)) 112 } 113 114 var code = "return new %s(%s)".sprintf(methodName, params.join(",")) 115 115 116 116 try { … … 301 301 var specificationCount = specifications.length 302 302 303 window.alert("Specifications: " + specificationCount)304 305 303 for (var i = 0; i < specificationCount; i++) { 306 304 var specification = specifications[i] … … 312 310 * someone finds a reason to try that. */ 313 311 if (specification.init == "eager") { 314 window.alert("Initting: " + specification.id)315 312 this.getObject(specification.id) 316 313 } -
xmvc/branches/remove-namespaces/src/main/javascript/joice/ContextConfiguration.js
r201 r204 139 139 var specs = {} 140 140 var loaders = { 141 "text/javascript": new DocumentWriteScriptLoader(semaphore),141 "text/javascript": new HttpJavaScriptLoader(semaphore), 142 142 "text/javascript;debug": new JITLoader(semaphore) 143 143 } … … 202 202 */ 203 203 var doc = element.ownerDocument 204 var arrayObject = doc.createElement NS(JOICENS,JOICENS_OBJECT)204 var arrayObject = doc.createElement(JOICENS_OBJECT) 205 205 206 206 arrayObject.setAttribute("constructor", "Array") … … 214 214 * bunch of elements that only have text nodes in them. Another 215 215 * way to do this would be to check the node type. ;-) */ 216 if (child.n amespaceURI == JOICENS) {217 var argument = doc.createElement NS(JOICENS,JOICENS_ARGUMENT)216 if (child.nodeType == ELEMENT_NODE) { 217 var argument = doc.createElement(JOICENS_ARGUMENT) 218 218 219 219 if (hasAttribute(child, "object")) { … … 235 235 236 236 function Context_parseProperty (element) { 237 if (hasAttribute(element, "value")) { 238 return new PropertySpecification("value", 239 element.getAttribute("value")) 240 } 241 else if (hasAttribute(element, "object")) { 242 return new PropertySpecification("object", 243 vivifyObject(element.getAttribute("object"))) 237 var value = element.getAttribute("value") 238 var object = element.getAttribute("object") 239 240 if (value != undefined) { 241 return new PropertySpecification("value", value) 242 } 243 else if (object != undefined) { 244 return new PropertySpecification("object", vivifyObject(object)) 244 245 } 245 246 else if (element.hasChildNodes()) { … … 251 252 var child = children[i] 252 253 253 if (child.n amespaceURI == JOICENS) switch (child.tagName) {254 if (child.nodeType == ELEMENT_NODE) switch (child.tagName) { 254 255 case JOICENS_OBJECT: 255 256 /* {} is just new Object(), I'm assuming that's true on … … 280 281 case JOICENS_XML: 281 282 matches++ 283 284 /* Select the first child element node as the root. */ 285 if (child.hasChildNodes()) { 286 FIRST_CHILD: for (var node = child.firstChild; 287 node != null; 288 node = node.nextSibling) 289 { 290 if (node.nodeValue == ELEMENT_NODE) { 291 child = node 292 break FIRST_CHILD 293 } 294 } 295 } 296 282 297 result = new PropertySpecification("value", 283 298 child) … … 377 392 this.parseConfig = function (config) { 378 393 var possibleObjects = config.childNodes 379 var elements = []380 394 381 395 for (var i = 0; i < possibleObjects.length; i++) { 382 396 var possibleObject = possibleObjects[i] 383 397 384 if (possibleObject.n amespaceURI == JOICENS&&398 if (possibleObject.nodeType == ELEMENT_NODE && 385 399 possibleObject.tagName == JOICENS_SCRIPT) { 386 400 Context_parseScript(possibleObject) 387 401 } 388 402 389 if (possibleObject.n amespaceURI == JOICENS&&403 if (possibleObject.nodeType == ELEMENT_NODE && 390 404 possibleObject.tagName == JOICENS_OBJECT) { 391 405 Context_parseObject(possibleObject) 392 406 } 393 394 elements.push("Not possible object {" + 395 possibleObject.namespaceURI 396 +"}"+ 397 possibleObject.localName 398 + " IE sucks " + 399 possibleObject.tagName) 400 } 401 402 window.alert(elements.join("\n")) 407 } 403 408 404 409 for (var key in specs) { -
xmvc/branches/remove-namespaces/src/main/javascript/joice/Loader.js
r201 r204 32 32 request.send(null) 33 33 34 var dispatch = true 35 34 36 request.onreadystatechange = function () { 35 37 /* TODO: Fix this is done in too many places, consolidate */ … … 44 46 case 200: 45 47 case 0: 46 window.alert("Fetched configuration") 47 callback(request.responseXML, request.responseText) 48 /* Only dispatch the callback once */ 49 if (dispatch) { 50 callback(request.responseXML, request.responseText) 51 dispatch = false 52 } 48 53 } 49 54 } -
xmvc/branches/remove-namespaces/src/main/javascript/string/format.js
r123 r204 3 3 */ 4 4 5 /* There is a bug in IE here for some reason, the string values never get 6 * substituted and the original string (less escaped characters) is returned.. 7 */ 5 8 String.prototype.format = function () { 6 9 if (!arguments.length) return this.toString() -
xmvc/branches/remove-namespaces/src/main/javascript/util/ScriptLoader.js
r201 r204 46 46 47 47 var source = request.responseText 48 var code = null49 48 50 49 try { 51 global.eval(source)50 window.eval(source) 52 51 } 53 52 catch (error) { … … 103 102 104 103 script.onreadystatechange = function () { 105 if (this.readyState == "complete") { 104 window.alert("ready state: " + this.readyState) 105 if (/complete|loaded/.test(this.readyState)) { 106 semaphore.release() 107 106 108 loader.onload() 107 109 } 108 110 } 109 111 112 script.onload = function () { 113 semaphore.release() 114 115 loader.onload() 116 } 117 118 document.body.appendChild(script) 119 /* 110 120 this.onload() 111 112 semaphore.release() 121 */ 113 122 } 114 123 } -
xmvc/branches/remove-namespaces/src/main/javascript/xmvc/Configuration.js
r201 r204 1 2 function XMLController (configuration) { 3 var controller = new Controller(window.document) 4 var configparser = new XMVCConfigParser(controller) 5 6 configparser.parse(configuration) 7 } 1 8 2 9 function XMVCConfigParser (controller) { … … 49 56 } 50 57 51 this._buildAction = function ( observer) {58 this._buildAction = function (action, observer) { 52 59 return controller.createAction( 53 60 action.getAttribute("object"), … … 62 69 /* TODO: I think this is all out of date... */ 63 70 if (node.hasAttribute("id")) { 64 window.alert("ID node")65 71 locateType = "id" 66 72 locatePath = node.getAttribute("id") 67 73 } 68 else if (node.hasAttribute("context")) { 69 window.alert("context node") 74 else if (node.hasAttribute("path")) { 70 75 locateType = "xpath" 71 locatePath = node.getAttribute(" context")76 locatePath = node.getAttribute("path") 72 77 } 73 78 else if (node.hasAttribute("type")) { 74 window.alert("type node") 75 locateType = node.getAttribute("locator") 76 locatePath = node.getAttribute("path") 79 locateType = node.getAttribute("type") 80 locatePath = node.getAttribute("expression") 81 } 82 else { 83 throw new Error("Invalid node expression, must have both " + 84 "type and expression attributes") 77 85 } 78 86 … … 82 90 this._buildSelection = function (node) { 83 91 var locator = this._buildLocator(node) 92 84 93 var selection = controller.createSelection(locator) 85 94 … … 90 99 if (child.tagName == "action") { 91 100 /* TODO: Support multiple transform observers through the 92 * listable transform interface. */ 101 * listable transform interocument) 102 context.addScope("document", documentScoface. */ 93 103 var transform = this._nextTransformNode(child) 94 104 var observer = null … … 118 128 node = node.nextSibling) 119 129 { 120 if (node. type == Node.ELEMENT_NODE) {130 if (node.nodeType == ELEMENT_NODE) { 121 131 if (node.tagName == "node") { 122 132 selections.push(this._buildSelection(node)) … … 128 138 } 129 139 130 this.parse = function (element) { 131 if (element.type == Node.DOCUMENT_NODE) { 132 element = element.documentElement 140 /** 141 * Parse a document (or fragment) 142 * 143 * <p>This expects a DOM node which is either the <em>document</em> element 144 * of a controller specification, or an element which contains a controller 145 * specification. It configures the controller this XMVCConfigParser 146 * wraps.</p> 147 */ 148 this.parse = function (node) { 149 var selections = [] 150 151 for (var node = node.firstChild; 152 node != null; 153 node = node.nextSibling) 154 { 155 if (node.nodeType == ELEMENT_NODE) { 156 if (node.tagName == "controller") { 157 selections = this._parseNodes(node) 158 } 159 } 133 160 } 134 161 135 var selections = this._parseNodes(element) 162 for (var i = 0; i < selections.length; i++) { 163 controller.addSelection(selections[i]) 164 } 136 165 } 137 166 } -
xmvc/branches/remove-namespaces/src/main/javascript/xmvc/Transformer.js
r201 r204 22 22 23 23 function Controller (document) { 24 window.alert("I think this is what's all messed up...")25 24 if (typeof document == "undefined") { 26 25 document = globalDocument 27 window.alert("YO!") 28 } 29 30 window.alert(document) 26 } 27 28 this.document = document 31 29 32 30 var selections = [] 33 31 var mustWalk = false 34 32 var walkObservers = [] 33 34 /* TODO I think the static id/xpath initialization is temporary */ 35 var locators = { 36 "id": FastIdLocator, 37 "xpath": XPathLocator 38 } 35 39 36 40 /* TODO: Debug document scope... … … 67 71 } 68 72 69 var handleProcessing = function ( element) {73 var handleProcessing = function (node) { 70 74 /* Walk the node if we have stuff to do... */ 71 75 if (walkObservers.length) { 72 this.walk( element)76 this.walk(node) 73 77 } 74 78 75 79 selections.each(function (selection) { 76 selection.attach( element)80 selection.attach(node) 77 81 }) 78 82 } 79 83 80 84 /** 81 * Process a given element(and it's descendants).82 */ 83 this.process = function ( element) {85 * Process a given node (and it's descendants). 86 */ 87 this.process = function (node) { 84 88 var controller = this 85 89 … … 90 94 * or something (like joice). */ 91 95 window.setTimeout(function () { 92 handleProcessing.call(controller, element)96 handleProcessing.call(controller, node) 93 97 }, 1) 98 } 99 100 /** 101 * Add a new locator. 102 * 103 * <p>Given a type and a constructor, register the given constructor as a 104 * factory for locators of the given type. Constructors are expected to 105 * accept the arguments <code>({@link Controller} controller, 106 * {@link String} expression)</code>, whereas the controller will be the 107 * instance of the controller which has factoried the object and the 108 * expression a string representing the path to the node using the given 109 * constructor.</p> 110 * 111 * @param type The name of the type for the locator. 112 * @param constructor The constructor of the locator. 113 */ 114 this.addLocator = function (type, constructor) { 115 if (locators[type] == undefined) { 116 locators[type] = constructor 117 } 118 else { 119 throw new Error("Unable to add locator, " + 120 "type \"%s\" already defined".sprintf(type)) 121 } 122 } 123 124 this.createLocator = function (type, expression) { 125 if (locators[type] != undefined) { 126 return new locators[type](this, expression) 127 } 128 else { 129 throw new Error("Locator type \"%s\" not available".sprintf(type)) 130 } 94 131 } 95 132 … … 98 135 99 136 this.addSelection(selection) 137 138 return selection 100 139 } 101 140 … … 162 201 * controller.createAction("objectName", "methodName", 163 202 * new NoopObserver())) 203 * 204 * controller.createSelection( 205 * controller.createLocator("id", "elementid") 206 * ).addAction("click", function () { 207 * window.alert("hello, world!") 208 * }) 164 209 * 165 210 */ … … 183 228 184 229 for (var type in actions) { 185 actions[type].each(callback) 230 actions[type].each(function (action) { 231 callback(type, action, node) 232 }) 186 233 } 187 234 } … … 201 248 */ 202 249 this.attach = function (element) { 203 return allActions(element, function ( action) {204 node.addEventListener(type, action.handle )250 return allActions(element, function (type, action, node) { 251 node.addEventListener(type, action.handle, false) 205 252 }) 206 253 } … … 257 304 /* If the method returned a value, simulate a notification with it. */ 258 305 try { 259 var result = object[method ](observer,306 var result = object[methodName](observer, 260 307 { element: this, event: event, extra: e, scope: scope }) 261 308 } … … 273 320 return result 274 321 } 322 323 this.toString = function () { 324 return "[action (%s.%s), observer: %s]".sprintf( 325 objectName, methodName, observer 326 ); 327 } 275 328 } 276 329 … … 309 362 * @param expression The xpath expression. 310 363 */ 311 function XPathLocator ( expression) {364 function XPathLocator (controller, expression) { 312 365 this.locate = function (context) { 313 366 if (context == null || typeof context == "undefined") { 314 context = document367 context = controller.document 315 368 } 316 369 … … 320 373 this.list = function (context) { 321 374 if (context == null) { 322 context = document375 context = controller.document 323 376 } 324 377 325 378 return context.selectNodes(expression) 326 379 } 327 } 328 329 function FastIdLocator (id) { 380 381 this.toString = function () { 382 return "xpath://%s/".sprintf(expression) 383 } 384 } 385 386 function FastIdLocator (controller, id) { 330 387 this.locate = function (context) { 331 var element = document.getElementById(id)388 var element = controller.document.getElementById(id) 332 389 333 390 if (context == null || typeof context == "undefined") { … … 351 408 return element != null ? [ element ] : [] 352 409 } 410 411 this.toString = function () { 412 return "node://#%s".sprintf(id) 413 } 353 414 } 354 415