List of usage examples for org.apache.commons.lang3 StringUtils remove
public static String remove(final String str, final char remove)
Removes all occurrences of a character from within the source string.
A null source string will return null .
From source file:com.qcadoo.mes.basic.shift.WorkingHours.java
private Set<TimeRange> parseIntervals(final String hoursRanges) { if (StringUtils.isBlank(hoursRanges)) { return Collections.emptySet(); }/*from ww w . j av a 2 s .c om*/ String trimmedHoursRanges = StringUtils.remove(hoursRanges, ' '); if (!WORKING_HOURS_PATTERN.matcher(trimmedHoursRanges).matches()) { throw new IllegalArgumentException( String.format("Invalid shift's work time definition format: %s", hoursRanges)); } final Set<TimeRange> intervals = Sets.newHashSet(); for (String hoursRange : StringUtils.split(trimmedHoursRanges, ',')) { TimeRange interval = stringToInterval(hoursRange); if (interval != null) { intervals.add(interval); } } return intervals; }
From source file:com.ufukuzun.myth.dialect.util.ExpressionUtils.java
public static String removeRenderExpressions(String value) { if (StringUtils.isNotBlank(value)) { List<String> renderExpressions = extractRenderExpressions(value); for (String each : renderExpressions) { value = StringUtils.remove(value, each); }//from w ww .j av a 2 s .c o m } return value; }
From source file:ke.co.tawi.babblesms.server.persistence.utils.DbFileUtils.java
/** * This is used to export the results of an SQL query into a CSV text file. * * @param sqlQuery/*from ww w . ja va 2 s . c o m*/ * @param fileName this should include the full path of the file e.g. * /tmp/myFile.csv * @param delimiter * * @return whether the action was successful or not */ public boolean sqlResultToCSV(String sqlQuery, String fileName, char delimiter) { boolean success = true; String sanitizedQuery = StringUtils.remove(sqlQuery, ';'); BufferedWriter writer; try ( // Return a database connection that is not pooled // to enable the connection to be cast to BaseConnection Connection conn = dbCredentials.getJdbcConnection();) { FileUtils.deleteQuietly(new File(fileName)); FileUtils.touch(new File(fileName)); writer = new BufferedWriter(new FileWriter(fileName)); CopyManager copyManager = new CopyManager((BaseConnection) conn); StringBuffer query = new StringBuffer("COPY (").append(sanitizedQuery) .append(") to STDOUT WITH DELIMITER '").append(delimiter).append("'"); copyManager.copyOut(query.toString(), writer); writer.close(); } catch (SQLException e) { logger.error( "SQLException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'."); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } catch (IOException e) { logger.error( "IOException while exporting results of query '" + sqlQuery + "' to file '" + fileName + "'."); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } return success; }
From source file:com.jayway.restassured.itest.java.CustomObjectMappingITest.java
@Test public void using_explicit_custom_object_mapper() throws Exception { final Message message = new Message(); message.setMessage("A message"); final ObjectMapper mapper = new ObjectMapper() { public Object deserialize(ObjectMapperDeserializationContext context) { final String toDeserialize = context.getDataToDeserialize().asString(); final String unquoted = StringUtils.remove(toDeserialize, "#"); final Message message = new Message(); message.setMessage(unquoted); customDeserializationUsed.set(true); return message; }//from w w w .j a v a2 s .c om public Object serialize(ObjectMapperSerializationContext context) { final Message objectToSerialize = context.getObjectToSerializeAs(Message.class); final String message = objectToSerialize.getMessage(); customSerializationUsed.set(true); return "##" + message + "##"; } }; final Message returnedMessage = given().body(message, mapper).when().post("/reflect").as(Message.class, mapper); assertThat(returnedMessage.getMessage(), equalTo("A message")); assertThat(customSerializationUsed.get(), is(true)); assertThat(customDeserializationUsed.get(), is(true)); }
From source file:cz.lidinsky.editor.Menu.java
protected void setLabel(final JMenuItem menuItem, final String label) { if (label != null) { int mnemonicIndex = label.indexOf('_'); if (mnemonicIndex >= 0) { String text = StringUtils.remove(label, '_'); int key = text.codePointAt(mnemonicIndex); menuItem.setText(text);/*from ww w. j a v a 2 s . com*/ menuItem.setMnemonic(key); } else { menuItem.setText(label); } } }
From source file:com.quartercode.femtoweb.impl.FemtoWebFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; // Retrieve the requested URI String uri = RequestUtils.getRequestUri(request); // If no specific action is specified (empty URI, e.g. "/"), redirect to the index URI (by default "/index") if (StringUtils.remove(uri, '/').isEmpty()) { response.sendRedirect(request.getContextPath() + context.getIndexUri()); return;/*from w w w . j a va 2 s .c o m*/ } // If the static content is requested, directly forward to that static content if (uri.startsWith(context.getStaticAssetPath())) { LOGGER.trace("Allowing direct access to static content '{}'", uri); chain.doFilter(request, response); return; } // If the request is no special case, retrieve and execute the action responsible for the requested URI processAction(request, response, uri); }
From source file:com.jadarstudios.rankcapes.forge.cape.CapePack.java
/** * Parses the Zip file in memory./*from ww w . jav a 2s. co m*/ * * @param input the bytes of a valid zip file */ private void parsePack(byte[] input) { try { ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(input)); String metadata = ""; ZipEntry entry; while ((entry = zipInput.getNextEntry()) != null) { String name = entry.getName(); if (name.endsWith(".png")) { // remove file extension from the name. name = FilenameUtils.removeExtension(name); StaticCape cape = this.loadCape(name, zipInput); this.unprocessedCapes.put(name, cape); } else if (name.endsWith(".mcmeta")) { // parses the pack metadata. InputStreamReader streamReader = new InputStreamReader(zipInput); while (streamReader.ready()) { metadata += (char) streamReader.read(); } } } if (!Strings.isNullOrEmpty(metadata)) { this.parsePackMetadata(StringUtils.remove(metadata, (char) 65535)); } else { RankCapesForge.log.warn("Cape Pack metadata is missing!"); } } catch (IOException e) { e.printStackTrace(); } }
From source file:de.jfachwert.steuer.UStIdNr.java
private static String verify(String nr, PruefzifferVerfahren<String> verfahren) { String unformatted = StringUtils.remove(nr, ' '); LengthValidator.verify(unformatted, 7, 14); verfahren.verify(unformatted.substring(2)); return unformatted; }
From source file:com.buildabrand.gsb.util.URLUtils.java
/** * Returns the canonicalized form of a URL, core logic written by Henrik Sjostrand, heavily modified for v2 by Dave Shanley. * * @param queryURL/*w w w. j a v a2 s .c om*/ * @return * @author Henrik Sjostrand, Netvouz, http://www.netvouz.com/, info@netvouz.com & Dave Shanley <dave@buildabrand.com> */ public String canonicalizeURL(String queryURL) { if (StringUtils.isEmpty(queryURL)) { return null; } // Start by stripping off the fragment identifier. queryURL = StringUtils.substringBefore(queryURL, "#"); // Stripping off leading and trailing white spaces. queryURL = StringUtils.trim(queryURL); // Remove any embedded tabs and CR/LF characters which aren't escaped. queryURL = StringUtils.remove(queryURL, '\t'); queryURL = StringUtils.remove(queryURL, '\r'); queryURL = StringUtils.remove(queryURL, '\n'); // Un-escape and re-escpae the URL just in case there are some encoded // characters in the url scheme for example. queryURL = escape(queryURL); URL url; try { url = new URL(queryURL); } catch (MalformedURLException e) { // Try again with "http://" try { url = new URL("http://" + queryURL); } catch (MalformedURLException e2) { logger.error("Malformed url", e); return null; } } if (!(url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("ftp"))) { return null; } // Note: applying HOST_PORT_REGEXP also removes any user and password. Matcher hostMatcher = HOST_PORT_REGEXP.matcher(url.getHost()); if (!hostMatcher.find()) { return null; } String host = hostMatcher.group(1); String canonicalHost = canonicalizeHost(host); if (canonicalHost == null) { return null; } // Now that the host is canonicalized we add the port back if it's not the // default port for that url scheme if (url.getPort() != -1 && ((url.getProtocol().equalsIgnoreCase("http") && url.getPort() != 80) || (url.getProtocol().equalsIgnoreCase("https") && url.getPort() != 443) || (url.getProtocol().equalsIgnoreCase("ftp") && url.getPort() != 21))) { canonicalHost = canonicalHost + ":" + url.getPort(); } String canonicalPath = canonicalizePath(url.getPath()); String canonicalUrl = url.getProtocol() + "://" + canonicalHost + canonicalPath; if (StringUtils.isNotEmpty(url.getQuery()) || queryURL.endsWith("?")) { canonicalUrl += "?" + url.getQuery(); } return canonicalUrl; }
From source file:at.jps.sanction.core.listhandler.reflist.BicListHandler.java
private void readList(final String filename) { logger.info("start reading " + LISTNAME + " file:" + filename); if (bicCodes != null) { return;/*from w w w . j a v a 2 s. c o m*/ } try { final BufferedReader input = new BufferedReader(new FileReader(filename)); try { String line = null; do { line = input.readLine(); if (line != null) { final int pos = line.indexOf("\",\""); final String bic = StringUtils.remove(line.substring(1, pos), "\""); final String name = StringUtils.remove(line.substring(pos + 2), "\""); // // String bic = // StringUtils.remove(tokenizer.nextToken(),"\""); // String name = // StringUtils.remove(tokenizer.nextToken(),"\""); logger.debug("BIC :" + bic + " -> " + name); getValues().put(bic, name); } } while (line != null); } finally { input.close(); } } catch (final Exception x) { logger.error( "parsing failed reading " + LISTNAME + " file:" + filename + " Exception: " + x.toString()); logger.debug("Exception : ", x); } logger.info("finished reading " + LISTNAME + " file:" + filename); logger.info("finished reading BICs :" + getValues().size()); }