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.hangum.tadpole.rdb.core.dialog.table.mysql.MySQLTableRelationDialog.java

@Override
protected void okPressed() {
    // ALTER TABLE `actor` ADD CONSTRAINT `bacdef` FOREIGN KEY (`actor_id`) REFERENCES `city` (`city_id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    // ALTER TABLE %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) ON DELETE %s ON UPDATE %s;
    String strReferenceName = StringUtils.trimToEmpty(textRefName.getText());

    if (StringUtils.isEmpty(strReferenceName)) {
        MessageDialog.openWarning(getShell(), Messages.get().Warning, "Please input the reference name");

        textRefName.setFocus();//w w w .j av a 2s  .  c o m
        return;
    }
    String strOriColumn = ((TableColumnDAO) comboOriColumn.getData(comboOriColumn.getText())).getField();
    String strRefTable = ((TableDAO) comboRefTableName.getData(comboRefTableName.getText())).getName();
    String strRefColumn = ((TableColumnDAO) comboRefColumnName.getData(comboRefColumnName.getText()))
            .getField();
    String strCreateIndex = String.format(TEMP_REFERENCE_SQL, tableDAO.getName(), strReferenceName,
            strOriColumn, strRefTable, strRefColumn, comboOnUpdate.getText(), comboOnDelete.getText());
    try {
        ExecuteDDLCommand.executSQL(userDB, strCreateIndex);

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

        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();

        textRefName.setFocus();
    }
}

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

@Override
protected void okPressed() {
    String strName = textColumnName.getText();
    String strType = comboType.getText();
    String strDefault = textDefault.getText();
    boolean isPrimaryKey = btnPrimaryKey.getSelection();
    boolean isNotNull = btnNotNull.getSelection();
    boolean isAutoIncrement = btnAutoIncrement.getSelection();
    String strCollation = comboCollation.getText();
    String strComment = textComment.getText();

    if (StringUtils.trimToEmpty(strName).equals("")) { //$NON-NLS-1$
        MessageDialog.openWarning(null, Messages.get().Warning, Messages.get().MySQLTableColumnDialog_20);
        textColumnName.setFocus();/*from  w w  w .jav a  2s  .  c om*/

        return;
    } else if (StringUtils.trimToEmpty(strType).equals("")) { //$NON-NLS-1$
        MessageDialog.openWarning(null, Messages.get().Warning, Messages.get().MySQLTableColumnDialog_23);
        textColumnName.setFocus();

        return;
    }

    TableColumnUpdateDAO metaDataDao = new TableColumnUpdateDAO();
    metaDataDao.setColumnName(strName);
    metaDataDao.setDataType(strType);
    metaDataDao.setDefaultValue(strDefault);
    metaDataDao.setPrimaryKey(isPrimaryKey);
    metaDataDao.setNotNull(isNotNull);
    metaDataDao.setAutoIncrement(isAutoIncrement);
    metaDataDao.setCollation(strCollation);
    metaDataDao.setComment(strComment);

    if (COMP_STATUS == DATA_STATUS.NEW) {
        try {
            TableColumnObjectQuery.addColumn(userDB, tableDAO, metaDataDao);
            refreshTableColumn();
            MessageDialog.openInformation(null, Messages.get().Confirm,
                    Messages.get().MySQLTableColumnDialog_25);

            textColumnName.setText("");
            textColumnName.setFocus();
        } catch (Exception e) {
            logger.error("add colum exception", e);

            TDBErroDialog errDialog = new TDBErroDialog(null, Messages.get().ObjectDeleteAction_25,
                    Messages.get().MySQLTableColumnDialog_27 + e.getMessage());
            errDialog.open();
        }
    } else {
        try {
            TableColumnObjectQuery.updateColumn(userDB, tableDAO, tableColumnDAO, metaDataDao);
            refreshTableColumn();
            MessageDialog.openInformation(null, Messages.get().Confirm,
                    Messages.get().MySQLTableColumnDialog_29);

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

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

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

/**
 * ? ?  ./*from   w  w w .j ava2s .  c  o  m*/
 * 
 * @return
 */
public boolean isValidate() {
    if (!message(comboGroup, "Group"))
        return false;
    if (!message(textHost, "Host")) //$NON-NLS-1$
        return false;
    if (!message(textPort, "Port")) //$NON-NLS-1$
        return false;
    if (!message(textDatabase, "Database")) //$NON-NLS-1$
        return false;
    if (!message(textUser, "User")) //$NON-NLS-1$
        return false;
    if (!message(textDisplayName, "Display Name")) //$NON-NLS-1$
        return false;

    String host = StringUtils.trimToEmpty(textHost.getText());
    String port = StringUtils.trimToEmpty(textPort.getText());

    try {
        if (!isPing(host, port)) {
            MessageDialog.openError(null, Messages.DBLoginDialog_14, Messages.MySQLLoginComposite_8);
            return false;
        }
    } catch (NumberFormatException nfe) {
        MessageDialog.openError(null, Messages.MySQLLoginComposite_3, Messages.MySQLLoginComposite_4);
        return false;
    }

    return true;
}

From source file:com.hangum.tadpole.engine.sql.dialog.save.ResourceSaveDialog.java

/**
 * data validation//from  w w  w.j av  a 2 s. co m
 * 
 * @param name
 * @return
 */
private boolean isValid() {
    int len = StringUtils.trimToEmpty(textName.getText()).length();
    if (len < 3) {
        MessageDialog.openWarning(null, Messages.get().Warning, Messages.get().ResourceSaveDialog_16);
        textName.setFocus();
        return false;
    }

    // sql type 
    if (resourceType == RESOURCE_TYPE.SQL) {
        if (PublicTadpoleDefine.YES_NO.YES.name().equals(comboUseAPI.getText())) {
            String strAPIURI = textAPIURI.getText().trim();

            if (strAPIURI.equals("")) { //$NON-NLS-1$
                MessageDialog.openWarning(getShell(), Messages.get().Warning,
                        Messages.get().ResourceSaveDialog_19);
                textAPIURI.setFocus();
                return false;
            }

            // check valid url. url pattern is must be /{parent}/{child}
            if (!RESTfulAPIUtils.validateURL(textAPIURI.getText())) {
                MessageDialog.openWarning(getShell(), Messages.get().Warning,
                        Messages.get().ResourceSaveDialog_21);

                textAPIURI.setFocus();
                return false;
            }
        }
    }

    return true;
}

From source file:net.bulletin.pdi.xero.step.XeroGetStep.java

private Stack<String> getContainerElementsStack(XeroGetStepMeta meta) throws KettleException {
    Stack<String> result = new Stack<String>();
    String ce = StringUtils.trimToEmpty(meta.getContainerElements());

    while (ce.startsWith("/")) {
        ce = ce.substring(1);/* w  ww.  ja  v  a2  s .  com*/
    }

    if (StringUtils.isNotBlank(ce)) {
        if (!PATTERN_CONTAINERELEMENTS.matcher(ce).matches()) {
            throw new KettleException("malformed container elements; " + ce);
        }

        Collections.addAll(result, ce.split("/"));
    }

    return result;
}

From source file:com.hangum.tadpole.commons.admin.core.dialogs.users.NewUserDialog.java

@Override
protected void okPressed() {
    String strEmail = StringUtils.trimToEmpty(textEMail.getText());
    String passwd = StringUtils.trimToEmpty(textPasswd.getText());
    String rePasswd = StringUtils.trimToEmpty(textRePasswd.getText());
    String name = StringUtils.trimToEmpty(textName.getText());

    if (!validation(strEmail, passwd, rePasswd, name))
        return;/*w ww.  j av  a 2s. c  o  m*/
    if (btnGetOptCode.getSelection()) {
        if ("".equals(textOTPCode.getText())) { //$NON-NLS-1$
            MessageDialog.openWarning(getShell(), Messages.get().Warning, Messages.get().NewUserDialog_40);
            textOTPCode.setFocus();
            return;
        }
        if (!GoogleAuthManager.getInstance().isValidate(secretKey, NumberUtils.toInt(textOTPCode.getText()))) {
            MessageDialog.openWarning(getShell(), Messages.get().Warning, Messages.get().NewUserDialog_42); //$NON-NLS-1$
            textOTPCode.setFocus();
            return;
        }
    }

    try {
        /**
         * ? ??  ? ? NO ,   YES .
         */
        String approvalYn = GetAdminPreference.getNewUserPermit();
        String isEmamilConrim = PublicTadpoleDefine.YES_NO.NO.name();

        SMTPDTO smtpDto = new SMTPDTO();
        try {
            smtpDto = GetAdminPreference.getSessionSMTPINFO();
        } catch (Exception e) {
            // igonre exception
        }
        if (isAdmin || "".equals(smtpDto.getEmail())) { //$NON-NLS-1$
            isEmamilConrim = PublicTadpoleDefine.YES_NO.YES.name();
        }

        String strEmailConformKey = Utils.getUniqueDigit(7);
        userDao = TadpoleSystem_UserQuery.newUser(PublicTadpoleDefine.INPUT_TYPE.NORMAL.toString(), strEmail,
                strEmailConformKey, isEmamilConrim, passwd, PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString(),
                name, comboLanguage.getText(), approvalYn, btnGetOptCode.getSelection() ? "YES" : "NO", //$NON-NLS-1$ //$NON-NLS-2$
                textSecretKey.getText(), "*"); //$NON-NLS-1$ //$NON-NLS-2$

        boolean isSentMail = false;
        if (!"".equals(smtpDto.getEmail())) { //$NON-NLS-1$
            sendEmailAccessKey(name, strEmail, strEmailConformKey);
            isSentMail = true;
        }

        try {
            AddDefaultSampleDBToUser.addUserDefaultDB(userDao.getSeq(), userDao.getEmail());
        } catch (Exception e) {
            logger.error("Sample db copy error", e); //$NON-NLS-1$
        }

        if (isSentMail)
            MessageDialog.openInformation(null, Messages.get().Confirm, Messages.get().NewUserDialog_31);
        else
            MessageDialog.openInformation(null, Messages.get().Confirm, Messages.get().NewUserDialog_29); //$NON-NLS-1$

    } catch (Exception e) {
        logger.error(Messages.get().NewUserDialog_8, e);
        MessageDialog.openError(getParentShell(), Messages.get().Confirm, e.getMessage());
        return;
    }

    super.okPressed();
}

From source file:com.collegesource.interfaces.student.BannerStudentFinder.java

/**
 * Create a StuMaster object from the search results map.
 * // w w  w  .j a v a 2 s  .  c o m
 * @param map
 */
private StuMaster createStudent(Map<String, Object> map) {
    StuMaster stuMaster = new StuMaster();
    StuDemo stuDemo = new StuDemo();
    StuDemoPK stuDemoPk = new StuDemoPK();

    stuMaster.setInstid(studentInstid);
    stuMaster.setInstidq(studentInstidq);
    stuMaster.setStuno(StringUtils.trimToEmpty((String) map.get("spriden_id")));

    stuDemoPk.setSourceId(studentInstid);
    stuDemoPk.setStuMaster(stuMaster);

    String name = StringUtils.trimToEmpty(StringUtils.substring((String) map.get("stuname"), 0, 35));

    stuDemo.setStuname(name);
    stuDemo.setStuidq(studentInstidq);
    stuDemo.setComp_id(stuDemoPk);

    List<StuDemo> demoList = new ArrayList<StuDemo>();
    demoList.add(stuDemo);

    stuMaster.setStuDemos(demoList);
    logger.debug("Created StuMaster with Banner Records: " + stuMaster);
    logger.debug("Student Name[" + stuDemo.getStuname() + "]");
    return stuMaster;
}

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

@Override
public boolean makeUserDBDao(boolean isTest) {
    if (!isValidateInput(isTest))
        return false;

    String dbUrl = "";
    if (comboConnType.getText().equals("SID")) {
        dbUrl = String.format(getSelectDB().getDB_URL_INFO(), StringUtils.trimToEmpty(textHost.getText()),
                StringUtils.trimToEmpty(textPort.getText()), StringUtils.trimToEmpty(textDatabase.getText()));
    } else if (comboConnType.getText().equals("Service Name")) {
        dbUrl = String.format("jdbc:oracle:thin:@%s:%s/%s", StringUtils.trimToEmpty(textHost.getText()),
                StringUtils.trimToEmpty(textPort.getText()), StringUtils.trimToEmpty(textDatabase.getText()));
    }//from   w ww.  ja  v  a 2s  . c om
    if (!"".equals(textJDBCOptions.getText())) {
        dbUrl += "?" + textJDBCOptions.getText();
    }

    userDB = new UserDBDAO();
    userDB.setDbms_type(getSelectDB().getDBToString());
    userDB.setUrl(dbUrl);
    userDB.setUrl_user_parameter(textJDBCOptions.getText());
    userDB.setDb(StringUtils.trimToEmpty(textDatabase.getText()));
    userDB.setGroup_name(StringUtils.trimToEmpty(preDBInfo.getComboGroup().getText()));
    userDB.setDisplay_name(StringUtils.trimToEmpty(preDBInfo.getTextDisplayName().getText()));

    String dbOpType = PublicTadpoleDefine.DBOperationType
            .getNameToType(preDBInfo.getComboOperationType().getText()).name();
    userDB.setOperation_type(dbOpType);
    if (dbOpType.equals(PublicTadpoleDefine.DBOperationType.PRODUCTION.name())
            || dbOpType.equals(PublicTadpoleDefine.DBOperationType.BACKUP.name())) {
        userDB.setIs_lock(PublicTadpoleDefine.YES_NO.YES.name());
    }

    userDB.setHost(StringUtils.trimToEmpty(textHost.getText()));
    userDB.setPort(StringUtils.trimToEmpty(textPort.getText()));
    userDB.setUsers(StringUtils.trimToEmpty(textUser.getText()));
    userDB.setPasswd(StringUtils.trimToEmpty(textPassword.getText()));

    // ? ?? ? .
    userDB.setRole_id(PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString());

    //      userDB.setLocale(comboLocale.getText().trim());

    // others connection  .
    setOtherConnectionInfo();

    return true;
}

From source file:com.hangum.tadpole.rdb.core.editors.sessionlist.SessionListEditor.java

/**
 * crate extension oracle /* ww  w.  j a v a2s . c  om*/
 */
private void createOracleExtensionUI() {
    Composite compositeExtension = new Composite(mainSashForm, SWT.NONE);
    compositeExtension.setLayout(new GridLayout(1, false));

    SashForm sashFormExtension = new SashForm(compositeExtension, SWT.VERTICAL);
    sashFormExtension.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeExtHead = new Composite(sashFormExtension, SWT.NONE);
    compositeExtHead.setLayout(new GridLayout(1, false));

    Composite composite = new Composite(compositeExtHead, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    btnAllLocks = new Button(composite, SWT.RADIO);
    btnAllLocks.setText("All Locks");
    btnAllLocks.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshLocksList("");
        }
    });

    btnSessionLocks = new Button(composite, SWT.RADIO);
    btnSessionLocks.setSelection(true);
    btnSessionLocks.setText("Session Locks");

    tableViewerLocks = new TableViewer(compositeExtHead, SWT.BORDER | SWT.FULL_SELECTION);
    tableLocks = tableViewerLocks.getTable();
    tableLocks.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (tableViewerLocks.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewerLocks.getSelection();
            HashMap map = (HashMap) ss.getFirstElement();
            if (null != map) {
                if (DBGroupDefine.MYSQL_GROUP == userDB.getDBGroup()) {
                    refreshLocksBlockList((String) map.get("lock_trx_id"), "");
                } else {
                    refreshLocksBlockList((String) map.get("LOCK_ID1"), (String) map.get("LOCK_ID2"));
                }
            }

        }
    });
    tableLocks.setHeaderVisible(true);
    tableLocks.setLinesVisible(true);
    tableLocks.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    createLocksTableColumn();

    Composite compositeExtBody = new Composite(sashFormExtension, SWT.NONE);
    compositeExtBody.setLayout(new GridLayout(1, false));

    Label lblBlockedBlocking = new Label(compositeExtBody, SWT.NONE);
    lblBlockedBlocking.setText("Blocked && Blocking");

    tableViewerBlock = new TableViewer(compositeExtBody, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewerBlock.getTable();
    table.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (tableViewerBlock.getSelection().isEmpty())
                return;

            StructuredSelection ss = (StructuredSelection) tableViewerBlock.getSelection();
            HashMap map = (HashMap) ss.getFirstElement();
            if (null != map) {
                textSQL.setText(StringUtils.trimToEmpty((String) map.get("SQL_TEXT")));
            } else {
                textSQL.setText(StringUtils.EMPTY);
            }
        }
    });
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    textSQL = new Text(compositeExtBody, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textSQL.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
    GridData gd_textSQL = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_textSQL.heightHint = 80;
    textSQL.setLayoutData(gd_textSQL);
    sashFormExtension.setWeights(new int[] { 1, 1 });

    createLocksBlockTableColumn();
}

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

@Override
public boolean makeUserDBDao(boolean isTest) {
    if (!isValidateInput(isTest))
        return false;

    String dbUrl = String.format(getSelectDB().getDB_URL_INFO(), StringUtils.trimToEmpty(textHost.getText()),
            StringUtils.trimToEmpty(textPort.getText()), StringUtils.trimToEmpty(textDatabase.getText()));
    if (!"".equals(textJDBCOptions.getText())) {
        dbUrl += "?" + textJDBCOptions.getText();
    }//from w  ww  .j a v a 2 s  .  c  om

    userDB = new UserDBDAO();
    userDB.setDbms_type(getSelectDB().getDBToString());
    userDB.setUrl(dbUrl);
    userDB.setUrl_user_parameter(textJDBCOptions.getText());
    userDB.setDb(StringUtils.trimToEmpty(textDatabase.getText()));
    userDB.setGroup_name(StringUtils.trimToEmpty(preDBInfo.getComboGroup().getText()));
    userDB.setDisplay_name(StringUtils.trimToEmpty(preDBInfo.getTextDisplayName().getText()));

    String dbOpType = PublicTadpoleDefine.DBOperationType
            .getNameToType(preDBInfo.getComboOperationType().getText()).name();
    userDB.setOperation_type(dbOpType);
    if (dbOpType.equals(PublicTadpoleDefine.DBOperationType.PRODUCTION.name())
            || dbOpType.equals(PublicTadpoleDefine.DBOperationType.BACKUP.name())) {
        userDB.setIs_lock(PublicTadpoleDefine.YES_NO.YES.name());
    }

    userDB.setHost(StringUtils.trimToEmpty(textHost.getText()));
    userDB.setPort(StringUtils.trimToEmpty(textPort.getText()));
    userDB.setUsers(StringUtils.trimToEmpty(textUser.getText()));
    userDB.setPasswd(StringUtils.trimToEmpty(textPassword.getText()));

    // others connection  .
    OthersConnectionInfoDAO otherConnectionDAO = othersConnectionInfo.getOthersConnectionInfo();
    userDB.setIs_readOnlyConnect(
            otherConnectionDAO.isReadOnlyConnection() ? PublicTadpoleDefine.YES_NO.YES.name()
                    : PublicTadpoleDefine.YES_NO.NO.name());
    userDB.setIs_autocommit(otherConnectionDAO.isAutoCommit() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());
    userDB.setIs_showtables(otherConnectionDAO.isShowTables() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());

    //      userDB.setIs_table_filter(otherConnectionDAO.isTableFilter()?PublicTadpoleDefine.YES_NO.YES.name():PublicTadpoleDefine.YES_NO.NO.name());
    //      userDB.setTable_filter_include(otherConnectionDAO.getStrTableFilterInclude());
    //      userDB.setTable_filter_exclude(otherConnectionDAO.getStrTableFilterExclude());

    userDB.setIs_profile(otherConnectionDAO.isProfiling() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());
    userDB.setQuestion_dml(otherConnectionDAO.isDMLStatement() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());

    userDB.setIs_external_browser(otherConnectionDAO.isExterBrowser() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());
    userDB.setListExternalBrowserdao(otherConnectionDAO.getListExterBroswer());

    //      userDB.setIs_visible(otherConnectionDAO.isVisible()?PublicTadpoleDefine.YES_NO.YES.name():PublicTadpoleDefine.YES_NO.NO.name());
    userDB.setIs_summary_report(otherConnectionDAO.isSummaryReport() ? PublicTadpoleDefine.YES_NO.YES.name()
            : PublicTadpoleDefine.YES_NO.NO.name());

    // ? ?? ? .
    userDB.setRole_id(PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString());

    return true;
}