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:com.joyent.manta.client.crypto.SupportedHmacsLookupMap.java
/** * Finds the HMAC implementation name based on the passed object. * * @param hmac instance to find name for * @return the name of implementation used by the SDK *///from www . j a v a 2 s . c o m public static String hmacNameFromInstance(final HMac hmac) { Validate.notNull(hmac, "HMAC instance must not be null"); final String digestName = hmac.getUnderlyingDigest().getAlgorithmName(); return "Hmac" + StringUtils.strip(digestName, "-"); }
From source file:forge.util.storage.StorageReaderFileSections.java
@Override public Map<String, T> readAll() { final Map<String, T> result = createMap(); int idx = 0;//from www .j a va 2s . c om Iterable<String> contents = FileUtil.readFile(file); List<String> accumulator = new ArrayList<String>(); String header = null; for (final String s : contents) { if (!lineContainsObject(s)) { continue; } if (s.charAt(0) == '[') { if (header != null) { // read previously collected item T item = readItem(header, accumulator, idx); if (item != null) { result.put(keySelector.apply(item), item); idx++; } } header = StringUtils.strip(s, "[] "); accumulator.clear(); } else { accumulator.add(s); } } // store the last item if (!accumulator.isEmpty()) { T item = readItem(header, accumulator, idx); if (item != null) { String newKey = keySelector.apply(item); if (result.containsKey(newKey)) System.err.println("StorageReader: Overwriting an object with key " + newKey); result.put(newKey, item); } } return result; }
From source file:com.twosigma.beakerx.mimetype.MIMEContainer.java
public static MIMEContainer Math(String data) { data = StringUtils.strip(data, "$"); return addMimeType(MIME.TEXT_LATEX, "$$" + data + "$$"); }
From source file:io.stallion.utils.Encrypter.java
public static String encryptString(String password, String value) { String salt = KeyGenerators.string().generateKey(); SecretKeySpec skeySpec = makeKeySpec(password, salt); byte[] iv = KeyGenerators.secureRandom(16).generateKey(); String ivString = Hex.encodeHexString(iv); try {//from w w w. j a v a2 s . co m Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new GCMParameterSpec(128, iv)); /* Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(iv)); */ byte[] encrypted = cipher.doFinal(value.getBytes(Charset.forName("UTF-8"))); String s = StringUtils.strip(new Base32().encodeAsString(encrypted), "=").toLowerCase(); // Strip line breaks s = salt + ivString + s.replaceAll("(\\n|\\r)", ""); return s; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.stallion.plugins.flatBlog.contacts.NotificationEmailer.java
private void build() { int totalCount = 0; String siteName = Settings.instance().getSiteName(); if (siteName.length() > 25) { try {/* w ww .j av a 2 s . c om*/ siteName = new URL(Settings.instance().getSiteUrl()).getHost(); } catch (MalformedURLException e) { throw new RuntimeException(e); } } Map<String, Integer> counts = map(); Map<String, String> singleToPlural = map(); for (NotificationCallbackResult result : results) { counts.put(result.getThing(), counts.getOrDefault(result.getThing(), 0) + 1); singleToPlural.put(result.getThing(), result.getThingPlural()); } StringBuffer subjectBuilder = new StringBuffer(); if (results.size() > 1) { subjectBuilder.append(results.size() + " updates from \"" + siteName + "\": "); } else { subjectBuilder.append("Update from \"" + siteName + "\": "); } for (Map.Entry<String, Integer> entry : counts.entrySet()) { if (entry.getValue() > 1) { subjectBuilder.append(entry.getValue() + " " + singleToPlural.get(entry.getKey())); } else { subjectBuilder.append("1 " + entry.getKey()); } subjectBuilder.append(", "); } subject = subjectBuilder.toString(); subject = StringUtils.strip(StringUtils.strip(subject, " "), ","); }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingProvider.java
@DataBoundSetter public void setBroker(String broker) { this.broker = StringUtils.strip(StringUtils.stripToNull(broker), "/"); }
From source file:com.rabidgremlin.legalbeagle.maven.MavenJarIdentifier.java
public void identifyFiles(Report report) throws Exception { for (ReportItem reportItem : report.getReportItems()) { File f = reportItem.getFile(); String fileHash = DigestUtils.sha1Hex(new FileInputStream(f)); try {/*from w w w . ja v a2 s .co m*/ log.info("Processing {}...", f.getAbsoluteFile()); Model mod = httpHelper.getPom(fileHash); if (mod != null) { reportItem.setReportItemStatus(ReportItemStatus.IDENTIFIED); reportItem.setDescription(mod.getName()); List<License> licenses = getLicense(httpHelper, mod); if (licenses != null) { for (License license : licenses) { // some names have spaces and CR or LF in them String licenseStr = license.getName().trim(); licenseStr = StringUtils.strip(licenseStr, "\n\r"); reportItem.addLicense(licenseStr); } } else { reportItem.setReportItemStatus(ReportItemStatus.NO_LICENSE_FOUND); } } else { reportItem.setReportItemStatus(ReportItemStatus.NOT_IDENTIFIED); } } catch (Exception e) { reportItem.setReportItemStatus(ReportItemStatus.ERR); reportItem.setError(e.getMessage()); } } }
From source file:com.github.rutledgepaulv.qbuilders.structures.FieldPath.java
private static String strip(String value) { return StringUtils.strip(value, "."); }
From source file:com.greenpepper.maven.runner.resolver.CoordinatesResolver.java
private MavenGAV resolveCoordinates(String value) { Matcher matcher = coordinatesPattern.matcher(value); if (matcher.matches()) { String groupId = matcher.group(1); String artifactId = matcher.group(2); String packaging = StringUtils.strip(matcher.group(3), ":"); String classifier = StringUtils.strip(matcher.group(4), ":"); String version = matcher.group(5); mavenGAV = new MavenGAV(groupId, artifactId, version); mavenGAV.setPackaging(packaging); mavenGAV.setClassifier(classifier); logger.info(String.format("Using maven coordinates '%s' as project", mavenGAV)); return mavenGAV; }// w ww .j a v a 2s . c o m throw new IllegalArgumentException("The value is not resolveable by the pattern: " + REGEX); }
From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java
/** * Returns the {@link Action} which is mapped to the given URI and located in the given package or a subpackage. * See {@link Context#getAction(String)} for more information. * * @param actionBasePackage The name of the package the action class must be located in somehow (subpackages are allowed). * For example, the URI {@code /some/test} and the package {@code com.quartercode.femtowebtest.actions} would result in the * class name {@code com.quartercode.femtowebtest.actions.some.TestAction}. * @param uri The URI whose mapped action class should be returned. * @return The action class which is mapped to the given URI. * @throws ActionNotFoundException If no action class is mapped to the given URI. *//*from w w w. j a v a 2s .co m*/ @SuppressWarnings("unchecked") public static Class<? extends Action> getAction(String actionBasePackage, String uri) throws ActionNotFoundException { // Remove any "/" from the start and the end of the URI String trimmedUri = StringUtils.strip(uri, "/"); // Replace all "/" with ".", add the action base package to the front, capitalize the last URI part, append "Action" to the last URI part // Example: "/path/to/someTest" -> "path.to.SomeTest") String[] uriComponents = splitAtLastSeparator(trimmedUri, "/"); String actionFQCNPackage = uriComponents[0].replace('/', '.'); String actionFQCNName = StringUtils.capitalize(uriComponents[1]) + "Action"; String actionFQCN = joinNonBlankItems(".", actionBasePackage, actionFQCNPackage, actionFQCNName); try { Class<?> c = Class.forName(actionFQCN); if (!Action.class.isAssignableFrom(c) || c.isAnnotationPresent(IgnoreAction.class)) { throw new ActionNotFoundException(uri, actionFQCN); } else { return (Class<? extends Action>) c; } } catch (ClassNotFoundException e) { throw new ActionNotFoundException(e, uri, actionFQCN); } }