List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(final String str)
Strips whitespace from the start and end of a String.
This is similar to #trim(String) but removes whitespace.
From source file:com.qcadoo.mes.productionCounting.hooks.ProductionTrackingHooks.java
private String getProductionRecordNumber(final String[] orderNumberSplited) { StringBuffer number = new StringBuffer(); for (int i = 0; i < orderNumberSplited.length; i++) { if (i > 0) { number.append(orderNumberSplited[i]); if (i != orderNumberSplited.length - 1) { number.append("-"); }/* w ww .j a v a2s.c o m*/ } } return StringUtils.strip(number.toString()); }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
/** * copy participant info/*from ww w . jav a 2s. c o m*/ */ private ParticipantType copyParticipant(ObjectFactory factory, Participant part) { final ParticipantType retVal = factory.createParticipantType(); if (part.getId() != null) retVal.setId(part.getId()); retVal.setName(part.getName()); final LocalDate bday = part.getBirthDate(); if (bday != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final XMLGregorianCalendar cal = df .newXMLGregorianCalendar(GregorianCalendar.from(bday.atStartOfDay(ZoneId.systemDefault()))); cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED); retVal.setBirthday(cal); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } final Period age = part.getAge(null); if (age != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final Duration ageDuration = df.newDuration(true, age.getYears(), age.getMonths(), age.getDays(), 0, 0, 0); retVal.setAge(ageDuration); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } retVal.setEducation(part.getEducation()); retVal.setGroup(part.getGroup()); final String lang = part.getLanguage(); final String langs[] = (lang != null ? lang.split(",") : new String[0]); for (String l : langs) { retVal.getLanguage().add(StringUtils.strip(l)); } if (part.getSex() == Sex.MALE) retVal.setSex(SexType.MALE); else if (part.getSex() == Sex.FEMALE) retVal.setSex(SexType.FEMALE); ParticipantRole prole = part.getRole(); if (prole == null) prole = ParticipantRole.TARGET_CHILD; retVal.setRole(prole.toString()); // create ID based on role if possible if (retVal.getId() == null && prole != null) { if (prole == ParticipantRole.TARGET_CHILD) { retVal.setId("CHI"); } else if (prole == ParticipantRole.MOTHER) { retVal.setId("MOT"); } else if (prole == ParticipantRole.FATHER) { retVal.setId("FAT"); } else if (prole == ParticipantRole.INTERVIEWER) { retVal.setId("INT"); } else { retVal.setId("p" + (++pIdx)); } } retVal.setSES(part.getSES()); return retVal; }
From source file:ca.phon.ipadictionary.impl.ImmutablePlainTextDictionary.java
/** * Read dictionary entries from the given stream. * Stream contents should be UTF-8 and formatted as * indicated above./* w w w. ja v a 2 s . c o m*/ * * @param is * @returns a new radix tree acting as our database * @throws IOException if an error occurs while * attempting to read the stream contents */ private TernaryTree<List<String>> readEntriesFromStream(InputStream is) throws IOException { InputStreamReader in = new InputStreamReader(is, "UTF-8"); BufferedReader reader = new BufferedReader(in); Pattern dictPattern = getPattern(); TernaryTree<List<String>> retVal = new TernaryTree<List<String>>(); String line = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { // ignore as a comment continue; } Matcher m = dictPattern.matcher(line); if (m.matches()) { String orthography = StringUtils.strip(m.group(1)).toLowerCase(); String ipa = StringUtils.strip(m.group(3)).toLowerCase(); if (orthography.length() > 0 && ipa.length() > 0) { List<String> ipaEntries = retVal.get(orthography); if (ipaEntries == null) { ipaEntries = new ArrayList<String>(); retVal.put(orthography, ipaEntries); } if (!ipaEntries.contains(ipa)) { ipaEntries.add(ipa); } } } } reader.close(); return retVal; }
From source file:ca.phon.app.session.editor.TranscriberSelectionDialog.java
public String getRealName() { if (newTranscriptButton.isSelected()) { return realNameField.getText(); } else {/*w w w . j a va2s.c o m*/ String userListName = existingUserList.getSelectedValue().toString(); StringTokenizer st = new StringTokenizer(userListName, "-"); return StringUtils.strip(st.nextToken()); } }
From source file:com.mingo.parser.xml.dom.QuerySetParser.java
/** * Parse <case/> tag./*from www . j a v a 2 s. com*/ * * @param node node * @return {@link QueryCase} */ private void parseCaseTag(Node node, Query query, QuerySet querySet) throws ParserException { if (node == null || !CASE_TAG.equals(node.getNodeName())) { return; } QueryCase queryCase = new QueryCase(); queryCase.setId(getAttributeString(node, ID)); queryCase.setPriority(getAttributeInt(node, CASE_PRIORITY_ATTR)); queryCase.setCondition(getAttributeString(node, CONDITION)); QueryType type = QueryType.getByName(getAttributeString(node, TYPE_ATTR)); queryCase.setQueryType(type != null ? type : query.getQueryType()); boolean inheritConverter = getAttributeBoolean(node, CONVERTER_INHERIT_ATTR); if (!inheritConverter) { queryCase.setConverter(getAttributeString(node, CONVERTER_CLASS_ATTR)); queryCase.setConverterMethod(getAttributeString(node, CONVERTER_METHOD_ATTR)); } else { queryCase.setConverterMethod(query.getConverterMethod()); queryCase.setConverter(query.getConverter()); } // parse case body if (node.hasChildNodes()) { StringBuilder caseBodyBuilder = new StringBuilder(); NodeList childList = node.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { Node child = childList.item(i); parseBody(caseBodyBuilder, child, querySet); } queryCase.setBody(StringUtils.strip(caseBodyBuilder.toString())); if (!validate(wrap(queryCase.getBody()))) { throw new ParserException(MessageFormatter .format(INVALID_QUERY_ERROR_MSG, queryCase.getId(), queryCase).getMessage()); } } query.addQueryCase(queryCase); }
From source file:ca.phon.app.session.editor.TranscriberSelectionDialog.java
public String getUsername() { if (newTranscriptButton.isSelected()) { return usernameField.getText(); } else {/*from w w w.ja v a 2 s.c o m*/ String userListName = existingUserList.getSelectedValue().toString(); StringTokenizer st = new StringTokenizer(userListName, "-"); if (st.countTokens() == 2) { st.nextToken(); return StringUtils.strip(st.nextToken()); } else { return new String(); } } }
From source file:net.jimj.automaton.Bot.java
protected void processMessage(User user, String message) { //Ignore self for any processing. if (user.getNick().equals(config.getNick())) { return;/* w ww .j a va 2s. com*/ } statsCollector.incMessageCount(); if (message.startsWith(config.getCommandChar())) { statsCollector.incCommandCount(); String commandName = message; //Try to chop off the first word int commandNameEnd = message.indexOf(" "); String args = null; //Strip off the command character for looking up the command if (commandNameEnd != -1) { commandName = message.substring(config.getCommandChar().length(), commandNameEnd); args = StringUtils .strip(message.substring(config.getCommandChar().length() + commandName.length())); } else { commandName = commandName.substring(config.getCommandChar().length()); } try { fireCommand(user, commandName, args); } catch (Exception e) { eventBus.post(new BehaviorEvent(user, BehaviorEvent.Behavior.SASSY)); LOGGER.error("Caused by " + user.getNick() + " with message " + message, e); } } else { for (Processor processor : processors) { if (processor.shouldProcess(message)) { statsCollector.incProcessCount(); processor.process(user, message); } } } }
From source file:io.cloudslang.content.utils.NumberUtilities.java
/** * Given an double string, it checks if it's a valid double (based on apaches NumberUtils.createDouble) * * @param doubleStr the double string to check * @return true if it's valid, otherwise false *//*from w ww . ja v a 2s .c o m*/ public static boolean isValidDouble(@Nullable final String doubleStr) { if (StringUtils.isBlank(doubleStr)) { return false; } final String stripedDouble = StringUtils.strip(doubleStr); try { NumberUtils.createDouble(stripedDouble); return true; } catch (NumberFormatException e) { return false; } }
From source file:com.mingo.parser.xml.dom.QuerySetParser.java
private String processString(String source) { if (StringUtils.isNotBlank(source)) { source = StringUtils.strip(source); source = source.replace("(?m)^[ \t]*\r?\n", ""); }/*from w w w.ja v a 2s . c om*/ return source; }
From source file:ca.phon.app.session.editor.view.segmentation.SegmentationEditorView.java
private void updateSegmentWindow() { String txt = StringUtils.strip(segmentWindowField.getText()); if (txt.length() == 0) txt = "0"; Integer windowLen = Integer.parseInt(txt); synchronized (segmentLabel) { segmentLabel.setSegmentWindow(windowLen); }//from ww w . ja v a 2 s . c o m }