Example usage for org.apache.commons.lang3 StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

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 ww  . j a  v a  2  s. c  o  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:de.jfachwert.net.Domainname.java

/**
 * Liefert die Top-Level-Domain (TLD) zurueck.
 *
 * @return z.B. "de"//from  w w  w  . j av  a2 s . co m
 */
public Domainname getTLD() {
    return new Domainname(StringUtils.substringAfterLast(this.getCode(), "."));
}

From source file:de.jcup.egradle.core.model.groovyantlr.GradleModelBuilderSupport.java

public AST handleTasksWithTypeClosure(String enameString, Item item, AST nextAST) {
    AST newLastAst = nextAST;/*from w  ww . j av  a2  s  .com*/
    if (enameString.startsWith("tasks.withType")) {
        String type = StringUtils.substringAfterLast(enameString, " ");
        item.setType(type);

        if (nextAST == null) {
            return null;
        }
        if (nextAST.getType() == ELIST) {
            AST elist = nextAST;
            AST methodCall2 = elist.getFirstChild();
            if (methodCall2 != null) {
                if (GroovyTokenTypes.SL == methodCall2.getType()) {
                    /* << */
                    methodCall2 = methodCall2.getFirstChild();
                }
                AST taskType = methodCall2.getFirstChild();
                item.setName("tasks.withType(" + taskType + ")");
                AST other = elist.getNextSibling();
                newLastAst = other;
            }
        }
        return newLastAst;

    }
    return newLastAst;
}

From source file:de.tuberlin.uebb.jbop.access.ClassDescriptor.java

/**
 * Get the Simple name (without package) of the class.
 * /*from   ww  w . j  av  a2 s.c o  m*/
 * @return the simple name
 */
public String getSimpleName() {
    return StringUtils.substringAfterLast(name, ".");
}

From source file:info.magnolia.photoreview.app.action.AddToAssetsAction.java

@Override
protected void executeTask(TasksManager taskManager, Task task) {
    // first resolve item properties from task
    String assetName = (String) task.getContent().get("itemId");
    String urlString = (String) task.getContent().get("images.standardResolution.url");
    String extension = StringUtils.substringAfterLast(urlString, ".");

    InputStream inputStream = null;
    try {/*from ww w.  j  av a  2  s .c o m*/
        URL url = new URL((String) urlString);
        inputStream = url.openStream();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // then import to dam
    try {
        // create root folder if it does not exist
        Node damRoot = MgnlContext.getInstance().getJCRSession(DamConstants.WORKSPACE).getRootNode();
        Node folder = null;
        if (!damRoot.hasNode(DAM_FOLDER_NAME)) {
            folder = damRoot.addNode(DAM_FOLDER_NAME, NodeTypes.Folder.NAME);
        } else {
            folder = damRoot.getNode(DAM_FOLDER_NAME);
        }

        // create asset and binary property
        Node asset = folder.addNode(assetName, AssetNodeTypes.Asset.NAME);
        Node jcrContent = asset.addNode(JcrConstants.JCR_CONTENT, NodeTypes.Resource.NAME);
        Binary binary = ValueFactoryImpl.getInstance().createBinary(inputStream);
        jcrContent.setProperty(JcrConstants.JCR_DATA, binary);
        jcrContent.setProperty(JcrConstants.JCR_MIMETYPE,
                StringUtils.defaultIfEmpty(MIMEMapping.getMIMEType(extension), "application/octet-stream"));

        folder.getSession().save();

        // finally resolve task
        super.executeTask(taskManager, task);

    } catch (RepositoryException e) {
        e.printStackTrace();
    }

}

From source file:com.github.benmanes.caffeine.cache.testing.CacheValidationListener.java

/** Returns the name of the executed test. */
private static String getTestName(IInvokedMethod method) {
    return StringUtils.substringAfterLast(method.getTestMethod().getTestClass().getName(), ".") + "#"
            + method.getTestMethod().getConstructorOrMethod().getName();
}

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// w w  w  .ja  va 2s  .c  o m
 * @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:io.knotx.mocks.adapter.MockAdapterHandler.java

protected String getFilePath(String path) {
    return catalogue + File.separator
            + (path.contains(SEPARATOR) ? StringUtils.substringAfterLast(path, SEPARATOR) : path);
}

From source file:com.norconex.commons.lang.time.YearMonthDay.java

/**
 * Constructs a YearMonthDay from a string of this format: 
 * <code>yyyy-MM-dd</code>./*  ww w  . j a  v  a2 s.co m*/
 * @param date a date string
 */
public YearMonthDay(String date) {
    this(Integer.valueOf(StringUtils.substringBefore(date, "-")),
            Integer.valueOf(StringUtils.substringBetween(date, "-")),
            Integer.valueOf(StringUtils.substringAfterLast(date, "-")));
}

From source file:com.adeptj.runtime.servlet.ErrorPages.java

static void renderErrorPage(HttpServletRequest req, HttpServletResponse resp) {
    String statusCode = StringUtils.substringAfterLast(req.getRequestURI(), Constants.SLASH);
    if (StringUtils.equals(TEMPLATE_ERROR, req.getRequestURI())) {
        ErrorPages.renderGenericErrorPage(req, resp);
    } else if (StringUtils.equals(STATUS_500, statusCode)) {
        ErrorPages.render500Page(req, resp);
    } else if (RequestUtil.hasException(req) && StringUtils.equals(STATUS_500, statusCode)) {
        ErrorPages.render500PageWithExceptionTrace(req, resp);
    } else if (Configs.of().undertow().getStringList(KEY_STATUS_CODES).contains(statusCode)) {
        ErrorPages.renderErrorPageForStatusCode(req, resp, statusCode);
    } else {/*from  w  ww. j  av a  2  s .  c  o m*/
        ResponseUtil.sendError(resp, HttpServletResponse.SC_NOT_FOUND);
    }
}