List of usage examples for org.apache.commons.lang StringUtils stripStart
public static String stripStart(String str, String stripChars)
Strips any of a set of characters from the start of a String.
From source file:org.apache.hive.ptest.execution.conf.UnitTestPropertiesParser.java
private String stripEndAndStart(String srcString, String stripChars) { srcString = StringUtils.stripEnd(srcString, stripChars); srcString = StringUtils.stripStart(srcString, stripChars); return srcString; }
From source file:org.apache.hive.ptest.execution.conf.UnitTestPropertiesParser.java
private String getPathPrefix(File file, String subDirPrefix) throws IOException { String fname = file.getCanonicalPath(); Preconditions.checkState(fname.startsWith(sourceDirectory.getCanonicalPath())); fname = fname.substring(sourceDirectory.getCanonicalPath().length(), fname.length()); if (fname.contains(subDirPrefix)) { fname = fname.substring(0, fname.indexOf(subDirPrefix)); fname = StringUtils.stripStart(fname, "/"); if (StringUtils.isEmpty(fname)) { fname = PREFIX_TOP_LEVEL;/*w ww . j a v a 2 s . com*/ } return fname; } else { logger.error("Could not find subDirPrefix {} in path: {}", subDirPrefix, fname); return PREFIX_TOP_LEVEL; } }
From source file:org.apache.ivory.entity.FeedHelper.java
public static String normalizePartitionExpression(String part1, String part2) { String partExp = StringUtils.stripToEmpty(part1) + "/" + StringUtils.stripToEmpty(part2); partExp = partExp.replaceAll("//+", "/"); partExp = StringUtils.stripStart(partExp, "/"); partExp = StringUtils.stripEnd(partExp, "/"); return partExp; }
From source file:org.apache.shindig.gadgets.parse.CompactHtmlSerializer.java
/** * Collapse any consecutive HTML whitespace characters inside a string into * one space character (0x20). This method will not output any characters when * the given string is entirely composed of whitespaces. * * References://from w ww. j a v a2 s . com * <ul> * <li>http://www.w3.org/TR/html401/struct/text.html#h-9.1</li> * <li>http://java.sun.com/javase/6/docs/api/java/lang/Character.html#isWhitespace(char)</li> * </ul> */ static void collapseWhitespace(String str, Appendable output) throws IOException { str = StringUtils.stripStart(str, HTML_WHITESPACE); // Whitespaces between a sequence of non-whitespace characters boolean seenWhitespace = false; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (HTML_WHITESPACE.indexOf(c) != -1) { seenWhitespace = true; } else { if (seenWhitespace) { output.append(' '); } output.append(c); seenWhitespace = false; } } }
From source file:org.apache.struts.maven.snippetextractor.parser.java.CommentParser.java
/** * Remove the java comment start pattern {@value #JAVA_COMMENT_START_STRING} from the start of * provided string. Whitespaces at the start are removed. If the java comment is a javadoc start, the second * asterisk is also removed. If no pattern is found the string is returned unchanged. * * @param string {@link String} which is to be stripped from the java comment start. * @return {@link String} without java comment or javadoc start or the unchanged string *///from w w w . j av a 2 s.c om public static String removeCommentStart(String string) { String result = StringUtils.stripStart(string, " \t"); if (!result.startsWith(CommentParser.JAVA_COMMENT_START_STRING)) { return string; } result = StringUtils.removeStart(result, CommentParser.JAVA_COMMENT_START_STRING); if (result.startsWith("*")) { result = result.substring(1); } return result; }
From source file:org.apache.struts.maven.snippetextractor.parser.java.CommentParser.java
/** * Remove the asterisk every javadoc line starts with. All whitespaces before the asterisk will be removed. If no * asterisk is found the string is returned unchanged. * * @param string {@link String} to be stripped from javadoc asterisks * @return {@link String} without the javadoc start asterisk or the unchanged provided string *///from w w w. ja v a2s. com public static String removeJavadocAsterisk(String string) { String stripped = StringUtils.stripStart(string, " \t"); if (stripped.startsWith("*")) { return stripped.substring(1, stripped.length()); } return string; }
From source file:org.apache.tajo.engine.function.string.LTrim.java
@Override public Datum eval(Tuple params) { if (params.isBlankOrNull(0)) { return NullDatum.get(); }/*from ww w . j a v a2 s .c o m*/ String input = params.getText(0); if (!hasTrimCharacters) { return DatumFactory.createText(StringUtils.stripStart(input, null)); } else { return DatumFactory.createText(StringUtils.stripStart(input, params.getText(1))); } }
From source file:org.apache.wookie.w3c.util.NumberUtils.java
public static int processNonNegativeInteger(String in) throws NumberFormatException { int result = 0; in = UnicodeUtils.normalizeSpaces(in); StringUtils.stripStart(in, ""); if (in.length() == 0) throw new NumberFormatException("no non-space characters"); for (int pos = 0; pos < in.length(); pos++) { String nextchar = in.substring(pos, pos + 1); // If the nextchar is not one of U+0030 (0) .. U+0039 (9), then return result. try {// w ww . ja v a 2s . com int i = Integer.parseInt(nextchar); result = result * 10 + i; } catch (Exception e) { return result; } } return result; }
From source file:org.candlepin.util.X509Util.java
/** * Creates a Content URL from the prefix and the path * @param contentPrefix to prepend to the path * @param pc the product content/*from w ww .ja v a2s . co m*/ * @return the complete content path */ public String createFullContentPath(String contentPrefix, ProductContent pc) { String prefix = "/"; String contentPath = pc.getContent().getContentUrl(); // Allow for the case where the content URL is a true URL. // If that is true, then return it as is. if (contentPath != null && (contentPath.startsWith("http://") || contentPath.startsWith("file://") || contentPath.startsWith("https://") || contentPath.startsWith("ftp://"))) { return contentPath; } if (!StringUtils.isEmpty(contentPrefix)) { // Ensure there is no double // in the URL. See BZ952735 // remove them all except one. prefix = StringUtils.stripEnd(contentPrefix, "/") + prefix; } contentPath = StringUtils.stripStart(contentPath, "/"); return prefix + contentPath; }
From source file:org.codehaus.mojo.mrm.impl.maven.MemoryArtifactStore.java
/** * {@inheritDoc}/* www . ja v a2 s .c o m*/ */ public synchronized Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Metadata metadata = new Metadata(); boolean foundMetadata = false; path = StringUtils.stripEnd(StringUtils.stripStart(path, "/"), "/"); String groupId = path.replace('/', '.'); Set pluginArtifactIds = getArtifactIds(groupId); if (pluginArtifactIds != null) { List plugins = new ArrayList(); for (Iterator i = pluginArtifactIds.iterator(); i.hasNext();) { String artifactId = (String) i.next(); Set pluginVersions = getVersions(groupId, artifactId); if (pluginVersions == null || pluginVersions.isEmpty()) { continue; } String[] versions = (String[]) pluginVersions.toArray(new String[pluginVersions.size()]); Arrays.sort(versions, new VersionComparator()); MavenXpp3Reader reader = new MavenXpp3Reader(); for (int j = versions.length - 1; j >= 0; j--) { InputStream inputStream = null; try { inputStream = get(new Artifact(groupId, artifactId, versions[j], "pom")); Model model = reader.read(new XmlStreamReader(inputStream)); if (model == null || !"maven-plugin".equals(model.getPackaging())) { continue; } Plugin plugin = new Plugin(); plugin.setArtifactId(artifactId); plugin.setName(model.getName()); // TODO proper goal-prefix determination // ugh! this is incredibly hacky and does not handle some fool that sets the goal prefix in // a parent pom... ok unlikely, but stupid is as stupid does boolean havePrefix = false; final Build build = model.getBuild(); if (build != null && build.getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPlugins()); } if (!havePrefix && build != null && build.getPluginManagement() != null && build.getPluginManagement().getPlugins() != null) { havePrefix = setPluginGoalPrefixFromConfiguration(plugin, build.getPluginManagement().getPlugins()); } if (!havePrefix && artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { plugin.setPrefix(StringUtils.removeStart(StringUtils.removeEnd(artifactId, "-plugin"), "maven-")); havePrefix = true; } if (!havePrefix && artifactId.endsWith("-maven-plugin")) { plugin.setPrefix(StringUtils.removeEnd(artifactId, "-maven-plugin")); havePrefix = true; } if (!havePrefix) { plugin.setPrefix(artifactId); } plugins.add(plugin); foundMetadata = true; break; } catch (ArtifactNotFoundException e) { // ignore } catch (XmlPullParserException e) { // ignore } finally { IOUtils.closeQuietly(inputStream); } } } if (!plugins.isEmpty()) { metadata.setPlugins(plugins); } } int index = path.lastIndexOf('/'); groupId = (index == -1 ? groupId : groupId.substring(0, index)).replace('/', '.'); String artifactId = (index == -1 ? null : path.substring(index + 1)); if (artifactId != null) { Set artifactVersions = getVersions(groupId, artifactId); if (artifactVersions != null && !artifactVersions.isEmpty()) { metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); Versioning versioning = new Versioning(); List versions = new ArrayList(artifactVersions); Collections.sort(versions, new VersionComparator()); // sort the Maven way long lastUpdated = 0; for (Iterator i = versions.iterator(); i.hasNext();) { String version = (String) i.next(); try { long lastModified = getLastModified(new Artifact(groupId, artifactId, version, "pom")); versioning.addVersion(version); if (lastModified >= lastUpdated) { lastUpdated = lastModified; versioning.setLastUpdatedTimestamp(new Date(lastModified)); versioning.setLatest(version); if (!version.endsWith("-SNAPSHOT")) { versioning.setRelease(version); } } } catch (ArtifactNotFoundException e) { // ignore } } metadata.setVersioning(versioning); foundMetadata = true; } } int index2 = index == -1 ? -1 : path.lastIndexOf('/', index - 1); groupId = index2 == -1 ? groupId : groupId.substring(0, index2).replace('/', '.'); artifactId = index2 == -1 ? artifactId : path.substring(index2 + 1, index); String version = index2 == -1 ? null : path.substring(index + 1); if (version != null && version.endsWith("-SNAPSHOT")) { Map artifactMap = (Map) contents.get(groupId); Map versionMap = (Map) (artifactMap == null ? null : artifactMap.get(artifactId)); Map filesMap = (Map) (versionMap == null ? null : versionMap.get(version)); if (filesMap != null) { List snapshotVersions = new ArrayList(); int maxBuildNumber = 0; long lastUpdated = 0; String timestamp = null; boolean found = false; for (Iterator i = filesMap.entrySet().iterator(); i.hasNext();) { final Map.Entry entry = (Map.Entry) i.next(); final Artifact artifact = (Artifact) entry.getKey(); final Content content = (Content) entry.getValue(); SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String lastUpdatedTime = fmt.format(new Date(content.getLastModified())); try { Maven3.addSnapshotVersion(snapshotVersions, artifact, lastUpdatedTime); } catch (LinkageError e) { // Maven 2 } if ("pom".equals(artifact.getType())) { if (artifact.getBuildNumber() != null && maxBuildNumber < artifact.getBuildNumber().intValue()) { maxBuildNumber = artifact.getBuildNumber().intValue(); timestamp = artifact.getTimestampString(); } else { maxBuildNumber = Math.max(1, maxBuildNumber); } lastUpdated = Math.max(lastUpdated, content.getLastModified()); found = true; } } if (!snapshotVersions.isEmpty() || found) { Versioning versioning = metadata.getVersioning(); if (versioning == null) { versioning = new Versioning(); } metadata.setGroupId(groupId); metadata.setArtifactId(artifactId); metadata.setVersion(version); try { Maven3.addSnapshotVersions(versioning, snapshotVersions); } catch (LinkageError e) { // Maven 2 } if (maxBuildNumber > 0) { Snapshot snapshot = new Snapshot(); snapshot.setBuildNumber(maxBuildNumber); snapshot.setTimestamp(timestamp); versioning.setSnapshot(snapshot); } versioning.setLastUpdatedTimestamp(new Date(lastUpdated)); metadata.setVersioning(versioning); foundMetadata = true; } } } if (!foundMetadata) { throw new MetadataNotFoundException(path); } return metadata; }