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

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

Introduction

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

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:org.kuali.kfs.sys.businessobject.lookup.BatchFileLookupableHelperServiceImpl.java

protected IOFileFilter getLastModifiedDateBasedFilter(String lastModifiedDatePattern) {
    if (StringUtils.isBlank(lastModifiedDatePattern)) {
        return null;
    }//from  w  w  w  .  j a  v a  2  s.c  om
    try {
        if (lastModifiedDatePattern.startsWith("<=")) {
            String dateString = StringUtils.removeStart(lastModifiedDatePattern, "<=");
            Date toDate = dateTimeService.convertToDate(dateString);
            return new LastModifiedDateFileFilter(null, toDate);
        }
        if (lastModifiedDatePattern.startsWith(">=")) {
            String dateString = StringUtils.removeStart(lastModifiedDatePattern, ">=");
            Date fromDate = dateTimeService.convertToDate(dateString);
            return new LastModifiedDateFileFilter(fromDate, null);
        }
        if (lastModifiedDatePattern.contains("..")) {
            String[] dates = StringUtils.splitByWholeSeparator(lastModifiedDatePattern, "..", 2);
            Date fromDate = dateTimeService.convertToDate(dates[0]);
            Date toDate = dateTimeService.convertToDate(dates[1]);
            return new LastModifiedDateFileFilter(fromDate, toDate);
        }
    } catch (ParseException e) {
        throw new RuntimeException("Can't parse date", e);
    }
    throw new RuntimeException("Unable to perform search using last modified date " + lastModifiedDatePattern);
}

From source file:org.kuali.kfs.sys.context.SchemaBuilder.java

/**
 * Constructs new AttributeSchemaValidationBuilder for the given attribute name to build the type XML lines which are added to
 * the given collection/* w  w w.  j a v  a2  s. c  o  m*/
 * 
 * @param ddAttributeName attribute entry name (business object class and attribute name) with dd: namespace prefix
 * @param typesSchemaLines collection of type XML lines to add to for any new types
 * @param builtTypes - Set of attribute names for which a schema validation type has been built
 * @see org.kuali.kfs.sys.context.AttributeSchemaValidationBuilder
 */
protected static void buildDataDictionarySchemaValidationType(String ddAttributeName,
        Collection typesSchemaLines, Set<String> builtTypes) {
    // strip prefix from attribute name so we can find it in dd map
    String attributeEntryName = StringUtils.removeStart(ddAttributeName, DD_VALIDATION_PREFIX);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving entry from data dictionary for attribute: " + attributeEntryName);
    }

    // only build one type for the attribute name
    if (!builtTypes.contains(attributeEntryName)) {
        AttributeSchemaValidationBuilder schemaBuilder = new AttributeSchemaValidationBuilder(
                attributeEntryName);
        typesSchemaLines.addAll(schemaBuilder.toSchemaType());
        typesSchemaLines.add(" ");

        builtTypes.add(attributeEntryName);
    }
}

From source file:org.kuali.kfs.sys.service.impl.ReportWriterTextServiceImpl.java

/**
 * @param printBusinessObjectValues indicates whether the bo values should be printed before the message
 * @see org.kuali.kfs.sys.service.ReportWriterService#writeError(java.lang.Class, org.kuali.kfs.sys.Message)
 *//*from w ww  .  ja v  a2  s .c om*/
public void writeError(BusinessObject businessObject, Message message, boolean printBusinessObjectValues) {
    // Check if we need to write a new table header. We do this if it hasn't been written before or if the businessObject
    // changed
    if (newPage || businessObjectClass == null
            || !businessObjectClass.getName().equals(businessObject.getClass().getName())) {
        if (businessObjectClass == null) {
            // If we didn't write the header before, write it with a subTitle
            this.writeSubTitle(errorSubTitle);
        } else if (!businessObjectClass.getName().equals(businessObject.getClass().getName())) {
            // If it changed push a newline in for neater formatting
            this.writeNewLines(1);
        }

        this.writeErrorHeader(businessObject);
        newPage = false;
        businessObjectClass = businessObject.getClass();
    }

    // Get business object formatter that will be used
    BusinessObjectReportHelper businessObjectReportHelper = getBusinessObjectReportHelper(businessObject);

    // Print the values of the businessObject per formatting determined by writeErrorHeader
    List<Object> formatterArgs = new ArrayList<Object>();
    if (printBusinessObjectValues) {
        formatterArgs.addAll(businessObjectReportHelper.getValues(businessObject));
    } else {
        formatterArgs.addAll(businessObjectReportHelper.getBlankValues(businessObject));
    }

    // write rest of message on new line(s) if it was cut off
    int maxMessageLength = Integer
            .parseInt(StringUtils.substringBefore(StringUtils.substringAfterLast(errorFormat, "%-"), "s"));
    String messageToPrint = message.getMessage();

    boolean firstMessageLine = true;
    while (messageToPrint.length() > 0 && StringUtils.isNotBlank(messageToPrint)) {
        if (!firstMessageLine) {
            formatterArgs = new ArrayList<Object>();
            formatterArgs.addAll(businessObjectReportHelper.getBlankValues(businessObject));
        } else {
            firstMessageLine = false;
        }

        messageToPrint = StringUtils.trim(messageToPrint);
        String messageLine = messageToPrint;
        if (messageLine.length() > maxMessageLength) {
            messageLine = StringUtils.substring(messageLine, 0, maxMessageLength);
            if (StringUtils.contains(messageLine, " ")) {
                messageLine = StringUtils.substringBeforeLast(messageLine, " ");
            }
        }

        formatterArgs.add(new Message(messageLine, message.getType()));
        this.writeFormattedMessageLine(errorFormat, formatterArgs.toArray());

        messageToPrint = StringUtils.removeStart(messageToPrint, messageLine);
    }
}

From source file:org.kuali.kpme.core.ListConverter.java

@Override
public Object sqlToJava(Object arg0) throws ConversionException {

    String selectedValues = arg0.toString();
    List<String> aList = new ArrayList<String>();

    selectedValues = StringUtils.removeStart(selectedValues, "[");
    selectedValues = StringUtils.removeEnd(selectedValues, "]");
    String[] values = StringUtils.split(selectedValues, ",");

    for (String value : values) {
        aList.add(StringUtils.strip(value, " ")); // strip whitespace from the start and end
    }/*  w  w  w  .  j  a va 2 s  . c o m*/

    return aList;
}

From source file:org.kuali.rice.core.api.search.SearchExpressionUtils.java

public static String parsePrefixUnaryOperatorValue(SearchOperator operator, String expression) {
    return StringUtils.removeStart(expression.trim(), operator.op()).trim();
}

From source file:org.kuali.rice.krad.data.provider.annotation.impl.AnnotationMetadataProviderImpl.java

/**
 * Used to find the property name from a getter method.
 * //from w w w  .  j a  v  a2 s . c o  m
 * <p>(Not using PropertyUtils since it required an instance of the class.)</p>
  *
  * @param m the method from which to get the property name.
  * @return the property name.
 */
protected String getPropertyNameFromGetterMethod(Method m) {
    String propertyName = "";
    if (m.getName().startsWith("get")) {
        propertyName = StringUtils.uncapitalize(StringUtils.removeStart(m.getName(), "get"));
    } else { // must be "is"
        propertyName = StringUtils.uncapitalize(StringUtils.removeStart(m.getName(), "is"));
    }
    return propertyName;
}

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Parses a bean of the spring namespace.
 *
 * @param tag - The Element to be parsed.
 * @return The parsed bean./*from  www  .  ja v a2s .c o  m*/
 */
protected Object parseSpringBean(Element tag, ParserContext parserContext) {
    if (tag.getLocalName().compareTo("ref") == 0) {
        // Create the referenced bean by creating a new bean and setting its parent to the referenced bean
        // then replace grand child with it
        Element temp = tag.getOwnerDocument().createElement("bean");
        temp.setAttribute("parent", tag.getAttribute("bean"));
        tag = temp;
        return new RuntimeBeanReference(tag.getAttribute("parent"));
    }

    //peel off p: properties an make them actual property nodes - p-namespace does not work properly (unknown cause)
    Document document = tag.getOwnerDocument();
    NamedNodeMap attributes = tag.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        String name = attribute.getNodeName();
        if (name.startsWith("p:")) {
            Element property = document.createElement("property");
            property.setAttribute("name", StringUtils.removeStart(name, "p:"));
            property.setAttribute("value", attribute.getTextContent());

            if (tag.getFirstChild() != null) {
                tag.insertBefore(property, tag.getFirstChild());
            } else {
                tag.appendChild(property);
            }
        }
    }

    // Create the bean definition for the grandchild and return it.
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
    BeanDefinitionHolder bean = delegate.parseBeanDefinitionElement(tag);

    // Creates a custom name for the new bean.
    String name = bean.getBeanDefinition().getParentName() + "$Customchild" + beanNumber;
    if (tag.getAttribute("id") != null && !StringUtils.isEmpty(tag.getAttribute("id"))) {
        name = tag.getAttribute("id");
    } else {
        beanNumber++;
    }

    return new BeanDefinitionHolder(bean.getBeanDefinition(), name);
}

From source file:org.kuali.rice.krad.lookup.LookupUtils.java

/**
 * Retrieves the value for the given parameter name to send as a lookup parameter.
 *
 * @param form form instance to retrieve values from
 * @param request request object to retrieve parameters from
 * @param lookupObjectClass data object class associated with the lookup, used to check whether the
 * value needs to be encyrpted//from   ww  w .  jav  a2  s.  c om
 * @param propertyName name of the property associated with the parameter, used to check whether the
 * value needs to be encrypted
 * @param parameterName name of the parameter to retrieve the value for
 * @return String parameter value or empty string if no value was found
 */
public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
        Class<?> lookupObjectClass, String propertyName, String parameterName) {
    String parameterValue = "";

    // get literal parameter values first
    if (StringUtils.startsWith(parameterName, "'") && StringUtils.endsWith(parameterName, "'")) {
        parameterValue = StringUtils.substringBetween(parameterName, "'");
    } 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);
    }
    // check if parameter is in request
    else if (request.getParameterMap().containsKey(parameterName)) {
        parameterValue = request.getParameter(parameterName);
    }
    // get parameter value from form object
    else {
        parameterValue = ObjectPropertyUtils.getPropertyValueAsText(form, parameterName);
    }

    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.theme.postprocessor.ThemeFilesProcessor.java

/**
 * Collects the file names to include for the theme, separated by whether they come from a plugin directory
 * or the theme directory//from  w  w  w  .ja  v a  2 s  .  co  m
 *
 * <p>
 * First all plugin directories that are included for the theme are listed based on the include for that
 * file type {@link #getFileIncludes()}. Individual plugin files can be excluded with the property
 * <code>pluginFileExcludes</code>, or the global excludes for the file type {@link #getFileExcludes()}
 *
 * Next the subdirectory of the theme that holds the file type, given by {@link #getFileTypeSubDirectory()},
 * is listed to pick up include files. Again the global file includes and excludes for the type is used
 *
 * Finally, subclasses can add additional files by implementing {@link #addAdditionalFiles(java.util.List)}
 * </p>
 *
 * @return map containing an entry for plugin file names, and theme file names. Keys are given by
 *         {@link #PLUGIN_FILES_KEY} and {@link #SUBDIR_FILES_KEY}
 * @see #getFileIncludes()
 * @see #getFileExcludes()
 * @see #getFileTypeSubDirectory()
 * @see #addAdditionalFiles(java.util.List)
 */
protected Map<String, List<File>> collectThemeFiles() {
    Map<String, List<File>> themeFiles = new HashMap<String, List<File>>();

    String[] fileIncludes = getFileIncludes();
    String[] fileExcludes = getFileExcludes();

    // add files from plugins first
    String[] pluginFileExcludes = null;
    if (this.themeProperties.containsKey(ThemeBuilderConstants.ThemeConfiguration.PLUGIN_FILE_EXCLUDES)) {
        pluginFileExcludes = ThemeBuilderUtils.getPropertyValueAsArray(
                ThemeBuilderConstants.ThemeConfiguration.PLUGIN_FILE_EXCLUDES, this.themeProperties);
    }

    // global file excludes should also apply to plugins
    if (fileExcludes != null) {
        if (pluginFileExcludes == null) {
            pluginFileExcludes = fileExcludes;
        } else {
            pluginFileExcludes = ThemeBuilderUtils.addToArray(pluginFileExcludes, fileExcludes);
        }
    }

    // for convenience we don't require the extension on the patterns, but it must be added before
    // we use the patterns for matching
    ThemeBuilderUtils.addExtensionToPatterns(fileIncludes, getFileTypeExtension());
    ThemeBuilderUtils.addExtensionToPatterns(fileExcludes, getFileTypeExtension());
    ThemeBuilderUtils.addExtensionToPatterns(pluginFileExcludes, getFileTypeExtension());

    List<File> pluginThemeFiles = new ArrayList<File>();
    for (Map.Entry<String, File> pluginMapping : this.themePluginDirsMap.entrySet()) {
        String pluginName = pluginMapping.getKey();
        File pluginDirectory = pluginMapping.getValue();

        // adjust plugin file excludes to not include the top directory
        String[] adjustedFileExcludes = null;
        if (pluginFileExcludes != null) {
            adjustedFileExcludes = new String[pluginFileExcludes.length];

            for (int i = 0; i < pluginFileExcludes.length; i++) {
                adjustedFileExcludes[i] = StringUtils.removeStart(pluginFileExcludes[i], pluginName + "/");
            }
        }

        pluginThemeFiles.addAll(
                ThemeBuilderUtils.getDirectoryFiles(pluginDirectory, fileIncludes, adjustedFileExcludes));
    }

    themeFiles.put(PLUGIN_FILES_KEY, pluginThemeFiles);

    // now add files in the subdirectory for this file type directory
    List<File> subDirThemeFiles = new ArrayList<File>();

    subDirThemeFiles
            .addAll(ThemeBuilderUtils.getDirectoryFiles(getFileTypeSubDirectory(), fileIncludes, fileExcludes));

    // allow additional files to be added based on the file type
    addAdditionalFiles(subDirThemeFiles);

    themeFiles.put(SUBDIR_FILES_KEY, subDirThemeFiles);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Found " + subDirThemeFiles.size() + "file(s) for theme " + this.themeName);
    }

    return themeFiles;
}

From source file:org.kuali.rice.krad.uif.component.BindingInfo.java

/**
 * Returns the binding path that is formed by taking the binding configuration
 * of this <code>BindingInfo</code> instance with the given property path as the
 * binding name. This can be used to get the binding path when just a property
 * name is given that is assumed to be on the same parent object of the field with
 * the configured binding info//from w ww.j a v  a  2  s. c o m
 *
 * <p>
 * Special check is done for org.kuali.rice.krad.uif.UifConstants#NO_BIND_ADJUST_PREFIX prefix
 * on the property name which indicates the property path is the full path and should
 * not be adjusted. Also, if the property is prefixed with
 * org.kuali.rice.krad.uif.UifConstants#FIELD_PATH_BIND_ADJUST_PREFIX, this indicates we should only append the
 * binding object path
 * </p>
 *
 * @param propertyPath path for property to return full binding path for
 * @return full binding path
 */
public String getPropertyAdjustedBindingPath(String propertyPath) {
    if (propertyPath.startsWith(UifConstants.NO_BIND_ADJUST_PREFIX)) {
        propertyPath = StringUtils.removeStart(propertyPath, UifConstants.NO_BIND_ADJUST_PREFIX);

        return propertyPath;
    }

    if (propertyPath.startsWith(UifConstants.FIELD_PATH_BIND_ADJUST_PREFIX)) {
        propertyPath = StringUtils.removeStart(propertyPath, UifConstants.FIELD_PATH_BIND_ADJUST_PREFIX);
    }

    String formedBindingPath = getBindingPathPrefix();

    if (bindToMap) {
        formedBindingPath += "[" + propertyPath + "]";
    } else {
        if (StringUtils.isNotBlank(formedBindingPath)) {
            formedBindingPath += ".";
        }
        formedBindingPath += propertyPath;
    }

    return formedBindingPath;
}