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.egt.core.util.EA.java

public static void rollConfigurationProperty(String name) {
    String value = configuration.getProperty(name, "");
    value = StringUtils.trimToEmpty(value);
    value = value.replace(LOWER_CASE_CODE, lower_case_code);
    value = value.replace(UPPER_CASE_CODE, upper_case_code);
    value = value.replace(CONTENT_ROOT_DIR, content_root_dir);
    value = value.replace(HOME_DIR, home_dir);
    value = value.replace(JDBC_DRIVER, jdbc_driver);
    value = value.replace(JDBC_URL, jdbc_url);
    value = value.replace(JDBC_USER, jdbc_user);
    value = value.replace(JDBC_PASSWORD, jdbc_password);
    value = value.replace(JNDI_EJB_PERSISTENCE_PATTERN, jndi_ejb_persistence_pattern);
    value = value.replace(VELOCITY_PROPERTIES_FILE, velocity_properties_file);
    value = value.replace(VELOCITY_FILE_RESOURCE_LOADER_PATH, velocity_file_resource_loader_path);
    configuration.setProperty(name, value);
}

From source file:com.hangum.tadpole.importdb.core.dialog.importdb.sql.SQLToDBImportDialog.java

/**
 * select? execute  ./*w w w  .  j  a  va 2  s. c om*/
 * 
 * @param listQuery
 * @throws Exception
 */
private int runSQLExecuteBatch(List<String> listQuery) throws Exception {
    java.sql.Connection conn = null;
    Statement statement = null;
    int result = 0;

    try {
        SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
        conn = client.getDataSource().getConnection();
        conn.setAutoCommit(false);
        statement = conn.createStatement();
        int count = 0;

        for (String strQuery : listQuery) {
            if ("".equals(StringUtils.trimToEmpty(strQuery))) //$NON-NLS-1$
                continue;

            statement.addBatch(strQuery);
            if (++count % batchSize == 0) {
                try {
                    statement.executeBatch();
                } catch (SQLException e) {
                    logger.error("Execute Batch error", e); //$NON-NLS-1$
                    bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$

                    SQLException ne = e.getNextException();
                    while (ne != null) {
                        logger.error("NEXT SQLException is ", ne);//$NON-NLS-1$
                        bufferBatchResult.append(ne.getMessage() + "\n");
                        ne = ne.getNextException();
                    }

                    if (btnIgnore.getSelection()) {
                        conn.commit();
                        continue;
                    } else {
                        conn.rollback();
                        result = -1;
                        break;
                    }
                }
            }
        }

        statement.executeBatch();
        conn.commit();
        conn.setAutoCommit(true);

        if (result < 0 && !"".equals(bufferBatchResult.toString())) { //$NON-NLS-1$
            MessageDialog.openError(null, Messages.CsvToRDBImportDialog_4, bufferBatchResult.toString());
        }
    } catch (SQLException e) {
        logger.error("Execute Batch error", e); //$NON-NLS-1$
        bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
        if (btnIgnore.getSelection()) {
            conn.commit();
        } else {
            conn.rollback();
        }

        SQLException ne = e.getNextException();
        while (ne != null) {
            logger.error("Execute Batch error", e); //$NON-NLS-1$
            bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
            ne = ne.getNextException();
        }
    } catch (Exception e) {
        result = -1;
        logger.error("Execute Batch error", e); //$NON-NLS-1$
        bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
        conn.rollback();
        throw e;
    } finally {
        try {
            if (statement != null)
                statement.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
    return result;
}

From source file:com.hangum.tadpole.rdb.core.editors.objects.table.TableDirectEditorComposite.java

/**
 * ??  , pk,fk ? ? index ./*from ww  w .ja v a 2s. com*/
 */
private void initBusiness() {

    String strWhere = StringUtils.trimToEmpty(textWhere.getText());
    String strOrder = StringUtils.trimToEmpty(textOrderBy.getText());

    try {
        primaryKeyListIndex.clear();
        //  
        runSQLSelect(strWhere, strOrder);

        //  ?  ?  .
        for (int i = 0; i < mapColumns.size(); i++) {

            if (primaryKEYListString.get(mapColumns.get(i)) == null)
                continue;

            if (primaryKEYListString.get(mapColumns.get(i))) {
                primaryKeyListIndex.add(i);
                primaryKEYIntStrList.put(i, mapColumns.get(i));
            }
        }

        // ? ?? .
        resultView();

    } catch (Exception e) {
        logger.error("Data moidfying..", e);

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

    // google analytic
    AnalyticCaller.track("TableDirectEditorComposite"); //$NON-NLS-1$
}

From source file:net.duckling.ddl.web.controller.task.TaskBaseController.java

/** ??? */
@RequestMapping(params = "func=modifySubmit")
public ModelAndView modifySubmitTask(HttpServletRequest request, @PathVariable("teamCode") String teamCode) {
    VWBContext context = VWBContext.createContext(request, UrlPatterns.T_TASK_PATTERNS);
    Site site = context.getSite();//from  w  w w.j  a  v a 2s.  c  om
    TaskService service = taskService;

    String taskId = StringUtils.trimToEmpty(request.getParameter("taskId"));
    String taskType = StringUtils.trimToEmpty(request.getParameter("taskType"));
    String taskTitle = StringUtils.trimToEmpty(request.getParameter("taskTitle"));
    String takerListStr = convert2TaskNameType(StringUtils.trimToEmpty(request.getParameter("takerList")),
            site);
    String takerFromPop = convert2TaskNameType(StringUtils.trimToEmpty(request.getParameter("takerList_pop")),
            site);
    takerListStr = deleteSame(takerListStr, takerFromPop);
    // 
    if (!isNull(taskId)) {
        String needDeleteItemsId = request.getParameter("needDeleteItemsId");
        String needUpdateItemsId = request.getParameter("needUpdateItemsId");
        String[] needAddItemsContents = request.getParameterValues("newTaskContent");
        String[] modifyContents = request.getParameterValues("modifyTaskContent");

        Task task = service.getShareTask(taskId);
        task.setTitle(taskTitle);
        service.updateTask(task);
        service.updateTakers(task, takerListStr, TaskService.TYPE_SHARE, DEntity.DTASK_SHARE);
        service.addShareItems(needAddItemsContents, task.getTaskId() + "");
        service.updateShareItems(needUpdateItemsId.split(","), modifyContents);
        service.deleteShareItems(needDeleteItemsId.split(","));
        // noticeS?
        service.sendNotice(site.getId(), service.getTakers(taskId), task, DEntity.DTASK_SHARE,
                DAction.UPDATE_TASK, task.getCreator());

    } // 
    else {
        String items[] = request.getParameterValues("newTaskContent");
        String title = request.getParameter("taskTitle");
        String[] takerArray = takerListStr.split(",");
        Task task = new Task();

        task.setTeamId(teamCode);
        task.setCreateTime(DateUtil.getCurrentTime());
        task.setCreator(context.getCurrentUID());
        task.setTaskType(taskType);
        task.setTitle(title);
        int id = service.addTask(task);
        task.setTaskId(id);
        service.addShareItems(items, id + "");
        service.addTakers(takerListStr.split(","), id + "");
        // noticeS ???
        service.sendNotice(site.getId(), getListFromArray(takerArray, id), task, DEntity.DTASK_SHARE,
                DAction.CREATE, task.getCreator());
    }
    return getRedirect(teamCode);
}

From source file:com.hangum.tadpole.importexport.core.dialogs.SQLToDBImportDialog.java

/**
 * select? execute  .//from   w w w .  ja v a  2s. co m
 * 
 * @param listQuery
 * @throws Exception
 */
private int runSQLExecuteBatch(List<String> listQuery) throws Exception {
    java.sql.Connection conn = null;
    Statement statement = null;
    int result = 0;

    try {
        SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
        conn = client.getDataSource().getConnection();
        conn.setAutoCommit(false);
        statement = conn.createStatement();
        int count = 0;

        for (String strQuery : listQuery) {
            if ("".equals(StringUtils.trimToEmpty(strQuery))) //$NON-NLS-1$
                continue;

            statement.addBatch(strQuery);
            if (++count % batchSize == 0) {
                try {
                    statement.executeBatch();
                } catch (SQLException e) {
                    logger.error("Execute Batch error", e); //$NON-NLS-1$
                    bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$

                    SQLException ne = e.getNextException();
                    while (ne != null) {
                        logger.error("NEXT SQLException is ", ne);//$NON-NLS-1$
                        bufferBatchResult.append(ne.getMessage() + "\n"); //$NON-NLS-1$
                        ne = ne.getNextException();
                    }

                    if (btnIgnore.getSelection()) {
                        conn.commit();
                        continue;
                    } else {
                        conn.rollback();
                        result = -1;
                        break;
                    }
                }
            }
        }

        statement.executeBatch();
        conn.commit();
        conn.setAutoCommit(true);

        if (result < 0 && !"".equals(bufferBatchResult.toString())) { //$NON-NLS-1$
            MessageDialog.openWarning(null, Messages.get().Warning, bufferBatchResult.toString());
        }
    } catch (SQLException e) {
        logger.error("Execute Batch error", e); //$NON-NLS-1$
        bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
        if (btnIgnore.getSelection()) {
            conn.commit();
        } else {
            conn.rollback();
        }

        SQLException ne = e.getNextException();
        while (ne != null) {
            logger.error("Execute Batch error", e); //$NON-NLS-1$
            bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
            ne = ne.getNextException();
        }
    } catch (Exception e) {
        result = -1;
        logger.error("Execute Batch error", e); //$NON-NLS-1$
        bufferBatchResult.append(e.getMessage() + "\n"); //$NON-NLS-1$
        conn.rollback();
        throw e;
    } finally {
        try {
            if (statement != null)
                statement.close();
        } catch (Exception e) {
        }
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
    return result;
}

From source file:com.egt.core.db.util.Exporter.java

private static String trimToDefaultNumber(String number) {
    String str = StringUtils.trimToEmpty(number);
    return StringUtils.isEmpty(str) || !StringUtils.isNumeric(str) ? DEFAULT_NUMBER_KW : str;
}

From source file:com.hangum.tadpole.rdb.core.dialog.resource.ResourceDetailDialog.java

/**
 * is valid//from   w  ww .ja  v  a 2  s .c o m
 * @return
 */
private boolean isValid(ResourceManagerDAO dao) {
    int len = StringUtils.trimToEmpty(textTitle.getText()).length();
    if (len < 3) {
        MessageDialog.openWarning(null, CommonMessages.get().Warning, Messages.get().ResourceManageEditor_27); //$NON-NLS-1$
        textTitle.setFocus();
        return false;
    }

    // sql type 
    if (dao.getResource_types().equals(RESOURCE_TYPE.SQL.name())) {
        if (PublicTadpoleDefine.YES_NO.YES.name().equals(dao.getRestapi_yesno())) {
            String strAPIURI = textAPIURL.getText().trim();

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

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

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

    try {
        TadpoleSystem_UserDBResource.userDBResourceDupUpdate(originalResourceDB.getParent(), dao);
    } catch (Exception ee) {
        logger.error("Resource validate", ee); //$NON-NLS-1$
        MessageDialog.openError(null, CommonMessages.get().Error, ee.getMessage()); //$NON-NLS-1$
        return false;
    }

    return true;
}

From source file:com.egt.core.jsf.JSF.java

public static String getWebuiString(String key, String altkey, String styles) {
    //      Bitacora.trace(JSF.class, "getWebuiString-2", key, altkey, styles);
    String k = StringUtils.trimToEmpty(key);
    if (StringUtils.isNotBlank(k)) {
        String v = getWebuiString(BundleWebui.getResourceBundle(), k);
        // <editor-fold defaultstate="collapsed">
        //          if (v == null) {
        //              String ak = StringUtils.trimToEmpty(altkey);
        //              int l = ak.length() - 1;
        //              if (l > 0) {
        //                  ak = ak.substring(0, l).trim();
        //                  ak = STP.getHumplessCase(ak);
        //                  String w = ak.startsWith("id_") ? "id" : ak.startsWith("numero_") ? "numero" : "";
        //                  l = w.length();
        //                  if (l > 0) {
        //                      String s = StringUtils.trimToEmpty(styles);
        //                      String c = "pdq-estilo-id-2";
        //                      if (s.contains(c)) {
        //                          ak = "nombre" + ak.substring(l);
        ////------------------------v = getWebuiString(BundleParametros.getResourceBundle(), ak);
        //                      }
        //                  }
        ////----------------v = getWebuiString(BundleParametros.getResourceBundle(), ak);
        //              }
        //          }
        // </editor-fold>
        return fix(v);
    }/*from   ww w.  j  av  a  2  s.  c  o m*/
    return null;
}

From source file:mrcg.MRCGInstance.java

private void createListJSPs() throws Exception {
    for (JavaClass jclass : types.values()) {
        if (!(jclass.isEnum() || jclass.isMapping() || skipGui(jclass))) {

            String path = "beans." + jclass.getName() + ".list.";

            List<ListField> listFields = new ArrayList<ListField>();
            List<Object> lfs = getList(path + "fields");
            if (lfs != null && !lfs.isEmpty()) {
                for (Object o : lfs) {
                    String s = StringUtils.trimToEmpty(o.toString());
                    ListField lf = new ListField();
                    if (s.contains(":")) {
                        String[] ss = s.split(":");
                        lf.setName(ss[0]);
                        lf.setLabel(ss[1]);
                    } else {
                        lf.setName(s);/*from  ww w  .j  a  v a  2s .c  o  m*/
                        lf.setLabel(
                                Utils.toSpacedCamelCase(StringUtils.capitaliseAllWords(s.replace('.', ' '))));
                    }
                    listFields.add(lf);
                }
            } else {
                for (JavaField jf : jclass.getListFields()) {
                    ListField lf = new ListField();
                    if (jf.isReferenceField()) {
                        JavaClass ref = jf.getReferences();
                        lf.setLabel(jf.getNameAsLabel().replace(" Id", ""));
                        String refField = "identifierLabel";
                        if (ref.getIdentifierField() != null) {
                            refField = ref.getIdentifierField().getName();
                        }
                        lf.setName(jf.getName().replace("Id", "") + "." + refField);
                    } else {
                        lf.setLabel(jf.getNameAsLabel());
                        lf.setName(jf.getName());
                    }
                    listFields.add(lf);
                }
            }

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("basePackage", basePackage);
            map.put("classUpper", StringUtils.capitalize(jclass.getName()));
            map.put("classUpperSpaced", Utils.toSpacedCamelCase(StringUtils.capitalize(jclass.getName())));
            map.put("classUpperSpacedPlural",
                    Utils.toSpacedCamelCase(StringUtils.capitalize(Utils.pluralize(jclass.getName()))));
            map.put("classLower", jclass.getName().toLowerCase());
            map.put("classLowerCamel", StringUtils.uncapitalize(jclass.getName()));
            map.put("fields", listFields);
            map.put("tagLibPrefix", tagLibPrefix);
            //            map.put("mappings", convertToJspEditCode(jclass));
            map.put("edit", getBoolean(path + "edit", true));
            map.put("view", getBoolean(path + "view", true));

            File file = new File(webPath + "admin/" + jclass.getName().toLowerCase() + "/list-generated.jsp");
            velocity(file, getResourcePath("list-jsp.vel"), map, true);
        }
    }
}