Example usage for java.util.regex Pattern matches

List of usage examples for java.util.regex Pattern matches

Introduction

In this page you can find the example usage for java.util.regex Pattern matches.

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:com.cyclopsgroup.waterview.valves.RenderPageValve.java

/**
 * Override or implement method of parent class or interface
 *
 * @see com.cyclopsgroup.waterview.Valve#invoke(com.cyclopsgroup.waterview.PageRuntime, com.cyclopsgroup.waterview.PipelineContext)
 *//*from   www. j av a 2 s.co  m*/
public void invoke(PageRuntime runtime, PipelineContext context) throws Exception {
    DynaViewFactory viewFactory = null;
    for (Iterator i = viewFactories.keySet().iterator(); i.hasNext();) {
        String pattern = (String) i.next();
        if (Pattern.matches('^' + pattern + '$', runtime.getPage())) {
            viewFactory = (DynaViewFactory) viewFactories.get(pattern);
            break;
        }
    }
    if (viewFactory != null) {
        runtime.getPageContext().put(DynaViewFactory.NAME, viewFactory);
    }

    runtime.setOutputContentType("text/html");
    ModuleManager mm = (ModuleManager) runtime.getServiceManager().lookup(ModuleManager.ROLE);
    Page page = (Page) runtime.getPageContext().get(Page.NAME);
    if (page != null) {
        page.execute(runtime, runtime.getPageContext());
        mm.getDefaultFrame().execute(runtime, runtime.getPageContext());
        mm.getDefaultFrame().display(page, runtime);
    }
    context.invokeNextValve(runtime);
    runtime.getOutput().flush();
}

From source file:com.nextgis.woody.fragment.LoginFragment.java

private void validatePassword(String password) {
    if (!Pattern.matches(Constants.PASSWORD_PATTERN, password) && password.length() > 0)
        ((TextInputLayout) mPassword.getParent()).setError(getString(R.string.error_weak_password));
    else/*from   w  w w . jav a  2s  .c  om*/
        ((TextInputLayout) mPassword.getParent()).setErrorEnabled(false);
}

From source file:com.aoeng.degu.utils.net.asyncthhpclient.BinaryHttpResponseHandler.java

@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    if (contentTypeHeaders.length != 1) {
        //malformed/ambiguous HTTP Header, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(
                status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
        return;//from  w ww.j a  v a  2 s  .  co m
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : getAllowedContentTypes()) {
        try {
            if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
                foundAllowedContentType = true;
            }
        } catch (PatternSyntaxException e) {
            Log.e("BinaryHttpResponseHandler", "Given pattern is not valid: " + anAllowedContentType, e);
        }
    }
    if (!foundAllowedContentType) {
        //Content-Type not in allowed list, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
                new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
        return;
    }
    super.sendResponseMessage(response);
}

From source file:gov.nist.healthcare.ttt.webapp.common.controller.GetCCDADocumentsController.java

public void buildJson(HashMap<String, Object> json, String[] path) {
    if (path.length == 1) {
        HashMap<String, Object> newObj = new HashMap<>();
        newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
        newObj.put("files", new ArrayList<HashMap<String, Object>>());
        json.put(path[0], newObj);/*w w  w.  j a  v a  2 s . c  o m*/

    } else {
        HashMap<String, Object> current = (HashMap<String, Object>) json.get(path[0]);
        for (int i = 1; i < path.length; i++) {
            String currentName = path[i];
            if (Pattern.matches(extensionRegex, currentName)) {
                HashMap<String, Object> newFile = new HashMap<>();
                newFile.put("name", currentName);
                newFile.put("link", getLink(path));
                List filesList = (List) current.get("files");
                filesList.add(newFile);
            } else {
                if (containsName((List<Map>) current.get("dirs"), currentName)) {
                    List<Map> directories = (List<Map>) current.get("dirs");
                    current = (HashMap<String, Object>) directories.get(getObjByName(directories, currentName));
                } else {
                    HashMap<String, Object> newObj = new HashMap<>();
                    newObj.put("name", currentName);
                    newObj.put("dirs", new ArrayList<HashMap<String, Object>>());
                    newObj.put("files", new ArrayList<HashMap<String, Object>>());
                    List dirsList = (List) current.get("dirs");
                    dirsList.add(newObj);
                }
            }
        }
    }
}

From source file:com.google.api.codegen.discovery.MainDiscoveryProviderFactory.java

public static DiscoveryProvider defaultCreate(Service service, ApiaryConfig apiaryConfig,
        JsonNode sampleConfigOverrides, String id) {
    // Use nodes corresponding to language pattern fields matching current language.
    List<JsonNode> overrides = new ArrayList<JsonNode>();
    // Sort patterns to ensure deterministic ordering of overrides
    if (sampleConfigOverrides != null) {
        List<String> languagePatterns = Lists.newArrayList(sampleConfigOverrides.fieldNames());
        Collections.sort(languagePatterns);
        for (String languagePattern : languagePatterns) {
            if (Pattern.matches(languagePattern, id)) {
                overrides.add(sampleConfigOverrides.get(languagePattern));
            }/*from   ww w.j av  a 2 s.  c o m*/
        }
    }

    SampleMethodToViewTransformer sampleMethodToViewTransformer = null;
    TypeNameGenerator typeNameGenerator = null;
    try {
        sampleMethodToViewTransformer = SAMPLE_METHOD_TO_VIEW_TRANSFORMER_MAP.get(id).newInstance();
        typeNameGenerator = TYPE_NAME_GENERATOR_MAP.get(id).newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    if (sampleMethodToViewTransformer == null || typeNameGenerator == null) {
        throw new NotImplementedException("MainDiscoveryProviderFactory: invalid id \"" + id + "\"");
    }

    return ViewModelProvider.newBuilder().setMethods(service.getApis(0).getMethodsList())
            .setApiaryConfig(apiaryConfig)
            .setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil()))
            .setMethodToViewTransformer(sampleMethodToViewTransformer).setOverrides(overrides)
            .setTypeNameGenerator(typeNameGenerator).setOutputRoot("autogenerated/" + apiaryConfig.getApiName()
                    + "/" + apiaryConfig.getApiVersion() + "/" + service.getDocumentation().getOverview())
            .build();
}

From source file:org.amanzi.splash.ui.wizards.ExportSplashToCsvWizard.java

/**
 *
 * @param v
 * @return
 */
private boolean needQuote(String v) {
    return !Pattern.matches("\\d*\\.{0,1}\\d*", v);
}

From source file:com.android.yijiang.kzx.http.BinaryHttpResponseHandler.java

@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders(AsyncHttpClient.HEADER_CONTENT_TYPE);
    if (contentTypeHeaders.length != 1) {
        //malformed/ambiguous HTTP Header, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(
                status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
        return;/* w  ww. ja v a 2  s.c  o  m*/
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : getAllowedContentTypes()) {
        try {
            if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
                foundAllowedContentType = true;
            }
        } catch (PatternSyntaxException e) {
            Log.e("BinaryHttpResponseHandler", "Given pattern is not valid: " + anAllowedContentType, e);
        }
    }
    if (!foundAllowedContentType) {
        //Content-Type not in allowed list, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
                new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
        return;
    }
    super.sendResponseMessage(response);
}

From source file:net.spfbl.whois.Owner.java

public static String normalizeID(String id) throws ProcessException {
    if (id == null) {
        return null;
    } else if (Pattern.matches("^[0-9]{3}\\.[0-9]{3}\\.[0-9]{3}-[0-9]{2}$", id)) {
        return id;
    } else if (Pattern.matches("^[0-9]{3}\\.[0-9]{3}\\.[0-9]{3}/[0-9]{4}-[0-9]{2}$", id)) {
        return id;
    } else if (Pattern.matches("^[0-9]{2}\\.[0-9]{3}\\.[0-9]{3}/[0-9]{4}-[0-9]{2}$", id)) {
        return "0" + id;
    } else {/*from ww w .  ja va 2s. c o  m*/
        throw new ProcessException("ERROR: INVALID ID");
    }
}

From source file:com.yunmall.ymsdk.net.http.BinaryHttpResponseHandler.java

@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    if (contentTypeHeaders.length != 1) {
        //malformed/ambiguous HTTP Header, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(
                status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
        return;/*from   w w w  . ja v  a2  s .c o m*/
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : getAllowedContentTypes()) {
        try {
            if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
                foundAllowedContentType = true;
            }
        } catch (PatternSyntaxException e) {
            YmLog.e("BinaryHttpResponseHandler", "Given pattern is not valid: " + anAllowedContentType, e);
        }
    }
    if (!foundAllowedContentType) {
        //Content-Type not in allowed list, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
                new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
        return;
    }
    super.sendResponseMessage(response);
}

From source file:com.flyn.net.asynchttp.BinaryHttpResponseHandler.java

@Override
public final void sendResponseMessage(HttpResponse response) throws IOException {
    StatusLine status = response.getStatusLine();
    Header[] contentTypeHeaders = response.getHeaders("Content-Type");
    if (contentTypeHeaders.length != 1) {
        // malformed/ambiguous HTTP Header, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null, new HttpResponseException(
                status.getStatusCode(), "None, or more than one, Content-Type Header found!"));
        return;/*from  w  ww  .j  a  v  a  2s  .  c  o  m*/
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : getAllowedContentTypes()) {
        try {
            if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
                foundAllowedContentType = true;
            }
        } catch (PatternSyntaxException e) {
            Log.e("BinaryHttpResponseHandler", "Given pattern is not valid: " + anAllowedContentType, e);
        }
    }
    if (!foundAllowedContentType) {
        // Content-Type not in allowed list, ABORT!
        sendFailureMessage(status.getStatusCode(), response.getAllHeaders(), null,
                new HttpResponseException(status.getStatusCode(), "Content-Type not allowed!"));
        return;
    }
    super.sendResponseMessage(response);
}