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

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

Introduction

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

Prototype

public static String defaultString(final String str) 

Source Link

Document

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

 StringUtils.defaultString(null)  = "" StringUtils.defaultString("")    = "" StringUtils.defaultString("bat") = "bat" 

Usage

From source file:com.linkedin.urls.Url.java

public String getScheme() {
    if (_scheme == null) {
        if (exists(UrlPart.SCHEME)) {
            _scheme = getPart(UrlPart.SCHEME);
            int index = _scheme.indexOf(":");
            if (index != -1) {
                _scheme = _scheme.substring(0, index);
            }// www .  j a  va  2 s  .c o  m
        } else if (!_originalUrl.startsWith("//")) {
            _scheme = DEFAULT_SCHEME;
        }
    }
    return StringUtils.defaultString(_scheme);
}

From source file:io.wcm.handler.url.impl.UrlHandlerImpl.java

String externalizeLinkUrl(final String url, final Page targetPage, final UrlMode urlMode) {

    // check for empty url
    if (StringUtils.isEmpty(url)) {
        return null;
    }//from   w w w.  ja  v a2 s .com

    // do not externalize urls again that are already externalized
    if (Externalizer.isExternalized(url)) {
        return url;
    }

    // apply sling mapping, namespace mangling and add webapp context path if required
    String externalizedUrl = Externalizer.externalizeUrl(url, resolver, request);

    // add link URL prefix (scheme/hostname or integrator placeholder) if required
    String linkUrlPrefix = getLinkUrlPrefix(urlMode, targetPage);
    externalizedUrl = StringUtils.defaultString(linkUrlPrefix) + externalizedUrl; //NOPMD

    return externalizedUrl;
}

From source file:com.sunchenbin.store.feilong.core.io.FilenameUtil.java

/**
 * ???(?. ?),?.//from  ww w . j  a  v  a  2s .c om
 * 
 * <p>
 * ???  "" (EMPTY)
 * </p>
 * 
 * <pre>
 * {@code
 * Example 1: 
 * F:/pie2.png, return png
 * 
 * Example 2: 
 * F:/pie2, return ""
 * }
 * </pre>
 * 
 * Gets the extension of a filename.
 * <p>
 * This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.
 * 
 * <pre>
 * foo.txt      --> "txt"
 * a/b/c.jpg    --> "jpg"
 * a/b.txt/c    --> ""
 * a/b/c        --> ""
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 * 
 * @param fileName
 *            ??
 * @return ?. ?
 * @see org.apache.commons.io.FilenameUtils#getExtension(String)
 * @see java.lang.String#substring(int, int)
 * @since 1.4.0
 */
public static String getExtension(String fileName) {
    return StringUtils.defaultString(org.apache.commons.io.FilenameUtils.getExtension(fileName));
}

From source file:com.linkedin.urls.Url.java

public String getUsername() {
    if (_username == null) {
        populateUsernamePassword();
    }
    return StringUtils.defaultString(_username);
}

From source file:gov.nih.nci.firebird.commons.selenium2.util.FormUtils.java

/**
 * Clears an input field and sends the input value as keystrokes
 * to the input.//w ww  . java 2 s .c o m
 *
 * @param input the input field
 * @param value the value
 */
public static void type(WebElement input, String value) {
    input.clear();
    input.sendKeys(StringUtils.defaultString(value));
}

From source file:de.bund.bfr.pmfml.sbml.MetadataAnnotation.java

public MetadataAnnotation(final Annotation annotation) {
    final XMLNode pmfNode = annotation.getNonRDFannotation().getChildElement(METADATA_TAG, "");

    metadata = SBMLFactory.createMetadata();

    final XMLNode creatorNode = pmfNode.getChildElement(CREATOR_TAG, "");
    if (creatorNode != null) {
        final String[] tempStrings = creatorNode.getChild(0).getCharacters().split("\\.", 3);

        metadata.setGivenName(StringUtils.defaultString(tempStrings[0]));
        metadata.setFamilyName(StringUtils.defaultString(tempStrings[1]));
        metadata.setContact(StringUtils.defaultString(tempStrings[2]));
    }/*from   ww w. jav  a 2 s  . co  m*/

    final XMLNode createdNode = pmfNode.getChildElement(CREATED_TAG, "");
    if (createdNode != null) {
        metadata.setCreatedDate(createdNode.getChild(0).getCharacters());
    }

    final XMLNode modifiedNode = pmfNode.getChildElement(MODIFIED_TAG, "");
    if (modifiedNode != null) {
        metadata.setModifiedDate(modifiedNode.getChild(0).getCharacters());
    }

    final XMLNode typeNode = pmfNode.getChildElement(TYPE_TAG, "");
    if (typeNode != null) {
        final ModelType modelType = ModelType.valueOf(typeNode.getChild(0).getCharacters());
        metadata.setType(modelType);
    }

    final XMLNode rightsNode = pmfNode.getChildElement(RIGHTS_TAG, "");
    if (rightsNode != null) {
        metadata.setRights(rightsNode.getChild(0).getCharacters());
    }

    final XMLNode refNode = pmfNode.getChildElement(REFERENCE_TAG, "");
    if (refNode != null) {
        metadata.setReferenceLink(refNode.getChild(0).getCharacters());
    }

    // Copies annotation
    this.annotation = annotation;
}

From source file:com.sonicle.webtop.core.app.SettingsManager.java

/**
 * Gets the setting (system) value indicated by the specified key.
 * Returns a null value if the key is not found.
 * @param serviceId The service ID.//from  w  ww .ja  v a  2s  .co m
 * @param key The name of the setting.
 * @return The string value of the setting.
 */
private String getSetting(String serviceId, String key) {
    SettingDAO dao = SettingDAO.getInstance();
    Connection con = null;
    OSetting item = null;

    try {
        con = wta.getConnectionManager().getConnection(CoreManifest.ID);
        item = dao.selectByServiceKey(con, serviceId, key);
        return (item != null) ? StringUtils.defaultString(item.getValue()) : null;

    } catch (Exception ex) {
        WebTopApp.logger.error("Unable to read setting [{}, {}]", serviceId, key, ex);
        throw new RuntimeException(ex);
    } finally {
        DbUtils.closeQuietly(con);
    }
}

From source file:name.martingeisse.admin.navigation.NavigationUtil.java

/**
 * Returns the current navigation node for the specified page.
 * @param page the page/*from w  w w.j  ava 2 s.c  o  m*/
 * @return the navigation node (never null -- if no actual node can be found,
 * this method returns the root not)
 */
public static NavigationNode getNavigationNodeForPage(final Page page) {
    final String currentNavigationPath = StringUtils
            .defaultString(NavigationUtil.getNavigationPathForPage(page));
    return NavigationTree.get().getRoot().findMostSpecificNode(currentNavigationPath);
}

From source file:com.linkedin.urls.Url.java

public String getPassword() {
    if (_password == null) {
        populateUsernamePassword();
    }
    return StringUtils.defaultString(_password);
}

From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginInterceptor.java

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    ActionContext actionContext = actionInvocation.getInvocationContext();
    Map<String, Object> session = actionContext.getSession();
    this.accountObj = (AccountObj) session.get(Constants.SESS_ACCOUNT);
    boolean getUserCurrentCookieFail = false; //  sysCurrentId  cookie, cookiecount tb_sys_usess ? core-web ?
    /*/*from w  w  w. java2  s  .  c o m*/
     * String contextPath = ServletActionContext.getServletContext().getContextPath();
     * if (!contextPath.endsWith( ApplicationSiteUtils.getContextPathFromMap(Constants.getMainSystem()) ) ) {
     */
    if (!Constants.getSystem().equals(Constants.getMainSystem())) {
        /**
         * 1. admin
         * 2. admin  tester
         *  gsbsc-web  http-session admin , ?core-web ??CURRENT cookie ? gsbsc-web 
         * ??? http-session 
         */
        this.invalidCurrentSessionForDifferentAccount(actionContext);
        if (accountObj == null) {
            getUserCurrentCookie(actionContext);
            if (accountObj == null && UserCurrentCookie
                    .foundCurrent((HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST))) {
                //  sysCurrentId  cookie, cookiecount tb_sys_usess ? core-web ?
                getUserCurrentCookieFail = true;
            }
        }
    }
    if (accountObj != null && !StringUtils.isBlank(accountObj.getAccount())) {
        Map<String, String> dataMap = UserCurrentCookie
                .getCurrentData((HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST));
        String currentId = StringUtils.defaultString(dataMap.get("currentId"));
        if (StringUtils.isBlank(currentId)) {
            currentId = "NULL";
        }
        if (uSessLogHelper.countByCurrent(accountObj.getAccount(), currentId) < 1) {
            return this.redirectLogin(session, getUserCurrentCookieFail);
        }
        boolean isUnknownSession = false;
        SecurityUtils.setSecurityManager((DefaultSecurityManager) AppContext.getBean("securityManager"));
        Subject subject = SecurityUtils.getSubject();
        try {
            if (subject.isAuthenticated() && !accountObj.getAccount().equals(subject.getPrincipal())) {
                subject.logout();
            }
        } catch (ExpiredSessionException ese) {
            logger.warn(ese.getMessage().toString());
            return this.redirectLogin(session, getUserCurrentCookieFail);
        } catch (UnknownSessionException ue) {
            logger.warn(ue.getMessage().toString());
            isUnknownSession = true;
        }

        /**
         * core-web  session, gsbsc-web session, gsbsc-web  http session
         *  apache shiro session  expires
         */
        if (!subject.isAuthenticated() || isUnknownSession) {
            GreenStepBaseUsernamePasswordToken token = new GreenStepBaseUsernamePasswordToken();
            //token.setRememberMe(true);
            token.setRememberMe(false);
            token.setCaptcha("");
            token.setUsername(accountObj.getAccount());
            token.setPassword(((AccountVO) accountObj).getPassword().toCharArray());
            try {
                subject.login(token);
            } catch (UnknownAccountException uae) {
                logger.warn(uae.getMessage().toString());
                subject = new Subject.Builder().buildSubject();
                subject.login(token);
            } catch (UnknownSessionException use) {
                logger.warn(use.getMessage().toString());
                subject = new Subject.Builder().buildSubject();
                /*
                Serializable sessionId = subject.getSession().getId();
                System.out.println("SESSION_ID=" + sessionId);
                subject = new Subject.Builder( (DefaultSecurityManager)AppContext.getBean("securityManager") )
                   .sessionId(sessionId)
                   .buildSubject();
                */
                subject.login(token);
            }
            UserAccountHttpSessionSupport.create(actionContext, accountObj);
        }
        return actionInvocation.invoke();
    }
    return this.redirectLogin(session, getUserCurrentCookieFail);
}