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:co.runrightfast.vertx.orientdb.config.OAutomaticBackupConfig.java

private void validate() {
    if (!enabled) {
        return;/*from w ww .  j ava 2  s.  c  o  m*/
    }
    checkArgument(isNotBlank(firstTime), MUST_NOT_BE_BLANK, "firstTime");
    final String firstTimePattern = "\\d\\d:\\d\\d:\\d\\d";
    checkArgument(Pattern.matches(firstTimePattern, firstTime), PATTERN_DOES_NOT_MATCH, "firstTime",
            firstTimePattern);
    checkArgument(compressionLevel >= 0 && compressionLevel <= 9, MUST_BE_WITHIN_RANGE, 0, 9);
    checkArgument(bufferSizeMB > 0, MUST_BE_GREATER_THAN_ZERO, "bufferSizeMB");
}

From source file:cx.fbn.nevernote.sql.REnSearch.java

private boolean matchTagsAll(List<String> tagNames, List<String> list) {

    for (int j = 0; j < list.size(); j++) {
        boolean negative = false;
        negative = false;/*from  w  w w .ja v  a 2s .co  m*/
        if (list.get(j).startsWith("-"))
            negative = true;
        int pos = list.get(j).indexOf(":");
        String filterName = cleanupWord(list.get(j).substring(pos + 1));
        filterName = filterName.replace("*", ".*"); // setup for regular expression pattern match

        if (tagNames.size() == 0 && !negative)
            return false;

        boolean matchFound = false;
        for (int i = 0; i < tagNames.size(); i++) {
            boolean matches = Pattern.matches(filterName.toLowerCase(), tagNames.get(i).toLowerCase());
            if (matches)
                matchFound = true;
        }
        if (negative)
            matchFound = !matchFound;
        if (!matchFound)
            return false;
    }
    return true;
}

From source file:org.opennms.ng.dao.support.InterfaceSnmpResourceType.java

private ArrayList<OnmsResource> populateResourceList(File parent, File relPath, OnmsNode node,
        Boolean isForeign) {/*from   w  w  w.  j a  v a  2  s  .  c o  m*/

    ArrayList<OnmsResource> resources = new ArrayList<OnmsResource>();

    File[] intfDirs = parent.listFiles(RrdFileConstants.INTERFACE_DIRECTORY_FILTER);

    Set<OnmsSnmpInterface> snmpInterfaces = node.getSnmpInterfaces();
    Map<String, OnmsSnmpInterface> intfMap = new HashMap<String, OnmsSnmpInterface>();

    for (OnmsSnmpInterface snmpInterface : snmpInterfaces) {
        /*
         * When Cisco Express Forwarding (CEF) or some ATM encapsulations
         * (AAL5) are used on Cisco routers, an additional entry might be 
         * in the ifTable for these sub-interfaces, but there is no
         * performance data available for collection.  This check excludes
         * ifTable entries where ifDescr contains "-cef".  See bug #803.
         */
        if (snmpInterface.getIfDescr() != null) {
            if (Pattern.matches(".*-cef.*", snmpInterface.getIfDescr())) {
                continue;
            }
        }

        String replacedIfName = AlphaNumeric.parseAndReplace(snmpInterface.getIfName(), '_');
        String replacedIfDescr = AlphaNumeric.parseAndReplace(snmpInterface.getIfDescr(), '_');

        String[] keys = new String[] { replacedIfName + "-", replacedIfDescr + "-",
                replacedIfName + "-" + snmpInterface.getPhysAddr(),
                replacedIfDescr + "-" + snmpInterface.getPhysAddr() };

        for (String key : keys) {
            if (!intfMap.containsKey(key)) {
                intfMap.put(key, snmpInterface);
            }
        }
    }

    for (File intfDir : intfDirs) {
        String name = intfDir.getName();

        String desc = name;
        String mac = "";

        // Strip off the MAC address from the end, if there is one
        int dashIndex = name.lastIndexOf("-");

        if (dashIndex >= 0) {
            desc = name.substring(0, dashIndex);
            mac = name.substring(dashIndex + 1, name.length());
        }

        String key = desc + "-" + mac;
        OnmsSnmpInterface snmpInterface = intfMap.get(key);

        String label;
        Long ifSpeed = null;
        String ifSpeedFriendly = null;
        if (snmpInterface == null) {
            label = name + " (*)";
        } else {
            StringBuffer descr = new StringBuffer();
            StringBuffer parenString = new StringBuffer();

            if (snmpInterface.getIfAlias() != null) {
                parenString.append(snmpInterface.getIfAlias());
            }
            // Append all of the IP addresses on this ifindex
            for (OnmsIpInterface ipif : snmpInterface.getIpInterfaces()) {
                String ipaddr = InetAddressUtils.str(ipif.getIpAddress());
                if (!"0.0.0.0".equals(ipaddr)) {
                    if (parenString.length() > 0) {
                        parenString.append(", ");
                    }
                    parenString.append(ipaddr);
                }
            }
            if ((snmpInterface.getIfSpeed() != null) && (snmpInterface.getIfSpeed() != 0)) {
                ifSpeed = snmpInterface.getIfSpeed();
                ifSpeedFriendly = SIUtils.getHumanReadableIfSpeed(ifSpeed);
                if (parenString.length() > 0) {
                    parenString.append(", ");
                }
                parenString.append(ifSpeedFriendly);
            }

            if (snmpInterface.getIfName() != null) {
                descr.append(snmpInterface.getIfName());
            } else if (snmpInterface.getIfDescr() != null) {
                descr.append(snmpInterface.getIfDescr());
            } else {
                /*
                 * Should never reach this point, since ifLabel is based on
                 * the values of ifName and ifDescr but better safe than sorry.
                 */
                descr.append(name);
            }

            /* Add the extended information in parenthesis after the ifLabel,
             * if such information was found.
             */
            if (parenString.length() > 0) {
                descr.append(" (");
                descr.append(parenString);
                descr.append(")");
            }

            label = descr.toString();
        }

        OnmsResource resource = null;
        if (isForeign) {
            resource = getResourceByNodeSourceAndInterface(relPath.toString(), intfDir.getName(), label,
                    ifSpeed, ifSpeedFriendly);
        } else {
            resource = getResourceByNodeAndInterface(node.getId(), intfDir.getName(), label, ifSpeed,
                    ifSpeedFriendly);
        }
        if (snmpInterface != null) {
            Set<OnmsIpInterface> ipInterfaces = snmpInterface.getIpInterfaces();
            if (ipInterfaces.size() > 0) {
                int id = ipInterfaces.iterator().next().getId();
                resource.setLink("element/interface.jsp?ipinterfaceid=" + id);
            } else {
                int ifIndex = snmpInterface.getIfIndex();
                if (ifIndex > -1) {
                    resource.setLink(
                            "element/snmpinterface.jsp?node=" + node.getNodeId() + "&ifindex=" + ifIndex);
                }
            }

            resource.setEntity(snmpInterface);
        } else {
            LOG.debug("populateResourceList: snmpInterface is null");
        }
        LOG.debug("populateResourceList: adding resource toString {}", resource.toString());
        resources.add(resource);
    }

    return resources;
}

From source file:jp.primecloud.auto.service.impl.FarmServiceImpl.java

/**
 * {@inheritDoc}/*from   ww  w .  ja v a2 s .c o  m*/
 */
@Override
public Long createFarm(Long userNo, String farmName, String comment) {
    // ?
    if (userNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "userNo");
    }
    if (farmName == null || farmName.length() == 0) {
        throw new AutoApplicationException("ECOMMON-000003", "farmName");
    }

    // ??
    if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", farmName)) {
        throw new AutoApplicationException("ECOMMON-000012", "farmName");
    }

    // TODO: ??

    // ?????
    Farm checkFarm = farmDao.readByFarmName(farmName);
    if (checkFarm != null) {
        // ???????
        throw new AutoApplicationException("ESERVICE-000201", farmName);
    }

    // ???
    // TODO: ???????
    String domainName = farmName + "." + Config.getProperty("dns.domain");

    // ??
    Farm farm = new Farm();
    farm.setFarmName(farmName);
    farm.setUserNo(userNo);
    farm.setComment(comment);
    farm.setDomainName(domainName);
    farm.setScheduled(false);
    farm.setComponentProcessing(false);
    farmDao.create(farm);

    List<Platform> platforms = platformDao.readAll();
    for (Platform platform : platforms) {
        // TODO CLOUD BRANCHING
        // VMware??
        if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) {
            if (vmwareKeyPairDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0) {
                // ???VLAN?
                VmwareNetwork publicNetwork = null;
                VmwareNetwork privateNetwork = null;
                List<VmwareNetwork> vmwareNetworks = vmwareNetworkDao
                        .readByPlatformNo(platform.getPlatformNo());
                for (VmwareNetwork vmwareNetwork : vmwareNetworks) {
                    if (vmwareNetwork.getFarmNo() != null) {
                        continue;
                    }
                    if (BooleanUtils.isTrue(vmwareNetwork.getPublicNetwork())) {
                        if (publicNetwork == null) {
                            publicNetwork = vmwareNetwork;
                        }
                    } else {
                        if (privateNetwork == null) {
                            privateNetwork = vmwareNetwork;
                        }
                    }
                }

                // VLAN?
                if (publicNetwork != null) {
                    publicNetwork.setFarmNo(farm.getFarmNo());
                    vmwareNetworkDao.update(publicNetwork);
                }
                if (privateNetwork != null) {
                    privateNetwork.setFarmNo(farm.getFarmNo());
                    vmwareNetworkDao.update(privateNetwork);
                }
            }
            // VCloud??
        } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType())) {
            //????????????vApp??
            if (BooleanUtils.isTrue(platform.getSelectable())
                    && vcloudCertificateDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0
                    && vcloudKeyPairDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0) {
                //vApp?
                IaasGatewayWrapper gateway = iaasGatewayFactory.createIaasGateway(userNo,
                        platform.getPlatformNo());
                gateway.createMyCloud(farmName);
            }
            // Azure??
        } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) {
            // ????
            // OpenStack??
        } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) {
            // ????
        }
    }

    // VCloud?(iaasGateWay??????)??Zabbix????????
    // ????
    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isTrue(useZabbix)) {
        zabbixHostProcess.createFarmHostgroup(farm.getFarmNo());
    }

    // 
    eventLogger.log(EventLogLevel.INFO, farm.getFarmNo(), farmName, null, null, null, null, "FarmCreate", null,
            null, null);

    return farm.getFarmNo();
}

From source file:ch.entwine.weblounge.common.impl.site.ModuleImpl.java

/**
 * {@inheritDoc}/*from   www. ja  v  a  2 s .c  o m*/
 * 
 * @see ch.entwine.weblounge.common.site.Module#setIdentifier(java.lang.String)
 */
public void setIdentifier(String identifier) {
    if (identifier == null)
        throw new IllegalArgumentException("Module identifier must not be null");
    else if (!Pattern.matches(MODULE_IDENTIFIER_REGEX, identifier))
        throw new IllegalArgumentException("Module identifier '" + identifier + "' is malformed");
    this.identifier = identifier;
}

From source file:com.cloud.network.resource.NuageVspResource.java

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

    _name = (String) params.get("name");
    if (_name == null) {
        throw new ConfigurationException("Unable to find name");
    }/*ww  w .  j  a v a2s .  c  o  m*/

    _guid = (String) params.get("guid");
    if (_guid == null) {
        throw new ConfigurationException("Unable to find the guid");
    }

    _zoneId = (String) params.get("zoneId");
    if (_zoneId == null) {
        throw new ConfigurationException("Unable to find zone");
    }

    String hostname = (String) params.get("hostname");
    if (hostname == null) {
        throw new ConfigurationException("Unable to find hostname");
    }

    String cmsUser = (String) params.get("cmsuser");
    if (cmsUser == null) {
        throw new ConfigurationException("Unable to find CMS username");
    }

    String cmsUserPassBase64 = (String) params.get("cmsuserpass");
    if (cmsUserPassBase64 == null) {
        throw new ConfigurationException("Unable to find CMS password");
    }

    String port = (String) params.get("port");
    if (port == null) {
        throw new ConfigurationException("Unable to find port");
    }

    String apiRelativePath = (String) params.get("apirelativepath");
    if ((apiRelativePath != null) && (!apiRelativePath.isEmpty())) {
        String apiVersion = apiRelativePath.substring(apiRelativePath.lastIndexOf('/') + 1);
        if (!Pattern.matches("v\\d+_\\d+", apiVersion)) {
            throw new ConfigurationException("Incorrect API version");
        }
    } else {
        throw new ConfigurationException("Unable to find API version");
    }

    String retryCount = (String) params.get("retrycount");
    if ((retryCount != null) && (!retryCount.isEmpty())) {
        try {
            _numRetries = Integer.parseInt(retryCount);
        } catch (NumberFormatException ex) {
            throw new ConfigurationException("Number of retries has to be between 1 and 10");
        }
        if ((_numRetries < 1) || (_numRetries > 10)) {
            throw new ConfigurationException("Number of retries has to be between 1 and 10");
        }
    } else {
        throw new ConfigurationException("Unable to find number of retries");
    }

    String retryInterval = (String) params.get("retryinterval");
    if ((retryInterval != null) && (!retryInterval.isEmpty())) {
        try {
            _retryInterval = Integer.parseInt(retryInterval);
        } catch (NumberFormatException ex) {
            throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
        }
        if ((_retryInterval < 0) || (_retryInterval > 10000)) {
            throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
        }
    } else {
        throw new ConfigurationException("Unable to find retry interval");
    }

    _relativePath = new StringBuffer().append("https://").append(hostname).append(":").append(port)
            .append(apiRelativePath).toString();

    String cmsUserPass = org.apache.commons.codec.binary.StringUtils
            .newStringUtf8(Base64.decodeBase64(cmsUserPassBase64));
    _cmsUserInfo = new String[] { CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass };

    try {
        loadNuageClient();
    } catch (Exception e) {
        throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
    }

    try {
        login();
    } catch (Exception e) {
        s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser + " Exception "
                + e.getMessage());
        throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
    }

    return true;
}

From source file:controllers.WidgetAdmin.java

private static String isPasswordStrongEnough(String password, String email) {
    if (StringUtils.length(password) < 8) {
        return "Password is too short";
    }//from w  w  w.j  av a 2 s .c o m
    if (!Pattern.matches("(?=^.{8,}$)((?=.*\\d)|(?=.*\\W+))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$", password)
            && !StringUtils.containsIgnoreCase(email, password)) {
        return "Password must match requirements";
    }

    Set<String> strSet = new HashSet<String>();
    for (String s : password.split("")) {
        if (StringUtils.length(s) > 0) {
            strSet.add(s.toLowerCase());
        }
    }

    if (CollectionUtils.size(strSet) < 3) {
        return "Too many repeating letters";
    }

    if (StringUtils.getLevenshteinDistance(password, email.split("@")[0]) < 5
            || StringUtils.getLevenshteinDistance(password, email.split("@")[1]) < 5) {
        return "Password similar to email";
    }

    return null;
}

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

/**
 * ?IP?(???192.168.1.1127.0.0.1?IP?)//from  ww w  . j  ava 2 s . c om
 *
 * @param ipAddress IPv4?
 * @return ??true?false
 */
public static boolean isIpAddress(String ipAddress) {
    if (StringUtils.isNotBlank(ipAddress)) {
        String regex = "[1-9](\\d{1,2})?\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))\\.(0|([1-9](\\d{1,2})?))";
        return Pattern.matches(regex, ipAddress);
    }
    return false;
}

From source file:io.dacopancm.socketdcm.helper.HelperUtil.java

public static boolean isValidText(String text, String regex) {
    // text required and editText is blank, so return false
    if (text.equalsIgnoreCase("")) {
        return false;
    }//from  w ww  . jav a  2  s  .c o  m
    return Pattern.matches(regex, text);
}

From source file:com.appcel.core.converter.locator.ConverterLocator.java

/**
  * ?OpenOffice/*from www  . j  av a2  s  . c o  m*/
  * @return
 */
protected String getOfficeHome() {
    String osName = System.getProperty("os.name");
    if (Pattern.matches("Linux.*", osName)) {
        return "/opt/openoffice.org3";
    } else if (Pattern.matches("Windows.*", osName)) {
        return "C:/Program Files (x86)/OpenOffice 4";//"E:/software/OpenOffice 4";
    } else if (Pattern.matches("Mac.*", osName)) {
        return "/Application/OpenOffice.org.app/Contents";
    }
    return null;
}