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

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

Introduction

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

Prototype

public static String substringBetween(String str, String open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:org.kuali.rice.krad.document.MaintenanceDocumentBase.java

private List<Note> getNotesFromXml(String notesTagName) {
    String notesXml = StringUtils.substringBetween(xmlDocumentContents, "<" + notesTagName + ">",
            "</" + notesTagName + ">");
    if (StringUtils.isBlank(notesXml)) {
        return Collections.emptyList();
    }/*from   w w w  .ja v  a 2  s.c  om*/
    List<Note> notes = (List<Note>) KRADServiceLocator.getXmlObjectSerializerService().fromXml(notesXml);
    if (notes == null) {
        return Collections.emptyList();
    }
    return notes;
}

From source file:org.kuali.rice.krad.document.MaintenanceDocumentBase.java

/**
 * Retrieves substring of document contents from maintainable tag name. Then use xml service to translate xml into
 * a//from  www . ja  v a2 s.c om
 * business object.
 */
protected Object getDataObjectFromXML(String maintainableTagName) {
    String maintXml = StringUtils.substringBetween(xmlDocumentContents, "<" + maintainableTagName + ">",
            "</" + maintainableTagName + ">");
    Object businessObject = KRADServiceLocator.getXmlObjectSerializerService().fromXml(maintXml);
    return businessObject;
}

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

/**
 * Add hidden search criteria components.
 *
 * @param lookupCriteriaFields// ww  w .ja  va2 s  . c  om
 */
protected void addHiddenComponentPostMetadata(Map<String, Map<String, Object>> lookupCriteriaFields) {
    for (String hiddenPropertyName : this.getAdditionalHiddenPropertyNames()) {
        hiddenPropertyName = StringUtils.substringBetween(hiddenPropertyName,
                UifPropertyPaths.LOOKUP_CRITERIA + "[", "]");

        // Prevent overwriting of visible components. Note, hidden components are allowed to be overwritten.
        if (!lookupCriteriaFields.containsKey(hiddenPropertyName)) {
            Map<String, Object> criteriaAttributes = new HashMap<String, Object>();
            criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.HIDDEN, true);
            lookupCriteriaFields.put(hiddenPropertyName, criteriaAttributes);
        }
    }
}

From source file:org.kuali.rice.krad.maintenance.MaintenanceDocumentBase.java

/**
 * Get notes from XML// w  ww  .j  av a 2 s  . com
 *
 * @param notesTagName the xml tag name of the notes
 * @return list of <code>Note</code>s
 */
private List<Note> getNotesFromXml(String notesTagName) {
    String notesXml = StringUtils.substringBetween(xmlDocumentContents, "<" + notesTagName + ">",
            "</" + notesTagName + ">");
    if (StringUtils.isBlank(notesXml)) {
        return Collections.emptyList();
    }
    List<Note> notes = (List<Note>) KRADServiceLocator.getXmlObjectSerializerService().fromXml(notesXml);
    if (notes == null) {
        return Collections.emptyList();
    }
    return notes;
}

From source file:org.kuali.rice.krad.maintenance.MaintenanceDocumentBase.java

/**
 * Get data object from XML//from  w w w.ja v a  2  s . c  o m
 *
 * <p>
 * Retrieves substring of document contents from maintainable tag name. Then use xml service to translate xml into
 * a business object.
 * </p>
 *
 * @param maintainableTagName the xml tag name of the maintainable
 * @return data object
 */
protected Object getDataObjectFromXML(String maintainableTagName) {
    String maintXml = StringUtils.substringBetween(xmlDocumentContents, "<" + maintainableTagName + ">",
            "</" + maintainableTagName + ">");

    boolean ignoreMissingFields = false;
    String classAndDocTypeNames = ConfigContext.getCurrentContextConfig()
            .getProperty(KRADConstants.Config.IGNORE_MISSIONG_FIELDS_ON_DESERIALIZE);
    if (!StringUtils.isEmpty(classAndDocTypeNames)) {
        String classNameOnXML = StringUtils.substringBetween(xmlDocumentContents,
                "<" + maintainableTagName + "><", ">");
        String classNamesNoSpaces = removeSpacesAround(classAndDocTypeNames);
        List<String> classAndDocTypeNamesList = Arrays
                .asList(org.apache.commons.lang.StringUtils.split(classNamesNoSpaces, ","));
        String originalDocTypeId = getDocumentHeader().getWorkflowDocument().getDocumentTypeId();
        DocumentType docType = KewApiServiceLocator.getDocumentTypeService()
                .getDocumentTypeById(originalDocTypeId);

        while (docType != null && !ignoreMissingFields) {
            for (String classNameOrDocTypeName : classAndDocTypeNamesList) {
                if (docType.getName().equalsIgnoreCase(classNameOrDocTypeName)
                        || classNameOnXML.equalsIgnoreCase(classNameOrDocTypeName)) {
                    ignoreMissingFields = true;
                    break;
                }
            }
            if (!StringUtils.isEmpty(docType.getParentId())) {
                docType = KewApiServiceLocator.getDocumentTypeService()
                        .getDocumentTypeById(docType.getParentId());
            } else {
                docType = null;
            }
        }
    }
    if (!ignoreMissingFields) {
        return KRADServiceLocator.getXmlObjectSerializerService().fromXml(maintXml);
    } else {
        return KRADServiceLocator.getXmlObjectSerializerIgnoreMissingFieldsService().fromXml(maintXml);
    }
}

From source file:org.kuali.rice.krad.messages.providers.ResourceMessageProvider.java

/**
 * Removes any component declaration within the given resource key
 *
 * @param resourceKey resource key to clean
 * @return String cleaned resource key/*w  w  w  . ja  va 2s.com*/
 */
protected String cleanResourceKey(String resourceKey) {
    String cleanedKey = resourceKey;

    String component = StringUtils.substringBetween(cleanedKey, COMPONENT_PLACEHOLDER_BEGIN,
            COMPONENT_PLACEHOLDER_END);
    if (StringUtils.isNotBlank(component)) {
        cleanedKey = StringUtils.remove(cleanedKey,
                COMPONENT_PLACEHOLDER_BEGIN + component + COMPONENT_PLACEHOLDER_END);
    }

    return cleanedKey;
}

From source file:org.kuali.rice.krad.theme.ThemeBuilderOverlays.java

/**
 * Helper method that parses the configuration string for additional overlays into a Map where
 * the key is the source path and the map value is the target path
 *
 * <p>//ww  w.  j a va 2  s .com
 * Each mapping in the string should be separated by a comma. Within the mapping, the source path should
 * be given, followed by the target path in parenthesis
 *
 * ex. sourcePath(targetPath),sourcePath2(targetPath2)
 * </p>
 *
 * @param additionalOverlaysStr string to parse into additional overlay mappings
 * @return map of additional overlay mappings
 */
protected static Map<String, String> parseAdditionalOverlaysStr(String additionalOverlaysStr) {
    Map<String, String> additionalOverlays = new HashMap<String, String>();

    if (StringUtils.isBlank(additionalOverlaysStr)) {
        return additionalOverlays;
    }

    String[] additionalOverlaysArray = additionalOverlaysStr.split(",");
    for (String additionalOverlay : additionalOverlaysArray) {
        String fromDir = "";
        String toDir = "";

        if (additionalOverlay.contains("(") && additionalOverlay.contains(")")) {
            fromDir = StringUtils.substringBefore(additionalOverlay, "(");
            toDir = StringUtils.substringBetween(additionalOverlay, "(", ")");
        } else {
            fromDir = additionalOverlay;
        }

        additionalOverlays.put(StringUtils.trimToEmpty(fromDir), StringUtils.trimToEmpty(toDir));
    }

    return additionalOverlays;
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#containsElPlaceholder(java.lang.String)
 *//*  w  w w  . ja  va  2  s.c  o  m*/
public boolean containsElPlaceholder(String value) {
    boolean containsElPlaceholder = false;

    if (StringUtils.isNotBlank(value)) {
        String elPlaceholder = StringUtils.substringBetween(value, UifConstants.EL_PLACEHOLDER_PREFIX,
                UifConstants.EL_PLACEHOLDER_SUFFIX);
        if (StringUtils.isNotBlank(elPlaceholder)) {
            containsElPlaceholder = true;
        }
    }

    return containsElPlaceholder;
}

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

/**
 * {@inheritDoc}/*  w ww.j  a v  a2s .c  om*/
 */
@Override
public boolean containsElPlaceholder(String value) {
    boolean containsElPlaceholder = false;

    if (StringUtils.isNotBlank(value)) {
        String elPlaceholder = StringUtils.substringBetween(value, UifConstants.EL_PLACEHOLDER_PREFIX,
                UifConstants.EL_PLACEHOLDER_SUFFIX);
        if (StringUtils.isNotBlank(elPlaceholder)) {
            containsElPlaceholder = true;
        }
    }

    return containsElPlaceholder;
}

From source file:org.kuali.student.common.uif.util.KSUifUtils.java

/**
 * Checks whether the given property value is of String type, and if so whether it contains the expression
 * placholder(s)/*from w w  w.  ja  v a 2  s .c  om*/
 *
 * @param propertyValue - value to check for expressions
 * @return boolean true if the property value contains expression(s), false if it does not
 */
public static boolean hasExpression(Object propertyValue) {
    if (propertyValue != null) {
        // if value is string, check for el expression
        String strValue = getStringValue(propertyValue);
        if (strValue != null) {
            String elPlaceholder = StringUtils.substringBetween(strValue, UifConstants.EL_PLACEHOLDER_PREFIX,
                    UifConstants.EL_PLACEHOLDER_SUFFIX);
            if (StringUtils.isNotBlank(elPlaceholder)) {
                return true;
            }
        }
    }

    return false;
}