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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:com.microsoft.alm.plugin.external.commands.ResolveConflictsCommand.java

/**
 * Outputs the resolved conflicts in the following format:
 * <p/>//from   w w w  . java 2s  . co m
 * Resolved /Users/leantk/tfvc-tfs/tfsTest_01/TestAdd.txt as KeepYours
 * Resolved /Users/leantk/tfvc-tfs/tfsTest_01/addFold/testHere2 as KeepYours
 *
 * @param stdout
 * @param stderr
 * @return
 */
@Override
public List<Conflict> parseOutput(final String stdout, final String stderr) {
    throwIfError(stderr);

    final List<Conflict> resolved = new ArrayList<Conflict>();
    final String[] lines = getLines(stdout);
    for (String line : lines) {
        if (StringUtils.startsWith(line, RESOLVED_PREFIX)) {
            line = StringUtils.removeStart(line, RESOLVED_PREFIX);
            final int index = line.indexOf(RESOLVED_POST_MSG);
            if (index != -1) {
                resolved.add(new Conflict(line.substring(0, index), Conflict.ConflictType.RESOLVED));
            }
        }
    }

    return resolved;
}

From source file:com.haulmont.cuba.gui.xml.layout.LayoutLoader.java

protected static void replaceAssignParameters(Document document) {
    Map<String, String> assignedParams = new HashMap<>();

    List<Element> assignElements = Dom4j.elements(document.getRootElement(), "assign");
    ThemeConstantsManager themeManager = AppBeans.get(ThemeConstantsManager.NAME);
    for (Element assignElement : assignElements) {
        String name = assignElement.attributeValue("name");
        if (StringUtils.isEmpty(name)) {
            throw new RuntimeException("'name' attribute of assign tag is empty");
        }/*from   w w  w . j a v  a 2  s.  c  o  m*/

        String value = assignElement.attributeValue("value");
        if (StringUtils.isEmpty(value)) {
            throw new RuntimeException("'value' attribute of assign tag is empty");
        }

        if (StringUtils.startsWith(value, ThemeConstants.PREFIX)) {
            ThemeConstants theme = themeManager.getConstants();
            value = theme.get(value.substring(ThemeConstants.PREFIX.length()));
        }

        assignedParams.put(name, value);
    }

    if (!assignedParams.isEmpty()) {
        Element layoutElement = document.getRootElement().element("layout");
        if (layoutElement != null) {
            Dom4j.walkAttributesRecursive(layoutElement, (element, attribute) -> {
                String attributeValue = attribute.getValue();
                if (StringUtils.isNotEmpty(attributeValue) && attributeValue.startsWith("${")
                        && attributeValue.endsWith("}")) {
                    String paramKey = attributeValue.substring(2, attributeValue.length() - 1);

                    String assignedValue = assignedParams.get(paramKey);
                    if (assignedValue == null) {
                        throw new RuntimeException("Unable to find value of assign param: " + paramKey);
                    }

                    attribute.setValue(assignedValue);
                }
            });
        }
    }
}

From source file:com.glaf.activiti.executionlistener.SqlInsertExecutionListener.java

public void notify(DelegateExecution execution) throws Exception {
    logger.debug("-------------------------------------------------------");
    logger.debug("--------------SqlInsertExecutionListener---------------");
    logger.debug("-------------------------------------------------------");
    String tableName = table.getExpressionText();
    if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) {
        tableName = (String) table.getValue(execution);
    }//  www.java2 s .  co  m

    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager()
            .findExecutionById(execution.getId());
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager()
            .findProcessDefinitionById(processDefinitionId);
    String processName = processDefinitionEntity.getKey();

    Map<String, Object> params = new java.util.HashMap<String, Object>();

    Map<String, Object> variables = execution.getVariables();
    if (variables != null && variables.size() > 0) {
        Iterator<String> iterator = variables.keySet().iterator();
        while (iterator.hasNext()) {
            String variableName = iterator.next();
            if (params.get(variableName) == null) {
                Object value = execution.getVariable(variableName);
                params.put(variableName, value);
            }
        }
    }

    params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey());
    params.put("processInstanceId", execution.getProcessInstanceId());
    params.put("processDefinitionId", processDefinitionEntity.getId());
    params.put("processName", processName);
    params.put("now", new Date());
    params.put("today", new Date());
    params.put("currentDate", new Date());

    String variable = (String) execution.getVariable(fields.getExpressionText());
    JSONObject jsonObject = JSON.parseObject(variable);

    TableModel tableModel = new TableModel();
    tableModel.setTableName(tableName);

    Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, Object> entry = iterator.next();
        String columnName = (String) entry.getKey();
        String value = (String) entry.getValue();

        if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) {
            value = value.substring(2, value.length() - 1);
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        } else {
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        }
    }

    commandContext.getDbSqlSession().getSqlSession().insert("insertBusinessTableData", tableModel);
}

From source file:com.glaf.activiti.executionlistener.SqlDeleteExecutionListener.java

public void notify(DelegateExecution execution) throws Exception {
    logger.debug("-------------------------------------------------------");
    logger.debug("--------------SqlDeleteExecutionListener---------------");
    logger.debug("-------------------------------------------------------");
    String tableName = table.getExpressionText();
    if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) {
        tableName = (String) table.getValue(execution);
    }/*from w w w  .j a  v a  2s .  co  m*/

    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager()
            .findExecutionById(execution.getId());
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager()
            .findProcessDefinitionById(processDefinitionId);
    String processName = processDefinitionEntity.getKey();

    Map<String, Object> params = new java.util.HashMap<String, Object>();

    Map<String, Object> variables = execution.getVariables();
    if (variables != null && variables.size() > 0) {
        Iterator<String> iterator = variables.keySet().iterator();
        while (iterator.hasNext()) {
            String variableName = iterator.next();
            if (params.get(variableName) == null) {
                Object value = execution.getVariable(variableName);
                params.put(variableName, value);
            }
        }
    }

    params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey());
    params.put("processInstanceId", execution.getProcessInstanceId());
    params.put("processDefinitionId", processDefinitionEntity.getId());
    params.put("processName", processName);
    params.put("now", new Date());
    params.put("today", new Date());
    params.put("currentDate", new Date());

    String variable = (String) execution.getVariable(fields.getExpressionText());
    JSONObject jsonObject = JSON.parseObject(variable);

    TableModel tableModel = new TableModel();
    tableModel.setTableName(tableName);

    Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, Object> entry = iterator.next();
        String columnName = (String) entry.getKey();
        String value = (String) entry.getValue();

        if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) {
            value = value.substring(2, value.length() - 1);
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            } else {
                throw new RuntimeException(columnName + " '" + value + "' value is null");
            }
        } else {
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            } else {
                throw new RuntimeException(columnName + " '" + value + "' value is null");
            }
        }
    }

    commandContext.getDbSqlSession().getSqlSession().delete("deleteBusinessTableData", tableModel);
}

From source file:controllers.Common.java

@Before(priority = 0)
public static void csrfCheck() {
    boolean isPost = StringUtils.equals(request.method, "POST");
    boolean isFormEncoded = StringUtils.equals(request.contentType, "application/x-www-form-urlencoded");
    boolean isApiRequest = StringUtils.startsWith(request.path, "/api/");
    if (isPost && isFormEncoded && !isApiRequest) {
        String authenticityToken = SecurityUtils.stripXSS(params.get("authenticityToken"));
        if (authenticityToken == null) {
            Logger.warn("No authenticity token from %s for request: %s", request.remoteAddress, request.url);
        }/*from   w w  w . ja va 2  s . c  om*/
        checkAuthenticity();
    }
}

From source file:com.glaf.activiti.executionlistener.SqlUpdateExecutionListener.java

public void notify(DelegateExecution execution) throws Exception {
    logger.debug("-------------------------------------------------------");
    logger.debug("--------------SqlUpdateExecutionListener---------------");
    logger.debug("-------------------------------------------------------");
    String tableName = table.getExpressionText();
    if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) {
        tableName = (String) table.getValue(execution);
    }/*from   www  .j a  va2 s. co m*/

    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager()
            .findExecutionById(execution.getId());
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager()
            .findProcessDefinitionById(processDefinitionId);
    String processName = processDefinitionEntity.getKey();

    Map<String, Object> params = new java.util.HashMap<String, Object>();

    Map<String, Object> variables = execution.getVariables();
    if (variables != null && variables.size() > 0) {
        Iterator<String> iterator = variables.keySet().iterator();
        while (iterator.hasNext()) {
            String variableName = iterator.next();
            if (params.get(variableName) == null) {
                Object value = execution.getVariable(variableName);
                params.put(variableName, value);
            }
        }
    }

    params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey());
    params.put("processInstanceId", execution.getProcessInstanceId());
    params.put("processDefinitionId", processDefinitionEntity.getId());
    params.put("processName", processName);
    params.put("now", new Date());
    params.put("today", new Date());
    params.put("currentDate", new Date());

    String variable = (String) execution.getVariable(fields.getExpressionText());
    JSONObject jsonObject = JSON.parseObject(variable);

    TableModel tableModel = new TableModel();
    tableModel.setTableName(tableName);

    ColumnModel idColumn = new ColumnModel();
    idColumn.setColumnName(primaryKey.getExpressionText());
    if (execution.getVariable("primaryKey") != null) {
        Object idValue = execution.getVariable("primaryKey");
        idColumn.setJavaType(idValue.getClass().getSimpleName());
        tableModel.setIdColumn(idColumn);
    } else {
        idColumn.setJavaType("String");
        idColumn.setValue(execution.getProcessBusinessKey());
        tableModel.setIdColumn(idColumn);
    }

    Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, Object> entry = iterator.next();
        String columnName = (String) entry.getKey();
        String value = (String) entry.getValue();

        if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) {
            value = value.substring(2, value.length() - 1);
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        } else {
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        }
    }

    commandContext.getDbSqlSession().getSqlSession().update("updateBusinessTableDataByPrimaryKey", tableModel);
}

From source file:mitm.common.util.DomainUtils.java

/**
 * Checks if the domain is valid for the domain type. If not valid null will be returned
 * if valid, leading white space will be removed.
 *///from  ww  w  .j  a va 2  s  .co  m
public static String validate(String domain, DomainType domainType) {
    if (domain == null) {
        return null;
    }

    Pattern pattern = null;

    switch (domainType) {
    case FULLY_QUALIFIED:
        pattern = fullyQualifiedPattern;
        break;
    case WILD_CARD:
        pattern = wildcardPattern;
        break;
    case FRAGMENT:
        pattern = fragmentPattern;
        break;

    default:
        throw new IllegalArgumentException("Unknown domainType.");
    }

    Matcher matcher = pattern.matcher(domain);

    String validated = null;

    if (matcher.matches()) {
        validated = matcher.group(1);

        String trimmed = StringUtils.trim(validated);

        /*
         * A domain should not start or end with -
         */
        if (StringUtils.startsWith(trimmed, "-") || StringUtils.endsWith(trimmed, "-")) {
            validated = null;
        }
    }

    return validated;
}

From source file:de.iteratec.visualizationmodel.Color.java

public Color(String serialized) {
    if (serialized == null) {
        return;//w w  w . ja  va2  s  .  c  o m
    }
    if (serialized.charAt(0) == '#') {
        if (serialized.length() == 3) {
            this.red = Integer.parseInt(serialized.substring(1, 2), BASE) * 17;
            this.green = Integer.parseInt(serialized.substring(2, 3), BASE) * 17;
            this.blue = Integer.parseInt(serialized.substring(3, 4), BASE) * 17;
        } else {
            this.red = Integer.parseInt(serialized.substring(1, 3), BASE);
            this.green = Integer.parseInt(serialized.substring(3, 5), BASE);
            this.blue = Integer.parseInt(serialized.substring(5, 7), BASE);
        }
    } else if (StringUtils.startsWith(serialized, "rgb(")) {
        String[] vals = serialized.substring(4, serialized.length() - 1).split(",");
        this.red = Integer.parseInt(vals[0].trim());
        this.green = Integer.parseInt(vals[1].trim());
        this.blue = Integer.parseInt(vals[2].trim());
    }
}

From source file:com.glaf.activiti.executionlistener.SqlUpdateByProcessInstanceListener.java

public void notify(DelegateExecution execution) throws Exception {
    logger.debug("-------------------------------------------------------");
    logger.debug("-------------SqlUpdateByProcessInstanceListener--------");
    logger.debug("-------------------------------------------------------");
    String tableName = table.getExpressionText();
    if (StringUtils.startsWith(tableName, "#{") && StringUtils.endsWith(tableName, "}")) {
        tableName = (String) table.getValue(execution);
    }//from  w w  w  .j a va  2 s .  co  m

    CommandContext commandContext = Context.getCommandContext();
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager()
            .findExecutionById(execution.getId());
    String processDefinitionId = executionEntity.getProcessDefinitionId();
    ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager()
            .findProcessDefinitionById(processDefinitionId);
    String processName = processDefinitionEntity.getKey();

    Map<String, Object> params = new java.util.HashMap<String, Object>();

    Map<String, Object> variables = execution.getVariables();
    if (variables != null && variables.size() > 0) {
        Iterator<String> iterator = variables.keySet().iterator();
        while (iterator.hasNext()) {
            String variableName = iterator.next();
            if (params.get(variableName) == null) {
                Object value = execution.getVariable(variableName);
                params.put(variableName, value);
            }
        }
    }

    params.put(Constants.BUSINESS_KEY, execution.getProcessBusinessKey());
    params.put("processInstanceId", execution.getProcessInstanceId());
    params.put("processDefinitionId", processDefinitionEntity.getId());
    params.put("processName", processName);
    params.put("now", new Date());
    params.put("today", new Date());
    params.put("currentDate", new Date());

    String variable = (String) execution.getVariable(fields.getExpressionText());
    JSONObject jsonObject = JSON.parseObject(variable);

    TableModel tableModel = new TableModel();
    tableModel.setTableName(tableName);

    ColumnModel idColumn = new ColumnModel();
    idColumn.setColumnName(processInstanceField.getExpressionText());
    idColumn.setJavaType("String");
    idColumn.setValue(execution.getProcessInstanceId());
    tableModel.setIdColumn(idColumn);

    Iterator<Entry<String, Object>> iterator = jsonObject.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, Object> entry = iterator.next();
        String columnName = (String) entry.getKey();
        String value = (String) entry.getValue();

        if (value.indexOf("#{") != -1 && value.indexOf("}") != -1) {
            value = value.substring(2, value.length() - 1);
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        } else {
            Object x = params.get(value);
            if (x != null) {
                ColumnModel column = new ColumnModel();
                column.setColumnName(columnName);
                column.setJavaType(x.getClass().getSimpleName());
                column.setValue(x);
                tableModel.addColumn(column);
            }
        }
    }

    commandContext.getDbSqlSession().getSqlSession().update("updateBusinessTableDataByPrimaryKey", tableModel);
}

From source file:hydrograph.ui.expression.editor.styletext.ExpressionEditorStyledText.java

@Override
public void insert(String string) {
    if (!StringUtils.startsWith(StringUtils.trim(string), Messages.CANNOT_SEARCH_INPUT_STRING)) {
        super.insert(string);
        this.setFocus();
        this.setSelection(this.getText().length() + 100);
    }/*from   w  w w.  java  2  s .c  o m*/
}