List of usage examples for org.apache.commons.lang3 StringUtils stripEnd
public static String stripEnd(final String str, final String stripChars)
Strips any of a set of characters from the end of a String.
A null input String returns null .
From source file:org.cleansvg.Formatter.java
String formatFloat(final float number, final boolean space, final int precision) { final long longNumber = (long) number; final String prefix = (space && number >= 0f) ? " " : ""; if (longNumber == number) { return formatLong(longNumber, prefix); }/*from www. jav a2s. c om*/ if (Math.abs(number) < Math.pow(10.0, -precision)) { return space ? " 0" : "0"; } final String formatString = (Math.abs(number) > 0.001f) ? "." : "#.#E0"; final DecimalFormat format = new DecimalFormat(formatString); format.setMaximumFractionDigits(precision); return prefix + StringUtils.stripEnd(format.format(number), "."); }
From source file:org.craftercms.core.store.impl.AbstractFileBasedContentStoreAdapter.java
/** * Normalize the path: this means, append a leading '/' at the beginning and remove any trailing '/' (unless * the path is root). This is done for consistency in handling paths. * * @param path//from w w w .j a v a 2 s .c om * @return the normalized path (with a leading '/' and without a trailing '/') */ protected String normalizePath(String path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.equals("/")) { path = StringUtils.stripEnd(path, "/"); } return path; }
From source file:org.craftercms.engine.http.impl.HttpProxyImpl.java
@Required public void setBaseServiceUrl(String baseServiceUrl) { this.baseServiceUrl = StringUtils.stripEnd(baseServiceUrl, "/"); }
From source file:org.craftercms.engine.macro.impl.RequestUriMacro.java
@Override protected String getMacroValue(String str) { RequestContext requestContext = RequestContext.getCurrent(); if (requestContext != null) { String requestUri = requestContext.getRequest().getRequestURI(); if (!requestUri.startsWith("/")) { requestUri = "/" + requestUri; }//from w ww. j a v a2 s .co m if (!requestUri.equals("/")) { requestUri = StringUtils.stripEnd(requestUri, "/"); } return requestUri; } else { return null; } }
From source file:org.craftercms.engine.macro.impl.WebAppContextPathMacro.java
@Override protected String getMacroValue(String str) { if (servletContext != null) { return StringUtils.stripEnd(servletContext.getContextPath(), "/"); } else {/*from w w w .j a v a 2s. c o m*/ return null; } }
From source file:org.craftercms.engine.macro.impl.WebAppPathMacro.java
@Override protected String getMacroValue(String str) { if (servletContext != null) { String webAppPath = servletContext.getRealPath("/"); webAppPath = StringUtils.stripEnd(webAppPath, "/"); return webAppPath; } else {/* ww w.ja v a 2s .c o m*/ return null; } }
From source file:org.docx4j.toc.TocEntry.java
public void setEntryValue(P sourceP) { /*//from www . j a v a2 s . c om Certain Run formatting on entries is re-used, including: font face italic text highlight hidden (honoured) small caps but not font size font color underline */ // Step 1: create a clone of the P P clonedP = (P) XmlUtils.deepCopy(sourceP); // Step 2: make a List<R>, comprising the w:r/w:t contents, // with styles resolved List<Object> runsFound = TocHelper.getAllElementsFromObject(clonedP, R.class); R lastRun = null; for (Object o : runsFound) { R r = (R) o; List<Object> textsFound = TocHelper.getAllElementsFromObject(r, Text.class); if (textsFound.size() > 0) { R newR = new R(); if (r.getRPr() == null) { newR.setRPr(wmlObjectFactory.createRPr()); } else { // Resolve the formatting newR.setRPr(getEffectiveRPr(r.getRPr())); // newR.setRPr( // r.getRPr()); // Step 3: strip/filter unwanted run formatting nullify(newR.getRPr()); if (newR.getRPr() == null) { newR.setRPr(wmlObjectFactory.createRPr()); } } // apply hyperlink if appropriate if (hyperlink) { RStyle rstyle = wmlObjectFactory.createRStyle(); newR.getRPr().setRStyle(rstyle); rstyle.setVal(HYPERLINK); } newR.getContent().addAll(textsFound); entryValues.add(newR); lastRun = newR; } } // drop any trailing space off last run (Word does this) if (lastRun != null) { int size = lastRun.getContent().size(); if (size > 0) { Text lastText = (Text) lastRun.getContent().get(size - 1); String val = lastText.getValue(); if (val != null) { lastText.setValue(StringUtils.stripEnd(val, null)); } } } // drop leading space off the first run R firstRun = null; if (runsFound.size() > 0) { firstRun = (R) runsFound.get(0); List<Object> textsFound = TocHelper.getAllElementsFromObject(firstRun, Text.class); int size = textsFound.size(); if (size > 0) { Text firstText = (Text) textsFound.get(0); String val = firstText.getValue(); if (val != null) { firstText.setValue(StringUtils.stripStart(val, null)); } } } }
From source file:org.eclipse.jdt.ls.core.internal.contentassist.JavadocCompletionProposal.java
private String prepareTemplate(String text, String lineDelimiter, boolean addGap) { boolean endWithLineDelimiter = text.endsWith(lineDelimiter); String[] lines = text.split(lineDelimiter); StringBuilder buf = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i];// www .j a va 2 s .c om if (addGap) { String stripped = StringUtils.stripStart(line, WHITESPACES); if (stripped.startsWith(ASTERISK)) { if (!stripped.equals(ASTERISK)) { int index = line.indexOf(ASTERISK); buf.append(line.substring(0, index + 1)); buf.append(" ${0}"); buf.append(lineDelimiter); } addGap = false; } } buf.append(StringUtils.stripEnd(line, WHITESPACES)); if (i < lines.length - 1 || endWithLineDelimiter) { buf.append(lineDelimiter); } } return buf.toString(); }
From source file:org.efaps.wikiutil.parser.gwiki.GWikiVisitor.java
/** * * @param _listEntryType parsed text string defining the list entry (to * calculate the indent of the entry) * @param _isNumbered is numbered list entry * @see #listIndent/*w w w.j a v a 2s . c om*/ * @see #listNumber */ public void listEntryStart(final String _listEntryType, final boolean _isNumbered) { final int indt = StringUtils.stripEnd(_listEntryType, " \t").length(); if (this.listIndent.isEmpty()) { makeEndText(true); this.listIndent.add(indt); this.listIsNumb.add(_isNumbered); if (_isNumbered) { this.wem.listNumberedStart(); } else { this.wem.listBulletedStart(); } this.wem.listEntryStart(); this.wem.paragraphStart(); } else { makeEndText(false); final int curSize = this.listIndent.size(); int parIndt = this.listIndent.peek(); boolean prevIsNumb = false; while (parIndt >= indt) { this.listIndent.pop(); prevIsNumb = this.listIsNumb.pop(); parIndt = this.listIndent.isEmpty() ? 0 : this.listIndent.peek(); } this.listIndent.add(indt); this.listIsNumb.add(_isNumbered); int newSize = this.listIndent.size(); if (newSize == curSize) { this.wem.paragraphEnd(); this.wem.listEntryEnd(); if (prevIsNumb != _isNumbered) { if (_isNumbered) { this.wem.listBulletedEnd(); this.wem.listNumberedStart(); } else { this.wem.listNumberedEnd(); this.wem.listBulletedStart(); } } this.wem.listEntryStart(); this.wem.paragraphStart(); } else if (newSize > curSize) { if (_isNumbered) { this.wem.listNumberedStart(); } else { this.wem.listBulletedStart(); } this.wem.listEntryStart(); this.wem.paragraphStart(); } else if (newSize < curSize) { this.wem.paragraphEnd(); this.wem.listEntryEnd(); while (newSize < curSize) { this.wem.listBulletedEnd(); this.wem.paragraphEnd(); this.wem.listEntryEnd(); newSize++; } this.wem.listEntryStart(); this.wem.paragraphStart(); } } }
From source file:org.gvnix.web.datatables.util.QuerydslUtils.java
/** * Return where clause expression for number properties by casting it to * string before check its value.//from w w w . j a va 2s.c om * <p/> * Querydsl Expr: * {@code entityPath.fieldName.stringValue() like ('%' + searchStr + '%')} * Database operation: * {@code str(entity.fieldName) like ('%' + searchStr + '%')} * <p/> * Like operation is case sensitive. * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code weight} in {@code Pet} entity, {@code age} in * {@code Pet.owner} entity. * @param searchStr the value to find, may be null * @return PredicateOperation */ public static <T, N extends java.lang.Number & java.lang.Comparable<?>> BooleanExpression createNumberExpression( PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor, String searchStr, ConversionService conversionService) { if (StringUtils.isBlank(searchStr)) { return null; } NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType); BooleanExpression expression = null; if (conversionService != null) { try { Object number = conversionService.convert(searchStr, STRING_TYPE_DESCRIPTOR, descriptor); if (number == null) { expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%")); } else { String toSearch = number.toString(); if (number instanceof BigDecimal && ((BigDecimal) number).scale() > 1) { // For bigDecimal trim 0 in decimal part toSearch = StringUtils.stripEnd(toSearch, "0"); if (StringUtils.endsWith(toSearch, ".")) { // prevent "#." strings toSearch = toSearch.concat("0"); } } expression = numberExpression.stringValue().like("%".concat(toSearch).concat("%")); } } catch (ConversionException e) { expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%")); } } else { expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%")); } return expression; }