List of usage examples for org.apache.commons.lang StringUtils trimToEmpty
public static String trimToEmpty(String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null
.
From source file:com.haulmont.cuba.web.toolkit.ui.converters.StringToEnumConverter.java
@Override public Enum convertToModel(String value, Class<? extends Enum> targetType, Locale locale) throws ConversionException { if (value == null) { return null; }// ww w. j a va 2 s .co m if (locale == null) { locale = VaadinSession.getCurrent().getLocale(); } if (isTrimming()) { value = StringUtils.trimToEmpty(value); } Object[] enumConstants = enumClass.getEnumConstants(); if (enumConstants != null) { for (Object enumValue : enumConstants) { if (Objects.equals(value, messages.getMessage((Enum) enumValue, locale))) { return (Enum) enumValue; } } } return null; }
From source file:com.qualogy.qafe.bind.orm.jibx.JIBXExceptionTranslator.java
/** * Method to get the line JIBX complains about in its error message * Method resets the given inputstream to get a clear vision * @param e/*from w w w. ja va 2s .c om*/ * @param in * @return * @throws BindException - when IOException occurs reading inputstream */ public static String getLine(JiBXException exception, InputStream in) throws BindException { String line = null; try { in.reset(); } catch (IOException e) { throw new BindException("Getting the original line failed", e); } if (exception.getMessage() != null) { String message = exception.getMessage(); int start = message.indexOf(JIBX_LINE_INDICATION_START_MARK) + JIBX_LINE_INDICATION_START_MARK.length(); if (start > -1) { int end = message.indexOf(JIBX_LINE_INDICATION_END_MARK, start); if (end > -1) { String lineNrStr = message.substring(start, end); if (NumberUtils.isNumber(lineNrStr)) { int lineNr = Integer.parseInt(lineNrStr); List lines = null; try { lines = IOUtils.readLines(in); } catch (IOException e) { throw new BindException("Getting the original line failed", e); } if (lines != null) { line = (String) (lines.get(lineNr - 1)); } } } } } if (line != null) line = StringUtils.trimToEmpty(line); return line; }
From source file:com.edgenius.wiki.ext.calendar.CalendarJson.java
public static CalendarJson toJson(List<CalendarEvent> calEvents, Date start, Date end) { CalendarJson json = new CalendarJson(); json.events = new ArrayList<List<Object>>(); for (CalendarEvent evt : calEvents) { List<Object> eventList = new ArrayList<Object>(); eventList.add(String.valueOf(evt.getUid())); eventList.add(evt.getSubject()); // eventList.add("\\/Date("+evt.getStart().getTime()+"\\/"); // eventList.add("\\/Date("+evt.getEnd().getTime()+"\\/"); eventList.add("@" + evt.getStart().getTime() + "@"); eventList.add("@" + evt.getEnd().getTime() + "@"); eventList.add(evt.isAllDayEvent() ? 1 : 0); eventList.add(!DateUtils.isSameDay(evt.getStart(), evt.getEnd()) ? 1 : 0); eventList.add(!StringUtils.isBlank(evt.getRepeatRule()) ? 1 : 0); eventList.add(evt.getCategory()); eventList.add(1);/*w w w . j a v a2 s . com*/ eventList.add(StringUtils.trimToEmpty(evt.getLocation())); eventList.add(StringUtils.trimToEmpty(evt.getInvitees())); json.events.add(eventList); } json.start = start; json.end = end; //error return json; }
From source file:com.haulmont.timesheets.entity.ExtUser.java
@Override public String getCaption() { if (StringUtils.isNotEmpty(firstName) || StringUtils.isNotEmpty(lastName)) { String pattern = "{0} {1}"; MessageFormat fmt = new MessageFormat(pattern); return StringUtils.trimToEmpty(fmt.format( new Object[] { StringUtils.trimToEmpty(firstName), StringUtils.trimToEmpty(lastName) })); }/*from ww w . j a v a2 s .co m*/ return super.getCaption(); }
From source file:com.edgenius.wiki.render.macro.HTMLMacro.java
public void execute(StringBuffer buffer, MacroParameter params) throws MalformedMacroException { String content = StringUtils.trimToEmpty(params.getContent()); //skip these dangerous tag? HtmlParser parser = new HtmlParser(); final StringBuilder buf = new StringBuilder(); parser.scan(content, new HtmlListener() { public void content(String content) { buf.append(content);//from ww w . j ava 2 s . c om } public void endDocument() { } public void startDocument() { } public void tag(String tagStr) { String tagname = HTMLUtil.getTagName(tagStr); if ("script".equals(tagname)) { return; } buf.append(tagStr); } }); buffer.append(buf); }
From source file:com.mmounirou.spotirss.provider.Apple.java
@Override @Nullable//from w ww. ja va 2 s.c o m public Track apply(@Nullable String strTitle) { int rankPos = strTitle.indexOf("."); String strRank = strTitle.substring(0, rankPos); String strArtistAndSong = strTitle.substring(rankPos + 1); String strTempSong = strArtistAndSong.substring(0, strArtistAndSong.lastIndexOf(" - ")); String strTempArtist = strArtistAndSong.substring(strArtistAndSong.lastIndexOf(" - ") + 2); String strSong = strTempSong; strSong = StringUtils.remove(strSong, String.format("(%s)", StringUtils.substringBetween(strSong, "(", ")"))); strSong = StringUtils.remove(strSong, String.format("[%s]", StringUtils.substringBetween(strSong, "[", "]"))); String strArtist = strTempArtist; String strfeaturing = StringUtils.trimToEmpty(StringUtils.substringBetween(strTempSong, "(", ")")); if (strfeaturing.contains("feat.")) { strArtist = strArtist + " " + strfeaturing; } strfeaturing = StringUtils.trimToEmpty(StringUtils.substringBetween(strTempSong, "[", "]")); if (strfeaturing.contains("feat.")) { strArtist = strArtist + " " + strfeaturing; } final Set<String> artistNames = StringTools.split(strArtist, new String[] { "Featuring", "Feat\\.", "feat\\.", "&", "," }); return new Track(Integer.parseInt(strRank), artistNames, strSong); }
From source file:com.dattack.dbtools.drules.beans.ForEachBean.java
public List<String> getValuesList() { return Arrays.asList(StringUtils.trimToEmpty(values).split(",")); }
From source file:ips1ap101.lib.core.db.util.DBUtils.java
public static String getProperErrorMessage(String message) { String join = getConstraintMessageJoin(message, ""); String trim = StringUtils.trimToEmpty(StringUtils.substringBefore(message, WHERE)); return StringUtils.defaultIfBlank(join, trim); }
From source file:com.iyonger.apm.web.util.HttpContainerContext.java
/** * Get current container nGrinder context base path. * <p/>/*from ww w . j av a2 s .c o m*/ * E.g) if user requests http://hostname:port/context_path/realurl, This * will return http://hostname:port/context_path * <p/> * In case of providing "http.url" property in system.properties file, this * method will return pre-set value. * * @return ngrinder context base path on http request. */ public String getCurrentContextUrlFromUserRequest() { String httpUrl = StringUtils.trimToEmpty(config.getControllerProperties().getProperty(PROP_CONTROLLER_URL)); // if provided if (StringUtils.isNotBlank(httpUrl)) { return httpUrl; } // if empty SecurityContextHolderAwareRequestWrapper request = cast( RequestContextHolder.currentRequestAttributes().resolveReference("request")); int serverPort = request.getServerPort(); // If it's http default port it will ignore the port part. // However, if ngrinder is provided in HTTPS.. it can be a problem. // FIXME : Later fix above. String portString = (serverPort == DEFAULT_WEB_PORT) ? StringUtils.EMPTY : ":" + serverPort; return httpUrl + request.getScheme() + "://" + request.getServerName() + portString + request.getContextPath(); }
From source file:jenkins.plugins.livingdoc.mapping.LivingDocProjectConfigPage.java
public void setTestResultsPattern(String pattern) { testResultsPattern().sendKeys(StringUtils.trimToEmpty(pattern)); }