List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:de.vandermeer.skb.datatool.commons.DataSet.java
/** * Returns the path common to all files in the given file list. * The rest (after this common path) will be used for auto-key-generation * @param fsl list of data files/* www .j a v a 2s.com*/ * @return common path of all files in the list */ String calcCommonPath(List<FileSource> fsl) { //get shortest absolute path, everything else is part of the key Set<String> paths = new HashSet<>(); for (FileSource fs : fsl) { paths.add(fs.getAbsolutePath()); } String ret = StringUtils.getCommonPrefix(paths.toArray(new String[] {})); if (ret.endsWith(File.separator)) { ret = StringUtils.substringBeforeLast(ret, File.separator); } return ret; }
From source file:com.hibo.bas.fileplugin.file.FtpPlugin.java
@Override public void upload(String path, File file, String contentType) { Map<String, String> ftpInfo = getFtpInfo(contentType); if (!"".equals(ftpInfo.get("host")) && !"".equals(ftpInfo.get("username")) && !"".equals(ftpInfo.get("password"))) { FTPClient ftpClient = new FTPClient(); InputStream inputStream = null; try {/*from w w w .j av a2 s.co m*/ inputStream = new FileInputStream(file); ftpClient.connect(ftpInfo.get("host"), 21); ftpClient.login(ftpInfo.get("username"), ftpInfo.get("password")); ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); path = ftpInfo.get("path") + path; if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { String directory = StringUtils.substringBeforeLast(path, "/"); String filename = StringUtils.substringAfterLast(path, "/"); if (!ftpClient.changeWorkingDirectory(directory)) { String[] paths = StringUtils.split(directory, "/"); String p = "/"; ftpClient.changeWorkingDirectory(p); for (String s : paths) { p += s + "/"; if (!ftpClient.changeWorkingDirectory(p)) { ftpClient.makeDirectory(s); ftpClient.changeWorkingDirectory(p); } } } ftpClient.storeFile(filename, inputStream); ftpClient.logout(); } } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); if (ftpClient.isConnected()) { try { ftpClient.disconnect(); } catch (IOException e) { } } } } }
From source file:com.zht.common.codegen.excute.impl.JSPGeneratorImplNew.java
@Override public void genjsp_add(String entityFullClassName, String controllerNameSpace, GenEntity genEntity, List<GenEntityProperty> genEntityPropertyList) { JSPModelNew jSPModel = new JSPModelNew(); //??/*from w ww .ja v a 2s . c om*/ String entitySimpleClassName = StringUtils.substringAfterLast(entityFullClassName, "."); // String str = StringUtils.substringBeforeLast(entityFullClassName, "."); str = StringUtils.substringBeforeLast(str, "."); String firstLower = ZStrUtil.toLowerCaseFirst(entitySimpleClassName); jSPModel.setControllerNameSpace(controllerNameSpace); jSPModel.setEntityFullClassName(entityFullClassName); jSPModel.setEntitySimpleClassName(entitySimpleClassName); jSPModel.setGenEntity(genEntity); jSPModel.setGenEntityPropertyList(genEntityPropertyList); Map<String, Object> data = new HashMap<String, Object>(); data.put("model", jSPModel); String filePath = new String(GenConstant.project_path + "WebRoot/WEB-INF/jsp/" + controllerNameSpace + "/" + firstLower + "Add.jsp"); super.generate(GenConstant.jsp_add_template_dir, data, filePath); }
From source file:net.gplatform.sudoor.server.security.model.DefaultPermissionEvaluator.java
/** * Find the expression string recursively from the config file * //from w w w . j a va2 s .com * @param name * @param permission * @return */ public String getExpressionString(String name, Object permission) { String expression = properties.getProperty(CONFIG_EXPRESSION_PREFIX + name + "." + permission); //Get generic permit if (expression == null) { expression = properties.getProperty(CONFIG_EXPRESSION_PREFIX + name); } //Get parent permit if (expression == null && StringUtils.contains(name, ".")) { String parent = StringUtils.substringBeforeLast(name, "."); expression = getExpressionString(parent, permission); } LOG.debug("Get Expression String: [{}] for name: [{}] permission: [{}]", expression, name, permission); return expression; }
From source file:de.jfachwert.net.EMailAdresse.java
/** * Als Local Part wird der Teil einer E-Mail-Adresse bezeichnet, der die * Adresse innerhalb der Domain des E-Mail-Providers eindeutig bezeichnet. * Typischerweise entspricht der Lokalteil dem Benutzernamen (haeufig ein * Pseudonym) des Besitzers des E-Mail-Kontos. * * @return z.B. "Max.Mustermann"/*from w w w .ja v a2 s .c o m*/ */ public String getLocalPart() { return StringUtils.substringBeforeLast(this.getCode(), "@"); }
From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java
@Test public void checkName() { Class<?> bukkitEvent = eventImpl.getSuperclass(); String poreName = event;//from w w w . j a v a2 s.c om String porePackage = StringUtils.substringBeforeLast(poreName, "."); poreName = StringUtils.substringAfterLast(poreName, "."); String bukkitName = StringUtils.removeStart(bukkitEvent.getName(), BUKKIT_PREFIX); String bukkitPackage = StringUtils.substringBeforeLast(bukkitName, "."); bukkitName = StringUtils.substringAfterLast(bukkitName, "."); String expectedName = "Pore" + bukkitName; assertEquals(poreName + " should be called " + expectedName, poreName, expectedName); assertEquals(poreName + " is in wrong package: should be in " + PORE_PREFIX + bukkitPackage, porePackage, bukkitPackage); }
From source file:com.newlandframework.rpc.jmx.ThreadPoolMonitorProvider.java
@Bean @DependsOn("registry") public ConnectorServerFactoryBean connectorServer() throws MalformedObjectNameException { MessageRecvExecutor ref = MessageRecvExecutor.getInstance(); String ipAddr = StringUtils.isNotEmpty(ref.getServerAddress()) ? StringUtils.substringBeforeLast(ref.getServerAddress(), DELIMITER) : "localhost"; url = "service:jmx:rmi://" + ipAddr + "/jndi/rmi://" + ipAddr + ":1099/nettyrpcstatus"; System.out.println("NettyRPC JMX MonitorURL : [" + url + "]"); ConnectorServerFactoryBean connectorServerFactoryBean = new ConnectorServerFactoryBean(); connectorServerFactoryBean.setObjectName("connector:name=rmi"); connectorServerFactoryBean.setServiceUrl(url); return connectorServerFactoryBean; }
From source file:info.magnolia.test.fixture.JcrPropertyServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String path = request.getParameter("path"); final String workspace = StringUtils.defaultString(request.getParameter("workspace"), RepositoryConstants.CONFIG); final String value = request.getParameter("value"); final boolean delete = Boolean.valueOf(request.getParameter("delete")); final String nodePath = StringUtils.substringBeforeLast(path, "/"); final String propertyName = StringUtils.substringAfterLast(path, "/"); try {/* w w w . ja va 2s . c o m*/ final Node node = SessionUtil.getNode(workspace, nodePath); if (node == null) { throw new ServletException("Node does not exist [" + nodePath + "]"); } final String returnValue = PropertyUtil.getString(node, propertyName); if (value != null) { node.setProperty(propertyName, value); node.getSession().save(); log.info("Changing value of '{}' from [{}] to [{}]", path, returnValue, value); } else if (delete) { if (node.hasProperty(propertyName)) { Property property = node.getProperty(propertyName); property.remove(); node.getSession().save(); log.info("Removed property '{}' from [{}].", propertyName, path); } else { log.info("No property '{}' found at [{}].", propertyName, path); } } response.getWriter().write(String.valueOf(returnValue)); } catch (RepositoryException e) { log.warn("Could not handle property [{}] from workspace [{}]", new Object[] { path, workspace }); throw new ServletException("Could not read property [" + path + "]"); } }
From source file:de.vandermeer.skb.datatool.commons.DataSet.java
/** * Returns the start of a key for key auto-generation * @param fs the file name//from w w w. j a v a2 s .c om * @param commonPath the common path of all file names * @return start of the key */ String calcKeyStart(FileSource fs, String commonPath) { //remove common path String ret = StringUtils.substringAfterLast(fs.getAbsoluteName(), commonPath + File.separator); //replace all path separators with key separators ret = StringUtils.replaceChars(ret, File.separatorChar, this.cs.getKeySeparator()); //remove the last dot (".json") ret = StringUtils.substringBeforeLast(ret, "."); //remove the last dot (".entry") - the entry file extension ret = StringUtils.substringBeforeLast(ret, "."); //return the key plus a final separator return ret + this.cs.getKeySeparator(); }
From source file:com.mgmtp.perfload.perfalyzer.util.ArchiveExtracter.java
/** * Processes a file. If the file is an archive (zip, tar.gz, tgz), it is extracted to a * directory with the name of the archive file. Otherwise, the file is copied to the destination * directory./*w w w . j ava2 s .com*/ */ @Override protected void handleFile(final File file, final int depth, final Collection<File> results) throws IOException { String fileName = file.getName(); File targetDir = new File(normalizedDestDirPath, currentNormalizedRelativeDirPath); if (!targetDir.exists()) { checkState(targetDir.mkdirs(), "Could not create directory: " + targetDir); } Matcher matcher = ARCHIVE_PATTERN.matcher(fileName); if (matcher.find()) { log.debug("Extracting file: {}", file); try { String extension = matcher.group(); String baseName = StringUtils.substringBeforeLast(fileName, extension); Archiver archiver = ArchiverFactory.createArchiver(file); archiver.extract(file, new File(targetDir, baseName)); } catch (IOException ex) { log.error("Error extracting file: " + file, ex); } } else { log.debug("Copying file: {}", file); // We skip supervisor.log because the Supervisor might be running perfAlyzer // and the file could be locked. The file is not needed anyways. if (!"supervisor.log".equals(file.getName())) { FileUtils.copyFile(file, new File(targetDir, fileName)); } } }