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:spdxedit.SpdxLogic.java

public static FileType[] getTypesForFile(Path path) {
    String extension = StringUtils
            .lowerCase(StringUtils.substringAfterLast(path.getFileName().toString(), "."));
    ArrayList<FileType> fileTypes = new ArrayList<>();
    if (sourceFileExtensions.contains(extension)) {
        fileTypes.add(SpdxFile.FileType.fileType_source);
    }//from w w  w  .j  a  va  2s.c  o  m
    if (binaryFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_binary);
    }
    if (textFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_text);
    }
    if (archiveFileExtensions.contains(extension)) {
        fileTypes.add(FileType.fileType_archive);
    }
    if ("spdx".equals(extension)) {
        fileTypes.add(FileType.fileType_spdx);
    }
    try {
        String mimeType = Files.probeContentType(path);
        if (StringUtils.startsWith(mimeType, MediaType.ANY_AUDIO_TYPE.type())) {
            fileTypes.add(FileType.fileType_audio);
        }
        if (StringUtils.startsWith(mimeType, MediaType.ANY_IMAGE_TYPE.type())) {
            fileTypes.add(FileType.fileType_image);
        }
        if (StringUtils.startsWith(mimeType, MediaType.ANY_APPLICATION_TYPE.type())) {
            fileTypes.add(FileType.fileType_application);
        }

    } catch (IOException ioe) {
        logger.warn("Unable to access file " + path.toString() + " to determine its type.", ioe);
    }
    return fileTypes.toArray(new FileType[] {});
}

From source file:suonos.services.player.mplayer.MPlayerProcessInstance.java

private double getNumber(String line, String after) {
    String val = StringUtils.substringAfterLast(line, after).trim();
    return Double.parseDouble(val);
}

From source file:tds.dll.mssql.CommonDLL.java

public String _CoreSessName_FN(SQLConnection connection, String clientName, String procName)
        throws ReturnStatusException {

    Integer space = null;//from ww  w.j  a  v  a  2s.  co  m
    String sessname = null;
    String environment = null;

    final String SQL_QUERY1 = "select environment from _externs where clientname = ${clientname};";
    SqlParametersMaps parms1 = (new SqlParametersMaps()).put("clientname", clientName);
    SingleDataResultSet result = executeStatement(connection, SQL_QUERY1, parms1, false).getResultSets().next();
    DbResultRecord record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        environment = record.<String>get("environment");
    }
    final String SQL_QUERY2 = "select TDS_ID as sessname from ${ConfigDB}.GEO_Database D, ${ConfigDB}.GEO_ClientApplication A "
            + " where clientname = ${clientname} and environment = ${environment} and ServiceType = ${Satellite} and AppName = ${proctor}"
            + " and _fk_GEO_Database = D._Key  and D.Servername = cast(serverproperty('machinename') as varchar(100)) and D.dbname = db_name();";
    String finalQuery = fixDataBaseNames(SQL_QUERY2);
    SqlParametersMaps parms2 = (new SqlParametersMaps()).put("clientname", clientName)
            .put("environment", environment).put("Satellite", "Satellite").put("proctor", "proctor");
    result = executeStatement(connection, finalQuery, parms2, false).getResultSets().next();
    record = (result.getCount() > 0 ? result.getRecords().next() : null);
    if (record != null) {
        sessname = record.<String>get("sessname");
    }
    if (DbComparator.notEqual(sessname, null)) {
        return (String.format("-%s", sessname));
    }
    sessname = StringUtils.substringAfterLast(procName, " ");
    if (sessname == null || sessname.length() == 0)
        sessname = procName.substring(0, 3).trim() + "-";
    else if (sessname.length() > 4)
        sessname = sessname.substring(0, 3).trim() + "-";
    else
        sessname += "-";

    return sessname;
}

From source file:tds.dll.mysql.CommonDLL.java

public String _CoreSessName_FN(SQLConnection connection, String clientName, String procName)
        throws ReturnStatusException {

    String sessname = null;//from w  ww  . ja va  2  s .co m

    sessname = StringUtils.substringAfterLast(procName, " ");
    if (sessname == null || sessname.length() == 0)
        sessname = procName.substring(0, 3).trim() + "-";
    else if (sessname.length() > 4)
        sessname = sessname.substring(0, 3).trim() + "-";
    else
        sessname += "-";

    return sessname;
}

From source file:therian.buildweaver.StandardOperatorsProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {//ww  w  . j  a  v  a  2 s  . co  m
        final FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT,
                StringUtils.substringBeforeLast(TARGET_CLASSNAME, ".").replace('.', '/'),
                StringUtils.substringAfterLast(TARGET_CLASSNAME, ".") + ".class");

        if (resource.getLastModified() > 0L) {
            processingEnv.getMessager().printMessage(Kind.NOTE,
                    String.format("%s already generated", TARGET_CLASSNAME));
            return false;
        }
    } catch (IOException e1) {
        // expected, swallow
    }
    try {
        ClassUtils.getClass(TARGET_CLASSNAME);
        processingEnv.getMessager().printMessage(Kind.ERROR,
                String.format("%s exists on classpath", TARGET_CLASSNAME));
        return false;
    } catch (ClassNotFoundException e) {
        // expected, swallow
    }

    if (roundEnv.processingOver()) {
        write();
        return true;
    }
    for (TypeElement ann : annotations) {
        final Set<? extends Element> standardOperatorElements = roundEnv.getElementsAnnotatedWith(ann);
        originatingElements.addAll(standardOperatorElements);

        for (Element element : standardOperatorElements) {
            Validate.validState(isValidStandardOperator(element), "%s is not a valid @StandardOperator",
                    appendTo(new StringBuilder(), element).toString());

            if (element.getKind() == ElementKind.CLASS) {
                operators.add(appendTo(new StringBuilder("new "), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.METHOD) {
                operators.add(appendTo(new StringBuilder(), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.FIELD) {
                operators.add(appendTo(new StringBuilder(), element).toString());
            }
        }
    }
    return true;
}

From source file:ubic.gemma.core.search.SearchServiceImpl.java

/**
 * @return results, if the settings.termUri is populated. This includes gene uris.
 *///from   w w  w  .  jav a 2s  .co m
private Map<Class<?>, List<SearchResult>> ontologyUriSearch(SearchSettings settings) {
    Map<Class<?>, List<SearchResult>> results = new HashMap<>();

    // 1st check to see if the query is a URI (from an ontology).
    // Do this by seeing if we can find it in the loaded ontologies.
    // Escape with general utilities because might not be doing a lucene backed search. (just a hibernate one).
    String termUri = settings.getTermUri();

    if (StringUtils.isBlank(termUri)) {
        termUri = settings.getQuery();
    }

    if (!termUri.startsWith("http://")) {
        return results;
    }

    OntologyTerm matchingTerm;
    String uriString;

    uriString = StringEscapeUtils.escapeJava(StringUtils.strip(termUri));

    if (StringUtils.containsIgnoreCase(uriString, SearchServiceImpl.NCBI_GENE)) {
        // Perhaps is a valid gene URL. Want to search for the gene in gemma.
        // 1st get objects tagged with the given gene identifier
        Collection<Class<?>> classesToFilterOn = new HashSet<>();
        classesToFilterOn.add(ExpressionExperiment.class);

        Collection<Characteristic> foundCharacteristics = characteristicService.findByUri(classesToFilterOn,
                uriString);
        Map<Characteristic, Object> parentMap = characteristicService.getParents(classesToFilterOn,
                foundCharacteristics);

        Collection<SearchResult> characteristicOwnerResults = this
                .filterCharacteristicOwnersByClass(classesToFilterOn, parentMap);

        if (!characteristicOwnerResults.isEmpty()) {
            results.put(ExpressionExperiment.class, new ArrayList<SearchResult>());
            results.get(ExpressionExperiment.class).addAll(characteristicOwnerResults);
        }

        if (settings.getSearchGenes()) {
            // Get the gene
            String ncbiAccessionFromUri = StringUtils.substringAfterLast(uriString, "/");
            Gene g = null;

            try {
                g = geneService.findByNCBIId(Integer.parseInt(ncbiAccessionFromUri));
            } catch (NumberFormatException e) {
                // ok
            }

            if (g != null) {
                results.put(Gene.class, new ArrayList<SearchResult>());
                results.get(Gene.class).add(new SearchResult(g));
            }
        }
        return results;
    }

    /*
     * Not searching for a gene.
     */
    Collection<SearchResult> matchingResults;
    Collection<Class<?>> classesToSearch = new HashSet<>();
    if (settings.getSearchExperiments()) {
        classesToSearch.add(ExpressionExperiment.class); // not sure ...
        classesToSearch.add(BioMaterial.class);
        classesToSearch.add(FactorValue.class);
    }

    // this doesn't seem to be implemented yet, LiteratureEvidence and GenericEvidence aren't handled in the
    // fillValueObjects method downstream
    /*
     * if ( settings.getSearchPhenotypes() ) { classesToSearch.add( PhenotypeAssociation.class ); }
     */
    matchingTerm = this.ontologyService.getTerm(uriString);
    if (matchingTerm == null || matchingTerm.getUri() == null) {
        /*
         * Maybe the ontology isn't loaded. Look anyway.
         */
        Map<Characteristic, Object> parentMap = characteristicService.getParents(classesToSearch,
                characteristicService.findByUri(classesToSearch, uriString));
        matchingResults = this.filterCharacteristicOwnersByClass(classesToSearch, parentMap);

    } else {

        SearchServiceImpl.log.info("Found ontology term: " + matchingTerm);

        // Was a URI from a loaded ontology soo get the children.
        Collection<OntologyTerm> terms2Search4 = matchingTerm.getChildren(true);
        terms2Search4.add(matchingTerm);

        matchingResults = this.databaseCharacteristicExactUriSearchForOwners(classesToSearch, terms2Search4);
    }

    for (SearchResult searchR : matchingResults) {
        if (results.containsKey(searchR.getResultClass())) {
            results.get(searchR.getResultClass()).add(searchR);
        } else {
            List<SearchResult> rs = new ArrayList<>();
            rs.add(searchR);
            results.put(searchR.getResultClass(), rs);
        }
    }

    return results;
}

From source file:ubicrypt.core.Utils.java

public static void setProperties(String[] args) {
    if (args == null || args.length == 0) {
        return;/* w ww. jav a2 s.  co m*/
    }
    int i = 0;
    do {
        String arg = trim(args[i]);
        String pured = arg;
        if (startsWith(arg, "-") || startsWith(arg, "--")) {
            pured = StringUtils.substringAfterLast(arg, "-");
        }
        if (StringUtils.contains(pured, "=")) {
            String[] split = StringUtils.split(pured, '=');
            System.setProperty(split[0], split[1]);
            i++;
            continue;
        }
        i++;
        if (i >= args.length) {
            System.setProperty(pured, "true");
            return;
        }
        String val = trim(args[i]);
        if (StringUtils.equals(val, "=")) {
            i++;
            if (i >= args.length) {
                return;
            }
            val = trim(args[i]);
        }

        if (startsWith(val, "-")) {
            System.setProperty(pured, "true");
        } else {
            System.setProperty(pured, val);
            i++;
        }

    } while (i < args.length);
}

From source file:uk.co.techblue.alfresco.resteasy.providers.DocumentContentProvider.java

/**
 * Gets the file suffix./*w  w  w  . j  a v a2  s.  c  o  m*/
 * 
 * @param mediaType the media type
 * @param fileName the file name
 * @return the file suffix
 */
private String getFileSuffix(final MediaType mediaType, final String fileName) {
    String suffix = StringUtils.substringAfterLast(fileName, ".");
    if (StringUtils.isNotBlank(suffix)) {
        suffix = "." + suffix;
    } else {
        final String mediaSubtype = StringUtils.defaultString(mediaType.getSubtype());
        suffix = getFileExtension(getHttpMimeType(mediaType), mediaSubtype);
    }
    return suffix;
}

From source file:uk.co.techblue.docusign.resteasy.providers.DocumentFileProvider.java

private String getFileSuffix(MediaType mediaType, String fileName) {
    String suffix = StringUtils.substringAfterLast(fileName, ".");
    String mediaSubtype = StringUtils.defaultString(mediaType.getSubtype());
    boolean suffixBlank = StringUtils.isBlank(suffix);
    boolean mediaSubtypeBlank = StringUtils.isBlank(mediaSubtype);
    if (!suffixBlank && mediaSubtype.equalsIgnoreCase(suffix)) {
        suffix = "." + suffix;
    } else if (!suffixBlank && mediaSubtypeBlank) {
        suffix = "." + suffix;
    } else if (suffixBlank && !mediaSubtypeBlank) {
        suffix = "." + mediaSubtype;
    } else if (!suffixBlank && !mediaSubtypeBlank) {
        suffix = "." + suffix + "." + mediaSubtype;
    } else {/* w w w .j  a v a 2s. c om*/
        suffix = ".pdf";
    }
    return suffix;
}