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:com.hubrick.vertx.s3.client.S3Client.java
private MultiMap populateHeadObjectHeaders(HeadObjectRequest headObjectRequest) { final MultiMap headers = MultiMap.caseInsensitiveMultiMap(); if (StringUtils.trimToNull(headObjectRequest.getRange()) != null) { headers.add(Headers.RANGE, StringUtils.trim(headObjectRequest.getRange())); }/*from w w w . ja v a 2 s.co m*/ if (StringUtils.trimToNull(headObjectRequest.getIfModifiedSince()) != null) { headers.add(Headers.IF_MODIFIED_SINCE, StringUtils.trim(headObjectRequest.getIfModifiedSince())); } if (StringUtils.trimToNull(headObjectRequest.getIfUnmodifiedSince()) != null) { headers.add(Headers.IF_UNMODIFIED_SINCE, StringUtils.trim(headObjectRequest.getIfUnmodifiedSince())); } if (StringUtils.trimToNull(headObjectRequest.getIfMatch()) != null) { headers.add(Headers.IF_MATCH, StringUtils.trim(headObjectRequest.getIfMatch())); } if (StringUtils.trimToNull(headObjectRequest.getIfNoneMatch()) != null) { headers.add(Headers.IF_NONE_MATCH, StringUtils.trim(headObjectRequest.getIfNoneMatch())); } return headers; }
From source file:com.hubrick.vertx.s3.client.S3Client.java
private Map<String, String> populateGetBucketQueryParams(GetBucketRequest listObjectsRequest) { final Map<String, String> queryParams = new HashMap<>(); queryParams.put("list-type", "2"); if (StringUtils.trimToNull(listObjectsRequest.getContinuationToken()) != null) { queryParams.put("continuation-token", StringUtils.trim(listObjectsRequest.getContinuationToken())); }//from w w w.j a va 2 s . co m if (StringUtils.trimToNull(listObjectsRequest.getDelimiter()) != null) { queryParams.put("delimiter", StringUtils.trim(listObjectsRequest.getDelimiter())); } if (StringUtils.trimToNull(listObjectsRequest.getEncodingType()) != null) { queryParams.put("encoding-type", StringUtils.trim(listObjectsRequest.getEncodingType())); } if (StringUtils.trimToNull(listObjectsRequest.getFetchOwner()) != null) { queryParams.put("fetch-owner", StringUtils.trim(listObjectsRequest.getFetchOwner())); } if (listObjectsRequest.getMaxKeys() != null) { queryParams.put("max-keys", StringUtils.trim(listObjectsRequest.getMaxKeys().toString())); } if (StringUtils.trimToNull(listObjectsRequest.getPrefix()) != null) { queryParams.put("prefix", StringUtils.trim(listObjectsRequest.getPrefix())); } if (StringUtils.trimToNull(listObjectsRequest.getStartAfter()) != null) { queryParams.put("start-after", StringUtils.trim(listObjectsRequest.getStartAfter())); } return queryParams; }
From source file:com.hubrick.vertx.s3.client.S3Client.java
private MultiMap populateDeleteObjectHeaders(DeleteObjectRequest deleteObjectRequest) { final MultiMap headers = MultiMap.caseInsensitiveMultiMap(); if (StringUtils.trimToNull(deleteObjectRequest.getAmzMfa()) != null) { headers.add(Headers.X_AMZ_MFA, StringUtils.trim(deleteObjectRequest.getAmzMfa())); }//from ww w . j av a 2s . c o m return headers; }
From source file:com.moviejukebox.plugin.ImdbPlugin.java
/** * Search for the IMDB Id in the NFO file * * @param nfo/*from w w w . j av a2 s .co m*/ * @param movie * @return */ private static String searchIMDB(String nfo, Movie movie) { final int flags = Pattern.CASE_INSENSITIVE | Pattern.DOTALL; String imdbPattern = ")[\\W].*?(tt\\d{7})"; // Issue 1912 escape special regex characters in title String title = Pattern.quote(movie.getTitle()); String id = UNKNOWN; Pattern patternTitle; Matcher matchTitle; try { patternTitle = Pattern.compile("(" + title + imdbPattern, flags); matchTitle = patternTitle.matcher(nfo); if (matchTitle.find()) { id = matchTitle.group(2); } else { String dir = FileTools.getParentFolderName(movie.getFile()); Pattern patternDir = Pattern.compile("(" + dir + imdbPattern, flags); Matcher matchDir = patternDir.matcher(nfo); if (matchDir.find()) { id = matchDir.group(2); } else { String strippedNfo = nfo.replaceAll("(?is)[^\\w\\r\\n]", ""); String strippedTitle = title.replaceAll("(?is)[^\\w\\r\\n]", ""); Pattern patternStrippedTitle = Pattern.compile("(" + strippedTitle + imdbPattern, flags); Matcher matchStrippedTitle = patternStrippedTitle.matcher(strippedNfo); if (matchStrippedTitle.find()) { id = matchTitle.group(2); } else { String strippedDir = dir.replaceAll("(?is)[^\\w\\r\\n]", ""); Pattern patternStrippedDir = Pattern.compile("(" + strippedDir + imdbPattern, flags); Matcher matchStrippedDir = patternStrippedDir.matcher(strippedNfo); if (matchStrippedDir.find()) { id = matchTitle.group(2); } } } } } catch (Exception error) { LOG.error("Error locating the IMDb ID in the nfo file for {}", movie.getBaseFilename()); LOG.error(error.getMessage()); } return StringUtils.trim(id); }
From source file:cgeo.geocaching.connector.gc.GCParser.java
/** * Parse a trackable HTML description into a Trackable object * * @param page// w ww .j av a 2 s .c o m * the HTML page to parse, already processed through {@link TextUtils#replaceWhitespace} * @return the parsed trackable, or null if none could be parsed */ static Trackable parseTrackable(final String page, final String possibleTrackingcode) { if (StringUtils.isBlank(page)) { Log.e("GCParser.parseTrackable: No page given"); return null; } if (page.contains(GCConstants.ERROR_TB_DOES_NOT_EXIST) || page.contains(GCConstants.ERROR_TB_ARITHMETIC_OVERFLOW) || page.contains(GCConstants.ERROR_TB_ELEMENT_EXCEPTION)) { return null; } final Trackable trackable = new Trackable(); // trackable geocode trackable.setGeocode(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GEOCODE, true, StringUtils.upperCase(possibleTrackingcode))); if (trackable.getGeocode() == null) { Log.e("GCParser.parseTrackable: could not figure out trackable geocode"); return null; } // trackable id trackable.setGuid(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GUID, true, trackable.getGuid())); // trackable icon trackable.setIconUrl( TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_ICON, true, trackable.getIconUrl())); // trackable name trackable.setName( Html.fromHtml(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_NAME, true, "")).toString()); // trackable type if (StringUtils.isNotBlank(trackable.getName())) { trackable.setType( TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_TYPE, true, trackable.getType())); } // trackable owner name try { final MatcherWrapper matcherOwner = new MatcherWrapper(GCConstants.PATTERN_TRACKABLE_OWNER, page); if (matcherOwner.find() && matcherOwner.groupCount() > 0) { trackable.setOwnerGuid(matcherOwner.group(1)); trackable.setOwner(matcherOwner.group(2).trim()); } } catch (final RuntimeException e) { // failed to parse trackable owner name Log.w("GCParser.parseTrackable: Failed to parse trackable owner name"); } // trackable origin trackable.setOrigin( TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_ORIGIN, true, trackable.getOrigin())); // trackable spotted try { final MatcherWrapper matcherSpottedCache = new MatcherWrapper( GCConstants.PATTERN_TRACKABLE_SPOTTEDCACHE, page); if (matcherSpottedCache.find() && matcherSpottedCache.groupCount() > 0) { trackable.setSpottedGuid(matcherSpottedCache.group(1)); trackable.setSpottedName(matcherSpottedCache.group(2).trim()); trackable.setSpottedType(Trackable.SPOTTED_CACHE); } final MatcherWrapper matcherSpottedUser = new MatcherWrapper(GCConstants.PATTERN_TRACKABLE_SPOTTEDUSER, page); if (matcherSpottedUser.find() && matcherSpottedUser.groupCount() > 0) { trackable.setSpottedGuid(matcherSpottedUser.group(1)); trackable.setSpottedName(matcherSpottedUser.group(2).trim()); trackable.setSpottedType(Trackable.SPOTTED_USER); } if (TextUtils.matches(page, GCConstants.PATTERN_TRACKABLE_SPOTTEDUNKNOWN)) { trackable.setSpottedType(Trackable.SPOTTED_UNKNOWN); } if (TextUtils.matches(page, GCConstants.PATTERN_TRACKABLE_SPOTTEDOWNER)) { trackable.setSpottedType(Trackable.SPOTTED_OWNER); } } catch (final RuntimeException e) { // failed to parse trackable last known place Log.w("GCParser.parseTrackable: Failed to parse trackable last known place"); } // released date - can be missing on the page final String releaseString = TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_RELEASES, false, null); if (releaseString != null) { try { trackable.setReleased(dateTbIn1.parse(releaseString)); } catch (ParseException e) { if (trackable.getReleased() == null) { try { trackable.setReleased(dateTbIn2.parse(releaseString)); } catch (ParseException e1) { Log.e("Could not parse trackable release " + releaseString); } } } } // trackable distance final String distance = TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_DISTANCE, false, null); if (null != distance) { try { trackable.setDistance(DistanceParser.parseDistance(distance, !Settings.isUseImperialUnits())); } catch (final NumberFormatException e) { Log.e("GCParser.parseTrackable: Failed to parse distance", e); } } // trackable goal trackable.setGoal(convertLinks( TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_GOAL, true, trackable.getGoal()))); // trackable details & image try { final MatcherWrapper matcherDetailsImage = new MatcherWrapper( GCConstants.PATTERN_TRACKABLE_DETAILSIMAGE, page); if (matcherDetailsImage.find() && matcherDetailsImage.groupCount() > 0) { final String image = StringUtils.trim(matcherDetailsImage.group(3)); final String details = StringUtils.trim(matcherDetailsImage.group(4)); if (StringUtils.isNotEmpty(image)) { trackable.setImage(image); } if (StringUtils.isNotEmpty(details) && !StringUtils.equals(details, "No additional details available.")) { trackable.setDetails(convertLinks(details)); } } } catch (final RuntimeException e) { // failed to parse trackable details & image Log.w("GCParser.parseTrackable: Failed to parse trackable details & image"); } if (StringUtils.isEmpty(trackable.getDetails()) && page.contains(GCConstants.ERROR_TB_NOT_ACTIVATED)) { trackable.setDetails(CgeoApplication.getInstance().getString(R.string.trackable_not_activated)); } // trackable logs try { final MatcherWrapper matcherLogs = new MatcherWrapper(GCConstants.PATTERN_TRACKABLE_LOG, page); /* * 1. Type (image) * 2. Date * 3. Author * 4. Cache-GUID * 5. <ignored> (strike-through property for ancient caches) * 6. Cache-name * 7. Log text */ while (matcherLogs.find()) { long date = 0; try { date = GCLogin.parseGcCustomDate(matcherLogs.group(2)).getTime(); } catch (final ParseException e) { } final LogEntry logDone = new LogEntry(Html.fromHtml(matcherLogs.group(3)).toString().trim(), date, LogType.getByIconName(matcherLogs.group(1)), matcherLogs.group(7).trim()); if (matcherLogs.group(4) != null && matcherLogs.group(6) != null) { logDone.cacheGuid = matcherLogs.group(4); logDone.cacheName = matcherLogs.group(6); } // Apply the pattern for images in a trackable log entry against each full log (group(0)) final String logEntry = matcherLogs.group(0); final MatcherWrapper matcherLogImages = new MatcherWrapper(GCConstants.PATTERN_TRACKABLE_LOG_IMAGES, logEntry); /* * 1. Image URL * 2. Image title */ while (matcherLogImages.find()) { final Image logImage = new Image(matcherLogImages.group(1), matcherLogImages.group(2)); logDone.addLogImage(logImage); } trackable.getLogs().add(logDone); } } catch (final Exception e) { // failed to parse logs Log.w("GCParser.parseCache: Failed to parse cache logs", e); } // tracking code if (!StringUtils.equalsIgnoreCase(trackable.getGeocode(), possibleTrackingcode)) { trackable.setTrackingcode(possibleTrackingcode); } if (CgeoApplication.getInstance() != null) { DataStore.saveTrackable(trackable); } return trackable; }
From source file:ch.cyberduck.ui.cocoa.controller.BrowserController.java
@Action public void quickConnectSelectionChanged(final NSComboBox sender) { final String input = StringUtils.trim(sender.stringValue()); if (StringUtils.isBlank(input)) { return;// w w w. j a v a2 s .c o m } // First look for equivalent bookmarks for (Host h : bookmarks) { if (BookmarkNameProvider.toString(h).equals(input)) { this.mount(h); return; } } // Try to parse the input as a URL and extract protocol, hostname, username and password if any. this.mount(HostParser.parse(input)); }
From source file:com.u2apple.rt.ui.RecognitionToolJFrame.java
private void knockOffButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knockOffButtonActionPerformed String productId = StringUtils.trim(productIdTextField.getText()); String resolution = StringUtils.trim((String) resolutionComboBox.getSelectedItem()); String partition = StringUtils.trim(partitionTextField.getText()); if (StringUtils.isBlank(productId)) { JOptionPane.showMessageDialog(jPanel13, "Product ID should not be blank."); } else if (StringUtils.isBlank(resolution)) { JOptionPane.showMessageDialog(jPanel13, "Resolution should not be blank."); } else if (StringUtils.isBlank(partition)) { JOptionPane.showMessageDialog(jPanel13, "Partition should not be blank."); } else {// w w w. j av a2s . c o m String config = KnockOffTool.getKnockOffConfig(productId, resolution, partition); resultTextArea.setText(config); } }
From source file:com.u2apple.rt.ui.RecognitionToolJFrame.java
private void addTestCase() { final String productId = StringUtils.trim(productIdTextField.getText()); final String vid = StringUtils.trim(vidTextField.getText()); final String roProductModel = StringUtils.trim(modelTextField.getText()); final String vid2 = StringUtils.trim(vid2TextField.getText()); //Validation. if (StringUtils.isBlank(productId)) { JOptionPane.showMessageDialog(jPanel13, "Product ID should not be blank."); } else if (StringUtils.isBlank(vid)) { JOptionPane.showMessageDialog(jPanel13, "Vid should not be blank."); } else if (StringUtils.isBlank(roProductModel)) { JOptionPane.showMessageDialog(jPanel13, "ro.product.model should not be blank."); } else {/*from w w w. j a v a 2 s .c o m*/ //Generate test case. Set<String> vidSet = new HashSet<>(); vidSet.add(vid); if (!StringUtils.equalsIgnoreCase(vid, Constants.RECOVERY_VID)) { vidSet.add(Constants.RECOVERY_VID); } if (StringUtils.isNotBlank(vid2)) { vidSet.add(vid2); } generateTestCase(vidSet.toArray(new String[vidSet.size()]), roProductModel, productId); } }
From source file:com.u2apple.rt.ui.RecognitionToolJFrame.java
private void generateTestCase(String[] vids, String roProductModel, String productId) { //Generate test case. String text;/* w w w . j a v a 2s . c o m*/ text = "Add test case for " + Arrays.toString(vids) + " model " + roProductModel; //Setting required properties. AndroidDevice androidDevice = new AndroidDevice(); // androidDevice.setVid(vid); androidDevice.setRoProductModel(roProductModel); androidDevice.setProductId(productId); androidDevice.setVids(vids); if (knockOffCheckBox.isSelected()) { //TODO: knock off case. String partitions = StringUtils.trim(partitionTextField.getText()); String resolution = StringUtils.trim((String) resolutionComboBox.getSelectedItem()); text = TestCaseTool.generateDeviceTestCase(productId, vids[0], roProductModel, resolution, partitions); } if (conditionCheckBox.isSelected()) { //1st condition. String condition = (String) conditionComboBox.getSelectedItem(); String conditionValue = conditionTextField.getText(); if (StringUtils.isNotBlank(conditionValue)) { switch (condition) { case "Board": androidDevice.setRoProductBoard(conditionValue); break; case "Brand": // String roProductBrand = AndroidDeviceUtils.getBrandByProductId(productId); androidDevice.setRoProductBrand(conditionValue); break; case "Cpu": androidDevice.setCpuHardware(conditionValue); break; case "Device": androidDevice.setRoProductDevice(conditionValue); break; case "Hardware": androidDevice.setRoHardware(conditionValue); break; case "Manufacturer": androidDevice.setRoProductManufacturer(conditionValue); break; case "Adb_Device": androidDevice.setAdbDevice(conditionValue); break; case "Display_ID": androidDevice.setRoBuildDisplayId(conditionValue); } } //2nd condition. String condition2 = (String) condition2ComboBox.getSelectedItem(); String condition2Value = condition2TextField.getText(); if (StringUtils.isNotBlank(condition2Value) && !condition.equalsIgnoreCase(condition2)) { switch (condition2) { case "Board": androidDevice.setRoProductBoard(condition2Value); break; case "Brand": androidDevice.setRoProductBrand(condition2Value); break; case "Cpu": androidDevice.setCpuHardware(condition2Value); break; case "Device": androidDevice.setRoProductDevice(condition2Value); break; case "Hardware": androidDevice.setRoHardware(condition2Value); break; case "Manufacturer": androidDevice.setRoProductManufacturer(condition2Value); break; case "Adb_Device": androidDevice.setAdbDevice(condition2Value); break; case "Display_ID": androidDevice.setRoBuildDisplayId(conditionValue); } } } TestCaseTool.generateTestCase(androidDevice); resultTextArea.append(System.getProperty("line.separator")); resultTextArea.append(text); }
From source file:com.mirth.connect.client.ui.Frame.java
/** * Alerts the user with an exception dialog with the passed in stack trace. *///from w ww . ja v a2 s.c o m public void alertThrowable(Component parentComponent, Throwable t, String customMessage, boolean showMessageOnForbidden, String safeErrorKey) { if (connectionError) { return; } if (safeErrorKey != null) { increaseSafeErrorFailCount(safeErrorKey); if (getSafeErrorFailCount(safeErrorKey) < 3) { return; } } parentComponent = getVisibleComponent(parentComponent); String message = StringUtils.trimToEmpty(customMessage); boolean showDialog = true; if (t != null) { // Always print the stacktrace for troubleshooting purposes t.printStackTrace(); if (t instanceof ExecutionException && t.getCause() != null) { t = t.getCause(); } if (t.getCause() != null && t.getCause() instanceof ClientException) { t = t.getCause(); } if (StringUtils.isBlank(message) && StringUtils.isNotBlank(t.getMessage())) { message = t.getMessage(); } /* * Logout if an exception occurs that indicates the server is no longer running or * accessible. We only want to do this if a ClientException was passed in, indicating it * was actually due to a request to the server. Other places in the application could * call this method with an exception that happens to contain the string * "Connection reset", for example. */ if (t instanceof ClientException) { if (t instanceof ForbiddenException || t.getCause() != null && t.getCause() instanceof ForbiddenException) { message = "You are not authorized to perform this action.\n\n" + message; if (!showMessageOnForbidden) { showDialog = false; } } else if (StringUtils.contains(t.getMessage(), "Received close_notify during handshake")) { return; } else if (t.getCause() != null && t.getCause() instanceof IllegalStateException && mirthClient.isClosed()) { return; } else if (StringUtils.contains(t.getMessage(), "reset") || (t instanceof UnauthorizedException || t.getCause() != null && t.getCause() instanceof UnauthorizedException)) { connectionError = true; statusUpdaterExecutor.shutdownNow(); alertWarning(parentComponent, "Sorry your connection to Mirth has either timed out or there was an error in the connection. Please login again."); if (!exportChannelOnError()) { return; } mirthClient.close(); this.dispose(); LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); return; } else if (t.getCause() != null && t.getCause() instanceof HttpHostConnectException && StringUtils.contains(t.getCause().getMessage(), "Connection refused")) { connectionError = true; statusUpdaterExecutor.shutdownNow(); String server; if (!StringUtils.isBlank(PlatformUI.SERVER_NAME)) { server = PlatformUI.SERVER_NAME + "(" + PlatformUI.SERVER_URL + ")"; } else { server = PlatformUI.SERVER_URL; } alertWarning(parentComponent, "The Mirth Connect server " + server + " is no longer running. Please start it and log in again."); if (!exportChannelOnError()) { return; } mirthClient.close(); this.dispose(); LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", ""); return; } } for (String stackFrame : ExceptionUtils.getStackFrames(t)) { if (StringUtils.isNotEmpty(message)) { message += '\n'; } message += StringUtils.trim(stackFrame); } } logger.error(message); if (showDialog) { Window owner = getWindowForComponent(parentComponent); if (owner instanceof java.awt.Frame) { new ErrorDialog((java.awt.Frame) owner, message); } else { // window instanceof Dialog new ErrorDialog((java.awt.Dialog) owner, message); } } }