List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.openhab.binding.weather.internal.converter.property.PercentIntegerConverter.java
/** * {@inheritDoc}// w w w . ja v a 2 s . co m */ @Override public Integer convert(String value) { return super.convert(StringUtils.remove(value, "%")); }
From source file:org.openhab.binding.weather.internal.provider.AbstractWeatherProvider.java
/** * Executes the http request and parses the returned stream. *///from w w w. j ava2 s. co m private void executeRequest(Weather weather, String url, LocationConfig locationConfig) throws Exception { GetMethod get = null; try { logger.trace("{}[{}]: request : {}", getProviderName(), locationConfig.getLocationId(), url); get = new GetMethod(url); httpClient.executeMethod(get); InputStream is = null; if (logger.isTraceEnabled()) { String response = get.getResponseBodyAsString(100000); response = StringUtils.remove(response, "\n"); response = StringUtils.trim(response); logger.trace("{}[{}]: response: {}", getProviderName(), locationConfig.getLocationId(), response); is = new ByteArrayInputStream(response.getBytes(get.getResponseCharSet())); } else { is = get.getResponseBodyAsStream(); } if (get.getStatusCode() == HttpStatus.SC_OK) { parser.parseInto(is, weather); } // special handling because of bad OpenWeatherMap json structure if (weather.getProvider() == ProviderName.OPENWEATHERMAP && weather.getResponseCode() != null && weather.getResponseCode() == 200) { weather.setError(null); } if (!weather.hasError() && get.getStatusCode() != HttpStatus.SC_OK) { weather.setError(get.getStatusLine().toString()); } if (weather.hasError()) { logger.error("{}[{}]: Can't retreive weather data: {}", getProviderName(), locationConfig.getLocationId(), weather.getError()); } else { setLastUpdate(weather); } } catch (Exception ex) { logger.error(getProviderName() + ": " + ex.getMessage()); weather.setError(ex.getClass().getSimpleName() + ": " + ex.getMessage()); throw ex; } finally { if (get != null) { get.releaseConnection(); } } }
From source file:org.openmrs.module.clinicalsummary.io.DownloadSummariesTask.java
private void processStream(ZipOutputStream zipOutputStream, String basePath, File currentFile, Date cutOffDate) throws Exception { byte data[] = new byte[TaskConstants.BUFFER_SIZE]; if (currentFile.isDirectory()) { FileFilter fileFilter = new WildcardFileFilter( StringUtils.join(Arrays.asList("*", Evaluator.FILE_TYPE_XML), ".")); File[] files = currentFile.listFiles(fileFilter); for (File file : files) { processStream(zipOutputStream, basePath, file, cutOffDate); }/*from ww w .j a v a 2s. co m*/ } else { if (cutOffDate == null || FileUtils.isFileNewer(currentFile, cutOffDate)) { processedFilename = currentFile.getName(); // add the zip entry String zipEntryName = StringUtils.remove(currentFile.getAbsolutePath(), basePath); ZipEntry entry = new ZipEntry(zipEntryName); zipOutputStream.putNextEntry(entry); // write the entry int count; InputStream inStream = new BufferedInputStream(new FileInputStream(currentFile)); while ((count = inStream.read(data, 0, TaskConstants.BUFFER_SIZE)) != -1) { zipOutputStream.write(data, 0, count); } inStream.close(); } } }
From source file:org.openmrs.module.ModuleUtil.java
/** * This method is an enhancement of {@link #compareVersion(String, String)} and adds support for * wildcard characters and upperbounds. <br> * <br>// w ww . j a va 2 s .c om * This method calls {@link ModuleUtil#checkRequiredVersion(String, String)} internally. <br> * <br> * The require version number in the config file can be in the following format: * <ul> * <li>1.2.3</li> * <li>1.2.*</li> * <li>1.2.2 - 1.2.3</li> * <li>1.2.* - 1.3.*</li> * </ul> * * @param version openmrs version number to be compared * @param versionRange value in the config file for required openmrs version * @return true if the <code>version</code> is within the <code>value</code> * @should allow ranged required version * @should allow ranged required version with wild card * @should allow ranged required version with wild card on one end * @should allow single entry for required version * @should allow required version with wild card * @should allow non numeric character required version * @should allow ranged non numeric character required version * @should allow ranged non numeric character with wild card * @should allow ranged non numeric character with wild card on one end * @should return false when openmrs version beyond wild card range * @should return false when required version beyond openmrs version * @should return false when required version with wild card beyond openmrs version * @should return false when required version with wild card on one end beyond openmrs version * @should return false when single entry required version beyond openmrs version * @should allow release type in the version * @should match when revision number is below maximum revision number * @should not match when revision number is above maximum revision number * @should correctly set upper and lower limit for versionRange with qualifiers and wild card * @should match when version has wild card plus qualifier and is within boundary * @should not match when version has wild card plus qualifier and is outside boundary * @should match when version has wild card and is within boundary * @should not match when version has wild card and is outside boundary * @should return true when required version is empty */ public static boolean matchRequiredVersions(String version, String versionRange) { // There is a null check so no risk in keeping the literal on the right side if (StringUtils.isNotEmpty(versionRange)) { String[] ranges = versionRange.split(","); for (String range : ranges) { // need to externalize this string String separator = "-"; if (range.indexOf("*") > 0 || range.indexOf(separator) > 0 && (!isVersionWithQualifier(range))) { // if it contains "*" or "-" then we must separate those two // assume it's always going to be two part // assign the upper and lower bound // if there's no "-" to split lower and upper bound // then assign the same value for the lower and upper String lowerBound = range; String upperBound = range; int indexOfSeparator = range.indexOf(separator); while (indexOfSeparator > 0) { lowerBound = range.substring(0, indexOfSeparator); upperBound = range.substring(indexOfSeparator + 1); if (upperBound.matches("^\\s?\\d+.*")) { break; } indexOfSeparator = range.indexOf(separator, indexOfSeparator + 1); } // only preserve part of the string that match the following format: // - xx.yy.* // - xx.yy.zz* lowerBound = StringUtils.remove(lowerBound, lowerBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*]+", "")); upperBound = StringUtils.remove(upperBound, upperBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*]+", "")); // if the lower contains "*" then change it to zero if (lowerBound.indexOf("*") > 0) { lowerBound = lowerBound.replaceAll("\\*", "0"); } // if the upper contains "*" then change it to maxRevisionNumber if (upperBound.indexOf("*") > 0) { upperBound = upperBound.replaceAll("\\*", Integer.toString(Integer.MAX_VALUE)); } int lowerReturn = compareVersion(version, lowerBound); int upperReturn = compareVersion(version, upperBound); if (lowerReturn < 0 || upperReturn > 0) { log.debug("Version " + version + " is not between " + lowerBound + " and " + upperBound); } else { return true; } } else { if (compareVersion(version, range) < 0) { log.debug("Version " + version + " is below " + range); } else { return true; } } } } else { //no version checking if required version is not specified return true; } return false; }
From source file:org.openo.gso.util.uuid.UuidUtils.java
/** * Generate UUID by 3rd tools.<br/> * //w ww.ja v a 2 s. c o m * @return uuid * @since GSO 0.5 */ public static String createUuid() { String uuid = UUID.randomUUID().toString(); return StringUtils.remove(uuid, '-'); }
From source file:org.pentaho.di.trans.steps.mailinput.MailInput.java
public boolean init(StepMetaInterface smi, StepDataInterface sdi) { meta = (MailInputMeta) smi;/*from ww w. java2 s . c o m*/ data = (MailInputData) sdi; if (!super.init(smi, sdi)) { return false; } if (!meta.isDynamicFolder()) { try { // Create the output row meta-data data.outputRowMeta = new RowMeta(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore); // get the // metadata // populated } catch (Exception e) { logError(BaseMessages.getString(PKG, "MailInput.ErrorInit", e.toString())); logError(Const.getStackTracker(e)); return false; } } data.usePOP = meta.getProtocol().equals(MailConnectionMeta.PROTOCOL_STRING_POP3); String realserver = environmentSubstitute(meta.getServerName()); if (meta.getProtocol().equals(MailConnectionMeta.PROTOCOL_STRING_MBOX) && StringUtils.startsWith(realserver, "file://")) { realserver = StringUtils.remove(realserver, "file://"); } String realusername = environmentSubstitute(meta.getUserName()); String realpassword = environmentSubstitute(meta.getPassword()); int realport = Const.toInt(environmentSubstitute(meta.getPort()), -1); String realProxyUsername = environmentSubstitute(meta.getProxyUsername()); if (!meta.isDynamicFolder()) { //Limit field has absolute priority String reallimitrow = environmentSubstitute(meta.getRowLimit()); int limit = Const.toInt(reallimitrow, 0); //Limit field has absolute priority if (limit == 0) { limit = getReadFirst(meta.getProtocol()); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat(MailInputMeta.DATE_PATTERN); // check search terms // Received Date try { switch (meta.getConditionOnReceivedDate()) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute(meta.getReceivedDate1()); if (Const.isEmpty(realBeginDate)) { throw new KettleException( BaseMessages.getString(PKG, "MailInput.Error.ReceivedDateSearchTermEmpty")); } beginDate = df.parse(realBeginDate); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute(meta.getReceivedDate1()); if (Const.isEmpty(realBeginDate)) { throw new KettleException( BaseMessages.getString(PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty")); } beginDate = df.parse(realBeginDate); String realEndDate = environmentSubstitute(meta.getReceivedDate2()); if (Const.isEmpty(realEndDate)) { throw new KettleException( BaseMessages.getString(PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty")); } endDate = df.parse(realEndDate); break; default: break; } } catch (Exception e) { logError(BaseMessages.getString(PKG, "MailInput.Error.SettingSearchTerms", e.getMessage())); setErrors(1); stopAll(); } try { // create a mail connection object data.mailConn = new MailConnection(log, MailConnectionMeta.getProtocolFromString(meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername); // connect data.mailConn.connect(); // Need to apply search filters? applySearch(beginDate, endDate); if (!meta.isDynamicFolder()) { // pass static folder name String realIMAPFolder = environmentSubstitute(meta.getIMAPFolder()); // return folders list // including sub folders if necessary data.folders = getFolders(realIMAPFolder); } } catch (Exception e) { logError(BaseMessages.getString(PKG, "MailInput.Error.OpeningConnection", e.getMessage())); setErrors(1); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; }
From source file:org.polymap.core.catalog.model.ServiceTypeFolder.java
public String getTitle() { String typeName = type.getSimpleName(); if (StringUtils.contains(typeName, "Post")) { return "PostGIS"; } else if (StringUtils.contains(typeName, "Shp")) { return "Shapefile"; } else if (StringUtils.contains(typeName, "WMS")) { return "WMS"; } else if (StringUtils.contains(typeName, "WFS")) { return "WFS"; } else if (StringUtils.contains(typeName, "Oracle")) { return "Oracle"; } else if (StringUtils.contains(typeName, "MySQL")) { return "MySQL"; } else if (StringUtils.containsIgnoreCase(typeName, "GeoTiff")) { return "GeoTIFF"; } else if (StringUtils.containsIgnoreCase(typeName, "DXF")) { return "DXF"; } else {// w ww .j a v a2s .co m try { IService service = (IService) services.get(0); String result = service.getInfo(null).getShortTitle(); if (result != null) { return result; } else { throw new Exception("trying last resort..."); } } catch (Exception e) { String result = StringUtils.remove(typeName, "Impl"); result = StringUtils.remove(result, "Service"); return result; } } }
From source file:org.red5.io.utils.PropertyConverter.java
/** * Converts a string denoting an amount of time into milliseconds and adds * it to the current date. Strings are expected to follow this form where # * equals a digit: #M The following are permitted for denoting time: H = * hours, M = minutes, S = seconds/* www.j ava2 s.co m*/ * * @param time time * @return time in milliseconds */ public static long convertStringToFutureTimeMillis(String time) { Calendar exp = Calendar.getInstance(); if (time.endsWith("H")) { exp.add(Calendar.HOUR, Integer.valueOf(StringUtils.remove(time, 'H'))); } else if (time.endsWith("M")) { exp.add(Calendar.MINUTE, Integer.valueOf(StringUtils.remove(time, 'M'))); } else if (time.endsWith("S")) { exp.add(Calendar.MILLISECOND, Integer.valueOf(StringUtils.remove(time, 'S')) * 1000); } return exp.getTimeInMillis(); }
From source file:org.red5.io.utils.PropertyConverter.java
/** * Converts a string denoting an amount of time into seconds. Strings are * expected to follow this form where # equals a digit: #M The following are * permitted for denoting time: H = hours, M = minutes, S = seconds * /*from ww w. j a va2 s . co m*/ * @param time time * @return time in seconds */ public static int convertStringToTimeSeconds(String time) { int result = 0; if (time.endsWith("H")) { int hoursToAdd = Integer.valueOf(StringUtils.remove(time, 'H')); result = (60 * 60) * hoursToAdd; } else if (time.endsWith("M")) { int minsToAdd = Integer.valueOf(StringUtils.remove(time, 'M')); result = 60 * minsToAdd; } else if (time.endsWith("S")) { int secsToAdd = Integer.valueOf(StringUtils.remove(time, 'S')); result = secsToAdd; } return result; }
From source file:org.red5.io.utils.PropertyConverter.java
/** * Converts a string denoting an amount of time into milliseconds. Strings * are expected to follow this form where # equals a digit: #M The following * are permitted for denoting time: H = hours, M = minutes, S = seconds * // w w w.ja va2 s . com * @param time time * @return time in milliseconds */ public static long convertStringToTimeMillis(String time) { long result = 0; if (time.endsWith("H")) { long hoursToAdd = Integer.valueOf(StringUtils.remove(time, 'H')); result = ((1000 * 60) * 60) * hoursToAdd; } else if (time.endsWith("M")) { long minsToAdd = Integer.valueOf(StringUtils.remove(time, 'M')); result = (1000 * 60) * minsToAdd; } else if (time.endsWith("S")) { long secsToAdd = Integer.valueOf(StringUtils.remove(time, 'S')); result = 1000 * secsToAdd; } return result; }