Example usage for org.apache.commons.lang StringUtils substringBeforeLast

List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBeforeLast.

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:ips1ap101.lib.base.BaseBundle.java

public static String getLimiteFilasFuncionReport(String key) {
    String string = getString(key, LIMITE_FILAS_FUNCION_REPORT);
    if (string == null) {
        String dominio = StringUtils.substringBeforeLast(key, ".");
        if (key.equals(dominio)) {
        } else {/*from   www.  ja v a  2 s .co m*/
            string = getString(dominio, LIMITE_FILAS_FUNCION_REPORT);
        }
    }
    if (string == null) {
        string = getString(DEFAULT, LIMITE_FILAS_FUNCION_REPORT);
    }
    return string;
}

From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.MovingPage.java

@Override
public void move(ReplicatorQueue replicatorQueue, ResourceResolver rr)
        throws IllegalAccessException, MovingException {
    // For starters, create a page manager with a modified replicator queue
    PageManager manager = pageManagerFactory.getPageManager(rr);
    Field replicatorField = FieldUtils.getDeclaredField(manager.getClass(), "replicator", true);
    FieldUtils.writeField(replicatorField, manager, replicatorQueue);

    // Some simple transformations
    String contentPath = getSourcePath() + "/" + JcrConstants.JCR_CONTENT;
    String destinationParent = StringUtils.substringBeforeLast(getDestinationPath(), "/");

    // Attempt move operation
    try {//from ww  w . j  a  v  a  2 s.  c  o  m
        Actions.retry(10, 500, res -> {
            waitUntilResourceFound(res, destinationParent);
            moveOrClonePage(rr, manager, contentPath, destinationParent, res);
            movePageChildren(rr, res);
        }).accept(rr);
    } catch (Exception e) {
        throw new MovingException(getSourcePath(), e);
    }
}

From source file:net.shopxx.plugin.ftpStorage.FtpStoragePlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String host = pluginConfig.getAttribute("host");
        Integer port = Integer.valueOf(pluginConfig.getAttribute("port"));
        String username = pluginConfig.getAttribute("username");
        String password = pluginConfig.getAttribute("password");
        FTPClient ftpClient = new FTPClient();
        InputStream inputStream = null;
        try {/*from  w  w  w.  j  a v  a2  s.  c  o m*/
            inputStream = new BufferedInputStream(new FileInputStream(file));
            ftpClient.connect(host, port);
            ftpClient.login(username, password);
            ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            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 (SocketException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(inputStream);
            try {
                if (ftpClient.isConnected()) {
                    ftpClient.disconnect();
                }
            } catch (IOException e) {
            }
        }
    }
}

From source file:de.awtools.basic.file.FindFilesTest.java

@Test
public void testStringUtilsSubstring() {
    String fileName = "findmy.txt";
    String relativePath = StringUtils.substringBeforeLast(fileName, "/");
    String realFileName = StringUtils.substringAfterLast(fileName, "/");

    Assert.assertTrue(!(StringUtils.isBlank(relativePath)));
    Assert.assertEquals(fileName, relativePath);
    Assert.assertTrue(StringUtils.isBlank(realFileName));
}

From source file:info.magnolia.cms.beans.runtime.MultipartForm.java

public void addDocument(String atomName, String fileName, String type, File file) {
    if (StringUtils.isEmpty(fileName)) {
        return;// w ww. j  a va2s  .co m
    }
    Document document = new Document();
    document.setAtomName(atomName);
    document.setType(type);
    document.setFile(file);
    if (!StringUtils.contains(fileName, ".")) { //$NON-NLS-1$
        document.setExtention(StringUtils.EMPTY);
        document.setFileName(fileName);
    } else {
        document.setExtention(StringUtils.substringAfterLast(fileName, ".")); //$NON-NLS-1$
        document.setFileName(StringUtils.substringBeforeLast(fileName, ".")); //$NON-NLS-1$
    }
    this.documents.put(atomName, document);
}

From source file:com.dp2345.plugin.ftp.FtpPlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String host = pluginConfig.getAttribute("host");
        Integer port = Integer.valueOf(pluginConfig.getAttribute("port"));
        String username = pluginConfig.getAttribute("username");
        String password = pluginConfig.getAttribute("password");
        FTPClient ftpClient = new FTPClient();
        InputStream inputStream = null;
        try {/*from   w  w  w  . j  a v a2 s.  c  om*/
            inputStream = new FileInputStream(file);
            ftpClient.connect(host, port);
            ftpClient.login(username, password);
            ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            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.google.gdt.eclipse.designer.uibinder.model.util.UiBinderTagResolver.java

/**
 * @return the namespace (existing or added) to use for given class.
 *//* ww  w  .  ja v a  2  s.c  o m*/
private String getNamespace(String className) {
    String packageName = StringUtils.substringBeforeLast(className, ".");
    String packageURI = "urn:import:" + packageName;
    return ensureName(packageURI, "p");
}

From source file:io.personium.core.utils.UriUtils.java

/**
 * getUnitUrl./*from  ww w  . j  a  v a  2  s.c  om*/
 * @param cellUrl String
 * @param index int from last
 * @return url String
 */
public static String getUnitUrl(String cellUrl, int index) {
    String[] list = cellUrl.split(STRING_SLASH);
    // ????????
    return StringUtils.substringBeforeLast(cellUrl, list[list.length - index]);
}

From source file:eionet.cr.staging.FileDownloader.java

@Override
public void run() {
    try {/*from w w  w  .  j ava  2 s.  c  o m*/
        File file = execute();
        // Remove the SUFFIX from the file name, now that it's downloaded.
        file.renameTo(new File(FILES_DIR, StringUtils.substringBeforeLast(file.getName(), FILE_SUFFIX)));
    } catch (IOException e) {
        LOGGER.error("Failed to download from the given URL: " + url, e);
    }
}

From source file:info.magnolia.module.workflow.commands.simple.ActivationCommand.java

/**
 * do real activation//from  ww  w . jav a 2s . com
 * @param path node path
 * @param recursive activet recursively or no
 * @throws Exception
 */
private void doActivate(String repository, String path, boolean recursive) throws Exception {
    Rule rule = new Rule();
    rule.addAllowType(ItemType.CONTENTNODE.getSystemName());
    rule.addAllowType(ItemType.NT_METADATA);
    rule.addAllowType(ItemType.NT_RESOURCE);
    if (recursive) {
        rule.addAllowType(ItemType.CONTENT.getSystemName());
    }

    Syndicator syndicator = (Syndicator) FactoryUtil.getInstance(Syndicator.class);
    syndicator.init(MgnlContext.getUser(), repository, ContentRepository.getDefaultWorkspace(repository), rule);

    String parentPath = StringUtils.substringBeforeLast(path, "/");
    if (StringUtils.isEmpty(parentPath)) {
        parentPath = "/";
    }
    syndicator.activate(parentPath, path);

}