List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:de.micromata.genome.gwiki.controls.GWikiLoginActionBean.java
public Object onLogin() { checkPublicRegister();/*from www.ja v a 2 s. c o m*/ if (StringUtils.isBlank(user) == true || StringUtils.isBlank(password) == true) { wikiContext.addValidationError("gwiki.page.admin.Login.message.userandpasswordneeded"); password = ""; return null; } GWikiAuthorization auth = wikiContext.getWikiWeb().getAuthorization(); boolean success = auth.login(wikiContext, StringUtils.trim(user), StringUtils.trim(password)); if (success == false) { wikiContext.addValidationError("gwiki.page.admin.Login.message.unknownuserpassword"); GLog.note(GWikiLogCategory.Wiki, "Invalid login: user: " + user + "; "); password = ""; return null; } if (keepLoginInSession == true) { auth.createAuthenticationCookie(wikiContext, user, password); } else { auth.clearAuthenticationCookie(wikiContext, user); } password = ""; if (StringUtils.isBlank(pageId) == false) { GWikiElementInfo ei = wikiContext.getWikiWeb().findElementInfo(pageId); if (ei != null) { return ei; } } return wikiContext.getWikiWeb().getHomeElement(wikiContext); }
From source file:com.neophob.sematrix.listener.TcpServer.java
/** * tcp server thread.// ww w .jav a 2 s .c om */ public void run() { LOG.log(Level.INFO, "Ready receiving messages..."); while (Thread.currentThread() == runner) { if (tcpServer != null) { try { //check if client is available if (client != null && client.active()) { //do not send sound status to gui - very cpu intensive! //sendSoundStatus(); if ((count % 20) == 2 && Collector.getInstance().isRandomMode()) { sendStatusToGui(); } } Client c = tcpServer.available(); if (c != null && c.available() > 0) { //clean message String msg = lastMsg + StringUtils.replace(c.readString(), "\n", ""); //add replacement end string msg = StringUtils.replace(msg, FUDI_ALTERNATIVE_END_MARKER, FUDI_MSG_END_MARKER); msg = StringUtils.trim(msg); int msgCount = StringUtils.countMatches(msg, FUDI_MSG_END_MARKER); LOG.log(Level.INFO, "Got Message: {0} cnt: {1}", new Object[] { msg, msgCount }); //work around bug - the puredata gui sends back a message as soon we send one long delta = System.currentTimeMillis() - lastMessageSentTimestamp; if (delta < FLOODING_TIME) { LOG.log(Level.INFO, "Ignore message, flooding protection ({0}<{1})", new String[] { "" + delta, "" + FLOODING_TIME }); //delete message msgCount = 0; msg = ""; } //ideal, one message receieved if (msgCount == 1) { msg = StringUtils.removeEnd(msg, FUDI_MSG_END_MARKER); lastMsg = ""; processMessage(StringUtils.split(msg, ' ')); } else if (msgCount == 0) { //missing end of message... save it lastMsg = msg; } else { //more than one message receieved, split it //TODO: reuse partial messages lastMsg = ""; String[] msgs = msg.split(FUDI_MSG_END_MARKER); for (String s : msgs) { s = StringUtils.trim(s); s = StringUtils.removeEnd(s, FUDI_MSG_END_MARKER); processMessage(StringUtils.split(s, ' ')); } } } } catch (Exception e) { } } count++; try { Thread.sleep(50); } catch (InterruptedException e) { //Ignored } } }
From source file:com.ottogroup.bi.asap.component.source.executor.SourceExecutor.java
/** * Adds the provided {@link Mailbox} as receiver of all {@link StreamingDataMessage} items received by the * underlying {@link Source}. The given identifier references the linked mailbox. * @param adaptorId/* w w w . ja v a2s. c o m*/ * @param messageSubscriber */ public void subscribe(final String subscriberId, final Mailbox subscriberMailbox) throws RequiredInputMissingException { /////////////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(subscriberId)) throw new RequiredInputMissingException("Missing required subscriber identifier"); if (subscriberMailbox == null) throw new RequiredInputMissingException("Missing required subscriber mailbox"); // /////////////////////////////////////////////////////////////////////////// this.subscriberMailboxes.put(StringUtils.trim(StringUtils.lowerCase(subscriberId)), subscriberMailbox); if (logger.isDebugEnabled()) logger.debug("subscribe[publisher=" + source.getId() + ", subscriber=" + subscriberId + ", mailbox=" + subscriberMailbox + "]"); }
From source file:com.workday.autoparse.xml.demo.XmlParserTest.java
@Test public void testSetters() throws ParseException, UnexpectedChildException, UnknownElementException { XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser(); InputStream in = getInputStreamOf("setter-input.xml"); SetterModel setterModel = (SetterModel) parser.parseStream(in); assertEquals(5, setterModel.anInt);/* w w w . j a v a 2 s .c o m*/ assertNotNull(setterModel.child); assertEquals(2, setterModel.repeatedChildren.size()); // Pull autoparse includes newlines and whitespace, so get rid of it here. assertEquals("Hello", StringUtils.trim(StringUtils.replace(setterModel.textContent, "\n", " "))); }
From source file:com.thinkbiganalytics.metadata.sla.DefaultServiceLevelAgreementScheduler.java
private String getUniqueName(String name) { String uniqueName = name;//w ww . j ava 2 s . co m final String checkName = name; String matchingName = Iterables.tryFind(scheduledJobNames.values(), new Predicate<String>() { @Override public boolean apply(String s) { return s.equalsIgnoreCase(checkName); } }).orNull(); if (matchingName != null) { //get numeric string after '-'; if (StringUtils.contains(matchingName, "-")) { String number = StringUtils.substringAfterLast(matchingName, "-"); if (StringUtils.isNotBlank(number)) { number = StringUtils.trim(number); if (StringUtils.isNumeric(number)) { Integer num = Integer.parseInt(number); num++; uniqueName += "-" + num; } else { uniqueName += "-1"; } } } else { uniqueName += "-1"; } } return uniqueName; }
From source file:com.erudika.scoold.controllers.TranslateController.java
@PostMapping("/{locale}/{index}") public String post(@PathVariable String locale, @PathVariable String index, @RequestParam String value, HttpServletRequest req, Model model) { Locale showLocale = utils.getLangutils().getProperLocale(locale); if (utils.isAuthenticated(req) && showLocale != null && !"en".equals(showLocale.getLanguage())) { Set<String> approved = utils.getLangutils().getApprovedTransKeys(showLocale.getLanguage()); Profile authUser = utils.getAuthUser(req); String langkey = langkeys.get(getIndex(index, langkeys)); boolean isTranslated = approved.contains(langkey); if (!StringUtils.isBlank(value) && (!isTranslated || utils.isAdmin(authUser))) { Translation trans = new Translation(showLocale.getLanguage(), langkey, StringUtils.trim(value)); trans.setCreatorid(authUser.getId()); trans.setAuthorName(authUser.getName()); trans.setTimestamp(System.currentTimeMillis()); pc.create(trans);/*w w w.j a v a2 s .co m*/ model.addAttribute("newtranslation", trans); } if (!utils.isAjaxRequest(req)) { return "redirect:" + TRANSLATELINK + "/" + showLocale.getLanguage() + "/" + getNextIndex(getIndex(index, langkeys), approved, langkeys); } } return "base"; }
From source file:com.adobe.cq.wcm.core.components.internal.servlets.AdaptiveImageServletMappingConfigurationFactory.java
/** * Internal helper for filtering out null and empty values from the configuration options. * * @param config - Array of strings which might include null or empty values * * @return - {@link List} of strings with no empty values; might be empty. *//*from www . j a v a2s . co m*/ @Nonnull private List<String> getValues(@Nonnull String[] config) { List<String> values = new ArrayList<>(config.length); for (String conf : config) { if (StringUtils.isNotEmpty(conf)) { values.add(StringUtils.trim(conf)); } } return values; }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineManager.java
/** * Initializes the micro pipeline manager - <b>used for testing purpose only</b> * @param processingNodeId identifier of node this manager lives on * @param factory/*w w w .j av a 2s . c o m*/ * @param executorService * @throws RequiredInputMissingException */ protected MicroPipelineManager(final String processingNodeId, final MicroPipelineFactory factory, final ExecutorService executorService) throws RequiredInputMissingException { ////////////////////////////////////////////////////////////////////////////// // validate provided input if (factory == null) throw new RequiredInputMissingException("Missing required component repository"); if (executorService == null) throw new RequiredInputMissingException("Missing required executor service"); if (StringUtils.isBlank(processingNodeId)) throw new RequiredInputMissingException("Missing required processing node identifier"); // ////////////////////////////////////////////////////////////////////////////// this.processingNodeId = StringUtils.lowerCase(StringUtils.trim(processingNodeId)); this.microPipelineFactory = factory; this.executorService = executorService; }
From source file:io.wcm.devops.conga.plugins.aem.util.ContentPackageUtil.java
/** * Merges description and file header to a single string. * @param description Description from configuration - may be null * @param fileHeader File header from file - may be null * @return Merged description or null if all input is null *//*from w w w .j a va 2 s . c om*/ private static String mergeDescriptionFileHeader(String description, FileHeaderContext fileHeader) { boolean hasDescription = StringUtils.isNotBlank(description); boolean hasFileHeader = fileHeader != null && !fileHeader.getCommentLines().isEmpty(); if (!hasDescription && !hasFileHeader) { return null; } StringBuilder result = new StringBuilder(); if (hasDescription) { result.append(description); } if (hasDescription && hasFileHeader) { result.append("\n---\n"); } if (hasFileHeader) { @SuppressWarnings("null") String fileHeaderString = StringUtils .trim(fileHeader.getCommentLines().stream().filter(line -> !StringUtils.contains(line, "*****")) .map(line -> StringUtils.trim(line)).collect(Collectors.joining("\n"))); result.append(fileHeaderString); } return result.toString(); }
From source file:com.ottogroup.bi.asap.component.operator.executor.OperatorExecutor.java
/** * Subscribes the referenced component/*ww w.ja va2s .co m*/ * @param subscriberId * @param subscriberMailbox */ public void subscribe(final String subscriberId, final Mailbox subscriberMailbox) throws RequiredInputMissingException { /////////////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(subscriberId)) throw new RequiredInputMissingException("Missing required subscriber identifier"); if (subscriberMailbox == null) throw new RequiredInputMissingException("Missing required subscriber mailbox"); // /////////////////////////////////////////////////////////////////////////// this.subscriberMailboxes.put(StringUtils.trim(StringUtils.lowerCase(subscriberId)), subscriberMailbox); if (logger.isDebugEnabled()) logger.debug("subscribe[publisher=" + operator.getId() + ", subscriber=" + subscriberId + ", mailbox=" + subscriberMailbox + "]"); }