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

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

Introduction

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

Prototype

public static boolean endsWith(String str, String suffix) 

Source Link

Document

Check if a String ends with a specified suffix.

Usage

From source file:org.kuali.rice.krad.uif.util.ExpressionUtils.java

/**
 * Used internally by parseExpression to evalute if the current stack is a property
 * name (ie, will be a control on the form)
 *
 * @param stack/*from   w w  w .  jav a2s.co m*/
 * @param controlNames
 */
public static void evaluateCurrentStack(String stack, List<String> controlNames) {
    if (StringUtils.isNotBlank(stack)) {
        if (!(stack.equals("==") || stack.equals("!=") || stack.equals(">") || stack.equals("<")
                || stack.equals(">=") || stack.equals("<=") || stack.equalsIgnoreCase("ne")
                || stack.equalsIgnoreCase("eq") || stack.equalsIgnoreCase("gt") || stack.equalsIgnoreCase("lt")
                || stack.equalsIgnoreCase("lte") || stack.equalsIgnoreCase("gte")
                || stack.equalsIgnoreCase("matches") || stack.equalsIgnoreCase("null")
                || stack.equalsIgnoreCase("false") || stack.equalsIgnoreCase("true")
                || stack.equalsIgnoreCase("and") || stack.equalsIgnoreCase("or") || stack.contains("#empty")
                || stack.equals("!") || stack.contains("#emptyList") || stack.contains("#listContains")
                || stack.startsWith("'") || stack.endsWith("'"))) {

            boolean isNumber = false;
            if ((StringUtils.isNumeric(stack.substring(0, 1)) || stack.substring(0, 1).equals("-"))) {
                try {
                    Double.parseDouble(stack);
                    isNumber = true;
                } catch (NumberFormatException e) {
                    isNumber = false;
                }
            }

            if (!(isNumber)) {
                //correct argument of a custom function ending in comma
                if (StringUtils.endsWith(stack, ",")) {
                    stack = StringUtils.removeEnd(stack, ",").trim();
                }

                if (!controlNames.contains(stack)) {
                    controlNames.add(stack);
                }
            }
        }
    }
}

From source file:org.kuali.rice.krad.uif.util.LookupInquiryUtils.java

public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
        Class<?> lookupObjectClass, String propertyName, String propertyValueName) {
    String parameterValue = "";

    // get literal parameter values first
    if (StringUtils.startsWith(propertyValueName, "'") && StringUtils.endsWith(propertyValueName, "'")) {
        parameterValue = StringUtils.removeStart(propertyValueName, "'");
        parameterValue = StringUtils.removeEnd(propertyValueName, "'");
    } else if (parameterValue.startsWith(
            KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
        parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
                + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER);
    }/*from w ww  . j a v  a 2s.  c  o  m*/
    // check if parameter is in request
    else if (request.getParameterMap().containsKey(propertyValueName)) {
        parameterValue = request.getParameter(propertyValueName);
    }
    // get parameter value from form object
    else {
        Object value = ObjectPropertyUtils.getPropertyValue(form, propertyValueName);
        if (value != null) {
            if (value instanceof String) {
                parameterValue = (String) value;
            }

            Formatter formatter = Formatter.getFormatter(value.getClass());
            parameterValue = (String) formatter.format(value);
        }
    }

    if (parameterValue != null && lookupObjectClass != null
            && KRADServiceLocatorWeb.getDataObjectAuthorizationService()
                    .attributeValueNeedsToBeEncryptedOnFormsAndLinks(lookupObjectClass, propertyName)) {
        try {
            if (CoreApiServiceLocator.getEncryptionService().isEnabled()) {
                parameterValue = CoreApiServiceLocator.getEncryptionService().encrypt(parameterValue)
                        + EncryptionService.ENCRYPTION_POST_PREFIX;
            }
        } catch (GeneralSecurityException e) {
            LOG.error("Unable to encrypt value for property name: " + propertyName);
            throw new RuntimeException(e);
        }
    }

    return parameterValue;
}

From source file:org.kuali.rice.krad.uif.util.ScriptUtils.java

/**
 * Convert a string to a javascript value - especially for use for options used to initialize
 * widgets such as the tree and rich table
 * /*from w  ww. j av  a2s .  c  om*/
 * @param value the string to be converted
 * @return the converted value
 */
public static String convertToJsValue(String value) {

    // save input value to preserve any whitespace formatting
    String originalValue = value;

    // remove whitespace for correct string matching
    value = StringUtils.strip(value);

    // If an option value starts with { or [, it would be a nested value
    // and it should not use quotes around it
    if (StringUtils.startsWith(value, "{") || StringUtils.startsWith(value, "[")) {
        return originalValue;
    }
    // need to be the base boolean value "false" is true in js - a non
    // empty string
    else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("true")) {
        return originalValue.toLowerCase();
    }
    // if it is a call back function, do not add the quotes
    else if (StringUtils.startsWith(value, "function") && StringUtils.endsWith(value, "}")) {
        return originalValue;
    }
    // for numerics
    else if (NumberUtils.isNumber(value)) {
        return originalValue;
    } else {
        // String values require double quotes
        return "\"" + originalValue + "\"";
    }
}

From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java

/**
 * Used internally by parseExpression to evalute if the current stack is a property
 * name (ie, will be a control on the form)
 *
 * @param stack/* www  . j  a v a  2  s  .  c om*/
 * @param controlNames
 */
protected void evaluateCurrentStack(String stack, List<String> controlNames) {
    if (StringUtils.isBlank(stack)) {
        return;
    }

    // These are special matches that can be directly replaced to a js equivalent (so skip evaluation of these)
    if (!(stack.equals("==") || stack.equals("!=") || stack.equals(">") || stack.equals("<")
            || stack.equals(">=") || stack.equals("<=") || stack.equalsIgnoreCase("ne")
            || stack.equalsIgnoreCase("eq") || stack.equalsIgnoreCase("gt") || stack.equalsIgnoreCase("lt")
            || stack.equalsIgnoreCase("lte") || stack.equalsIgnoreCase("gte")
            || stack.equalsIgnoreCase("matches") || stack.equalsIgnoreCase("null")
            || stack.equalsIgnoreCase("false") || stack.equalsIgnoreCase("true")
            || stack.equalsIgnoreCase("and") || stack.equalsIgnoreCase("or") || stack.startsWith("#")
            || stack.equals("!") || stack.startsWith("'") || stack.endsWith("'"))) {

        boolean isNumber = NumberUtils.isNumber(stack);

        // If it is not a number must be check to see if it is a name of a control
        if (!(isNumber)) {
            //correct argument of a custom function ending in comma
            if (StringUtils.endsWith(stack, ",")) {
                stack = StringUtils.removeEnd(stack, ",").trim();
            }

            if (!controlNames.contains(stack)) {
                controlNames.add(stack);
            }
        }
    }

}

From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java

/**
 * {@inheritDoc}/*from   w w  w  .j  a v  a  2  s .c  o m*/
 */
@Override
public Object evaluateExpression(Map<String, Object> evaluationParameters, String expressionStr) {
    Object result = null;

    // if expression contains placeholders remove before evaluating
    if (StringUtils.startsWith(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX)
            && StringUtils.endsWith(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX)) {
        expressionStr = StringUtils.removeStart(expressionStr, UifConstants.EL_PLACEHOLDER_PREFIX);
        expressionStr = StringUtils.removeEnd(expressionStr, UifConstants.EL_PLACEHOLDER_SUFFIX);
    }

    try {
        Expression expression = retrieveCachedExpression(expressionStr);

        if (evaluationParameters != null) {
            evaluationContext.setVariables(evaluationParameters);
        }

        result = expression.getValue(evaluationContext);
    } catch (Exception e) {
        LOG.error("Exception evaluating expression: " + expressionStr);
        throw new RuntimeException("Exception evaluating expression: " + expressionStr, e);
    }

    return result;
}

From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java

/**
 * {@inheritDoc}/*from  ww  w.j av  a  2  s .co  m*/
 */
@Override
public void evaluatePropertyExpression(View view, Map<String, Object> evaluationParameters,
        UifDictionaryBean expressionConfigurable, String propertyName, boolean removeExpression) {

    Map<String, String> propertyExpressions = expressionConfigurable.getPropertyExpressions();
    if ((propertyExpressions == null) || !propertyExpressions.containsKey(propertyName)) {
        return;
    }

    String expression = propertyExpressions.get(propertyName);

    // check whether expression should be evaluated or property should retain the expression
    if (CopyUtils.fieldHasAnnotation(expressionConfigurable.getClass(), propertyName, KeepExpression.class)) {
        // set expression as property value to be handled by the component
        ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, expression);
        return;
    }

    Object propertyValue = null;

    // replace binding prefixes (lp, dp, fp) in expression before evaluation
    String adjustedExpression = replaceBindingPrefixes(view, expressionConfigurable, expression);

    // determine whether the expression is a string template, or evaluates to another object type
    if (StringUtils.startsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX)
            && StringUtils.endsWith(adjustedExpression, UifConstants.EL_PLACEHOLDER_SUFFIX)
            && (StringUtils.countMatches(adjustedExpression, UifConstants.EL_PLACEHOLDER_PREFIX) == 1)) {
        propertyValue = evaluateExpression(evaluationParameters, adjustedExpression);
    } else {
        // treat as string template
        propertyValue = evaluateExpressionTemplate(evaluationParameters, adjustedExpression);
    }

    // if property name has the special indicator then we need to add the expression result to the property
    // value instead of replace
    if (StringUtils.endsWith(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR)) {
        StringUtils.removeEnd(propertyName, ExpressionEvaluator.EMBEDDED_PROPERTY_NAME_ADD_INDICATOR);

        Collection collectionValue = ObjectPropertyUtils.getPropertyValue(expressionConfigurable, propertyName);
        if (collectionValue == null) {
            throw new RuntimeException("Property name: " + propertyName
                    + " with collection type was not initialized. Cannot add expression result");
        }
        collectionValue.add(propertyValue);
    } else {
        ObjectPropertyUtils.setPropertyValue(expressionConfigurable, propertyName, propertyValue);
    }

    if (removeExpression) {
        propertyExpressions.remove(propertyName);
    }
}

From source file:org.kuali.student.cm.course.service.impl.CourseMaintainableImpl.java

@Override
public void processCollectionAddBlankLine(ViewModel model, String collectionId, String collectionPath) {

    MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model;
    MaintenanceDocument document = maintenanceForm.getDocument();

    CourseInfoWrapper courseInfoWrapper = (CourseInfoWrapper) document.getNewMaintainableObject()
            .getDataObject();/*from  www.  ja va 2s. com*/

    if (StringUtils.endsWith(collectionPath, "unitsContentOwner")) {

        //Before adding a new row, just make sure all the existing rows are not editable.
        for (CourseCreateUnitsContentOwner existing : courseInfoWrapper.getUnitsContentOwner()) {
            existing.getRenderHelper().setNewRow(false);
            if (!existing.isUserEntered()) {
                populateOrgName(courseInfoWrapper.getCourseInfo().getSubjectArea(), existing);
            }
        }

        OrgsBySubjectCodeValuesFinder optionsFinder = new OrgsBySubjectCodeValuesFinder();
        List<KeyValue> availableOptions = optionsFinder.getAvailableOrgs(courseInfoWrapper);

        if (!availableOptions.isEmpty()) {
            CourseCreateUnitsContentOwner newCourseCreateUnitsContentOwner = new CourseCreateUnitsContentOwner();
            newCourseCreateUnitsContentOwner.getRenderHelper().setNewRow(true);

            courseInfoWrapper.getUnitsContentOwner().add(newCourseCreateUnitsContentOwner);
        }

        return;
    } else if (StringUtils.endsWith(collectionPath, "formats")) {
        FormatInfo format = new FormatInfo();
        ActivityInfo activity = new ActivityInfo();
        format.getActivities().add(activity);
        courseInfoWrapper.getFormats().add(format);
        return;
    }

    super.processCollectionAddBlankLine(model, collectionId, collectionPath);
}

From source file:org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingMaintainableImpl.java

@Override
public void processCollectionAddBlankLine(ViewModel model, String collectionId, String collectionPath) {

    if (StringUtils.endsWith(collectionPath, "formatOfferingList")) {
        MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model;
        MaintenanceDocument document = maintenanceForm.getDocument();

        if (document.getNewMaintainableObject().getDataObject() instanceof CourseOfferingEditWrapper) {
            CourseOfferingEditWrapper wrapper = (CourseOfferingEditWrapper) document.getNewMaintainableObject()
                    .getDataObject();/*  w w  w. j  a v  a  2s .  c o m*/

            populateFormatNames(wrapper);

            FormatOfferingWrapper newFoWrapper = new FormatOfferingWrapper();
            newFoWrapper.getRenderHelper().setNewRow(true);

            wrapper.getFormatOfferingList().add(newFoWrapper);

            return;
        }
    }

    super.processCollectionAddBlankLine(model, collectionId, collectionPath);
}

From source file:org.mifosplatform.infrastructure.documentmanagement.api.ImagesApiResource.java

/**
 * Returns a base 64 encoded client image Data URI
 *//*from  w ww  .j ava  2  s .c  om*/
@GET
@Consumes({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })
public String retrieveClientImage(@PathParam("clientId") final Long clientId) {

    this.context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");

    final ImageData imageData = this.imageReadPlatformService.retrieveClientImage(clientId);

    // TODO: Need a better way of determining image type
    String imageDataURISuffix = ContentRepositoryUtils.IMAGE_DATA_URI_SUFFIX.JPEG.getValue();
    if (StringUtils.endsWith(imageData.location(),
            ContentRepositoryUtils.IMAGE_FILE_EXTENSION.GIF.getValue())) {
        imageDataURISuffix = ContentRepositoryUtils.IMAGE_DATA_URI_SUFFIX.GIF.getValue();
    } else if (StringUtils.endsWith(imageData.location(),
            ContentRepositoryUtils.IMAGE_FILE_EXTENSION.PNG.getValue())) {
        imageDataURISuffix = ContentRepositoryUtils.IMAGE_DATA_URI_SUFFIX.PNG.getValue();
    }

    final String clientImageAsBase64Text = imageDataURISuffix + Base64.encodeBytes(imageData.getContent());
    return clientImageAsBase64Text;
}

From source file:org.mifosplatform.portfolio.client.api.ClientImagesApiResource.java

/**
 * Returns a base 64 encoded client image Data URI
 *///  w ww . j a va 2  s . c o  m
@GET
@Consumes({ MediaType.TEXT_PLAIN, MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.TEXT_PLAIN })
public String retrieveClientImage(@PathParam("clientId") final Long clientId) {

    context.authenticatedUser().validateHasReadPermission("CLIENTIMAGE");

    final ClientData clientData = this.clientReadPlatformService.retrieveOne(clientId);

    if (clientData.imageKeyDoesNotExist()) {
        throw new ImageNotFoundException("clients", clientId);
    }

    // TODO: Need a better way of determining image type
    String imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.JPEG.getValue();
    if (StringUtils.endsWith(clientData.imageKey(), IMAGE_FILE_EXTENSION.GIF.getValue())) {
        imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.GIF.getValue();
    } else if (StringUtils.endsWith(clientData.imageKey(), IMAGE_FILE_EXTENSION.PNG.getValue())) {
        imageDataURISuffix = IMAGE_DATA_URI_SUFFIX.PNG.getValue();
    }

    String clientImageAsBase64Text = imageDataURISuffix + Base64.encodeFromFile(clientData.imageKey());

    return clientImageAsBase64Text;
}