use of org.wso2.uri.template.URITemplate in project jaggery by wso2.
the class URIMatcherHostObject method jsFunction_match.
/**
* Match function that takes the URI template as an argument
*
* @param cx
* @param thisObj
* @param args
* @param funObj
* @return
* @throws ScriptException
*/
public static ScriptableObject jsFunction_match(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "match";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs("RhinoTopLevel", functionName, argsCount, false);
}
String template = (String) args[0];
URIMatcherHostObject uriho = (URIMatcherHostObject) thisObj;
Map<String, String> urlParts = new HashMap<String, String>();
try {
URITemplate uriTemplate = new URITemplate(template);
boolean uriMatch = uriTemplate.matches(uriho.uriToBeMatched, urlParts);
if (!uriMatch) {
return null;
}
} catch (URITemplateException e) {
throw new ScriptException(e);
}
ScriptableObject nobj = (ScriptableObject) cx.newObject(thisObj);
for (Map.Entry<String, String> entry : urlParts.entrySet()) {
nobj.put(entry.getKey(), nobj, entry.getValue());
}
uriho.uriParts = nobj;
return nobj;
}
Aggregations