org.springframework.boot.bind.RelaxedNames Java Examples

The following examples show how to use org.springframework.boot.bind.RelaxedNames. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringBootServiceImpl.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
@Override
public ConfigurationMetadataProperty getPropertyMetadata(String propertyName) {
    if (cpExec == null) {
        init();
    }
    if (cachedProperties != null) {
        // generate and try relaxed variants
        for (String relaxedName : new RelaxedNames(propertyName)) {
            if (cachedProperties.containsKey(relaxedName)) {
                return cachedProperties.get(relaxedName);
            } else {
                // try to interpret array notation (strip '[index]' from pName)
                Matcher mArrNot = PATTERN_ARRAY_NOTATION.matcher(relaxedName);
                if (mArrNot.matches()) {
                    return cachedProperties.get(mArrNot.group(1));
                } else {
                    // try to interpret map notation (see if pName starts with a set of known map props)
                    for (String mapPropertyName : getMapPropertyNames()) {
                        if (relaxedName.startsWith(mapPropertyName)) {
                            return cachedProperties.get(mapPropertyName);
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example #2
Source File: RelaxedNamesBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // 生成属性名称 "user.HOME-PAGE" 的所有松散格式
    RelaxedNames relaxedNames = new RelaxedNames("user.homePage");
    // 输出所有松散格式
    relaxedNames.forEach(System.out::println);
}
 
Example #3
Source File: DataTypeMismatchHighlightingTask.java    From nb-springboot with Apache License 2.0 4 votes vote down vote up
private boolean checkType(String type, String text, ClassLoader cl) throws IllegalArgumentException {
    Class<?> clazz = ClassUtils.resolveClassName(type, cl);
    if (clazz != null) {
        try {
            parser.parseType(text, clazz);
        } catch (Exception e1) {
            if (clazz.isEnum()) {
                // generate and try relaxed variants of value
                for (String relaxedName : new RelaxedNames(text)) {
                    try {
                        parser.parseType(relaxedName, clazz);
                        return true;
                    } catch (Exception e2) {
                        // try another variant
                    }
                    if (canceled) {
                        break;
                    }
                }
                return false;
            } else {
                try {
                    // handle a few specific cases where no direct constructor from string or converter exist
                    switch (type) {
                        case "java.nio.file.Path":
                            Paths.get(text);
                            return true;
                        case "java.util.Locale":
                            LocaleUtils.toLocale(text);
                            return true;
                        case "java.time.Duration":
                            DurationStyle.detectAndParse(text);
                            return true;
                        case "org.springframework.util.unit.DataSize":
                            DataSize.parse(text);
                            return true;
                        case "java.lang.Class":
                            cl.loadClass(text);
                            return true;
                        default:
                            return false;
                    }
                } catch (Exception e3) {
                    return false;
                }
            }
        }
    }
    // unresolvable/unknown class, assume user knows what is doing
    return true;
}