Example usage for org.apache.commons.lang WordUtils capitalizeFully

List of usage examples for org.apache.commons.lang WordUtils capitalizeFully

Introduction

In this page you can find the example usage for org.apache.commons.lang WordUtils capitalizeFully.

Prototype

public static String capitalizeFully(String str) 

Source Link

Document

Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.

Usage

From source file:com.gtwm.pb.model.manageData.DataManagement.java

public String getReportMapJson(CompanyInfo company, BaseReportInfo report, Map<BaseField, String> filters)
        throws CodingErrorException, CantDoThatException, SQLException {
    ReportMapInfo map = report.getMap();
    if (map == null) {
        throw new CantDoThatException("Report has no map configured");
    }/*from  ww  w.  j  a v a2s  .co m*/
    ReportFieldInfo postcodeField = map.getPostcodeField();
    if (postcodeField == null) {
        throw new CantDoThatException("Report map has no postcode field identified");
    }
    ReportFieldInfo colourField = map.getColourField();
    ReportFieldInfo categoryField = map.getCategoryField();
    List<DataRowInfo> reportDataRows = this.getReportDataRows(company, report, filters, false,
            new HashMap<BaseField, Boolean>(0), 10000, QuickFilterType.AND, true);
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter stringWriter = new StringWriter(1024);
    JsonGenerator jg;
    try {
        jg = jsonFactory.createJsonGenerator(stringWriter);
        jg.writeStartArray();
        for (DataRowInfo reportDataRow : reportDataRows) {
            jg.writeStartObject();
            jg.writeNumberField("rowId", reportDataRow.getRowId());
            LocationDataRowFieldInfo postcodeDataRowField = (LocationDataRowFieldInfo) reportDataRow
                    .getValue(postcodeField);
            jg.writeStringField("postcode", postcodeDataRowField.getKeyValue());
            jg.writeNumberField("latitude", postcodeDataRowField.getLatitude());
            jg.writeNumberField("longitude", postcodeDataRowField.getLongitude());
            jg.writeStringField("title", buildEventTitle(report, reportDataRow, true));
            if (colourField != null) {
                String colourValue = reportDataRow.getValue(colourField).getKeyValue();
                jg.writeStringField("colourValue", colourValue);
                int upperHash = colourValue.toUpperCase().hashCode();
                int hue = 0;
                if (upperHash != Integer.MIN_VALUE) {
                    // http://findbugs.blogspot.co.uk/2006/09/is-mathabs-broken.html
                    hue = Math.abs(upperHash) % 360;
                }
                int saturation = 20;
                int lowerHash = colourValue.toLowerCase().hashCode();
                if (lowerHash != Integer.MIN_VALUE) {
                    saturation += (Math.abs(lowerHash) % 80);
                }
                int lightness = 50;
                int capsHash = WordUtils.capitalizeFully(colourValue).hashCode();
                if (capsHash != Integer.MIN_VALUE) {
                    lightness += (Math.abs(capsHash) % 40);
                }
                jg.writeNumberField("h", hue);
                jg.writeNumberField("s", saturation);
                jg.writeNumberField("l", lightness);
            }
            if (categoryField != null) {
                DataRowFieldInfo categoryValue = reportDataRow.getValue(categoryField);
                jg.writeStringField("categoryValue", categoryValue.getDisplayValue());
            }
            jg.writeEndObject();
        }
        jg.writeEndArray();
        jg.flush();
        jg.close();
    } catch (IOException ioex) {
        throw new CodingErrorException("JSON generation produced IO Exception: " + ioex, ioex);
    }
    return stringWriter.toString();
}

From source file:ninja.text.TextImpl.java

@Override
public Text capitalize() {
    return Text.of(new StringBuilder(WordUtils.capitalizeFully(data.toString())));
}

From source file:nvinayshetty.DTOnator.NameConventionCommands.test.java

public static void main(String[] args) {
    // String string = WordUtils.capitalize("INVALID IDENTIFIER");
    String string = WordUtils.capitalizeFully("INVALID IDENTIFIER");
    string = WordUtils.capitalizeFully(string, new char[] { '_' });
    System.out.println(string);/*from  w  w  w .jav a2  s  . c om*/
}

From source file:org.ala.dao.TaxonConceptSHDaoImpl.java

/**
 * @see org.ala.dao.TaxonConceptDao//from  w ww  .j a v a2  s  .  c  o m
 */
public String syncTriples(org.ala.model.Document document, List<Triple> triples, Map<String, String> dublinCore,
        boolean statsOnly) throws Exception {
    List<String> scientificNames = new ArrayList<String>();
    String specificEpithet = null;
    List<String> subspecies = new ArrayList<String>();
    List<String> species = new ArrayList<String>();
    String genus = null;
    String family = null;
    String superfamily = null;
    String order = null;
    String phylum = null;
    String klass = null;
    String kingdom = null;

    String dcSource = null;
    String dcPublisher = null;
    String dcIdentifier = null;
    String dcTitle = null;

    boolean isScreenshot = false;
    boolean isPreferredImage = false;

    String occurrenceUid = null;
    String occurrenceRowKey = null;

    if (document != null) {
        dcPublisher = document.getInfoSourceName();
        dcSource = document.getInfoSourceUri();
        dcIdentifier = document.getIdentifier();
        dcTitle = document.getTitle();
    }

    // iterate through triples and find scientific names and genus
    for (Triple triple : triples) {

        String predicate = triple.predicate.substring(triple.predicate.lastIndexOf("#") + 1);

        if (predicate.endsWith("hasKingdom")) {
            kingdom = triple.object.trim();
        }
        if (predicate.endsWith("hasPhylum")) {
            phylum = triple.object.trim();
        }
        if (predicate.endsWith("hasClass")) {
            klass = triple.object.trim();
        }
        if (predicate.endsWith("hasOrder")) {
            order = triple.object.trim();
        }
        if (predicate.endsWith("hasFamily")) {
            family = triple.object.trim();
        }
        if (predicate.endsWith("hasSuperFamily")) {
            superfamily = triple.object.trim();
        }
        if (predicate.endsWith("hasGenus")) {
            genus = triple.object.trim();
        }
        if (predicate.endsWith("hasSpecies")) {
            species.add(triple.object.trim());
        }
        if (predicate.endsWith("hasSubSpecies")) {
            subspecies.add(triple.object.trim());
        }
        if (predicate.endsWith("hasSpecificEpithet")) {
            specificEpithet = triple.object.trim();
        }
        if (predicate.endsWith("hasScientificName")) {
            scientificNames.add(triple.object.trim());
        }
        if (predicate.endsWith("hasVideoPageUrl")) {
            isScreenshot = true;
        }
        if (predicate.endsWith("isPreferredImage")) {
            isPreferredImage = true;
        }
        if (predicate.endsWith("hasOccurrenceUid")) {
            occurrenceUid = triple.object.trim();
        }
        if (predicate.endsWith("hasOccurrenceRowKey")) {
            occurrenceRowKey = triple.object.trim();
        }
    }

    if (scientificNames.isEmpty() && subspecies.isEmpty() && specificEpithet == null && species.isEmpty()
            && genus == null && family == null && superfamily == null && order == null && klass == null
            && phylum == null) {
        logger.info("No classification found for document at: " + document.getFilePath());
        return null; // we have nothing to work with, so give up
    }

    // Lookup LSID in Checklist Bank data
    String rank = null;
    Rank rankObj = null;
    if (scientificNames.isEmpty()) {
        if (!subspecies.isEmpty()) {
            scientificNames.addAll(subspecies);
            rank = "subspecies";
            rankObj = Rank.SSP;
        } else if (!species.isEmpty()) {
            scientificNames.addAll(species);
            rank = "species";
            rankObj = Rank.SP;
        } else if (genus != null) {
            if (specificEpithet != null) {
                scientificNames.add(genus + " " + specificEpithet);
                rank = "species";
                rankObj = Rank.SP;
            } else {
                scientificNames.add(genus);
                rank = "genus";
                rankObj = Rank.GEN;
            }
        } else if (family != null) {
            scientificNames.add(family);
            rank = "family";
            rankObj = Rank.FAM;
        } else if (superfamily != null) {
            scientificNames.add(superfamily);
            rank = "superfamily";
            rankObj = Rank.SUPERFAM;
        } else if (order != null) {
            scientificNames.add(order);
            rank = "order";
            rankObj = Rank.ORD;
        } else if (klass != null) {
            scientificNames.add(klass);
            rank = "class";
            rankObj = Rank.CL;
        } else if (phylum != null) {
            scientificNames.add(phylum);
            rank = "phylum";
            rankObj = Rank.PHYLUM;
        } else if (kingdom != null) {
            scientificNames.add(kingdom);
            rank = "kingdom";
            rankObj = Rank.REG;
        } else {
            logger.info("Not enough search data for Checklist Bank found for document at: "
                    + document.getFilePath());
            return null;
        }
    }

    String guid = null;

    for (String scientificName : scientificNames) {
        LinnaeanRankClassification classification = new LinnaeanRankClassification(kingdom, phylum, klass,
                order, family, genus, scientificName);
        guid = findLsidByName(scientificName, classification, rank);
        if (guid != null)
            break;
    }

    if (guid == null) {
        for (String sp : species) {
            LinnaeanRankClassification classification = new LinnaeanRankClassification(kingdom, phylum, klass,
                    order, family, genus, sp);
            guid = findLsidByName(sp, classification, rank);
            if (guid != null)
                break;
        }
    }

    if (guid == null && genus != null && specificEpithet != null) {
        LinnaeanRankClassification classification = new LinnaeanRankClassification(kingdom, phylum, klass,
                order, family, genus, null);
        guid = findLsidByName(genus + " " + specificEpithet, classification, "species");
    }
    //is statsOnly we can return whether or not the scientific name was found...
    if (statsOnly) {
        return guid;
    }

    if (guid != null) {

        List<SimpleProperty> simpleProperties = new ArrayList<SimpleProperty>();

        for (Triple triple : triples) {
            // check for an empty object
            String object = StringUtils.trimToNull(triple.object);

            if (object != null) {

                logger.trace(triple.predicate);

                // check here for predicates of complex objects
                if (triple.predicate.endsWith("hasCommonName")) {

                    CommonName commonName = new CommonName();
                    String commonNameString = WordUtils.capitalizeFully(triple.object);
                    commonName.setNameString(commonNameString.trim());
                    commonName.setInfoSourceId(Integer.toString(document.getInfoSourceId()));
                    commonName.setInfoSourceUid(document.getInfoSourceUid());
                    commonName.setDocumentId(Integer.toString(document.getId()));
                    commonName.setInfoSourceName(dcPublisher);
                    commonName.setInfoSourceURL(dcSource);
                    commonName.setTitle(dcTitle);
                    commonName.setIdentifier(dcIdentifier);
                    addCommonName(guid, commonName);

                } else if (triple.predicate.endsWith("hasConservationStatus")) {

                    // dont add conservation status to higher ranks than
                    // species
                    if (rankObj != null && rankObj.getId() >= Rank.SP.getId()) {

                        // lookup the vocabulary term
                        ConservationStatus cs = vocabulary.getConservationStatusFor(document.getInfoSourceId(),
                                triple.object);
                        if (cs == null) {
                            cs = new ConservationStatus();
                            cs.setStatus(triple.object.trim());
                        }

                        cs.setInfoSourceId(Integer.toString(document.getInfoSourceId()));
                        cs.setInfoSourceUid(document.getInfoSourceUid());
                        cs.setDocumentId(Integer.toString(document.getId()));
                        cs.setInfoSourceName(dcPublisher);
                        cs.setInfoSourceURL(dcSource);
                        cs.setTitle(dcTitle);
                        cs.setIdentifier(dcIdentifier);
                        cs.setRawStatus(triple.object.trim());
                        addConservationStatus(guid, cs);
                    }

                } else if (triple.predicate.endsWith("hasPestStatus")) {

                    if (rankObj != null && rankObj.getId() >= Rank.SP.getId()) {
                        // lookup the vocabulary term
                        PestStatus ps = vocabulary.getPestStatusFor(document.getInfoSourceId(), triple.object);
                        if (ps == null) {
                            ps = new PestStatus();
                            ps.setStatus(triple.object.trim());
                        }

                        ps.setInfoSourceId(Integer.toString(document.getInfoSourceId()));
                        ps.setInfoSourceUid(document.getInfoSourceUid());
                        ps.setDocumentId(Integer.toString(document.getId()));
                        ps.setInfoSourceName(dcPublisher);
                        ps.setInfoSourceURL(dcSource);
                        ps.setTitle(dcTitle);
                        ps.setIdentifier(dcIdentifier);
                        ps.setRawStatus(triple.object.trim());
                        addPestStatus(guid, ps);
                    }

                } else if (triple.predicate.endsWith("hasImagePageUrl")) {
                    // do nothing but prevent getting caught next - added
                    // further down
                } else if (!Predicates.getTaxonomicPredicates().contains(triple.predicate)) {

                    // FIXME - this feels mighty unscalable...
                    // essentially we are putting all other field values in
                    // one very
                    // large cell
                    // if this becomes a performance problem we should split
                    // on the predicate value. i.e. tc:hasHabitatText,
                    // this was the intention with the "raw:" column family
                    // namespace
                    SimpleProperty simpleProperty = new SimpleProperty();
                    simpleProperty.setName(triple.predicate);
                    simpleProperty.setValue(triple.object.trim());
                    simpleProperty.setInfoSourceId(Integer.toString(document.getInfoSourceId()));
                    simpleProperty.setInfoSourceUid(document.getInfoSourceUid());
                    simpleProperty.setDocumentId(Integer.toString(document.getId()));
                    simpleProperty.setInfoSourceName(dcPublisher);
                    simpleProperty.setInfoSourceURL(dcSource);
                    simpleProperty.setTitle(dcTitle);
                    simpleProperty.setIdentifier(dcIdentifier);
                    //addTextProperty(guid, simpleProperty);
                    simpleProperties.add(simpleProperty);
                }
            }
        }

        if (!simpleProperties.isEmpty()) {
            addTextProperties(guid, simpleProperties);
        }

        // retrieve the content type
        if (document.getFilePath() != null) {
            if (document != null && document.getMimeType() != null
                    && MimeType.getImageMimeTypes().contains(document.getMimeType())) {
                Image image = new Image();
                image.setContentType(document.getMimeType());
                if (!isScreenshot) {
                    image.setRepoLocation(document.getFilePath() + File.separator + FileType.RAW.getFilename()
                            + MimeType.getFileExtension(document.getMimeType()));
                } else {
                    image.setRepoLocation(
                            document.getFilePath() + File.separator + FileType.SCREENSHOT.getFilename()
                                    + MimeType.getFileExtension(document.getMimeType()));
                }
                if (isPreferredImage) {
                    image.setPreferred(true);
                } else {
                    image.setPreferred(false);
                }
                image.setInfoSourceId(Integer.toString(document.getInfoSourceId()));
                image.setInfoSourceUid(document.getInfoSourceUid());
                image.setDocumentId(Integer.toString(document.getId()));
                image.setInfoSourceName(dcPublisher);
                image.setInfoSourceURL(dcSource);
                image.setIdentifier(dcIdentifier);
                image.setTitle(dcTitle);

                if (dublinCore != null) {
                    image.setCreator(dublinCore.get(Predicates.DC_CREATOR.toString()));
                    image.setLocality(dublinCore.get(Predicates.LOCALITY.toString()));
                    image.setIsPartOf(dublinCore.get(Predicates.DC_IS_PART_OF.toString()));
                    image.setLicence(dublinCore.get(Predicates.DC_LICENSE.toString()));
                    image.setRights(dublinCore.get(Predicates.DC_RIGHTS.toString()));
                    image.setIdentifier(dublinCore.get(Predicates.DC_IDENTIFIER.toString()));
                    image.setDescription(dublinCore.get(Predicates.DC_DESCRIPTION.toString()));
                }

                if (hasPredicate(triples, Predicates.DIST_MAP_IMG_URL)) {
                    addDistributionImage(guid, image);
                } else if (hasPredicate(triples, Predicates.VIDEO_PAGE_URL)) {
                    addScreenshotImage(guid, image);
                } else {
                    image.setOccurrenceUid(occurrenceUid);
                    image.setOccurrenceRowKey(occurrenceRowKey);
                    addImage(guid, image);
                    //                  logger.info("ADDING IMAGE TO: " + guid);
                }

            } else {
                // do something for videos.....
            }
        }

        logger.info("Adding content to: " + guid + ", using scientific name: " + scientificNames.get(0));
        // addLiteralValues(guid,
        // infoSourceId,Integer.toString(document.getId()), properties);

        //THIS CAUSES SOLR FILE LOCK ERRORS.

        //         if(reindex && guid != null){
        //            List<SolrInputDocument> docList = indexTaxonConcept(guid, null);
        //            SolrServer solrServer = solrUtils.getSolrServer();
        //            if(solrServer != null){
        //               solrServer.add(docList);
        ////               solrServer.commit(true, true);
        //            }
        //            else{
        //               logger.error("****** Can't connect to Solr server.....");
        //            }
        //         }
        //         return true;
    } else {
        logger.info("GUID null");
        //         return false;
    }
    return guid;
}

From source file:org.ala.dao.TaxonConceptSHDaoImpl.java

/**
 * Index the supplied taxon concept./*ww w . j  a  v  a2 s .c  om*/
 * 
 * @param guid
 * @return
 */
public List<SolrInputDocument> indexTaxonConcept(String guid, Scanner scanner) throws Exception {

    List<SolrInputDocument> docsToAdd = new ArrayList<SolrInputDocument>();

    // get taxon concept details
    TaxonConcept taxonConcept = scanner != null
            ? (TaxonConcept) scanner.getValue(ColumnType.TAXONCONCEPT_COL.getColumnName(), TaxonConcept.class)
            : getByGuid(guid);

    if (taxonConcept != null) {
        // get synonyms concepts
        List<SynonymConcept> synonyms = scanner != null
                ? (List) scanner.getListValue(ColumnType.SYNONYM_COL.getColumnName(), SynonymConcept.class)
                : getSynonymsFor(guid);

        // get congruent concepts
        // List<TaxonConcept> congruentTcs = getCongruentConceptsFor(guid);

        // treat congruent objects the same way we do synonyms
        // synonyms.addAll(congruentTcs);

        // get common names
        List<CommonName> commonNames = scanner != null
                ? (List) scanner.getListValue(ColumnType.VERNACULAR_COL.getColumnName(), CommonName.class)
                : getCommonNamesFor(guid);

        // add the parent id to enable tree browsing with this index
        List<TaxonConcept> children = scanner != null
                ? (List) scanner.getListValue(ColumnType.IS_PARENT_COL_OF.getColumnName(), TaxonConcept.class)
                : getChildConceptsFor(guid);

        // add conservation and pest status'
        List<ConservationStatus> conservationStatuses = scanner != null
                ? (List) scanner.getListValue(ColumnType.CONSERVATION_STATUS_COL.getColumnName(),
                        ConservationStatus.class)
                : getConservationStatuses(guid);
        // List<PestStatus> pestStatuses = getPestStatuses(guid);

        List<Category> categories = scanner != null
                ? (List) scanner.getListValue(ColumnType.CATEGORY_COL.getColumnName(), Category.class)
                : getCategories(guid);

        // add text properties
        List<SimpleProperty> simpleProperties = scanner != null
                ? (List) scanner.getListValue(ColumnType.TEXT_PROPERTY_COL.getColumnName(),
                        SimpleProperty.class)
                : getTextPropertiesFor(guid);

        // save all infosource ids to add in a Set to index at the end
        Set<String> infoSourceIds = new TreeSet<String>();
        Set<String> infoSourceUids = new TreeSet<String>();

        // get alternative ids
        List<String> identifiers = scanner != null
                ? (List) scanner.getListValue(ColumnType.IDENTIFIER_COL.getColumnName(), String.class)
                : getIdentifiers(guid);

        List<TaxonConcept> otherTaxonConcepts = scanner != null
                ? (List) scanner.getListValue(ColumnType.SAME_AS_COL.getColumnName(), TaxonConcept.class)
                : getSameAsFor(guid);

        // TODO this index should also include nub ids
        SolrInputDocument doc = new SolrInputDocument();

        //if the doc is an ala generated concept include a flag
        if (guid.startsWith("ALA"))
            doc.addField("is_ala_b", "true");

        //add the "isExcluded" value
        doc.addField("is_excluded_b", taxonConcept.getIsExcluded());

        doc.addField("idxtype", IndexedTypes.TAXON);

        // is this species iconic
        Boolean iconic = null;
        Boolean australian = null;
        if (scanner != null) {
            iconic = (Boolean) scanner.getValue(ColumnType.IS_ICONIC.getColumnName(), Boolean.class);
            if (iconic == null)
                iconic = false;
            australian = (Boolean) scanner.getValue(ColumnType.IS_AUSTRALIAN.getColumnName(), Boolean.class);
            if (australian == null)
                australian = false;
        }
        Boolean isAustralian = australian == null ? isAustralian(guid) : australian;
        boolean isIconic = iconic == null ? isIconic(guid) : iconic;
        // does this taxon have occurrence records associated with it?
        Integer count = scanner != null
                ? (Integer) scanner.getValue(ColumnType.OCCURRENCE_RECORDS_COUNT_COL.getColumnName(),
                        Integer.class)
                : getOccurrenceRecordCount(guid);
        // boolean isGs=count != null && count.size() >0 && count.get(0)>0;
        if (count != null) {
            doc.addField("occurrenceCount", count);
        }
        //Index the Georeferenced count
        Integer gsCount = scanner != null
                ? (Integer) scanner.getValue(ColumnType.GEOREF_RECORDS_COUNT_COL.getColumnName(), Integer.class)
                : getGeoreferencedRecordsCount(guid);
        if (gsCount != null) {
            doc.addField("georeferencedCount", gsCount);
        }

        if (taxonConcept.getNameString() != null) {

            doc.addField("id", taxonConcept.getGuid());
            doc.addField("guid", taxonConcept.getGuid());

            for (TaxonConcept tc : otherTaxonConcepts) {
                doc.addField("otherGuid", tc.getGuid());
            }

            for (String identifier : identifiers) {
                doc.addField("otherGuid", identifier);
            }
            // add the numeric checklistbank id
            doc.addField("otherGuid", taxonConcept.getId());

            addToSetSafely(infoSourceIds, taxonConcept.getInfoSourceId());
            addToSetSafely(infoSourceUids, taxonConcept.getInfoSourceUid());

            //TODO do we want to add all the associated TaxonNames???
            TaxonName taxonName = null;
            if (scanner != null) {
                List<TaxonName> tns = (List) scanner.getListValue(ColumnType.TAXONNAME_COL.getColumnName(),
                        TaxonName.class);
                if (tns.size() > 0) {
                    taxonName = tns.get(0);
                }
            } else {
                taxonName = getTaxonNameFor(guid);
            }
            if (taxonName != null && taxonName.getNameComplete() != null) {
                doc.addField("nameComplete", taxonName.getNameComplete());
            } else {
                doc.addField("nameComplete", taxonConcept.getNameString());
            }

            // add multiple forms of the scientific name to the index]
            try {
                addScientificNameToIndex(doc, taxonConcept.getNameString(), taxonConcept.getRankString(),
                        taxonConcept.getRankID());
                //now add the supplied name string as the "sortable" singleScientificName
                doc.addField(SINGLE_SCI_NAME, taxonConcept.getNameString());
            } catch (NullPointerException e) {
                System.out.println("TAXONCONCEPT WITH NPE: " + taxonConcept);
                e.printStackTrace();
            }

            if (taxonConcept.getParentGuid() != null) {
                doc.addField("parentGuid", taxonConcept.getParentGuid());
            }
            if (taxonConcept.getParentId() != null) {
                doc.addField("parentId", taxonConcept.getParentId());
            }

            // add the nested set values
            doc.addField("left", taxonConcept.getLeft());
            doc.addField("right", taxonConcept.getRight());
            doc.addField("author", taxonConcept.getAuthor());

            for (ConservationStatus cs : conservationStatuses) {
                if (cs.getRawStatus() != null) {
                    doc.addField("conservationStatus", cs.getRawStatus(), 0.6f);
                    addToSetSafely(infoSourceIds, cs.getInfoSourceId());
                    addToSetSafely(infoSourceUids, cs.getInfoSourceUid());
                    if (cs.getRegion() != null && Regions.getRegion(cs.getRegion()) != null) {
                        Regions r = Regions.getRegion(cs.getRegion());
                        doc.addField("conservationStatus" + r.getAcronym(), cs.getRawStatus());
                    }
                }
            }

            //add the category information
            for (Category category : categories) {
                //add the category to the "general" field so all categories from all dr's can be filetred on
                doc.addField("category_m_s", category.getCategory());
                //add to a dr specific category so that faceting can be performed on individual DR's categories eg weeds or animal pests.
                doc.addField(category.getInfoSourceUid() + "_category_m_s", category.getCategory());
                //add state limiting facet if necessary
                if (StringUtils.isNotBlank(category.getStateProvince())) {
                    doc.addField("category_" + getStateAbbreviation(category.getStateProvince()) + "_m_s",
                            category.getCategory());
                }
                addToSetSafely(infoSourceUids, category.getInfoSourceUid());
            }

            for (SimpleProperty sp : simpleProperties) {
                // index *Text properties
                if (sp.getName().endsWith("Text")) {
                    // Field textField = new Field("simpleText",
                    // sp.getValue(), Store.YES, Index.ANALYZED);
                    // textField.setBoost(0.4f);
                    doc.addField("simpleText", sp.getValue(), 0.4f);
                    addToSetSafely(infoSourceIds, sp.getInfoSourceId());
                    addToSetSafely(infoSourceUids, sp.getInfoSourceUid());
                }
            }

            // StringBuffer cnStr = new StringBuffer();
            Set<String> commonNameSet = new TreeSet<String>();
            List<String> higherPriorityNames = new ArrayList<String>();
            for (CommonName cn : commonNames) {
                if (cn.getNameString() != null && !cn.getIsBlackListed()) {
                    // normalise the common names for display
                    String commonNameString = WordUtils.capitalizeFully(cn.getNameString());
                    commonNameString.trim();
                    commonNameSet.add(commonNameString);

                    if (cn.isPreferred()) {
                        higherPriorityNames.add(cn.getNameString());
                    }
                    addToSetSafely(infoSourceIds, cn.getInfoSourceId());
                    addToSetSafely(infoSourceUids, cn.getInfoSourceUid());

                    // push CAAB preferred common name up
                    if (cn.getRanking() != null && cn.getRanking() > 90000) {
                        logger.debug("**********: " + cn.getNameString() + " , " + cn.getRanking() + "\n");
                        doc.addField("preferredName", cn.getNameString().trim().toLowerCase());
                    }
                }
            }

            if (commonNameSet.size() > 0) {
                String commonNamesConcat = StringUtils.deleteWhitespace(StringUtils.join(commonNameSet, " "));
                doc.addField("commonNameSort", commonNamesConcat);
                // add each common name separately
                // We need to add all common names to the commonNameExact
                // because the CommonName also stores the "parts" of the
                // common name
                for (String commonName : commonNameSet) {
                    if (isIconic) {
                        doc.addField("commonName", commonName, 100f);
                        doc.addField("commonNameExact", commonName, 100f);
                    } else if (higherPriorityNames.contains(commonName)) {
                        doc.addField("commonName", commonName, 5f);
                        doc.addField("commonNameExact", commonName, 5f);
                    } else {
                        doc.addField("commonName", commonName, 1.4f);
                        doc.addField("commonNameExact", commonName, 1.4f);
                    }
                    // pull apart the common name
                    String[] parts = commonName.split(" ");
                    if (parts.length > 1) {
                        String lastPart = parts[parts.length - 1];
                        if (isIconic) {
                            doc.addField("commonName", lastPart, 100f);
                        } else {
                            doc.addField("commonName", lastPart, 2.5f);
                        }
                    }
                }

                doc.addField("commonNameDisplay", StringUtils.join(commonNameSet, ", "));
                doc.addField("commonNameSingle", commonNames.get(0).getNameString().trim());
            }
            String lastNameLsid = null;
            for (SynonymConcept synonym : synonyms) {
                if (synonym.getNameString() != null
                        && (synonym.getNameGuid() != null && !synonym.getNameGuid().equals(lastNameLsid))) {
                    lastNameLsid = synonym.getNameGuid();
                    logger.debug("adding synonym to index: " + synonym.getNameString());
                    // add a new document for each synonym
                    SolrInputDocument synonymDoc = new SolrInputDocument();
                    synonymDoc.addField("id", synonym.getGuid() + taxonConcept.getGuid());//combination of the 2 uniquely identifies a synonym
                    synonymDoc.addField("syn_guid", synonym.getGuid());
                    synonymDoc.addField("guid", taxonConcept.getGuid());
                    synonymDoc.addField("idxtype", IndexedTypes.TAXON);
                    addScientificNameToIndex(synonymDoc, synonym.getNameString(), null, -1);
                    synonymDoc.addField("acceptedConceptName", taxonConcept.getNameString());
                    if (!commonNames.isEmpty()) {
                        synonymDoc.addField("commonNameSort", commonNames.get(0).getNameString());
                        synonymDoc.addField("commonNameDisplay", StringUtils.join(commonNameSet, ", "));
                    }
                    addRankToIndex(synonymDoc, taxonConcept.getRankString(), taxonConcept.getRankID(),
                            taxonConcept.getRawRankString());
                    //add the synonym author
                    synonymDoc.addField("author", synonym.getAuthor());

                    //set the concept as australian if the "accepted" concept is australian
                    if (isAustralian != null && isAustralian) {
                        synonymDoc.addField("australian_s", "recorded");
                        synonymDoc.addField("aus_s", "yes");
                    }
                    //add the synonym type
                    synonymDoc.addField("synonymRelationship_s", synonym.getRelationship());
                    synonymDoc.addField("synonymDescription_s", synonym.getDescription());

                    // add the synonym as a separate document
                    docsToAdd.add(synonymDoc);
                    // store the source
                    if (synonym.getInfoSourceId() != null) {
                        infoSourceIds.add(synonym.getInfoSourceId()); // getting
                        // NPE
                    }
                    addToSetSafely(infoSourceUids, synonym.getInfoSourceUid());
                }
            }

            List<Classification> classifications = scanner != null
                    ? (List) scanner.getListValue(ColumnType.CLASSIFICATION_COL.getColumnName(),
                            Classification.class)
                    : getClassifications(guid);

            for (Classification classification : classifications) {
                addIfNotNull(doc, "kingdom", classification.getKingdom());
                addIfNotNull(doc, "phylum", classification.getPhylum());
                addIfNotNull(doc, "class", classification.getClazz());
                addIfNotNull(doc, "bioOrder", classification.getOrder());
                addIfNotNull(doc, "family", classification.getFamily());
                addIfNotNull(doc, "genus", classification.getGenus());

                //if we have something higher than a genus, add groups
                if (classification.getRankId() != null && classification.getRankId() > 6000) {
                    List<String> speciesGroups = speciesGroupsUtil.getSpeciesGroup(classification);
                    for (String g : speciesGroups) {
                        doc.addField("speciesGroup", g);
                    }
                    List<String> speciesSubgroups = speciesGroupsUtil.getSpeciesSubgroup(classification);
                    for (String g : speciesSubgroups) {
                        doc.addField("speciesSubgroup", g);
                    }
                }
            }

            //check valid image (not blacklisted)
            List<Image> images = scanner != null
                    ? (List) scanner.getListValue(ColumnType.IMAGE_COL.getColumnName(), Image.class)
                    : getImages(guid);

            boolean hasImages = false;
            int firstValidImage = -1;
            int imageCount = 0;
            Set<String> imageSources = new HashSet<String>();
            if (!images.isEmpty()) {
                for (int i = 0; i < images.size(); i++) {
                    Image image = images.get(i);
                    if (!image.getIsBlackListed()) {
                        if (firstValidImage < 0) {
                            firstValidImage = i;
                            hasImages = true;
                        }
                        imageCount++;
                        imageSources.add(image.getInfoSourceUid());
                    }
                }
            }

            //get image count (non-blacklisted sources only)
            doc.addField("imageCount", imageCount);
            //get infosource count  (non-blacklisted sources only)
            doc.addField("imagesSourceCount", imageSources.size());
            //get infosource count  (non-blacklisted sources only)
            for (String imageSource : imageSources)
                doc.addField("imageSources", imageSource);

            if (hasImages && firstValidImage >= 0) {
                // FIXME should be replaced by the highest ranked image
                Image image = images.get(firstValidImage);
                if (image.getRepoLocation() != null) {
                    doc.addField("image", image.getRepoLocation());
                    try {
                        String imageInfosourceId = getImageInfosourceId(image.getRepoLocation());
                        logger.debug("!!!" + imageInfosourceId);
                        infoSourceIds.add(imageInfosourceId);
                        addToSetSafely(infoSourceUids, image.getInfoSourceUid());
                    } catch (Exception e) {
                        logger.warn("Image infosourceId could not be retrieved");
                    }
                    // Change to adding this in earlier
                    String thumbnail = image.getRepoLocation().replace("raw", "thumbnail");
                    doc.addField("thumbnail", thumbnail);
                    doc.addField("imageSource", image.getInfoSourceUid());
                } else {
                    logger.error("Error adding image to concept: " + image);
                }
            }

            doc.addField("hasImage", hasImages);

            if (isAustralian != null && isAustralian) {
                doc.addField("australian_s", "recorded");
                doc.addField("aus_s", "yes");
            }

            String linkIdentifier = scanner != null
                    ? (String) scanner.getValue(ColumnType.LINK_IDENTIFIER.getColumnName(), String.class)
                    : getLinkIdentifier(guid);
            if (linkIdentifier != null) {
                doc.addField("linkIdentifier", linkIdentifier);
            }

            addRankToIndex(doc, taxonConcept.getRankString(), taxonConcept.getRankID(),
                    taxonConcept.getRawRankString());

            doc.addField("hasChildren", Boolean.toString(!children.isEmpty()));
            //doc.addField("dataset", StringUtils.join(infoSourceIds, " "));
            //Add all the dataset id's individually so that they can be searched indivdually
            for (String iid : infoSourceIds) {
                doc.addField("dataset", iid);
            }
            for (String uid : infoSourceUids) {
                doc.addField("uid", uid);
            }
            docsToAdd.add(doc);
        }
    }
    return docsToAdd;
}

From source file:org.apache.hadoop.hive.ql.exec.vector.expressions.StringInitCap.java

public StringInitCap(int colNum, int outputColumn) {
    super(colNum, outputColumn, new IUDFUnaryString() {

        Text t = new Text();

        @Override/*from www . j  av  a2 s  . c  om*/
        public Text evaluate(Text s) {
            if (s == null) {
                return null;
            }
            t.set(WordUtils.capitalizeFully(s.toString()));
            return t;
        }
    });
}

From source file:org.apache.hadoop.hive.ql.udf.generic.GenericUDFInitCap.java

@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
    String val = getStringValue(arguments, 0, converters);
    if (val == null) {
        return null;
    }//from  w w w. j  a va  2  s . c  o  m

    String valCap = WordUtils.capitalizeFully(val);
    output.set(valCap);
    return output;
}

From source file:org.apache.myfaces.custom.convertStringUtils.StringUtilsConverter.java

private String format(String val, boolean duringOutput) throws ConverterException {

    String str;//from w w w  .ja  v  a 2  s . c o m
    if (BooleanUtils.isTrue(trim)) {
        str = val.trim();
    } else {
        str = val;
    }
    // Any decorations first
    if (StringUtils.isNotEmpty(format)) {
        if ("uppercase".equalsIgnoreCase(format)) {
            str = StringUtils.upperCase(str);
        } else if ("lowercase".equalsIgnoreCase(format)) {
            str = StringUtils.lowerCase(str);
        } else if ("capitalize".equalsIgnoreCase(format)) {
            str = WordUtils.capitalizeFully(str);
        } else {
            throw new ConverterException("Invalid format '" + format + "'");
        }
    }

    boolean appendEllipses = ((duringOutput)
            && ((null != appendEllipsesDuringOutput) && (appendEllipsesDuringOutput.booleanValue())))
            || ((false == duringOutput)
                    && ((null != appendEllipsesDuringInput) && (appendEllipsesDuringInput.booleanValue())));

    if (appendEllipses) {
        // See if we need to abbreviate/truncate this string
        if (null != maxLength && maxLength.intValue() > 4) {
            str = StringUtils.abbreviate(str, maxLength.intValue());
        }
    } else {
        // See if we need to truncate this string
        if (null != maxLength) {
            str = str.substring(0, maxLength.intValue());
        }
    }
    return str;
}

From source file:org.apache.oodt.cas.product.jaxrs.configurations.RdfConfiguration.java

/**
 * Creates an {@link Element} for a {@link Document}.
 * @param key a map key used to search this configuration's maps
 * @param value the value for the element
 * @param document the document context of the element
 * @return a new element constructed within the rules and constraints of this
 * configuration//ww w .ja v  a 2  s . co  m
 */
public Element createElement(String key, String value, Document document) {
    // Apply the rewrite rules.
    String tagName = rewriteMap.containsKey(key) ? rewriteMap.get(key) : key;
    if (tagName.contains(" ")) {
        tagName = StringUtils.join(WordUtils.capitalizeFully(tagName).split(" "));
    }

    // Get the tag's namespace or the default namespace.
    String namespace = keyNsMap.containsKey(key) ? keyNsMap.get(key) : defaultKeyNs;

    // Create the element.
    Element element;
    if (resLinkMap.containsKey(key)) {
        element = document.createElement(namespace + ":" + tagName);
        String linkBase = resLinkMap.get(key);
        linkBase += linkBase.endsWith("/") ? "" : "/";
        element.setAttribute(RDF_RES_ATTR, linkBase + value);
    } else {
        element = document.createElement(namespace + ":" + tagName);
        element.appendChild(document.createTextNode(StringEscapeUtils.escapeXml(value)));
    }

    return element;
}

From source file:org.apache.oodt.cas.product.jaxrs.configurations.RssConfiguration.java

/**
 * Appends elements (tags) defined in a configuration file to a specific
 * parent element./*www.  j  av  a2s  .co  m*/
 * @param metadata the metadata for the product
 * @param document the document to which these elements belong
 * @param parent the parent element to attach these elements to
 */
public void appendTags(Metadata metadata, Document document, Element parent) {
    for (RssTag tag : tagList) {
        String tagName = tag.getName();
        if (tagName.contains(" ")) {
            tagName = StringUtils.join(WordUtils.capitalizeFully(tagName).split(" "));
        }

        // Create a new element for the tag.
        Element element = XMLUtils.addNode(document, parent, tagName);

        // Add a value for the tag from the tag source.
        if (tag.getSource() != null) {
            element.appendChild(document.createTextNode(
                    StringEscapeUtils.escapeXml(PathUtils.replaceEnvVariables(tag.getSource(), metadata))));
        }

        // Add attributes to the tag as defined in the configuration.
        for (RssTagAttribute attribute : tag.getAttributes()) {
            element.setAttribute(attribute.getName(),
                    PathUtils.replaceEnvVariables(attribute.getValue(), metadata));
        }
    }
}