List of usage examples for org.apache.commons.lang3 StringUtils removeStart
public static String removeStart(final String str, final String remove)
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {/* ww w .j a va 2s .com*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:io.wcm.devops.conga.resource.AbstractClasspathResourceImpl.java
protected static String convertPath(String path) { return StringUtils.replace(StringUtils.removeStart(path, "/"), "\\", "/"); }
From source file:com.github.riccardove.easyjasub.commons.CommonsLangStringUtils.java
public static String removeStart(String str, String remove) { return StringUtils.removeStart(str, remove); }
From source file:net.lmxm.ute.utils.PathUtils.java
/** * Builds the full path.// w w w. ja va 2 s .c o m * * @param rootPath the root path * @param relativePath the relative path * @return the string */ public static String buildFullPath(final String rootPath, final String relativePath) { final String prefix = "buildFullPath() :"; LOGGER.debug("{} entered, root={}, relativepath=" + relativePath, prefix, rootPath); final String root = StringUtils.removeEnd(StringUtils.trimToEmpty(rootPath), "/"); final String relative = StringUtils.removeStart(StringUtils.trimToEmpty(relativePath), "/"); String fullPath; if (StringUtils.isBlank(relative)) { fullPath = root; } else { fullPath = StringUtils.join(new Object[] { root, "/", relative }); } LOGGER.debug("{} returning {}", prefix, fullPath); return fullPath; }
From source file:com.aqnote.app.wifianalyzer.wifi.model.WiFiUtils.java
public static String convertSSID(@NonNull String SSID) { return StringUtils.removeEnd(StringUtils.removeStart(SSID, QUOTE), QUOTE); }
From source file:com.technophobia.substeps.model.Util.java
public static String[] getArgs(final String patternString, final String sourceString, final String[] keywordPrecedence) { log.debug("Util getArgs String[] with pattern: " + patternString + " and sourceStr: " + sourceString); String[] rtn = null;//w ww . j a va 2s .co m ArrayList<String> argsList = null; String patternCopy = new String(patternString); if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) { // for (String s : keywordPrecedence) { patternCopy = StringUtils.removeStart(patternCopy, s); } patternCopy = "(?:" + StringUtils.join(keywordPrecedence, "|") + ")" + patternCopy; } final Pattern pattern = Pattern.compile(patternCopy); final Matcher matcher = pattern.matcher(sourceString); final int groupCount = matcher.groupCount(); // TODO - this doesn't work if we're not doing strict matching if (matcher.find()) { for (int i = 1; i <= groupCount; i++) { final String arg = matcher.group(i); if (arg != null) { if (argsList == null) { argsList = new ArrayList<String>(); } argsList.add(arg); } } } if (argsList != null) { rtn = argsList.toArray(new String[argsList.size()]); if (log.isDebugEnabled()) { final StringBuilder buf = new StringBuilder(); buf.append("returning args: "); for (final String s : argsList) { buf.append("[").append(s).append("] "); } log.debug(buf.toString()); } } return rtn; }
From source file:com.cognifide.aet.job.common.comparators.w3chtml5.WarningNodeToW3cHtml5IssueFunction.java
@Override public W3cHtml5Issue apply(Node child) { if (!(child instanceof Element)) { return null; }//from ww w . ja v a 2s . c o m Element element = (Element) child; W3cHtml5IssueType issueType = W3cHtml5IssueType .valueOf(StringUtils.removeStart(element.attr("class"), "msg_").toUpperCase()); String message = element.getElementsByAttributeValue("class", "msg").html(); String additionalInfo = element.child(1).html(); return new W3cHtml5Issue(0, 0, message, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, additionalInfo, issueType); }
From source file:actions.support.PathParser.java
public PathParser(String contextPath, String path) { String contextRemovedPath = StringUtils.removeStart(path, contextPath); this.pathSegments = StringUtils.split(contextRemovedPath, DELIM); }
From source file:ch.cyberduck.core.local.TildeExpander.java
public String abbreviate(final String name) { if (StringUtils.startsWith(name, preferences.getProperty("local.user.home"))) { return Local.HOME + StringUtils.removeStart(name, preferences.getProperty("local.user.home")); }//from www . j a v a 2s .c o m return name; }
From source file:com.ewcms.publication.freemarker.loader.DatabaseTemplateLoader.java
@Override public Object findTemplateSource(String name) throws IOException { Assert.notNull(name, "template uniquepath is null"); String path = StringUtils.removeStart(name, "/"); TemplateBody body = templatePublishDao.findBody(path); if (body == null) { logger.debug("{} is not exist.", path); return null; }//from w w w .ja v a2s . c o m byte[] content = body.getBody(); long lastTime = System.currentTimeMillis(); return new TemplateSource(path, content, lastTime); }