List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:com.cognifide.slice.core.internal.injector.InjectorsRepositoryService.java
@Override public String getInjectorNameForResource(final String resourcePath) { String injectorName = null;/* w w w. j av a 2 s.com*/ String iteratedPath = getIteratedPath(resourcePath); while (!iteratedPath.isEmpty()) { injectorName = injectors.getInjectorNameByApplicationPath(iteratedPath); if (injectorName != null) { break; } iteratedPath = StringUtils.substringBeforeLast(iteratedPath, "/"); } return injectorName; }
From source file:com.adobe.acs.commons.util.impl.GraphicIconSelectionDialogRewriteRule.java
@Override public Node applyTo(final Node root, final Set<Node> finalNodes) throws DialogRewriteException, RepositoryException { final Node parent = root.getParent(); final String name = root.getName(); DialogRewriteUtils.rename(root);//from www . ja v a 2 s . c om // add node for multifield final Node newRoot = parent.addNode(name, JcrConstants.NT_UNSTRUCTURED); finalNodes.add(newRoot); for (final String propertyName : PROPERTIES_TO_COPY) { DialogRewriteUtils.copyProperty(root, propertyName, newRoot, propertyName); } newRoot.setProperty(PN_SLING_RESOURCE_TYPE, "acs-commons/components/authoring/graphiciconselect"); if (root.hasProperty(PN_OPTIONS)) { final String options = root.getProperty(PN_OPTIONS).getString(); if (options.startsWith("/etc/acs-commons/lists")) { final Node dataSource = newRoot.addNode("datasource", JcrConstants.NT_UNSTRUCTURED); dataSource.setProperty(PN_SLING_RESOURCE_TYPE, "acs-commons/components/utilities/genericlist/datasource"); // assuming the options property is something like /etc/acs-commons/lists/font-awesome-icons/_jcr_content.list.json, we want /etc/acs-commons/lists/font-awesome-icons dataSource.setProperty("path", StringUtils.substringBeforeLast(options, "/")); } } root.remove(); return newRoot; }
From source file:info.magnolia.module.delta.BootstrapConditionally.java
private static String cleanupFilename(String filename) { filename = StringUtils.replace(filename, "\\", "/"); filename = StringUtils.substringAfterLast(filename, "/"); filename = StringUtils.substringBeforeLast(filename, "."); return StringUtils.removeEnd(filename, DataTransporter.XML); }
From source file:ips1ap101.lib.base.BaseBundle.java
public static String getOpcionOrdenFuncionReport(String key) { String string = getString(key, OPCION_ORDEN_FUNCION_REPORT); if (string == null) { String dominio = StringUtils.substringBeforeLast(key, "."); if (key.equals(dominio)) { } else {// w w w .j a va 2 s . co m string = getString(dominio, OPCION_ORDEN_FUNCION_REPORT); } } if (string == null) { string = getString(DEFAULT, OPCION_ORDEN_FUNCION_REPORT); } return string; }
From source file:com.microsoft.alm.plugin.idea.git.ui.pullrequest.PullRequestHelper.java
/** * Create a default title for pull request * <p/>/*from w w w . j a v a2 s . co m*/ * If there is only one commit, use its subject; otherwise use a standard template * "Merge source to target". * <p/> * Default titles will be less than 120 chars. * * @return default title */ public String createDefaultTitle(final List<GitCommit> commits, final String sourceBranchName, final String targetBranchName) { if (commits == null || commits.isEmpty()) { return StringUtils.EMPTY; } if (commits.size() == 1) { // if we only have one commit, use it's title as the title of pull request final GitCommit commit = commits.get(0); final String commitMessage = commit.getSubject(); //WebAcess use 80 (because it's common code for many things, and 80 is such a magic number), //but IMHO 80 is too short for title, set it to 120 final int titleLength = 120; if (commitMessage.length() < titleLength) { return commitMessage; } else { // break at last whitespace right before length 120 final String shortCommitMessage = commitMessage.substring(0, titleLength); return StringUtils.substringBeforeLast(shortCommitMessage, "\\s+"); } } // Standard title "merging source branch to target branch" return TfPluginBundle.message(TfPluginBundle.KEY_CREATE_PR_DEFAULT_TITLE, sourceBranchName, targetBranchName); }
From source file:com.alibaba.otter.manager.biz.monitor.impl.PipelineTimeoutRuleMonitor.java
private boolean checkTimeout(AlarmRule rule, long elapsed) { if (!inPeriod(rule)) { return false; }/*from w w w .ja v a 2 s . c o m*/ String matchValue = rule.getMatchValue(); matchValue = StringUtils.substringBeforeLast(matchValue, "@"); Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue)); // sinceLastSync maxSpentTime if (elapsed >= (maxSpentTime * 1000)) { sendAlarm(rule, String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), (elapsed / 1000))); return true; } return false; }
From source file:com.echosource.ada.core.AdaFile.java
/** * Returns a AdaFile if the given file is a php file and can be found in the given directories. This instance will be initialized with * inferred attribute values/*from w w w . j av a2s .c o m*/ * * @param file * the file to load * @param isUnitTest * if <code>true</code> the given resource will be marked as a unit test, otherwise it will be marked has a class * @param dirs * the dirs * @return the php file */ public static AdaFile fromIOFile(File file, List<File> dirs, boolean isUnitTest) { // If the file has a valid suffix if (file == null || !Ada.INSTANCE.hasValidSuffixes(file.getName())) { return null; } String relativePath = DefaultProjectFileSystem.getRelativePath(file, dirs); // and can be found in the given directories if (relativePath != null) { String packageName = null; String className = relativePath; if (relativePath.indexOf('/') >= 0) { packageName = StringUtils.substringBeforeLast(relativePath, PATH_SEPARATOR); packageName = StringUtils.replace(packageName, PATH_SEPARATOR, PACKAGE_SEPARATOR); className = StringUtils.substringAfterLast(relativePath, PATH_SEPARATOR); } String extension = PACKAGE_SEPARATOR + StringUtils.substringAfterLast(className, PACKAGE_SEPARATOR); // className = StringUtils.substringBeforeLast(className, PACKAGE_SEPARATOR); return new AdaFile(packageName, className, extension, isUnitTest); } return null; }
From source file:com.thalesgroup.sonar.plugins.tusar.TUSARResource.java
/** * File in project. Key is the path relative to project source directories. It is not the absolute path * and it does not include the path to source directories. Example : <code>new File("org/sonar/foo.sql")</code>. The * absolute path may be c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir * is src/main/sql./* w ww.j av a2 s . c o m*/ */ public TUSARResource(String key, boolean unitTest) { if (key == null) { throw new IllegalArgumentException("File key is null"); } String realKey = parseKey(key); if (realKey != null && realKey.indexOf(Directory.SEPARATOR) >= 0) { this.directoryKey = Directory.parseKey(StringUtils.substringBeforeLast(key, Directory.SEPARATOR)); this.filename = StringUtils.substringAfterLast(realKey, Directory.SEPARATOR); realKey = new StringBuilder().append(this.directoryKey).append(Directory.SEPARATOR).append(filename) .toString(); } else { this.filename = key; } setKey(realKey); this.unitTest = unitTest; }
From source file:com.bsb.cms.commons.template.freemarker.SpringFreemarkerGenerator.java
@Override public void createFile(String ftlTemplateFile, Map<String, Object> dataMap, String filePath) throws TemplateRuntimeException { Writer out = null;//from w ww .j av a 2 s. c o m try { String htmlText = FreeMarkerTemplateUtils .processTemplateIntoString(configuration.getTemplate(ftlTemplateFile), dataMap); filePath = filePath.replace("\\", "/"); filePath = filePath.replace("//", "/"); String savePath = StringUtils.substringBeforeLast(filePath, "/"); File file = new File(savePath); if (!file.exists()) { file.mkdirs(); } out = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"); out.write(htmlText); } catch (IOException e) { log.error(e.getMessage()); throw new TemplateRuntimeException(e.getMessage()); } catch (TemplateException e) { log.error(e.getMessage()); throw new TemplateRuntimeException(e.getMessage()); } finally { if (out != null) { try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.alibaba.otter.manager.biz.monitor.impl.ProcessTimeoutRuleMonitor.java
private String checkTimeout(AlarmRule rule, Map<Long, Long> processTime) { if (!inPeriod(rule)) { return StringUtils.EMPTY; }//from w w w .jav a 2s . c o m String matchValue = rule.getMatchValue(); matchValue = StringUtils.substringBeforeLast(matchValue, "@"); Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue)); List<Long> timeoutProcessIds = new LinkedList<Long>(); Collections.sort(timeoutProcessIds); long maxSpent = 0; for (Entry<Long, Long> entry : processTime.entrySet()) { // maxSpentTime processTimevalue if (entry.getValue() >= (maxSpentTime * 1000)) { timeoutProcessIds.add(entry.getKey()); maxSpent = maxSpent > entry.getValue() ? maxSpent : entry.getValue(); } } if (CollectionUtils.isEmpty(timeoutProcessIds)) { return StringUtils.EMPTY; } String processIds = StringUtils.join(timeoutProcessIds, ","); String message = String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), processIds, (maxSpent / 1000)); sendAlarm(rule, message); return message; }