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

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

Introduction

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

Prototype

public static String capitalize(final String str) 

Source Link

Document

Capitalizes a String changing the first letter to title case as per Character#toTitleCase(char) .

Usage

From source file:org.gvnix.web.screen.roo.addon.EntityBatchMetadata.java

/**
 * Generate a setter for <code>field</code>
 * /*from ww w . j a  v a 2 s . co  m*/
 * @param field field metadata
 * @return
 */
private MethodMetadataBuilder getListInner_setter(FieldMetadata field) {
    // Gets filed name
    String fieldName = field.getFieldName().getSymbolName();

    // prepares method body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine(MessageFormat.format("this.{0} = {0};", new Object[] { fieldName }));

    // Create method builder
    MethodMetadataBuilder builder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
            new JavaSymbolName("set".concat(StringUtils.capitalize(fieldName))), JavaType.VOID_PRIMITIVE,
            bodyBuilder);

    // Adds setter parameter
    List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
    builder.addParameterType(new AnnotatedJavaType(field.getFieldType(), annotations));
    builder.addParameterName(field.getFieldName());

    return builder;
}

From source file:org.gwt.json.serialization.AccessorResolveUtil.java

private static void populateSetAccessor(JField jField, JClassType jClassType, FieldInfo fieldInfo) {
    String accessorName = "set" + StringUtils.capitalize(jField.getName());
    JType[] types = new JType[1];
    types[0] = jField.getType();//w ww .ja  v a 2 s .c om

    try {
        jClassType.getMethod(accessorName, types);
        fieldInfo.setSetAccessorName(accessorName);
    } catch (NotFoundException e) {
        //ignore
    }
}

From source file:org.gwt.json.serialization.AccessorResolveUtil.java

private static void populateGetAccessor(JField jField, JClassType jClassType, FieldInfo fieldInfo) {
    String accessorName = "get" + StringUtils.capitalize(jField.getName());
    try {//  w  w w. ja  v a  2 s .c  o m
        jClassType.getMethod(accessorName, new JType[0]);
        fieldInfo.setGetAccessorName(accessorName);
    } catch (NotFoundException e) {
        //try 'is' accessor
        if (jField.getType().getQualifiedSourceName().equals(Boolean.class.getName())
                || jField.getType().getQualifiedSourceName().equals("boolean")) {
            accessorName = "is" + StringUtils.capitalize(jField.getName());
            try {
                jClassType.getMethod(accessorName, new JType[0]);
                fieldInfo.setGetAccessorName(accessorName);
            } catch (NotFoundException ex) {
                //ignore
            }
        }
    }

}

From source file:org.hibernate.ejb.metamodel.AbstractAttribute.java

public String getHumanName() {
    return StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(StringUtils.capitalize(this.getName())),
            ' ');
}

From source file:org.jamwiki.db.AnsiDataHandler.java

/**
 *
 */// ww  w . j a  va 2s .c  o  m
private void addTopicLinks(List<String> links, String virtualWiki, int topicId, Connection conn)
        throws DataAccessException {
    // strip any links longer than 200 characters and any duplicates
    Map<String, Topic> linksMap = new HashMap<String, Topic>();
    for (String link : links) {
        if (link.length() <= 200) {
            Namespace namespace = LinkUtil.retrieveTopicNamespace(virtualWiki, link);
            String pageName = LinkUtil.retrieveTopicPageName(namespace, virtualWiki, link);
            // FIXE - link to records are always capitalized, which will cause problems for the
            // rare case of two topics such as "eBay" and "EBay".
            pageName = StringUtils.capitalize(pageName);
            Topic topic = new Topic(virtualWiki, namespace, pageName);
            linksMap.put(topic.getName(), topic);
        }
    }
    List<Topic> topicLinks = new ArrayList<Topic>(linksMap.values());
    try {
        this.queryHandler().insertTopicLinks(topicLinks, topicId, conn);
    } catch (SQLException e) {
        throw new DataAccessException(e);
    }
}

From source file:org.jamwiki.db.AnsiDataHandler.java

/**
 *
 *///from   www .j ava  2  s.  c om
private Topic lookupTopic(String virtualWiki, Namespace namespace, String pageName, boolean deleteOK,
        Connection conn) throws DataAccessException {
    long start = System.currentTimeMillis();
    String key = this.cacheTopicKey(virtualWiki, namespace, pageName);
    if (conn == null) {
        // retrieve topic from the cache only if this call is not currently a part
        // of a transaction to avoid retrieving data that might have been updated
        // as part of this transaction and would thus now be out of date
        Integer cacheTopicId = CACHE_TOPIC_IDS_BY_NAME.retrieveFromCache(key);
        if (cacheTopicId != null || CACHE_TOPIC_IDS_BY_NAME.isKeyInCache(key)) {
            Topic cacheTopic = (cacheTopicId != null) ? this.lookupTopicById(cacheTopicId.intValue(), conn)
                    : null;
            return (cacheTopic == null || (!deleteOK && cacheTopic.getDeleteDate() != null)) ? null
                    : cacheTopic;
        }
    }
    boolean checkSharedVirtualWiki = this.useSharedVirtualWiki(virtualWiki, namespace);
    String sharedVirtualWiki = Environment.getValue(Environment.PROP_SHARED_UPLOAD_VIRTUAL_WIKI);
    if (conn == null && checkSharedVirtualWiki) {
        String sharedKey = this.cacheTopicKey(sharedVirtualWiki, namespace, pageName);
        Integer cacheTopicId = CACHE_TOPIC_IDS_BY_NAME.retrieveFromCache(sharedKey);
        if (cacheTopicId != null || CACHE_TOPIC_IDS_BY_NAME.isKeyInCache(sharedKey)) {
            Topic cacheTopic = (cacheTopicId != null) ? this.lookupTopicById(cacheTopicId.intValue(), conn)
                    : null;
            return (cacheTopic == null || (!deleteOK && cacheTopic.getDeleteDate() != null)) ? null
                    : cacheTopic;
        }
    }
    Topic topic = null;
    try {
        int virtualWikiId = this.lookupVirtualWikiId(virtualWiki);
        topic = this.queryHandler().lookupTopic(virtualWikiId, namespace, pageName, conn);
        if (topic == null && Environment.getBooleanValue(Environment.PROP_PARSER_ALLOW_CAPITALIZATION)) {
            String alternativePageName = (StringUtils.equals(pageName, StringUtils.capitalize(pageName)))
                    ? StringUtils.lowerCase(pageName)
                    : StringUtils.capitalize(pageName);
            topic = this.queryHandler().lookupTopic(virtualWikiId, namespace, alternativePageName, conn);
        }
        if (topic == null && checkSharedVirtualWiki) {
            topic = this.lookupTopic(sharedVirtualWiki, namespace, pageName, deleteOK, conn);
        }
        if (conn == null) {
            // add topic to the cache only if it is not currently a part of a transaction
            // to avoid caching something that might need to be rolled back.
            if (topic == null) {
                CACHE_TOPIC_IDS_BY_NAME.addToCache(key, null);
                CACHE_TOPIC_NAMES_BY_NAME.addToCache(key, null);
            } else {
                this.cacheTopicRefresh(topic, false, key);
            }
        }
    } catch (SQLException e) {
        throw new DataAccessException(e);
    }
    if (logger.isDebugEnabled()) {
        long execution = (System.currentTimeMillis() - start);
        if (execution > TIME_LIMIT_TOPIC_LOOKUP) {
            logger.debug("Slow topic lookup for: " + Topic.buildTopicName(virtualWiki, namespace, pageName)
                    + " (" + (execution / 1000.000) + " s)");
        }
    }
    return (topic == null || (!deleteOK && topic.getDeleteDate() != null)) ? null : topic;
}

From source file:org.jamwiki.db.AnsiDataHandler.java

/**
 * Find the names for all topics that link to a specified topic.
 *
 * @param virtualWiki The virtual wiki for the topic.
 * @param topicName The name of the topic.
 * @return A list of topic name and (for redirects) the redirect topic
 *  name for all topics that link to the specified topic.  If no results
 *  are found then an empty list is returned.
 * @throws DataAccessException Thrown if any error occurs during method execution.
 *//*from   w ww  .  ja  v  a2  s. c o m*/
public List<String[]> lookupTopicLinks(String virtualWiki, String topicName) throws DataAccessException {
    int virtualWikiId = this.lookupVirtualWikiId(virtualWiki);
    Namespace namespace = LinkUtil.retrieveTopicNamespace(virtualWiki, topicName);
    String pageName = LinkUtil.retrieveTopicPageName(namespace, virtualWiki, topicName);
    // FIXE - link to records are always capitalized, which will cause problems for the
    // rare case of two topics such as "eBay" and "EBay".
    pageName = StringUtils.capitalize(pageName);
    Topic topic = new Topic(virtualWiki, namespace, pageName);
    try {
        return this.queryHandler().lookupTopicLinks(virtualWikiId, topic);
    } catch (SQLException e) {
        throw new DataAccessException(e);
    }
}

From source file:org.jamwiki.migrate.MediaWikiXmlImporter.java

/**
 * Initialize the current topic, validating that it does not yet exist.
 *//*  w ww  .ja  va2  s.com*/
private void initCurrentTopic(String topicName) throws SAXException {
    topicName = convertArticleNameFromWikipediaToJAMWiki(topicName);
    WikiLink wikiLink = new WikiLink(null, this.virtualWiki, topicName);
    Topic existingTopic = null;
    try {
        existingTopic = WikiBase.getDataHandler().lookupTopic(this.virtualWiki, topicName, false);
    } catch (DataAccessException e) {
        throw new SAXException("Failure while validating topic name: " + this.virtualWiki + ':' + topicName, e);
    }
    if (existingTopic != null && existingTopic.getVirtualWiki().equals(this.virtualWiki)) {
        // do a second comparison of capitalized topic names in a case-sensitive way
        // since the initial topic lookup will return a case-insensitive match for some
        // namespaces.
        String existingTopicName = (Environment.getBooleanValue(Environment.PROP_PARSER_ALLOW_CAPITALIZATION))
                ? StringUtils.capitalize(existingTopic.getPageName())
                : existingTopic.getPageName();
        String importTopicName = (Environment.getBooleanValue(Environment.PROP_PARSER_ALLOW_CAPITALIZATION))
                ? StringUtils.capitalize(wikiLink.getArticle())
                : wikiLink.getArticle();
        if (StringUtils.equals(existingTopicName, importTopicName)) {
            // FIXME - update so that this merges any new versions instead of throwing an error
            WikiException e = new WikiException(new WikiMessage("import.error.topicexists", topicName));
            throw new SAXException(
                    "Topic " + this.virtualWiki + ':' + topicName + " already exists and cannot be imported",
                    e);
        }
    }
    this.currentTopic = new Topic(this.virtualWiki, wikiLink.getNamespace(), wikiLink.getArticle());
    this.currentTopic.setTopicType(WikiUtil.findTopicTypeForNamespace(wikiLink.getNamespace()));
}

From source file:org.jamwiki.parser.LinkUtil.java

/**
 * Utility method for building a URL link to a wiki edit page for a
 * specified topic./*from  www. j av  a 2  s .com*/
 *
 * @param context The servlet context for the link that is being created.
 * @param virtualWiki The virtual wiki for the link that is being created.
 * @param topic The name of the topic for which an edit link is being
 *  created.
 * @param query Any existing query parameters to append to the edit link.
 *  This value may be either <code>null</code> or empty.
 * @param section The section defined by the name parameter within the
 *  HTML page for the topic being edited.  If provided then the edit link
 *  will allow editing of only the specified section.
 * @return A url that links to the edit page for the specified topic.
 *  Note that this method returns only the URL, not a fully-formed HTML
 *  anchor tag.
 * @throws DataAccessException Thrown if any error occurs while builing the link URL.
 */
public static String buildEditLinkUrl(String context, String virtualWiki, String topic, String query,
        int section) throws DataAccessException {
    if (Environment.getBooleanValue(Environment.PROP_PARSER_ALLOW_CAPITALIZATION)) {
        topic = StringUtils.capitalize(topic);
    }
    query = LinkUtil.appendQueryParam(query, "topic", topic);
    if (section > 0) {
        query += "&amp;section=" + section;
    }
    // FIXME - hard coding
    WikiLink wikiLink = new WikiLink(context, virtualWiki, "Special:Edit");
    wikiLink.setQuery(query);
    return wikiLink.toRelativeUrl();
}

From source file:org.jamwiki.parser.LinkUtil.java

/**
 * Utility method for determining if an article name corresponds to a valid
 * wiki link.  In this case an "article name" could be an existing topic, a
 * "Special:" page, a user page, an interwiki link, etc.  This method will
 * return the article name if the given name corresponds to a valid special
 * page, user page, topic, or other existing article, or <code>null</code>
 * if no valid article exists.//from   www.  ja  v a2 s.  c o m
 *
 * @param virtualWiki The virtual wiki for the topic being checked.
 * @param articleName The name of the article that is being checked.
 * @return The article name if the given name and virtual wiki correspond
 *  to a valid special page, user page, topic, or other existing article,
 *  or <code>null</code> if no valid article exists.
 * @throws DataAccessException Thrown if an error occurs during lookup.
 */
public static String isExistingArticle(String virtualWiki, String articleName) throws DataAccessException {
    if (StringUtils.isBlank(virtualWiki) || StringUtils.isBlank(articleName)) {
        return null;
    }
    WikiLink wikiLink = new WikiLink(null, virtualWiki, articleName);
    if (PseudoTopicHandler.isPseudoTopic(wikiLink.getDestination())) {
        return articleName;
    }
    if (wikiLink.getInterwiki() != null) {
        return articleName;
    }
    if (!Environment.isInitialized()) {
        // not initialized yet
        return null;
    }
    String topicName = WikiBase.getDataHandler().lookupTopicName(virtualWiki, wikiLink.getNamespace(),
            wikiLink.getArticle());
    if (topicName == null && Environment.getBooleanValue(Environment.PROP_PARSER_ALLOW_CAPITALIZATION)) {
        String alternativeArticleName = (StringUtils.equals(wikiLink.getArticle(),
                StringUtils.capitalize(wikiLink.getArticle()))) ? StringUtils.lowerCase(wikiLink.getArticle())
                        : StringUtils.capitalize(wikiLink.getArticle());
        topicName = WikiBase.getDataHandler().lookupTopicName(virtualWiki, wikiLink.getNamespace(),
                alternativeArticleName);
    }
    return topicName;
}