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

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

Introduction

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

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:com.jeans.iservlet.controller.impl.ImportController.java

@RequestMapping(method = RequestMethod.POST, value = "/ac")
@ResponseBody/*  w  w  w  .  ja v  a  2 s.c  o  m*/
public void importAC(@RequestParam("data") CommonsMultipartFile data, HttpServletResponse response)
        throws IOException {
    PrintWriter out = response.getWriter();
    if (null == data) {
        showError(out, "??");
        out.close();
        return;
    }
    int count = 0;
    String info = null;
    try (Workbook workBook = WorkbookFactory.create(data.getInputStream())) {
        Sheet acsSheet = workBook.getSheet("");
        if (null == acsSheet) {
            data.getInputStream().close();
            showError(out, "????Sheet");
            out.close();
            return;
        }
        Company comp = getCurrentCompany();
        int total = acsSheet.getLastRowNum();
        double progress = 0.0;
        double step = 100.0 / (double) total;
        showProgressDialog(out, getCurrentCompany().getAlias() + "???");
        // acsSheet: 1?06?70?
        int last = acsSheet.getLastRowNum();
        for (int rn = 1; rn <= last; rn++) {
            Row r = acsSheet.getRow(rn);
            // ??""???
            String flag = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(0, Row.RETURN_BLANK_AS_NULL)));
            // ???name?
            String name = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(2, Row.RETURN_BLANK_AS_NULL)));
            progress += step;
            if (!"".equals(flag) || StringUtils.isBlank(name)) {
                continue;
            }
            showProgress(out, "???" + name, progress); // 
            AccessoryType type = parseAccessoryType(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(1, Row.RETURN_BLANK_AS_NULL))));
            String brand = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(3, Row.RETURN_BLANK_AS_NULL)));
            String model = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(4, Row.RETURN_BLANK_AS_NULL)));
            String description = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(5, Row.RETURN_BLANK_AS_NULL)));
            String unit = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(6, Row.RETURN_BLANK_AS_NULL)));

            if (null != acsService.create(comp, type, name, brand, model, unit, description)) {
                count++;
            }
        }
        info = "????" + count + "?";
    } catch (Exception e) {
        log(e);
        info = "???????"
                + count + "?";
    } finally {
        data.getInputStream().close();
        closeProgressDialog(out);
        showInfo(out, info);
        out.close();
        log(info);
    }
}

From source file:net.lmxm.ute.configuration.ConfigurationReader.java

/**
 * Parses the preference./*from  w w  w .j a  va2s  .c o m*/
 * 
 * @param preferenceType the preference type
 * @return the preference
 */
private Preference parsePreference(final PreferenceType preferenceType) {
    final String prefix = "parsePreference() :";

    LOGGER.debug("{} entered", prefix);

    final Preference preference = new Preference();

    preference.setId(StringUtils.trim(preferenceType.getId()));

    LOGGER.debug("{} returning {}", prefix, preference);

    return preference;
}

From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineFactory.java

/**
 * Initializes a {@link MicroPipelineComponent} instance according to provided information
 * @param componentConfiguration/*from   w  ww  . j a  v  a 2  s  . co  m*/
 * @return
 * @throws RequiredInputMissingException
 * @throws ComponentInitializationFailedException
 * TODO test for settings that must be provided for type SOURCE
 * TODO test for settings that must be provided for type EMITTER
 * TODO test for settings that must be provided for type OPERATOR
 * TODO test queue references in toQueues and fromQueues
 * TODO test component instantiation
 */
protected MicroPipelineComponent initializeComponent(
        final MicroPipelineComponentConfiguration componentConfiguration,
        final Map<String, StreamingMessageQueue> queues)
        throws RequiredInputMissingException, ComponentInitializationFailedException {

    ///////////////////////////////////////////////////////////////////////////////////
    // validate input
    if (componentConfiguration == null)
        throw new RequiredInputMissingException("Missing required component configuration");
    if (StringUtils.isBlank(componentConfiguration.getId()))
        throw new RequiredInputMissingException("Missing required component identifier");
    if (componentConfiguration.getType() == null)
        throw new RequiredInputMissingException("Missing required component type");
    if (StringUtils.isBlank(componentConfiguration.getName()))
        throw new RequiredInputMissingException("Missing required component name");
    if (StringUtils.isBlank(componentConfiguration.getVersion()))
        throw new RequiredInputMissingException("Missing required component version");
    if (componentConfiguration.getSettings() == null)
        throw new RequiredInputMissingException("Missing required component settings");
    //
    ////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////
    // validate settings for components of type: SOURCE
    if (componentConfiguration.getType() == MicroPipelineComponentType.SOURCE) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: DIRECT_RESPONSE_OPERATOR
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.DIRECT_RESPONSE_OPERATOR) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: DELAYED_RESPONSE_OPERATOR
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.DELAYED_RESPONSE_OPERATOR) {

        if (StringUtils.isBlank(componentConfiguration.getToQueue()))
            throw new RequiredInputMissingException("Missing required queues to write content to");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getToQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown destination queue '" + componentConfiguration.getToQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");

        if (StringUtils.isBlank(componentConfiguration.getSettings()
                .getProperty(DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME)))
            throw new RequiredInputMissingException(
                    "Missing required settings for wait strategy applied to delayed response operator");

        ////////////////////////////////////////////////////////////////////////////////////
        // validate settings for components of type: EMITTER
    } else if (componentConfiguration.getType() == MicroPipelineComponentType.EMITTER) {

        if (StringUtils.isBlank(componentConfiguration.getFromQueue()))
            throw new RequiredInputMissingException("Missing required queues to retrieve content from");
        if (!queues.containsKey(StringUtils.lowerCase(StringUtils.trim(componentConfiguration.getFromQueue()))))
            throw new RequiredInputMissingException(
                    "Unknown source queue '" + componentConfiguration.getFromQueue() + "'");
    }
    //
    ////////////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////
    // instantiate component class
    try {
        return this.componentRepository.newInstance(componentConfiguration.getId(),
                componentConfiguration.getName(), componentConfiguration.getVersion(),
                componentConfiguration.getSettings());
    } catch (Exception e) {
        throw new ComponentInitializationFailedException("Failed to initialize component '"
                + componentConfiguration.getId() + "'. Error: " + e.getMessage(), e);
    }
    //
    ////////////////////////////////////////////////////////////////////////////////////

}

From source file:io.seldon.importer.articles.GeneralItemAttributesImporter.java

private void invalidateUsingBannerItemLogFile(ItemBean item) throws Exception {
    if (bannerItemLogFile != null) {

        if (bannerInValidType == null) {
            throw new Exception("using -bannerItemLogFile but bannerInValidType is null");
        }/*  w  ww  .  j a  v  a2  s . c  o  m*/

        final String current_item_id = item.getId();
        final String current_item_baseurl = item.getAttributesName().get("baseurl");

        { // make sure we log the current item if it was modified
            if (!current_item_id.equals(current_item_baseurl)) { // if the currrent's id and baseurl are the same - means it wasnt imported and it set with an id, so dont write it out
                PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(bannerItemLogFile, true)));
                out.println(current_item_id + "|" + current_item_baseurl);
                out.close();
            }
        }

        File f = new File(bannerItemLogFile);
        if (f.exists() && !f.isDirectory()) {
            Set<String> itemList = new HashSet<String>();
            BufferedReader br = new BufferedReader(new FileReader(bannerItemLogFile));
            String line;
            while ((line = br.readLine()) != null) {
                line = StringUtils.trim(line);
                if (line.length() > 0) {
                    itemList.add(line);
                }
            }
            br.close();

            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(bannerItemLogFile, false)));
            for (String loggedItem : itemList) {

                String logged_item_id = null;
                String logged_item_baseurl = null;
                {
                    String[] line_items = StringUtils.split(loggedItem, '|');
                    if (line_items.length == 2) {
                        logged_item_id = line_items[0];
                        logged_item_baseurl = line_items[1];
                    }
                }
                if ((logged_item_id != null) && (logged_item_baseurl != null)) {

                    if (logged_item_baseurl.equalsIgnoreCase(current_item_baseurl)
                            && !logged_item_id.equalsIgnoreCase(current_item_id)) {
                        ItemBean itemToInvalidate = new ItemBean(logged_item_id, "",
                                Integer.parseInt(bannerInValidType));
                        if (invalidContentTypeOverride != null) {
                            Map<String, String> attributes_override = new HashMap<String, String>();
                            attributes_override.put("content_type", invalidContentTypeOverride);
                            itemToInvalidate.setAttributesName(attributes_override);
                        }
                        logger.info("Invalidating Item: " + itemToInvalidate);
                        if (!testmode) {
                            try {
                                client.updateItem(itemToInvalidate);
                            } catch (ApiException e) {
                                logger.error("ERROR trying to invalidate item [" + itemToInvalidate.getId()
                                        + "] :" + e.toString());
                                out.println(logged_item_id + "|" + logged_item_baseurl); // keep as we have an error
                            }
                        } else {
                            logger.info("TESTMODE skipping Invalidate update");
                        }
                    } else {
                        out.println(logged_item_id + "|" + logged_item_baseurl);
                    }
                }
            }
            out.close();
        }
    }
}

From source file:net.lmxm.ute.configuration.ConfigurationReader.java

/**
 * Parses the property./*from w ww  . j  a  v  a  2 s . c o  m*/
 * 
 * @param propertyType the property type
 * 
 * @return the property
 */
private Property parseProperty(final PropertyType propertyType) {
    final String prefix = "parseProperty() :";

    LOGGER.debug("{} entered", prefix);

    final Property property = new Property();

    property.setId(StringUtils.trim(propertyType.getId()));
    property.setValue(StringUtils.trim(propertyType.getValue()));

    LOGGER.debug("{} returning {}", prefix, property);

    return property;
}

From source file:com.moviejukebox.plugin.TheMovieDbPlugin.java

@Override
public boolean scanNFO(String nfo, Movie movie) {
    int beginIndex;

    boolean result = Boolean.FALSE;

    if (StringTools.isValidString(movie.getId(TMDB_PLUGIN_ID))) {
        LOG.debug("TheMovieDb ID exists for {} = {}", movie.getBaseName(), movie.getId(TMDB_PLUGIN_ID));
        result = Boolean.TRUE;/*  ww w.  j  av a2s . c o  m*/
    } else {
        LOG.debug("Scanning NFO for TheMovieDb ID");
        beginIndex = nfo.indexOf("/movie/");
        if (beginIndex != -1) {
            StringTokenizer st = new StringTokenizer(nfo.substring(beginIndex + 7), TOKEN_SPLIT);
            movie.setId(TMDB_PLUGIN_ID, st.nextToken());
            LOG.debug("TheMovieDb ID found in NFO = {}", movie.getId(TMDB_PLUGIN_ID));
            result = Boolean.TRUE;
        } else {
            LOG.debug("No TheMovieDb ID found in NFO!");
        }
    }

    // We might as well look for the IMDb ID as well
    if (StringTools.isValidString(movie.getId(IMDB_PLUGIN_ID))) {
        LOG.debug("IMDB ID exists for {} = {}", movie.getBaseName(), movie.getId(IMDB_PLUGIN_ID));
        result = Boolean.TRUE;
    } else {
        beginIndex = nfo.indexOf("/tt");
        if (beginIndex != -1) {
            StringTokenizer st = new StringTokenizer(nfo.substring(beginIndex + 1), TOKEN_SPLIT);
            movie.setId(ImdbPlugin.IMDB_PLUGIN_ID, StringUtils.trim(st.nextToken()));
            LOG.debug("IMDB ID found in nfo = {}", movie.getId(ImdbPlugin.IMDB_PLUGIN_ID));
        } else {
            beginIndex = nfo.indexOf("/Title?");
            if (beginIndex != -1 && beginIndex + 7 < nfo.length()) {
                StringTokenizer st = new StringTokenizer(nfo.substring(beginIndex + 7), TOKEN_SPLIT);
                movie.setId(ImdbPlugin.IMDB_PLUGIN_ID, "tt" + StringUtils.trim(st.nextToken()));
                LOG.debug("IMDB ID found in NFO = {}", movie.getId(ImdbPlugin.IMDB_PLUGIN_ID));
            }
        }
    }
    return result;
}

From source file:com.blacklocus.metrics.CloudWatchReporter.java

private String appendGlobalDimensions(String metric) {
    if (StringUtils.isBlank(StringUtils.trim(dimensions))) {
        return metric;
    } else {/* w w w  . ja  va 2 s .  c o  m*/
        return metric + NAME_TOKEN_DELIMITER + dimensions;
    }
}

From source file:net.lmxm.ute.configuration.ConfigurationReader.java

/**
 * Parses the subversion repository location.
 * //from ww w  . j  a v a 2  s.c om
 * @param locationType the location type
 * @return the subversion repository location
 */
private SubversionRepositoryLocation parseSubversionRepositoryLocation(
        final SubversionRepositoryLocationType locationType) {
    final String prefix = "parseSubversionRepositoryLocation() :";

    LOGGER.debug("{} entered", prefix);

    final SubversionRepositoryLocation location = new SubversionRepositoryLocation();

    location.setId(StringUtils.trim(locationType.getId()));
    location.setUrl(StringUtils.trim(locationType.getUrl()));
    location.setUsername(StringUtils.trim(locationType.getUsername()));
    location.setPassword(StringUtils.trim(locationType.getPassword()));

    LOGGER.debug("{} returning {}", prefix, location);

    return location;
}

From source file:br.com.autonomiccs.cloudTraces.main.CloudTracesSimulator.java

private static Collection<VirtualMachine> getAllVirtualMachinesFromCloudTraces(
        String cloudTraceFullQualifiedFilePath) {
    Map<String, VirtualMachine> poolOfVirtualMachines = new HashMap<>();
    try (BufferedReader bf = new BufferedReader(new FileReader(cloudTraceFullQualifiedFilePath))) {
        String line = bf.readLine();
        while (line != null) {
            if (StringUtils.trim(line).isEmpty() || StringUtils.startsWith(line, "#")) {
                line = bf.readLine();/*w w  w  .  ja v a  2  s . co m*/
                continue;
            }
            Matcher matcher = patternMatchVmsData.matcher(line);
            if (!matcher.matches()) {
                throw new GoogleTracesToCloudTracesException(
                        String.format("String [%s] does not meet the expected pattern.", line));
            }
            int time = Integer.parseInt(matcher.group(1));
            String vmId = matcher.group(2);
            VirtualMachine virtualMachine = poolOfVirtualMachines.get(vmId);
            if (virtualMachine == null) {
                virtualMachine = createVirtualMachine(matcher);
                poolOfVirtualMachines.put(vmId, virtualMachine);
            }
            loadTaskForTime(matcher, time, virtualMachine);
            line = bf.readLine();
        }
    } catch (IOException e) {
        throw new GoogleTracesToCloudTracesException(e);
    }
    return poolOfVirtualMachines.values();
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

private CodeTemplateRootTreeTableNode getFilteredRootNode(CodeTemplateRootTreeTableNode root) {
    CodeTemplateRootTreeTableNode newRoot = new CodeTemplateRootTreeTableNode();
    String filter = StringUtils.trim(templateFilterField.getText());

    for (Enumeration<? extends MutableTreeTableNode> libraryNodes = root.children(); libraryNodes
            .hasMoreElements();) {/*from  w  w  w . ja va 2 s .  co m*/
        CodeTemplateLibraryTreeTableNode libraryNode = (CodeTemplateLibraryTreeTableNode) libraryNodes
                .nextElement();

        CodeTemplateLibraryTreeTableNode newLibraryNode = new CodeTemplateLibraryTreeTableNode(
                libraryNode.getLibrary());

        for (Enumeration<? extends MutableTreeTableNode> codeTemplateNodes = libraryNode
                .children(); codeTemplateNodes.hasMoreElements();) {
            CodeTemplateTreeTableNode codeTemplateNode = (CodeTemplateTreeTableNode) codeTemplateNodes
                    .nextElement();

            if (StringUtils.containsIgnoreCase((String) codeTemplateNode.getValueAt(TEMPLATE_NAME_COLUMN),
                    filter)) {
                CodeTemplateTreeTableNode newCodeTemplateNode = new CodeTemplateTreeTableNode(
                        codeTemplateNode.getCodeTemplate());
                newLibraryNode.add(newCodeTemplateNode);
            }
        }

        if (newLibraryNode.getChildCount() > 0 || StringUtils
                .containsIgnoreCase((String) libraryNode.getValueAt(TEMPLATE_NAME_COLUMN), filter)) {
            newRoot.add(newLibraryNode);
        }
    }

    return newRoot;
}