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

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

Introduction

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

Prototype

public static int lastIndexOf(String str, String searchStr) 

Source Link

Document

Finds the last index within a String, handling null.

Usage

From source file:opennlp.tools.parse_thicket.external_rst.ExternalRSTImporter.java

public List<RstNode> buildArrayOfRSTnodes(ParseThicket pt, String jotyDumpFileName) {
    String dump = null;// w  w w .jav  a  2 s  . c  om
    try {
        dump = FileUtils.readFileToString(new File(jotyDumpFileName), Charset.defaultCharset().toString());
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    List<RstNode> nodes = new ArrayList<RstNode>();
    String[] lines = dump.split("\n");
    int startOfDim = StringUtils.lastIndexOf(lines[0], " ");
    String dimStr = lines[0].substring(startOfDim).replace(")", "").trim();
    int dim = Integer.parseInt(dimStr);
    Integer[][] rstArcsIndices = new Integer[dim][dim];
    for (int i = 1; i < lines.length; i++) {
        RstNode node = new RstNode(lines[i]);
        nodes.add(node);
    }
    return nodes;
}

From source file:opennlp.tools.similarity.apps.BingQueryRunner.java

public List<HitBase> runSearch(String query, int nRes) {

    if (query.length() > MAX_QUERY_LENGTH) {
        try {//  w w  w.  j  a  v  a2 s .c o m
            query = query.substring(0, MAX_QUERY_LENGTH);
            //should not cut words, need the last space to end the query
            query = query.substring(0, StringUtils.lastIndexOf(query, " "));
        } catch (Exception e) {
            LOG.severe("Problem reducing the length of query :" + query);
        }
    }
    aq.setAppid(BING_KEY);
    aq.setQuery(query);
    aq.setPerPage(nRes);
    try {
        aq.doQuery();
    } catch (Exception e) { // most likely exception is due to limit on bing key
        aq.setAppid("pjtCgujmf9TtfjCVBdcQ2rBUQwGLmtLtgCG4Ex7kekw");
        try {
            aq.doQuery();
        } catch (Exception e1) {
            aq.setAppid("Cec1TlE67kPGDA/1MbeqPfHzP0I1eJypf3o0pYxRsuU=");
            try {
                aq.doQuery();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        e.printStackTrace();
    }

    //org.xml.sax.SAXParseException

    List<HitBase> results = new ArrayList<HitBase>();
    AzureSearchResultSet<AzureSearchWebResult> ars = aq.getQueryResult();

    for (AzureSearchWebResult anr : ars) {
        HitBase h = new HitBase();
        h.setAbstractText(anr.getDescription());
        h.setTitle(anr.getTitle());
        h.setUrl(anr.getUrl());
        results.add(h);
    }
    return results;
}

From source file:opennlp.tools.similarity.apps.utils.Utils.java

public static String addDomainToUrl(String siteUrl, String url) {
    if (StringUtils.isEmpty(url)) {
        return null; // should we return siteUrl here ??
    }//from  ww  w . j av  a  2  s. c om
    if (!url.startsWith("http://")) {
        String domain = StringUtils.substringBetween(siteUrl, "http://", "/");
        if (domain == null) {
            url = siteUrl + (url.startsWith("/") ? "" : "/") + url;
        } else {
            if (!url.startsWith("/")) {
                int lastIndex = StringUtils.lastIndexOf(siteUrl, "/");
                url = siteUrl.substring(0, lastIndex) + "/" + url;
            } else {
                url = "http://" + domain + url;
            }
        }
    }
    return url;
}

From source file:org.apache.click.service.XmlConfigService.java

/**
 * @see ConfigService#isJspPage(String)/*from  w  w  w. j  ava2s. c o  m*/
 *
 * @param path the Page ".htm" path
 * @return true if JSP exists for the given ".htm" path
 */
public boolean isJspPage(String path) {
    HtmlStringBuffer buffer = new HtmlStringBuffer();
    int index = StringUtils.lastIndexOf(path, ".");
    if (index > 0) {
        buffer.append(path.substring(0, index));
    } else {
        buffer.append(path);
    }
    buffer.append(".jsp");
    return pageByPathMap.containsKey(buffer.toString());
}

From source file:org.apache.oodt.cas.protocol.ProtocolFile.java

/**
 * Gets the parent {@link ProtocolFile} for this path.
 * //from  w  w  w  .  j ava2  s  . c om
 * @return The parent {@link ProtocolFile}
 */
public ProtocolFile getParent() {
    if (parent != null) {
        return parent;
    } else {
        int index = StringUtils.lastIndexOf(path, SEPARATOR);
        return (index > 0) ? new ProtocolFile(StringUtils.substring(path, 0, index), true) : null;
    }
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//from   w w w  . ja  v a2  s.  c o  m
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseElementTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("element-type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//w w w  .  j  ava 2s .c om
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseKeyTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("key-type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//ww  w  . j a va  2  s .com
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.ranger.plugin.util.RangerRESTUtils.java

public String getHostnameFromPluginId(String pluginId, String serviceName) {
    String ret = "";

    if (StringUtils.isNotBlank(pluginId)) {
        int lastIndex;
        String[] parts = pluginId.split("@");
        int index = parts.length > 1 ? 1 : 0;
        if (StringUtils.isNotBlank(serviceName)) {
            lastIndex = StringUtils.lastIndexOf(parts[index], serviceName);
            if (lastIndex > 1) {
                ret = parts[index].substring(0, lastIndex - 1);
            }/*  w w  w.  j a  va 2  s .  c  o  m*/
        } else {
            lastIndex = StringUtils.lastIndexOf(parts[index], "-");
            if (lastIndex > 0) {
                ret = parts[index].substring(0, lastIndex);
            }
        }
    }

    return ret;
}

From source file:org.artifactory.api.maven.MavenArtifactInfo.java

public static MavenArtifactInfo fromRepoPath(RepoPath repoPath) {
    String groupId, artifactId, version, type = MavenArtifactInfo.NA, classifier = MavenArtifactInfo.NA;

    String path = repoPath.getPath();
    String fileName = repoPath.getName();

    //The format of the relative path in maven is a/b/c/artifactId/baseVer/fileName where
    //groupId="a.b.c". We split the path to elements and analyze the needed fields.
    LinkedList<String> pathElements = new LinkedList<>();
    StringTokenizer tokenizer = new StringTokenizer(path, "/");
    while (tokenizer.hasMoreTokens()) {
        pathElements.add(tokenizer.nextToken());
    }/*w  ww  .j a va  2  s .  co  m*/
    //Sanity check, we need groupId, artifactId and version
    if (pathElements.size() < 3) {
        log.debug(
                "Cannot build MavenArtifactInfo from '{}'. The groupId, artifactId and version are unreadable.",
                repoPath);
        return new MavenArtifactInfo();
    }

    //Extract the version, artifactId and groupId
    int pos = pathElements.size() - 2; // one before the last path element
    version = pathElements.get(pos--);
    artifactId = pathElements.get(pos--);
    StringBuilder groupIdBuff = new StringBuilder();
    for (; pos >= 0; pos--) {
        if (groupIdBuff.length() != 0) {
            groupIdBuff.insert(0, '.');
        }
        groupIdBuff.insert(0, pathElements.get(pos));
    }
    groupId = groupIdBuff.toString();
    //Extract the type and classifier except for metadata files
    boolean metaData = NamingUtils.isMetadata(fileName);
    if (!metaData) {
        if (MavenNaming.isUniqueSnapshotFileName(fileName)) {
            version = StringUtils.remove(version, "-" + MavenNaming.SNAPSHOT);
            version = version + "-" + MavenNaming.getUniqueSnapshotVersionTimestampAndBuildNumber(fileName);
        }

        type = StringUtils.substring(fileName, artifactId.length() + version.length() + 2);
        int versionStartIndex = StringUtils.indexOf(fileName, "-", artifactId.length()) + 1;
        int classifierStartIndex = StringUtils.indexOf(fileName, "-", versionStartIndex + version.length());
        if (classifierStartIndex >= 0) {
            Set<String> customMavenTypes = getMavenCustomTypes();
            for (String customMavenType : customMavenTypes) {
                if (StringUtils.endsWith(fileName, customMavenType)) {
                    classifier = StringUtils.remove(type, "." + customMavenType);
                    type = customMavenType;
                    break;
                }
            }

            if (MavenArtifactInfo.NA.equals(classifier)) {
                int typeDotStartIndex = StringUtils.lastIndexOf(type, ".");
                classifier = StringUtils.substring(type, 0, typeDotStartIndex);
                type = StringUtils.substring(type, classifier.length() + 1);
            }
        }
    }
    return new MavenArtifactInfo(groupId, artifactId, version, classifier, type);
}