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

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

Introduction

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

Prototype

public static boolean isEmpty(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is empty ("") or null.

 StringUtils.isEmpty(null)      = true StringUtils.isEmpty("")        = true StringUtils.isEmpty(" ")       = false StringUtils.isEmpty("bob")     = false StringUtils.isEmpty("  bob  ") = false 

NOTE: This method changed in Lang version 2.0.

Usage

From source file:com.glaf.core.config.SystemConfig.java

public static boolean getBoolean(String key) {
    boolean ret = false;
    SystemProperty property = getProperty(key);
    if (property != null) {
        String value = property.getValue();
        if (StringUtils.isEmpty(value)) {
            value = property.getInitValue();
        }//from   ww w .j a va  2 s .c  o  m
        if (StringUtils.equalsIgnoreCase(value, "true") || StringUtils.equalsIgnoreCase(value, "1")
                || StringUtils.equalsIgnoreCase(value, "y") || StringUtils.equalsIgnoreCase(value, "yes")) {
            ret = true;
        }
    }
    return ret;
}

From source file:com.jredrain.tag.PagerTag.java

@Override
public void doTag() throws JspException, IOException {
    JspWriter out = getJspContext().getOut();

    if (StringUtils.isEmpty(idParameterName)) {
        idParameterName = "pageNo";
    }/* ww  w.  j  a v  a2s. c  o m*/
    if (StringUtils.isEmpty(sizeParameterName)) {
        sizeParameterName = "pageSize";
    }

    if (!href.endsWith("?") && !href.endsWith("&")) {
        if (href.indexOf("?") == -1) {
            href = href + "?";
        } else {
            href = href + "&";
        }
    }

    int pageTotal = 0;
    if ((total % size) == 0) {
        pageTotal = total / size;
    } else {
        pageTotal = (total / size) + 1;
    }

    if (id <= 0) {
        id = 1;
    } else if (id > pageTotal) {
        id = pageTotal;
    }

    //?
    if (getTotal() <= 0) {
        super.doTag();
        return;
    }
    out.append("<ul class='pagination fr mr20'>");
    // 
    if (id == 1) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, 1, "");
    }

    // 
    if (id == 1) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, id - 1, "");
    }

    int offsetNum = 5;
    int startId;
    if (id < offsetNum * 2 + 1) {
        startId = 1;
    } else {
        startId = id - offsetNum;
    }

    int endId = id + offsetNum;
    if (endId > pageTotal) {
        endId = pageTotal;
    }

    for (int i = startId; i <= endId; i++) {
        if (i == id) {
            wrapSpan(out, String.valueOf(i), 1);
        } else {
            wrapLink(out, href, i, String.valueOf(i));
        }
    }

    // 
    if (id == pageTotal) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, id + 1, "");
    }

    // 
    if (id == pageTotal) {
        wrapSpan(out, "", -1);
    } else {
        wrapLink(out, href, pageTotal, "");
    }
    out.append("</ul>");
    super.doTag();
}

From source file:lineage2.gameserver.network.clientpackets.RequestFriendInvite.java

/**
 * Method runImpl.//from  w  w w  . ja  va 2 s  . c om
 */
@Override
protected void runImpl() {
    Player activeChar = getClient().getActiveChar();
    if ((activeChar == null) || StringUtils.isEmpty(_name)) {
        return;
    }
    if (activeChar.isOutOfControl()) {
        activeChar.sendActionFailed();
        return;
    }
    if (activeChar.isProcessingRequest()) {
        activeChar.sendPacket(SystemMsg.WAITING_FOR_ANOTHER_REPLY);
        return;
    }
    Player target = World.getPlayer(_name);
    if (target == null) {
        activeChar.sendPacket(SystemMsg.THE_USER_WHO_REQUESTED_TO_BECOME_FRIENDS_IS_NOT_FOUND_IN_THE_GAME);
        return;
    }
    if (target == activeChar) {
        activeChar.sendPacket(SystemMsg.YOU_CANNOT_ADD_YOURSELF_TO_YOUR_OWN_FRIEND_LIST);
        return;
    }
    if (target.isBlockAll() || target.isInBlockList(activeChar) || target.getMessageRefusal()) {
        activeChar.sendPacket(SystemMsg.THAT_PERSON_IS_IN_MESSAGE_REFUSAL_MODE);
        return;
    }
    if (activeChar.getFriendList().getList().containsKey(target.getObjectId())) {
        activeChar.sendPacket(new SystemMessage2(SystemMsg.C1_IS_ALREADY_ON_YOUR_FRIEND_LIST).addName(target));
        return;
    }
    if (activeChar.getFriendList().getList().size() >= Player.MAX_FRIEND_SIZE) {
        activeChar.sendPacket(SystemMsg.YOU_CAN_ONLY_ENTER_UP_128_NAMES_IN_YOUR_FRIENDS_LIST);
        return;
    }
    if (target.getFriendList().getList().size() >= Player.MAX_FRIEND_SIZE) {
        activeChar.sendPacket(
                SystemMsg.THE_FRIENDS_LIST_OF_THE_PERSON_YOU_ARE_TRYING_TO_ADD_IS_FULL_SO_REGISTRATION_IS_NOT_POSSIBLE);
        return;
    }
    if (target.isInOlympiadMode()) {
        activeChar.sendPacket(
                SystemMsg.A_USER_CURRENTLY_PARTICIPATING_IN_THE_OLYMPIAD_CANNOT_SEND_PARTY_AND_FRIEND_INVITATIONS);
        return;
    }
    new Request(L2RequestType.FRIEND, activeChar, target).setTimeout(10000L);
    activeChar.sendPacket(
            new SystemMessage2(SystemMsg.YOUVE_REQUESTED_C1_TO_BE_ON_YOUR_FRIENDS_LIST).addName(target));
    target.sendPacket(new SystemMessage2(SystemMsg.C1_HAS_SENT_A_FRIEND_REQUEST).addName(activeChar),
            new FriendAddRequest(activeChar.getName()));
}

From source file:beans.BeansFactory.java

public EventMonitor getEventMonitor() {
    //        logger.info( "bean factory - getEventMonitor is invoked with mock [{}] and impl [{}] ", eventMonitorMock, eventMonitorImpl );

    // GUY _ NOTE _ VERY IMPORTANT - the "@Inject"ed fields for eventMonitorImpl and eventMonitorMock are null.
    // please refer to stackoverflow's question : http://stackoverflow.com/questions/15183145/autowiring-factory-bean
    // to read more about this.
    if (StringUtils.isEmpty(conf.mixpanelApiKey)) {
        logger.info("using mock eventMonitor");
        return (EventMonitor) Spring.getBean("eventMonitorMock");// eventMonitorMock;
    } else {/*from  w  w w  . ja  v a  2 s  .c  om*/
        logger.info("using impl eventMonitor");
        return (EventMonitor) Spring.getBean("eventMonitorImpl"); // eventMonitor
    }
}

From source file:net.dv8tion.jda.core.entities.Game.java

/**
 * Creates a new Game instance with the specified name and url.
 *
 * @param name/*from   w w w .j  a va 2  s  .  com*/
 *      The not-null name of the newly created game
 * @param url
 *      The streaming url to use, invalid for {@link GameType#DEFAULT GameType#DEFAULT}
 * @return
 *      A valid Game instance with the provided name and url
 * @throws IllegalArgumentException
 *      if the specified name is null or empty
 * @see #isValidStreamingUrl(String)
 */
static Game of(String name, String url) {
    if (StringUtils.isEmpty(name))
        throw new IllegalArgumentException("Game name may not be null or empty.");
    GameType type;
    if (isValidStreamingUrl(url))
        type = GameType.TWITCH;
    else
        type = GameType.DEFAULT;
    return new GameImpl(name, url, type);
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.security.SamlValidator.java

@Override
public void validate(ConfigProblemSetBuilder p, Saml saml) {
    if (!saml.isEnabled()) {
        return;//  w w  w  .  j  av a 2  s  .  c om
    }

    if (StringUtils.isEmpty(saml.getMetadataLocal()) && StringUtils.isEmpty(saml.getMetadataRemote())) {
        p.addProblem(Problem.Severity.ERROR, "No metadata file specified.");
    }

    if (StringUtils.isNotEmpty(saml.getMetadataLocal())) {
        try {
            new File(new URI("file:" + saml.getMetadataLocal()));
        } catch (Exception f) {
            p.addProblem(Problem.Severity.ERROR, f.getMessage());
        }
    }

    if (StringUtils.isNotEmpty(saml.getMetadataRemote())) {
        try {
            HttpClientBuilder.create().build().execute(new HttpGet(saml.getMetadataRemote()));
        } catch (IOException e) {
            p.addProblem(Problem.Severity.WARNING, "Cannot access remote metadata.xml file: " + e.getMessage());
        }
    }

    if (StringUtils.isEmpty(saml.getIssuerId())) {
        p.addProblem(Problem.Severity.ERROR, "No issuerId specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStore())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStorePassword())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore password specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStoreAliasName())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore alias specified.");
    }

    InputStream is = null;
    try {
        File f = new File(new URI("file:" + saml.getKeyStore()));
        is = new FileInputStream(f);
        val keystore = KeyStore.getInstance(KeyStore.getDefaultType());

        // will throw an exception if `keyStorePassword` is invalid
        keystore.load(is, saml.getKeyStorePassword().toCharArray());

        Collections.list(keystore.aliases()).stream()
                .filter(alias -> alias.equalsIgnoreCase(saml.getKeyStoreAliasName())).findFirst()
                .orElseThrow(() -> new RuntimeException(
                        "Keystore does not contain alias " + saml.getKeyStoreAliasName()));

    } catch (Exception e) {
        p.addProblem(Problem.Severity.ERROR, "Keystore validation problem: " + e.getMessage());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                // ignored.
            }
        }
    }

    if (saml.getServiceAddress() == null) {
        p.addProblem(Problem.Severity.ERROR, "No service address specified.");
    } else if (!saml.getServiceAddress().getProtocol().equalsIgnoreCase("https")) {
        p.addProblem(Problem.Severity.WARNING, "Gate should operate on HTTPS");
    }
}

From source file:de.micromata.genome.gwiki.wicket.GWikiLocalizer.java

protected String getI18NFromGWiki(String key, Component component, IModel<?> model) {
    GWikiWeb wikiWeb = GWikiWeb.getWiki();
    Locale loc = component.getLocale();
    String lang = loc.getLanguage();
    if (StringUtils.isEmpty(lang) == true) {
        lang = "en";
    }/*from   w  w  w .  j  av a 2  s  .  co m*/

    for (String mod : modules) {
        GWikiI18nElement el = (GWikiI18nElement) wikiWeb.getElement(mod);
        String v = el.getMessage(lang, key);
        if (v != null) {
            return v;
        }
    }
    return null;
}

From source file:com.qcadoo.mes.materialFlowResources.validators.LocationValidators.java

public boolean hasAlgorithm(final DataDefinition dataDefinition, final Entity entity) {
    if (LocationType.WAREHOUSE.equals(LocationType.parseString(entity.getStringField(LocationFields.TYPE)))
            && StringUtils.isEmpty(entity.getStringField(LocationFieldsMFR.ALGORITHM))) {
        entity.addError(dataDefinition.getField(LocationFieldsMFR.ALGORITHM),
                "qcadooView.validate.field.error.missing");
        return false;
    }//  w  w  w.  ja  v  a 2  s . c o  m

    return true;
}

From source file:microsoft.exchange.webservices.data.property.complex.ConversationId.java

/**
 * Defines an implicit conversion between ConversationId and String.
 *
 * @param conversationId the conversation id
 * @return A ConversationId initialized with the specified unique Id.
 * @throws Exception the validation exception
 *///from w w  w .  j  a va2 s  . c  o  m
public static String getStringFromConversationId(ConversationId conversationId) throws Exception {
    EwsUtilities.validateParam(conversationId, "conversationId");

    if (StringUtils.isEmpty(conversationId.getUniqueId())) {
        return "";
    } else {
        // Ignoring the change key info
        return conversationId.getUniqueId();
    }
}

From source file:com.xpn.xwiki.render.macro.TableBuilder.java

public static Table build(String content) {
    Table table = new Table();
    StringTokenizer tokenizer = new StringTokenizer(content, "|\n", true);
    String lastToken = null;/*from w  ww  . j  av a  2 s . c o  m*/
    boolean firstCell = true;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.equals("\r")) {
            continue;
        }
        // If a token contains [, then all tokens up to one containing a ] are concatenated. Kind of a block marker.
        if (token.indexOf('[') != -1 && token.indexOf(']') == -1) {
            String linkToken = "";
            while (token.indexOf(']') == -1 && tokenizer.hasMoreTokens()) {
                linkToken += token;
                token = tokenizer.nextToken();
            }
            token = linkToken + token;
        }
        if ("\n".equals(token)) {
            // New line: either new row, or a literal newline.
            lastToken = (lastToken == null) ? "" : lastToken;
            if (!StringUtils.endsWith(lastToken, "\\")) {
                // A new row, not a literal newline.
                // If the last cell didn't contain any data, then it was skipped. Add a blank cell to compensate.
                if ((StringUtils.isEmpty(lastToken) || "|".equals(lastToken)) && !firstCell) {
                    table.addCell(" ");
                }
                table.newRow();
            } else {
                // A continued row, with a literal newline.
                String cell = lastToken;
                // Keep concatenating while the cell data ends with \\
                while (cell.endsWith("\\") && tokenizer.hasMoreTokens()) {
                    token = tokenizer.nextToken();
                    if (!"|".equals(token)) {
                        cell = cell + token;
                    } else {
                        break;
                    }
                }
                firstCell = false;
                table.addCell(cell.trim());
                if (!tokenizer.hasMoreTokens()) {
                    table.newRow();
                }
            }
        } else if (!"|".equals(token)) {
            // Cell data
            if (!token.endsWith("\\")) {
                // If the cell data ends with \\, then it will be continued. Current data is stored in lastToken.
                table.addCell(token.trim());
                firstCell = false;
            } else if (!tokenizer.hasMoreTokens()) {
                // Remove backslashes from the end
                while (token.endsWith("\\")) {
                    token = StringUtils.chop(token);
                }
                table.addCell(token.trim());
            }
        } else if ("|".equals(token)) {
            // Cell delimiter
            if ((StringUtils.isEmpty(lastToken) && firstCell) || "|".equals(lastToken)) {
                // If the last cell didn't contain any data, then it was skipped. Add a blank cell to compensate.
                table.addCell(" ");
                firstCell = false;
            } else if (StringUtils.endsWith(lastToken, "\\")) {
                // The last cell wasn't added because it ended with a continuation mark (\\). Add it now.
                table.addCell(lastToken.trim());
                firstCell = false;
            }
        }
        lastToken = token;
    }

    return table;
}