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

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

Introduction

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

Prototype

public static String remove(String str, char remove) 

Source Link

Document

Removes all occurrences of a character from within the source string.

Usage

From source file:com.hangum.tadpole.rdb.core.viewers.connections.ManagerViewer.java

/**
 * SQLite file download/*ww w.j  a va 2 s .  c o  m*/
 */
public void download(final UserDBDAO userDB) {
    try {
        String strFileLoc = StringUtils
                .difference(StringUtils.remove(userDB.getDBDefine().getDB_URL_INFO(), "%s"), userDB.getUrl());
        File dbFile = new File(strFileLoc);

        byte[] arrayData = FileUtils.readFileToByteArray(dbFile);

        downloadServiceHandler.setContentType("");
        downloadServiceHandler.setName(dbFile.getName()); //$NON-NLS-1$
        downloadServiceHandler.setByteContent(arrayData);
        DownloadUtils.provideDownload(compositeMainComposite, downloadServiceHandler.getId());
    } catch (Exception e) {
        logger.error("SQLite file Download exception", e); //$NON-NLS-1$

        Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
        ExceptionDetailsErrorDialog.openError(null, Messages.get().Error, "DB Download Exception", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:module.siadap.domain.wrappers.UnitSiadapWrapper.java

/**
 * /*from   w w w  .  j  ava2 s .c  o m*/
 * @return the number of the harmonization unit, or null if there is no H.U.
 */
public Integer getHarmonizationUnitNumber() {
    Unit harmonizationUnit = getHarmonizationUnit();
    if (harmonizationUnit == null) {
        return null;
    }
    return Integer.valueOf(StringUtils.remove(harmonizationUnit.getAcronym(), HARMONIZATION_UNIT_NAME_PREFIX));
}

From source file:info.magnolia.templating.elements.AreaElement.java

protected String resolveAvailableComponents() {
    if (StringUtils.isNotEmpty(availableComponents)) {
        return StringUtils.remove(availableComponents, " ");
    }//from  w ww .j  av a 2 s .  co  m
    if (areaDefinition != null && areaDefinition.getAvailableComponents().size() > 0) {
        Iterator<ComponentAvailability> iterator = areaDefinition.getAvailableComponents().values().iterator();
        List<String> componentIds = new ArrayList<String>();
        final Collection<String> userRoles = MgnlContext.getUser().getAllRoles();
        while (iterator.hasNext()) {
            ComponentAvailability availableComponent = iterator.next();
            if (availableComponent.isEnabled()) {
                // check roles
                final Collection<String> roles = availableComponent.getRoles();
                if (!roles.isEmpty()) {
                    if (CollectionUtils.containsAny(userRoles, roles)) {
                        componentIds.add(availableComponent.getId());
                    }
                } else {
                    componentIds.add(availableComponent.getId());
                }
            }
        }
        return StringUtils.join(componentIds, ',');
    }
    return "";
}

From source file:edu.ku.brc.specify.tools.l10nios.StrLocalizerAppForiOS.java

/**
 * //from w  w  w.ja  v  a 2  s  .  c  o m
 */
private void itemSelected() {
    checkForChange();

    int inx = termList.getSelectedIndex();
    if (inx > -1) {
        transBtn.setEnabled(true);
        L10NItem srcEntry = (L10NItem) model.getElementAt(inx);
        //System.out.println(srcEntry.hashCode());

        srcLbl.setText(srcEntry.getTitle());

        String comStr = srcEntry.isUIComp() ? "" : srcEntry.getComment();
        if (StringUtils.isNotEmpty(comStr)) {
            comStr = StringUtils.remove(comStr, "/* ");
            comStr = StringUtils.remove(comStr, " */").trim();
            comStr = StringUtils.replace(comStr, " \n", "\n");
            comStr = StringUtils.replace(comStr, "\n  ", "\n");
            comStr = StringUtils.replace(comStr, "\n", ";\n");
        }
        comment.setText(comStr);

        String str = srcEntry.getValue();

        try {
            str = new String(str.getBytes("UTF-8"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        textField.setText(str);//str != null ? str : srcEntry.getKey());

        rsController.removeListener(rscListener);
        rsController.setIndex(inx);
        rsController.addListener(rscListener);

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                textField.requestFocus();
                textField.selectAll();
            }
        });

    } else {
        srcLbl.setText("");
        textField.setText("");
        transBtn.setEnabled(false);
    }
    oldInx = inx;
}

From source file:adalid.core.AbstractArtifact.java

/**
 * @return the full name/*from w w  w  . j  av  a2s . c  om*/
 */
@Override
public String getFullName() {
    return StringUtils.remove(getPathString(), "." + "this");
}

From source file:edu.ku.brc.specify.config.LatLonConverter.java

public static BigDecimal convertDDDDStrToDDDDBD(final String str) {
    String withoutDegSign = StringUtils.chomp(str, "");
    //above doesn't always work for Windows/Mac so try again...
    withoutDegSign = StringUtils.chomp(withoutDegSign, "");
    //apparently need to do this on mac
    withoutDegSign = StringUtils.remove(withoutDegSign, UNICODE_DEGREE);

    String val = StringUtils.replace(StringUtils.replace(withoutDegSign, decimalSep, ""), "-", "");
    return StringUtils.isNumeric(val) ? parseDoubleToBigDecimal(withoutDegSign) : null;
}

From source file:com.doculibre.constellio.wicket.pages.SearchResultsPage.java

private void initComponents() {
    final SimpleSearch simpleSearch = getSimpleSearch();
    String collectionName = simpleSearch.getCollectionName();
    ConstellioUser currentUser = ConstellioSession.get().getUser();
    RecordCollectionServices recordCollectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    RecordCollection collection = recordCollectionServices.get(collectionName);
    boolean userHasPermission = false;
    if (collection != null) {
        userHasPermission = (!collection.hasSearchPermission())
                || (currentUser != null && currentUser.hasSearchPermission(collection));
    }/*  ww w.j  a  v  a 2 s  .  c  om*/
    if (StringUtils.isEmpty(collectionName) || !userHasPermission) {
        setResponsePage(ConstellioApplication.get().getHomePage());
    } else {

        final IModel suggestedSearchKeyListModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                ListOrderedMap suggestedSearch = new ListOrderedMap();
                if (simpleSearch.isQueryValid() && simpleSearch.getQuery() != null) {
                    SpellChecker spellChecker = new SpellChecker(ConstellioApplication.get().getDictionaries());
                    try {
                        if (!simpleSearch.getQuery().equals("*:*")) {
                            suggestedSearch = spellChecker.suggest(simpleSearch.getQuery(),
                                    simpleSearch.getCollectionName());
                        }
                    } catch (RuntimeException e) {
                        e.printStackTrace();
                        // chec du spellchecker, pas besoin de faire planter la page
                    }
                }
                return suggestedSearch;
            }
        };

        BaseSearchResultsPageHeaderPanel headerPanel = (BaseSearchResultsPageHeaderPanel) getHeaderComponent();
        headerPanel.setAdvancedForm(simpleSearch.getAdvancedSearchRule() != null);
        SearchFormPanel searchFormPanel = headerPanel.getSearchFormPanel();

        final ThesaurusSuggestionPanel thesaurusSuggestionPanel = new ThesaurusSuggestionPanel(
                "thesaurusSuggestion", simpleSearch, getLocale());
        add(thesaurusSuggestionPanel);

        SpellCheckerPanel spellCheckerPanel = new SpellCheckerPanel("spellChecker",
                searchFormPanel.getSearchTxtField(), searchFormPanel.getSearchButton(),
                suggestedSearchKeyListModel) {
            @SuppressWarnings("unchecked")
            public boolean isVisible() {
                boolean visible = false;
                if (dataProvider != null && !thesaurusSuggestionPanel.isVisible()) {
                    RecordCollectionServices collectionServices = ConstellioSpringUtils
                            .getRecordCollectionServices();
                    RecordCollection collection = collectionServices.get(simpleSearch.getCollectionName());
                    if (collection != null && collection.isSpellCheckerActive()
                            && simpleSearch.getAdvancedSearchRule() == null) {
                        ListOrderedMap spell = (ListOrderedMap) suggestedSearchKeyListModel.getObject();
                        if (spell.size() > 0/* && dataProvider.size() == 0 */) {
                            for (String key : (List<String>) spell.keyList()) {
                                if (spell.get(key) != null) {
                                    return visible = true;
                                }
                            }
                        }
                    }
                }
                return visible;
            }
        };
        add(spellCheckerPanel);

        dataProvider = new SearchResultsDataProvider(simpleSearch, 10);

        WebMarkupContainer searchResultsSection = new WebMarkupContainer("searchResultsSection") {
            @Override
            public boolean isVisible() {
                return StringUtils.isNotBlank(simpleSearch.getLuceneQuery());
            }
        };
        add(searchResultsSection);

        IModel detailsLabelModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                String detailsLabel;
                QueryResponse queryResponse = dataProvider.getQueryResponse();
                long start;
                long nbRes;
                double elapsedTimeSeconds;
                if (queryResponse != null) {
                    start = queryResponse.getResults().getStart();
                    nbRes = dataProvider.size();
                    elapsedTimeSeconds = (double) queryResponse.getElapsedTime() / 1000;
                } else {
                    start = 0;
                    nbRes = 0;
                    elapsedTimeSeconds = 0;
                }
                long end = start + 10;
                if (nbRes < end) {
                    end = nbRes;
                }

                String pattern = "#.####";
                DecimalFormat elapsedTimeFormatter = new DecimalFormat(pattern);
                String elapsedTimeStr = elapsedTimeFormatter.format(elapsedTimeSeconds);

                String forTxt = new StringResourceModel("for", SearchResultsPage.this, null).getString();
                String noResultTxt = new StringResourceModel("noResult", SearchResultsPage.this, null)
                        .getString();
                String resultsTxt = new StringResourceModel("results", SearchResultsPage.this, null)
                        .getString();
                String ofTxt = new StringResourceModel("of", SearchResultsPage.this, null).getString();
                String secondsTxt = new StringResourceModel("seconds", SearchResultsPage.this, null)
                        .getString();

                String queryTxt = " ";
                if (simpleSearch.isQueryValid() && simpleSearch.getQuery() != null
                        && simpleSearch.getAdvancedSearchRule() == null) {
                    queryTxt = " " + forTxt + " " + simpleSearch.getQuery() + " ";
                }

                if (nbRes > 0) {
                    Locale locale = getLocale();
                    detailsLabel = resultsTxt + " " + NumberFormatUtils.format(start + 1, locale) + " - "
                            + NumberFormatUtils.format(end, locale) + " " + ofTxt + " "
                            + NumberFormatUtils.format(nbRes, locale) + queryTxt + "(" + elapsedTimeStr + " "
                            + secondsTxt + ")";
                } else {
                    detailsLabel = noResultTxt + " " + queryTxt + "(" + elapsedTimeStr + " " + secondsTxt + ")";
                }

                String collectionName = dataProvider.getSimpleSearch().getCollectionName();
                if (collectionName != null) {
                    RecordCollectionServices collectionServices = ConstellioSpringUtils
                            .getRecordCollectionServices();
                    RecordCollection collection = collectionServices.get(collectionName);
                    Locale displayLocale = collection.getDisplayLocale(getLocale());
                    String collectionTitle = collection.getTitle(displayLocale);
                    detailsLabel = collectionTitle + " > " + detailsLabel;
                }
                return detailsLabel;
            }
        };
        Label detailsLabel = new Label("detailsRes", detailsLabelModel);
        add(detailsLabel);

        final IModel sortOptionsModel = new LoadableDetachableModel() {

            @Override
            protected Object load() {
                List<SortChoice> choices = new ArrayList<SortChoice>();
                choices.add(new SortChoice(null, null, null));
                String collectionName = dataProvider.getSimpleSearch().getCollectionName();
                if (collectionName != null) {
                    IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
                    RecordCollectionServices collectionServices = ConstellioSpringUtils
                            .getRecordCollectionServices();
                    RecordCollection collection = collectionServices.get(collectionName);
                    for (IndexField indexField : indexFieldServices.getSortableIndexFields(collection)) {
                        String label = indexField.getLabel(IndexField.LABEL_TITLE,
                                ConstellioSession.get().getLocale());
                        if (label == null || label.isEmpty()) {
                            label = indexField.getName();
                        }
                        choices.add(new SortChoice(indexField.getName(), label, "asc"));
                        choices.add(new SortChoice(indexField.getName(), label, "desc"));
                    }
                }
                return choices;
            }
        };

        IChoiceRenderer triChoiceRenderer = new ChoiceRenderer() {
            @Override
            public Object getDisplayValue(Object object) {
                SortChoice choice = (SortChoice) object;
                String displayValue;
                if (choice.title == null) {
                    displayValue = new StringResourceModel("sort.relevance", SearchResultsPage.this, null)
                            .getString();
                } else {
                    String order = new StringResourceModel("sortOrder." + choice.order, SearchResultsPage.this,
                            null).getString();
                    displayValue = choice.title + " " + order;
                }
                return displayValue;
            }
        };
        IModel value = new Model(new SortChoice(simpleSearch.getSortField(), simpleSearch.getSortField(),
                simpleSearch.getSortOrder()));
        DropDownChoice sortField = new DropDownChoice("sortField", value, sortOptionsModel, triChoiceRenderer) {
            @Override
            protected boolean wantOnSelectionChangedNotifications() {
                return true;
            }

            @Override
            protected void onSelectionChanged(Object newSelection) {
                SortChoice choice = (SortChoice) newSelection;
                if (choice.name == null) {
                    simpleSearch.setSortField(null);
                    simpleSearch.setSortOrder(null);
                } else {
                    simpleSearch.setSortField(choice.name);
                    simpleSearch.setSortOrder(choice.order);
                }
                simpleSearch.setPage(0);

                PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                RequestCycle.get().setResponsePage(pageFactoryPlugin.getSearchResultsPage(),
                        SearchResultsPage.getParameters(simpleSearch));
            }

            @Override
            public boolean isVisible() {
                return ((List<?>) sortOptionsModel.getObject()).size() > 1;
            }
        };
        searchResultsSection.add(sortField);
        sortField.setNullValid(false);

        add(new AjaxLazyLoadPanel("facetsPanel") {
            @Override
            public Component getLazyLoadComponent(String markupId) {
                return new FacetsPanel(markupId, dataProvider);
            }
        });

        final IModel featuredLinkModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                FeaturedLink suggestion;
                RecordCollectionServices collectionServices = ConstellioSpringUtils
                        .getRecordCollectionServices();
                FeaturedLinkServices featuredLinkServices = ConstellioSpringUtils.getFeaturedLinkServices();
                Long featuredLinkId = simpleSearch.getFeaturedLinkId();
                if (featuredLinkId != null) {
                    suggestion = featuredLinkServices.get(featuredLinkId);
                } else {
                    String collectionName = simpleSearch.getCollectionName();
                    if (simpleSearch.getAdvancedSearchRule() == null) {
                        String text = simpleSearch.getQuery();
                        RecordCollection collection = collectionServices.get(collectionName);
                        suggestion = featuredLinkServices.suggest(text, collection);
                        if (suggestion == null) {
                            SynonymServices synonymServices = ConstellioSpringUtils.getSynonymServices();
                            List<String> synonyms = synonymServices.getSynonyms(text, collectionName);
                            if (!synonyms.isEmpty()) {
                                for (String synonym : synonyms) {
                                    if (!synonym.equals(text)) {
                                        suggestion = featuredLinkServices.suggest(synonym, collection);
                                    }
                                    if (suggestion != null) {
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        suggestion = new FeaturedLink();
                    }
                }
                return suggestion;
            }
        };
        IModel featuredLinkTitleModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                FeaturedLink featuredLink = (FeaturedLink) featuredLinkModel.getObject();
                return featuredLink.getTitle(getLocale());
            }
        };
        final IModel featuredLinkDescriptionModel = new LoadableDetachableModel() {
            @Override
            protected Object load() {
                FeaturedLink featuredLink = (FeaturedLink) featuredLinkModel.getObject();
                StringBuffer descriptionSB = new StringBuffer();
                String description = featuredLink.getDescription(getLocale());
                if (description != null) {
                    descriptionSB.append(description);
                    String lookFor = "${";
                    int indexOfLookFor = -1;
                    while ((indexOfLookFor = descriptionSB.indexOf(lookFor)) != -1) {
                        int indexOfEnclosingQuote = descriptionSB.indexOf("}", indexOfLookFor);
                        String featuredLinkIdStr = descriptionSB.substring(indexOfLookFor + lookFor.length(),
                                indexOfEnclosingQuote);

                        int indexOfTagBodyStart = descriptionSB.indexOf(">", indexOfEnclosingQuote) + 1;
                        int indexOfTagBodyEnd = descriptionSB.indexOf("</a>", indexOfTagBodyStart);
                        String capsuleQuery = descriptionSB.substring(indexOfTagBodyStart, indexOfTagBodyEnd);
                        if (capsuleQuery.indexOf("<br/>") != -1) {
                            capsuleQuery = StringUtils.remove(capsuleQuery, "<br/>");
                        }
                        if (capsuleQuery.indexOf("<br />") != -1) {
                            capsuleQuery = StringUtils.remove(capsuleQuery, "<br />");
                        }

                        try {
                            String linkedCapsuleURL = getFeaturedLinkURL(new Long(featuredLinkIdStr));
                            descriptionSB.replace(indexOfLookFor, indexOfEnclosingQuote + 1, linkedCapsuleURL);
                        } catch (NumberFormatException e) {
                            // Ignore
                        }
                    }
                }
                return descriptionSB.toString();
            }

            private String getFeaturedLinkURL(Long featuredLinkId) {
                SimpleSearch clone = simpleSearch.clone();
                clone.setFeaturedLinkId(featuredLinkId);
                PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class);
                String url = RequestCycle.get()
                        .urlFor(pageFactoryPlugin.getSearchResultsPage(), getParameters(clone)).toString();
                return url;
            }
        };

        WebMarkupContainer featuredLink = new WebMarkupContainer("featuredLink", featuredLinkModel) {
            @Override
            public boolean isVisible() {
                boolean visible = super.isVisible();
                if (visible) {
                    if (featuredLinkModel.getObject() != null) {
                        String description = (String) featuredLinkDescriptionModel.getObject();
                        visible = StringUtils.isNotEmpty(description);
                    } else {
                        visible = false;
                    }
                }
                DataView dataView = (DataView) searchResultsPanel.getDataView();
                return visible && dataView.getCurrentPage() == 0;
            }
        };
        searchResultsSection.add(featuredLink);
        featuredLink.add(new Label("title", featuredLinkTitleModel));
        featuredLink.add(new WebMarkupContainer("description", featuredLinkDescriptionModel) {
            @Override
            protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
                String descriptionHTML = (String) getModel().getObject();
                replaceComponentTagBody(markupStream, openTag, descriptionHTML);
            }
        });

        searchResultsSection
                .add(searchResultsPanel = new SearchResultsPanel("resultatsRecherchePanel", dataProvider));
    }
}

From source file:edu.ku.brc.util.LatLonConverter.java

/**
 * Converts Decmal Degrees to BigDecimal.
 * @param bd the DigDecimal to be converted.
 * @return a BigDecimal/*from   w  ww.  j ava 2s.c o  m*/
 */
public static BigDecimal convertDDDDStrToDDDDBD(final String str) {
    String withoutDegSign = StringUtils.chomp(str, "");
    //above doesn't always work for Windows/Mac so try again...
    withoutDegSign = StringUtils.chomp(withoutDegSign, "");
    //apparently need to do this on mac
    withoutDegSign = StringUtils.remove(withoutDegSign, UNICODE_DEGREE);

    String val = StringUtils.replace(StringUtils.replace(withoutDegSign, decimalSep, ""), "-", "");
    return StringUtils.isNumeric(val) ? UIHelper.parseDoubleToBigDecimal(withoutDegSign) : null;
}

From source file:com.centrica.vms.ws.service.VMSAckVoidService.java

private String removePrefix(String transactionID) {
    return StringUtils.remove(transactionID, "VOID_");
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatter.java

/**
 * Validates with any formatter that has fields defined and an inputed string
 * @param formatter the formatter // www  . j a  v a 2 s. com
 * @param text the text to be validated.
 * @return true if it is valid
 */
public static boolean isValid(final UIFieldFormatterIFace formatter, final String text,
        final boolean doValidateAll) {
    if (isNotEmpty(text)) {
        int txtLen = text.length();
        if (formatter.isLengthOK(txtLen)) {
            if (formatter.isDate()) {
                return isDateValid(formatter, text);
            }

            int inx = 0;
            int pos = 0;
            for (UIFieldFormatterField field : formatter.getFields()) {
                if (pos < txtLen) {
                    if (!field.isIncrementer() || doValidateAll) {
                        //numeric, alphanumeric, alpha, separator, year
                        String val = text.substring(pos, Math.min(pos + field.getSize(), txtLen));
                        switch (field.getType()) {
                        case numeric: {
                            String str1 = StringUtils.remove(val, '.');
                            String str2 = StringUtils.remove(str1, '-');

                            if (StringUtils.isNumeric(str2)) {
                                Class<?> cls = formatter.getDataClass();
                                if (cls == java.lang.Integer.class || cls == java.lang.Long.class
                                        || cls == java.lang.Short.class || cls == java.lang.Byte.class) {
                                    return str1.length() == val.length();
                                }
                                return true;
                            }
                            return false;
                        }

                        case alphanumeric:
                            if (!isAlphanumeric(val)) {
                                return false;
                            }
                            break;

                        case alpha:
                            if (!isAlpha(val)) {
                                return false;
                            }
                            break;

                        case year:
                            if (!StringUtils.isNumeric(val)) {
                                return false;
                            }
                            int year = Integer.parseInt(val);
                            return year > 0 && year < 2100;

                        case constant:
                        case separator:
                            if (!val.equals(field.getValue())) {
                                return false;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                } else {
                    return false;
                }
                pos += field.getSize();
                inx++;
            }
            return true;
        }
    }
    return false;
}