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

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

Introduction

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

Prototype

public static String stripToNull(String str) 

Source Link

Document

Strips whitespace from the start and end of a String returning null if the String is empty ("") after the strip.

Usage

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.AgentStatusReportExecutorTest.java

private boolean hasEnvironmentVariable(Document document, String name, String value) {
    final Elements elements = document.select(
            MessageFormat.format(".environments .name-value .name-value_pair label:contains({0})", name));
    if (elements.isEmpty()) {
        return false;
    }// w  w w . j av a  2s .c  om

    final String envValueSpanText = StringUtils.stripToNull(elements.get(0).parent().select("span").text());
    return StringUtils.equals(value, envValueSpanText);
}

From source file:gov.nih.nci.calims2.taglib.form.OptionManager.java

/**
 * @param idProperty the idProperty to set
 */
public void setIdProperty(String idProperty) {
    this.idProperty = StringUtils.stripToNull(idProperty);
}

From source file:gov.nih.nci.calims2.taglib.form.OptionManager.java

/**
 * @param labelProperty the labelProperty to set
 *///from   w  ww.  j a v a2  s  . c  o  m
public void setLabelProperty(String labelProperty) {
    this.labelProperty = StringUtils.stripToNull(labelProperty);
}

From source file:com.activecq.samples.clientcontext.impl.ClientContextBuilderImpl.java

@Override
public String getPath(SlingHttpServletRequest request) {
    final String path = StringUtils.stripToNull(getParameterOrAttribute(request, PATH, null));
    if (path == null) {
        return path;
    }/*from  www.j  a va 2  s .c  o  m*/

    final ResourceResolver resourceResolver = request.getResourceResolver();
    return resourceResolver.map(request, path);
}

From source file:gov.nih.nci.calims2.taglib.form.SingleSelectTag.java

/**
 * @param properties the properties to set
 */
public void setProperties(String properties) {
    this.properties = StringUtils.stripToNull(properties);
}

From source file:au.edu.anu.portal.portlets.tweetal.TweetalPortlet.java

/**
 * Process any portlet actions//from ww  w  .  j  a  v a  2s  .c o  m
 */
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {
    String consumerKey = (String) request.getPreferences().getValue("consumerKey", null);
    String consumerSecret = (String) request.getPreferences().getValue("consumerSecret", null);

    twitterLogic.setOAuthConsumer(consumerKey, consumerSecret);

    PortletPreferences pref = request.getPreferences();
    String portletMode = request.getPortletMode().toString();

    if (StringUtils.equalsIgnoreCase(portletMode, "config")) {
        String operation = request.getParameter("operation");

        if (StringUtils.equalsIgnoreCase(operation, "save")) {

            consumerKey = request.getParameter("consumerKey");
            consumerSecret = request.getParameter("consumerSecret");

            try {
                // validate here
                twitterLogic.setOAuthConsumer(consumerKey, consumerSecret);
                if (twitterLogic.validate()) {
                    // Try to set the prefs
                    pref.setValue("consumerKey", consumerKey);
                    pref.setValue("consumerSecret", consumerSecret);
                    log.info("Changing consumer key and secret to ****");

                } else {
                    log.error("Invalid consumer key and secret");
                    response.setRenderParameter("errorMessage", Messages.getString("config_error_register"));
                    return;
                }

            } catch (ReadOnlyException e) {
                response.setRenderParameter("errorMessage", Messages.getString("error_form_readonly"));
                log.error(e);
                return;
            }

            // save the prefs
            try {
                pref.store();
                response.setPortletMode(PortletMode.VIEW);
            } catch (ValidatorException e) {
                response.setRenderParameter("errorMessage", e.getMessage());
                log.error(e);
            } catch (IOException e) {
                response.setRenderParameter("errorMessage", Messages.getString("error_form_save"));
                log.error(e);
            } catch (PortletModeException e) {
                e.printStackTrace();
                log.error(e);
            }

        } else if (StringUtils.equalsIgnoreCase(operation, "cancel")) {
            response.setPortletMode(PortletMode.VIEW);
        }

    } else if (request.getPortletMode().equals(PortletMode.EDIT)) {
        // when user in edit mode
        String operation = request.getParameter("operation");

        if (operation.equalsIgnoreCase("save")) {

            String pin = StringUtils.stripToNull(request.getParameter("authCode"));

            if (StringUtils.isBlank(pin)) {
                response.setRenderParameter("errorMessage", Messages.getString("error_invalid_pin_empty"));
                log.error("Empty pin");
                return;
            }

            AccessToken accessToken = twitterLogic.getAccessToken(requestToken, pin);

            if (accessToken == null) {
                //inline error - check your pin and try again
                response.setRenderParameter("errorMessage", Messages.getString("error_invalid_pin"));
                log.error("AccessToken was null possibly due to an invalid pin");
                return;
            }

            // persist to the accessToken for future reference.
            String userToken = accessToken.getToken();
            String userSecret = accessToken.getTokenSecret();

            // save them to preferences
            pref.setValue("userToken", userToken);
            pref.setValue("userSecret", userSecret);

            // save the prefs
            try {
                pref.store();
                // redirect to view page
                response.setPortletMode(PortletMode.VIEW);
            } catch (ValidatorException e) {
                response.setRenderParameter("errorMessage", e.getMessage());
                log.error(e);
            } catch (IOException e) {
                response.setRenderParameter("errorMessage", Messages.getString("error_form_save"));
                log.error(e);
            } catch (PortletModeException e) {
                e.printStackTrace();
                log.error(e);
            }

        } else if (operation.equalsIgnoreCase("cancel")) {
            response.setPortletMode(PortletMode.VIEW);

        } else if (operation.equalsIgnoreCase("remove")) {
            //remove stuff
            removeUserPreferences(request);
            // redirect to view page
            response.setPortletMode(PortletMode.VIEW);

        } else {
            //log error, unsupported operation
            log.error("Unsupported operation");
        }
    }
}

From source file:com.activecq.tools.errorpagehandler.impl.ErrorPageHandlerImpl.java

/**
 * Find the full path to the most appropriate Error Page
 *
 * @param request/*from   ww w  .j a  v a  2s  . c o  m*/
 * @param errorResource
 * @return
 */
@Override
public String findErrorPage(SlingHttpServletRequest request, Resource errorResource) {
    if (!isEnabled()) {
        return null;
    }

    Resource page = null;
    final ResourceResolver resourceResolver = errorResource.getResourceResolver();

    // Get error page name to look for based on the error code/name
    final String pageName = getErrorPageName(request);

    // Try to find the closest real parent for the requested resource
    final Resource parent = findFirstRealParentOrSelf(errorResource);

    final SortedMap<String, String> errorPagesMap = getErrorPagesMap(resourceResolver);

    if (!errorPagesMap.isEmpty()) {
        // Get the best-matching Errors Path for this particular Request
        final String errorsPath = this.getErrorPagesPath(parent, errorPagesMap);

        if (StringUtils.isNotBlank(errorsPath)) {
            // Search for CQ Page for specific servlet named Page (404, 500, Throwable, etc.)
            SearchResult result = executeQuery(resourceResolver, pageName);
            List<String> errorPaths = filterResults(errorsPath, result);

            // Return the first existing match
            for (String errorPath : errorPaths) {
                page = getResource(resourceResolver, errorPath);
                if (page != null) {
                    break;
                }
            }

            // No error-specific page could be found, use the "default" error page
            // for the Root content path
            if (page == null && StringUtils.isNotBlank(errorsPath)) {
                page = resourceResolver.resolve(errorsPath);
            }
        }
    }

    if (page == null || ResourceUtil.isNonExistingResource(page)) {
        // If no error page could be found
        if (this.hasSystemErrorPage()) {
            final String errorPage = applyExtension(this.getSystemErrorPagePath());
            log.debug("Using default error page: {}", errorPage);
            return StringUtils.stripToNull(errorPage);
        }
    } else {
        final String errorPage = applyExtension(page.getPath());
        log.debug("Using resolved error page: {}", errorPage);
        return StringUtils.stripToNull(errorPage);
    }

    return null;
}

From source file:gov.nih.nci.calims2.taglib.form.OptionManager.java

/**
 * @param selectKey the selectKey to set
 */
public void setSelectKey(String selectKey) {
    this.selectKey = StringUtils.stripToNull(selectKey);
}

From source file:com.egt.core.db.util.InterpreteSqlAbstracto.java

@Override
public String getComandoSelect(String comando) {
    return StringUtils.stripToNull(comando);
}

From source file:com.egt.core.db.util.InterpreteSqlAbstracto.java

@Override
public String getNombreTabla(String tabla) {
    return StringUtils.stripToNull(tabla);
}