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

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

Introduction

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

Prototype

String EMPTY

To view the source code for org.apache.commons.lang3 StringUtils EMPTY.

Click Source Link

Document

The empty String "" .

Usage

From source file:com.baifendian.swordfish.webserver.service.LogHelper.java

public LogResult getLog(Integer from, Integer size, String query, String jobId) {
    //  id , ?/*from  w w w .ja  v  a2 s  . c om*/
    if (StringUtils.isEmpty(jobId)) {
        return LogResult.EMPTY_LOG_RESULT;
    }

    if (from == null) {
        from = 0;
    }

    if (size == null) {
        size = 100;
    }

    long start = System.currentTimeMillis();

    LogResult result = new LogResult();

    try {
        SearchResponse response = search.search(from, size, query, jobId/*, (sort == null) ? true : sort*/);

        if (response != null) {
            if (response.status() == RestStatus.OK) {
                SearchHits searchHits = response.getHits();

                result.setTotal(searchHits.getTotalHits()); // total
                result.setLength(searchHits.getHits().length); // real length
                result.setOffset(from); // offset

                List<String> contents = new ArrayList<>();

                for (SearchHit hit : searchHits.getHits()) {
                    Map<String, Object> fieldMap = hit.getSource();

                    if (fieldMap != null && fieldMap.containsKey("nest_msg")) {
                        String message = fieldMap.get("nest_msg").toString();

                        contents.add(message);
                    } else {
                        contents.add(StringUtils.EMPTY);
                    }
                }

                result.setContent(contents);
            } else {
                logger.error("search status: {}", response.status());
            }
        }
    } catch (IOException e) {
        logger.error("Catch an exception", e);
        return null;
    }

    // 
    result.setTook(System.currentTimeMillis() - start);
    return result;
}

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

/**
 * Method runImpl.// www.  j a va  2s .  c o  m
 */
@Override
protected void runImpl() {
    Player activeChar = getClient().getActiveChar();
    if (activeChar == null) {
        return;
    }
    if (activeChar.getClanId() == 0) {
        activeChar.sendActionFailed();
        return;
    }
    if (activeChar.isInCombat()) {
        activeChar.sendPacket(Msg.ONE_CANNOT_LEAVE_ONES_CLAN_DURING_COMBAT);
        return;
    }
    Clan clan = activeChar.getClan();
    if (clan == null) {
        return;
    }
    UnitMember member = clan.getAnyMember(activeChar.getObjectId());
    if (member == null) {
        activeChar.sendActionFailed();
        return;
    }
    if (member.isClanLeader()) {
        activeChar.sendMessage("A clan leader may not be dismissed.");
        return;
    }
    int subUnitType = activeChar.getPledgeType();
    clan.removeClanMember(subUnitType, activeChar.getObjectId());
    clan.broadcastToOnlineMembers(
            new SystemMessage2(SystemMsg.S1_HAS_WITHDRAWN_FROM_THE_CLAN).addString(activeChar.getName()),
            new PledgeShowMemberListDelete(activeChar.getName()));
    if (subUnitType == Clan.SUBUNIT_ACADEMY) {
        activeChar.setLvlJoinedAcademy(0);
    }
    activeChar.setClan(null);
    if (!activeChar.isNoble()) {
        activeChar.setTitle(StringUtils.EMPTY);
    }
    activeChar.setLeaveClanCurTime();
    activeChar.broadcastCharInfo();
    activeChar.sendPacket(SystemMsg.YOU_HAVE_RECENTLY_BEEN_DISMISSED_FROM_A_CLAN,
            PledgeShowMemberListDeleteAll.STATIC);
}

From source file:de.blizzy.backup.BackupPlugin.java

private String getApplicationArg(String argName) {
    String[] args = Platform.getApplicationArgs();
    for (String arg : args) {
        if (arg.equals(argName)) {
            return StringUtils.EMPTY;
        }/*from w w  w .j a  va2  s  . c  o  m*/
        if (arg.startsWith(argName + "=")) { //$NON-NLS-1$
            return arg.substring(argName.length() + 1);
        }
    }
    return null;
}

From source file:com.discovery.darchrow.net.ParamUtil.java

/**
 * ??,???. <br>/*from  w w w .j  a  va  2s  .co m*/
 * 
 * <ol>
 * <li>? a  z ?????? </li>
 * <li>????&??</li>
 * <li>?????.</li>
 * <li><span style="color:red">?: ???? encoding ?</span></li>
 * </ol>
 * 
 * <h3>??:</h3> <blockquote>
 * <ol>
 * <li>{@code if isNullOrEmpty(filePath)---->} return {@link org.apache.commons.lang3.StringUtils#EMPTY}</li>
 * <li>paramsMap to naturalOrderingMap(TreeMap)</li>
 * <li>for naturalOrderingMap's entrySet(),join key and value use =,join each entry use &</li>
 * </ol>
 * </blockquote>
 *
 * @param paramsMap
 *            ???
 * @return the string
 * @since 1.2.0
 */
public static String toNaturalOrderingString(Map<String, String> paramsMap) {
    if (Validator.isNullOrEmpty(paramsMap)) {
        return StringUtils.EMPTY;
    }

    StringBuilder sb = new StringBuilder();

    Map<String, String> naturalOrderingMap = new TreeMap<String, String>(paramsMap);

    int i = 0;
    int size = naturalOrderingMap.size();
    for (Map.Entry<String, String> entry : naturalOrderingMap.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        sb.append(key + "=" + value);

        // ??? &
        if (i != size - 1) {
            sb.append("&");
        }
        ++i;
    }

    String naturalOrderingString = sb.toString();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(naturalOrderingString);
    }
    return naturalOrderingString;
}

From source file:com.qq.tars.web.controller.ExpandController.java

@RequestMapping(value = "server/api/cascade_select_server", produces = { "application/json" })
@ResponseBody/*from w w  w  .  j  a va 2 s  . c o  m*/
public List<String> select(@RequestParam int level, @RequestParam(required = false) String application,
        @RequestParam(value = "server_name", required = false) String serverName,
        @RequestParam(required = false) String set) throws Exception {
    switch (level) {
    case 1:
        return expandServerService.getApplication();
    case 2:
        if (StringUtils.isBlank(application)) {
            throw new ServletRequestParameterException("?application");
        }
        return expandServerService.getServerName(application);
    case 3:
        if (StringUtils.isAnyBlank(application, serverName)) {
            throw new ServletRequestParameterException("?applicationserver_name");
        }
        return expandServerService.getSet(application, serverName);
    case 4:
        if (StringUtils.isAnyBlank(application, serverName)) {
            throw new ServletRequestParameterException("?applicationserver_name");
        }

        if (StringUtils.isBlank(set)) {
            set = StringUtils.EMPTY;
        } else {
            try {
                SetTriple.parseSet(set);
            } catch (IllegalArgumentException e) {
                throw new ServletRequestParameterException("?set?");
            }
        }
        return expandServerService.getNodeName(application, serverName, set);
    default:
        throw new ServletRequestParameterException();
    }
}

From source file:com.tesshu.subsonic.client.sample4_music_andmovie.BinaryDownloadApplication.java

@Bean
protected CommandLineRunner run(RestTemplate restTemplate) throws Exception {
    return args -> {

        File tmpDirectory = new File(tmpPath);
        tmpDirectory.mkdir();/*from   www  . ja  va 2 s.  com*/

        Optional<SearchResult2> result2 = search2.getOf("e", null, null, null, null, 1, null, null);
        result2.ifPresent(result -> result.getSongs().forEach(song -> {

            download.download(song, (subject, inputStream) -> {

                File dir = new File(tmpPath + "/" + song.getPath().replaceAll("([^/]+?)?$", StringUtils.EMPTY));
                dir.mkdirs();
                File file = new File(tmpPath + "/" + song.getPath());
                try {
                    FileOutputStream fos = new FileOutputStream(file);
                    BufferedInputStream reader = new BufferedInputStream(inputStream);
                    byte buf[] = new byte[256];
                    int len;
                    while ((len = reader.read(buf)) != -1) {
                        fos.write(buf, 0, len);
                    }
                    fos.flush();
                    fos.close();
                    reader.close();
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                LOG.info(file.getAbsolutePath());
            }, callback);
        }));

        tmpDirectory.deleteOnExit();
    };

}

From source file:com.longtime.ajy.support.weixin.HttpsKit.java

/**
 * ??Get//from   w  w  w .j  a va  2s .  c o m
 * 
 * @param url
 * @return
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws IOException
 * @throws KeyManagementException
 */
public static String get(String url) {//throws NoSuchAlgorithmException, NoSuchProviderException, IOException, KeyManagementException {
    InputStream in = null;
    HttpsURLConnection http = null;

    try {
        StringBuffer bufferRes = null;
        TrustManager[] tm = { new MyX509TrustManager() };
        SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
        sslContext.init(null, tm, new java.security.SecureRandom());
        // SSLContextSSLSocketFactory  
        SSLSocketFactory ssf = sslContext.getSocketFactory();

        URL urlGet = new URL(url);
        http = (HttpsURLConnection) urlGet.openConnection();
        // 
        http.setConnectTimeout(TIME_OUT_CONNECT);
        // ? --??
        http.setReadTimeout(TIME_OUT_READ);
        http.setRequestMethod("GET");
        http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        http.setSSLSocketFactory(ssf);
        http.setDoOutput(true);
        http.setDoInput(true);
        http.connect();

        in = http.getInputStream();
        BufferedReader read = new BufferedReader(new InputStreamReader(in, DEFAULT_CHARSET));
        String valueString = null;
        bufferRes = new StringBuffer();
        while ((valueString = read.readLine()) != null) {
            bufferRes.append(valueString);
        }
        return bufferRes.toString();
    } catch (Exception e) {
        logger.error(String.format("HTTP GET url=[%s] due to fail.", url), e);
    } finally {
        if (null != in) {
            try {
                in.close();
            } catch (IOException e) {
                logger.error(String.format("HTTP GET url=[%s] close inputstream due to fail.", url), e);
            }
        }
        if (http != null) {
            // 
            http.disconnect();
        }
    }

    return StringUtils.EMPTY;

}

From source file:com.itjenny.web.ArticleController.java

@RequestMapping(value = "{title}/{chapterCssId}", method = RequestMethod.POST)
public ModelAndView checkAnswer(HttpServletRequest request, @PathVariable String title,
        @PathVariable String chapterCssId, @RequestParam String answer) {
    Integer chapterIndex = Integer.valueOf(chapterCssId.replace(Consts.CHAPTER, StringUtils.EMPTY));
    ModelAndView mav = new ModelAndView();
    ModelMap model = new ModelMap();
    for (Cookie cookie : request.getCookies()) {
        if (cookie.getName().equals("keynote")) {
            Article article = articleService.get(title);
            if (article == null || !article.getUserId().equals(sessionService.getLoginUser().getUserId())) {
                break;
            }/*from   w w  w.j a  va2s . c o  m*/

            // keynote mode
            if (!articleService.isChapterExisted(title, chapterIndex + 1)) {
                bookmarkService.complete(title);
                return new ModelAndView("redirect:/article/" + title + "/license");
            }
            model.addAttribute("chapter", articleService.getChapter(title, chapterIndex + 1));
            model.addAttribute("totalSection", articleService.getTotalSection(title));
            model.addAttribute("answer", articleService.getChapter(title, chapterIndex).getQuiz().getAnswer());
            mav.setViewName(View.CHAPTER);
            mav.addAllObjects(model);

            bookmarkService.updateChapter(title, chapterIndex + 1);
            return mav;
        }
    }

    // word mode
    Chapter chapter = articleService.getChapter(title, chapterIndex);
    if (answerService.check(chapter, answer)) {
        if (!articleService.isChapterExisted(title, chapterIndex + 1)) {
            bookmarkService.complete(title);
            return new ModelAndView("redirect:/article/" + title + "/license");
        }
        model.addAttribute("chapter", articleService.getChapter(title, chapterIndex + 1));
        model.addAttribute("totalSection", articleService.getTotalSection(title));
        model.addAttribute("answer", articleService.getChapter(title, chapterIndex).getQuiz().getAnswer());
        mav.setViewName(View.CHAPTER);
        mav.addAllObjects(model);

        bookmarkService.updateChapter(title, chapterIndex + 1);
    } else {
        mav.setViewName(View.WRONG);
        mav.addAllObjects(model);
    }
    return mav;
}

From source file:de.blizzy.documentr.web.access.UserControllerTest.java

@Test
public void addUser() {
    String view = userController.addUser(model);
    assertEquals("/user/edit", view); //$NON-NLS-1$

    verify(model).addAttribute(eq("userForm"), //$NON-NLS-1$
            argUserForm(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, false));
}

From source file:com.ltln.modules.ni.omc.system.core.ftp.OmcFtplet.java

@Override
public FtpletResult onDisconnect(final FtpSession session) throws FtpException, IOException {
    Logger.info(String.format("User %s onDisconnect to FtpServer", session.getClientAddress().toString()));
    if (this.listener != null) {
        SelfBeanFactoryAware.getTaskThreadPool().submit(new Runnable() {
            @Override/*from  w  w w .  j a v a  2 s  .co  m*/
            public void run() {
                String user = session.getUser() == null ? StringUtils.EMPTY : session.getUser().getName();
                listener.ConnectionInactive(
                        new ConnectionModel(session.getClientAddress().toString(), EConnectionType.FTP, user));
            }
        });
    }
    return super.onDisconnect(session);
}