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.apache.hadoop.hive.metastore.utils.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   ww w .  ja v  a 2 s . com
 * @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<>(partCols.size());
    for (FieldSchema field : partCols) {
        String val = StringUtils.defaultString(partSpec.get(field.getName()));
        pvals.add(val);
    }
    return pvals;
}

From source file:org.apache.jetspeed.portlets.clone.PortletCloneManagerPortlet.java

@Override
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String status = "fail";
    ClonePortletInfo clonePortletInfo = readClonePortletInfoFromRequest(request);
    PortletDefinition def = registry//from w w w.  j  av a 2s  .c o m
            .getPortletDefinitionByUniqueName(clonePortletInfo.getOriginalPortletUniqueName());

    try {
        if (def == null) {
            throw new IllegalArgumentException(
                    "Cannot find the portlet or clone: " + clonePortletInfo.getOriginalPortletUniqueName());
        }

        if (StringUtils.isBlank(clonePortletInfo.getPortletName())) {
            throw new IllegalArgumentException("Invalid clone name: " + clonePortletInfo.getPortletName());
        }

        PortletDefinition clone = registry.clonePortletDefinition(def,
                StringUtils.trim(clonePortletInfo.getPortletName()));
        clone.getPortletInfo().setTitle(StringUtils.defaultString(clonePortletInfo.getPortletTitle()));
        clone.getPortletInfo()
                .setShortTitle(StringUtils.defaultString(clonePortletInfo.getPortletShortTitle()));
        clone.getPortletInfo().setKeywords(StringUtils.defaultString(clonePortletInfo.getPortletKeywords()));

        Locale defaultLocale = Locale.getDefault();
        DisplayName defaultDisplayName = null;

        for (DisplayName displayName : clone.getDisplayNames()) {
            if (displayName.getLocale().equals(defaultLocale)) {
                defaultDisplayName = displayName;
                break;
            }
        }

        if (defaultDisplayName == null) {
            defaultDisplayName = clone.addDisplayName(defaultLocale.toString());
        }

        defaultDisplayName.setDisplayName(StringUtils.defaultString(clonePortletInfo.getPortletDisplayName()));

        for (Map.Entry<String, List<String>> entry : clonePortletInfo.getPortletPreferences().entrySet()) {
            String prefName = entry.getKey();
            List<String> prefValues = entry.getValue();
            Preferences prefs = clone.getPortletPreferences();
            Preference pref = prefs.getPortletPreference(prefName);

            if (pref == null) {
                pref = prefs.addPreference(prefName);
            }

            List<String> values = pref.getValues();
            values.clear();
            values.addAll(prefValues);

            prefProvider.storeDefaults(clone, pref);
        }

        registry.savePortletDefinition(clone);
        status = "success";
    } catch (Exception e) {
        request.getPortletSession(true).setAttribute("errorMessage", e.toString());
        log.error("Failed to clone portlet from " + clonePortletInfo.getOriginalPortletUniqueName() + " to "
                + clonePortletInfo.getPortletName(), e);
    }

    request.getPortletSession(true).setAttribute("status", status);
}

From source file:org.apache.jetspeed.portlets.custom.CustomConfigModePortlet.java

private void addSecurityConstraint(ActionRequest request, ActionResponse response)
        throws PortletException, IOException {
    try {/*from w w w  . jav a2  s  .c o  m*/
        RequestContext requestContext = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
        ContentPage page = requestContext.getPage();
        String fragmentId = request.getParameter("fragment");

        ContentFragment fragment = page.getFragmentById(fragmentId);

        if (fragment == null) {
            throw new PortletException("Cannot find fragment: " + fragmentId);
        }

        SecurityConstraints constraints = new TransientSecurityConstraints(fragment.getSecurityConstraints());
        SecurityConstraint constraint = new TransientSecurityConstraint(fragment.newSecurityConstraint());
        String[] rolesArray = StringUtils.split(request.getParameter("roles"), DELIMITERS);
        String[] groupsArray = StringUtils.split(request.getParameter("groups"), DELIMITERS);
        String[] usersArray = StringUtils.split(request.getParameter("users"), DELIMITERS);

        if (!ArrayUtils.isEmpty(rolesArray)) {
            constraint.setRoles(Arrays.asList(rolesArray));
        }

        if (!ArrayUtils.isEmpty(groupsArray)) {
            constraint.setGroups(Arrays.asList(groupsArray));
        }

        if (!ArrayUtils.isEmpty(usersArray)) {
            constraint.setUsers(Arrays.asList(usersArray));
        }

        String[] permissionArray = StringUtils
                .split(StringUtils.defaultString(request.getParameter("permissions")), DELIMITERS);

        if (!ArrayUtils.isEmpty(permissionArray)) {
            constraint.setPermissions(Arrays.asList(permissionArray));
        }

        List<SecurityConstraint> constraintList = constraints.getSecurityConstraints();

        if (constraintList == null) {
            constraintList = new ArrayList<SecurityConstraint>();
        }

        constraintList.add(constraint);
        constraints.setSecurityConstraints(constraintList);

        pageLayoutComponent.updateSecurityConstraints(fragment, constraints);
    } catch (Exception e) {
        throw new PortletException("Failed to add security constraint.", e);
    }
}

From source file:org.apache.sling.dynamicinclude.IncludeTagFilter.java

private static String sanitize(String path) {
    return StringUtils.defaultString(path);
}

From source file:org.apache.wiki.WikiSession.java

/**
 * Adds a message to the specific set of messages associated with the
 * session. These messages retain their order of insertion and remain until
 * the {@link #clearMessages()} method is called.
 * @param topic the topic to associate the message to;
 * @param message the message to add/*from www  .j a va 2 s .  co  m*/
 */
public final void addMessage(String topic, String message) {
    if (topic == null) {
        throw new IllegalArgumentException("addMessage: topic cannot be null.");
    }
    Set<String> messages = m_messages.get(topic);
    if (messages == null) {
        messages = new LinkedHashSet<String>();
        m_messages.put(topic, messages);
    }
    messages.add(StringUtils.defaultString(message));
}

From source file:org.archive.modules.writer.ARCWriterProcessor.java

private static String replace(String meta, String find, String replace) {
    replace = StringUtils.defaultString(replace);
    replace = StringEscapeUtils.escapeXml(replace);
    return meta.replace(find, replace);
}

From source file:org.artifactory.common.wicket.component.links.BaseTitledLink.java

protected String getCssClass(ComponentTag tag) {
    String oldCssClass = StringUtils.defaultString(tag.getAttributes().getString("class"));
    if (!isEnabled()) {
        return oldCssClass + " button " + oldCssClass + "-disabled button-disabled";
    }/*from   w  w w  . ja v a 2 s .  c o  m*/
    return oldCssClass + " button";
}

From source file:org.artifactory.message.ArtifactoryUpdatesServiceImpl.java

private String messageBody(HttpResponse response) throws IOException {
    String body = EntityUtils.toString(response.getEntity());
    return StringUtils.defaultString(body);
}

From source file:org.axiom_tools.codecs.ModelCodec.java

/**
 * Returns a new model instance./*from   ww  w .  ja v a  2  s .co m*/
 * @param modelXML a model in XML format
 * @return a new model, or null
 */
public ModelType fromXML(String modelXML) {
    if (StringUtils.defaultString(modelXML).isEmpty()) {
        return null;
    }

    try {
        byte[] xmlData = modelXML.getBytes(XML_ENCODING);
        ByteArrayInputStream stream = new ByteArrayInputStream(xmlData);
        return (ModelType) buildJAXBContext().createUnmarshaller().unmarshal(stream);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
        return null;
    }
}

From source file:org.axiom_tools.codecs.ModelCodec.java

/**
 * Returns a new model instance./* w ww. j a va  2s .c o m*/
 * @param modelJSON a model in JSON format
 * @return a new model, or null
 */
public ModelType fromJSON(String modelJSON) {
    if (StringUtils.defaultString(modelJSON).isEmpty()) {
        return null;
    }

    try {
        return buildObjectMapper().readValue(modelJSON, this.entityClass);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
        return null;
    }
}