List of usage examples for org.apache.commons.lang3 StringUtils split
public static String[] split(final String str)
Splits the provided text into an array, using whitespace as the separator.
From source file:name.martingeisse.stackd.client.console.Console.java
/** * Causes the console to execute a command line programmatically. * @param commandLine the command line to execute *///from w w w .ja v a2s . c o m public final void executeCommandLine(String commandLine) { // remove special characters { StringBuilder builder = new StringBuilder(); for (int i = 0; i < commandLine.length(); i++) { char c = commandLine.charAt(i); if (c >= 32) { builder.append(c); } } commandLine = builder.toString(); } // split into segments String[] segments = StringUtils.split(commandLine); if (segments.length == 0) { return; } // invoke the command handler String command = segments[0]; String[] args = ArrayUtils.subarray(segments, 1, segments.length); commandHandler.handleCommand(this, command, args); }
From source file:de.vandermeer.skb.interfaces.transformers.textformat.String_To_Justified.java
@Override default StrBuilder transform(String s) { IsTransformer.super.transform(s); StrBuilder ret = (this.getBuilderForAppend() == null) ? new StrBuilder(this.getLength()) : this.getBuilderForAppend(); // set string and replace all inner ws with required character String[] ar = StringUtils.split((s == null) ? "" : s); int length = 0; for (String str : ar) { length += str.length();/*from ww w. j a va 2s. c om*/ } //first spaces to distributed (even) //do that until all firsts have been consumed int l = ((ar.length - 1) == 0) ? 1 : (ar.length - 1); // null safe dividend int first = ((this.getLength() - length) / l) * (ar.length - 1); while (first > 0) { for (int i = 0; i < ar.length - 1; i++) { if (first != 0) { ar[i] += this.getInnerWsChar(); first--; } } } //second space to distributed (leftovers, as many as there are) //do seconds from the back to front, until all seconds have been consumed //reverse means do not append to the last array element! int second = (this.getLength() - length) % l; while (second > 0) { for (int i = ar.length - 2; i > 0; i--) { if (second != 0) { ar[i] += this.getInnerWsChar(); second--; } } } ret.append(StringUtils.join(ar)); while (ret.length() < this.getLength()) { ret.append(' '); } return ret; }
From source file:com.nesscomputing.migratory.loader.HttpLoader.java
@Override public Collection<URI> loadFolder(final URI folderUri, final String searchPattern) throws IOException { final List<URI> results = Lists.newArrayList(); final Pattern pattern = (searchPattern == null) ? null : Pattern.compile(searchPattern); final String path = folderUri.getPath(); final URI baseUri = (path.endsWith("/") ? folderUri : folderUri.resolve(path + "/")); final String content = loadFile(baseUri); if (content == null) { // File not found return results; }// www .j ava 2 s . co m // The folders are a list of file names in plain text. Split it up. final String[] filenames = StringUtils.split(content); for (String filename : filenames) { if (pattern.matcher(filename).matches()) { results.add(URI.create(baseUri + filename)); } } return results; }
From source file:gov.nih.nci.caintegrator.web.ajax.DataElementSearchAjaxUpdater.java
/** * {@inheritDoc}/*ww w.j a va 2s .co m*/ * @throws IOException * @throws ServletException */ @Override public void runSearch(String returnType, String studyConfId, String fieldDescId, String keywords, String searchResultJsp) throws ServletException, IOException { inititalizeAndCheckTimeout(); if (!searchResultJsp.equalsIgnoreCase("")) { WebContext wctx = WebContextFactory.get(); utilThis.setValue("searchResult", wctx.forwardToString(searchResultJsp), false); } if (!isCurrentlyRunning()) { this.studyConfigurationId = studyConfId; this.fieldDescriptorId = fieldDescId; this.type = ReturnTypeEnum.getByValue(returnType); if (StringUtils.isNotBlank(keywords)) { lastRunSearch = System.currentTimeMillis(); workspace.getDataElementSearchObject().clear(); workspace.getDataElementSearchObject().setKeywordsForSearch(keywords); keywordsList = Arrays.asList(StringUtils.split(keywords)); annotationDefinitionSearchThread = new Thread(new AnnotationDefinitionSearchAjaxRunner(this)); annotationDefinitionSearchThread.start(); caDsrSearchThread = new Thread(new CaDsrSearchAjaxRunner(this)); caDsrSearchThread.start(); } } else { setErrorMessage("There is currently a search in progress, please wait for that to finish."); } }
From source file:bogdan.rechi.swt.commons.controls.TimeCombo.java
/** * Initialize combo values./*from w w w. ja va2s .com*/ */ private void initialize() { _combo.addVerifyListener(new VerifyListener() { @Override public void verifyText(VerifyEvent e) { String text = _combo.getText(); text = String.format("%s%s%s", text.substring(0, e.start), e.text, text.substring(e.end)); _combo.setBackground(_pattern.matcher(text).find() ? _initialBackground : _invalidTimeBackground); e.doit = true; } }); _combo.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { if (!isValid()) _combo.select(0); else { String[] items = _combo.getText().split(":"); if (items.length == 1) items = StringUtils.split(_combo.getText()); items[0] = items[0].trim(); items[1] = items[1].trim(); Calendar moment = Calendar.getInstance(); moment.set(Calendar.HOUR_OF_DAY, Integer.parseInt(items[0])); moment.set(Calendar.MINUTE, Integer.parseInt(items[1])); moment.add(Calendar.MINUTE, e.keyCode == SWT.ARROW_UP ? 1 : -1); String newTime = String.format("%02d:%02d", moment.get(Calendar.HOUR_OF_DAY), moment.get(Calendar.MINUTE)); _combo.setText(newTime); _combo.setSelection(new Point(0, newTime.length())); } e.doit = false; } } }); _combo.addMenuDetectListener(new MenuDetectListener() { @Override public void menuDetected(MenuDetectEvent arg0) { arg0.doit = false; } }); for (int i = 0; i < 24; i++) { _combo.add(String.format("%02d:00", i)); _combo.add(String.format("%02d:30", i)); } _combo.setBackground( _pattern.matcher(_combo.getText()).find() ? _initialBackground : _invalidTimeBackground); }
From source file:name.martingeisse.stackd.client.gui.element.TextParagraph.java
@Override public void requestSize(final int width, final int height) { // obtain the font final Font effectiveFont = getEffectiveFont(); if (effectiveFont == null || text == null) { setSize(0, 0);/*from www . ja v a2 s . c o m*/ return; } // break the text into lines final Gui gui = getGui(); ArrayList<String> lines = new ArrayList<>(); StringBuilder lineBuilder = new StringBuilder(); for (String word : StringUtils.split(text.trim())) { if (lineBuilder.length() != 0) { lineBuilder.append(' '); } int previousCharacterCount = lineBuilder.length(); lineBuilder.append(word); int newSize = gui.pixelsToUnitsInt(effectiveFont.getStringWidth(lineBuilder.toString())); if (newSize > width) { lineBuilder.setLength(previousCharacterCount); lines.add(lineBuilder.toString()); lineBuilder.setLength(0); lineBuilder.append(word); } } if (lineBuilder.length() > 0) { lines.add(lineBuilder.toString()); } this.lines = lines.toArray(new String[lines.size()]); // determine the size of the paragraph final int lineHeight = gui.pixelsToUnitsInt(effectiveFont.getCharacterHeight()); setSize(width, lineHeight * this.lines.length); }
From source file:eionet.webq.converter.XmlSchemaExtractor.java
/** * Parse noNamespaceSchemaLocation attribute and extract space delimited schema URLs. * * @param noNamespaceSchemaLocation Schema location string * @return Space delimited schema URLs//www. j av a2 s. c o m */ private String parseNoNamespaceSchemaLocation(String noNamespaceSchemaLocation) { if (StringUtils.isBlank(noNamespaceSchemaLocation)) { return noNamespaceSchemaLocation; } String[] split = StringUtils.split(noNamespaceSchemaLocation); return StringUtils.join(split, ' '); }
From source file:com.neocotic.bloggaer.web.listener.EntityRegistrationListener.java
/** * Loads the consolidated {@code entities.properties} file and returns the all the lines that it contains. * // ww w.j a v a 2 s.c om * @return The lines within the properties file. */ private String[] readLines() throws Exception { logger.entering(); InputStream input = null; String[] lines = null; try { input = getClass().getClassLoader() .getResourceAsStream(StringUtils.trimToNull(System.getProperty(FILE_PATH_PROPERTY))); lines = StringUtils.split(new Scanner(input).useDelimiter("\\A").next()); } finally { try { input.close(); } catch (Exception e) { } } if (lines == null) lines = new String[0]; logger.exiting(lines); return lines; }
From source file:de.jcup.egradle.core.model.Item.java
/** * Set name and calculate identifier - if you want to explicit set identifer * you must it after calling this method via {@link #setIdentifier(String)} * //w w w. jav a 2 s . c o m * @param name */ public void setName(String name) { if (name == null) { name = ""; } this.name = name; String[] splitted = StringUtils.split(name.trim()); if (splitted == null || splitted.length == 0) { this.identifier = ""; } else { this.identifier = splitted[0]; } }
From source file:net.pms.encoders.FFmpegDVRMSRemux.java
@Override public ProcessWrapper launchTranscode(DLNAResource dlna, DLNAMediaInfo media, OutputParams params) throws IOException { String ffmpegAlternativePath = configuration.getFfmpegAlternativePath(); List<String> cmdList = new ArrayList<String>(); final String filename = dlna.getSystemName(); cmdList.addAll(getGlobalOptions(logger)); if (ffmpegAlternativePath != null && ffmpegAlternativePath.length() > 0) { cmdList.add(ffmpegAlternativePath); } else {//from w w w .j a va 2 s . c om cmdList.add(executable()); } if (params.timeseek > 0) { cmdList.add("-ss"); cmdList.add("" + params.timeseek); } cmdList.add("-i"); cmdList.add(filename); for (String arg : args()) { cmdList.add(arg); } String customSettingsString = configuration.getMPEG2MainSettingsFFmpeg(); if (StringUtils.isNotBlank(customSettingsString)) { String[] customSettingsArray = StringUtils.split(customSettingsString); if (customSettingsArray != null) { for (String option : customSettingsArray) { cmdList.add(option); } } } cmdList.add("pipe:"); String[] cmdArray = new String[cmdList.size()]; cmdList.toArray(cmdArray); cmdArray = finalizeTranscoderArgs(filename, dlna, media, params, cmdArray); ProcessWrapperImpl pw = new ProcessWrapperImpl(cmdArray, params); pw.runInNewThread(); return pw; }