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.thoughtworks.go.domain.materials.svn.SvnExternalParser.java
private String relativeRoot(String absoluteRoot, String repoUrl) { return StringUtils.strip(StringUtils.remove(absoluteRoot, repoUrl), "/"); }
From source file:ke.co.tawi.babblesms.server.servlet.upload.UploadUtil.java
protected void saveContacts(File contactFile, Account account, ContactDAO contactDAO, PhoneDAO phoneDAO, List<String> groupUuids, ContactGroupDAO contactGroupDAO) { LineIterator lineIterator = null;//from w ww. java2s . c o m Contact contact; Phone phone; List<Group> groupList = new LinkedList<>(); Group grp; for (String uuid : groupUuids) { grp = new Group(); grp.setUuid(uuid); groupList.add(grp); } try { lineIterator = FileUtils.lineIterator(contactFile, "UTF-8"); String line; String[] rowTokens, phoneTokens, networkTokens; while (lineIterator.hasNext()) { line = lineIterator.nextLine(); rowTokens = StringUtils.split(line, ','); // Extract the Contact and save contact = new Contact(); contact.setAccountUuid(account.getUuid()); contact.setName(rowTokens[0]); contact.setStatusUuid(Status.ACTIVE); contactDAO.putContact(contact); // Extract the phones and save phoneTokens = StringUtils.split(rowTokens[1], ';'); networkTokens = StringUtils.split(rowTokens[2], ';'); String network; for (int j = 0; j < phoneTokens.length; j++) { phone = new Phone(); phone.setPhonenumber(StringUtils.trimToEmpty(phoneTokens[j])); phone.setPhonenumber(StringUtils.remove(phone.getPhonenumber(), ' ')); phone.setContactUuid(contact.getUuid()); phone.setStatusuuid(Status.ACTIVE); network = StringUtils.lowerCase(StringUtils.trimToEmpty(networkTokens[j])); phone.setNetworkuuid(networkUuidArray[networkList.indexOf(network)]); phoneDAO.putPhone(phone); } // Associate the Contact to the Groups for (Group group : groupList) { contactGroupDAO.putContact(contact, group); } } // end 'while (lineIterator.hasNext())' } catch (IOException e) { logger.error("IOException when storing: " + contactFile); logger.error(e); } finally { if (lineIterator != null) { lineIterator.close(); } } }
From source file:com.moviejukebox.reader.MovieNFOReader.java
/** * Try and read a NFO file for information * * First try as XML format file, then check to see if it contains XML and text and split it to read each part * * @param nfoFile//from ww w .j a v a2 s . c om * @param movie * @return */ public static boolean readNfoFile(File nfoFile, Movie movie) { String nfoText = FileTools.readFileToString(nfoFile); boolean parsedNfo = Boolean.FALSE; // Was the NFO XML parsed correctly or at all boolean hasXml = Boolean.FALSE; if (StringUtils.containsIgnoreCase(nfoText, XML_START + TYPE_MOVIE) || StringUtils.containsIgnoreCase(nfoText, XML_START + TYPE_TVSHOW) || StringUtils.containsIgnoreCase(nfoText, XML_START + TYPE_EPISODE)) { hasXml = Boolean.TRUE; } // If the file has XML tags in it, try reading it as a pure XML file if (hasXml) { parsedNfo = readXmlNfo(nfoFile, movie); } // If it has XML in it, but didn't parse correctly, try splitting it out if (hasXml && !parsedNfo) { int posMovie = findPosition(nfoText, TYPE_MOVIE); int posTv = findPosition(nfoText, TYPE_TVSHOW); int posEp = findPosition(nfoText, TYPE_EPISODE); int start = Math.min(posMovie, Math.min(posTv, posEp)); posMovie = StringUtils.indexOf(nfoText, XML_END + TYPE_MOVIE); posTv = StringUtils.indexOf(nfoText, XML_END + TYPE_TVSHOW); posEp = StringUtils.indexOf(nfoText, XML_END + TYPE_EPISODE); int end = Math.max(posMovie, Math.max(posTv, posEp)); if ((end > -1) && (end > start)) { end = StringUtils.indexOf(nfoText, '>', end) + 1; // Send text to be read String nfoTrimmed = StringUtils.substring(nfoText, start, end); parsedNfo = readXmlNfo(nfoTrimmed, movie, nfoFile.getName()); nfoTrimmed = StringUtils.remove(nfoText, nfoTrimmed); if (parsedNfo && nfoTrimmed.length() > 0) { // We have some text left, so scan that with the text scanner readTextNfo(nfoTrimmed, movie); } } } // If the XML wasn't found or parsed correctly, then fall back to the old method if (parsedNfo) { LOG.debug("Successfully scanned {} as XML format", nfoFile.getName()); } else { parsedNfo = MovieNFOReader.readTextNfo(nfoText, movie); if (parsedNfo) { LOG.debug("Successfully scanned {} as text format", nfoFile.getName()); } else { LOG.debug("Failed to find any information in {}", nfoFile.getName()); } } return Boolean.FALSE; }
From source file:com.thruzero.common.core.fs.walker.visitor.ZipCompressingVisitor.java
protected String getRelativePath(final File file) { // make relative path String relativePath = StringUtils.remove(file.getAbsolutePath(), rootDirectory.getAbsolutePath()); if (StringUtils.isEmpty(relativePath)) { return StringUtils.EMPTY; }/*from w w w . ja v a 2s . c o m*/ return StringUtils.stripStart(relativePath, String.valueOf(File.separatorChar)); }
From source file:io.github.swagger2markup.Swagger2MarkupMojo.java
private String getInputDirStructurePath(Swagger2MarkupConverter converter) { /*/* w ww .j a va2s .c om*/ * When the Swagger input is a local folder (e.g. /Users/foo/) you'll want to group the generated output in the * configured output directory. The most obvious approach is to replicate the folder structure from the input * folder to the output folder. Example: * - swaggerInput is set to /Users/foo * - there's a single Swagger file at /Users/foo/bar-service/v1/bar.yaml * - outputDir is set to /tmp/asciidoc * -> markdown files from bar.yaml are generated to /tmp/asciidoc/bar-service/v1 */ String swaggerFilePath = new File(converter.getContext().getSwaggerLocation()).getAbsolutePath(); // /Users/foo/bar-service/v1/bar.yaml String swaggerFileFolder = StringUtils.substringBeforeLast(swaggerFilePath, File.separator); // /Users/foo/bar-service/v1 return StringUtils.remove(swaggerFileFolder, getSwaggerInputAbsolutePath()); // /bar-service/v1 }
From source file:com.qtplaf.library.util.NumberUtils.java
/** * Returns a string key by concatenating the list of values, applying the scale and sign (1 for positive, 0 for * negative)./*from w w w . j a v a 2 s. c o m*/ * * @param values The list of values. * @param scale The scale. * @return The string key. */ public static String getStringKey(double[] values, int scale) { StringBuilder b = new StringBuilder(); for (double value : values) { String sign = (value >= 0 ? "1" : "0"); b.append(sign); b.append(StringUtils.remove(getBigDecimal(Math.abs(value), scale).toPlainString(), '.')); } return b.toString(); }
From source file:jodtemplate.template.expression.DefaultExpressionHandler.java
private VariableExpression createVariableExpressionNoCheck(final String expressionBody) { String defaultValue = StringUtils.substringAfterLast(expressionBody, DEFAULT_VALUE_SEPARATOR).trim(); defaultValue = StringUtils.remove(defaultValue, '"'); final String variableWithParams = StringUtils.substringBefore(expressionBody, DEFAULT_VALUE_SEPARATOR); final String variable = StringUtils.substringBefore(variableWithParams, PARAMS_VALUE_SEPARATOR); final String paramsString = StringUtils.substringAfter(variableWithParams, PARAMS_VALUE_SEPARATOR); final List<String> params = Arrays.asList(StringUtils.split(paramsString, PARAMS_VALUE_SEPARATOR)); final VariableExpression variableExpression = new VariableExpression(variable, params, defaultValue); return variableExpression; }
From source file:at.jps.sanction.core.util.TokenTool.java
public static List<String> getTokenList(final String text, final String delimiters, final String deadCharacters, final int minlength, final Collection<String> excludeList, final boolean filterTokens) { final List<String> textTokens = new ArrayList<>(10); if ((text != null) && (text.length() > minlength)) { String oriText = text.toUpperCase(); // remove dead characters if (deadCharacters != null) { for (int i = 0; i < deadCharacters.length(); i++) { oriText = StringUtils.remove(oriText, deadCharacters.charAt(i)); // oriText.replace(deadCharacters.charAt(i), ' '); }/* www. jav a 2s.c om*/ } // TODO: transliterate // remove stopwords - !! dead characters MUST NOT exist in stopwords !! // must be sorted by length !! if (!filterTokens) { if (excludeList != null) { for (final String stopword : excludeList) { oriText = oriText.replace(stopword.toUpperCase(), ""); } } } // maybe preserve original formatted text ? // StrTokenizer textTokenizer = new StrTokenizer(oriText, delimiters); // textTokenizer.setEmptyTokenAsNull(false); // textTokenizer.setIgnoreEmptyTokens(true); // feature !! if (delimiters != null) { final StringTokenizer textTokenizer = new StringTokenizer(oriText, delimiters); while (textTokenizer.hasMoreTokens()) { final String token = textTokenizer.nextToken().trim(); if ((token != null) && (token.length() >= minlength)) { // TODO: clear tokens ( deadchars...) if (filterTokens) { if ((excludeList == null) || (!excludeList.contains(token))) { if (!textTokens.contains(token)) { textTokens.add(token); } } } else { if (!textTokens.contains(token)) { textTokens.add(token); } } } } } else { textTokens.add(oriText); } } return textTokens; }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelper.java
/** * Get JDT ArrayType for the given type name. * /* w w w.j a va 2 s . co m*/ * @param ast * JDT AST tree * @param typeName * input type name * @return JDT ArrayType */ public ArrayType getAstArrayType(AST ast, String typeName) { Type componentType = null; // Remove [] for componentType typeName = StringUtils.remove(typeName, "[]"); if (dataTypeUtils.isPrimitiveType(typeName)) { componentType = getAstPrimitiveType(ast, typeName); } else { componentType = getAstSimpleType(ast, typeName); } ArrayType arrayType = ast.newArrayType(componentType); return arrayType; }
From source file:com.sangupta.passcode.PassCode.java
/** * Generate the unique password for the given master password and the salt * (the site's key).//from w w w.j a va 2 s . c o m * * @param masterPassword * the master password or passphrase to use * * @param saltOrSiteKey * the site based keyword to use * * @return the generated password as {@link String} */ public String generate(String masterPassword, String saltOrSiteKey) { if (this.required.size() > this.config.length) { throw new IllegalStateException("Length too small to fit all required characters"); } if (this.allowed.length() == 0) { throw new IllegalStateException("No characters available to create a password"); } // check for uuid append if (AssertUtils.isNotEmpty(this.config.uuid)) { saltOrSiteKey = saltOrSiteKey + this.config.uuid; } // get hash final double entropy = this.getEntropy(); // System.out.println("Entropy: " + entropy); byte[] hash = this.hash(masterPassword, saltOrSiteKey, 2 * (int) entropy); // System.out.println("Hex: " + com.sangupta.jerry.util.StringUtils.asHex(hash)); // convert to hash stream HashStream stream = new HashStream(hash); // start encoding the password // refer http://checkmyworking.com/2012/06/converting-a-stream-of-binary-digits-to-a-stream-of-base-n-digits/ // on the process // adapted for https://github.com/jcoglan/vault String result = ""; // int iter = 1; int previous = 0; while (result.length() < this.config.length) { int index = stream.generate(this.required.size(), 2, false); String charset = this.required.remove(index); // if(!result.isEmpty()) { // previous = result.charAt(result.length() - 1); // } else { // previous = 0; // } int i = this.config.repeat - 1; boolean same = (previous > 0) && (i >= 0); // System.out.println("iter: " + (iter++) + ", index:" + index + ", previous: " + Character.toString((char) previous) + ", i: " + i + ", same: " + same + ", charset: " + charset); while (same && (i-- >= 0)) { same = same && isSameChar(result, result.length() + i - this.config.repeat, previous); } if (same) { charset = StringUtils.remove(this.allowed, charset); } index = stream.generate(charset.length(), 2, false); result += charset.charAt(index); previous = charset.charAt(index); } return result; }