Search in sources :

Example 1 with URITemplateException

use of org.wso2.uri.template.URITemplateException 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;
}
Also used : URITemplateException(org.wso2.uri.template.URITemplateException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) HashMap(java.util.HashMap) URITemplate(org.wso2.uri.template.URITemplate) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1 URITemplate (org.wso2.uri.template.URITemplate)1 URITemplateException (org.wso2.uri.template.URITemplateException)1