List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.adobe.acs.commons.mcp.impl.processes.DataImporter.java
public void createMissingNode(String path, ResourceResolver rr, Map<String, CompositeVariant> row) throws PersistenceException { String parentPath = StringUtils.substringBeforeLast(path, "/"); Resource parent = ResourceUtil.getOrCreateResource(rr, parentPath, defaultNodeType, defaultNodeType, true); String nodeName = StringUtils.substringAfterLast(path, "/"); if (!row.containsKey(JCR_PRIMARY_TYPE)) { row.put("JCR_TYPE", new CompositeVariant(defaultNodeType)); }/* w w w . j av a 2 s. co m*/ Map<String, Object> nodeProps = new HashMap(row); rr.refresh(); rr.create(parent, nodeName, nodeProps); }
From source file:com.google.dart.tools.core.internal.builder.AnalysisMarkerManager.java
/** * @return the {@link ErrorCode} enumeration constant for string from * {@link #encodeErrorCode(ErrorCode)}. *//*from ww w .j a v a 2s .co m*/ private static ErrorCode decodeErrorCode(String encoding) { try { String className = StringUtils.substringBeforeLast(encoding, "."); String fieldName = StringUtils.substringAfterLast(encoding, "."); Class<?> errorCodeClass = Class.forName(className); return (ErrorCode) errorCodeClass.getField(fieldName).get(null); } catch (Throwable e) { return null; } }
From source file:com.thinkbiganalytics.metadata.upgrade.v080.UpgradeAction.java
private void moveNode(Session session, Node node, Node parentNode) { try {/*from w w w .j a va 2 s . c om*/ if ((node != null) && (parentNode != null)) { final String srcPath = node.getParent().getPath() + "/" + StringUtils.substringAfterLast(node.getPath(), "/"); // Path may not be accurate if parent node moved recently session.move(srcPath, parentNode.getPath() + "/" + node.getName()); } } catch (RepositoryException e) { throw new UpgradeException("Failed to moved node " + node + " under parent " + parentNode, e); } }
From source file:de.crowdcode.movmvn.plugin.general.GeneralPlugin.java
private void moveFiles() { try {// w w w . ja v a2s.c om context.logInfo("Move files..."); String projectSourceName = context.getProjectSourceName(); String projectTargetName = context.getProjectTargetName(); // Move files *.java from src -> src/main/java // Move files *.properties;*.txt;*.jpg -> src/main/resources // Move files *.java from test -> src/test/java // Move files *.properties;*.txt;*.jpg -> src/test/resources // Move files *.* from resources or resource -> src/main/resources // Move files from / to / but not .classpath, .project -> // src/main/resources // Move directory META-INF -> src/main/resources String[] extensionsJava = { "java" }; Iterator<File> fileIterator = FileUtils.iterateFiles(new File(projectSourceName + "/src"), extensionsJava, true); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); String nameResultAfterSrc = StringUtils.substringAfterLast(currentFile.getAbsolutePath(), "src\\"); nameResultAfterSrc = projectTargetName.concat("/src/main/java/").concat(nameResultAfterSrc); log.info("Target file: " + nameResultAfterSrc); File targetFile = new File(nameResultAfterSrc); FileUtils.copyFile(currentFile, targetFile, true); } // Check whether "resource" or "resources" exist? File directoryResources = new File(projectSourceName + "/resource"); File targetResourcesDir = new File(projectTargetName.concat("/src/main/resources")); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } directoryResources = new File(projectSourceName + "/resources"); if (directoryResources.exists()) { // Move the files FileUtils.copyDirectory(directoryResources, targetResourcesDir); } // META-INF File directoryMetaInf = new File(projectSourceName + "/META-INF"); if (directoryMetaInf.exists()) { FileUtils.copyDirectoryToDirectory(directoryMetaInf, targetResourcesDir); } // Directory . *.txt, *.doc*, *.png, *.jpg -> src/main/docs File targetDocsDir = new File(projectTargetName.concat("/src/main/docs")); String[] extensionsRootDir = { "txt", "doc", "docx", "png", "jpg" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetDocsDir); } // Directory . *.cmd, *.sh -> src/main/bin File targetBinDir = new File(projectTargetName.concat("/src/main/bin")); String[] extensionsRootBinDir = { "sh", "cmd", "properties" }; fileIterator = FileUtils.iterateFiles(new File(projectSourceName), extensionsRootBinDir, false); for (Iterator<File> iterator = fileIterator; iterator.hasNext();) { File currentFile = iterator.next(); log.info("File to be copied: " + currentFile.getCanonicalPath()); FileUtils.copyFileToDirectory(currentFile, targetBinDir); } } catch (IOException e) { log.info(e.getStackTrace().toString()); } }
From source file:com.gargoylesoftware.htmlunit.html.XmlSerializer.java
private String getSuffix(final WebResponse response) { // first try to take the one from the requested file final String url = response.getWebRequest().getUrl().toString(); final String fileName = StringUtils.substringAfterLast(StringUtils.substringBefore(url, "?"), "/"); // if there is a suffix with 2-4 letters, the take it final String suffix = StringUtils.substringAfterLast(fileName, "."); if (suffix.length() > 1 && suffix.length() < 5) { return suffix; }//from w w w . j a v a 2 s . c o m // use content type return MimeType.getFileExtension(response.getContentType()); }
From source file:com.inkubator.hrm.web.ImageBioDataStreamerController.java
public StreamedContent getDocumentFile() throws IOException { FacesContext context = FacesUtil.getFacesContext(); String id = context.getExternalContext().getRequestParameterMap().get("id"); if (context.getRenderResponse() || id == null) { return new DefaultStreamedContent(); } else {//from w w w . j a v a2s.co m InputStream is = null; try { BioDocument bioDocument = bioDocumentService.getEntiyByPK(Long.parseLong(id)); String path = bioDocument.getUploadPath(); if (StringUtils.isEmpty(path)) { path = facesIO.getPathUpload() + "no_image.png"; } is = facesIO.getInputStreamFromURL(path); return new DefaultStreamedContent(is, null, StringUtils.substringAfterLast(path, "/")); } catch (Exception ex) { LOGGER.error(ex, ex); return new DefaultStreamedContent(); } } }
From source file:kenh.expl.impl.ExpLParser.java
/** * Get the value in brace./*from w w w .ja v a 2s.c om*/ * $ - it will be a variable in environment. * # - will be a function * other - use sub parser * * @param variable the string in brace. * @return Return string or non-string object. Return empty string instead of null. * @throws UnsupportedExpressionException */ private Object getVariableValue(String variable) throws UnsupportedExpressionException { if (variable == null) { UnsupportedExpressionException e = new UnsupportedExpressionException("Variable is null."); throw e; } logger.trace("Var: " + variable); if (variable.startsWith("$")) { // $ - it will be a variable in environment. if (variable.indexOf('{') != -1) { Object obj = this.parseExpress(variable); if (obj instanceof String) { variable = (String) obj; } else { UnsupportedExpressionException ex = new UnsupportedExpressionException( "Unable to get variable"); ex.push(variable); throw ex; } } String name = variable.substring(1); int index = name.indexOf('.'); if (index == -1) { return this.getEnvironment().getVariable(name); } else { // use BeanUtils String str = name.substring(index + 1); name = name.substring(0, index); Object obj = null; if ((obj = this.getEnvironment().getVariable(name)) != null) { try { return BeanUtils.getProperty(obj, str); } catch (Exception e) { return ""; } } else { return ""; } } } else if (variable.startsWith("#")) { // # - will be a function int left = StringUtils.countMatches(variable, "("); int right = StringUtils.countMatches(variable, ")"); if (left != right) { UnsupportedExpressionException ex = new UnsupportedExpressionException( "'(' and ')' does not match."); ex.push(variable); throw ex; } String funcName = StringUtils.substringBefore(variable, "("); String funcAfter = StringUtils.substringAfterLast(variable, ")"); if (StringUtils.isNotBlank(funcAfter)) { UnsupportedExpressionException e = new UnsupportedExpressionException("Function parse error."); e.push(variable); throw e; } if (funcNamePattern.matcher(funcName).matches()) { Object result = executeFunction(variable); logger.debug(variable + " -> " + ((result == null) ? "<null>" : result.toString())); if (result == null) return ""; return result; } else { UnsupportedExpressionException e = new UnsupportedExpressionException("Function name parse error."); e.push(variable); throw e; } } else { if (variable.indexOf('{') != -1) { Object obj = this.parseExpress(variable); if (obj instanceof String) { variable = (String) obj; } else { UnsupportedExpressionException ex = new UnsupportedExpressionException( "Unable to get variable"); ex.push(variable); throw ex; } } // use sub parser try { return subParser.parse(variable); } catch (UnsupportedExpressionException e) { e.push(variable); throw e; } catch (Exception e) { UnsupportedExpressionException ex = new UnsupportedExpressionException(e); ex.push(variable); throw ex; } } }
From source file:gov.nih.nci.firebird.FirebirdModule.java
private void addEmailMapping(Map<String, String> emailMapping, String emailMappingString) { if (emailMappingString.contains(":")) { String sponsorExternalId = StringUtils.substringBeforeLast(emailMappingString, ":"); String sponsorEmail = StringUtils.substringAfterLast(emailMappingString, ":"); emailMapping.put(sponsorExternalId, sponsorEmail); }// w w w . j av a 2 s . c o m }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.view.EcsServerClusterProvider.java
private TaskDefinition buildTaskDefinition(com.amazonaws.services.ecs.model.TaskDefinition taskDefinition) { String roleArn = taskDefinition.getTaskRoleArn(); String iamRole = roleArn != null ? StringUtils.substringAfterLast(roleArn, "/") : "None"; ContainerDefinition containerDefinition = taskDefinition.getContainerDefinitions().get(0); return new TaskDefinition().setContainerImage(containerDefinition.getImage()) .setContainerPort(containerDefinition.getPortMappings().get(0).getContainerPort()) .setCpuUnits(containerDefinition.getCpu()) .setMemoryReservation(containerDefinition.getMemoryReservation()).setIamRole(iamRole) .setTaskName(StringUtils.substringAfterLast(taskDefinition.getTaskDefinitionArn(), "/")) .setEnvironmentVariables(containerDefinition.getEnvironment()); }
From source file:com.xpn.xwiki.plugin.image.ImagePlugin.java
/** * Transforms the given image (i.e. shrinks the image and changes its quality) before it is downloaded. * /* w w w . ja va2 s .c o m*/ * @param image the image to be downloaded * @param width the desired image width; this value is taken into account only if it is greater than zero and less * than the current image width * @param height the desired image height; this value is taken into account only if it is greater than zero and less * than the current image height * @param quality the desired compression quality * @param context the XWiki context * @return the transformed image * @throws Exception if transforming the image fails */ private XWikiAttachment downloadImage(XWikiAttachment image, int width, int height, float quality, XWikiContext context) throws Exception { if (this.imageCache == null) { initCache(context); } boolean keepAspectRatio = Boolean.valueOf(context.getRequest().getParameter("keepAspectRatio")); XWikiAttachment thumbnail = this.imageCache == null ? shrinkImage(image, width, height, keepAspectRatio, quality, context) : downloadImageFromCache(image, width, height, keepAspectRatio, quality, context); // If the image has been transformed, update the file name extension to match the image format. String fileName = thumbnail.getFilename(); String extension = StringUtils.lowerCase(StringUtils.substringAfterLast(fileName, String.valueOf('.'))); if (thumbnail != image && !Arrays.asList("jpeg", "jpg", "png").contains(extension)) { // The scaled image is PNG, so correct the extension in order to output the correct MIME type. thumbnail.setFilename(StringUtils.substringBeforeLast(fileName, ".") + ".png"); } return thumbnail; }