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:org.apache.eagle.service.security.hdfs.resolver.MAPRStatusCodeResolver.java

@Override
public void validateRequest(GenericAttributeResolveRequest request) throws BadAttributeResolveRequestException {
    String query = request.getQuery();
    boolean matched = Pattern.matches("[a-zA-Z]+", query);
    if (query == null || !matched) {
        throw new BadAttributeResolveRequestException(MAPRFS_STATUS_CODE_RESOLVE_FORMAT_HINT);
    }/*from   w w  w .j  a  v a  2  s  .  co  m*/
}

From source file:cn.edu.zzu.wemall.http.BinaryHttpResponseHandler.java

@Override
protected 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 va  2 s.co m*/
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : mAllowedContentTypes) {
        if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
            foundAllowedContentType = true;
        }
    }
    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:fit.TypeAdapter.java

public boolean equals(Object a, Object b) {
    boolean isEqual;

    if (isRegex)/*from  ww w  .j  a v  a  2s  . c om*/
        isEqual = Pattern.matches(a.toString(), b.toString());
    else {
        if (a == null)
            isEqual = (b == null);
        else
            isEqual = a.equals(b);
    }
    return isEqual;
}

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.WebDavExplorer.java

public static List<Source> getFilesFrom(Repository repository)
        throws IOException, DavException, PanelException {
    List<Source> repositoryFiles = new LinkedList<Source>();

    IOException ioe = null;//  w  w  w  .  j  a  va 2 s.c om
    DavException dee = null;

    String user = repository.getUser();
    String pass = repository.getPassword();
    String url = repository.getUrl();

    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(url)) {
        throw new PanelException("La url del repositorio no es vlida: " + url);
    }

    HttpClient client = new HttpClient();

    if (!StringUtils.isEmpty(user) || !StringUtils.isEmpty(pass)) {
        Credentials creds = new UsernamePasswordCredentials(user, pass);
        client.getState().setCredentials(AuthScope.ANY, creds);
    }

    DavMethod lsMethod = null;
    try {

        lsMethod = new PropFindMethod(url, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
        client.executeMethod(lsMethod);
        MultiStatus multiStatus = lsMethod.getResponseBodyAsMultiStatus();
        for (MultiStatusResponse msResponse : multiStatus.getResponses()) {
            // gets properties from the remote resource
            String sourceUrl = null, sourceName = null, sourceCType = null;
            Integer sourceSize = -1;
            FileType sourceType = null;

            DavPropertySet properties = msResponse.getProperties(200);

            // url
            sourceUrl = msResponse.getHref();
            // name
            DavProperty<?> propName = properties.get(DavPropertyName.DISPLAYNAME);
            if (propName != null) {
                sourceName = (String) propName.getValue();
            }
            if (StringUtils.isEmpty(sourceName)) {
                sourceName = Utils.getFileNameFromPath(sourceUrl);
            }
            // size
            DavProperty<?> propLength = properties.get(DavPropertyName.GETCONTENTLENGTH);
            if (propLength != null) {
                String sizeStr = (String) propLength.getValue();
                try {
                    sourceSize = Integer.parseInt(sizeStr);
                } catch (NumberFormatException e) {
                    // none
                }
            }
            // content-type
            DavProperty<?> propCType = properties.get(DavPropertyName.GETCONTENTTYPE);
            if (propCType != null) {
                sourceCType = (String) propCType.getValue();
            }
            // type
            sourceType = Utils.getTypeFromContentType(sourceCType);
            if (sourceType == FileType.UNKNOW) {
                sourceType = Utils.getTypeFromName(sourceName);
            }
            // creates the source and adds it to the list
            if (sourceType != null) {
                boolean validShape = ((sourceType == FileType.SHAPEFILE)
                        && (Pattern.matches("^.+\\.shp$", sourceName.toLowerCase())));
                boolean validCSV = (sourceType == FileType.CSV);
                boolean validFile = (validShape || validCSV || Utils.isCompressedFile(sourceCType));
                if (validFile) {
                    Source source = new Source();
                    source.setRemote(true);
                    source.setName(sourceName);
                    source.setSize(sourceSize);
                    source.setContentType(sourceCType);
                    source.setType(sourceType);
                    // repository
                    source.setAlias(repository.getAlias());
                    source.setUrl(repository.getUrl());
                    source.setUser(repository.getUser());
                    source.setPassword(repository.getPassword());
                    repositoryFiles.add(source);
                }
            }
        }
    } catch (IOException e) {
        ioe = e;
    } catch (DavException e) {
        dee = e;
    } finally {
        if (lsMethod != null) {
            lsMethod.releaseConnection();
        }
    }

    if (ioe != null) {
        throw ioe;
    }

    if (dee != null) {
        throw dee;
    }

    return repositoryFiles;
}

From source file:com.wyb.utils.util.PatternUtil.java

/**
 * ?// w ww .ja va 2s .com
 *
 * @param birthday ?1992-09-031992.09.03
 * @return ??true?false
 */
public static boolean isBirthday(String birthday) {
    if (StringUtils.isNotBlank(birthday)) {
        String regex = "^(\\d{4})-(\\d{2})-(\\d{2})$";
        return Pattern.matches(regex, birthday);
    }
    return false;
}

From source file:com.ab.http.BinaryHttpResponseHandler.java

/**
 * ??TODO/*w  w  w.j a  v a  2 s  .c om*/
 * @see com.ab.http.AsyncHttpResponseHandler#sendResponseMessage(org.apache.http.HttpResponse)
 * @author: zhaoqp
 * @date2013-10-22 ?4:23:15
 * @version v1.0
 */
@Override
protected 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;
    }
    Header contentTypeHeader = contentTypeHeaders[0];
    boolean foundAllowedContentType = false;
    for (String anAllowedContentType : mAllowedContentTypes) {
        if (Pattern.matches(anAllowedContentType, contentTypeHeader.getValue())) {
            foundAllowedContentType = true;
        }
    }
    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:org.opennms.ng.dao.support.ResourceTypeUtils.java

/**
 * <p>isResponseTime</p>/* w  ww.j  ava 2  s . c o  m*/
 *
 * @param relativePath a {@link String} object.
 * @return a boolean.
 */
public static boolean isResponseTime(String relativePath) {
    return Pattern.matches("^" + DefaultResourceDao.RESPONSE_DIRECTORY + ".+$", relativePath);
}

From source file:cn.rongcloud.im.server.network.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;/* w w w  . j  a v  a 2s . 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) {
        }
    }
    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.nutsuser.ridersdomain.http.BinaryHttpResponseHandler.java

@Override
protected 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;/*ww w .j ava 2 s.c om*/
    }
    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:com.fanniemae.ezpie.common.StringUtilities.java

public static boolean isLong(String value) {
    if (isNullOrEmpty(value))
        return false;
    value = value.trim();/*from   ww  w.j a  v a 2s.co  m*/
    return (Pattern.matches("^[+-]?\\d+$", value) && (value.length() <= 17));
}