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

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

Introduction

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

Prototype

public static String trimToNull(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

Usage

From source file:com.ms.commons.cookie.parser.CookieParser.java

/**
 * CookieName???Cookievalue. ?CookieNameCookieKey
 * /*from  w w w  . ja v  a2  s.co  m*/
 * @return ?null
 */
static CookieNameHelper paserCookieValue(CookieNameConfig cookieNameConfig, String cookieValue) {
    String value = StringUtils.trimToNull(cookieValue);
    if (value == null || StringUtils.equalsIgnoreCase("null", value))
        return null;

    // ?
    if (cookieNameConfig.isEncrypt()) {
        value = CookieUtils.decrypt(value);
    }
    CookieNameHelper cookieNameHelper = new CookieNameHelper(cookieNameConfig.getCookieName(),
            cookieNameConfig);
    // ??Key??,?
    if (cookieNameConfig.isSimpleValue()) {
        cookieNameHelper.parserValue(value);
    } else {
        // ??Value??
        Map<CookieKeyEnum, String> kv = CookieUtils.strToKVMap(value, cookieNameConfig);
        // CookieNameHelper cookieNameHelper = null;
        if (kv != null && !kv.isEmpty())
            cookieNameHelper.parserAllValues(kv);
    }
    return cookieNameHelper;
}

From source file:com.partnet.automation.util.SystemPropsUtil.java

/**
 * Look for a required system property.//from   www  . j  av  a 2  s  .  c o  m
 * 
 * @param propertyName
 *          name of the property to get
 * @return value of the given property
 * @throws IllegalStateException
 *           if the property isn't defined or has an empty/blank value
 */
public static String getRequiredProperty(final String propertyName) {
    String propertyValue = System.getProperty(propertyName);
    if (StringUtils.trimToNull(propertyValue) == null) {
        throw new IllegalStateException(String.format("Missing required property %s", propertyName));
    }
    return propertyValue;
}

From source file:fr.dutra.confluence2wordpress.core.converter.visitors.AttributesCleaner.java

/**
  * @inheritdoc//w ww  .  j ava2s .co m
  */
public boolean visit(TagNode parentNode, HtmlNode htmlNode) {
    if (htmlNode instanceof TagNode) {
        TagNode tag = (TagNode) htmlNode;

        //filter css classes: allow only css classes starting with "c2w"
        //all others will be useless once on the Wordpress side
        String classes = tag.getAttributeByName(CLASS);
        if (classes != null) {
            classes = filterCssClasses(classes);
            tag.setAttribute(CLASS, classes);
            classes = StringUtils.trimToNull(classes);
            if (classes == null) {
                tag.removeAttribute(CLASS);
            } else {
                tag.setAttribute(CLASS, classes);
            }
        }

        //remove "data-" or "confluence-" attributes
        Map<String, String> attributes = tag.getAttributes();
        Iterator<String> iterator = attributes.keySet().iterator();
        while (iterator.hasNext()) {
            String name = iterator.next();
            if (name.startsWith("data-") || name.startsWith("confluence-")) {
                iterator.remove();
            }
        }

    }
    return true;
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlParser.java

public Map<String, Object> parse(Element element) throws Exception {
    Map<String, Object> objectModel = new HashMap<String, Object>();

    String qualifiedName = getQualifiedName(element);
    objectModel.put("dataType", qualifiedName);

    // collect attributes
    Element attributeContainer = DOMUtil.getChild(element, "attributes");
    Map<String, Object> attrs = new HashMap<String, Object>();
    if (attributeContainer != null) {
        List<Element> attributes = DOMUtil.getChildren(attributeContainer, "attribute");
        for (Element e : attributes) {
            // only legitimate attributes should find their way into the attributes map
            if (StringUtils.trimToNull(e.getAttribute("skipMe")) == null) {
                String attributeName = getQualifiedName(e);
                List<Element> value = DOMUtil.getChildren(e, "value");

                if (value.size() == 1) {
                    String stringValue = value.get(0).getTextContent();
                    attrs.put(attributeName, stringValue);
                } else if (value.size() > 1) {
                    List<String> values = new ArrayList<String>(value.size());
                    for (Element valueElement : value) {
                        String stringValue = StringUtils.trimToEmpty(valueElement.getTextContent());
                        values.add(stringValue);
                    }//w  ww  .  j a v  a  2s .c o m
                    attrs.put(attributeName, values);
                }
            }
        }
    }
    objectModel.put("attributes", attrs);

    // collect associations
    Element associationsContener = DOMUtil.getChild(element, "associations");

    List<AssociationBean> assos = new ArrayList<AssociationBean>();
    if (associationsContener != null) {
        String associationsAction = associationsContener.getAttribute("action");
        if (StringUtils.trimToNull(associationsAction) != null) {
            objectModel.put("associationsAction", associationsAction);
        }
        List<Element> associations = DOMUtil.getChildren(associationsContener, "association");
        for (Element e : associations) {
            AssociationBean association = new AssociationBean();
            association.setAssociationName(getQualifiedName(e));
            Element target = DOMUtil.getChild(e, "target");
            String action = e.getAttribute("action");
            if (StringUtils.trimToNull(action) != null) {
                association.setAction(AssociationBean.Actions.valueOf(action));
            }
            if (target != null) {
                String targetRef = target.getTextContent();
                String targetQualifiedName = getQualifiedName(target);
                association.setTargetQualifiedName(targetQualifiedName);
                association.setTargetId(targetRef);
            }
            assos.add(association);
        }
    }
    objectModel.put("associations", assos);

    return objectModel;
}

From source file:com.egt.core.util.JS.java

public static String getConfirmDialogJavaScript(String table, String alertMessage, String confirmMessage) {
    VelocityContext context = new VelocityContext();
    context.put("table", StringUtils.trimToNull(table));
    context.put("alertMessage", StringUtils.trimToNull(alertMessage));
    context.put("confirmMessage", StringUtils.trimToNull(confirmMessage));
    return merge("js-confirm-dialog", context);
}

From source file:com.enonic.vertical.VerticalProperties.java

public String getProperty(final String key, final String defaultValue) {
    final String systemProperty = StringUtils.trimToNull(System.getProperty(key));
    if (systemProperty != null) {
        return systemProperty;
    }/* w w  w  .j av a 2 s. c om*/
    return StringUtils.trimToNull(properties.getProperty(key, defaultValue));
}

From source file:com.bluexml.xforms.actions.DeleteAction.java

@Override
protected void afterSubmit() {
    // unstack last page
    Page currentPage = navigationPath.popCurrentPage();
    Map<String, String> initParams = currentPage.getInitParams();

    String url = StringUtils.trimToNull(initParams.get(MsgId.PARAM_NEXT_PAGE_DELETE.getText()));

    if (url == null) { // #1656
        // there may be something specified in the Xtension property of this form
        url = controller.getXtensionNextPageDelete(currentPage.getFormName(), currentPage.getFormType());
    }/*from w  ww  . j ava 2  s  .  c o  m*/

    if (StringUtils.trimToNull(url) != null) {
        String nextPageUrl = buildRedirectionUrlWithParams(url, currentPage);
        super.redirectClient(nextPageUrl);
    } else {
        // previous page by default
        boolean empty = navigationPath.isEmpty();
        if (empty) {
            currentPage.setDataId(null);
            // forward to create if no page exists
            navigationPath.pushPage(currentPage);
        } else {
            // removes reference in current form
            if (elementId != null) {
                controller.removeReference(navigationPath.peekCurrentPage().getNode(), elementId);

            }
        }
        setSubmissionDefaultLocation(getServletURL(), result);
    }
}

From source file:edu.amc.sakai.user.EmailAddressDerivingLdapAttributeMapper.java

/**
 * Returns {@link #doUnpackEidFromAddress(String)} if the given 
 * <code>email/code> string validates against 
 * {@link #validateAddress(String)}. Otherwise throws a
 * {@Link InvalidEmailAddressException}. Throws the same
 * exception type if {@link #doUnpackEidFromAddress(String)} returns
 * <code>null</code> or a whitespace string.
 *///  w  w w. j  a  v a2  s .co m
public String unpackEidFromAddress(String address) throws InvalidEmailAddressException {
    boolean validated = validateAddress(address);
    if (!(validated)) {
        throw new InvalidEmailAddressException("Unable to unpack EID from email address [" + address
                + "]. Expected pattern = [" + getAddressPattern() + "]");
    }
    String eid = StringUtils.trimToNull(doUnpackEidFromAddress(address));
    if (eid == null) {
        throw new InvalidEmailAddressException("Unpacked an empty EID from email address [" + address + "].");
    }
    return eid;
}

From source file:com.bluexml.xforms.actions.CancelAction.java

@Override
public void submit() throws ServletException {
    // pop page from stack
    Page currentPage = navigationPath.popCurrentPage();
    Map<String, String> initParams = currentPage.getInitParams();

    String url = StringUtils.trimToNull(initParams.get(MsgId.PARAM_NEXT_PAGE_CANCEL.getText()));

    if (url == null) { // #1656
        // there may be something specified in the Xtension property of this form
        url = controller.getXtensionNextPageCancel(currentPage.getFormName(), currentPage.getFormType());
    }/*from  ww  w.  ja va 2  s.com*/

    if (StringUtils.trimToNull(url) != null) {
        String nextPageUrl = buildRedirectionUrlWithParams(url, currentPage);
        super.redirectClient(nextPageUrl);
    } else {
        navigationPath.clearStatusMsg();
        boolean empty = navigationPath.isEmpty();
        if (empty) {
            // ** #1367; we redo what is normally done in GetAction
            boolean formIsReadOnly = (currentPage.getDataType() != currentPage.getFormName());
            String dataType = currentPage.getDataType();
            String dataId = currentPage.getDataId();
            Document node;
            if (currentPage.getFormType() == FormTypeEnum.FORM) {
                GetInstanceFormBean bean = new GetInstanceFormBean(dataType, dataId, formIsReadOnly, false,
                        null);
                node = controller.getInstanceForm(transaction, bean);
            } else {
                node = controller.getInstanceClass(transaction, dataType, dataId, formIsReadOnly, false);
            }
            currentPage.setNode(node);
            // ** #1367
            navigationPath.pushPage(currentPage);
        }
        setSubmissionDefaultLocation(getServletURL(), result);
    }
}

From source file:com.seyren.core.service.notification.HubotNotificationService.java

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
        throws NotificationFailedException {
    String hubotUrl = StringUtils.trimToNull(seyrenConfig.getHubotUrl());

    if (hubotUrl == null) {
        LOGGER.warn("Hubot URL needs to be set before sending notifications to Hubot");
        return;//w w  w  .  ja  va 2 s.  co  m
    }

    Map<String, Object> body = new HashMap<String, Object>();
    body.put("seyrenUrl", seyrenConfig.getBaseUrl());
    body.put("check", check);
    body.put("subscription", subscription);
    body.put("alerts", alerts);
    body.put("rooms", subscription.getTarget().split(","));

    HttpClient client = HttpClientBuilder.create().useSystemProperties().build();

    HttpPost post = new HttpPost(hubotUrl + "/seyren/alert");
    try {
        HttpEntity entity = new StringEntity(MAPPER.writeValueAsString(body), ContentType.APPLICATION_JSON);
        post.setEntity(entity);
        client.execute(post);
    } catch (IOException e) {
        throw new NotificationFailedException("Sending notification to Hubot at " + hubotUrl + " failed.", e);
    } finally {
        HttpClientUtils.closeQuietly(client);
    }
}