List of usage examples for java.lang Character isLowerCase
public static boolean isLowerCase(int codePoint)
From source file:com.microsoft.azure.management.storage.StorageAccountOperationsImpl.java
/** * Updates the account type or tags for a storage account. It can also be * used to add a custom domain (note that custom domains cannot be added * via the Create operation). Only one custom domain is supported per * storage account. In order to replace a custom domain, the old value must * be cleared before a new value may be set. To clear a custom domain, * simply update the custom domain with empty string. Then call update * again with the new cutsom domain name. The update API can only be used * to update one of tags, accountType, or customDomain per call. To update * multiple of these properties, call the API multiple times with one * change per call. This call does not change the storage keys for the * account. If you want to change storage account keys, use the * RegenerateKey operation. The location and name of the storage account * cannot be changed after creation./*from ww w . j av a 2 s . c o m*/ * * @param resourceGroupName Required. The name of the resource group within * the user's subscription. * @param accountName Required. The name of the storage account within the * specified resource group. Storage account names must be between 3 and 24 * characters in length and use numbers and lower-case letters only. * @param parameters Required. The parameters to update on the account. Note * that only one property can be changed at a time using this API. * @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 The Update storage account operation response. */ @Override public StorageAccountUpdateResponse update(String resourceGroupName, String accountName, StorageAccountUpdateParameters parameters) throws IOException, ServiceException, URISyntaxException { // Validate if (resourceGroupName == null) { throw new NullPointerException("resourceGroupName"); } if (accountName == null) { throw new NullPointerException("accountName"); } if (accountName.length() < 3) { throw new IllegalArgumentException("accountName"); } if (accountName.length() > 24) { throw new IllegalArgumentException("accountName"); } for (char accountNameChar : accountName.toCharArray()) { if (Character.isLowerCase(accountNameChar) == false && Character.isDigit(accountNameChar) == false) { throw new IllegalArgumentException("accountName"); } } if (parameters == null) { throw new NullPointerException("parameters"); } if (parameters.getCustomDomain() != null) { if (parameters.getCustomDomain().getName() == null) { throw new NullPointerException("parameters.CustomDomain.Name"); } } // 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("accountName", accountName); tracingParameters.put("parameters", parameters); CloudTracing.enter(invocationId, this, "updateAsync", 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.Storage/storageAccounts/"; url = url + URLEncoder.encode(accountName, "UTF-8"); ArrayList<String> queryParameters = new ArrayList<String>(); queryParameters.add("api-version=" + "2015-06-15"); 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 HttpPatch httpRequest = new HttpPatch(url); // Set Headers httpRequest.setHeader("Content-Type", "application/json"); httpRequest.setHeader("x-ms-client-request-id", UUID.randomUUID().toString()); // Serialize Request String requestContent = null; JsonNode requestDoc = null; ObjectMapper objectMapper = new ObjectMapper(); ObjectNode storageAccountUpdateParametersJsonValue = objectMapper.createObjectNode(); requestDoc = storageAccountUpdateParametersJsonValue; if (parameters.getTags() != null) { if (parameters.getTags() instanceof LazyCollection == false || ((LazyCollection) parameters.getTags()).isInitialized()) { ObjectNode tagsDictionary = objectMapper.createObjectNode(); for (Map.Entry<String, String> entry : parameters.getTags().entrySet()) { String tagsKey = entry.getKey(); String tagsValue = entry.getValue(); ((ObjectNode) tagsDictionary).put(tagsKey, tagsValue); } ((ObjectNode) storageAccountUpdateParametersJsonValue).put("tags", tagsDictionary); } } ObjectNode propertiesValue = objectMapper.createObjectNode(); ((ObjectNode) storageAccountUpdateParametersJsonValue).put("properties", propertiesValue); if (parameters.getAccountType() != null) { ((ObjectNode) propertiesValue).put("accountType", StorageManagementClientImpl.accountTypeToString(parameters.getAccountType())); } if (parameters.getCustomDomain() != null) { ObjectNode customDomainValue = objectMapper.createObjectNode(); ((ObjectNode) propertiesValue).put("customDomain", customDomainValue); ((ObjectNode) customDomainValue).put("name", parameters.getCustomDomain().getName()); if (parameters.getCustomDomain().isUseSubDomain() != null) { ((ObjectNode) customDomainValue).put("useSubDomain", parameters.getCustomDomain().isUseSubDomain()); } } 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"); // 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, requestContent, httpResponse, httpResponse.getEntity()); if (shouldTrace) { CloudTracing.error(invocationId, ex); } throw ex; } // Create Result StorageAccountUpdateResponse result = null; // Deserialize Response if (statusCode == HttpStatus.SC_OK) { InputStream responseContent = httpResponse.getEntity().getContent(); result = new StorageAccountUpdateResponse(); 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) { StorageAccount storageAccountInstance = new StorageAccount(); result.setStorageAccount(storageAccountInstance); JsonNode idValue = responseDoc.get("id"); if (idValue != null && idValue instanceof NullNode == false) { String idInstance; idInstance = idValue.getTextValue(); storageAccountInstance.setId(idInstance); } JsonNode nameValue = responseDoc.get("name"); if (nameValue != null && nameValue instanceof NullNode == false) { String nameInstance; nameInstance = nameValue.getTextValue(); storageAccountInstance.setName(nameInstance); } JsonNode typeValue = responseDoc.get("type"); if (typeValue != null && typeValue instanceof NullNode == false) { String typeInstance; typeInstance = typeValue.getTextValue(); storageAccountInstance.setType(typeInstance); } JsonNode locationValue = responseDoc.get("location"); if (locationValue != null && locationValue instanceof NullNode == false) { String locationInstance; locationInstance = locationValue.getTextValue(); storageAccountInstance.setLocation(locationInstance); } 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 tagsKey2 = property.getKey(); String tagsValue2 = property.getValue().getTextValue(); storageAccountInstance.getTags().put(tagsKey2, tagsValue2); } } JsonNode propertiesValue2 = responseDoc.get("properties"); if (propertiesValue2 != null && propertiesValue2 instanceof NullNode == false) { JsonNode provisioningStateValue = propertiesValue2.get("provisioningState"); if (provisioningStateValue != null && provisioningStateValue instanceof NullNode == false) { ProvisioningState provisioningStateInstance; provisioningStateInstance = EnumUtility.fromString(ProvisioningState.class, provisioningStateValue.getTextValue()); storageAccountInstance.setProvisioningState(provisioningStateInstance); } JsonNode accountTypeValue = propertiesValue2.get("accountType"); if (accountTypeValue != null && accountTypeValue instanceof NullNode == false) { AccountType accountTypeInstance; accountTypeInstance = StorageManagementClientImpl .parseAccountType(accountTypeValue.getTextValue()); storageAccountInstance.setAccountType(accountTypeInstance); } JsonNode primaryEndpointsValue = propertiesValue2.get("primaryEndpoints"); if (primaryEndpointsValue != null && primaryEndpointsValue instanceof NullNode == false) { Endpoints primaryEndpointsInstance = new Endpoints(); storageAccountInstance.setPrimaryEndpoints(primaryEndpointsInstance); JsonNode blobValue = primaryEndpointsValue.get("blob"); if (blobValue != null && blobValue instanceof NullNode == false) { URI blobInstance; blobInstance = new URI(blobValue.getTextValue()); primaryEndpointsInstance.setBlob(blobInstance); } JsonNode queueValue = primaryEndpointsValue.get("queue"); if (queueValue != null && queueValue instanceof NullNode == false) { URI queueInstance; queueInstance = new URI(queueValue.getTextValue()); primaryEndpointsInstance.setQueue(queueInstance); } JsonNode tableValue = primaryEndpointsValue.get("table"); if (tableValue != null && tableValue instanceof NullNode == false) { URI tableInstance; tableInstance = new URI(tableValue.getTextValue()); primaryEndpointsInstance.setTable(tableInstance); } JsonNode fileValue = primaryEndpointsValue.get("file"); if (fileValue != null && fileValue instanceof NullNode == false) { URI fileInstance; fileInstance = new URI(fileValue.getTextValue()); primaryEndpointsInstance.setFile(fileInstance); } } JsonNode primaryLocationValue = propertiesValue2.get("primaryLocation"); if (primaryLocationValue != null && primaryLocationValue instanceof NullNode == false) { String primaryLocationInstance; primaryLocationInstance = primaryLocationValue.getTextValue(); storageAccountInstance.setPrimaryLocation(primaryLocationInstance); } JsonNode statusOfPrimaryValue = propertiesValue2.get("statusOfPrimary"); if (statusOfPrimaryValue != null && statusOfPrimaryValue instanceof NullNode == false) { AccountStatus statusOfPrimaryInstance; statusOfPrimaryInstance = EnumUtility.fromString(AccountStatus.class, statusOfPrimaryValue.getTextValue()); storageAccountInstance.setStatusOfPrimary(statusOfPrimaryInstance); } JsonNode lastGeoFailoverTimeValue = propertiesValue2.get("lastGeoFailoverTime"); if (lastGeoFailoverTimeValue != null && lastGeoFailoverTimeValue instanceof NullNode == false) { Calendar lastGeoFailoverTimeInstance; lastGeoFailoverTimeInstance = DatatypeConverter .parseDateTime(lastGeoFailoverTimeValue.getTextValue()); storageAccountInstance.setLastGeoFailoverTime(lastGeoFailoverTimeInstance); } JsonNode secondaryLocationValue = propertiesValue2.get("secondaryLocation"); if (secondaryLocationValue != null && secondaryLocationValue instanceof NullNode == false) { String secondaryLocationInstance; secondaryLocationInstance = secondaryLocationValue.getTextValue(); storageAccountInstance.setSecondaryLocation(secondaryLocationInstance); } JsonNode statusOfSecondaryValue = propertiesValue2.get("statusOfSecondary"); if (statusOfSecondaryValue != null && statusOfSecondaryValue instanceof NullNode == false) { AccountStatus statusOfSecondaryInstance; statusOfSecondaryInstance = EnumUtility.fromString(AccountStatus.class, statusOfSecondaryValue.getTextValue()); storageAccountInstance.setStatusOfSecondary(statusOfSecondaryInstance); } JsonNode creationTimeValue = propertiesValue2.get("creationTime"); if (creationTimeValue != null && creationTimeValue instanceof NullNode == false) { Calendar creationTimeInstance; creationTimeInstance = DatatypeConverter .parseDateTime(creationTimeValue.getTextValue()); storageAccountInstance.setCreationTime(creationTimeInstance); } JsonNode customDomainValue2 = propertiesValue2.get("customDomain"); if (customDomainValue2 != null && customDomainValue2 instanceof NullNode == false) { CustomDomain customDomainInstance = new CustomDomain(); storageAccountInstance.setCustomDomain(customDomainInstance); JsonNode nameValue2 = customDomainValue2.get("name"); if (nameValue2 != null && nameValue2 instanceof NullNode == false) { String nameInstance2; nameInstance2 = nameValue2.getTextValue(); customDomainInstance.setName(nameInstance2); } JsonNode useSubDomainValue = customDomainValue2.get("useSubDomain"); if (useSubDomainValue != null && useSubDomainValue instanceof NullNode == false) { boolean useSubDomainInstance; useSubDomainInstance = useSubDomainValue.getBooleanValue(); customDomainInstance.setUseSubDomain(useSubDomainInstance); } } JsonNode secondaryEndpointsValue = propertiesValue2.get("secondaryEndpoints"); if (secondaryEndpointsValue != null && secondaryEndpointsValue instanceof NullNode == false) { Endpoints secondaryEndpointsInstance = new Endpoints(); storageAccountInstance.setSecondaryEndpoints(secondaryEndpointsInstance); JsonNode blobValue2 = secondaryEndpointsValue.get("blob"); if (blobValue2 != null && blobValue2 instanceof NullNode == false) { URI blobInstance2; blobInstance2 = new URI(blobValue2.getTextValue()); secondaryEndpointsInstance.setBlob(blobInstance2); } JsonNode queueValue2 = secondaryEndpointsValue.get("queue"); if (queueValue2 != null && queueValue2 instanceof NullNode == false) { URI queueInstance2; queueInstance2 = new URI(queueValue2.getTextValue()); secondaryEndpointsInstance.setQueue(queueInstance2); } JsonNode tableValue2 = secondaryEndpointsValue.get("table"); if (tableValue2 != null && tableValue2 instanceof NullNode == false) { URI tableInstance2; tableInstance2 = new URI(tableValue2.getTextValue()); secondaryEndpointsInstance.setTable(tableInstance2); } JsonNode fileValue2 = secondaryEndpointsValue.get("file"); if (fileValue2 != null && fileValue2 instanceof NullNode == false) { URI fileInstance2; fileInstance2 = new URI(fileValue2.getTextValue()); secondaryEndpointsInstance.setFile(fileInstance2); } } } } } 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:io.manasobi.utils.StringUtils.java
/** * ? ? <br><br>//from w ww .j av a 2 s . c om * * StringUtils.swapFirstLetterCase("java") = "Java" * * @param str ? * @return ? ? ? */ public static String swapFirstLetterCase(String str) { StringBuilder sbuf = new StringBuilder(str); sbuf.deleteCharAt(0); if (Character.isLowerCase(str.substring(0, 1).toCharArray()[0])) { sbuf.insert(0, str.substring(0, 1).toUpperCase()); } else { sbuf.insert(0, str.substring(0, 1).toLowerCase()); } return sbuf.toString(); }
From source file:com.test.stringtest.StringUtils.java
/** * <p>Checks if the String contains only lowercase characters.</p> * * <p><code>null</code> will return <code>false</code>. * An empty String ("") will return <code>false</code>.</p> * * <pre>// w w w . jav a 2 s . c o m * StringUtils.isAllLowerCase(null) = false * StringUtils.isAllLowerCase("") = false * StringUtils.isAllLowerCase(" ") = false * StringUtils.isAllLowerCase("abc") = true * StringUtils.isAllLowerCase("abC") = false * </pre> * * @param str the String to check, may be null * @return <code>true</code> if only contains lowercase characters, and is non-null * @since 2.5 */ public static boolean isAllLowerCase(String str) { if (str == null || isEmpty(str)) { return false; } int sz = str.length(); for (int i = 0; i < sz; i++) { if (Character.isLowerCase(str.charAt(i)) == false) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>/*from w ww.ja v a 2 s .c o m*/ * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, {@code null} if null String input */ public static String swapCase(String str) { if (StringUtils.isEmpty(str)) { return str; } char[] buffer = str.toCharArray(); for (int i = 0; i < buffer.length; i++) { char ch = buffer[i]; if (Character.isUpperCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { buffer[i] = Character.toUpperCase(ch); } } return new String(buffer); }
From source file:com.sjdf.platform.xss.StringUtils.java
/** * <p>// w w w . ja v a 2 s.c o m * Checks if the CharSequence contains only lowercase characters. * </p> * <p/> * <p> * {@code null} will return {@code false}. An empty CharSequence * (length()=0) will return {@code false}. * </p> * <p/> * <pre> * StringUtils.isAllLowerCase(null) = false * StringUtils.isAllLowerCase("") = false * StringUtils.isAllLowerCase(" ") = false * StringUtils.isAllLowerCase("abc") = true * StringUtils.isAllLowerCase("abC") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains lowercase characters, and is * non-null * @since 3.0 Changed signature from isAllLowerCase(String) to * isAllLowerCase(CharSequence) */ public static boolean isAllLowerCase(CharSequence cs) { if (cs == null || isEmpty(cs)) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (!Character.isLowerCase(cs.charAt(i))) { return false; } } return true; }
From source file:org.apache.commons.lang3.StringUtils.java
/** * <p>Checks if the CharSequence contains only lowercase characters.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code false}.</p> * * <pre>/* w ww .j a v a 2 s. c o m*/ * StringUtils.isAllLowerCase(null) = false * StringUtils.isAllLowerCase("") = false * StringUtils.isAllLowerCase(" ") = false * StringUtils.isAllLowerCase("abc") = true * StringUtils.isAllLowerCase("abC") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if only contains lowercase characters, and is non-null * @since 2.5 * @since 3.0 Changed signature from isAllLowerCase(String) to isAllLowerCase(CharSequence) */ public static boolean isAllLowerCase(CharSequence cs) { if (cs == null || isEmpty(cs)) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if (Character.isLowerCase(cs.charAt(i)) == false) { return false; } } return true; }
From source file:com.rdm.common.util.StringUtils.java
/** * <p>Uncapitalizes a String changing the first letter to title case as * per {@link Character#toLowerCase(char)}. No other letters are changed.</p> * * <p>For a word based algorithm, see {@link com.rdm.common.util.text.WordUtils#uncapitalize(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre>//from w w w . j a v a 2 s.c o m * StringUtils.uncapitalize(null) = null * StringUtils.uncapitalize("") = "" * StringUtils.uncapitalize("Cat") = "cat" * StringUtils.uncapitalize("CAT") = "cAT" * </pre> * * @param str the String to uncapitalize, may be null * @return the uncapitalized String, {@code null} if null String input * @see com.rdm.common.util.text.WordUtils#uncapitalize(String) * @see #capitalize(String) * @since 2.0 */ public static String uncapitalize(final String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } char firstChar = str.charAt(0); if (Character.isLowerCase(firstChar)) { // already uncapitalized return str; } return new StringBuilder(strLen).append(Character.toLowerCase(firstChar)).append(str.substring(1)) .toString(); }
From source file:com.rdm.common.util.StringUtils.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>// w w w.ja va 2 s. c om * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link com.rdm.common.util.text.WordUtils#swapCase(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, {@code null} if null String input */ public static String swapCase(final String str) { if (StringUtils.isEmpty(str)) { return str; } final char[] buffer = str.toCharArray(); for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (Character.isUpperCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { buffer[i] = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { buffer[i] = Character.toUpperCase(ch); } } return new String(buffer); }
From source file:com.clark.func.Functions.java
/** * <p>/*from w w w . j av a2 s .c o m*/ * Swaps the case of a String changing upper and title case to lower case, * and lower case to upper case. * </p> * * <ul> * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p> * For a word based algorithm, see * {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. A * <code>null</code> input String returns <code>null</code>. * </p> * * <pre> * swapCase(null) = null * swapCase("") = "" * swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p> * NOTE: This method changed in Lang version 2.0. It no longer performs a * word based algorithm. If you only use ASCII, you will notice no change. * That functionality is available in * org.apache.commons.lang3.text.WordUtils. * </p> * * @param str * the String to swap case, may be null * @return the changed String, <code>null</code> if null String input */ public static String swapCase(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } StringBuilder buffer = new StringBuilder(strLen); char ch = 0; for (int i = 0; i < strLen; i++) { ch = str.charAt(i); if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { ch = Character.toUpperCase(ch); } buffer.append(ch); } return buffer.toString(); }
From source file:com.zimbra.cs.account.ldap.LdapProvisioning.java
/** * called to check password strength. Should pass in either an Account, or Cos/Attributes (during creation). * * @param password/*from w w w .j a va 2 s .c om*/ * @param acct * @param cos * @param attrs * @throws ServiceException */ private void checkPasswordStrength(String password, Account acct, Cos cos, ZMutableEntry entry) throws ServiceException { int minLength = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinLength, 0); if (minLength > 0 && password.length() < minLength) { throw AccountServiceException.INVALID_PASSWORD("too short", new Argument(Provisioning.A_zimbraPasswordMinLength, minLength, Argument.Type.NUM)); } int maxLength = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMaxLength, 0); if (maxLength > 0 && password.length() > maxLength) { throw AccountServiceException.INVALID_PASSWORD("too long", new Argument(Provisioning.A_zimbraPasswordMaxLength, maxLength, Argument.Type.NUM)); } int minUpperCase = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinUpperCaseChars, 0); int minLowerCase = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinLowerCaseChars, 0); int minNumeric = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinNumericChars, 0); int minPunctuation = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinPunctuationChars, 0); int minAlpha = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinAlphaChars, 0); int minNumOrPunc = getInt(acct, cos, entry, Provisioning.A_zimbraPasswordMinDigitsOrPuncs, 0); String allowedChars = getString(acct, cos, entry, Provisioning.A_zimbraPasswordAllowedChars); Pattern allowedCharsPattern = null; if (allowedChars != null) { try { allowedCharsPattern = Pattern.compile(allowedChars); } catch (PatternSyntaxException e) { throw AccountServiceException.INVALID_PASSWORD( Provisioning.A_zimbraPasswordAllowedChars + " is not valid regex: " + e.getMessage()); } } String allowedPuncChars = getString(acct, cos, entry, Provisioning.A_zimbraPasswordAllowedPunctuationChars); Pattern allowedPuncCharsPattern = null; if (allowedPuncChars != null) { try { allowedPuncCharsPattern = Pattern.compile(allowedPuncChars); } catch (PatternSyntaxException e) { throw AccountServiceException.INVALID_PASSWORD(Provisioning.A_zimbraPasswordAllowedPunctuationChars + " is not valid regex: " + e.getMessage()); } } boolean hasPolicies = minUpperCase > 0 || minLowerCase > 0 || minNumeric > 0 || minPunctuation > 0 || minAlpha > 0 || minNumOrPunc > 0 || allowedCharsPattern != null || allowedPuncCharsPattern != null; if (!hasPolicies) { return; } int upper = 0; int lower = 0; int numeric = 0; int punctuation = 0; int alpha = 0; for (int i = 0; i < password.length(); i++) { char ch = password.charAt(i); if (allowedCharsPattern != null) { if (!allowedCharsPattern.matcher(Character.toString(ch)).matches()) { throw AccountServiceException.INVALID_PASSWORD(ch + " is not an allowed character", new Argument(Provisioning.A_zimbraPasswordAllowedChars, allowedChars, Argument.Type.STR)); } } boolean isAlpha = true; if (Character.isUpperCase(ch)) { upper++; } else if (Character.isLowerCase(ch)) { lower++; } else if (Character.isDigit(ch)) { numeric++; isAlpha = false; } else if (allowedPuncCharsPattern != null) { if (allowedPuncCharsPattern.matcher(Character.toString(ch)).matches()) { punctuation++; isAlpha = false; } } else if (isAsciiPunc(ch)) { punctuation++; isAlpha = false; } if (isAlpha) { alpha++; } } if (upper < minUpperCase) { throw AccountServiceException.INVALID_PASSWORD("not enough upper case characters", new Argument(Provisioning.A_zimbraPasswordMinUpperCaseChars, minUpperCase, Argument.Type.NUM)); } if (lower < minLowerCase) { throw AccountServiceException.INVALID_PASSWORD("not enough lower case characters", new Argument(Provisioning.A_zimbraPasswordMinLowerCaseChars, minLowerCase, Argument.Type.NUM)); } if (numeric < minNumeric) { throw AccountServiceException.INVALID_PASSWORD("not enough numeric characters", new Argument(Provisioning.A_zimbraPasswordMinNumericChars, minNumeric, Argument.Type.NUM)); } if (punctuation < minPunctuation) { throw AccountServiceException.INVALID_PASSWORD("not enough punctuation characters", new Argument( Provisioning.A_zimbraPasswordMinPunctuationChars, minPunctuation, Argument.Type.NUM)); } if (alpha < minAlpha) { throw AccountServiceException.INVALID_PASSWORD("not enough alpha characters", new Argument(Provisioning.A_zimbraPasswordMinAlphaChars, minAlpha, Argument.Type.NUM)); } if (numeric + punctuation < minNumOrPunc) { throw AccountServiceException.INVALID_PASSWORD("not enough numeric or punctuation characters", new Argument(Provisioning.A_zimbraPasswordMinDigitsOrPuncs, minNumOrPunc, Argument.Type.NUM)); } }