List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.kuali.kfs.module.purap.util.ItemParserBase.java
/** * @see org.kuali.kfs.module.purap.util.ItemParser#parseItem(org.apache.struts.upload.FormFile,java.lang.Class,java.lang.String) *//*from www . ja v a 2s. co m*/ public List<PurApItem> importItems(FormFile itemFile, Class<? extends PurApItem> itemClass, String documentNumber) { // check input parameters try { checkItemClass(itemClass); checkItemFile(itemFile); } catch (IllegalArgumentException e) { throw new InfrastructureException("unable to import items.", e); } // open input stream List<PurApItem> importedItems = new ArrayList<PurApItem>(); InputStream is; BufferedReader br; try { is = itemFile.getInputStream(); br = new BufferedReader(new InputStreamReader(is)); } catch (IOException e) { throw new InfrastructureException("unable to open import file in ItemParserBase.", e); } // parse items line by line lineNo = 0; boolean failed = false; String itemLine = null; try { while ((itemLine = br.readLine()) != null) { lineNo++; if (StringUtils .isBlank(StringUtils.remove(StringUtils.deleteWhitespace(itemLine), KFSConstants.COMMA))) { continue; } try { PurApItem item = parseItem(itemLine, itemClass, documentNumber); importedItems.add(item); } catch (ItemParserException e) { // continue to parse the rest of the items after the current item fails // error messages are already dealt with inside parseItem, so no need to do anything here failed = true; } } if (failed) { throw new ItemParserException("errors in parsing item lines in file " + itemFile.getFileName(), ERROR_ITEMPARSER_ITEM_LINE, itemFile.getFileName()); } } catch (IOException e) { throw new InfrastructureException("unable to read line from BufferReader in ItemParserBase", e); } finally { try { br.close(); } catch (IOException e) { throw new InfrastructureException("unable to close BufferReader in ItemParserBase", e); } } return importedItems; }
From source file:org.kuali.kfs.module.tem.batch.AgencyDataXmlInputFileType.java
/** * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(java.lang.String, java.lang.Object, java.lang.String) */// w ww .ja va 2 s. c o m @Override public String getFileName(String principalName, Object parsedFileContents, String fileUserIdentifier) { StringBuilder fileName = new StringBuilder(); fileUserIdentifier = StringUtils.deleteWhitespace(fileUserIdentifier); fileUserIdentifier = StringUtils.remove(fileUserIdentifier, TemConstants.FILE_NAME_PART_DELIMITER); fileName.append(this.getFileNamePrefix()).append(TemConstants.FILE_NAME_PART_DELIMITER); fileName.append(principalName).append(TemConstants.FILE_NAME_PART_DELIMITER); fileName.append(fileUserIdentifier).append(TemConstants.FILE_NAME_PART_DELIMITER); fileName.append(dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate())); return fileName.toString(); }
From source file:org.kuali.kfs.pdp.batch.PaymentInputFileType.java
/** * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(org.kuali.rice.kim.api.identity.Person, java.lang.Object, * java.lang.String)/*from www. j a v a 2 s. com*/ */ @Override public String getFileName(String principalName, Object parsedFileContents, String fileUserIdentifer) { Timestamp currentTimestamp = dateTimeService.getCurrentTimestamp(); String fileName = PdpConstants.PDP_FILE_UPLOAD_FILE_PREFIX + "_" + principalName; if (StringUtils.isNotBlank(fileUserIdentifer)) { fileName += "_" + StringUtils.remove(fileUserIdentifer, " "); } fileName += "_" + dateTimeService.toString(currentTimestamp, "yyyyMMdd_HHmmss"); // remove spaces in filename fileName = StringUtils.remove(fileName, " "); return fileName; }
From source file:org.kuali.kfs.sec.businessobject.lookup.AccessSecurityBalanceLookupableHelperServiceImpl.java
/** * changes from/to dates into the range operators the lookupable dao expects ("..",">" etc) this method modifies the passed in map and returns a list containing only the * modified fields//from w w w . j a va 2s . co m * * @param lookupFormFields */ protected Map<String, String> preprocessDateFields(Map lookupFormFields) { Map<String, String> fieldsToUpdate = new HashMap<String, String>(); Set<String> fieldsForLookup = lookupFormFields.keySet(); for (String propName : fieldsForLookup) { if (propName.startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) { String fromDateValue = (String) lookupFormFields.get(propName); String dateFieldName = StringUtils.remove(propName, KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX); String dateValue = (String) lookupFormFields.get(dateFieldName); String newPropValue = dateValue;// maybe clean above with ObjectUtils.clean(propertyValue) if (StringUtils.isNotEmpty(fromDateValue) && StringUtils.isNotEmpty(dateValue)) { newPropValue = fromDateValue + ".." + dateValue; } else if (StringUtils.isNotEmpty(fromDateValue) && StringUtils.isEmpty(dateValue)) { newPropValue = ">=" + fromDateValue; } else if (StringUtils.isNotEmpty(dateValue) && StringUtils.isEmpty(fromDateValue)) { newPropValue = "<=" + dateValue; } // could optionally continue on else here fieldsToUpdate.put(dateFieldName, newPropValue); } } // update lookup values from found date values to update Set<String> keysToUpdate = fieldsToUpdate.keySet(); for (String updateKey : keysToUpdate) { lookupFormFields.put(updateKey, fieldsToUpdate.get(updateKey)); } return fieldsToUpdate; }
From source file:org.kuali.kfs.sec.service.impl.AccessPermissionEvaluatorImpl.java
/** * Determines whether two values match performing an equal, greater than, or less than check and also considering wildcards * /*from w w w .j a v a2 s. co m*/ * @param matchValue String value to match, can contain the * wildcard * @param value String value to compare * @return boolean true if values match, false otherwise */ protected boolean isMatch(String matchValue, String value) { boolean match = false; boolean performWildcardMatch = false; if (StringUtils.contains(matchValue, SecConstants.SecurityValueSpecialCharacters.WILDCARD_CHARACTER)) { matchValue = StringUtils.remove(matchValue, SecConstants.SecurityValueSpecialCharacters.WILDCARD_CHARACTER); performWildcardMatch = true; } if (performEqualMatch) { if (performWildcardMatch) { match = value.startsWith(matchValue); } else { match = value.equals(matchValue); } } if (!match && performLessThanMatch) { match = value.compareTo(matchValue) < 0; } if (!match && performGreaterThanMatch) { match = value.compareTo(matchValue) > 0; } return match; }
From source file:org.kuali.kfs.sys.businessobject.AccountingLineParserBase.java
/** * Calls the appropriate parseAccountingLine method * /*from w ww.ja v a 2s .co m*/ * @param stream * @param transactionalDocument * @param isSource * @return List */ protected List<AccountingLine> importAccountingLines(String fileName, InputStream stream, AccountingDocument transactionalDocument, boolean isSource) { List<AccountingLine> importedAccountingLines = new ArrayList<AccountingLine>(); this.fileName = fileName; BufferedReader br = new BufferedReader(new InputStreamReader(stream)); try { String accountingLineAsString = null; lineNo = 0; while ((accountingLineAsString = br.readLine()) != null) { lineNo++; if (StringUtils.isBlank(StringUtils.remove(StringUtils.deleteWhitespace(accountingLineAsString), KFSConstants.COMMA))) { continue; } AccountingLine accountingLine = null; try { if (isSource) { accountingLine = parseSourceAccountingLine(transactionalDocument, accountingLineAsString); } else { accountingLine = parseTargetAccountingLine(transactionalDocument, accountingLineAsString); } validateImportedAccountingLine(accountingLine, accountingLineAsString); importedAccountingLines.add(accountingLine); } catch (AccountingLineParserException e) { GlobalVariables.getMessageMap().putError( (isSource ? "sourceAccountingLines" : "targetAccountingLines"), KFSKeyConstants.ERROR_ACCOUNTING_DOCUMENT_ACCOUNTING_LINE_IMPORT_GENERAL, new String[] { e.getMessage() }); } } } catch (IOException e) { throw new InfrastructureException("unable to readLine from bufferReader in accountingLineParserBase", e); } finally { try { br.close(); } catch (IOException e) { throw new InfrastructureException("unable to close bufferReader in accountingLineParserBase", e); } } return importedAccountingLines; }
From source file:org.kuali.kfs.vnd.batch.VendorExcludeInputFileType.java
@Override public Object parse(byte[] fileByteContent) throws ParseException { LOG.info("Parsing Vendor Exclude Input File ..."); // create CSVReader, using conventional separator, quote, null escape char, skip first line, use strict quote, ignore leading white space int skipLine = 1; // skip the first line, which is the header line Reader inReader = new InputStreamReader(new ByteArrayInputStream(fileByteContent)); CSVReader reader = new CSVReader(inReader, ',', '"', Character.MIN_VALUE, skipLine, true, true); List<DebarredVendorDetail> debarredVendors = new ArrayList<DebarredVendorDetail>(); String[] nextLine;// w w w . ja v a 2s . com DebarredVendorDetail vendor; int lineNumber = skipLine; try { while ((nextLine = reader.readNext()) != null) { lineNumber++; LOG.debug("Line " + lineNumber + ": " + nextLine[0]); vendor = new DebarredVendorDetail(); boolean emptyLine = true; // this should never happen, as for an empty line, CSVReader.readNext returns a string array with an empty string as the only element // but just in case somehow a zero sized array is returned, we skip it. if (nextLine.length == 0) { continue; } StringBuffer name = new StringBuffer(); // if the name field is not empty, use that as vendor name if (StringUtils.isNotEmpty(nextLine[0])) { name.append(nextLine[0]); } // otherwise, there should be a first/middle/last name, which we concatenate into vendor name else { if (nextLine.length > 1 && !StringUtils.isNotEmpty(nextLine[1])) { name.append(" " + nextLine[1]); } if (nextLine.length > 2 && !StringUtils.isNotEmpty(nextLine[2])) { name.append(" " + nextLine[2]); } if (nextLine.length > 3 && !StringUtils.isNotEmpty(nextLine[3])) { name.append(" " + nextLine[3]); } if (nextLine.length > 4 && !StringUtils.isNotEmpty(nextLine[4])) { name.append(" " + nextLine[4]); } if (nextLine.length > 5 && StringUtils.isNotEmpty(nextLine[5])) { name.append(" " + nextLine[5]); } } if (StringUtils.isNotEmpty(name.toString())) { vendor.setName(StringUtils.left(name.toString(), FIELD_SIZES[0])); emptyLine = false; } if (nextLine.length > 6 && StringUtils.isNotEmpty(nextLine[6])) { vendor.setAddress1(StringUtils.left(nextLine[6], FIELD_SIZES[1])); emptyLine = false; } if (nextLine.length > 7 && StringUtils.isNotEmpty(nextLine[7])) { vendor.setAddress2(StringUtils.left(nextLine[7], FIELD_SIZES[2])); emptyLine = false; } if (nextLine.length > 8 && StringUtils.isNotEmpty(nextLine[8])) { vendor.setCity(StringUtils.left(nextLine[8], FIELD_SIZES[3])); emptyLine = false; } if (nextLine.length > 9 && StringUtils.isNotEmpty(nextLine[9])) { vendor.setProvince(StringUtils.left(nextLine[9], FIELD_SIZES[4])); emptyLine = false; } if (nextLine.length > 10 && StringUtils.isNotEmpty(nextLine[10])) { vendor.setState(StringUtils.left(nextLine[10], FIELD_SIZES[5])); emptyLine = false; } if (nextLine.length > 11 && StringUtils.isNotEmpty(nextLine[11])) { vendor.setZip(StringUtils.left(nextLine[11], FIELD_SIZES[6])); emptyLine = false; } if (nextLine.length > 13 && StringUtils.isNotEmpty(nextLine[13])) { vendor.setAliases(StringUtils.left(StringUtils.remove(nextLine[13], "\""), FIELD_SIZES[7])); emptyLine = false; } if (nextLine.length > 18 && StringUtils.isNotEmpty(nextLine[18])) { vendor.setDescription(StringUtils.left(nextLine[18], FIELD_SIZES[8])); emptyLine = false; } if (emptyLine) { /* give warnings on a line that doesn't have any useful vendor info LOG.warn("Note: line " + lineNumber + " in the Vendor Exclude Input File is skipped since all parsed fields are empty."); */ // throw parser exception on a line that doesn't have any useful vendor info. // Since the file usually doesn't contain empty lines or lines with empty fields, this happening usually is a good indicator that // some line ahead has wrong data format, for ex, missing a quote on a field, which could mess up the following fields and lines. throw new ParseException("Line " + lineNumber + " in the Vendor Exclude Input File contains no valid field or only empty fields within quote pairs. Please check the lines ahead to see if any field is missing quotes."); } else { vendor.setLoadDate(new Date(new java.util.Date().getTime())); debarredVendors.add(vendor); } } } catch (IOException ex) { throw new ParseException( "Error reading Vendor Exclude Input File at line " + lineNumber + ": " + ex.getMessage()); } LOG.info("Total number of lines read from Vendor Exclude Input File: " + lineNumber); LOG.info("Total number of vendors parsed from Vendor Exclude Input File: " + debarredVendors.size()); return debarredVendors; }
From source file:org.kuali.kpme.pm.position.web.PositionLookupableImpl.java
@Override protected Collection<?> executeSearch(Map<String, String> searchCriteria, List<String> wildcardAsLiteralSearchCriteria, boolean bounded, Integer searchResultsLimit) { List<PositionContract> retVal = new ArrayList<PositionContract>(); // read and remove the primary department from the field map String primaryDepartment = searchCriteria.remove("primaryDepartment"); // KPME-3189 List<PositionContract> posContracts = (List<PositionContract>) super.executeSearch(searchCriteria, wildcardAsLiteralSearchCriteria, bounded, searchResultsLimit); if (StringUtils.isEmpty(primaryDepartment)) { retVal = posContracts;/* w w w. j a va2s . c om*/ } else { // clean out wildcards from user entered value for primary department - KPME-3189 // TODO: shouldn't this be doing wildcard based matching (using regexes perhaps) instead? primaryDepartment = StringUtils.remove(StringUtils.remove(primaryDepartment, "*"), "%"); // check for each position if its primary department matches the user entered primary department for (PositionContract posContract : posContracts) { List<? extends PositionDepartmentContract> posDepartments = posContract.getDepartmentList(); for (PositionDepartmentContract posDepartment : posDepartments) { if (posDepartment.getDeptAfflObj().isPrimaryIndicator()) { if (posDepartment.getDepartment().toUpperCase().equals(primaryDepartment.toUpperCase())) { retVal.add(posContract); break; } } } } } List<PositionContract> results = filterLookupPositions(retVal); return results; }
From source file:org.kuali.kra.proposaldevelopment.bo.ProposalPerson.java
/** * set the <code>simpleName</code> & the full name. *//*from www. j a va2s . c o m*/ public void setFullName(String fullName) { this.fullName = fullName; setSimpleName(getFullName()); setSimpleName(getSimpleName().toLowerCase()); setSimpleName(StringUtils.deleteWhitespace(getSimpleName())); setSimpleName(StringUtils.remove(getSimpleName(), '.')); }
From source file:org.kuali.kra.s2s.service.impl.S2SUtilServiceImpl.java
public String removeTimezoneFactor(String applicationXmlText) { SimpleDateFormat timeFormat = new SimpleDateFormat("Z"); String offset = timeFormat.format(dateTimeService.getCurrentDate()); String offsetString = offset.substring(0, 3) + ":" + offset.substring(3); String filteredApplicationStr = StringUtils.remove(applicationXmlText, offsetString); return filteredApplicationStr; }