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

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

Introduction

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

Prototype

public static String trimToEmpty(String str) 

Source Link

Document

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

Usage

From source file:com.prowidesoftware.swift.model.field.Field94G.java

/**
 * Get the Address as a concatenation of component2 to component3.
 * @return the Address from components/*from  ww  w.  ja v a2  s . c o m*/
 */
public String getAddress() {
    StringBuilder result = new StringBuilder();
    for (int i = 2; i < 4; i++) {
        if (StringUtils.isNotBlank(getComponent(i))) {
            if (result.length() > 0) {
                result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
            }
            result.append(StringUtils.trimToEmpty(getComponent(i)));
        }
    }
    return result.toString();
}

From source file:com.laxser.blitz.scanner.ModuleResourceProviderImpl.java

protected void checkModuleResourceCandidate(Local local, FileObject root, FileObject topModuleFile,
        FileObject candidate) throws IOException {

    String relative = topModuleFile.getName().getRelativeName(candidate.getName());
    String mappingPath = null;/*  w ww  .ja v  a 2  s  . co m*/
    String[] interceptedAllow = null;
    String[] interceptedDeny = null;

    ModuleResource parentModule = local.moduleResourceMap.get(candidate.getParent());
    // blitz.propertiescontrollersmodule.path?
    FileObject blitzPropertiesFile = candidate.getChild("blitz.properties");
    if (blitzPropertiesFile != null && blitzPropertiesFile.exists()) {
        Properties p = new Properties();
        InputStream in = blitzPropertiesFile.getContent().getInputStream();
        p.load(in);
        in.close();

        // controllers=ignored...
        String ignored = p.getProperty(CONF_MODULE_IGNORED, "false").trim();
        if ("true".equalsIgnoreCase(ignored) || "1".equalsIgnoreCase(ignored)) {
            if (logger.isInfoEnabled()) {
                logger.info("Ignored module(include submodules) by blitz.properties[ignored=" + ignored + "]: "
                        + candidate);
            }
            return;
        }

        mappingPath = p.getProperty(CONF_MODULE_PATH);
        if (mappingPath != null) {
            mappingPath = mappingPath.trim();
            String parentModulePlaceHolder = "${" + CONF_PARENT_MODULE_PATH + "}";
            if (mappingPath.indexOf(parentModulePlaceHolder) != -1) {
                String parentModulePath = "";
                if (candidate.getParent() != null) {
                    parentModulePath = (parentModule == null) ? "" : parentModule.getMappingPath();
                }
                mappingPath = mappingPath.replace(parentModulePlaceHolder, parentModulePath);
            }
            if (mappingPath.length() != 0 && !mappingPath.startsWith("/")) {
                if (parentModule != null) {
                    mappingPath = parentModule.getMappingPath() + "/" + mappingPath;
                } else if (StringUtils.isNotEmpty(relative)) {
                    mappingPath = relative + "/" + mappingPath;
                } else {
                    mappingPath = "/" + mappingPath;
                }
            }
            mappingPath = BlitzStringUtil.mappingPath(mappingPath);
        }

        //interceptedAllow?interceptedDeny
        String interceptedAllowStrings = p.getProperty(CONF_INTERCEPTED_ALLOW);
        interceptedAllowStrings = StringUtils.trimToEmpty(interceptedAllowStrings);
        if (interceptedAllowStrings.length() > 0) {
            interceptedAllow = StringUtils.split(interceptedAllowStrings, ",");
        }

        String interceptedDenyStrings = p.getProperty(CONF_INTERCEPTED_DENY);
        interceptedDenyStrings = StringUtils.trimToEmpty(interceptedDenyStrings);
        if (interceptedDenyStrings.length() > 0) {
            interceptedDeny = StringUtils.split(interceptedDenyStrings, ",");
        }

    }
    // 
    if (mappingPath == null) {
        if (parentModule != null) {
            mappingPath = parentModule.getMappingPath() + "/" + candidate.getName().getBaseName();
        } else {
            mappingPath = "";
        }
    }
    ModuleResource moduleResource = new ModuleResource();
    moduleResource.setMappingPath(mappingPath);
    moduleResource.setModuleUrl(candidate.getURL());
    moduleResource.setRelativePath(BlitzStringUtil.relativePathToModulePath(relative));
    moduleResource.setParent(parentModule);
    if (interceptedAllow != null) {
        moduleResource.setInterceptedAllow(interceptedAllow);
    }
    if (interceptedDeny != null) {
        moduleResource.setInterceptedDeny(interceptedDeny);
    }
    local.moduleResourceMap.put(candidate, moduleResource);
    local.moduleResourceList.add(moduleResource);
    if (logger.isDebugEnabled()) {
        logger.debug("found module '" + mappingPath + "' in " + candidate.getURL());
    }

    FileObject[] children = candidate.getChildren();
    for (FileObject child : children) {
        if (child.getType().hasContent() && !child.getType().hasChildren()) {
            handlerModuleResource(local, root, candidate, child);
        }
    }
    for (FileObject child : children) {
        if (child.getType().hasChildren()) {
            checkModuleResourceCandidate(local, root, topModuleFile, child);
        }
    }
}

From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.dialog.ExtensionBrowserURLDialog.java

/**
 * browser data ./*from   w  w  w .  j  av a 2 s  .co  m*/
 */
private void addExtensionBrowserData() {
    String strName = StringUtils.trimToEmpty(textName.getText());
    String strUrl = StringUtils.trimToEmpty(textURL.getText());
    String strCmt = StringUtils.trimToEmpty(textComment.getText());

    if (!ValidChecker.checkTextCtl(textName, Messages.get().Name))
        return;
    if (!ValidChecker.checkTextCtl(textURL, Messages.get().URL))
        return;

    // url?? ?  .
    List<ExternalBrowserInfoDAO> listCheckExterBroswer = (List) tableViewer.getInput();
    for (ExternalBrowserInfoDAO externalBrowserInfoDAO : listCheckExterBroswer) {
        if (strUrl.equals(externalBrowserInfoDAO.getUrl())) {
            MessageDialog.openWarning(null, Messages.get().Warning, Messages.get().Name); //$NON-NLS-1$
            return;
        }
    }

    // ?? .
    ExternalBrowserInfoDAO newDao = new ExternalBrowserInfoDAO();
    newDao.setIs_used(comboUsed.getText());
    newDao.setName(strName);
    newDao.setUrl(strUrl);
    newDao.setComment(strCmt);

    listExterBroswer.add(newDao);
    tableViewer.refresh();
}

From source file:com.iyonger.apm.web.controller.FileEntryController.java

/**
 * Provide new file creation form data.//from ww  w  .  j ava2  s .c  om
 *
 * @param user                  current user
 * @param path                  path in which a file will be added
 * @param testUrl               url which the script may use
 * @param fileName              fileName
 * @param scriptType            Type of script. optional
 * @param createLibAndResources true if libs and resources should be created as well.
 * @param redirectAttributes    redirect attributes storage
 * @param model                 model.
 * @return script/editor"
 */
@RequestMapping(value = "/new/**", params = "type=script", method = RequestMethod.POST)
public String createForm(@RemainedPath String path,
        @RequestParam(value = "testUrl", required = false) String testUrl,
        @RequestParam("fileName") String fileName,
        @RequestParam(value = "scriptType", required = false) String scriptType,
        @RequestParam(value = "createLibAndResource", defaultValue = "false") boolean createLibAndResources,
        @RequestParam(value = "options", required = false) String options,
        RedirectAttributes redirectAttributes, ModelMap model) throws Exception {
    User user = getCurrentUser();

    fileName = StringUtils.trimToEmpty(fileName);
    String name = "Test1";
    if (StringUtils.isEmpty(testUrl)) {
        testUrl = StringUtils.defaultIfBlank(testUrl, "http://please_modify_this.com");
    } else {
        name = UrlUtils.getHost(testUrl);
    }
    ScriptHandler scriptHandler = fileEntryService.getScriptHandler(scriptType);
    FileEntry entry = new FileEntry();
    entry.setPath(fileName);
    if (scriptHandler instanceof ProjectHandler) {
        if (!fileEntryService.hasFileEntry(user, PathUtils.join(path, fileName))) {
            fileEntryService.prepareNewEntry(user, path, fileName, name, testUrl, scriptHandler,
                    createLibAndResources, options);
            redirectAttributes.addFlashAttribute("message", fileName + " project is created.");
            return "redirect:/script/list/" + path + "/" + fileName;
        } else {
            redirectAttributes.addFlashAttribute("exception",
                    fileName + " is already existing. Please choose the different name");
            return "redirect:/script/list/" + path + "/";
        }

    } else {
        String fullPath = PathUtils.join(path, fileName);
        if (fileEntryService.hasFileEntry(user, fullPath)) {
            model.addAttribute("file", fileEntryService.getOne(user, fullPath));
        } else {
            model.addAttribute("file", fileEntryService.prepareNewEntry(user, path, fileName, name, testUrl,
                    scriptHandler, createLibAndResources, options));
        }
    }
    model.addAttribute("breadcrumbPath", getScriptPathBreadcrumbs(PathUtils.join(path, fileName)));
    model.addAttribute("scriptHandler", scriptHandler);
    model.addAttribute("createLibAndResource", createLibAndResources);
    return "/script/editor";
}

From source file:com.hangum.tadpole.rdb.core.dialog.table.mysql.MySQLTaableCreateDialog.java

@Override
protected void okPressed() {
    String strTableName = StringUtils.trimToEmpty(textTableName.getText());
    if ("".equals(strTableName)) {
        MessageDialog.openWarning(null, Messages.get().Warning, Messages.get().TableCreationNameAlter);
        textTableName.setFocus();/*www . j a  va 2s.co  m*/
        return;
    }

    tableCreateDao = new TableCreateDAO();
    tableCreateDao.setName(strTableName);
    Map<Integer, Object> selEncodingData = (Map<Integer, Object>) comboTableEncoding
            .getData(comboTableEncoding.getText());
    tableCreateDao.setEncoding("" + selEncodingData.get(0));
    tableCreateDao.setCollation("" + comboTableCollation.getData(comboTableCollation.getText()));
    tableCreateDao.setType("" + comboTableType.getData(comboTableType.getText()));

    if (MessageDialog.openConfirm(null, Messages.get().Confirm, Messages.get().TableCreationWantToCreate)) {
        String strCreateTable = String.format(MySQLDMLTemplate.TMP_DIALOG_CREATE_TABLE,
                tableCreateDao.getName(), tableCreateDao.getEncoding(), tableCreateDao.getCollation(),
                tableCreateDao.getType());

        try {
            ExecuteDDLCommand.executSQL(userDB, strCreateTable);

            ExplorerViewer ev = (ExplorerViewer) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                    .getActivePage().findView(ExplorerViewer.ID);
            if (ev != null)
                ev.refreshTable(true, strTableName);

            super.okPressed();
        } catch (Exception e) {
            logger.error("table create exception", e); //$NON-NLS-1$

            TDBErroDialog errDialog = new TDBErroDialog(null, Messages.get().ObjectDeleteAction_25,
                    Messages.get().TableCreationError + e.getMessage());
            errDialog.open();

            textTableName.setFocus();
        }
    }
}

From source file:com.alibaba.otter.manager.biz.autokeeper.impl.AutoKeeperCollector.java

public void collectorServerStat(String address) {
    List<String> netAddress = splitAddress(address);
    if (netAddress.isEmpty()) {
        return;//from ww  w . ja va2s  .  c  o m
    }
    String ip = netAddress.get(0);
    String port = netAddress.get(1);
    String[] cmd = { "/bin/bash", "-c", String.format(CMD_STAT, ip, port) };
    String cmdresult = collector(cmd);
    String[] result = cmdresult.split(WRAP);
    AutoKeeperServerStat summary = new AutoKeeperServerStat();
    summary.setOriginalContent(cmdresult);
    for (String line : result) {

        if (line.contains(MODE_FOLLOWER)) {
            summary.setQuorumType(AutoKeeperQuorumType.FOLLOWER);
        } else if (line.contains(MODE_LEADERER)) {
            summary.setQuorumType(AutoKeeperQuorumType.LEADER);
        } else if (line.contains(MODE_STANDALONE)) {
            summary.setQuorumType(AutoKeeperQuorumType.STANDALONE);
        } else if (line.contains(MODE_OBSERVER)) {
            summary.setQuorumType(AutoKeeperQuorumType.OBSERVER);
        } else if (line.contains(STRING_LATENCY)) {
            List<String> latency = Arrays.asList(
                    StringUtils.trimToEmpty(line.replace(STRING_LATENCY, StringUtils.EMPTY)).split("/"));
            summary.setMinLatency(Long.parseLong(latency.get(0)));
            summary.setAvgLatency(Long.parseLong(latency.get(1)));
            summary.setMaxLatency(Long.parseLong(latency.get(2)));
        } else if (line.contains(STRING_OUTSTANDING)) {
            summary.setQueued(Long
                    .parseLong(StringUtils.trimToEmpty(line.replace(STRING_OUTSTANDING, StringUtils.EMPTY))));
        } else if (line.contains(NODE_COUNT)) {
            summary.setNodeCount(
                    Long.parseLong(StringUtils.trimToEmpty(line.replace(NODE_COUNT, StringUtils.EMPTY))));
        } else if (line.contains(STRING_SENT)) {
            summary.setSent(
                    Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_SENT, StringUtils.EMPTY))));
        } else if (line.contains(STRING_RECEIVED)) {
            summary.setRecved(
                    Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_RECEIVED, StringUtils.EMPTY))));
        }
    }

    autoKeeperData.joinServer(address, summary);
}

From source file:com.egt.ejb.toolkit.ToolKitUtils.java

public static String concatenate(String string1, String string2) {
    String s1 = StringUtils.trimToEmpty(string1);
    String s2 = StringUtils.trimToEmpty(string2);
    if (StringUtils.isEmpty(s1)) {
        return s2;
    } else if (StringUtils.isEmpty(s2)) {
        return s1;
    } else {/*ww w.  ja va 2  s  .com*/
        return s1 + ' ' + s2;
    }
}

From source file:com.edgenius.wiki.installation.DBLoader.java

public String getDriver(String dbType, String driverType) {
    driverType = StringUtils.isBlank(driverType) ? "" : ("." + StringUtils.trim(driverType));
    return StringUtils.trimToEmpty(prototype.getProperty(dbType + driverType + ".driver"));
}

From source file:com.edgenius.wiki.render.impl.LinkRenderHelperImpl.java

public String getExternalImage(RenderContext renderContext, String url) {
    //put aid="norender, so that in RichRender, it won't render to !image.jpg! markup
    // NOTE: the same image also hardcode in Filter regex in com.edgenius.wiki.render.Filter.properties file
    if (StringUtils.trimToEmpty(url).startsWith("mailto")) {
        return RenderUtil.getExternalEmailImage(renderContext);
    } else {/* w  w  w . j  a v  a 2  s  .c  o  m*/
        return RenderUtil.getExternalImage(renderContext);
    }
}

From source file:adalid.commons.util.StrUtils.java

public static String getStringParametrizado(String patron, Object... argumentos) {
    if (StringUtils.isBlank(patron)) {
        return null;
    }/*from   w  ww .  j ava 2s .  c  om*/
    ArrayList<Object> objetos = new ArrayList<>();
    for (Object arg : argumentos) {
        objetos.add(StringUtils.trimToEmpty(getString(arg)));
    }
    return MessageFormat.format(patron, objetos.toArray());
}