Java 类org.mozilla.javascript.regexp.NativeRegExp 实例源码

项目:pizzascript    文件:ChromeBrowser.java   
@Override
public void verifyText(NativeRegExp regexp) {
    HashMap<String,Object> params = new HashMap<>();
    String text = regexp.toString();
    params.put("regexp", text);
    JSONObject result = pizzaHandler.sendCommand("verifyText", params);
    if (!getResponseBoolean(result)) {
        throw new ScriptException(String.format("Unable to find text matching '%s'", text));
    }
}
项目:pizzascript    文件:ChromeBrowser.java   
@Override
public void verifyNotText(NativeRegExp regexp) {
    HashMap<String,Object> params = new HashMap<>();
    String text = regexp.toString();
    params.put("regexp", text);
    JSONObject result = pizzaHandler.sendCommand("verifyText", params);
    if (getResponseBoolean(result)) {
        throw new ScriptException(String.format("Found text matching '%s'", text));
    }
}
项目:pizzascript    文件:ChromeBrowser.java   
@Override
public void verifyTitle(NativeRegExp regexp) {
    HashMap<String,Object> params = new HashMap<>();
    String text = regexp.toString();
    params.put("regexp", text);
    JSONObject result = pizzaHandler.sendCommand("verifyTitle", params);
    if (!getResponseBoolean(result)) {
        throw new ScriptException(String.format("Page title did not match %s", text));
    }
}
项目:pizzascript    文件:ChromeBrowser.java   
@Override
public void verifyRequest(NativeRegExp regExp) {
    pizzaHandler.verifyRequest(regExp);
}
项目:pizzascript    文件:ChromeWebSocket.java   
public void verifyRequest(NativeRegExp regExp) {
    if (regExp == null) {
        throw new ScriptException("regex null");
    }

    String regexp = regExp.toString();
    int start = 0;
    int end = 0;
    if (regexp.startsWith("/")) {
        start = 1;
    }

    if (regexp.endsWith("/")) {
        end = regexp.length() - 1;
    }

    regexp = regexp.substring(start, end);
    Pattern p = Pattern.compile(regexp);
    boolean found = false;
    synchronized (testResult) {
        Page page = getCurrentPage();
        if (page == null) {
            throw new ScriptException("No page found");
        }

        for (HttpRequest request : page.requests) {
            String url = request.getUrl();
            if (url != null) {
                Matcher m = p.matcher(url);
                if (m.find()) {
                    verifyRequest(url, request);
                    found = true;
                }
            }
        }
    }

    if (!found) {
        throw new ScriptException(String.format("Unable to find request matching '%s'",
            regexp));
    }
}
项目:minium    文件:MiniumBackend.java   
public void addStepDefinition(Global jsStepDefinition, NativeRegExp regexp, NativeFunction bodyFunc, NativeFunction argumentsFromFunc) throws Throwable {
    StackTraceElement stepDefLocation = jsLocation();
    RhinoStepDefinition stepDefinition = new RhinoStepDefinition(cx, scope, jsStepDefinition, regexp, bodyFunc, stepDefLocation, argumentsFromFunc);
    glue.addStepDefinition(stepDefinition);
}
项目:alfresco-enhanced-script-environment    文件:NativeStringMethodSwitchInterceptor.java   
/**
 * {@inheritDoc}
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable
{
    Object result;

    final Object _this = invocation.getThis();
    if (_this instanceof NativeJavaMethod)
    {
        final Object[] arguments = invocation.getArguments();

        final Method method = invocation.getMethod();
        final String metaMethodName = method.getName();
        final String calledFnName = ((NativeJavaMethod) _this).getFunctionName();
        if ("call".equals(metaMethodName))
        {
            // signature is call(Context cs, Scriptable scope, Scriptable thisObj, Object[] args)
            final Scriptable scope = (Scriptable) arguments[1];
            final Object _stringThis = arguments[2];
            final Object[] fnArgs = (Object[]) arguments[3];

            String backingString = null;
            if (_stringThis instanceof NativeJavaObject)
            {
                final Object unwrapped = ((NativeJavaObject) _stringThis).unwrap();
                if (unwrapped instanceof String)
                {
                    backingString = (String) unwrapped;
                }
            }

            if (backingString != null)
            {
                if (REGEX_FN_NAMES.contains(calledFnName) && fnArgs[0] instanceof NativeRegExp)
                {
                    final Scriptable nativeString = ScriptRuntime.toObject(Context.getCurrentContext(), scope, backingString);
                    result = ScriptableObject.callMethod(nativeString, calledFnName, fnArgs);
                }
                // TODO Need to handle other fn/method constellations
                else
                {
                    result = invocation.proceed();
                }
            }
            else
            {
                result = invocation.proceed();
            }
        }
        else
        {
            result = invocation.proceed();
        }
    }
    else
    {
        result = invocation.proceed();
    }

    return result;
}
项目:pizzascript    文件:Browser.java   
/**
 * Verify some text on the page matches the given regular expression.
 * <p>
 * An exception is thrown if no text matches the regexp.
 *
 * @param regexp the regex to search for in the page text
 */
void verifyText(NativeRegExp regexp);
项目:pizzascript    文件:Browser.java   
/**
 * Verify that the text of the page does not match the given regular expression.
 * <p>
 * An exception is thrown if there is a match.
 *
 * @param regexp the regex to search for in the page text
 */
void verifyNotText(NativeRegExp regexp);
项目:pizzascript    文件:Browser.java   
/**
 * Verify the page title matches the given regular expression.
 *
 * @param regexp the regex to match against the title
 */
void verifyTitle(NativeRegExp regexp);
项目:pizzascript    文件:Browser.java   
void verifyRequest(NativeRegExp regExp);