Skip to content

Commit

Permalink
[BUG #7525] Overwrite path with default path if no listener is regist…
Browse files Browse the repository at this point in the history
…ered
  • Loading branch information
rsternagel committed Aug 12, 2013
1 parent 5386bb3 commit 964a534
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
24 changes: 18 additions & 6 deletions framework/source/class/qx/application/Routing.js
Expand Up @@ -124,13 +124,27 @@ qx.Bootstrap.define("qx.application.Routing", {
}

var path = this.getState();
if (path == "" || path == null){
path = defaultRoute || qx.application.Routing.DEFAULT_PATH;
}
path = this._getPathOrFallback(path, defaultRoute);
this._executeGet(path, null, true);
},


/**
* Checks if path is valid and registered in channel "get" and then just returns it.
* If the path is not valid either the <code>defaultPath</code> (if given) or the
* {@link #DEFAULT_PATH} will be returned.
*
* @param path {String} Path which gets checked.
* @param defaultPath {String?} Optional default path.
*/
_getPathOrFallback : function(path, defaultPath) {
if (path == "" || path == null || !this.__messaging.isListenerRegisteredFor("get", path)) {
path = defaultPath || qx.application.Routing.DEFAULT_PATH;
}
return path;
},


/**
* Adds a route handler for the "get" operation. The route gets called
* when the {@link #executeGet} method found a match.
Expand Down Expand Up @@ -232,9 +246,7 @@ qx.Bootstrap.define("qx.application.Routing", {
__onChangeHash : function(evt)
{
var path = evt.getData();
if (path == "" || path == null){
path = qx.application.Routing.DEFAULT_PATH;
}
path = this._getPathOrFallback(path);

if (path != this.__currentGetPath) {
this._executeGet(path, null, true);
Expand Down
27 changes: 26 additions & 1 deletion framework/source/class/qx/event/Messaging.js
Expand Up @@ -132,6 +132,31 @@ qx.Bootstrap.define("qx.event.Messaging",
},


/**
* Checks if a listener is registered for the given path in the given channel.
*
* @param channel {String} The channel of the message.
* @param path {String} The path to check.
*/
isListenerRegisteredFor : function(channel, path) {
var listeners = this._listener[channel];
if (!listeners || qx.lang.Object.isEmpty(listeners)) {
qx.Bootstrap.info("No listener found for channel: " + channel);
return false;
}

for (var id in listeners)
{
var listener = listeners[id];
if (listener.regExp.test(path)) {
return true;
}
}

qx.Bootstrap.info("No listener found for path: " + path);
return false;
},

/**
* Sends a message on the given channel and informs all matching route handlers.
*
Expand Down Expand Up @@ -234,4 +259,4 @@ qx.Bootstrap.define("qx.event.Messaging",
return match != undefined;
}
}
});
});

0 comments on commit 964a534

Please sign in to comment.