List of usage examples for java.util.regex Pattern matches
public static boolean matches(String regex, CharSequence input)
From source file:com.microsoft.azure.management.resources.ResourceGroupOperationsImpl.java
/** * Get a resource group./* www . ja v a 2 s. c om*/ * * @param resourceGroupName Required. The name of the resource group to get. * The name is case insensitive. * @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 Resource group information. */ @Override public ResourceGroupGetResult get(String resourceGroupName) 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"); } // 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); CloudTracing.enter(invocationId, this, "getAsync", 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"); 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 HttpGet httpRequest = new HttpGet(url); // Set Headers 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) { ServiceException ex = ServiceException.createFromJson(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result ResourceGroupGetResult result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new ResourceGroupGetResult(); ObjectMapper objectMapper = new ObjectMapper(); 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) { ResourceGroupExtended resourceGroupInstance = new ResourceGroupExtended(); result.setResourceGroup(resourceGroupInstance); JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); resourceGroupInstance.setId(idInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); resourceGroupInstance.setName(nameInstance); } JsonNode propertiesValue = responseDoc.get("properties"); if (propertiesValue != null && propertiesValue instanceof NullNode == false) { JsonNode provisioningStateValue = propertiesValue.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { String provisioningStateInstance; provisioningStateInstance = provisioningStateValue.getTextValue(); resourceGroupInstance.setProvisioningState(provisioningStateInstance); } } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); resourceGroupInstance.setLocation(locationInstance); } JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { String propertiesInstance; propertiesInstance = propertiesValue2.getTextValue(); resourceGroupInstance.setProperties(propertiesInstance); } JsonNode tagsSequenceElement = ((JsonNode) responseDoc.get("tags")); if (tagsSequenceElement != null && tagsSequenceElement instanceof NullNode == false) { Iterator<Map.Entry<String, JsonNode>> itr = tagsSequenceElement.getFields(); while (itr.hasNext()) { Map.Entry<String, JsonNode> property = itr.next(); String tagsKey = property.getKey(); String tagsValue = property.getValue().getTextValue(); resourceGroupInstance.getTags().put(tagsKey, tagsValue); } } JsonNode provisioningStateValue2 = responseDoc.get("provisioningState"); if (provisioningStateValue2 != null && provisioningStateValue2 instanceof NullNode == false) { String provisioningStateInstance2; provisioningStateInstance2 = provisioningStateValue2.getTextValue(); resourceGroupInstance.setProvisioningState(provisioningStateInstance2); } } } result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:jp.primecloud.auto.service.impl.LoadBalancerServiceImpl.java
/** * {@inheritDoc}/*from w ww .j ava 2 s. co m*/ */ @Override public Long createCloudstackLoadBalancer(Long farmNo, String loadBalancerName, String comment, Long platformNo, Long componentNo) { // ? if (farmNo == null) { throw new AutoApplicationException("ECOMMON-000003", "farmNo"); } if (loadBalancerName == null || loadBalancerName.length() == 0) { throw new AutoApplicationException("ECOMMON-000003", "loadBalancerName"); } if (platformNo == null) { throw new AutoApplicationException("ECOMMON-000003", "platformNo"); } if (componentNo == null) { throw new AutoApplicationException("ECOMMON-000003", "componentNo"); } // ?? if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", loadBalancerName)) { throw new AutoApplicationException("ECOMMON-000012", "loadBalancerName"); } // TODO: ?? // ?? Platform platform = platformDao.read(platformNo); if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType()) == false) { throw new AutoApplicationException("ESERVICE-000606", platformNo); } // ?????? LoadBalancer checkLoadBalancer = loadBalancerDao.readByFarmNoAndLoadBalancerName(farmNo, loadBalancerName); if (checkLoadBalancer != null) { // ???????? throw new AutoApplicationException("ESERVICE-000601", loadBalancerName); } // ???? Instance checkInstance = instanceDao.readByFarmNoAndInstanceName(farmNo, loadBalancerName); if (checkInstance != null) { // ??????? throw new AutoApplicationException("ESERVICE-000626", loadBalancerName); } // ?? Farm farm = farmDao.read(farmNo); if (farm == null) { throw new AutoApplicationException("ESERVICE-000602", farmNo); } // ???? long countComponent = componentDao.countByComponentNo(componentNo); if (countComponent == 0) { // ??????? throw new AutoApplicationException("ESERVICE-000607", componentNo); } // ??? LoadBalancer loadBalancer = new LoadBalancer(); loadBalancer.setFarmNo(farmNo); loadBalancer.setLoadBalancerName(loadBalancerName); loadBalancer.setComment(comment); loadBalancer.setFqdn(loadBalancerName + "." + farm.getDomainName()); loadBalancer.setPlatformNo(platformNo); loadBalancer.setType(PCCConstant.LOAD_BALANCER_CLOUDSTACK); loadBalancer.setEnabled(false); loadBalancer.setStatus(LoadBalancerStatus.STOPPED.toString()); loadBalancer.setComponentNo(componentNo); loadBalancerDao.create(loadBalancer); Long loadBalancerNo = loadBalancer.getLoadBalancerNo(); PlatformCloudstack platformCloudstack = platformCloudstackDao.read(platformNo); // Cloudstack??? //"NAME", "ALGORITHM", "ZONEID", "PUBLICPORT", "PRIVATEPORT"??? //?? CloudstackLoadBalancer cloudstackLoadBalancer = new CloudstackLoadBalancer(); cloudstackLoadBalancer.setLoadBalancerNo(loadBalancerNo); cloudstackLoadBalancer.setName(loadBalancerName + "-" + loadBalancerNo); cloudstackLoadBalancer.setAlgorithm("roundrobin"); cloudstackLoadBalancer.setZoneid(platformCloudstack.getZoneId()); cloudstackLoadBalancer.setPublicport("80"); cloudstackLoadBalancer.setPrivateport("80"); cloudstackLoadBalancerDao.create(cloudstackLoadBalancer); // ?? createDefaultAutoScalingConf(loadBalancer); // ?? registerInstances(loadBalancer); // eventLogger.log(EventLogLevel.INFO, farmNo, farm.getFarmName(), null, null, null, null, "LoadBalancerCreate", null, null, new Object[] { loadBalancerName, platform.getPlatformName(), PCCConstant.LOAD_BALANCER_ELB }); return loadBalancerNo; }
From source file:net.spfbl.spf.SPF.java
/** * Verifica se o whois um mecanismo mx vlido. * * @param token o whois a ser verificado. * @return verdadeiro se o whois um mecanismo mx vlido. *//*w w w .j a v a 2s.c o m*/ private static boolean isMechanismMX(String token) { token = expand(token, "127.0.0.1", "sender@domain.tld", "host.domain.tld"); return Pattern.matches("^(\\+|-|~|\\?)?mx" + "(:(?=.{1,255}$)[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?(?:\\.[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?)*\\.?)?" + "(\\.|/[0-9]{1,2})?(//[0-9]{1,3})?" + "$", token.toLowerCase()); }
From source file:net.spfbl.spf.SPF.java
/** * Verifica se o whois um mecanismo ptr vlido. * * @param token o whois a ser verificado. * @return verdadeiro se o whois um mecanismo ptr vlido. *//*from www. j a v a2s. c o m*/ private static boolean isMechanismPTR(String token) { token = expand(token, "127.0.0.1", "sender@domain.tld", "host.domain.tld"); return Pattern.matches("^(\\+|-|~|\\?)?ptr" + "(:(?=.{1,255}$)[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?(?:\\.[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?)*\\.?)?" + "$", token.toLowerCase()); }
From source file:com.couchbase.lite.Manager.java
/** * in CBLManager.m//from w w w . j ava 2 s .co m * - (NSString*) pathForDatabaseNamed: (NSString*)name * * @exclude */ @InterfaceAudience.Private private String pathForDatabaseNamed(String name) { if ((name == null) || (name.length() == 0) || Pattern.matches(LEGAL_CHARACTERS, name)) return null; // NOTE: CouchDB allows forward slash as part of database name. // However, ':' is illegal character on Windows platform. // For Windows, substitute with period '.' name = isWindows() ? name.replace('/', '.') : name.replace('/', ':'); String result = directoryFile.getPath() + File.separator + name + Manager.kDBExtension; return result; }
From source file:net.spfbl.spf.SPF.java
/** * Verifica se o whois um mecanismo existis vlido. * * @param token o whois a ser verificado. * @return verdadeiro se o whois um mecanismo existis vlido. *///from ww w .j av a 2s .c o m private static boolean isMechanismExistis(String token) { token = expand(token, "127.0.0.1", "sender@domain.tld", "host.domain.tld"); return Pattern.matches("^(\\+|-|~|\\?)?exists:" + "((?=.{1,255}$)[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?(?:\\.[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?)*\\.?)" + "$", token.toLowerCase()); }
From source file:com.predic8.membrane.core.interceptor.administration.DynamicAdminPageInterceptor.java
private Outcome dispatchRequest(Exchange exc) throws Exception { String pathQuery = URLUtil.getPathQuery(router.getUriFactory(), exc.getDestinations().get(0)); for (Method m : getClass().getMethods()) { Mapping a = m.getAnnotation(Mapping.class); if (a != null && Pattern.matches(a.value(), pathQuery)) { exc.setResponse(//from w w w .j a va 2 s.co m (Response) m.invoke(this, new Object[] { getParams(exc), getRelativeRootPath(pathQuery) })); return Outcome.RETURN; } } return Outcome.CONTINUE; }
From source file:net.spfbl.spf.SPF.java
/** * Verifica se o whois um mecanismo include vlido. * * @param token o whois a ser verificado. * @return verdadeiro se o whois um mecanismo include vlido. */// w ww . j a va2 s. co m private static boolean isMechanismInclude(String token) { token = expand(token, "127.0.0.1", "sender@domain.tld", "host.domain.tld"); return Pattern.matches("^(\\+|-|~|\\?)?include:" + "(\\.?(?=.{1,255}$)[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?(?:\\.[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?)*\\.?)" + "$", token.toLowerCase()); }
From source file:com.microsoft.azure.management.resources.ResourceOperationsImpl.java
/** * Delete resource and all of its resources. * * @param resourceGroupName Required. The name of the resource group. The * name is case insensitive./* w ww. j av a2 s. c om*/ * @param identity Required. Resource identity. * @throws InterruptedException Thrown when a thread is waiting, sleeping, * or otherwise occupied, and the thread is interrupted, either before or * during the activity. Occasionally a method may wish to test whether the * current thread has been interrupted, and if so, to immediately throw * this exception. The following code can be used to achieve this effect: * @throws ExecutionException Thrown when attempting to retrieve the result * of a task that aborted by throwing an exception. This exception can be * inspected using the Throwable.getCause() method. * @throws IOException Thrown if there was an error setting up tracing for * the request. * @throws ServiceException Thrown if an unexpected response is found. * @return A standard service response including an HTTP status code and * request ID. */ @Override public OperationResponse delete(String resourceGroupName, ResourceIdentity identity) throws InterruptedException, ExecutionException, IOException, ServiceException { // 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 (identity == null) { throw new NullPointerException("identity"); } if (identity.getResourceName() == null) { throw new NullPointerException("identity."); } if (identity.getResourceProviderApiVersion() == null) { throw new NullPointerException("identity."); } if (identity.getResourceProviderNamespace() == null) { throw new NullPointerException("identity."); } if (identity.getResourceType() == null) { throw new NullPointerException("identity."); } // 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("identity", identity); CloudTracing.enter(invocationId, this, "deleteAsync", 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/"; url = url + URLEncoder.encode(identity.getResourceProviderNamespace(), "UTF-8"); url = url + "/"; if (identity.getParentResourcePath() != null) { url = url + identity.getParentResourcePath(); } url = url + "/"; url = url + identity.getResourceType(); url = url + "/"; url = url + URLEncoder.encode(identity.getResourceName(), "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + URLEncoder.encode(identity.getResourceProviderApiVersion(), "UTF-8")); 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 CustomHttpDelete httpRequest = new CustomHttpDelete(url); // Set Headers 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_ACCEPTED && statusCode != HttpStatus.SC_NO_CONTENT) { ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; // Deserialize Response result = new OperationResponse(); result.setStatusCode(statusCode); if (httpResponse.getHeaders("x-ms-request-id").length > 0) { result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue()); } if (shouldTrace) { CloudTracing.exit(invocationId, result); } return result; } finally { if (httpResponse != null && httpResponse.getEntity() != null) { httpResponse.getEntity().getContent().close(); } } }
From source file:net.spfbl.spf.SPF.java
/** * Verifica se o whois um modificador redirect vlido. * * @param token o whois a ser verificado. * @return verdadeiro se o whois um modificador redirect vlido. *///from w ww. ja v a2 s . co m private static boolean isModifierRedirect(String token) { token = expand(token, "127.0.0.1", "sender@domain.tld", "host.domain.tld"); return Pattern.matches("^redirect=" + "((?=.{1,255}$)[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?(?:\\.[0-9A-Za-z_](?:(?:[0-9A-Za-z_]|-){0,61}[0-9A-Za-z_])?)*\\.?)" + "$", token.toLowerCase()); }