List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:gov.nih.nci.cabig.caaers.web.admin.OrganizationImporter.java
/** * This method accepts a String which should be like * "CA531","California Hematology Oncology Medical Group","Torrance","CA","USA" * It splits the string into 5 tokens and creates a LocalOrganization object. * If the number of token are less than 5 the record/line is rejected. * @param organizationString//from w w w .j a v a2s . c o m * @return */ protected DomainObjectImportOutcome<Organization> processOrganization(String organizationString, int lineNumber) { DomainObjectImportOutcome<Organization> organizationImportOutcome = null; LocalOrganization localOrganization = null; StringTokenizer st = null; String institutionCode; String institutionName; String city; String state; String country; if (StringUtils.isNotEmpty(organizationString)) { logger.debug("Orginial line from file -- >>> " + organizationString); organizationString = organizationString.trim(); //Replace ", with "| //This is done to set a delimiter other than , organizationString = StringUtils.replace(organizationString, "\",", "\"|"); logger.debug("Modified line -- >>> " + organizationString); //Generate tokens from input String. st = new StringTokenizer(organizationString, "|"); //If there are 5 tokens as expected, process the record. Create a LocalOrganization object. if (st.hasMoreTokens() && st.countTokens() == 5) { organizationImportOutcome = new DomainObjectImportOutcome<Organization>(); localOrganization = new LocalOrganization(); institutionCode = StringUtils.removeStart(st.nextToken(), "\"").trim(); institutionCode = StringUtils.removeEnd(institutionCode, "\""); institutionName = StringUtils.removeStart(st.nextToken(), "\"").trim(); institutionName = StringUtils.removeEnd(institutionName, "\""); city = StringUtils.removeStart(st.nextToken(), "\"").trim(); city = StringUtils.removeEnd(city, "\""); state = StringUtils.removeStart(st.nextToken(), "\"").trim(); state = StringUtils.removeEnd(state, "\""); country = StringUtils.removeStart(st.nextToken(), "\"").trim(); country = StringUtils.removeEnd(country, "\""); localOrganization.setName(institutionName); localOrganization.setNciInstituteCode(institutionCode); localOrganization.setCity(city); localOrganization.setState(state); localOrganization.setCountry(country); organizationImportOutcome.setImportedDomainObject(localOrganization); organizationImportOutcome.setSavable(Boolean.TRUE); } else { logger.debug("Error in record -- >>> " + organizationString); organizationImportOutcome = new DomainObjectImportOutcome<Organization>(); StringBuilder msgBuilder = new StringBuilder("Invalid organization record found at line ::: "); msgBuilder.append(lineNumber); organizationImportOutcome.addErrorMessage(msgBuilder.toString(), Severity.ERROR); } } return organizationImportOutcome; }
From source file:gobblin.util.io.StreamUtils.java
/** * Convert a {@link Path} to a {@link String} and make sure it is properly formatted to be recognized as a file * by {@link TarArchiveEntry}.// w w w . j av a2 s. c om */ private static String formatPathToFile(Path path) { return StringUtils.removeEnd(path.toString(), Path.SEPARATOR); }
From source file:it.av.eatt.service.impl.JcrApplicationServiceJackrabbit.java
public void setBasePath(String basePath) { if (StringUtils.isBlank(basePath)) { this.basePath = ""; } else {//from w w w .j a v a 2 s .co m this.basePath = StringUtils.trimToEmpty(basePath); if ((StringUtils.endsWith(this.basePath, "/"))) { this.basePath = StringUtils.removeEnd(this.basePath, "/"); } } }
From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java
/** * Processing normal request (i.e. when user goes directly to that application - not from cmscockpit) * <p/>/*from ww w. j a va 2 s . c om*/ * <b>Note:</b> <br/> * We preparing application by setting correct: * <ul> * <li>Current Site</li> * <li>Current Catalog Versions</li> * <li>Enabled language fallback</li> * </ul> * * @see ContextInformationLoader#initializeSiteFromRequest(String) * @see ContextInformationLoader#setCatalogVersions() * @param httpRequest * current request * @param httpResponse * the http response * @throws java.io.IOException */ protected boolean processNormalRequest(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws IOException { final String queryString = httpRequest.getQueryString(); final String currentRequestURL = httpRequest.getRequestURL().toString(); //set current site CMSSiteModel cmsSiteModel = getCurrentCmsSite(); if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) { final String absoluteURL = StringUtils.removeEnd(currentRequestURL, "/") + (StringUtils.isBlank(queryString) ? "" : "?" + queryString); cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL); } if (cmsSiteModel == null) { // Failed to lookup CMS site httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE); return false; } else if (!getSiteChannelValidationStrategy().validateSiteChannel(cmsSiteModel.getChannel())) // Restrict to configured channel { // CMS site that we looked up was for an unsupported channel httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE); return false; } if (!isActiveSite(cmsSiteModel)) { throw new IllegalStateException( "Site is not active. Active flag behaviour must be implement for this project."); } getContextInformationLoader().setCatalogVersions(); //set fall back language enabled setFallbackLanguage(httpRequest, Boolean.TRUE); return true; }
From source file:com.ewcms.core.site.model.Channel.java
private String removeStartAndEndPathSeparator(final String dir) { String path = dir;/*from w ww . ja v a 2 s .c om*/ path = StringUtils.removeStart(path, PATH_SEPARATOR); path = StringUtils.removeEnd(path, PATH_SEPARATOR); return path; }
From source file:edu.monash.merc.system.scheduling.impl.RifcsProcessor.java
private String getRootRelPath(String fullPath) { String path = StringUtils.removeEnd(fullPath, "/"); String relPpath = StringUtils.substringAfterLast(path, "/"); if (StringUtils.isBlank(relPpath)) { throw new DMConfigException("The root relative path is null"); }/* w w w.ja v a2 s . c o m*/ return relPpath; }
From source file:com.google.gdt.eclipse.designer.refactoring.GwtRefactoringUtils.java
/** * @return {@link Change} for changing name of servlet in "servlet" element. *//*from w ww. j a v a 2s. c om*/ public static Change web_replaceServletPath(IType type, final String oldName, final String newName) throws Exception { return modifyWeb(type, new DocumentModelVisitor() { @Override public void endVisit(DocumentElement element) { if (element instanceof com.google.gdt.eclipse.designer.model.web.ServletElement) { com.google.gdt.eclipse.designer.model.web.ServletElement servlet = (com.google.gdt.eclipse.designer.model.web.ServletElement) element; if (servlet.getName().equals(oldName)) { servlet.setName(newName); } } if (element instanceof com.google.gdt.eclipse.designer.model.web.ServletMappingElement) { com.google.gdt.eclipse.designer.model.web.ServletMappingElement mapping = (com.google.gdt.eclipse.designer.model.web.ServletMappingElement) element; if (mapping.getName().equals(oldName)) { mapping.setName(newName); } String pattern = mapping.getPattern(); if (pattern.endsWith("/" + oldName)) { pattern = StringUtils.removeEnd(pattern, oldName) + newName; mapping.setPattern(pattern); } } } }); }
From source file:com.hangum.tadpole.engine.sql.util.export.SQLExporter.java
public static String makeFileUpdateStatment(String tableName, QueryExecuteResultDTO rsDAO, List<String> listWhere, int intLimitCnt, int commit) throws Exception { String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".sql"; String strFullPath = strTmpDir + strFile; final String UPDATE_STMT = "UPDATE " + tableName + " SET %s WHERE 1=1 %s;" + PublicTadpoleDefine.LINE_SEPARATOR; Map<Integer, String> mapColumnName = rsDAO.getColumnLabelName(); // ?? ./*from www . j a v a 2s . co m*/ StringBuffer sbInsertInto = new StringBuffer(); int DATA_COUNT = 1000; List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); Map<Integer, Integer> mapColumnType = rsDAO.getColumnType(); String strStatement = ""; String strWhere = ""; for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); strStatement = ""; strWhere = ""; for (int j = 1; j < mapColumnName.size(); j++) { String strColumnName = mapColumnName.get(j); Object strValue = mapColumns.get(j); strValue = strValue == null ? "" : strValue; if (!RDBTypeToJavaTypeUtils.isNumberType(mapColumnType.get(j))) { strValue = StringEscapeUtils.escapeSql(strValue.toString()); strValue = StringHelper.escapeSQL(strValue.toString()); strValue = SQLUtil.makeQuote(strValue.toString()); } boolean isWhere = false; for (String strTmpColumn : listWhere) { if (strColumnName.equals(strTmpColumn)) { isWhere = true; break; } } if (isWhere) strWhere += String.format("%s=%s and", strColumnName, strValue); else strStatement += String.format("%s=%s,", strColumnName, strValue); } strStatement = StringUtils.removeEnd(strStatement, ","); strWhere = StringUtils.removeEnd(strWhere, "and"); sbInsertInto.append(String.format(UPDATE_STMT, strStatement, strWhere)); if (intLimitCnt == i) { return sbInsertInto.toString(); } if (commit > 0 && (i % commit) == 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); sbInsertInto.setLength(0); } } if (sbInsertInto.length() > 0) { if (commit > 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); } return strFullPath; }
From source file:hydrograph.ui.engine.ui.converter.impl.OutputMysqlUiConverter.java
/** * Appends update keys using a comma//from w ww. j a va 2 s . c om * @param update */ private String getLoadTypeUpdateKeyUIValue(TypeUpdateKeys update) { StringBuffer buffer = new StringBuffer(); if (update != null && update.getUpdateByKeys() != null) { TypeKeyFields keyFields = update.getUpdateByKeys(); for (TypeFieldName fieldName : keyFields.getField()) { buffer.append(fieldName.getName()); buffer.append(","); } } return StringUtils.removeEnd(buffer.toString(), ","); }
From source file:info.magnolia.freemarker.FreemarkerServletContextWrapper.java
/** * Clean url and get the file.//from w ww.jav a2 s . c o m * @param url url to cleanup * @return file to url */ private File sanitizeToFile(URL url) { try { String fileUrl = url.getFile(); // needed because somehow the URLClassLoader has encoded URLs, and getFile does not decode them. fileUrl = URLDecoder.decode(fileUrl, "UTF-8"); // needed for Resin - for some reason, its URLs are formed as jar:file:/absolutepath/foo/bar.jar instead of // using the :///abs.. notation fileUrl = StringUtils.removeStart(fileUrl, "file:"); fileUrl = StringUtils.removeEnd(fileUrl, "!/"); return new File(fileUrl); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }