List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.kuali.rice.core.impl.services.ConfigurationServiceImpl.java
/** * Removes the spaces around the elements on a csv list of elements * * <p>/* w w w . j a v a2s.co m*/ * A null input will return a null output. * </p> * * @param csv a list of elements in csv format e.g. foo, bar, baz * @return a list of elements in csv format without spaces e.g. foo,bar,baz */ private String removeSpacesAround(String csv) { if (csv == null) { return null; } final StringBuilder result = new StringBuilder(); for (final String value : csv.split(",")) { if (!"".equals(value.trim())) { result.append(value.trim()); result.append(","); } } //remove trailing comma int i = result.lastIndexOf(","); if (i != -1) { result.deleteCharAt(i); } return result.toString(); }
From source file:org.wso2.carbon.identity.mgt.store.InMemoryIdentityDataStore.java
@Override public void store(UserIdentityClaimsDO userIdentityDTO, UserStoreManager userStoreManager) throws IdentityException { if (userIdentityDTO != null && userIdentityDTO.getUserName() != null) { String userName = userIdentityDTO.getUserName(); if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) { if (!IdentityUtil .isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) { if (log.isDebugEnabled()) { log.debug("Case insensitive user store found. Changing username from : " + userName + " to : " + userName.toLowerCase()); }/*from w w w . j av a 2s . c o m*/ userName = userName.toLowerCase(); } } if (log.isDebugEnabled()) { StringBuilder data = new StringBuilder("{"); if (userIdentityDTO.getUserIdentityDataMap() != null) { for (Map.Entry<String, String> entry : userIdentityDTO.getUserIdentityDataMap().entrySet()) { data.append("[").append(entry.getKey()).append(" = ").append(entry.getValue()) .append("], "); } } if (data.indexOf(",") >= 0) { data.deleteCharAt(data.lastIndexOf(",")); } data.append("}"); log.debug("Storing UserIdentityClaimsDO to cache for user: " + userName + " with claims: " + data); } org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager; String domainName = store.getRealmConfiguration() .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); String key = domainName + CarbonContext.getThreadLocalCarbonContext().getTenantId() + userName; Cache<String, UserIdentityClaimsDO> cache = getCache(); if (cache != null) { cache.put(key, userIdentityDTO); } } }
From source file:us.mn.state.health.lims.common.services.NoteService.java
public String getNotesAsString(String prefix, String noteSeparator) { List<Note> noteList = noteDAO.getNotesChronologicallyByRefIdAndRefTable(objectId, tableId); if (noteList.isEmpty()) { return null; }/* w w w .j a va2 s.com*/ StringBuilder builder = new StringBuilder(); for (Note note : noteList) { builder.append(StringUtil.blankIfNull(prefix)); builder.append(note.getText()); builder.append(StringUtil.blankIfNull(noteSeparator)); } if (!GenericValidator.isBlankOrNull(noteSeparator)) { builder.setLength(builder.lastIndexOf(noteSeparator)); } return builder.toString(); }
From source file:org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.java
private void maybeAddSeparatorToScript(StringBuilder scriptBuilder) { if (this.separator == null) { return;/*from w w w . j a va 2s . c om*/ } String trimmed = this.separator.trim(); if (trimmed.length() == this.separator.length()) { return; } // separator ends in whitespace, so we might want to see if the script is trying // to end the same way if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) { scriptBuilder.append(this.separator.substring(trimmed.length())); } }
From source file:org.drools.workbench.jcr2vfsmigration.jcrExport.ModuleAssetExporter.java
private String setupAssetExportFile(String moduleUuid) { StringBuilder fileNameBuilder = new StringBuilder(); boolean success = false; if (StringUtils.isNotBlank(moduleUuid)) { fileNameBuilder.insert(0, moduleUuid); success = fileManager.createAssetExportFile(fileNameBuilder.toString()); }//from w w w.jav a2 s . c om if (!success) { fileNameBuilder.replace(0, fileNameBuilder.lastIndexOf("."), Integer.toString(assetFileName++)); success = fileManager.createAssetExportFile(fileNameBuilder.toString()); if (!success) { logger.error("Module asset file could not be created"); return null; } } return fileNameBuilder.toString(); }
From source file:net.eusashead.hateoas.hal.response.impl.HalPageResponseBuilderImpl.java
/** * Build a query string from the supplied parameters * @param params/*from w w w.j av a2 s . co m*/ * @return */ private String buildQueryString(Map<String, String[]> params) { // Build the query string up from the parameters StringBuilder builder = new StringBuilder(); for (String key : params.keySet()) { for (String val : params.get(key)) { builder.append(key); builder.append("="); builder.append(val); builder.append("&"); } } // Remove the last ampersand if it is the trailing character if (builder.length() > 0) { if (builder.lastIndexOf("&") == (builder.length() - 1)) { builder.deleteCharAt(builder.length() - 1); } } return builder.toString(); }
From source file:cn.com.ebmp.freesql.io.ResolverUtil.java
/** * Attempts to deconstruct the given URL to find a JAR file containing the * resource referenced by the URL. That is, assuming the URL references a * JAR entry, this method will return a URL that references the JAR file * containing the entry. If the JAR cannot be located, then this method * returns null./*from w w w .j av a 2 s .c o m*/ * * @param url * The URL of the JAR entry. * @param path * The path by which the URL was requested from the class loader. * @return The URL of the JAR file, if one is found. Null if not. * @throws MalformedURLException */ protected URL findJarForResource(URL url, String path) throws MalformedURLException { log.debug("Find JAR URL: " + url); // If the file part of the URL is itself a URL, then that URL probably // points to the JAR try { for (;;) { url = new URL(url.getFile()); log.debug("Inner URL: " + url); } } catch (MalformedURLException e) { // This will happen at some point and serves a break in the loop } // Look for the .jar extension and chop off everything after that StringBuilder jarUrl = new StringBuilder(url.toExternalForm()); int index = jarUrl.lastIndexOf(".jar"); if (index >= 0) { jarUrl.setLength(index + 4); log.debug("Extracted JAR URL: " + jarUrl); } else { log.debug("Not a JAR: " + jarUrl); return null; } // Try to open and test it try { URL testUrl = new URL(jarUrl.toString()); if (isJar(testUrl)) { return testUrl; } else { // WebLogic fix: check if the URL's file exists in the // filesystem. log.debug("Not a JAR: " + jarUrl); jarUrl.replace(0, jarUrl.length(), testUrl.getFile()); File file = new File(jarUrl.toString()); // File name might be URL-encoded // if (!file.exists()) { // file = new File(StringUtil.urlDecode(jarUrl.toString())); // } if (file.exists()) { log.debug("Trying real file: " + file.getAbsolutePath()); testUrl = file.toURI().toURL(); if (isJar(testUrl)) { return testUrl; } } } } catch (MalformedURLException e) { log.warn("Invalid JAR URL: " + jarUrl); } log.debug("Not a JAR: " + jarUrl); return null; }
From source file:org.egov.egf.web.actions.masters.BankAction.java
public String getAccountTypesJSON() { final List<Object[]> accounttypes = persistenceService.findAllBy( "SELECT name,id FROM CChartOfAccounts WHERE glcode LIKE '4502%' AND classification=2 ORDER BY glcode"); final StringBuilder accountdetailtypeJson = new StringBuilder("{\"\":\"\","); for (final Object[] accType : accounttypes) { accType[0] = org.egov.infra.utils.StringUtils.escapeJavaScript((String) accType[0]); accountdetailtypeJson.append("\"").append(accType[1] + "#" + accType[0]).append("\"").append(":") .append("\"").append(accType[0]).append("\"").append(","); }/*w w w . j a v a2 s.com*/ accountdetailtypeJson.deleteCharAt(accountdetailtypeJson.lastIndexOf(",")); return accountdetailtypeJson.append("}").toString(); }
From source file:org.wso2.carbon.identity.governance.store.InMemoryIdentityDataStore.java
@Override public UserIdentityClaim load(String userName, UserStoreManager userStoreManager) { try {/*from w w w. j a v a2 s . co m*/ PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); Cache<String, UserIdentityClaim> cache = getCache(); if (userName != null && cache != null) { if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) { if (!IdentityUtil.isUserStoreCaseSensitive( (org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) { if (log.isDebugEnabled()) { log.debug("Case insensitive user store found. Changing username from : " + userName + " to : " + userName.toLowerCase()); } userName = userName.toLowerCase(); } } org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager; String domainName = store.getRealmConfiguration() .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME); UserIdentityClaim userIdentityDTO = cache .get(domainName + userStoreManager.getTenantId() + userName); if (userIdentityDTO != null && log.isDebugEnabled()) { StringBuilder data = new StringBuilder("{"); if (userIdentityDTO.getUserIdentityDataMap() != null) { for (Map.Entry<String, String> entry : userIdentityDTO.getUserIdentityDataMap() .entrySet()) { data.append("[" + entry.getKey() + " = " + entry.getValue() + "], "); } } if (data.indexOf(",") >= 0) { data.deleteCharAt(data.lastIndexOf(",")); } data.append("}"); log.debug("Loaded UserIdentityClaimsDO from cache for user :" + userName + " with claims: " + data); } return userIdentityDTO; } } catch (UserStoreException e) { log.error("Error while obtaining tenant ID from user store manager"); } finally { PrivilegedCarbonContext.endTenantFlow(); } return null; }
From source file:com.quartzdesk.executor.common.db.DatabaseScriptExecutor.java
private void maybeAddSeparatorToScript(StringBuilder scriptBuilder) { if (separator == null) { return;//from w ww .j a v a 2 s .c om } String trimmed = separator.trim(); if (trimmed.length() == separator.length()) { return; } // separator ends in whitespace, so we might want to see if the script is trying // to end the same way if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) { scriptBuilder.append(separator.substring(trimmed.length())); } }