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.orange.ngsi2.server.Ngsi2BaseControllerTest.java

@Test
public void checkPattern() {
    assertTrue(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn_Welt"));
    assertTrue(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn-Welt"));
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn Welt"));
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn&Welt"));
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn?Welt"));
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn/Welt"));
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", "Bcn#Welt"));

    String p257times = IntStream.range(0, 257).mapToObj(x -> "p").collect(Collectors.joining());
    assertTrue(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", p257times));
    String invalid256times = IntStream.range(0, 256).mapToObj(x -> "?").collect(Collectors.joining());
    assertFalse(Pattern.matches("[\\x21\\x22\\x24\\x25\\x27-\\x2E\\x30-\\x3E\\x40-\\x7E]*", invalid256times));
}

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

protected void updateInstance(Long instanceNo, String instanceName, String comment) {
    // ?/*from   ww  w  .ja va2  s  .  c o m*/
    if (instanceNo == null) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceNo");
    }
    if (instanceName == null || instanceName.length() == 0) {
        throw new AutoApplicationException("ECOMMON-000003", "instanceName");
    }

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

    // TODO: ??

    // ??
    Instance instance = instanceDao.read(instanceNo);
    if (instance == null) {
        // ?????
        throw new AutoApplicationException("ESERVICE-000403", instanceNo);
    }

    // ??????
    if (InstanceStatus.fromStatus(instance.getStatus()) != InstanceStatus.STOPPED) {
        // ??????????????????
        if (!StringUtils.equals(instance.getInstanceName(), instanceName)) {
            throw new AutoApplicationException("ESERVICE-000407", instance.getInstanceName());
        }
    }

    // ????
    if (!StringUtils.equals(instance.getInstanceName(), instanceName)) {
        // ?????
        Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(instance.getFarmNo(), instanceName);
        if (checkInstance != null && !instanceNo.equals(checkInstance.getInstanceNo())) {
            // ???????
            throw new AutoApplicationException("ESERVICE-000401", instanceName);
        }

        // ?????
        LoadBalancer checkLoadBalancer = loadBalancerDao.readByFarmNoAndLoadBalancerName(instance.getFarmNo(),
                instanceName);
        if (checkLoadBalancer != null) {
            // ????????
            throw new AutoApplicationException("ESERVICE-000417", instanceName);
        }
    }

    // ?
    Farm farm = farmDao.read(instance.getFarmNo());

    instance.setInstanceName(instanceName);
    instance.setComment(comment);
    instance.setFqdn(instanceName + "." + farm.getDomainName());
    instanceDao.update(instance);
}

From source file:com.android.tradefed.device.NativeDevice.java

/**
 * {@inheritDoc}/*from  w ww. jav  a2  s . com*/
 */
@Override
public boolean isEncryptionSupported() throws DeviceNotAvailableException {
    if (!isEnableAdbRoot()) {
        CLog.i("root is required for encryption");
        mIsEncryptionSupported = false;
        return mIsEncryptionSupported;
    }
    if (mIsEncryptionSupported != null) {
        return mIsEncryptionSupported.booleanValue();
    }
    enableAdbRoot();
    String output = executeShellCommand("vdc cryptfs enablecrypto").trim();

    mIsEncryptionSupported = (output != null
            && Pattern.matches("(500)(\\s+)(\\d+)(\\s+)(Usage)(.*)(:)(.*)", output));
    return mIsEncryptionSupported;
}

From source file:fr.univlorraine.mondossierweb.controllers.EtudiantController.java

public List<String> updateContact(String telephone, String mail, String codetu) {
    List<String> retour = new LinkedList<String>();
    boolean erreur = false;
    String message = "";
    if (StringUtils.hasText(telephone) && !Pattern.matches("[0-9[. ]]*", telephone)) {
        message = applicationContext.getMessage("modificationContact.erreur.tel", null, Locale.getDefault());
        retour.add(message);/*from  w  w  w .  j a va  2 s .  co  m*/
        erreur = true;
    }
    if (StringUtils.hasText(mail)
            && !Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$", mail)) {
        message = applicationContext.getMessage("modificationContact.erreur.mail", null, Locale.getDefault());
        retour.add(message);
        erreur = true;
    }

    //Si aucune erreur sur les donnes insres
    if (!erreur) {
        boolean succes = false;
        //On insere dans Apoge
        if (monProxyEtu == null) {
            monProxyEtu = (EtudiantMetierServiceInterface) WSUtils.getService(WSUtils.ETUDIANT_SERVICE_NAME);
        }
        if (monProxyAdministratif == null) {
            monProxyAdministratif = (AdministratifMetierServiceInterface) WSUtils
                    .getService(WSUtils.ADMINISTRATIF_SERVICE_NAME);
        }
        try {
            //recup de l'ancienne et modif dessus:
            String[] annees = monProxyAdministratif.recupererAnneesIa(codetu, null);
            //rcupration de l'anne la plus rcente
            String annee = "0";
            for (int i = 0; i < annees.length; i++) {
                if (Integer.parseInt(annees[i]) > Integer.parseInt(annee)) {
                    annee = annees[i];
                }
            }
            CoordonneesDTO2 cdto = monProxyEtu.recupererAdressesEtudiant_v2(codetu, annee, "N");

            AdresseMajDTO adanmaj = new AdresseMajDTO();
            AdresseMajDTO adfixmaj = new AdresseMajDTO();

            adanmaj.setLibAd1(cdto.getAdresseAnnuelle().getLibAd1());
            adanmaj.setLibAd2(cdto.getAdresseAnnuelle().getLibAd2());
            adanmaj.setLibAd3(cdto.getAdresseAnnuelle().getLibAd3());
            adanmaj.setNumTel(cdto.getAdresseAnnuelle().getNumTel());
            adanmaj.setCodPays(cdto.getAdresseAnnuelle().getPays().getCodPay());
            if (cdto.getAdresseAnnuelle().getCommune() != null) {
                CommuneMajDTO comanmaj = new CommuneMajDTO();
                comanmaj.setCodeInsee(cdto.getAdresseAnnuelle().getCommune().getCodeInsee());
                comanmaj.setCodePostal(cdto.getAdresseAnnuelle().getCommune().getCodePostal());
                adanmaj.setCommune(comanmaj);
            }
            if (StringUtils.hasText(cdto.getAdresseAnnuelle().getLibAde())) {
                adanmaj.setLibAde(cdto.getAdresseAnnuelle().getLibAde());
            }

            adfixmaj.setLibAd1(cdto.getAdresseFixe().getLibAd1());
            adfixmaj.setLibAd2(cdto.getAdresseFixe().getLibAd2());
            adfixmaj.setLibAd3(cdto.getAdresseFixe().getLibAd3());
            adfixmaj.setNumTel(cdto.getAdresseFixe().getNumTel());
            adfixmaj.setCodPays(cdto.getAdresseFixe().getPays().getCodPay());
            if (cdto.getAdresseFixe().getCommune() != null) {
                CommuneMajDTO comfixmaj = new CommuneMajDTO();
                comfixmaj.setCodeInsee(cdto.getAdresseFixe().getCommune().getCodeInsee());
                comfixmaj.setCodePostal(cdto.getAdresseFixe().getCommune().getCodePostal());
                adfixmaj.setCommune(comfixmaj);
            }
            if (StringUtils.hasText(cdto.getAdresseFixe().getLibAde())) {
                adfixmaj.setLibAde(cdto.getAdresseFixe().getLibAde());
            }

            CoordonneesMajDTO cdtomaj = new CoordonneesMajDTO();
            cdtomaj.setAnnee(annee);
            cdtomaj.setTypeHebergement(cdto.getTypeHebergement().getCodTypeHebergement());
            cdtomaj.setEmail(mail);
            cdtomaj.setNumTelPortable(telephone);
            cdtomaj.setAdresseAnnuelle(adanmaj);
            cdtomaj.setAdresseFixe(adfixmaj);

            LOG.debug("==== MAJ ADRESSE ===" + cdto.getAnnee() + " "
                    + cdto.getTypeHebergement().getCodTypeHebergement());
            monProxyEtu.mettreAJourAdressesEtudiant(cdtomaj, codetu);

            succes = true;
        } catch (WebBaseException ex) {
            LOG.error(
                    "Probleme avec le WS lors de la maj des adresses de l'etudiant dont codetu est : " + codetu,
                    ex);
        } catch (Exception ex) {
            LOG.error(
                    "Probleme avec le WS lors de la maj des adresses de l'etudiant dont codetu est : " + codetu,
                    ex);
        }

        if (!succes) {
            message = applicationContext.getMessage("modificationContact.erreur.ws", null, Locale.getDefault());
            retour.add(message);
        } else {
            retour.add("OK");
        }
    }
    return retour;
}

From source file:com.microsoft.azure.management.resources.DeploymentOperationsImpl.java

/**
* Validate a deployment template.// w  ww . j  av a2  s.  c  om
*
* @param resourceGroupName Required. The name of the resource group. The
* name is case insensitive.
* @param deploymentName Required. The name of the deployment.
* @param parameters Required. Deployment to validate.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return Information from validate template deployment response.
*/
@Override
public DeploymentValidateResponse validate(String resourceGroupName, String deploymentName,
        Deployment parameters) throws IOException, ServiceException, URISyntaxException {
    // Validate
    if (resourceGroupName == null) {
        throw new NullPointerException("resourceGroupName");
    }
    if (resourceGroupName != null && resourceGroupName.length() > 1000) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (Pattern.matches("^[-\\w\\._]+$", resourceGroupName) == false) {
        throw new IllegalArgumentException("resourceGroupName");
    }
    if (deploymentName == null) {
        throw new NullPointerException("deploymentName");
    }
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getProperties() != null) {
        if (parameters.getProperties().getParametersLink() != null) {
            if (parameters.getProperties().getParametersLink().getUri() == null) {
                throw new NullPointerException("parameters.Properties.ParametersLink.Uri");
            }
        }
        if (parameters.getProperties().getTemplateLink() != null) {
            if (parameters.getProperties().getTemplateLink().getUri() == null) {
                throw new NullPointerException("parameters.Properties.TemplateLink.Uri");
            }
        }
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("resourceGroupName", resourceGroupName);
        tracingParameters.put("deploymentName", deploymentName);
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "validateAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/subscriptions/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/resourcegroups/";
    url = url + URLEncoder.encode(resourceGroupName, "UTF-8");
    url = url + "/providers/microsoft.resources/deployments/";
    url = url + URLEncoder.encode(deploymentName, "UTF-8");
    url = url + "/validate";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("api-version=" + "2014-04-01-preview");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Serialize Request
    String requestContent = null;
    JsonNode requestDoc = null;

    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode deploymentValue = objectMapper.createObjectNode();
    requestDoc = deploymentValue;

    if (parameters.getProperties() != null) {
        ObjectNode propertiesValue = objectMapper.createObjectNode();
        ((ObjectNode) deploymentValue).put("properties", propertiesValue);

        if (parameters.getProperties().getTemplate() != null) {
            ((ObjectNode) propertiesValue).put("template",
                    objectMapper.readTree(parameters.getProperties().getTemplate()));
        }

        if (parameters.getProperties().getTemplateLink() != null) {
            ObjectNode templateLinkValue = objectMapper.createObjectNode();
            ((ObjectNode) propertiesValue).put("templateLink", templateLinkValue);

            ((ObjectNode) templateLinkValue).put("uri",
                    parameters.getProperties().getTemplateLink().getUri().toString());

            if (parameters.getProperties().getTemplateLink().getContentVersion() != null) {
                ((ObjectNode) templateLinkValue).put("contentVersion",
                        parameters.getProperties().getTemplateLink().getContentVersion());
            }
        }

        if (parameters.getProperties().getParameters() != null) {
            ((ObjectNode) propertiesValue).put("parameters",
                    objectMapper.readTree(parameters.getProperties().getParameters()));
        }

        if (parameters.getProperties().getParametersLink() != null) {
            ObjectNode parametersLinkValue = objectMapper.createObjectNode();
            ((ObjectNode) propertiesValue).put("parametersLink", parametersLinkValue);

            ((ObjectNode) parametersLinkValue).put("uri",
                    parameters.getProperties().getParametersLink().getUri().toString());

            if (parameters.getProperties().getParametersLink().getContentVersion() != null) {
                ((ObjectNode) parametersLinkValue).put("contentVersion",
                        parameters.getProperties().getParametersLink().getContentVersion());
            }
        }

        if (parameters.getProperties().getMode() != null) {
            ((ObjectNode) propertiesValue).put("mode", parameters.getProperties().getMode().toString());
        }
    }

    StringWriter stringWriter = new StringWriter();
    objectMapper.writeValue(stringWriter, requestDoc);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/json; charset=utf-8");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_BAD_REQUEST) {
            ServiceException ex = ServiceException.createFromJson(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        DeploymentValidateResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_BAD_REQUEST) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new DeploymentValidateResponse();
            JsonNode responseDoc = null;
            String responseDocContent = IOUtils.toString(responseContent);
            if (responseDocContent == null == false && responseDocContent.length() > 0) {
                responseDoc = objectMapper.readTree(responseDocContent);
            }

            if (responseDoc != null && responseDoc instanceof NullNode == false) {
                JsonNode errorValue = responseDoc.get("error");
                if (errorValue != null && errorValue instanceof NullNode == false) {
                    ResourceManagementErrorWithDetails errorInstance = new ResourceManagementErrorWithDetails();
                    result.setError(errorInstance);

                    JsonNode detailsArray = errorValue.get("details");
                    if (detailsArray != null && detailsArray instanceof NullNode == false) {
                        for (JsonNode detailsValue : ((ArrayNode) detailsArray)) {
                            ResourceManagementError resourceManagementErrorInstance = new ResourceManagementError();
                            errorInstance.getDetails().add(resourceManagementErrorInstance);

                            JsonNode codeValue = detailsValue.get("code");
                            if (codeValue != null && codeValue instanceof NullNode == false) {
                                String codeInstance;
                                codeInstance = codeValue.getTextValue();
                                resourceManagementErrorInstance.setCode(codeInstance);
                            }

                            JsonNode messageValue = detailsValue.get("message");
                            if (messageValue != null && messageValue instanceof NullNode == false) {
                                String messageInstance;
                                messageInstance = messageValue.getTextValue();
                                resourceManagementErrorInstance.setMessage(messageInstance);
                            }

                            JsonNode targetValue = detailsValue.get("target");
                            if (targetValue != null && targetValue instanceof NullNode == false) {
                                String targetInstance;
                                targetInstance = targetValue.getTextValue();
                                resourceManagementErrorInstance.setTarget(targetInstance);
                            }
                        }
                    }

                    JsonNode codeValue2 = errorValue.get("code");
                    if (codeValue2 != null && codeValue2 instanceof NullNode == false) {
                        String codeInstance2;
                        codeInstance2 = codeValue2.getTextValue();
                        errorInstance.setCode(codeInstance2);
                    }

                    JsonNode messageValue2 = errorValue.get("message");
                    if (messageValue2 != null && messageValue2 instanceof NullNode == false) {
                        String messageInstance2;
                        messageInstance2 = messageValue2.getTextValue();
                        errorInstance.setMessage(messageInstance2);
                    }

                    JsonNode targetValue2 = errorValue.get("target");
                    if (targetValue2 != null && targetValue2 instanceof NullNode == false) {
                        String targetInstance2;
                        targetInstance2 = targetValue2.getTextValue();
                        errorInstance.setTarget(targetInstance2);
                    }
                }

                JsonNode propertiesValue2 = responseDoc.get("properties");
                if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) {
                    DeploymentPropertiesExtended propertiesInstance = new DeploymentPropertiesExtended();
                    result.setProperties(propertiesInstance);

                    JsonNode provisioningStateValue = propertiesValue2.get("provisioningState");
                    if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) {
                        String provisioningStateInstance;
                        provisioningStateInstance = provisioningStateValue.getTextValue();
                        propertiesInstance.setProvisioningState(provisioningStateInstance);
                    }

                    JsonNode correlationIdValue = propertiesValue2.get("correlationId");
                    if (correlationIdValue != null && correlationIdValue instanceof NullNode == false) {
                        String correlationIdInstance;
                        correlationIdInstance = correlationIdValue.getTextValue();
                        propertiesInstance.setCorrelationId(correlationIdInstance);
                    }

                    JsonNode timestampValue = propertiesValue2.get("timestamp");
                    if (timestampValue != null && timestampValue instanceof NullNode == false) {
                        Calendar timestampInstance;
                        timestampInstance = DatatypeConverter.parseDateTime(timestampValue.getTextValue());
                        propertiesInstance.setTimestamp(timestampInstance);
                    }

                    JsonNode outputsValue = propertiesValue2.get("outputs");
                    if (outputsValue != null && outputsValue instanceof NullNode == false) {
                        String outputsInstance;
                        outputsInstance = outputsValue.getTextValue();
                        propertiesInstance.setOutputs(outputsInstance);
                    }

                    JsonNode providersArray = propertiesValue2.get("providers");
                    if (providersArray != null && providersArray instanceof NullNode == false) {
                        for (JsonNode providersValue : ((ArrayNode) providersArray)) {
                            Provider providerInstance = new Provider();
                            propertiesInstance.getProviders().add(providerInstance);

                            JsonNode idValue = providersValue.get("id");
                            if (idValue != null && idValue instanceof NullNode == false) {
                                String idInstance;
                                idInstance = idValue.getTextValue();
                                providerInstance.setId(idInstance);
                            }

                            JsonNode namespaceValue = providersValue.get("namespace");
                            if (namespaceValue != null && namespaceValue instanceof NullNode == false) {
                                String namespaceInstance;
                                namespaceInstance = namespaceValue.getTextValue();
                                providerInstance.setNamespace(namespaceInstance);
                            }

                            JsonNode registrationStateValue = providersValue.get("registrationState");
                            if (registrationStateValue != null
                                    && registrationStateValue instanceof NullNode == false) {
                                String registrationStateInstance;
                                registrationStateInstance = registrationStateValue.getTextValue();
                                providerInstance.setRegistrationState(registrationStateInstance);
                            }

                            JsonNode resourceTypesArray = providersValue.get("resourceTypes");
                            if (resourceTypesArray != null && resourceTypesArray instanceof NullNode == false) {
                                for (JsonNode resourceTypesValue : ((ArrayNode) resourceTypesArray)) {
                                    ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                    providerInstance.getResourceTypes().add(providerResourceTypeInstance);

                                    JsonNode resourceTypeValue = resourceTypesValue.get("resourceType");
                                    if (resourceTypeValue != null
                                            && resourceTypeValue instanceof NullNode == false) {
                                        String resourceTypeInstance;
                                        resourceTypeInstance = resourceTypeValue.getTextValue();
                                        providerResourceTypeInstance.setName(resourceTypeInstance);
                                    }

                                    JsonNode locationsArray = resourceTypesValue.get("locations");
                                    if (locationsArray != null && locationsArray instanceof NullNode == false) {
                                        for (JsonNode locationsValue : ((ArrayNode) locationsArray)) {
                                            providerResourceTypeInstance.getLocations()
                                                    .add(locationsValue.getTextValue());
                                        }
                                    }

                                    JsonNode apiVersionsArray = resourceTypesValue.get("apiVersions");
                                    if (apiVersionsArray != null
                                            && apiVersionsArray instanceof NullNode == false) {
                                        for (JsonNode apiVersionsValue : ((ArrayNode) apiVersionsArray)) {
                                            providerResourceTypeInstance.getApiVersions()
                                                    .add(apiVersionsValue.getTextValue());
                                        }
                                    }

                                    JsonNode propertiesSequenceElement = ((JsonNode) resourceTypesValue
                                            .get("properties"));
                                    if (propertiesSequenceElement != null
                                            && propertiesSequenceElement instanceof NullNode == false) {
                                        Iterator<Map.Entry<String, JsonNode>> itr = propertiesSequenceElement
                                                .getFields();
                                        while (itr.hasNext()) {
                                            Map.Entry<String, JsonNode> property = itr.next();
                                            String propertiesKey = property.getKey();
                                            String propertiesValue3 = property.getValue().getTextValue();
                                            providerResourceTypeInstance.getProperties().put(propertiesKey,
                                                    propertiesValue3);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    JsonNode dependenciesArray = propertiesValue2.get("dependencies");
                    if (dependenciesArray != null && dependenciesArray instanceof NullNode == false) {
                        for (JsonNode dependenciesValue : ((ArrayNode) dependenciesArray)) {
                            Dependency dependencyInstance = new Dependency();
                            propertiesInstance.getDependencies().add(dependencyInstance);

                            JsonNode dependsOnArray = dependenciesValue.get("dependsOn");
                            if (dependsOnArray != null && dependsOnArray instanceof NullNode == false) {
                                for (JsonNode dependsOnValue : ((ArrayNode) dependsOnArray)) {
                                    BasicDependency basicDependencyInstance = new BasicDependency();
                                    dependencyInstance.getDependsOn().add(basicDependencyInstance);

                                    JsonNode idValue2 = dependsOnValue.get("id");
                                    if (idValue2 != null && idValue2 instanceof NullNode == false) {
                                        String idInstance2;
                                        idInstance2 = idValue2.getTextValue();
                                        basicDependencyInstance.setId(idInstance2);
                                    }

                                    JsonNode resourceTypeValue2 = dependsOnValue.get("resourceType");
                                    if (resourceTypeValue2 != null
                                            && resourceTypeValue2 instanceof NullNode == false) {
                                        String resourceTypeInstance2;
                                        resourceTypeInstance2 = resourceTypeValue2.getTextValue();
                                        basicDependencyInstance.setResourceType(resourceTypeInstance2);
                                    }

                                    JsonNode resourceNameValue = dependsOnValue.get("resourceName");
                                    if (resourceNameValue != null
                                            && resourceNameValue instanceof NullNode == false) {
                                        String resourceNameInstance;
                                        resourceNameInstance = resourceNameValue.getTextValue();
                                        basicDependencyInstance.setResourceName(resourceNameInstance);
                                    }
                                }
                            }

                            JsonNode idValue3 = dependenciesValue.get("id");
                            if (idValue3 != null && idValue3 instanceof NullNode == false) {
                                String idInstance3;
                                idInstance3 = idValue3.getTextValue();
                                dependencyInstance.setId(idInstance3);
                            }

                            JsonNode resourceTypeValue3 = dependenciesValue.get("resourceType");
                            if (resourceTypeValue3 != null && resourceTypeValue3 instanceof NullNode == false) {
                                String resourceTypeInstance3;
                                resourceTypeInstance3 = resourceTypeValue3.getTextValue();
                                dependencyInstance.setResourceType(resourceTypeInstance3);
                            }

                            JsonNode resourceNameValue2 = dependenciesValue.get("resourceName");
                            if (resourceNameValue2 != null && resourceNameValue2 instanceof NullNode == false) {
                                String resourceNameInstance2;
                                resourceNameInstance2 = resourceNameValue2.getTextValue();
                                dependencyInstance.setResourceName(resourceNameInstance2);
                            }
                        }
                    }

                    JsonNode templateValue = propertiesValue2.get("template");
                    if (templateValue != null && templateValue instanceof NullNode == false) {
                        String templateInstance;
                        templateInstance = templateValue.getTextValue();
                        propertiesInstance.setTemplate(templateInstance);
                    }

                    JsonNode templateLinkValue2 = propertiesValue2.get("templateLink");
                    if (templateLinkValue2 != null && templateLinkValue2 instanceof NullNode == false) {
                        TemplateLink templateLinkInstance = new TemplateLink();
                        propertiesInstance.setTemplateLink(templateLinkInstance);

                        JsonNode uriValue = templateLinkValue2.get("uri");
                        if (uriValue != null && uriValue instanceof NullNode == false) {
                            URI uriInstance;
                            uriInstance = new URI(uriValue.getTextValue());
                            templateLinkInstance.setUri(uriInstance);
                        }

                        JsonNode contentVersionValue = templateLinkValue2.get("contentVersion");
                        if (contentVersionValue != null && contentVersionValue instanceof NullNode == false) {
                            String contentVersionInstance;
                            contentVersionInstance = contentVersionValue.getTextValue();
                            templateLinkInstance.setContentVersion(contentVersionInstance);
                        }
                    }

                    JsonNode parametersValue = propertiesValue2.get("parameters");
                    if (parametersValue != null && parametersValue instanceof NullNode == false) {
                        String parametersInstance;
                        parametersInstance = parametersValue.getTextValue();
                        propertiesInstance.setParameters(parametersInstance);
                    }

                    JsonNode parametersLinkValue2 = propertiesValue2.get("parametersLink");
                    if (parametersLinkValue2 != null && parametersLinkValue2 instanceof NullNode == false) {
                        ParametersLink parametersLinkInstance = new ParametersLink();
                        propertiesInstance.setParametersLink(parametersLinkInstance);

                        JsonNode uriValue2 = parametersLinkValue2.get("uri");
                        if (uriValue2 != null && uriValue2 instanceof NullNode == false) {
                            URI uriInstance2;
                            uriInstance2 = new URI(uriValue2.getTextValue());
                            parametersLinkInstance.setUri(uriInstance2);
                        }

                        JsonNode contentVersionValue2 = parametersLinkValue2.get("contentVersion");
                        if (contentVersionValue2 != null && contentVersionValue2 instanceof NullNode == false) {
                            String contentVersionInstance2;
                            contentVersionInstance2 = contentVersionValue2.getTextValue();
                            parametersLinkInstance.setContentVersion(contentVersionInstance2);
                        }
                    }

                    JsonNode modeValue = propertiesValue2.get("mode");
                    if (modeValue != null && modeValue instanceof NullNode == false) {
                        DeploymentMode modeInstance;
                        modeInstance = Enum.valueOf(DeploymentMode.class, modeValue.getTextValue());
                        propertiesInstance.setMode(modeInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }
        if (statusCode == HttpStatus.SC_OK) {
            result.setIsValid(true);
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.ah.ui.actions.config.ImportCsvFileAction.java

/**
 * Check the ipAddress' format//  w  w w.j a va 2 s .  c o  m
 *
 * @param arg_IpAddress -
 * @return boolean - true:the ip is wrong;false:the ip is right.
 */
public static boolean getIpAddressWrongFlag(String arg_IpAddress) {
    boolean bool = false;
    String[] strIp = arg_IpAddress.split("\\.");
    if (strIp.length != 4 || arg_IpAddress.length() > 15) {
        bool = true;
    } else {
        for (int i = 0; i < 4; i++) {
            if (!isNumber(strIp[i]) || Integer.parseInt(strIp[i]) > 255) {
                bool = true;
                break;
            }
        }
        if (!bool) {
            bool = Pattern.matches("^([0]{1,3}\\.){3}[0]{1,3}$", arg_IpAddress);
        }
    }
    return bool;
}

From source file:com.ah.ui.actions.config.ImportCsvFileAction.java

/**
 * Check the email address of local user.
 *
 * @param mailAddress -//  w w  w .  j  a  v a  2 s  .c o  m
 * @param intLine the line number
 * @return boolean
 */
private boolean checkMailAddress(String mailAddress, int intLine, String msg) {
    if (mailAddress.equals("")) {
        return false;
    }
    String regex = "^([a-z0-9A-Z]+[-|_\\.+]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";

    /* The following is the list of known TLDs that an e-mail address must end with. */
    String[] knownDomsPat = new String[] { ".com", ".net", ".org", ".edu", ".int", ".mil", ".gov", ".arpa",
            ".biz", ".aero", ".name", ".coop", ".info", ".pro", ".museum" };

    boolean bool = true;
    String mail[] = mailAddress.split(";");
    for (String oneItem : mail) {
        if (oneItem.equals("")) {
            bool = false;
            break;
        }
        if (!Pattern.matches(regex, oneItem)) {
            bool = false;
            break;
        }
        String[] total = oneItem.split("\\.");
        if (total[total.length - 1].length() != 2) {
            bool = false;
            for (String endStr : knownDomsPat) {
                if (oneItem.endsWith(endStr)) {
                    bool = true;
                    break;
                }
            }
            if (!bool) {
                break;
            }
        }
    }
    if (!bool) {
        result.append(MgrUtil.getUserMessage("hm.system.log.import.csv.file.check"))
                .append(" " + intLine + "::").append(msg).append("::").append(mailAddress).append("\n");
    }
    return bool;
}

From source file:com.clark.func.Functions.java

/**
 * <p>/*from   w w w.j  a v a2  s. c  o  m*/
 * Validate that the specified argument character sequence matches the
 * specified regular expression pattern; otherwise throwing an exception.
 * </p>
 * 
 * <pre>
 * Validate.matchesPattern(&quot;hi&quot;, &quot;[a-z]*&quot;);
 * </pre>
 * 
 * <p>
 * The syntax of the pattern is the one used in the {@link Pattern} class.
 * </p>
 * 
 * @param input
 *            the character sequence to validate
 * @param pattern
 *            regular expression pattern
 * @throws IllegalArgumentException
 *             if the character sequence does not match the pattern
 * @see #matchesPattern(CharSequence, String, String, Object...)
 */
public static void matchesPattern(CharSequence input, String pattern) {
    if (Pattern.matches(pattern, input) == false) {
        throw new IllegalArgumentException(String.format(DEFAULT_MATCHES_PATTERN_EX, input, pattern));
    }
}

From source file:com.clark.func.Functions.java

/**
 * <p>/*w ww  .j  a  va 2 s.  c  om*/
 * Validate that the specified argument character sequence matches the
 * specified regular expression pattern; otherwise throwing an exception
 * with the specified message.
 * </p>
 * 
 * <pre>
 * Validate.matchesPattern("hi", "[a-z]*", "%s does not match %s", "hi" "[a-z]*");
 * </pre>
 * 
 * <p>
 * The syntax of the pattern is the one used in the {@link Pattern} class.
 * </p>
 * 
 * @param input
 *            the character sequence to validate
 * @param pattern
 *            regular expression pattern
 * @param message
 *            the exception message
 * @param values
 *            (optional) values to replace in the exception message
 * @throws IllegalArgumentException
 *             if the character sequence does not match the pattern
 * @see #matchesPattern(CharSequence, String)
 */
public static void matchesPattern(CharSequence input, String pattern, String message, Object... values) {
    if (Pattern.matches(pattern, input) == false) {
        throw new IllegalArgumentException(String.format(message, values));
    }
}