List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(String str, final String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:org.lockss.servlet.LockssServlet.java
public String getParameter(String name) { String val = req.getParameter(name); if (val == null && multiReq != null) { val = multiReq.getString(name); }//w w w .j a v a2 s .c o m if (val == null) { return null; } val = StringUtils.strip(val, " \t"); // if (StringUtil.isNullString(val)) { if ("".equals(val)) { return null; } return val; }
From source file:org.openecomp.sdc.common.util.ValidationUtils.java
private static String cleanFileName(String str) { str = CLEAN_FILENAME_PATTERN.matcher(str).replaceAll(""); str = normaliseWhitespace(str);/*w ww. j a va 2 s .co m*/ str = SPACE_PATTERN.matcher(str).replaceAll("-"); str = DASH_PATTERN.matcher(str).replaceAll("-"); str = StringUtils.strip(str, "-_ ."); return str; }
From source file:org.perfcake.examples.weaver.Weaver.java
/** * Parses worker configuration line.//from w ww . j av a 2 s .com * * @param configLine * The configuration line. * @return The number of worker instances created. */ private int parseWorker(final String configLine) { if (configLine != null && !configLine.isEmpty() && !configLine.startsWith("#")) { final String[] spaceSplit = configLine.split(" ", 2); final String[] equalsSplit = spaceSplit[1].split("=", 2); final int count = Integer.parseInt(StringUtils.strip(spaceSplit[0], " x")); String clazz = StringUtils.strip(equalsSplit[0]); clazz = clazz.contains(".") ? clazz : "org.perfcake.examples.weaver.worker." + clazz; final String[] propertiesConfig = StringUtils.stripAll(StringUtils.strip(equalsSplit[1]).split(",")); final Properties properties = new Properties(); final Properties mapProperties = new Properties(); for (final String property : propertiesConfig) { final String[] keyValue = StringUtils.stripAll(property.split(":", 2)); if (keyValue[0].matches("worker[0-9][0-9]*_.*")) { mapProperties.setProperty(keyValue[0], keyValue[1]); } else { properties.setProperty(keyValue[0], keyValue[1]); } } try { log.info("Summoning " + count + " instances of " + clazz + " with properties " + properties + " and map properties " + mapProperties); for (int i = 0; i < count; i++) { final Worker worker = (Worker) ObjectFactory.summonInstance(clazz, properties); boolean add = true; if (worker instanceof MapConfigurable) { add = ((MapConfigurable) worker).configure(mapProperties); } if (add) { workers.add(worker); } else { log.warn("Bad configuration. Skipping worker " + clazz); } } return count; } catch (ReflectiveOperationException e) { log.error("Unable to parse line '" + configLine + "': ", e); } } return 0; }
From source file:org.sleuthkit.autopsy.imagegallery.gui.navpanel.GroupTree.java
private static List<String> groupingToPath(DrawableGroup g) { String path = g.getGroupByValueDislpayName(); if (g.getGroupByAttribute() == DrawableAttribute.PATH) { String[] cleanPathTokens = StringUtils.stripStart(path, "/").split("/"); return Arrays.asList(cleanPathTokens); } else {//from w w w.ja v a 2 s. c om String stripStart = StringUtils.strip(path, "/"); return Arrays.asList(stripStart); } }
From source file:org.structr.common.PathHelper.java
public static String clean(final String path) { // Remove leading and trailing / return StringUtils.strip(path, PATH_SEP); }
From source file:org.structr.files.text.FulltextIndexingAgent.java
private void doIndexing(final Indexable file) { boolean parsingSuccessful = false; InputStream inputStream = null; String fileName = "unknown file"; try {//from w w w.j a va2 s. c om try (final Tx tx = StructrApp.getInstance().tx()) { inputStream = file.getInputStream(); fileName = file.getName(); tx.success(); } if (inputStream != null) { final FulltextTokenizer tokenizer = new FulltextTokenizer(fileName); try (final InputStream is = inputStream) { final AutoDetectParser parser = new AutoDetectParser(); parser.parse(is, new BodyContentHandler(tokenizer), new Metadata()); parsingSuccessful = true; } // only do indexing when parsing was successful if (parsingSuccessful) { try (Tx tx = StructrApp.getInstance().tx()) { // don't modify access time when indexing is finished file.getSecurityContext().preventModificationOfAccessTime(); // save raw extracted text file.setProperty(Indexable.extractedContent, tokenizer.getRawText()); // tokenize name tokenizer.write(getName()); // tokenize owner name final Principal _owner = file.getProperty(owner); if (_owner != null) { final String ownerName = _owner.getName(); if (ownerName != null) { tokenizer.write(ownerName); } final String eMail = _owner.getProperty(User.eMail); if (eMail != null) { tokenizer.write(eMail); } final String twitterName = _owner.getProperty(User.twitterName); if (twitterName != null) { tokenizer.write(twitterName); } } tx.success(); } // index document excluding stop words final NodeService nodeService = Services.getInstance().getService(NodeService.class); final Index<Node> fulltextIndex = nodeService.getNodeIndex(NodeService.NodeIndex.fulltext); final Set<String> stopWords = languageStopwordMap.get(tokenizer.getLanguage()); final String indexKeyName = Indexable.indexedWords.jsonName(); final Iterator<String> wordIterator = tokenizer.getWords().iterator(); final Node node = file.getNode(); final Set<String> indexedWords = new TreeSet<>(); logger.log(Level.INFO, "Indexing {0}..", fileName); while (wordIterator.hasNext()) { try (Tx tx = StructrApp.getInstance().tx()) { // remove node from index (in case of previous indexing runs) fulltextIndex.remove(node, indexKeyName); while (wordIterator.hasNext()) { // strip double quotes final String word = StringUtils.strip(wordIterator.next(), "\""); if (!stopWords.contains(word)) { indexedWords.add(word); fulltextIndex.add(node, indexKeyName, word); // if (indexedWords > 1000) { // indexedWords = 0; // break; // } } } tx.success(); } } // store indexed words separately try (Tx tx = StructrApp.getInstance().tx()) { // don't modify access time when indexing is finished file.getSecurityContext().preventModificationOfAccessTime(); // store indexed words file.setProperty(Indexable.indexedWords, (String[]) indexedWords.toArray(new String[indexedWords.size()])); tx.success(); } logger.log(Level.INFO, "Indexing of {0} finished, {1} words extracted", new Object[] { fileName, tokenizer.getWordCount() }); } } } catch (final Throwable t) { logger.log(Level.WARNING, "Indexing of {0} failed: {1}", new Object[] { fileName, t.getMessage() }); } }
From source file:org.structr.text.FulltextIndexingAgent.java
private void doIndexing(final Indexable file) { boolean parsingSuccessful = false; InputStream inputStream = null; String fileName = "unknown file"; try {/* ww w . j a va2 s. c om*/ try (final Tx tx = StructrApp.getInstance().tx()) { inputStream = file.getInputStream(); fileName = file.getName(); tx.success(); } if (inputStream != null) { final FulltextTokenizer tokenizer = new FulltextTokenizer(fileName); try (final InputStream is = inputStream) { final AutoDetectParser parser = new AutoDetectParser(); parser.parse(is, new BodyContentHandler(tokenizer), new Metadata()); parsingSuccessful = true; } // only do indexing when parsing was successful if (parsingSuccessful) { try (Tx tx = StructrApp.getInstance().tx()) { // don't modify access time when indexing is finished file.getSecurityContext().preventModificationOfAccessTime(); // save raw extracted text file.setProperty(Indexable.extractedContent, tokenizer.getRawText()); // tokenize name tokenizer.write(getName()); // tokenize owner name final Principal _owner = file.getProperty(owner); if (_owner != null) { final String ownerName = _owner.getName(); if (ownerName != null) { tokenizer.write(ownerName); } final String eMail = _owner.getProperty(User.eMail); if (eMail != null) { tokenizer.write(eMail); } final String twitterName = _owner.getProperty(User.twitterName); if (twitterName != null) { tokenizer.write(twitterName); } } tx.success(); } // index document excluding stop words final NodeService nodeService = Services.getInstance().getService(NodeService.class); final Index<Node> fulltextIndex = nodeService.getNodeIndex(NodeService.NodeIndex.fulltext); final Set<String> stopWords = languageStopwordMap.get(tokenizer.getLanguage()); final String indexKeyName = Indexable.indexedWords.jsonName(); final Iterator<String> wordIterator = tokenizer.getWords().iterator(); final Node node = file.getNode(); final Set<String> indexedWords = new TreeSet<>(); logger.log(Level.INFO, "Indexing {0}..", fileName); while (wordIterator.hasNext()) { try (Tx tx = StructrApp.getInstance().tx()) { // remove node from index (in case of previous indexing runs) fulltextIndex.remove(node, indexKeyName); while (wordIterator.hasNext()) { // strip double quotes final String word = StringUtils.strip(wordIterator.next(), "\""); if (!stopWords.contains(word)) { indexedWords.add(word); fulltextIndex.add(node, indexKeyName, word, String.class); // if (indexedWords > 1000) { // indexedWords = 0; // break; // } } } tx.success(); } } // store indexed words separately try (Tx tx = StructrApp.getInstance().tx()) { // don't modify access time when indexing is finished file.getSecurityContext().preventModificationOfAccessTime(); // store indexed words file.setProperty(Indexable.indexedWords, (String[]) indexedWords.toArray(new String[indexedWords.size()])); tx.success(); } logger.log(Level.INFO, "Indexing of {0} finished, {1} words extracted", new Object[] { fileName, tokenizer.getWordCount() }); } } } catch (final Throwable t) { logger.log(Level.WARNING, "Indexing of {0} failed: {1}", new Object[] { fileName, t.getMessage() }); } }
From source file:org.talend.components.netsuite.NetSuiteComponentDefinition.java
public static RuntimeInfo getRuntimeInfo(final NetSuiteProvideConnectionProperties properties, final String runtimeClassName) { NetSuiteConnectionProperties connectionProperties = properties.getConnectionProperties(); String endpointUrl = StringUtils.strip(connectionProperties.endpoint.getStringValue(), "\""); String apiVersion = detectApiVersion(endpointUrl); String artifactId = MAVEN_ARTIFACT_ID.replace("${version}", apiVersion); String className = runtimeClassName.replace("${version}", apiVersion); return new JarRuntimeInfo("mvn:" + MAVEN_GROUP_ID + "/" + artifactId, DependenciesReader.computeDependenciesFilePath(MAVEN_GROUP_ID, artifactId), className); }
From source file:org.talend.components.salesforce.connection.oauth.SalesforceJwtConnection.java
private X509Key x509Key() { return X509Key.builder()// .keyStorePath(StringUtils.strip(oauth2Prop.keyStore.getStringValue(), "\""))// .keyStorePassword(oauth2Prop.keyStorePassword.getStringValue())// .certificateAlias(oauth2Prop.certificateAlias.getStringValue())// certificate alias .build();/*from w w w . ja va 2 s . c o m*/ }
From source file:org.talend.components.salesforce.runtime.SalesforceSourceOrSink.java
protected PartnerConnection doConnection(ConnectorConfig config) throws ConnectionException { SalesforceConnectionProperties connProps = properties.getConnectionProperties(); String endpoint = connProps.endpoint.getStringValue(); endpoint = StringUtils.strip(endpoint, "\""); if (SalesforceConnectionProperties.LoginType.OAuth.equals(connProps.loginType.getValue())) { SalesforceOAuthConnection oauthConnection = new SalesforceOAuthConnection(connProps.oauth, endpoint, API_VERSION);/*from w w w .ja v a 2 s.com*/ oauthConnection.login(config); } else { config.setAuthEndpoint(endpoint); } PartnerConnection connection; connection = new PartnerConnection(config); return connection; }