List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size)
Left pad a String with spaces (' ').
From source file:org.kuali.kfs.gl.batch.service.impl.CollectorReportServiceImpl.java
/** * Writes the Amount/Count line of the Collector to a buffer * * @param buf the buffer to write the line to * @param countTitle the title of this part of the report * @param count the Collector count/*from w w w.j av a 2 s . c om*/ * @param amountString the Collector amount */ protected void appendAmountCountLine(StringBuilder buf, String countTitle, String count, KualiDecimal amount) { appendPaddingString(buf, ' ', countTitle.length(), 35); buf.append(countTitle); appendPaddingString(buf, '0', count.length(), 5); buf.append(count); if (amount == null) { buf.append(StringUtils.leftPad("N/A", 21)); } else { Map<String, String> settings = new HashMap<String, String>(); settings.put(CurrencyFormatter.SHOW_SYMBOL, Boolean.TRUE.toString()); org.kuali.rice.core.web.format.Formatter f = org.kuali.rice.core.web.format.Formatter .getFormatter(KualiDecimal.class, settings); String amountString = (String) f.format(amount); appendPaddingString(buf, ' ', amountString.length(), 21); buf.append(amountString); } buf.append("\n"); }
From source file:org.kuali.kfs.module.bc.document.service.impl.PayrateExportServiceImpl.java
/** * Returns a field that is the length of fieldSize, to facilitate formatting payrate export file * /*from w w w . jav a2 s.c om*/ * @param stringToPad * @param fieldSize * @return */ @NonTransactional protected String padString(String stringToPad, int fieldSize, boolean leftJustifiy) { if (stringToPad.length() < fieldSize) { if (leftJustifiy) return StringUtils.rightPad(stringToPad, fieldSize); else return StringUtils.leftPad(stringToPad, fieldSize); } else if (stringToPad.length() > fieldSize) return stringToPad.substring(0, fieldSize - 1); return stringToPad; }
From source file:org.kuali.kfs.pdp.service.impl.PdpEmailServiceImpl.java
/** * @see org.kuali.kfs.pdp.service.PdpEmailService#sendAchSummaryEmail(java.util.Map, java.util.Map, java.util.Date) *//*from w w w . j a v a 2 s . c o m*/ @Override public void sendAchSummaryEmail(Map<String, Integer> unitCounts, Map<String, KualiDecimal> unitTotals, Date disbursementDate) { LOG.debug("sendAchSummaryEmail() starting"); MailMessage message = new MailMessage(); List<String> toAddressList = new ArrayList<String>(parameterService.getParameterValuesAsString( ExtractAchPaymentsStep.class, PdpParameterConstants.ACH_SUMMARY_TO_EMAIL_ADDRESS_PARMAETER_NAME)); message.getToAddresses().addAll(toAddressList); message.getCcAddresses().addAll(toAddressList); message.getBccAddresses().addAll(toAddressList); String returnAddress = parameterService.getParameterValueAsString(KFSConstants.ParameterNamespaces.PDP, "Batch", KFSConstants.FROM_EMAIL_ADDRESS_PARM_NM); if (StringUtils.isEmpty(returnAddress)) { returnAddress = mailService.getBatchMailingList(); } message.setFromAddress(returnAddress); String subject = parameterService.getParameterValueAsString(ExtractAchPaymentsStep.class, PdpParameterConstants.ACH_SUMMARY_EMAIL_SUBJECT_PARAMETER_NAME); message.setSubject(subject); StringBuilder body = new StringBuilder(); body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_DISB_DATE, disbursementDate) + "\n"); Integer totalCount = 0; KualiDecimal totalAmount = KualiDecimal.ZERO; for (String unit : unitCounts.keySet()) { body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_UNIT_TOTAL, StringUtils.leftPad(unit, 13), StringUtils.leftPad(unitCounts.get(unit).toString(), 10), StringUtils.leftPad(unitTotals.get(unit).toString(), 20)) + "\n"); totalCount = totalCount + unitCounts.get(unit); totalAmount = totalAmount.add(unitTotals.get(unit)); } body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_EXTRACT_TOTALS, StringUtils.leftPad(totalCount.toString(), 10), StringUtils.leftPad(totalAmount.toString(), 20)) + "\n"); body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_COMPLETE)); message.setMessage(body.toString()); // KFSMI-6475 - if not a production instance, replace the recipients with the testers list alterMessageWhenNonProductionInstance(message, null); try { mailService.sendMessage(message); } catch (Exception e) { LOG.error("sendAchSummaryEmail() Invalid email address. Message not sent", e); } }
From source file:org.kuali.ole.pdp.service.impl.PdpEmailServiceImpl.java
/** * @see org.kuali.ole.pdp.service.PdpEmailService#sendAchSummaryEmail(java.util.Map, java.util.Map, java.util.Date) *//*w w w.ja v a 2s. co m*/ @Override public void sendAchSummaryEmail(Map<String, Integer> unitCounts, Map<String, KualiDecimal> unitTotals, Date disbursementDate) { LOG.debug("sendAchSummaryEmail() starting"); MailMessage message = new MailMessage(); List<String> toAddressList = new ArrayList<String>(parameterService.getParameterValuesAsString( ExtractAchPaymentsStep.class, PdpParameterConstants.ACH_SUMMARY_TO_EMAIL_ADDRESS_PARMAETER_NAME)); message.getToAddresses().addAll(toAddressList); message.getCcAddresses().addAll(toAddressList); message.getBccAddresses().addAll(toAddressList); String returnAddress = parameterService.getParameterValueAsString(OLEConstants.ParameterNamespaces.PDP, "Batch", OLEConstants.FROM_EMAIL_ADDRESS_PARM_NM); if (StringUtils.isEmpty(returnAddress)) { returnAddress = mailService.getBatchMailingList(); } message.setFromAddress(returnAddress); String subject = parameterService.getParameterValueAsString(ExtractAchPaymentsStep.class, PdpParameterConstants.ACH_SUMMARY_EMAIL_SUBJECT_PARAMETER_NAME); message.setSubject(subject); StringBuilder body = new StringBuilder(); body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_DISB_DATE, disbursementDate) + "\n"); Integer totalCount = 0; KualiDecimal totalAmount = KualiDecimal.ZERO; for (String unit : unitCounts.keySet()) { body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_UNIT_TOTAL, StringUtils.leftPad(unit, 13), StringUtils.leftPad(unitCounts.get(unit).toString(), 10), StringUtils.leftPad(unitTotals.get(unit).toString(), 20)) + "\n"); totalCount = totalCount + unitCounts.get(unit); totalAmount = totalAmount.add(unitTotals.get(unit)); } body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_EXTRACT_TOTALS, StringUtils.leftPad(totalCount.toString(), 10), StringUtils.leftPad(totalAmount.toString(), 20)) + "\n"); body.append(getMessage(PdpKeyConstants.MESSAGE_PDP_ACH_SUMMARY_EMAIL_COMPLETE)); message.setMessage(body.toString()); // KFSMI-6475 - if not a production instance, replace the recipients with the testers list alterMessageWhenNonProductionInstance(message, null); try { mailService.sendMessage(message); } catch (Exception e) { LOG.error("sendAchSummaryEmail() Invalid email address. Message not sent", e); } }
From source file:org.nuxeo.ecm.server.info.service.impl.ServerInfoCollectorImpl.java
protected void appendInfoList(StringBuilder sb, String label, List<String> values) { sb.append(label);/*from w w w . j a va2 s .c o m*/ sb.append(":\n"); int spacerLength = label.length() + 2; for (String value : values) { sb.append(StringUtils.leftPad("", spacerLength)); sb.append(value); sb.append("\n"); } }
From source file:org.nuxeo.ecm.server.info.service.impl.ServerInfoCollectorImpl.java
protected void appendBundleInfos(StringBuilder sb, String label, List<SimplifiedBundleInfo> values) { sb.append(label);/* w w w .ja va 2s .c om*/ sb.append(":\n"); int spacerLength = label.length() + 2; for (SimplifiedBundleInfo value : values) { sb.append(StringUtils.leftPad("", spacerLength)); sb.append(value.getName()); sb.append("\t"); sb.append(value.getVersion()); sb.append("\n"); } }
From source file:org.onosproject.store.primitives.impl.FederatedDistributedPrimitiveCreator.java
/** * Returns the {@code DistributedPrimitiveCreator} to use for hosting a primitive. * @param name primitive name/*from www .jav a 2 s . co m*/ * @return primitive creator */ private DistributedPrimitiveCreator getCreator(String name) { long hashCode = HashCode.fromBytes(Tools.getBytesUtf8(StringUtils.leftPad(name, 8))).asLong(); int index = Hashing.consistentHash(hashCode, members.size()); return members.get(sortedMemberPartitionIds.get(index)); }
From source file:org.openspotlight.graph.query.console.command.system.HelpSystemCommand.java
/** * Instantiates a new help system command. * // w ww. j a v a2 s .com * @param commands all the commands (system and dynamic) */ public HelpSystemCommand(final Collection<Command> commands) { int maxSize = 4; if (commands != null) { int size = 0; for (final Command command : commands) { if (command != null) { size++; } } descriptions = new String[size + 1]; for (final Command command : commands) { if (command != null && command.getCommand().length() > maxSize) { maxSize = command.getCommand().length(); } } int i = 0; for (final Command command : commands) { if (command != null) { descriptions[i] = StringUtils.leftPad(command.getCommand(), maxSize) + " - " + command.getDescription(); i++; } } } else { descriptions = new String[1]; } descriptions[0] = StringUtils.leftPad("help", maxSize) + " - " + getDescription(); }
From source file:org.opoo.press.impl.SiteImpl.java
public SiteImpl(ConfigImpl siteConfig) { super();//from ww w . j a v a2s. com this.config = siteConfig; this.data = new HashMap<String, Object>(/*config*/); this.basedir = config.getBasedir(); this.root = config.get("root", ""); this.permalink = config.get("permalink"); this.showDrafts = config.get("show_drafts", false); boolean debug = config.get("debug", false); if (showDrafts) { log.info("+ Show drafts option set 'ON'"); } if (debug) { for (Map.Entry<String, Object> en : config.entrySet()) { String name = en.getKey(); name = StringUtils.leftPad(name, 25); log.info(name + ": " + en.getValue()); } } //theme theme = createTheme(); //templates templates = theme.getTemplates(); log.debug("Template directory: {}", templates); //sources sources = new ValidDirList(); sources.addDir(theme.getSource()); List<String> sourcesConfig = config.get("source_dirs"); sources.addDirs(basedir, sourcesConfig); log.debug("Source directories: {}", sources); //assets assets = new ValidDirList(); assets.addDir(theme.getAssets()); List<String> assetsConfig = config.get("asset_dirs"); assets.addDirs(basedir, assetsConfig); log.debug("Assets directories: {}", assets); //target directory String destDir = config.get("dest_dir"); this.dest = PathUtils.appendBaseIfNotAbsolute(basedir, destDir); log.debug("Destination directory: {}", dest); //working directory String workingDir = config.get("work_dir"); this.working = PathUtils.appendBaseIfNotAbsolute(basedir, workingDir); log.debug("Working directory: {}", working); reset(); setup(); }
From source file:org.pentaho.di.trans.steps.edi2xml.Edi2Xml.java
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { meta = (Edi2XmlMeta) smi;/*w ww.ja v a 2 s . c om*/ data = (Edi2XmlData) sdi; Object[] r = getRow(); // get row, blocks when needed! if (r == null) { // no more input to be expected... setOutputDone(); return false; } String inputValue = ""; if (first) { first = false; data.inputRowMeta = getInputRowMeta().clone(); data.outputRowMeta = getInputRowMeta().clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore); String realInputField = environmentSubstitute(meta.getInputField()); String realOutputField = environmentSubstitute(meta.getOutputField()); data.inputFieldIndex = getInputRowMeta().indexOfValue(realInputField); int numErrors = 0; if (data.inputFieldIndex < 0) { logError(BaseMessages.getString(PKG, "Edi2Xml.Log.CouldNotFindInputField", realInputField)); numErrors++; } if (!data.inputRowMeta.getValueMeta(data.inputFieldIndex).isString()) { logError(BaseMessages.getString(PKG, "Edi2Xml.Log.InputFieldIsNotAString", realInputField)); numErrors++; } if (numErrors > 0) { setErrors(numErrors); stopAll(); return false; } data.inputMeta = data.inputRowMeta.getValueMeta(data.inputFieldIndex); if (Const.isEmpty(meta.getOutputField())) { // same field data.outputMeta = data.outputRowMeta.getValueMeta(data.inputFieldIndex); data.outputFieldIndex = data.inputFieldIndex; } else { // new field data.outputMeta = data.outputRowMeta.searchValueMeta(realOutputField); data.outputFieldIndex = data.outputRowMeta.size() - 1; } // create instances of lexer/tokenstream/parser // treat null values as empty strings for parsing purposes inputValue = Const.NVL(data.inputMeta.getString(r[data.inputFieldIndex]), ""); lexer = new FastSimpleGenericEdifactDirectXMLLexer(new ANTLRStringStream(inputValue)); tokens = new CommonTokenStream(lexer); parser = new FastSimpleGenericEdifactDirectXMLParser(tokens); } else { // treat null values as empty strings for parsing purposes inputValue = Const.NVL(data.inputMeta.getString(r[data.inputFieldIndex]), ""); lexer.setCharStream(new ANTLRStringStream(inputValue)); tokens.setTokenSource(lexer); parser.setTokenStream(tokens); } try { parser.edifact(); // make sure the row is big enough r = RowDataUtil.resizeArray(r, data.outputRowMeta.size()); // place parsing result into output field r[data.outputFieldIndex] = parser.buf.toString(); putRow(data.outputRowMeta, r); } catch (MismatchedTokenException e) { StringBuilder errorMessage = new StringBuilder(180); errorMessage.append("error parsing edi on line " + e.line + " position " + e.charPositionInLine); errorMessage.append(": expecting " + ((e.expecting > -1) ? parser.getTokenNames()[e.expecting] : "<UNKNOWN>") + " but found "); errorMessage.append((e.token.getType() >= 0) ? parser.getTokenNames()[e.token.getType()] : "<EOF>"); if (getStepMeta().isDoingErrorHandling()) { putError(getInputRowMeta(), r, 1L, errorMessage.toString(), environmentSubstitute(meta.getInputField()), "MALFORMED_EDI"); } else { logError(errorMessage.toString()); // try to determine the error line String errorline = "<UNKNOWN>"; try { errorline = inputValue.split("\\r?\\n")[e.line - 1]; } catch (Exception ee) { // Ignore pattern syntax errors } logError("Problem line: " + errorline); logError(StringUtils.leftPad("^", e.charPositionInLine + "Problem line: ".length() + 1)); throw new KettleException(e); } } catch (RecognitionException e) { StringBuilder errorMessage = new StringBuilder(180); errorMessage.append("error parsing edi on line ").append(e.line).append(" position ") .append(e.charPositionInLine).append(". ").append(e.toString()); if (getStepMeta().isDoingErrorHandling()) { putError(getInputRowMeta(), r, 1L, errorMessage.toString(), environmentSubstitute(meta.getInputField()), "MALFORMED_EDI"); } else { logError(errorMessage.toString()); // try to determine the error line String errorline = "<UNKNOWN>"; try { errorline = inputValue.split("\\r?\\n")[e.line - 1]; } catch (Exception ee) { // Ignore pattern syntax errors } logError("Problem line: " + errorline); logError(StringUtils.leftPad("^", e.charPositionInLine + "Problem line: ".length() + 1)); throw new KettleException(e); } } if (checkFeedback(getLinesRead())) { logBasic("Linenr " + getLinesRead()); } return true; }