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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:ubic.gemma.search.GeneSetSearchImpl.java

@Override
public Collection<GeneSet> findByName(String name, Taxon taxon) {
    return geneSetService.findByName(StringUtils.strip(name), taxon);
}

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

/**
 * @param settings// www .jav a2  s  .c  om
 * @return results, if the settings.termUri is populated. This includes gene uris.
 */
private Map<Class<?>, List<SearchResult>> ontologyUriSearch(SearchSettings settings) {
    Map<Class<?>, List<SearchResult>> results = new HashMap<Class<?>, List<SearchResult>>();

    // 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 = null;
    String uriString = null;

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

    if (StringUtils.containsIgnoreCase(uriString, 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<Class<?>>();
        classesToFilterOn.add(ExpressionExperiment.class);

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

        Collection<SearchResult> characteristicOwnerResults = 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<Class<?>>();
    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( PhenotypeAssociationImpl.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 = filterCharacteristicOwnersByClass(classesToSearch, parentMap);

    } else {

        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<SearchResult>();
            rs.add(searchR);
            results.put(searchR.getResultClass(), rs);
        }
    }

    return results;
}

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

/**
 * Makes no attempt at resolving the search query as a URI. Will tokenize the search query if there are control
 * characters in the String. URI's will get parsed into multiple query terms and lead to bad results.
 * // w  w  w. j a v  a 2s  .c  om
 * @param settings Will try to resolve general terms like brain --> to appropriate OntologyTerms and search for
 *        objects tagged with those terms (if isUseCharacte = true)
 * @param fillObjects If false, the entities will not be filled in inside the searchsettings; instead, they will be
 *        nulled (for security purposes). You can then use the id and Class stored in the SearchSettings to load the
 *        entities at your leisure. If true, the entities are loaded in the usual secure fashion. Setting this to
 *        false can be an optimization if all you need is the id. Note: filtering by taxon will not be done unless
 *        objects are filled
 * @param webSpeedSearch if true, this call is probably coming from a web app combo box and results will be limited to
 *         improve speed
 * @return
 */
protected Map<Class<?>, List<SearchResult>> generalSearch(SearchSettings settings, boolean fillObjects,
        boolean webSpeedSearch) {
    String searchString = QueryParser.escape(StringUtils.strip(settings.getQuery()));

    if (settings.getTaxon() == null) {

        // split the query around whitespace characters, limit the splitting to 4 terms (may be excessive)
        String[] searchTerms = searchString.split("\\s+", 4);
        for (int i = 0; i < searchTerms.length; i++) {
            searchTerms[i] = searchTerms[i].toLowerCase();
        }
        List<String> searchTermsList = Arrays.asList(searchTerms);

        // this Set is ordered by insertion order(LinkedHashMap)
        Set<String> keywords = nameToTaxonMap.keySet();

        // only strip out taxon terms if there is more than one search term in query and if the entire search string
        // is not itself a keyword
        if (searchTerms.length > 1 && !keywords.contains(searchString.toLowerCase())) {

            for (String keyword : keywords) {

                int termIndex = searchString.toLowerCase().indexOf(keyword);
                // make sure that the keyword occurs in the searchString
                if (termIndex != -1) {
                    // make sure that either the keyword is multi-term or that it occurs as a single term(not as
                    // part of another word)
                    if (keyword.contains(" ") || searchTermsList.contains(keyword)) {
                        searchString = searchString.replaceFirst("(?i)" + keyword, "").trim();
                        settings.setTaxon(nameToTaxonMap.get(keyword));
                        // break on first term found in keywords since they should be(more or less) ordered by
                        // precedence
                        break;
                    }
                }

            }

        }

    }

    String[] searchTerms = searchString.split("\\s+");

    // some strings of size 1 cause lucene to barf and they were slipping through in multi-term queries, get rid of
    // them
    if (searchTerms.length > 0) {
        searchString = "";
        for (String sTerm : searchTerms) {
            if (sTerm.length() > 1) {
                searchString = searchString + " " + sTerm;
            }
        }
        searchString = searchString.trim();
    }

    settings.setQuery(searchString);

    // If nothing to search return nothing.
    if (StringUtils.isBlank(searchString)) {
        return new HashMap<Class<?>, List<SearchResult>>();
    }

    List<SearchResult> rawResults = new ArrayList<SearchResult>();

    if (settings.getSearchExperiments()) {
        Collection<SearchResult> foundEEs = expressionExperimentSearch(settings);
        rawResults.addAll(foundEEs);
    }

    Collection<SearchResult> genes = null;
    if (settings.getSearchGenes()) {
        genes = geneSearch(settings, webSpeedSearch);
        accreteResults(rawResults, genes);
    }

    // SearchSettings persistent entity does not contain a usePhenotypes property that these logic requires
    /*
     * if ( settings.getUsePhenotypes() && settings.getSearchGenes() ) {
     * 
     * Collection<SearchResult> phenotypeGenes = dbHitsToSearchResult(
     * geneSearchService.getPhenotypeAssociatedGenes( searchString, settings.getTaxon() ),
     * "From phenotype association" ); accreteResults( rawResults, phenotypeGenes ); }
     */

    Collection<SearchResult> compositeSequences = null;
    if (settings.getSearchProbes()) {
        compositeSequences = compositeSequenceSearch(settings);
        accreteResults(rawResults, compositeSequences);
    }

    if (settings.getSearchPlatforms()) {
        Collection<SearchResult> foundADs = arrayDesignSearch(settings, compositeSequences);
        accreteResults(rawResults, foundADs);
    }

    if (settings.getSearchBioSequences()) {
        Collection<SearchResult> bioSequences = bioSequenceSearch(settings, genes);
        accreteResults(rawResults, bioSequences);
    }

    if (settings.getUseGo()) {
        Collection<SearchResult> ontologyGenes = dbHitsToSearchResult(
                geneSearchService.getGOGroupGenes(searchString, settings.getTaxon()), "From GO group");
        accreteResults(rawResults, ontologyGenes);
    }

    if (settings.getSearchBibrefs()) {
        Collection<SearchResult> bibliographicReferences = compassBibliographicReferenceSearch(settings);
        accreteResults(rawResults, bibliographicReferences);
    }

    if (settings.getSearchGeneSets()) {
        Collection<SearchResult> geneSets = geneSetSearch(settings);
        accreteResults(rawResults, geneSets);
    }

    if (settings.getSearchExperimentSets()) {
        Collection<SearchResult> experimentSets = experimentSetSearch(settings);
        accreteResults(rawResults, experimentSets);
    }

    if (settings.getSearchPhenotypes()) {
        Collection<SearchResult> phenotypes = phenotypeSearch(settings);
        accreteResults(rawResults, phenotypes);
    }
    Map<Class<?>, List<SearchResult>> sortedLimitedResults = getSortedLimitedResults(settings, rawResults,
            fillObjects);

    log.info("search for: " + settings.getQuery() + " " + rawResults.size()
            + " raw results (final tally may be filtered)");

    return sortedLimitedResults;
}

From source file:uk.me.g4dpz.satellite.TLE.java

/**
 * Constructor./*w  w w  . ja v  a 2  s  .c o  m*/
 *
 * @param tle the three line elements
 * @throws IllegalArgumentException here was something wrong with the TLE
 */
public TLE(final String[] tle, final boolean nilStart) throws IllegalArgumentException {

    if (nilStart) {
        tle[0] = tle[0].substring(2);
    }

    if (null == tle) {
        throw new IllegalArgumentException("TLE was null");
    }

    if (tle.length != THREELINES) {
        throw new IllegalArgumentException("TLE had " + tle.length + " elements");
    }

    int lineCount = 0;

    for (final String line : tle) {

        testArguments(lineCount, line);

        lineCount++;
    }

    catnum = Integer.parseInt(StringUtils.strip(tle[1].substring(2, 7)));
    name = tle[0].trim();
    setnum = Integer.parseInt(StringUtils.strip(tle[1].substring(64, 68)));
    year = Integer.parseInt(StringUtils.strip(tle[1].substring(18, 20)));
    refepoch = Double.parseDouble(tle[1].substring(20, 32));
    incl = Double.parseDouble(tle[2].substring(8, 16));
    raan = Double.parseDouble(tle[2].substring(17, 25));
    eccn = 1.0e-07 * Double.parseDouble(tle[2].substring(26, 33));
    argper = Double.parseDouble(tle[2].substring(34, 42));
    meanan = Double.parseDouble(tle[2].substring(43, 51));
    meanmo = Double.parseDouble(tle[2].substring(52, 63));
    drag = Double.parseDouble(tle[1].substring(33, 43));

    double tempnum = 1.0e-5 * Double.parseDouble(tle[1].substring(44, 50));
    nddot6 = tempnum / Math.pow(10.0, Double.parseDouble(tle[1].substring(51, 52)));

    tempnum = 1.0e-5 * Double.parseDouble(tle[1].substring(53, 59));

    bstar = tempnum / Math.pow(10.0, Double.parseDouble(tle[1].substring(60, 61)));

    orbitnum = Integer.parseInt(StringUtils.strip(tle[2].substring(63, 68)));

    /* reassign the values to thse which get used in calculations */
    epoch = (1000.0 * getYear()) + getRefepoch();

    xndt2o = drag;

    double temp = incl;
    temp *= DEG2RAD;
    xincl = temp;

    temp = raan;
    temp *= DEG2RAD;
    xnodeo = temp;

    eo = eccn;

    temp = argper;
    temp *= DEG2RAD;
    omegao = temp;

    temp = meanan;
    temp *= DEG2RAD;
    xmo = temp;

    xno = meanmo;

    /* Preprocess tle set */

    preProcessTLESet();
}

From source file:us.paulevans.basicxslt.SaveAsConfigurationFrame.java

/**
 * Event handler/*from  ww w  . j  a va 2 s . c  o  m*/
 */
public void actionPerformed(ActionEvent aEvent) {

    Object eventSource;
    String newConfigurationName;

    eventSource = aEvent.getSource();
    if (eventSource == cancelBtn) {
        dispose();
    } else if (eventSource == okayBtn) {
        newConfigurationName = StringUtils.strip(configurationName.getText());
        if (StringUtils.isNotBlank(newConfigurationName)) {
            userPrefs.copyCurrentPreferences(newConfigurationName);
            userPrefs.setConfiguration(newConfigurationName, makeDefault.isSelected());
            parent.refreshConfigurationLabel();
            dispose();
        } else {
            Utils.showDialog(this,
                    stringFactory.getString(LabelStringFactory.SAVEASCONFIG_FRAME_CONFIG_STR_CANNOT_BE_EMPTY),
                    stringFactory.getString(LabelStringFactory.SAVEASCONFIG_FRAME_ERROR),
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:us.paulevans.basicxslt.TransformOutputPropertiesFrame.java

/**
 * Sets aOutputProperties from the state of the GUI
 * @param aOutputProperties/*from   w w  w  .  j a  v a2  s. co m*/
 */
private void setOutputProperties(TransformOutputProperties aOutputProperties) {

    String val;

    aOutputProperties.setCDATA_SECTION_ELEMENTS(StringUtils.strip(CDATASectionElements.getText()));
    aOutputProperties.setDOCTYPE_PUBLIC(StringUtils.strip(doctypePublic.getText()));
    aOutputProperties.setDOCTYPE_SYSTEM(doctypeSystem.getText());
    aOutputProperties.setENCODING(encoding.getText());
    aOutputProperties.setMEDIA_TYPE(mediaType.getText());
    aOutputProperties.setENCODING(encoding.getText());
    aOutputProperties.setVERSION(version.getText());
    aOutputProperties.setOMIT_XML_DECLARATION(omitXmlDeclaration.isSelected());
    aOutputProperties.setINDENT(indent.isSelected());
    aOutputProperties.setSTANDALONE(standalone.isSelected());
    if (xml.isSelected()) {
        val = VALID_METHODS[XML_INDEX];
    } else if (html.isSelected()) {
        val = VALID_METHODS[HTML_INDEX];
    } else if (text.isSelected()) {
        val = VALID_METHODS[TEXT_INDEX];
    } else {
        val = otherMethod.getText();
    }
    aOutputProperties.setMETHOD(val);
}