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

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

Introduction

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

Prototype

public static String trim(String str) 

Source Link

Document

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

Usage

From source file:com.bstek.dorado.view.resolver.PackageFileResolver.java

private void collectFileInfos(DoradoContext context, List<FileInfo> fileInfos, Package pkg,
        String resourcePrefix, String resourceSuffix) throws Exception {
    String[] fileNameArray = pkg.getFileNames();
    if (fileNameArray != null) {
        for (int j = 0; j < fileNameArray.length; j++) {
            String fileName = StringUtils.trim(fileNameArray[j]);
            if (fileName.indexOf(NONE_FILE) < 0) {
                fileInfos.add(new FileInfo(pkg.getName(), fileName));
            }/*w  w  w  .ja va 2s  . co  m*/
        }
    }

    if (JAVASCRIPT_SUFFIX.equals(resourceSuffix)) {
        ClientI18NFileRegistry.FileInfo fileInfo = clientI18NFileRegistry.getFileInfo(pkg.getName());
        if (fileInfo != null) {
            if (fileInfo.isReplace()) {
                for (int i = fileInfos.size() - 1; i >= 0; i--) {
                    FileInfo fi = fileInfos.get(i);
                    if (I18N.equals(fi.getFileType())) {
                        fileInfos.remove(i);
                    }
                }
            }
            fileInfos.add(new FileInfo(pkg.getName(), fileInfo.getPath(), I18N));
        }
    }
}

From source file:hydrograph.ui.graph.model.Container.java

private boolean checkIfDuplicateComponentExists(String newNameORComponentId, Component currentComponent,
        boolean checkId) {
    newNameORComponentId = StringUtils.trim(newNameORComponentId);
    if (!getChildren().isEmpty()) {
        for (Object object : getChildren()) {
            if (object instanceof Component && !object.equals(currentComponent)) {
                Component component = (Component) object;
                if (checkId && StringUtils.equalsIgnoreCase(StringUtils.trim(component.getComponentId()),
                        newNameORComponentId)) {
                    LoggerUtil.getLoger(this.getClass()).trace("Duplicate component exists.");
                    return true;
                } else if (!checkId && StringUtils.equalsIgnoreCase(
                        StringUtils.trim(component.getComponentLabel().getLabelContents()),
                        newNameORComponentId)) {
                    LoggerUtil.getLoger(this.getClass()).trace("Duplicate component exists.");
                    return true;
                }//from   w  w  w  .java  2s .c  om
            }
        }
    }
    return false;
}

From source file:adalid.core.wrappers.ArtifactWrapper.java

protected String getSomeShortLabel(boolean b) {
    String string = getWordyName();
    Entity declaringEntity = _artifact.getDeclaringEntity();
    String declaringEntityName = declaringEntity == null ? null
            : StrUtils.getWordyString(declaringEntity.getName());
    Operation declaringOperation = _artifact.getDeclaringOperation();
    Entity declaringOperationEntity = declaringOperation == null ? null
            : declaringOperation.getDeclaringEntity();
    String declaringOperationEntityName = declaringOperationEntity == null ? null
            : StrUtils.getWordyString(declaringOperationEntity.getName());
    if (_artifact instanceof Property && declaringEntity != null) {
        Property property = (Property) _artifact;
        if (property.isNotDeclared()) {
        } else if (_artifact.equals(declaringEntity.getPrimaryKeyProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.PRIMARY_KEY, b);
        } else if (_artifact.equals(declaringEntity.getVersionProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.VERSION, b);
        } else if (_artifact.equals(declaringEntity.getBusinessKeyProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.BUSINESS_KEY, b);
        } else if (_artifact.equals(declaringEntity.getNumericKeyProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.NUMERIC_KEY, b);
        } else if (_artifact.equals(declaringEntity.getCharacterKeyProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.CHARACTER_KEY, b);
        } else if (_artifact.equals(declaringEntity.getNameProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.NAME, b);
        } else if (_artifact.equals(declaringEntity.getDescriptionProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.DESCRIPTION, b);
        } else if (_artifact.equals(declaringEntity.getInactiveIndicatorProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.INACTIVE_INDICATOR, b);
        } else if (_artifact.equals(declaringEntity.getUrlProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.URL, b);
        } else if (_artifact.equals(declaringEntity.getParentProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.PARENT, b);
        } else if (_artifact.equals(declaringEntity.getOwnerProperty())) {
            string = shortLabelOf(declaringEntity, KeyProperty.OWNER, b);
        } else if (_artifact instanceof EntityReference) {
            string = StrUtils.removeWords(string, EntityReference.class);
            string = StrUtils.removeWholeWord(string, declaringEntityName);
        } else {//from   ww  w  . j a  v a  2s. c  o m
            string = StrUtils.removeWords(string, property.getDataType());
            string = StrUtils.removeWholeWord(string, declaringEntityName);
        }
    } else if (_artifact instanceof Parameter && declaringOperationEntity != null) {
        Parameter parameter = (Parameter) _artifact;
        if (parameter.isNotDeclared()) {
        } else if (_artifact instanceof EntityReference) {
            string = StrUtils.removeWords(string, EntityReference.class);
            string = StrUtils.removeWholeWord(string, declaringOperationEntityName);
        } else {
            string = StrUtils.removeWords(string, parameter.getDataType());
            string = StrUtils.removeWholeWord(string, declaringOperationEntityName);
        }
    }
    string = StringUtils.trim(StringUtils.replace(string, "  ", " "));
    return StringUtils.isNotBlank(string) ? string : getWordyName();
}

From source file:mitm.djigzo.web.beans.impl.DLPPropertiesBeanImpl.java

@Override
public void save() throws HierarchicalPropertiesException {
    dlpProperties.setEnabled(enabled.getUserValue());
    dlpProperties.setQuarantineURL(StringUtils.trim(quarantineURL.getUserValue()));
    dlpProperties.setDLPManagers(StringUtils.split(dlpManagers.getUserValue(), ","));
    dlpProperties.setSendWarningToOriginator(sendWarningToOriginator.getUserValue());
    dlpProperties.setSendWarningToDLPManagers(sendWarningToDLPManagers.getUserValue());
    dlpProperties.setSendQuarantineToOriginator(sendQuarantineToOriginator.getUserValue());
    dlpProperties.setSendQuarantineToDLPManagers(sendQuarantineToDLPManagers.getUserValue());
    dlpProperties.setSendBlockToOriginator(sendBlockToOriginator.getUserValue());
    dlpProperties.setSendBlockToDLPManagers(sendBlockToDLPManagers.getUserValue());
    dlpProperties.setSendErrorToOriginator(sendErrorToOriginator.getUserValue());
    dlpProperties.setSendErrorToDLPManagers(sendErrorToDLPManagers.getUserValue());
    dlpProperties.setAllowDownloadMessage(allowDownloadMessage.getUserValue());
    dlpProperties.setAllowReleaseMessage(allowReleaseMessage.getUserValue());
    dlpProperties.setAllowReleaseEncryptMessage(allowReleaseEncryptMessage.getUserValue());
    dlpProperties.setAllowReleaseAsIsMessage(allowReleaseAsIsMessage.getUserValue());
    dlpProperties.setAllowDeleteMessage(allowDeleteMessage.getUserValue());
    dlpProperties.setQuarantineOnError(quarantineOnError.getUserValue());
    dlpProperties.setQuarantineOnFailedEncryption(quarantineOnFailedEncryption.getUserValue());
    dlpProperties.setSendReleaseNotifyToOriginator(sendReleaseNotifyToOriginator.getUserValue());
    dlpProperties.setSendReleaseNotifyToDLPManagers(sendReleaseNotifyToDLPManagers.getUserValue());
    dlpProperties.setSendDeleteNotifyToOriginator(sendDeleteNotifyToOriginator.getUserValue());
    dlpProperties.setSendDeleteNotifyToDLPManagers(sendDeleteNotifyToDLPManagers.getUserValue());
    dlpProperties.setSendExpireNotifyToOriginator(sendExpireNotifyToOriginator.getUserValue());
    dlpProperties.setSendExpireNotifyToDLPManagers(sendExpireNotifyToDLPManagers.getUserValue());

    saveableProperties.save();// ww  w . jav  a 2  s  .c om
}

From source file:com.adobe.acs.commons.contentfinder.querybuilder.impl.viewhandler.GQLToQueryBuilderConverter.java

/**
 * @param map/*from   w  w w . ja  va 2 s  .co m*/
 * @param predicateValue  => jcr:title
 * @param predicate       => property
 * @param predicateSuffix => value
 * @param values          => [Square, Triangle]
 * @param group           => ID
 * @param or              => true/false
 * @return
 */
public static Map<String, String> putAll(Map<String, String> map, String predicate, String predicateValue,
        String predicateSuffix, String[] values, int group, boolean or) {
    final String groupId = String.valueOf(group) + SUFFIX_GROUP;

    map.put(groupId + "." + predicate, predicateValue);

    int count = 1;
    for (final String value : values) {
        final String predicateId = predicate;
        final String predicateSuffixId = count + "_" + predicateSuffix;
        map.put(groupId + "." + predicateId + "." + predicateSuffixId, StringUtils.trim(value));
        count++;
    }

    map.put(groupId + SUFFIX_P_OR, String.valueOf(or));

    return map;
}

From source file:com.github.technosf.posterer.controllers.impl.RequestController.java

/**
 * Fire event - User hits the {@code Fire} button
 * //w ww  .  j a v  a2  s  .c o  m
 * @throws IOException
 */
public void fire() throws IOException {
    logger.debug("Fire  --  Starts");

    if (StringUtils.isNotBlank(endpoint.getValue()))
        return;

    progress.setVisible(true); // Show we're busy

    try {
        updateRequest();

        URI uri = new URI(StringUtils.trim(endpoint.getValue()));

        endpoint.getItems().add(uri.toString());

        /* Fire off the request */
        ResponseModel response = requestModel.doRequest(requestBean.copy());

        /* Feedback to Request status panel */
        statusController.setStatus(INFO_FIRED, response.getReferenceId(), response.getRequestBean().getMethod(),
                response.getRequestBean().getUri());

        /*
         * Open the Response window managing this request instance
         */
        ResponseController.loadStage(response).show();
    } catch (URISyntaxException e)
    // uri did not compute
    {
        logger.debug("Fire endpoint is not a URI.");
        tabs.getSelectionModel().select(destination);
        statusController.setStatus(ERROR_URL_VALIDATION);
        // status_fade = new FadeTransition(Duration.millis(5000), status);
        // status_fade.play();
    } finally
    // Clear the progress ticker
    {
        progress.setVisible(false); // No longer busy
    }

    logger.debug("Fire  --  ends");
}

From source file:br.com.bropenmaps.util.Util.java

/**
 * Retira espaos em branco do incio e do final de uma sequncia de caracteres. Alm disso remove os caracteres &nbsp; (espao) das sequncia. 
 * @param str/*from  w  ww  .ja  va 2 s  .  c  o m*/
 * @return Sequncia de caracteres sem os espaos.
 */
public static String trim(String str) {

    if (str == null) {

        return null;

    }

    str = StringUtils.replace(str, "&nbsp;", " ");

    return StringUtils.trim(str);

}

From source file:com.googlecode.l10nmavenplugin.validators.property.HtmlValidator.java

private String applyWorkArroundForMultipleLIsIfNecessary(String formattedMessage) {
    String result = formattedMessage;
    String trimmed = StringUtils.trim(formattedMessage);
    if (MULTIPLE_LIS_AT_ROOT_PATTERN.matcher(trimmed).matches()) {
        result = "<ul>" + formattedMessage + "</ul>";
    }/*from  w  w  w .j  a v a 2 s  .co m*/
    return result;
}

From source file:edu.monash.merc.system.parser.nextprot.NXHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    //get current path from the stack
    String currentPath = pathStack.currentPath();

    //end - nextprotExport/proteins/protein
    if (currentPath.equalsIgnoreCase(NXFields.PATH_PROTEIN)) {
        nxEntryBeans.add(nxEntryBean);//from   w  w  w  .  j  av  a  2s  .com
    }

    //end - protein/proteinNames/entityName/value end
    if (currentPath.equalsIgnoreCase(NXFields.PATH_PROTEIN_DESC)) {
        String desc = stringBuilder.toString();
        identifiedAccession.setDescription(desc);
        mainProteinDesc = false;
    }

    //end - nextprotExport/proteins/protein/geneNames/entityName/value
    if (currentPath.equalsIgnoreCase(NXFields.PATH_GENE_SYMBOL)) {
        String geneSymbol = stringBuilder.toString();
        nxEntryBean.getGeneBean().setDisplayName(geneSymbol);
        mainGeneSymbol = false;
    }

    //end - nextprotExport/proteins/protein/identifiers
    if (currentPath.equalsIgnoreCase(NXFields.PATH_IDENTIFIERS)) {
        //Set the DbSourceAcEntryBean list
        nxEntryBean.setDbSourceAcEntryBeans(dbAcEntryBeans);
    }

    //process pe ms ann and pe anti ann evidence hyperlink.
    //end of nextprotExport/proteins/protein/xrefs/xref/url
    if (currentPath.equalsIgnoreCase(NXFields.PATH_XREF_URL)) {
        String xrefUrl = stringBuilder.toString();
        xrefUrl = StringUtils.trim(xrefUrl);
        if (peMsAnnEvExisted) {
            peMsAnnEvidenceBean.setHyperlink(xrefUrl);
        }
        //find peAntiUrl
        findPeAnTiAnnURL(xrefDatabase, xrefCategory, xrefAccession, xrefUrl);
        //reset the database, category and accession
        xrefDatabase = null;
        xrefCategory = null;
        xrefAccession = null;
    }

    //process individual pe ms ann evidence bean
    //end -- nextprotExport/proteins/protein/xrefs/xref
    if (currentPath.equalsIgnoreCase(NXFields.PATH_XREF)) {
        //add the pe ms ann evidence bean into list
        if (peMsAnnEvExisted) {
            peMsAnnEvidenceBeans.add(peMsAnnEvidenceBean);
            peMsAnnEvExisted = false;
        }
    }

    //end -- nextprotExport/proteins/protein/xrefs
    if (currentPath.equalsIgnoreCase(NXFields.PATH_XREFS)) {
        //add the pe ms ann evidence bean list (peMsAnnEvidenceBeans)into NXPeMsAntiEntryBean
        peMsAntiEntryBean.setPeMsAnnEvidenceBeans(peMsAnnEvidenceBeans);

        //create pe anti ann evidence if it exists
        if (peAntiAnnEvExisted) {

            if (peAntiAnnCounter == 0) {
                peAntiAnnEvidenceBean.setColorLevel(ColorType.BLACK.color());
            }

            if (peAntiAnnCounter == 1) {
                peAntiAnnEvidenceBean.setColorLevel(ColorType.RED.color());
            }

            if (peAntiAnnCounter > 1) {
                peAntiAnnEvidenceBean.setColorLevel(ColorType.YELLOW.color());
            }

            peAntiAnnEvidenceBean.setEvidenceValue(peAntiAnnCounter + " " + NXConts.XREF_HPA_ANTIBODY_DESC);
            peAntiAnnEvidenceBean.setHyperlink(peAntiURL);
            //create a TPBDataTypeBean
            TPBDataTypeBean tpbDataTypeBean = new TPBDataTypeBean();
            //set the data type
            tpbDataTypeBean.setDataType(DataType.PE_ANTI_ANN.type());
            //set the traffic lights level to 3
            tpbDataTypeBean.setLevel(TLLevel.TL3.level());
            peAntiAnnEvidenceBean.setTpbDataTypeBean(tpbDataTypeBean);
            //set the pe anti ann object
            peMsAntiEntryBean.setPeAntiAnnEvidenceBean(peAntiAnnEvidenceBean);
            //dpn't forget to rest pe anti ann evidence existed flag to false.
            peAntiAnnEvExisted = false;
            //reset peAntiURL to null.
            peAntiURL = null;
        }

        //and
        nxEntryBean.setNxPeMsAntiEntryBean(peMsAntiEntryBean);
    }

    //finally pop the current path as it's end of current element.
    pathStack.pop();
}

From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.rdb.view.TadpoleViewerComposite.java

private void createWidget(final CTabFolder tabFolderObject) {
    tbtmViews = new CTabItem(tabFolderObject, SWT.NONE);
    tbtmViews.setText(Messages.get().Views);
    tbtmViews.setData(TAB_DATA_KEY, PublicTadpoleDefine.OBJECT_TYPE.VIEWS.name());

    Composite compositeTables = new Composite(tabFolderObject, SWT.NONE);
    tbtmViews.setControl(compositeTables);
    GridLayout gl_compositeTables = new GridLayout(1, false);
    gl_compositeTables.verticalSpacing = 2;
    gl_compositeTables.horizontalSpacing = 2;
    gl_compositeTables.marginHeight = 2;
    gl_compositeTables.marginWidth = 2;//w  ww .j  a  v a2 s  .  co  m
    compositeTables.setLayout(gl_compositeTables);

    SashForm sashForm = new SashForm(compositeTables, SWT.NONE);
    sashForm.setOrientation(SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    //  SWT.VIRTUAL ?  FILTER ? ?? ?  .
    viewListViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
    viewListViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (PublicTadpoleDefine.YES_NO.NO.name().equals(userDB.getIs_showtables()))
                return;

            IStructuredSelection is = (IStructuredSelection) event.getSelection();

            if (PermissionChecker.isShow(getUserRoleType(), userDB)) {
                if (null != is) {
                    try {
                        TableDAO viewDao = (TableDAO) is.getFirstElement();
                        StringBuffer sbSQL = new StringBuffer();

                        List<TableColumnDAO> showTableColumns = DBSystemSchema.getViewColumnList(userDB,
                                viewDao);
                        sbSQL.append("SELECT "); //$NON-NLS-1$
                        for (int i = 0; i < showTableColumns.size(); i++) {
                            TableColumnDAO dao = showTableColumns.get(i);
                            sbSQL.append(dao.getSysName());

                            //  ? ,  
                            if (i < (showTableColumns.size() - 1))
                                sbSQL.append(", "); //$NON-NLS-1$
                            else
                                sbSQL.append(" "); //$NON-NLS-1$
                        }
                        sbSQL.append(PublicTadpoleDefine.LINE_SEPARATOR + "FROM " + viewDao.getSysName() //$NON-NLS-1$
                                + PublicTadpoleDefine.SQL_DELIMITER); //$NON-NLS-2$

                        //
                        FindEditorAndWriteQueryUtil.run(userDB, sbSQL.toString(),
                                PublicTadpoleDefine.OBJECT_TYPE.VIEWS);
                    } catch (Exception e) {
                        logger.error("get view listt", e);

                        Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
                        ExceptionDetailsErrorDialog.openError(null, Messages.get().Error,
                                Messages.get().GenerateSQLSelectAction_0, errStatus); //$NON-NLS-1$
                    }
                }
            }
        }
    });
    viewListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // ??  ?? .
            try {
                IStructuredSelection is = (IStructuredSelection) event.getSelection();
                if (!is.isEmpty()) {
                    if (is.getFirstElement() != null) {
                        TableDAO viewDao = (TableDAO) is.getFirstElement();
                        showViewColumns = DBSystemSchema.getViewColumnList(userDB, viewDao);
                    } else {
                        showViewColumns = new ArrayList<>();
                    }

                } else {
                    showViewColumns.clear();
                }
            } catch (Exception e) {
                logger.error("get view list", e); //$NON-NLS-1$
                Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
                ExceptionDetailsErrorDialog.openError(getSite().getShell(), Messages.get().Error,
                        Messages.get().ExplorerViewer_29, errStatus); //$NON-NLS-1$
            } finally {
                viewColumnViewer.setInput(showViewColumns);
                tableColumnComparator = new TableColumnComparator();
                viewColumnViewer.setSorter(tableColumnComparator);
                viewColumnViewer.refresh();
                TableUtil.packTable(viewColumnViewer.getTable());
            }
        }
    });
    Table tableTableList = viewListViewer.getTable();
    tableTableList.setLinesVisible(true);
    tableTableList.setHeaderVisible(true);

    // sorter
    viewComparator = new TableComparator();
    viewListViewer.setSorter(viewComparator);
    viewComparator.setColumn(0);

    TableViewerColumn tableViewerColumn = new TableViewerColumn(viewListViewer, SWT.NONE);
    TableColumn tblclmnTableName = tableViewerColumn.getColumn();
    tblclmnTableName.setWidth(200);
    tblclmnTableName.setText(Messages.get().Name);
    tblclmnTableName
            .addSelectionListener(getSelectionAdapter(viewListViewer, viewComparator, tblclmnTableName, 0));
    tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return ResourceManager.getPluginImage(Activator.PLUGIN_ID,
                    "resources/icons/objectExplorer/view.png"); //$NON-NLS-1$
        }

        @Override
        public String getText(Object element) {
            TableDAO tdbDao = (TableDAO) element;
            if ("".equals(tdbDao.getSchema_name()) | null == tdbDao.getSchema_name())
                return tdbDao.getName();
            else
                return String.format("%s.%s", tdbDao.getSchema_name(), tdbDao.getName());
        }
    });
    viewListViewer.setContentProvider(new ArrayContentProvider());
    viewListViewer.setInput(showViews);

    viewFilter = new TableFilter(userDB);
    viewListViewer.addFilter(viewFilter);

    createMenu();

    // columns
    viewColumnViewer = new TableViewer(sashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    viewColumnViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection is = (IStructuredSelection) event.getSelection();

            if (null != is) {
                TableColumnDAO tableDAO = (TableColumnDAO) is.getFirstElement();
                FindEditorAndWriteQueryUtil.runAtPosition(StringUtils.trim(tableDAO.getField()));
            }
        }
    });
    Table tableTableColumn = viewColumnViewer.getTable();
    tableTableColumn.setHeaderVisible(true);
    tableTableColumn.setLinesVisible(true);

    tableColumnComparator = new TableColumnComparator();
    viewColumnViewer.setSorter(tableColumnComparator);

    createViewColumne();

    viewColumnViewer.setContentProvider(new ArrayContentProvider());
    viewColumnViewer.setLabelProvider(new TableColumnLabelprovider());

    //      createTableColumnMenu();

    sashForm.setWeights(new int[] { 1, 1 });
}