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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:org.jts.protocolvalidator.Guard.java

/**
 * Retrieve a list of Promela guard function definitions
 * @return - the list of Promela code for definitions
 *//*from   w  w w .  j a v  a2  s  .  c o  m*/
public List<String> getConditionList() {
    List<String> output = new ArrayList<String>();
    String tmpcond = Util.formatConditionString(condition);
    tmpcond = tmpcond.replaceAll("(msg)", "incoming_pid, " + messageData);
    tmpcond = tmpcond.replace("transportData", "incoming_pid");

    // get rid of some of the whitespace
    // remove all logical operators, since we are concerned with just the elemenats.
    tmpcond = tmpcond.replace(" && ", " \t ");
    tmpcond = tmpcond.replace(" || ", " \t ");
    tmpcond = tmpcond.replaceAll("!", "");
    // if the comments are too long, then break them up
    // on multiple lines.  at the same time remove additional spaces.
    // The assumption is that these conditions don't normally contain tabs within the element.

    String[] tmpstr = tmpcond.split("[\t]+");
    for (String element : tmpstr) {
        element = StringUtils.strip(element);
        element = StringUtils.deleteWhitespace(element);
        // add prefix to make this defintion unique
        if (messageData.length() > INST_LEN && element.contains(messageData)) {
            element = messageData.substring(0, messageData.length() - INST_LEN) + "_" + element;
        }
        output.add("#define " + element + " (true)");
    }

    return output;
}

From source file:org.jts.protocolvalidator.Util.java

/**
 * Takes a poorly formatted description or interpretation string and formats it
 * so that it wraps at the proper column and also removes all the obnoxious whitespace.
 * This is necessary due to the formatting imposed by the comments in the JSIDL.
 * @param comment - The input string that will become a comment in the Promela code.
 * @param isBlockComment - true if this is a block comment. Otherwise, it is a line comment
 *                          and will be broken up into multiple line comments.
 * @return - a single comment string that may represent multiple lines.
 *//*from www. j  a  va2 s .  c  om*/
public static List<String> formatCommentString(String comment, boolean isBlockComment) {
    List<String> output = new ArrayList<String>();
    if (comment == null || comment.isEmpty()) {
        return output;
    }
    // figure out how many tabs are being used so we keep good alignment
    if (isBlockComment) {
        output.add("/**");
    }
    String returnString = "";
    // get rid of some of the whitespace
    comment = StringUtils.strip(comment);

    // if the comments are too long, then break them up
    // on multiple lines.  at the same time remove additional spaces.
    String[] tmpstr = comment.split("[ \n\t]+");
    long count = 0;
    for (String word : tmpstr) {
        // start off the comment line with the appropriate markers
        if (returnString.isEmpty()) {
            if (isBlockComment) {
                returnString = "* ";
            } else {
                returnString = "// ";
            }
        }
        // many whitespace characters are embedded in these strings
        // make sure we remove them.
        returnString += " " + StringUtils.strip(word);
        count += word.length();
        if (count > LINE_LEN) {
            count = 0;
            output.add(returnString);
            returnString = "";
        }

    }
    if (!returnString.isEmpty()) {
        output.add(returnString);
    }
    if (isBlockComment) {
        output.add("*/");
    }
    return output;
}

From source file:org.jts.protocolvalidator.Util.java

/**
 * Takes a poorly formatted description or interpretation string and formats it
 * so that it wraps at the proper column and also removes all the obnoxious whitespace.
 * This is necessary due to the formatting imposed by the comments in the JSIDL.
 * @param comment - The input string that will become a comment in the Promela code.
 * @param isBlockComment - true if this is a block comment. Otherwise, it is a line comment
 *                          and will be broken up into multiple line comments.
 * @return - a single comment string that may represent multiple lines.
 *//*from ww  w .  j a  v  a 2 s. c  o  m*/
public static String formatConditionString(String condition) {
    if (condition == null || condition.isEmpty()) {
        return condition;
    }
    String returnString = "";
    // get rid of some of the whitespace
    condition = StringUtils.strip(condition);

    // if the comments are too long, then break them up
    // on multiple lines.  at the same time remove additional spaces.
    String[] tmpstr = condition.split("[ \n\t]+");

    for (String word : tmpstr) {
        returnString += " " + StringUtils.strip(word);
    }

    return returnString;
}

From source file:org.kordamp.json.xml.XMLSerializer.java

private boolean checkChildElements(Element parentElement, boolean isTopLevel) {
    String parentName = parentElement.getQualifiedName();
    int childCount = parentElement.getChildCount();
    Elements elements = parentElement.getChildElements();
    int elementCount = elements.size();

    if (childCount == 1 && parentElement.getChild(0) instanceof Text) {
        return isTopLevel;
    }/*  w  w  w .  ja  v a 2 s  .  c  o  m*/

    if (childCount == elementCount) {
        if (elementCount == 0) {
            return true;
        }
        if (elementCount == 1) {
            // TODO jenkisci/json-lib changed && to ||
            return skipWhitespace && parentElement.getChild(0) instanceof Text;
        }
    }

    if (childCount > elementCount) {
        for (int i = 0; i < childCount; i++) {
            Node node = parentElement.getChild(i);
            if (node instanceof Text) {
                Text text = (Text) node;
                if (StringUtils.isNotBlank(StringUtils.strip(text.getValue())) && !skipWhitespace) {
                    return false;
                }
            }
        }
    }

    String childName = elements.get(0).getQualifiedName();
    for (int i = 1; i < elementCount; i++) {

        if (childName.compareTo(elements.get(i).getQualifiedName()) != 0
                && !forcedArrayElements.contains(parentName)) { // forcedArrayElements.isEmpty()
            return false;

        } else {
            if (childName.compareTo(elements.get(i).getQualifiedName()) != 0
                    && forcedArrayElements.contains(parentName)) {
                log.warn("Child elements [{},{}] of forced array element [{}] are not from the same type",
                        childName, elements.get(i).getQualifiedName(), parentElement.getQualifiedName());
            }
        }
    }

    return childName.equals(arrayName) || elementCount > 1;
}

From source file:org.kordamp.json.xml.XMLSerializer.java

private JSON processArrayElement(Element element, String defaultType) {
    JSONArray jsonArray = new JSONArray();
    // process children (including text)
    int childCount = element.getChildCount();
    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                jsonArray.element(text.getValue());
            }//  w ww.j a  v a 2  s .c o  m
        } else if (child instanceof Element) {
            setValue(jsonArray, (Element) child, defaultType);
        }
    }
    if (keepArrayName) {
        boolean isSameElementNameInArray = true;
        String arrayName = null;
        for (int i = 0; i < element.getChildElements().size(); i++) {
            final String arrayElement = element.getChildElements().get(i).getQualifiedName();
            if (arrayName == null) {
                arrayName = arrayElement;
            } else if (!arrayName.equals(arrayElement) && forcedArrayElements.isEmpty()) {
                isSameElementNameInArray = false;
            } else if (!arrayName.equals(arrayElement)
                    && forcedArrayElements.contains(element.getQualifiedName())) {
                log.warn("Child elements [{},{}] of forced array element [{}] are not from the same type",
                        arrayName, arrayElement, element.getQualifiedName());
            }
        }

        if (isSameElementNameInArray) {
            JSONObject result = new JSONObject();
            // in the case of a self-closing tag, arrayName will be null
            // and this will throw an error if we return the empty array
            // then it will be added correctly to the result
            if (arrayName == null) {
                return jsonArray;
            }
            result.put(arrayName, jsonArray);
            return result;
        }

    } else if (forcedArrayElements != null && forcedContains(forcedArrayElements, element.getQualifiedName())) {
        // array not named, check if forced array and give warning if elements not same type
        String arrayName = null;
        for (int i = 0; i < element.getChildElements().size(); i++) {
            final String arrayElement = element.getChildElements().get(i).getQualifiedName();
            if (arrayName == null) {
                arrayName = arrayElement;
            } else if (!arrayName.equals(arrayElement)) {
                log.warn(
                        "Child elements [" + arrayName + "," + arrayElement + "] of " + "forced array element ["
                                + element.getQualifiedName() + "] " + "are not from the same type");
            }
        }

    }
    return jsonArray;
}

From source file:org.kuali.kfs.module.bc.document.service.impl.BudgetRequestImportServiceImpl.java

/**
 * @see org.kuali.kfs.module.bc.document.service.BudgetRequestImportService#processImportFile(java.io.InputStream, java.lang.String,
 *      java.lang.String, java.lang.String)
 *//*from   w ww .  j  a  va 2 s. com*/
@Transactional
public List processImportFile(InputStream fileImportStream, String principalId, String fieldSeperator,
        String textDelimiter, String fileType, Integer budgetYear) throws IOException {
    List fileErrorList = new ArrayList();

    deleteBudgetConstructionMoveRecords(principalId);

    BudgetConstructionRequestMove budgetConstructionRequestMove = new BudgetConstructionRequestMove();

    BufferedReader fileReader = new BufferedReader(new InputStreamReader(fileImportStream));
    int currentLine = 1;
    while (fileReader.ready()) {
        String line = StringUtils.strip(fileReader.readLine());
        boolean isAnnualFile = (fileType.equalsIgnoreCase(RequestImportFileType.ANNUAL.toString())) ? true
                : false;

        if (StringUtils.isNotBlank(line)) {
            budgetConstructionRequestMove = ImportRequestFileParsingHelper.parseLine(line, fieldSeperator,
                    textDelimiter, isAnnualFile);

            // check if there were errors parsing the line
            if (budgetConstructionRequestMove == null) {
                fileErrorList.add(BCConstants.REQUEST_IMPORT_FILE_PROCESSING_ERROR_MESSAGE_GENERIC + " "
                        + currentLine + ".");
                // clean out table since file processing has stopped
                deleteBudgetConstructionMoveRecords(principalId);
                return fileErrorList;
            }

            String lineValidationError = validateLine(budgetConstructionRequestMove, currentLine, isAnnualFile);

            if (StringUtils.isNotEmpty(lineValidationError)) {
                fileErrorList.add(lineValidationError);
                // clean out table since file processing has stopped
                deleteBudgetConstructionMoveRecords(principalId);
                return fileErrorList;
            }

            // set default values
            if (StringUtils.isBlank(budgetConstructionRequestMove.getSubAccountNumber())) {
                budgetConstructionRequestMove.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
            }

            if (StringUtils.isBlank(budgetConstructionRequestMove.getFinancialSubObjectCode())) {
                budgetConstructionRequestMove
                        .setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
            }
            //set object type code
            Collection<String> revenueObjectTypesParamValues = BudgetParameterFinder.getRevenueObjectTypes();
            Collection<String> expenditureObjectTypesParamValues = BudgetParameterFinder
                    .getExpenditureObjectTypes();
            ObjectCode objectCode = getObjectCode(budgetConstructionRequestMove, budgetYear);
            if (objectCode != null) {
                if (expenditureObjectTypesParamValues.contains(objectCode.getFinancialObjectTypeCode())) {
                    budgetConstructionRequestMove
                            .setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());

                    // now using type from object code table
                    //budgetConstructionRequestMove.setFinancialObjectTypeCode(optionsService.getOptions(budgetYear).getFinObjTypeExpenditureexpCd());
                } else if (revenueObjectTypesParamValues.contains(objectCode.getFinancialObjectTypeCode())) {
                    budgetConstructionRequestMove
                            .setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());

                    // now using type from object code table
                    //budgetConstructionRequestMove.setFinancialObjectTypeCode(optionsService.getOptions(budgetYear).getFinObjectTypeIncomecashCode());
                }
            }

            //check for duplicate key exception, since it requires a different error message
            Map searchCriteria = new HashMap();
            searchCriteria.put("principalId", principalId);
            searchCriteria.put("chartOfAccountsCode", budgetConstructionRequestMove.getChartOfAccountsCode());
            searchCriteria.put("accountNumber", budgetConstructionRequestMove.getAccountNumber());
            searchCriteria.put("subAccountNumber", budgetConstructionRequestMove.getSubAccountNumber());
            searchCriteria.put("financialObjectCode", budgetConstructionRequestMove.getFinancialObjectCode());
            searchCriteria.put("financialSubObjectCode",
                    budgetConstructionRequestMove.getFinancialSubObjectCode());
            if (this.businessObjectService.countMatching(BudgetConstructionRequestMove.class,
                    searchCriteria) != 0) {
                LOG.error("Move table store error, import aborted");
                fileErrorList.add(
                        "Duplicate Key for " + budgetConstructionRequestMove.getErrorLinePrefixForLogFile());
                fileErrorList.add("Move table store error, import aborted");
                deleteBudgetConstructionMoveRecords(principalId);

                return fileErrorList;
            }
            try {
                budgetConstructionRequestMove.setPrincipalId(principalId);
                importRequestDao.save(budgetConstructionRequestMove, false);
            } catch (RuntimeException e) {
                LOG.error("Move table store error, import aborted");
                fileErrorList.add("Move table store error, import aborted");
                return fileErrorList;
            }
        }

        currentLine++;
    }

    return fileErrorList;
}

From source file:org.kuali.kfs.pdp.businessobject.BankChangeHistory.java

public String getOriginalBankCodeList() {
    String commaSeparatedOriginalBankCodeList = "";

    for (PaymentGroupHistory paymentGroupHistory : this.getPaymentGroup().getPaymentGroupHistory()) {
        if (!StringUtils.isEmpty(paymentGroupHistory.getOrigBankCode()))
            commaSeparatedOriginalBankCodeList = commaSeparatedOriginalBankCodeList
                    + paymentGroupHistory.getOrigBankCode() + ", ";
    }/*from   w  w w.  j  a v a2 s .  c o  m*/

    commaSeparatedOriginalBankCodeList = StringUtils.strip(commaSeparatedOriginalBankCodeList);
    commaSeparatedOriginalBankCodeList = StringUtils.removeEnd(commaSeparatedOriginalBankCodeList, ",");

    return commaSeparatedOriginalBankCodeList;
}

From source file:org.kuali.kpme.pm.position.PositionQualifierValueKeyValueFinder.java

@Override
public List<KeyValue> getKeyValues(ViewModel model) {
    MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
    List<KeyValue> options = new ArrayList<KeyValue>();

    PositionQualificationBo aQualification = (PositionQualificationBo) docForm.getNewCollectionLines()
            .get("document.newMaintainableObject.dataObject.qualificationList");
    if (aQualification != null) {
        String aTypeId = aQualification.getQualificationType();
        PstnQlfrTypeContract aTypeObj = PmServiceLocator.getPstnQlfrTypeService().getPstnQlfrTypeById(aTypeId);
        if (aTypeObj != null) {
            if (aTypeObj.getTypeValue().equals(PMConstants.PSTN_QLFR_SELECT)) {
                String[] aCol = aTypeObj.getSelectValues().split(",");
                for (String aString : aCol) {
                    aString = StringUtils.strip(aString);
                    options.add(new ConcreteKeyValue(aString, aString));
                }//from   www  .  j  a  v  a  2 s .  c o  m
            } else {
                return new ArrayList<KeyValue>();
            }
        }
    }
    return options;
}

From source file:org.kuali.kpme.pm.position.PositionQualifierValueKeyValueFinder.java

@Override
public List<KeyValue> getKeyValues(ViewModel model, InputField field) {

    MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;
    HrBusinessObject anHrObject = (HrBusinessObject) docForm.getDocument().getNewMaintainableObject()
            .getDataObject();/*  w  w w  . j  av  a  2 s.c om*/
    List<KeyValue> options = new ArrayList<KeyValue>();

    if (field.getId().contains("add")) {
        // For "add" line, just delegate to getKeyValues(model) method as it is working correctly
        options = getKeyValues(model);
    } else {
        // Strip index off field id
        String fieldId = field.getId();
        int line_index = fieldId.indexOf("line");
        int index = Integer.parseInt(fieldId.substring(line_index + 4));

        PositionBo aPosition = (PositionBo) anHrObject;
        List<PositionQualificationBo> qualificationList = aPosition.getQualificationList(); // holds "added" lines
        PositionQualificationBo posQualification = (PositionQualificationBo) qualificationList.get(index);
        String aTypeId = posQualification.getQualificationType();

        PstnQlfrTypeContract aTypeObj = PmServiceLocator.getPstnQlfrTypeService().getPstnQlfrTypeById(aTypeId);
        ;
        if (aTypeObj != null) {
            if (aTypeObj.getTypeValue().equals(PMConstants.PSTN_QLFR_SELECT)) {
                String[] aCol = aTypeObj.getSelectValues().split(",");
                for (String aString : aCol) {
                    aString = StringUtils.strip(aString);
                    options.add(new ConcreteKeyValue(aString, aString));
                }
            } else {
                return new ArrayList<KeyValue>();
            }
        }
    }

    return options;

}

From source file:org.kuali.kpme.pm.util.QualifierValueKeyValueFinder.java

@Override
public List<KeyValue> getKeyValues(ViewModel model) {
    MaintenanceDocumentForm docForm = (MaintenanceDocumentForm) model;

    List<KeyValue> options = new ArrayList<KeyValue>();

    ClassificationQualificationBo aQualification = (ClassificationQualificationBo) docForm
            .getNewCollectionLines().get("document.newMaintainableObject.dataObject.qualificationList");
    if (aQualification != null) {
        String aTypeId = aQualification.getQualificationType();
        PstnQlfrTypeContract aTypeObj = PmServiceLocator.getPstnQlfrTypeService().getPstnQlfrTypeById(aTypeId);
        if (aTypeObj != null) {
            if (aTypeObj.getTypeValue().equals(PMConstants.PSTN_QLFR_SELECT)) {
                String[] aCol = aTypeObj.getSelectValues().split(",");
                for (String aString : aCol) {
                    aString = StringUtils.strip(aString);
                    options.add(new ConcreteKeyValue(aString, aString));
                }/*ww  w.  j  a  va  2  s. co m*/
            } else {
                return new ArrayList<KeyValue>();
            }
        }
    }
    return options;
}