(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null); if (this.customEditors != null) { this.customEditors.forEach(target::registerCustomEditor); this.customEditorsForPath.forEach((editorPath, editorHolder) -> { if (nestedProperty != null) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath); if (pos != -1) { String editorNestedProperty = editorPath.substring(0, pos);
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Get the last component of the path. Also works if not nested. * @param pa property accessor to work on * @param nestedPath property path we know is nested * @return last component of the path (the property on the target bean) */ protected String getFinalPath(AbstractNestablePropertyAccessor pa, String nestedPath) { if (pa == this) { return nestedPath; } return nestedPath.substring(PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(nestedPath) + 1); }
/** * Recursively navigate to return a property accessor for the nested property path. * @param propertyPath property path, which may be nested * @return a property accessor for the target bean */ @SuppressWarnings("unchecked") // avoid nested generic protected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath); // Handle nested properties recursively. if (pos > -1) { String nestedProperty = propertyPath.substring(0, pos); String nestedPath = propertyPath.substring(pos + 1); AbstractNestablePropertyAccessor nestedPa = getNestedPropertyAccessor(nestedProperty); return nestedPa.getPropertyAccessorForPropertyPath(nestedPath); } else { return this; } }
/** * <p>Constructor for PropertyPath.</p> * * @param nestedPath a {@link java.lang.String} object. */ public PropertyPath(String nestedPath) { String canonicalPath = PropertyAccessorUtils.canonicalPropertyName(nestedPath); int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(canonicalPath); if (lastIndex < 0) { propertyName = PropertyAccessorUtils.getPropertyName(canonicalPath); key = computeKey(canonicalPath); } else { parent = new PropertyPath(canonicalPath.substring(0, lastIndex)); String lastProperty = canonicalPath.substring(lastIndex+1); propertyName = PropertyAccessorUtils.getPropertyName(lastProperty); key = computeKey(lastProperty); } }
Object convertedValue = resolvedValue; boolean convertible = bw.isWritableProperty(propertyName) && !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName); if (convertible) { convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);
/** * Determine the first nested property separator in the * given property path, ignoring dots in keys (like "map[my.key]"). * @param propertyPath the property path to check * @return the index of the nested property separator, or -1 if none */ public static int getLastNestedPropertySeparatorIndex(String propertyPath) { return getNestedPropertySeparatorIndex(propertyPath, true); }
/** * @param value the original value, must not be {@literal null}.. * @param segment the property segment to look up, must not be {@literal null} or empty. * @return */ private Object lookupValueOn(Object value, String segment) { PersistentProperty<?> property = entities.getPersistentEntity(value.getClass()) // .map(it -> it.getPersistentProperty(PropertyAccessorUtils.getPropertyName(segment))) // .orElseThrow(() -> new NotReadablePropertyException(value.getClass(), segment)); ConfigurablePropertyAccessor accessor = property.usePropertyAccess() // ? PropertyAccessorFactory.forBeanPropertyAccess(value) // : PropertyAccessorFactory.forDirectFieldAccess(value); return accessor.getPropertyValue(segment); } };
/** * Register fields that should <i>not</i> be allowed for binding. Default is none. * Mark fields as disallowed for example to avoid unwanted modifications * by malicious users when binding HTTP request parameters. * <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching * can be implemented by overriding the {@code isAllowed} method. * <p>Alternatively, specify a list of <i>allowed</i> fields. * @param disallowedFields array of field names * @see #setAllowedFields * @see #isAllowed(String) */ public void setDisallowedFields(@Nullable String... disallowedFields) { this.disallowedFields = PropertyAccessorUtils.canonicalPropertyNames(disallowedFields); }
/** * Recursively navigate to return a property accessor for the nested property path. * @param propertyPath property path, which may be nested * @return a property accessor for the target bean */ @SuppressWarnings("unchecked") // avoid nested generic protected AbstractNestablePropertyAccessor getPropertyAccessorForPropertyPath(String propertyPath) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath); // Handle nested properties recursively. if (pos > -1) { String nestedProperty = propertyPath.substring(0, pos); String nestedPath = propertyPath.substring(pos + 1); AbstractNestablePropertyAccessor nestedPa = getNestedPropertyAccessor(nestedProperty); return nestedPa.getPropertyAccessorForPropertyPath(nestedPath); } else { return this; } }
Object convertedValue = resolvedValue; boolean convertible = bw.isWritableProperty(propertyName) && !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName); if (convertible) { convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);
/** * Determine the first nested property separator in the * given property path, ignoring dots in keys (like "map[my.key]"). * @param propertyPath the property path to check * @return the index of the nested property separator, or -1 if none */ public static int getFirstNestedPropertySeparatorIndex(String propertyPath) { return getNestedPropertySeparatorIndex(propertyPath, false); }
/** * Gets indexes that have been modified. * * <p> * Returns a set of indexes which have been modified in the given collection. If the returned set contains * {@link java.lang.Integer#MAX_VALUE} then it means that it should be treated as if all items in the collection * have been modified. * </p> * * @return indexes which have been modified in the given collection */ private Set<Integer> extractModifiedIndicies(DataObjectCollection collectionMetadata, Map<String, Set<String>> decomposedPaths) { String relationshipName = collectionMetadata.getName(); Set<Integer> modifiedIndicies = Sets.newHashSet(); // if it contains *exactly* the collection relationship name, then indicate that all items modified if (decomposedPaths.containsKey(relationshipName)) { modifiedIndicies.add(Integer.valueOf(Integer.MAX_VALUE)); } for (String propertyName : decomposedPaths.keySet()) { if (relationshipName.equals(PropertyAccessorUtils.getPropertyName(relationshipName))) { Integer index = extractIndex(propertyName); if (index != null) { modifiedIndicies.add(index); } } } return modifiedIndicies; }
/** * Register fields that should be allowed for binding. Default is all * fields. Restrict this for example to avoid unwanted modifications * by malicious users when binding HTTP request parameters. * <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching * can be implemented by overriding the {@code isAllowed} method. * <p>Alternatively, specify a list of <i>disallowed</i> fields. * @param allowedFields array of field names * @see #setDisallowedFields * @see #isAllowed(String) */ public void setAllowedFields(@Nullable String... allowedFields) { this.allowedFields = PropertyAccessorUtils.canonicalPropertyNames(allowedFields); }
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null); if (this.customEditors != null) { this.customEditors.forEach(target::registerCustomEditor); this.customEditorsForPath.forEach((editorPath, editorHolder) -> { if (nestedProperty != null) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath); if (pos != -1) { String editorNestedProperty = editorPath.substring(0, pos);
@Override public void setProperty(String path, String value) { int index = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(path); BeanWrapperImpl wrapper = createBeanWrapper(path, index); String key = path.substring(index + 1); wrapper.setPropertyValue(key, value); }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Get the last component of the path. Also works if not nested. * @param pa property accessor to work on * @param nestedPath property path we know is nested * @return last component of the path (the property on the target bean) */ protected String getFinalPath(AbstractNestablePropertyAccessor pa, String nestedPath) { if (pa == this) { return nestedPath; } return nestedPath.substring(PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(nestedPath) + 1); }
Object convertedValue = resolvedValue; boolean convertible = bw.isWritableProperty(propertyName) && !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName); if (convertible) { convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);
/** * Determine the first nested property separator in the * given property path, ignoring dots in keys (like "map[my.key]"). * @param propertyPath the property path to check * @return the index of the nested property separator, or -1 if none */ public static int getLastNestedPropertySeparatorIndex(String propertyPath) { return getNestedPropertySeparatorIndex(propertyPath, true); }