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

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

Introduction

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

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:org.adaptto.rookie.demo.components.DiscussionComment.java

private String escapeHtml(String value) {
    return StringEscapeUtils.escapeHtml(StringUtils.defaultString(value));
}

From source file:org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity.java

public String getDesiredStackVersion() {
    return StringUtils.defaultString(desiredStackVersion);
}

From source file:org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryStorage.java

@Override
public String getFilePath(String requestPath, ManagedRepository managedRepository) {
    // managedRepository can be null
    // extract artifact reference from url
    // groupId:artifactId:version:packaging:classifier
    //org/apache/archiva/archiva-checksum/1.4-M4-SNAPSHOT/archiva-checksum-1.4-M4-SNAPSHOT.jar
    String logicalResource = null;
    String requestPathInfo = StringUtils.defaultString(requestPath);

    //remove prefix ie /repository/blah becomes /blah
    requestPathInfo = removePrefix(requestPathInfo);

    // Remove prefixing slash as the repository id doesn't contain it;
    if (requestPathInfo.startsWith("/")) {
        requestPathInfo = requestPathInfo.substring(1);
    }//from   w  w w  . j  ava2  s.  c  o m

    int slash = requestPathInfo.indexOf('/');
    if (slash > 0) {
        logicalResource = requestPathInfo.substring(slash);

        if (logicalResource.endsWith("/..")) {
            logicalResource += "/";
        }

        if (logicalResource != null && logicalResource.startsWith("//")) {
            logicalResource = logicalResource.substring(1);
        }

        if (logicalResource == null) {
            logicalResource = "/";
        }
    } else {
        logicalResource = "/";
    }
    return logicalResource;

}

From source file:org.apache.archiva.model.ArchivaArtifact.java

public ArchivaArtifact(String groupId, String artifactId, String version, String classifier, String type,
        String repositoryId) {//w w w.  j  av a2  s. c o  m
    if (empty(groupId)) {
        throw new IllegalArgumentException("Unable to create ArchivaArtifact with empty groupId ["
                + Keys.toKey(groupId, artifactId, version, classifier, type) + "]");
    }

    if (empty(artifactId)) {
        throw new IllegalArgumentException("Unable to create ArchivaArtifact with empty artifactId ["
                + Keys.toKey(groupId, artifactId, version, classifier, type) + "]");
    }

    if (empty(version)) {
        throw new IllegalArgumentException("Unable to create ArchivaArtifact with empty version ["
                + Keys.toKey(groupId, artifactId, version, classifier, type) + "]");
    }

    if (empty(type)) {
        throw new IllegalArgumentException("Unable to create ArchivaArtifact with empty type ["
                + Keys.toKey(groupId, artifactId, version, classifier, type) + "]");
    }

    if (empty(repositoryId)) {
        throw new IllegalArgumentException("Unable to create ArchivaArtifact with empty repositoryId ["
                + Keys.toKey(groupId, artifactId, version, classifier, type) + "]");
    }

    model = new ArchivaArtifactModel();

    model.setGroupId(groupId);
    model.setArtifactId(artifactId);
    model.setVersion(version);
    model.setClassifier(StringUtils.defaultString(classifier));
    model.setType(type);
    model.setSnapshot(VersionUtil.isSnapshot(version));
    model.setRepositoryId(repositoryId);

    this.baseVersion = VersionUtil.getBaseVersion(version);
}

From source file:org.apache.archiva.model.Keys.java

public static String toKey(String groupId, String artifactId, String version, String classifier, String type) {
    StringBuilder key = new StringBuilder();

    key.append(groupId).append(":");
    key.append(artifactId).append(":");
    key.append(version).append(":");
    key.append(StringUtils.defaultString(classifier)).append(":");
    key.append(type);/* w  w w .  j  a  va 2s.c o  m*/

    return key.toString();
}

From source file:org.apache.archiva.webdav.util.RepositoryPathUtil.java

public static String getRepositoryName(final String href) {
    String requestPathInfo = StringUtils.defaultString(href);

    //remove prefix ie /repository/blah becomes /blah
    requestPathInfo = removePrefix(requestPathInfo);

    // Remove prefixing slash as the repository id doesn't contain it;
    if (requestPathInfo.startsWith("/")) {
        requestPathInfo = requestPathInfo.substring(1);
    }//from  w  w  w .j ava2 s  .  co m

    // Find first element, if slash exists.
    int slash = requestPathInfo.indexOf('/');
    if (slash > 0) {
        // Filtered: "central/org/apache/maven/" -> "central"
        return requestPathInfo.substring(0, slash);
    }
    return requestPathInfo;
}

From source file:org.apache.click.util.ClickUtils.java

/**
 * Return the given control CSS selector or null if no selector can be found.
 * <p/>/* w ww.  j  av  a 2 s.  co  m*/
 * <b>Please note:</b> it is highly recommended to set a control's ID
 * attribute when dealing with Ajax requests.
 * <p/>
 * The CSS selector is calculated as follows:
 * <ol>
 *   <li>if control.getId() is set, prepend it with a '#' char
 *       and return the value. An example selector will be: <tt>#field-id</tt>
 *   </li>
 *
 *   <li>if control.getName() is set do the following:
 *     <ol>
 *       <li>if the control is of type {@link org.apache.click.control.ActionLink},
 *       it's "<tt>class</tt>" attribute selector will be returned. For example:
 *       <tt>a[class=red]</tt>. <b>Please note:</b> if the link class attribute is
 *       not set, the class attribute will be set to its name, prefixed with
 *       a dash, '-'. For example: <tt>a[class=-my-link]</tt>.
 *       </li>
 *
 *       <li>if the control is not an ActionLink, it is assumed the control
 *       will render its "<tt>name</tt>" attribute and the name attribute
 *       selector will be returned. For example: <tt>input[name=my-button]</tt>.
 *       </li>
 *     </ol>
 *   </li>
 *
 *   <li>otherwise return null.
 *   </li>
 * </ol>
 *
 * @param control the control which CSS selector to return
 * @return the control CSS selector or null if no selector can be found
 * @throws IllegalArgumentException if control is null
 */
public static String getCssSelector(Control control) {
    if (control == null) {
        throw new IllegalArgumentException("Control cannot be null");
    }

    String id = control.getId();
    String name = control.getName();
    String cssSelector = null;

    if (StringUtils.isNotBlank(id)) {
        cssSelector = '#' + id;
    } else if (StringUtils.isNotBlank(name)) {
        String tag = null;

        // Try and create a more specific selector by retrieving the
        // control's tag
        if (control instanceof AbstractControl) {
            tag = StringUtils.defaultString(((AbstractControl) control).getTag());
        }

        HtmlStringBuffer buffer = new HtmlStringBuffer(20);

        // Handle ActionLink (perhaps other link controls too?) differently
        // as it doesn't render the "name" attribute. The "name" attribute
        // is used by links for bookmarking purposes. Instead set the class
        // attribute to the link's name and use that as the selector.
        if (control instanceof ActionLink) {
            ActionLink link = (ActionLink) control;
            if (!link.hasAttribute("class")) {
                link.setAttribute("class", '-' + name);
            }
            buffer.append(tag).append("[class*=");
            buffer.append(link.getAttribute("class")).append("]");

        } else {
            buffer.append(tag).append("[name=");
            buffer.append(name).append("]");
        }
        cssSelector = buffer.toString();
    }
    return cssSelector;
}

From source file:org.apache.cocoon.template.instruction.Call.java

public Call(ParsingContext parsingContext, StartElement raw, Attributes attrs, Stack stack)
        throws SAXException {
    super(raw);//  w  w w .  ja va  2 s.  c  om
    this.parameters = new HashMap();
    Locator locator = getLocation();

    String name = attrs.getValue("macro");
    if (name == null) {
        throw new SAXParseException("if: \"test\" is required", locator, null);
    }
    this.macro = parsingContext.getStringTemplateParser().compileExpr(name, "call: \"macro\": ", locator);

    String namespace = StringUtils.defaultString(attrs.getValue("targetNamespace"));
    this.targetNamespace = parsingContext.getStringTemplateParser().compileExpr(namespace,
            "call: \"targetNamespace\": ", locator);
}

From source file:org.apache.cocoon.template.instruction.Define.java

public Define(ParsingContext parsingContext, StartElement raw, Attributes attrs, Stack stack)
        throws SAXException {

    super(raw);//  w  ww  . j  a v a 2s. c  om

    // <macro name="myTag" targetNamespace="myNamespace">
    // <parameter name="paramName" required="Boolean"
    // default="value"/>
    // body
    // </macro>
    this.namespace = StringUtils.defaultString(attrs.getValue("targetNamespace"));
    this.name = attrs.getValue("name");
    if (this.name == null) {
        throw new SAXParseException("macro: \"name\" is required", getLocation(), null);
    }

    this.qname = "{" + namespace + "}" + name;
    this.parameters = new HashMap();
}

From source file:org.apache.hadoop.hive.metastore.MetaStoreUtils.java

/**
 * Given a list of partition columns and a partial mapping from
 * some partition columns to values the function returns the values
 * for the column.//from  w ww . j  a  va 2 s  . c  o m
 * @param partCols the list of table partition columns
 * @param partSpec the partial mapping from partition column to values
 * @return list of values of for given partition columns, any missing
 *         values in partSpec is replaced by an empty string
 */
public static List<String> getPvals(List<FieldSchema> partCols, Map<String, String> partSpec) {
    List<String> pvals = new ArrayList<String>(partCols.size());
    for (FieldSchema field : partCols) {
        String val = StringUtils.defaultString(partSpec.get(field.getName()));
        pvals.add(val);
    }
    return pvals;
}