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

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

Introduction

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

Prototype

public static String chop(String str) 

Source Link

Document

Remove the last character from a String.

Usage

From source file:com.haulmont.timesheets.entity.Task.java

@MetaProperty
public String getDefaultTagsList() {
    if (defaultTags != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Tag defaultTag : defaultTags) {
            stringBuilder.append(defaultTag.getInstanceName()).append(",");
        }/*from  w  w  w.ja v a  2 s . c  om*/
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}

From source file:com.haulmont.timesheets.entity.Task.java

@MetaProperty
public String getRequiredTagTypesList() {
    if (requiredTagTypes != null) {
        StringBuilder stringBuilder = new StringBuilder();
        for (TagType requiredTagType : requiredTagTypes) {
            stringBuilder.append(requiredTagType.getInstanceName()).append(",");
        }/*w w  w .  j  a  va 2 s.com*/
        return StringUtils.chop(stringBuilder.toString());
    }

    return "";
}

From source file:com.huawei.streaming.cql.CQLClient.java

private int processLine(String line) {
    int lastRet = 0;
    int ret = 0;//from  w ww.  ja  va2  s. com
    String command = "";
    for (String oneCmd : line.split(";")) {
        if (StringUtils.isBlank(oneCmd.trim())) {
            continue;
        }

        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + ";";
            continue;
        } else {
            command += oneCmd;
        }

        if (StringUtils.isBlank(command)) {
            continue;
        }

        ret = processCQL(command, true);
        lastRet = ret;
    }
    return lastRet;
}

From source file:biz.netcentric.cq.tools.actool.configuration.CqActionsMapping.java

/**
 * method that converts jcr:privileges to cq actions
 * /*from  w w  w.j  ava 2  s  .  c  om*/
 * @param jcrPrivilegesString
 *            comma separated String containing jcr:privileges
 * @return comma separated String containing the assigned cq actions
 * @throws RepositoryException 
 * @throws AccessControlException 
 */
public static String getCqActions(final String jcrPrivilegesString, AccessControlManager aclManager)
        throws AccessControlException, RepositoryException {
    List<String> jcrPrivileges = new ArrayList<String>(Arrays.asList(jcrPrivilegesString.split(",")));

    // go through all aggregates to extend the list with all non-aggregate privileges
    for (String jcrPrivilege : jcrPrivilegesString.split(",")) {
        Privilege privilege = aclManager.privilegeFromName(jcrPrivilege);
        for (Privilege aggregatedPrivileges : privilege.getAggregatePrivileges()) {
            jcrPrivileges.add(aggregatedPrivileges.getName());
        }
    }

    // loop through keySet of cqActions. Remove successively all privileges
    // which are associated to a cq action from jcrPrivileges string
    // and add this actions name to actions string

    Set<String> cqActions = ACTIONS_MAP.keySet();
    String actionsString = "";

    for (String action : cqActions) {
        List<String> jcrPrivilegesFromMap = ACTIONS_MAP.get(action);
        if (jcrPrivileges.containsAll(jcrPrivilegesFromMap)) {
            jcrPrivileges.removeAll(jcrPrivilegesFromMap);
            actionsString = actionsString + action + ",";
        }
    }

    // remove last comma from actions string
    actionsString = StringUtils.chop(actionsString);

    if (actionsString.isEmpty()) {
        actionsString = "";
    }
    return actionsString;
}

From source file:biz.netcentric.cq.tools.actool.configuration.CqActionsMapping.java

public static AceBean getConvertedPrivilegeBean(AceBean bean) {
    Set<String> actions = new LinkedHashSet<String>();
    Set<String> privileges = new LinkedHashSet<String>();

    if (bean.getActions() != null) {
        actions = new LinkedHashSet<String>(Arrays.asList(bean.getActions()));
    }//ww  w .ja  v a 2 s  . c  o  m
    if (bean.getPrivileges() != null) {
        privileges = new LinkedHashSet<String>(Arrays.asList(bean.getPrivileges()));
    }

    // convert cq:actions to their jcr:privileges
    for (String action : actions) {
        if (ACTIONS_MAP.containsKey(action)) { // fix for possible NPE
            privileges.addAll(ACTIONS_MAP.get(action));
        } else {
            LOG.warn("Unrecognized action: '{}' for bean {}", action, bean);
        }
    }
    bean.clearActions();
    bean.setActionsStringFromConfig("");

    StringBuilder sb = new StringBuilder();
    for (String privilege : privileges) {
        sb.append(privilege).append(",");
    }

    bean.setPrivilegesString(StringUtils.chop(sb.toString()));

    return bean;

}

From source file:cn.teamlab.wg.framework.util.csv.CsvWriter.java

/**
 * Bean?CSV?//from   w ww  .j a va  2s. c  o  m
 * Bean@CsvPropAnno(index = ?)
 * @param objList
 * @return
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 */
public static String bean2Csv(List<?> objList) throws Exception {
    if (objList == null || objList.size() == 0) {
        return "";
    }
    TreeMap<Integer, CsvFieldBean> map = new TreeMap<Integer, CsvFieldBean>();
    Object bean0 = objList.get(0);
    Class<?> clazz = bean0.getClass();

    PropertyDescriptor[] arr = org.springframework.beans.BeanUtils.getPropertyDescriptors(clazz);
    for (PropertyDescriptor p : arr) {
        String fieldName = p.getName();
        Field field = FieldUtils.getDeclaredField(clazz, fieldName, true);
        if (field == null) {
            continue;
        }

        boolean isAnno = field.isAnnotationPresent(CsvFieldAnno.class);
        if (isAnno) {
            CsvFieldAnno anno = field.getAnnotation(CsvFieldAnno.class);
            int idx = anno.index();
            map.put(idx, new CsvFieldBean(idx, anno.title(), fieldName));
        }
    }

    // CSVBuffer
    StringBuffer buff = new StringBuffer();

    // ???
    boolean withTitle = clazz.isAnnotationPresent(CsvTitleAnno.class);
    // ??csv
    if (withTitle) {
        StringBuffer titleBuff = new StringBuffer();
        for (int key : map.keySet()) {
            CsvFieldBean fieldBean = map.get(key);
            titleBuff.append(Letters.QUOTE).append(fieldBean.getTitle()).append(Letters.QUOTE);
            titleBuff.append(Letters.COMMA);
        }
        buff.append(StringUtils.chop(titleBuff.toString()));
        buff.append(Letters.LF);
        titleBuff.setLength(0);
    }

    for (Object o : objList) {
        StringBuffer tmpBuff = new StringBuffer();

        for (int key : map.keySet()) {
            CsvFieldBean fieldBean = map.get(key);

            Object val = BeanUtils.getProperty(o, fieldBean.getFieldName());
            if (val != null) {
                tmpBuff.append(Letters.QUOTE).append(val).append(Letters.QUOTE);
            } else {
                tmpBuff.append(StringUtils.EMPTY);
            }
            tmpBuff.append(Letters.COMMA);
        }

        buff.append(StringUtils.chop(tmpBuff.toString()));
        buff.append(Letters.LF);
        tmpBuff.setLength(0);
    }

    return buff.toString();
}

From source file:com.mss.msp.util.DataSourceDataProvider.java

/**
 * *****************************************************************************
 * Date ://  w w w . java 2 s  .co m
 *
 * Author:
 *
 * ForUse : getSkillsMap() method is used to
 *
 * *****************************************************************************
 */
public Map getSkillsMap(int contechReviewId) throws ServiceLocatorException {
    System.out.println(
            "********************DataSourceDataProvider :: getSkillsMap Method Start*********************");
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    String queryString = "";
    Map skillsQuestionsMap = new TreeMap();
    queryString = null;
    String option1 = null;
    String option2 = null;
    String option3 = null;
    String option4 = null;
    String option5 = null;
    String option6 = null;
    String option7 = null;
    String option8 = null;
    String option9 = null;
    String option10 = null;
    connection = ConnectionProvider.getInstance().getConnection();
    queryString = "SELECT option1,option2,option3,option4,option5,option6,option7,option8,option9,option10 FROM sb_onlineexam WHERE techreviewid="
            + contechReviewId + " ";
    System.out.println("getSkillsMap :: query string ------>" + queryString);
    try {
        statement = connection.createStatement();
        resultSet = statement.executeQuery(queryString);
        while (resultSet.next()) {
            option1 = resultSet.getString("option1");
            option2 = resultSet.getString("option2");
            option3 = resultSet.getString("option3");
            option4 = resultSet.getString("option4");
            option5 = resultSet.getString("option5");
            option6 = resultSet.getString("option6");
            option7 = resultSet.getString("option7");
            option8 = resultSet.getString("option8");
            option9 = resultSet.getString("option9");
            option10 = resultSet.getString("option10");
        }
        if (!"".equals(option1)) {
            String[] parts1 = option1.split("-");
            if (Integer.parseInt(parts1[1]) != 0) {
                skillsQuestionsMap.put(parts1[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts1[0]))));
            }
        }
        if (!"".equals(option2)) {
            String[] parts2 = option2.split("-");
            if (Integer.parseInt(parts2[1]) != 0) {
                skillsQuestionsMap.put(parts2[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts2[0]))));
            }
        }
        if (!"".equals(option3)) {
            String[] parts3 = option3.split("-");
            if (Integer.parseInt(parts3[1]) != 0) {
                skillsQuestionsMap.put(parts3[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts3[0]))));
            }
        }
        if (!"".equals(option4)) {
            String[] parts4 = option4.split("-");
            if (Integer.parseInt(parts4[1]) != 0) {
                skillsQuestionsMap.put(parts4[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts4[0]))));
            }
        }
        if (!"".equals(option5)) {
            String[] parts5 = option5.split("-");
            if (Integer.parseInt(parts5[1]) != 0) {
                skillsQuestionsMap.put(parts5[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts5[0]))));
            }
        }
        if (!"".equals(option6)) {
            String[] parts6 = option6.split("-");
            if (Integer.parseInt(parts6[1]) != 0) {
                skillsQuestionsMap.put(parts6[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts6[0]))));
            }
        }
        if (!"".equals(option7)) {
            String[] parts7 = option7.split("-");
            if (Integer.parseInt(parts7[1]) != 0) {
                skillsQuestionsMap.put(parts7[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts7[0]))));
            }
        }
        if (!"".equals(option8)) {
            String[] parts8 = option8.split("-");
            if (Integer.parseInt(parts8[1]) != 0) {
                skillsQuestionsMap.put(parts8[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts8[0]))));
            }
        }
        if (!"".equals(option9)) {
            String[] parts9 = option9.split("-");
            if (Integer.parseInt(parts9[1]) != 0) {
                skillsQuestionsMap.put(parts9[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts9[0]))));
            }
        }
        if (!"".equals(option10)) {
            String[] parts10 = option10.split("-");
            if (Integer.parseInt(parts10[1]) != 0) {
                skillsQuestionsMap.put(parts10[0],
                        StringUtils.chop(getReqSkillsSet(Integer.parseInt(parts10[0]))));
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        try {
            // resultSet Object Checking if it's null then close and set
            // null
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (statement != null) {
                statement.close();
                statement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException ex) {
            throw new ServiceLocatorException(ex);
        }
    }
    System.out.println(
            "********************DataSourceDataProvider :: getSkillsMap Method End*********************");
    return skillsQuestionsMap;
}

From source file:com.mss.msp.util.DataSourceDataProvider.java

public String checkTasksAuthId(int aInt, int taskId, String flag, int usersessionId)
        throws ServiceLocatorException {
    System.out.println(/*from   w  w  w . j ava 2s.co  m*/
            "********************DataSourceDataProvider :: checkTimesheetAuthId Method Start*********************");
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    String queryString = "";
    String checkAllow = "";
    System.out.println("flag------->" + flag);
    if ("mytaskflag".equals(flag)) {
        // queryString= "SELECT COUNT(*) AS total FROM usrtimesheets ut LEFT
        // OUTER JOIN users u ON(ut.usr_id = u.usr_id) WHERE ut.timesheetid
        // = "+timesheetId+" AND ut.usr_id = "+userId+" AND u.org_id =
        // "+aInt;
        queryString = "SELECT COUNT(*) AS total FROM task_list WHERE task_id =" + taskId
                + " AND (task_created_by=" + usersessionId + " OR pri_assigned_to=" + usersessionId
                + " OR sec_assigned_to=" + usersessionId + ")";
    } else {
        queryString = "SELECT pri_assigned_to,sec_assigned_to,task_created_by FROM task_list WHERE task_id = "
                + taskId;
    }

    System.out.println("checkTimesheetAuthId :: query string ------>" + queryString);
    try {
        connection = ConnectionProvider.getInstance().getConnection();
        statement = connection.createStatement();
        resultSet = statement.executeQuery(queryString);
        while (resultSet.next()) {
            if (!"mytaskflag".equals(flag)) {
                // dfdqueryString= "SELECT COUNT(*) AS total FROM
                // vwtimesheetlist WHERE EmpId in ("+userId+")";
                // checkTimeSheetId();

                String userIds = resultSet.getString("pri_assigned_to") + ","
                        + resultSet.getString("task_created_by") + ",";
                if (resultSet.getInt("sec_assigned_to") != 0) {
                    userIds = userIds + resultSet.getString("sec_assigned_to") + ",";
                }
                // StringUtils.chop(userIds);
                System.out.println("assingned,priassign,created" + userIds);
                checkAllow = checkTasksAuth(StringUtils.chop(userIds), usersessionId);

            } else {
                if (resultSet.getInt("total") == 0) {
                    checkAllow = "notAllow";
                } else {
                    checkAllow = "allow";
                }
            }

        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        try {
            // resultSet Object Checking if it's null then close and set
            // null
            if (resultSet != null) {
                resultSet.close();
                resultSet = null;
            }
            if (statement != null) {
                statement.close();
                statement = null;
            }
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (SQLException ex) {
            throw new ServiceLocatorException(ex);
        }
    }
    System.out.println(
            "********************DataSourceDataProvider :: checkTimesheetAuthId Method End*********************");
    return checkAllow;
}

From source file:org.apache.hadoop.hive.ql.QTestUtil.java

private int executeClientInternal(String commands) {
    List<String> cmds = CliDriver.splitSemiColon(commands);
    int rc = 0;//from  ww  w. j  a  v a 2 s .  c  o  m

    String command = "";
    for (String oneCmd : cmds) {
        if (StringUtils.endsWith(oneCmd, "\\")) {
            command += StringUtils.chop(oneCmd) + "\\;";
            continue;
        } else {
            if (isHiveCommand(oneCmd)) {
                command = oneCmd;
            } else {
                command += oneCmd;
            }
        }
        if (StringUtils.isBlank(command)) {
            continue;
        }

        if (isCommandUsedForTesting(command)) {
            rc = executeTestCommand(command);
        } else {
            rc = cliDriver.processLine(command);
        }

        if (rc != 0 && !ignoreErrors()) {
            break;
        }
        command = "";
    }
    if (rc == 0 && SessionState.get() != null) {
        SessionState.get().setLastCommand(null); // reset
    }
    return rc;
}

From source file:org.apache.hadoop.hive.ql.QTestUtil.java

private int executeTestCommand(final String command) {
    String commandName = command.trim().split("\\s+")[0];
    String commandArgs = command.trim().substring(commandName.length());

    if (commandArgs.endsWith(";")) {
        commandArgs = StringUtils.chop(commandArgs);
    }/*from   www .ja v a 2  s  .c o m*/

    //replace ${hiveconf:hive.metastore.warehouse.dir} with actual dir if existed.
    //we only want the absolute path, so remove the header, such as hdfs://localhost:57145
    String wareHouseDir = SessionState.get().getConf().getVar(ConfVars.METASTOREWAREHOUSE)
            .replaceAll("^[a-zA-Z]+://.*?:\\d+", "");
    commandArgs = commandArgs.replaceAll("\\$\\{hiveconf:hive\\.metastore\\.warehouse\\.dir\\}", wareHouseDir);

    if (SessionState.get() != null) {
        SessionState.get().setLastCommand(commandName + " " + commandArgs.trim());
    }

    enableTestOnlyCmd(SessionState.get().getConf());

    try {
        CommandProcessor proc = getTestCommand(commandName);
        if (proc != null) {
            CommandProcessorResponse response = proc.run(commandArgs.trim());

            int rc = response.getResponseCode();
            if (rc != 0) {
                SessionState.getConsole().printError(response.toString(),
                        response.getException() != null
                                ? Throwables.getStackTraceAsString(response.getException())
                                : "");
            }

            return rc;
        } else {
            throw new RuntimeException("Could not get CommandProcessor for command: " + commandName);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not execute test command", e);
    }
}