List of usage examples for org.apache.commons.lang CharUtils LF
char LF
To view the source code for org.apache.commons.lang CharUtils LF.
Click Source Link
linefeed LF ('\n'). From source file:de.hybris.platform.servicelayer.cronjob.impl.DefaultJobLogConverterTest.java
@Test public void testValidFormatLogs() { final String pattern = "dd HH"; converter.setDateFormatPattern(pattern); final Date date = new Date(); final JobLogModel logEntry = new JobLogModel(); logEntry.setCreationtime(date);//from w w w. java 2s.c o m logEntry.setLevel(JobLogLevel.FATAL); final List<JobLogModel> entries = Arrays.asList(logEntry); final String result = converter.convert(entries); Mockito.verify(formatFactory, Mockito.times(1)).createDateTimeFormat(DateFormat.DEFAULT, -1); final SimpleDateFormat sdf = (SimpleDateFormat) formatFactory.createDateTimeFormat(DateFormat.DEFAULT, -1); sdf.applyPattern(pattern); Assert.assertEquals(result, String.format("%s: FATAL: <empty>" + CharUtils.LF, sdf.format(date))); }
From source file:de.hybris.platform.webservices.PriceResourceTest.java
/** * creates some test purpose discounts/vouchers/tax row entries *///from www .j av a2s . c om private void createTestDiscountsTaxes(final String productCode) throws ImpExException { final StringBuffer taxBuffer = new StringBuffer(1000); taxBuffer.append( "insert_update Tax;code[unique=true,allownull=true];currency(isocode);name[lang=testLang1];value;") .append(CharUtils.LF); taxBuffer.append(";RobinHoodTax;;RobinHood's Tax;" + TAX_LEVEL + ";").append(CharUtils.LF); new ImpExImportReader(taxBuffer.toString()).readAll(); final StringBuffer promoBuffer = new StringBuffer(1000); promoBuffer.append( "insert_update Discount;code[unique=true,forceWrite=true,allownull=true];currency(isocode);name[lang=testLang1];value[allownull=true];") .append(CharUtils.LF); promoBuffer.append(";TestVoucher;---;TestVoucher;5;").append(CharUtils.LF); new ImpExImportReader(promoBuffer.toString()).readAll(); final StringBuffer discountBuffer = new StringBuffer(1000); discountBuffer.append( "insert_update DiscountRow;catalogVersion(catalog(id),version);currency(isocode);discount(code)[forceWrite=true,allownull=true];pg(code,itemtype(code));product(catalogVersion(catalog(id),version),code)[unique=true];ug(code,itemtype(code));user(uid);value;") .append(CharUtils.LF); discountBuffer.append(";testCatalog1:testVersion1;---;TestVoucher;;testCatalog1:testVersion1:" + productCode + ";;anonymous;" + discountValue + ";").append(CharUtils.LF); new ImpExImportReader(discountBuffer.toString()).readAll(); final StringBuffer taxRowBuffer = new StringBuffer(1000); taxRowBuffer.append( "insert_update TaxRow;catalogVersion(catalog(id),version)[unique=true];currency(isocode);pg(code,itemtype(code));product(catalogVersion(catalog(id),version),code)[unique=true];tax(code)[forceWrite=true,allownull=true];ug(code,itemtype(code));user(uid);value") .append(CharUtils.LF); taxRowBuffer.append(";;;;testCatalog1:testVersion1:" + productCode + ";RobinHoodTax;;;") .append(CharUtils.LF); new ImpExImportReader(taxRowBuffer.toString()).readAll(); final StringBuffer priceRowBuffer = new StringBuffer(1000); priceRowBuffer.append( "insert_update PriceRow;catalogVersion(catalog(id),version);currency(isocode)[allownull=true];giveAwayPrice[allownull=true];matchValue;minqtd[allownull=true,unique=true];net[allownull=true];owner(pk);pg(code,itemtype(code));price[allownull=true];product(catalogVersion(catalog(id),version),code)[unique=true];ug(code,itemtype(code));unit(code)[allownull=true];user(uid)") .append(CharUtils.LF); priceRowBuffer.append(";testCatalog1:testVersion1;---;false;5;" + itemCountLevel + ";false;;;" + PRICE_LEVEL_1 + ";testCatalog1:testVersion1:" + productCode + ";;testUnit1;") .append(CharUtils.LF); priceRowBuffer.append(";testCatalog1:testVersion1;---;false;5;0;false;;;" + PRICE_LEVEL_2 + ";testCatalog1:testVersion1:" + productCode + ";;testUnit1;").append(CharUtils.LF); new ImpExImportReader(priceRowBuffer.toString()).readAll(); }
From source file:de.hybris.platform.servicelayer.cronjob.CronJobServiceTest.java
@Test public void testGetLogTextForOneEntry() { final ServicelayerJobModel job = modelService.create(ServicelayerJobModel.class); job.setCode("testJob"); job.setSpringId("moveMediaJob"); final MoveMediaCronJobModel cronJob = modelService.create(MoveMediaCronJobModel.class); cronJob.setCode("test"); cronJob.setJob(job);//ww w. j a va 2 s .c om modelService.saveAll(job, cronJob); final JobLogModel jobLog = modelService.create(JobLogModel.class); jobLog.setCronJob(cronJob); jobLog.setLevel(de.hybris.platform.cronjob.enums.JobLogLevel.ERROR); final StringBuffer buffer = new StringBuffer(1000); for (int i = 0; i < 500; i++) { buffer.append("Sample message").append(CharUtils.LF); } jobLog.setMessage(buffer.toString()); modelService.save(jobLog); final String oneEntry = cronJobService.getLogsAsText(cronJob, 1); Assert.assertEquals(10, oneEntry.split(String.valueOf(CharUtils.LF)).length); }
From source file:de.hybris.platform.servicelayer.cronjob.impl.DefaultJobLogConverterTest.java
@Test public void testValidFormatLogsWithEntries() { final String pattern = "dd HH"; converter.setDateFormatPattern(pattern); final StringBuilder messageBuilder = new StringBuilder(1000); for (int i = 0; i < 5; i++) { messageBuilder.append("message" + i + CharUtils.LF); }/*from ww w. j a v a 2 s. c o m*/ final Date date = new Date(); final JobLogModel logEntry = new JobLogModel(); logEntry.setCreationtime(date); logEntry.setLevel(JobLogLevel.FATAL); logEntry.setMessage(messageBuilder.toString()); final List<JobLogModel> entries = Arrays.asList(logEntry); final String result = converter.convert(entries); Mockito.verify(formatFactory, Mockito.times(1)).createDateTimeFormat(DateFormat.DEFAULT, -1); final SimpleDateFormat sdf = (SimpleDateFormat) formatFactory.createDateTimeFormat(DateFormat.DEFAULT, -1); sdf.applyPattern(pattern); Assert.assertEquals(result, String.format("%s: FATAL: " + messageBuilder.toString(), sdf.format(date))); }
From source file:de.hybris.platform.catalog.job.strategy.impl.AbstractRemoveStrategy.java
/** * Starts catalog version removal , returns true if wait for started import job needed *//*from ww w .j a va 2 s .c o m*/ protected void removeCatalogVersionCollection(final Collection<CatalogVersionModel> catalogVersions, final RemoveCatalogVersionCronJobModel cronJob, final List<ComposedTypeModel> orderedComposedTypes) { ImportResult result = null; StringBuilder buffer = null; try { removeCallback.beforeRemove(cronJob, catalogVersions); for (final CatalogVersionModel catalogVersionModel : catalogVersions) { final int countBefore = catalogVersionDao.getItemInstanceCount(catalogVersionModel, orderedComposedTypes); if (countBefore > 0) { if (buffer == null) { buffer = new StringBuilder(1000); } buffer.append(removeScriptGenerator.generate(catalogVersionModel, orderedComposedTypes)); if (LOG.isDebugEnabled()) { LOG.debug("Generated script [" + CharUtils.LF + buffer.toString() + CharUtils.LF + "] for removing " + countBefore + " items from catalogversion " + catalogVersionModel); } } } if (buffer != null) { LOG.info("Starting impex based removing of the catalogversions " + catalogVersions); try { final ImportConfig config = getImpexConfig(buffer); result = importService.importData(config); //this code is because result seemed to be isRuninng = false //Thread.sleep(POLL_PERIOD);//sleep LOG.info(" Import is running " + result.isRunning() + " finished " + result.isFinished() + " status " + result.getCronJob().getStatus() + " cronjob " + result.getCronJob().getCode()); while (result.isRunning() && result.getCronJob() != null) { //this is only for presenting the progress to outside removeCallback.doRemove(cronJob, catalogVersions, result); Thread.sleep(POLL_PERIOD);//sleep if (result.getCronJob() != null) { modelService.refresh(result.getCronJob()); } } } catch (final InterruptedException e) { LOG.error("Current thread " + Thread.currentThread() + " was interrupted with message " + e.getMessage() + ", please set log level to debug for more details"); if (LOG.isDebugEnabled()) { LOG.error(e.getMessage(), e); } Thread.currentThread().interrupt(); } catch (final Exception e) { LOG.error(e.getMessage(), e); } } } finally { removeCallback.afterRemoved(cronJob, catalogVersions, result); if (result != null) { if (LOG.isDebugEnabled()) { LOG.debug("After job finished with result, unresolved lines " + result.hasUnresolvedLines() + ", is finished :" + result.isFinished() + ", is running :" + result.isRunning()); } } } }
From source file:de.hybris.platform.acceleratorservices.dataimport.batch.converter.impl.DefaultImpexConverter.java
protected boolean doesNotContainNewLine(final String string) { return !StringUtils.contains(string, CharUtils.LF); }
From source file:de.hybris.platform.servicelayer.cronjob.impl.DefaultJobLogConverterTest.java
@Test public void testValidFormatLogsWithEntriesTruncated() { final String pattern = "dd HH"; converter.setDateFormatPattern(pattern); final StringBuilder messageFromLogs = new StringBuilder(1000); for (int i = 0; i < 15; i++) { messageFromLogs.append("message" + i + CharUtils.LF); }/*from w w w . j a va2 s . c om*/ final StringBuilder messageExpected = new StringBuilder(1000); for (int i = 0; i < 10; i++) { messageExpected.append("message" + i + (i == 9 ? "" : String.valueOf(CharUtils.LF))); } messageExpected.append(" ..." + CharUtils.LF); final Date date = new Date(); final JobLogModel logEntry = new JobLogModel(); logEntry.setCreationtime(date); logEntry.setLevel(JobLogLevel.FATAL); logEntry.setMessage(messageFromLogs.toString()); final List<JobLogModel> entries = Arrays.asList(logEntry); final String result = converter.convert(entries); Mockito.verify(formatFactory, Mockito.times(1)).createDateTimeFormat(DateFormat.DEFAULT, -1); final SimpleDateFormat sdf = (SimpleDateFormat) formatFactory.createDateTimeFormat(DateFormat.DEFAULT, -1); sdf.applyPattern(pattern); Assert.assertEquals(result, String.format("%s: FATAL: " + messageExpected.toString(), sdf.format(date))); }
From source file:com.dtolabs.rundeck.core.cli.CLIUtils.java
public static void escapeUnixShellChars(StringBuilder out, String str) { if (StringUtils.containsNone(str, UNIX_SHELL_CHARS)) { if (str != null) { out.append(str);//from w w w. j a v a2 s . c o m } return; } for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (UNIX_SHELL_CHARS.indexOf(c) >= 0) { out.append('\\'); } else if (WS_CHARS.indexOf(c) >= 0) { out.append('\\'); if (c == CharUtils.CR) { out.append('r'); } else if (c == CharUtils.LF) { out.append('n'); } else if (c == '\t') { out.append('t'); } continue; } out.append(c); } }
From source file:de.hybris.platform.maintenance.CleanupCronJobIntegrationTest.java
private void createCronJobs(final String codeprefix, final CronJobResult cjr, final CronJobStatus cjs, final int count, final int daysold, final String cronjobtype) throws ImpExException { final StringBuffer cronjobbuffer = new StringBuffer(1000); cronjobbuffer.append(//from w w w.ja v a 2 s. co m "insert_update " + cronjobtype + ";code[unique=true];job(code);status(code)[forceWrite=true];"); cronjobbuffer.append("result(code)[forceWrite=true];startTime[forceWrite=true,dateformat=dd-MM-yyyy];"); cronjobbuffer.append("endTime[forceWrite=true,dateformat=dd-MM-yyyy] ").append(CharUtils.LF); for (int index = 0; index < count; index++) { final DateTime start = new DateTime().minusDays(daysold).minusHours(1); final DateTime end = new DateTime().minusDays(daysold); cronjobbuffer .append(";" + codeprefix + "_" + index + ";cleanupCronJobsPerformable;" + cjs.getCode() + ";"); cronjobbuffer.append(cjr.getCode() + ";" + start.getDayOfMonth() + "-" + start.getMonthOfYear() + "-" + start.getYear()); cronjobbuffer.append(";" + end.getDayOfMonth() + "-" + end.getMonthOfYear() + "-" + end.getYear()) .append(CharUtils.LF); } ImpExManager.getInstance().importDataLight(new CSVReader(cronjobbuffer.toString()), true); }
From source file:com.test.stringtest.StringUtils.java
/** * <p>Removes one newline from end of a String if it's there, * otherwise leave it alone. A newline is "<code>\n</code>", * "<code>\r</code>", or "<code>\r\n</code>".</p> * * <p>NOTE: This method changed in 2.0. * It now more closely matches Perl chomp.</p> * * <pre>// w w w. ja va 2 s.c o m * StringUtils.chomp(null) = null * StringUtils.chomp("") = "" * StringUtils.chomp("abc \r") = "abc " * StringUtils.chomp("abc\n") = "abc" * StringUtils.chomp("abc\r\n") = "abc" * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n" * StringUtils.chomp("abc\n\r") = "abc\n" * StringUtils.chomp("abc\n\rabc") = "abc\n\rabc" * StringUtils.chomp("\r") = "" * StringUtils.chomp("\n") = "" * StringUtils.chomp("\r\n") = "" * </pre> * * @param str the String to chomp a newline from, may be null * @return String without newline, <code>null</code> if null String input */ public static String chomp(String str) { if (isEmpty(str)) { return str; } if (str.length() == 1) { char ch = str.charAt(0); if (ch == CharUtils.CR || ch == CharUtils.LF) { return EMPTY; } return str; } int lastIdx = str.length() - 1; char last = str.charAt(lastIdx); if (last == CharUtils.LF) { if (str.charAt(lastIdx - 1) == CharUtils.CR) { lastIdx--; } } else if (last != CharUtils.CR) { lastIdx++; } return str.substring(0, lastIdx); }