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.streamsets.datacollector.util.EdgeUtil.java

public static void publishEdgePipeline(PipelineConfiguration pipelineConfiguration, String edgeHttpUrl

) throws PipelineException {
    String pipelineId = pipelineConfiguration.getPipelineId();

    PipelineConfigBean pipelineConfigBean = PipelineBeanCreator.get().create(pipelineConfiguration,
            new ArrayList<>(), null);
    if (!pipelineConfigBean.executionMode.equals(ExecutionMode.EDGE)) {
        throw new PipelineException(ContainerError.CONTAINER_01600, pipelineConfigBean.executionMode);
    }//from  w  w  w  . ja  va  2 s.  c  o m

    if (StringUtils.isEmpty(edgeHttpUrl)) {
        edgeHttpUrl = pipelineConfigBean.edgeHttpUrl;
    }

    Response response = null;
    try {
        UUID uuid;
        response = ClientBuilder.newClient().target(edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId).request()
                .get();
        if (response.getStatus() == Response.Status.OK.getStatusCode()) {
            // Pipeline with same pipelineId already exist, update pipeline
            PipelineConfigurationJson pipelineConfigurationJson = response
                    .readEntity(PipelineConfigurationJson.class);
            uuid = pipelineConfigurationJson.getUuid();
        } else {
            // Pipeline Doesn't exist, create new pipeline
            response.close();
            response = ClientBuilder.newClient().target(edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId)
                    .queryParam("description", pipelineConfiguration.getDescription()).request()
                    .put(Entity.json(BeanHelper.wrapPipelineConfiguration(pipelineConfiguration)));
            PipelineConfigurationJson pipelineConfigurationJson = response
                    .readEntity(PipelineConfigurationJson.class);
            uuid = pipelineConfigurationJson.getUuid();
        }

        // update pipeline Configuration
        response.close();
        pipelineConfiguration.setUuid(uuid);
        response = ClientBuilder.newClient().target(edgeHttpUrl + "/rest/v1/pipeline/" + pipelineId)
                .queryParam("pipelineTitle", pipelineConfiguration.getPipelineId())
                .queryParam("description", pipelineConfiguration.getDescription()).request()
                .post(Entity.json(BeanHelper.wrapPipelineConfiguration(pipelineConfiguration)));

        if (response.getStatus() != Response.Status.OK.getStatusCode()) {
            throw new PipelineException(ContainerError.CONTAINER_01605, response.getStatus(),
                    response.readEntity(String.class));
        }

    } catch (ProcessingException ex) {
        if (ex.getCause() instanceof ConnectException) {
            throw new PipelineException(ContainerError.CONTAINER_01602, edgeHttpUrl, ex);
        }
        throw ex;
    } finally {
        if (response != null) {
            response.close();
        }
    }
}

From source file:com.renlg.door.controller.LoginController.java

/**
 * //w w  w .j a  v a2 s . c om
 * @param userName
 * @param password
 * @param request
 * @return
 */
@RequestMapping(value = "login")
@ResponseBody
public JsonResult login(String userName, String password, HttpServletRequest request) {
    JsonResult result = new JsonResult();
    if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)) {
        result.setSuccess(false);
        result.setMessage("???");
        return result;
    }
    User user = userService.login(userName, password);
    if (user != null) {
        request.getSession().setAttribute(Constant.SESSION_USER_KEY, user);
        result.setModel(user);
    } else {
        result.setSuccess(false);
        result.setMessage("??");
    }
    return result;
}

From source file:de.jcup.egradle.codeassist.SourceCodeInsertionSupport.java

private InsertionData prepareInsertionString(String originInsertion, String textBeforeColumn,
        boolean ignoreIndentOnFirstLine) {
    InsertionData result = new InsertionData();
    if (StringUtils.isEmpty(originInsertion)) {
        return result;
    }/*from   w ww  . j  av  a2s .  c  om*/
    String insertion = originInsertion;
    /* first do indent if necessary */
    if (StringUtils.isNotEmpty(textBeforeColumn)) {
        /* build indent */
        String indention = transformTextBeforeToIndentString(textBeforeColumn);

        /* for each line append indent before... */
        boolean endsWithNewLine = insertion.endsWith("\n");
        StringBuilder sb = new StringBuilder();
        String[] splitted = StringUtils.splitByWholeSeparator(insertion, "\n");
        for (int i = 0; i < splitted.length; i++) {
            boolean lastLineEmpty = endsWithNewLine;
            lastLineEmpty = lastLineEmpty && i == splitted.length - 1;
            lastLineEmpty = lastLineEmpty && StringUtils.isEmpty(splitted[i]);

            boolean appendLine = !lastLineEmpty;
            if (!appendLine) {
                continue;
            }
            if (i > 0 || !ignoreIndentOnFirstLine) {
                sb.append(indention);
            }
            sb.append(splitted[i]);
            sb.append("\n");

        }
        insertion = sb.toString();

    }
    result.cursorOffset = insertion.indexOf("$cursor");
    if (result.cursorOffset != -1) {
        result.sourceCode = REPLACE_CURSOR_POS.matcher(insertion).replaceAll("");
    } else {
        result.sourceCode = insertion;
    }
    return result;

}

From source file:com.ankang.report.context.ReportApplicationContext.java

@Override
public Map getPool(String alias) {
    if (StringUtils.isEmpty(alias)) {
        return new HashMap<>();
    }/*from  ww w  .  ja  va 2  s.  com*/
    return ALIASPOOLS.get(alias);
}

From source file:architecture.ee.web.util.ServletUtils.java

public static String getContextPath(HttpServletRequest request) {

    if (StringUtils.isEmpty(request.getContextPath())) {
        return CONTEXT_ROOT_PATH;
    } else if (StringUtils.equals("/", request.getContextPath().trim())) {
        return CONTEXT_ROOT_PATH;
    } else {/*www. ja  v  a2s . co  m*/
        return request.getContextPath();
    }
}

From source file:com.gdo.util.XmlWriter.java

/**
 * Creates a new XML writer./*from   w w w. jav a  2 s .c  om*/
 * 
 * @param writer
 *            underlying writer.
 * @param indent
 *            starting indentation level.
 * @param encoding
 *            character encoding used.
 */
public XmlWriter(Writer writer, int indent, String encoding) {
    if (writer == null) {
        throw new NullPointerException("Cannot create a XML writer without an underlying writer");
    }
    if (StringUtils.isEmpty(encoding)) {
        throw new NullPointerException("Cannot create a XML writer without charset encoding");
    }
    _writer = writer;
    _encoding = encoding;
    _indent = indent;
}

From source file:controllers.base.SessionedAction.java

public static String getSessionKey(Context ctx) {
    if (ctx == null) {
        ctx = Validate.notNull(Context.current());
    }/*from   ww w  .ja  v  a 2  s  .c o  m*/

    String sessionId = null;

    // try to get the session id from the query string.
    String[] param = ctx.request().queryString().get("session");
    if (param != null && param.length > 0) {
        sessionId = param[0];
        WebSession session = getWebSession(sessionId);
        if (session == null || session.getStatus() != SessionStatus.IMMORTALIZED) {
            sessionId = null;
        }
    }

    // if not, try to get the session id from headers or cookies.
    if (StringUtils.isEmpty(sessionId)) {
        // decrypt it.
        sessionId = StringUtils.defaultString(StringUtils.defaultString(
                ctx.request().getHeader(SARE_SESSION_HEADER), ctx.session().get(SESSION_ID_KEY)));
        if (StringUtils.isNotEmpty(sessionId)) {
            try {
                sessionId = Crypto.decryptAES(sessionId);
            } catch (Throwable e) {
                sessionId = null;
            }
        }
    }

    return UuidUtils.isUuid(sessionId) ? sessionId : null;
}

From source file:com.dell.asm.asmcore.asmmanager.util.razor.RazorUtil.java

/**
 * Parse the return value of the razor nodes GET api, e.g.
 * http://RAZOR_HOST/api/collections/nodes
 * into a list of node names.//from   w w  w. ja  v a  2  s.  c  o m
 *
 * @param mapper ObjectMapper to parse JSON
 * @param json Json nodes data
 * @return List of node names
 */
public static List<String> parseNodeNamesJson(ObjectMapper mapper, String json) throws IOException {
    List<String> ret = new ArrayList<>();
    Map repoMap = mapper.readValue(json, Map.class);
    List list = (List) repoMap.get("items");
    for (Object o : list) {
        Map elem = (Map) o;
        String name = (String) elem.get(NODES_NAME_KEY);
        if (StringUtils.isEmpty(name)) {
            LOGGER.warn("Invalid node element " + elem + " in " + json);
        } else {
            ret.add(name);
        }
    }
    return ret;
}

From source file:com.webbfontaine.valuewebb.action.tt.TtPrinting.java

public SingleTTReport prepareFCVRReport(TtGen ttGen, boolean isDraft) {
    SingleTTReport str = new SingleTTReport();

    str.getTtId().setValue(new BigDecimal(ttGen.getId().toString()));

    ClassLoader classLoader = getClass().getClassLoader();

    if (isDraft) {
        str.getDraft().setValue(classLoader.getResourceAsStream(PrintUtils.getDraftImagePath()));
    } else {//from   ww  w.j  a va  2 s  . co  m
        String signImage = PrintUtils.getSignatureImagePath();
        if (!StringUtils.isEmpty(signImage)) {
            str.getSignature().setValue(classLoader.getResourceAsStream(signImage));
        }

        if (ttGen.getFcvrNum() == null) {
            str.getDraft().setValue(classLoader.getResourceAsStream(PrintUtils.getDraftImagePath()));
        }
    }

    str.getTitle().setValue(classLoader.getResourceAsStream(PrintUtils.getTitleImagePath()));
    return str;
}

From source file:at.beris.virtualfile.util.UrlUtils.java

/**
 * Masks sensitive information in an url (e.g. for logging)
 *
 * @param url/* w  ww . ja  va2  s.  c o  m*/
 * @return
 */
public static String maskedUrlString(URL url) {
    StringBuilder stringBuilder = new StringBuilder("");

    stringBuilder.append(url.getProtocol());
    stringBuilder.append(':');
    if (!url.getProtocol().toLowerCase().equals("file"))
        stringBuilder.append("//");

    String authority = url.getAuthority();
    if (!StringUtils.isEmpty(authority)) {
        String[] authorityParts = authority.split("@");

        if (authorityParts.length > 1) {
            String[] userInfoParts = authorityParts[0].split(":");
            stringBuilder.append(userInfoParts[0]);

            if (userInfoParts.length > 1) {
                stringBuilder.append(":***");
            }
            stringBuilder.append('@');
            stringBuilder.append(authorityParts[1]);
        } else {
            stringBuilder.append(authorityParts[0]);
        }
    }

    stringBuilder.append(url.getPath());

    return stringBuilder.toString();
}