List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size, String padStr)
Right pad a String with a specified String.
From source file:org.oscarehr.PMmodule.exporter.AbstractIntakeExporter.java
private String getFieldValue(IntakeAnswer ans, DATISField field) { String value = ans.getValue(); if (value.equalsIgnoreCase(ANSWER_DECLINED)) { value = " "; }/*from w w w. j av a2 s .co m*/ if (value.length() > field.getMaxSize()) { value = value.substring(0, field.getMaxSize()); } else { value = StringUtils.rightPad(value, field.getMaxSize(), ' '); } return value; }
From source file:org.projectforge.user.UserDao.java
/** * Encrypts the given str with AES. The key is the current authenticationToken of the given user (by id) (first 16 bytes of it). * @param userId/* w ww .java 2s . c o m*/ * @param data * @return The base64 encoded result (url safe). * @see Crypt#encrypt(String, String) */ public String encrypt(final Integer userId, final String data) { final String authenticationToken = StringUtils.rightPad(getCachedAuthenticationToken(userId), 32, "x"); return Crypt.encrypt(authenticationToken, data); }
From source file:org.projectforge.user.UserDao.java
/** * @param userId/* ww w .ja v a2 s . c o m*/ * @param encryptedString * @return The decrypted string. * @see Crypt#decrypt(String, String) */ public String decrypt(final Integer userId, final String encryptedString) { final PFUserDO user = userGroupCache.getUser(userId); // for faster access (due to permanent usage e. g. by subscription of calendars // (ics). final String authenticationToken = StringUtils.rightPad(getCachedAuthenticationToken(userId), 32, "x"); return Crypt.decrypt(authenticationToken, encryptedString); }
From source file:org.redpill.alfresco.pdfapilot.worker.PdfaPilotWorker.java
private String getBasename(NodeRef node) { if (node == null || !_nodeService.exists(node)) { return "PPCTW_" + GUID.generate(); }/*from w w w. j a v a2 s . co m*/ try { String filename = (String) _nodeService.getProperty(node, ContentModel.PROP_NAME); String basename = FilenameUtils.getBaseName(filename); // TODO: Investigate if this is really needed // callas currently has a bug that makes it crash if the whole filepath is // longer than 260 characters basename = StringUtils.substring(basename, 0, 100); // 0x2013 is the long hyphen, not allowed here... char c = 0x2013; if (StringUtils.contains(basename, c)) { if (LOG.isTraceEnabled()) { LOG.trace("Long hyphen replaced with short one"); } basename = StringUtils.replaceChars(basename, c, '-'); } filename = basename; if (LOG.isTraceEnabled()) { LOG.trace("Filename before normalization"); for (char character : filename.toCharArray()) { LOG.trace(character + " : " + (int) character); } } filename = Normalizer.normalize(filename, Form.NFKC); if (LOG.isTraceEnabled()) { LOG.trace("Filename after normalization"); for (char character : filename.toCharArray()) { LOG.trace(character + " : " + (int) character); } } // pad the string with _ until it's at lest 3 characters long if (basename.length() < 3) { basename = StringUtils.rightPad(basename, 3, "_"); } return basename; } catch (final Exception ex) { throw new RuntimeException(ex); } }
From source file:org.springframework.xd.dirt.container.DefaultContainer.java
@Override public void stop() { if (this.context != null) { this.context.publishEvent(new ContainerStoppedEvent(this)); this.context.close(); if (logger.isInfoEnabled()) { final String message = "Stopped container: " + this.jvmName; final StringBuilder sb = new StringBuilder(LINE_SEPARATOR); sb.append(StringUtils.rightPad("", message.length(), "-")).append(LINE_SEPARATOR).append(message) .append(LINE_SEPARATOR).append(StringUtils.rightPad("", message.length(), "-")) .append(LINE_SEPARATOR); logger.info(sb.toString());/*from w w w . j a v a2s . co m*/ } } }
From source file:org.springframework.xd.dirt.container.XDContainer.java
@Override public void stop() { if (this.context != null && isContainerRunning()) { this.containerRunning = false; // Publish the container stopped event before the context is closed. this.context.publishEvent(new ContainerStoppedEvent(this)); this.context.close(); ((ConfigurableApplicationContext) context.getParent()).close(); if (logger.isInfoEnabled()) { final String message = "Stopped container: " + this.jvmName; final StringBuilder sb = new StringBuilder(LINE_SEPARATOR); sb.append(StringUtils.rightPad("", message.length(), "-")).append(LINE_SEPARATOR).append(message) .append(LINE_SEPARATOR).append(StringUtils.rightPad("", message.length(), "-")) .append(LINE_SEPARATOR); logger.info(sb.toString());//www . j a va 2 s . c om } } }
From source file:org.talend.dataprep.transformation.actions.text.Padding.java
protected String apply(String from, int size, char paddingChar, String position) { if (from == null) { return StringUtils.EMPTY; }//w ww.j a v a 2 s .c o m if (position.equals(LEFT_POSITION)) { return StringUtils.leftPad(from, size, paddingChar); } else { return StringUtils.rightPad(from, size, paddingChar); } }
From source file:stroom.streamstore.server.ReprocessDataHandler.java
@Override public SharedList<ReprocessDataInfo> exec(final ReprocessDataAction action) { final List<ReprocessDataInfo> info = new ArrayList<ReprocessDataInfo>(); try {// www . j a va2 s . com final FindStreamCriteria criteria = action.getCriteria(); criteria.getFetchSet().add(StreamProcessor.ENTITY_TYPE); criteria.getFetchSet().add(PipelineEntity.ENTITY_TYPE); // We only want 1000 streams to be // reprocessed at a maximum. criteria.obtainPageRequest().setOffset(0L); criteria.obtainPageRequest().setLength(MAX_STREAM_TO_REPROCESS); final BaseResultList<Stream> streams = streamStore.find(criteria); if (!streams.isExact()) { info.add(new ReprocessDataInfo(Severity.ERROR, "Results exceed " + MAX_STREAM_TO_REPROCESS + " configure a pipeline processor for large data sets", null)); } else { int skippingCount = 0; final StringBuilder unableListSB = new StringBuilder(); final StringBuilder submittedListSB = new StringBuilder(); final Map<StreamProcessor, EntityIdSet<Stream>> streamToProcessorSet = new HashMap<>(); for (final Stream stream : streams) { // We can only reprocess streams that have a stream // processor and a parent stream id. if (stream.getStreamProcessor() != null && stream.getParentStreamId() != null) { EntityIdSet<Stream> streamSet = streamToProcessorSet.get(stream.getStreamProcessor()); if (streamSet == null) { streamSet = new EntityIdSet<Stream>(); streamToProcessorSet.put(stream.getStreamProcessor(), streamSet); } streamSet.add(stream.getParentStreamId()); } else { skippingCount++; } } final List<StreamProcessor> list = new ArrayList<StreamProcessor>(streamToProcessorSet.keySet()); Collections.sort(list, new Comparator<StreamProcessor>() { @Override public int compare(final StreamProcessor o1, final StreamProcessor o2) { return o1.getPipeline().getName().compareTo(o2.getPipeline().getName()); } }); for (final StreamProcessor streamProcessor : list) { final EntityIdSet<Stream> streamSet = streamToProcessorSet.get(streamProcessor); final FindStreamCriteria findStreamCriteria = new FindStreamCriteria(); findStreamCriteria.setStreamIdSet(streamSet); if (!streamProcessor.isEnabled()) { unableListSB.append(streamProcessor.getPipeline().getName()); unableListSB.append("\n"); } else { final String padded = StringUtils.rightPad(streamProcessor.getPipeline().getName(), 40, ' '); submittedListSB.append(padded); submittedListSB.append("\t"); submittedListSB.append(streamSet.size()); submittedListSB.append(" streams\n"); streamProcessorFilterService.addFindStreamCriteria(streamProcessor, 10, findStreamCriteria); } } if (skippingCount > 0) { info.add(new ReprocessDataInfo(Severity.INFO, "Skipping " + skippingCount + " streams that are not a result of processing", null)); } final String unableList = unableListSB.toString().trim(); if (unableList.length() > 0) { info.add(new ReprocessDataInfo(Severity.WARNING, "Unable to reprocess all streams as some pipelines are not enabled", unableList)); } final String submittedList = submittedListSB.toString().trim(); if (submittedList.length() > 0) { info.add(new ReprocessDataInfo(Severity.INFO, "Created new processor filters to reprocess streams", submittedList)); } } } catch (final Exception ex) { info.add(new ReprocessDataInfo(Severity.ERROR, ex.getMessage(), null)); } return new SharedList<ReprocessDataInfo>(info); }
From source file:wzw.text.Formatter.java
/** * @param args//from w w w . j av a 2 s. c o m * @throws JspException */ public static void main(String[] args) throws Exception { /// Formatter fmt = new Formatter(); System.out.println( StringUtils.rightPad("fmt.formatObject( new Double(\"12345678\"),\"##,##0.##\") ", 60, " ") + "=" + Formatter.formatObject(new Double("12345678"), "##,##0.##")); System.out.println( StringUtils.rightPad("fmt.formatObject( new Double(\"12345678\"),\"##,##0.00\") ", 60, " ") + "=" + Formatter.formatObject(new Double("12345678"), "##,##0.00")); System.out.println( StringUtils.rightPad("fmt.formatObject( new Double(\"12345678\"),\"$##,##0.0#\") ", 60, " ") + "=" + Formatter.formatObject(new Double("12345678"), "$##,##0.0#")); System.out.println(StringUtils.rightPad("fmt.formatObject( new Double(\"12345678\"),\"##0.000\") ", 60, " ") + "=" + Formatter.formatObject(new Double("12345678"), "##0.000")); //System.out.println( StringUtils.rightPad("fmt.formatObject.add(1.2, 1.32) ", 35," ") // + "=" + fmt.formatObject( ("12345678"),"##0.000") ); }
From source file:wzw.util.DateUtils.java
/** * @param args//ww w . j a v a2 s . c o m */ public static void main(String[] args) { // ??? int pad = 35; System.out.println(StringUtils.rightPad("getCurrentDate()", pad, " ") + "=" + getCurrentDate()); System.out.println(StringUtils.rightPad("getCurrentDate('.')", pad, " ") + "=" + getCurrentDate(".")); System.out.println(StringUtils.rightPad("getCurrentTime()", pad, " ") + "=" + getCurrentTime()); System.out.println(StringUtils.rightPad("getCurrentTime('.')", pad, " ") + "=" + getCurrentTime(".")); System.out.println(StringUtils.rightPad("getCerrentDateAndTime()", pad, " ") + "=" + getCerrentDateTime()); System.out .println(StringUtils.rightPad("getYear(2002-09-13?)", pad, " ") + "=" + getYear("2002-09-13")); System.out.println(StringUtils.rightPad("getYear(2002-9-13?)", pad, " ") + "=" + getYear("2002-9-13")); System.out.println(StringUtils.rightPad("getYear(2002-9-1?)", pad, " ") + "=" + getYear("2002-9-1")); System.out.println( StringUtils.rightPad("getMonth(2002-09-13?)", pad, " ") + "=" + getMonth("2002-09-13")); System.out .println(StringUtils.rightPad("getMonth(2002-9-13?)", pad, " ") + "=" + getMonth("2002-9-13")); System.out.println(StringUtils.rightPad("getMonth(2002-9-1?)", pad, " ") + "=" + getMonth("2002-9-1")); System.out.println(StringUtils.rightPad("getDay(2002-09-13?)", pad, " ") + "=" + getDay("2002-09-13")); System.out.println(StringUtils.rightPad("getDay(2002-9-13?)", pad, " ") + "=" + getDay("2002-9-13")); System.out.println(StringUtils.rightPad("getDay(2002-9-1?)", pad, " ") + "=" + getDay("2002-9-1")); System.out.println(StringUtils.rightPad("getDay(2002-9-01?)", pad, " ") + "=" + getDay("2002-9-01")); System.out.println(StringUtils.rightPad("getDay(2002-9-1 12:02:05?)", pad, " ") + "=" + getDay("2002-9-1 12:02:05")); }