|
|
|
@ -9,26 +9,30 @@ import java.util.regex.Pattern;
|
|
|
|
|
*/ |
|
|
|
|
public class JsonPathFilterFactory { |
|
|
|
|
|
|
|
|
|
private static final Pattern ROOT_FILTER = Pattern.compile("\\$"); |
|
|
|
|
private static final Pattern PROPERTY_FILTER = Pattern.compile("\\w+"); |
|
|
|
|
private static final Pattern WILDCARD_PROPERTY_FILTER = Pattern.compile("\\*"); |
|
|
|
|
private static final Pattern LIST_FILTER = Pattern.compile("\\[.*?\\]"); |
|
|
|
|
private static final Pattern TRAVERSE_FILTER = Pattern.compile("\\.\\."); |
|
|
|
|
private final static Pattern ROOT_FILTER_PATTERN = Pattern.compile("\\$"); |
|
|
|
|
private final static Pattern PROPERTY_FILTER_PATTERN = Pattern.compile("\\w+"); |
|
|
|
|
private final static Pattern WILDCARD_PROPERTY_FILTER_PATTERN = Pattern.compile("\\*"); |
|
|
|
|
private final static Pattern LIST_FILTER_PATTERN = Pattern.compile("\\[.*?\\]"); |
|
|
|
|
private final static Pattern TRAVERSE_FILTER_PATTERN = Pattern.compile("\\.\\."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static RootFilter ROOT_FILTER = new RootFilter(); |
|
|
|
|
private final static TraverseFilter TRAVERSE_FILTER = new TraverseFilter(); |
|
|
|
|
|
|
|
|
|
public static JsonPathFilterBase createFilter(String pathFragment){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ROOT_FILTER.matcher(pathFragment).matches()){ |
|
|
|
|
return new RootFilter(); |
|
|
|
|
if(ROOT_FILTER_PATTERN.matcher(pathFragment).matches()){ |
|
|
|
|
return ROOT_FILTER; |
|
|
|
|
} |
|
|
|
|
else if(PROPERTY_FILTER.matcher(pathFragment).matches() || WILDCARD_PROPERTY_FILTER.matcher(pathFragment).matches() ){ |
|
|
|
|
else if(PROPERTY_FILTER_PATTERN.matcher(pathFragment).matches() || WILDCARD_PROPERTY_FILTER_PATTERN.matcher(pathFragment).matches() ){ |
|
|
|
|
return new PropertyFilter(pathFragment); |
|
|
|
|
} |
|
|
|
|
else if(LIST_FILTER.matcher(pathFragment).matches()){ |
|
|
|
|
else if(LIST_FILTER_PATTERN.matcher(pathFragment).matches()){ |
|
|
|
|
return new ListFilter(pathFragment); |
|
|
|
|
} |
|
|
|
|
else if(TRAVERSE_FILTER.matcher(pathFragment).matches()){ |
|
|
|
|
return new TraverseFilter(pathFragment); |
|
|
|
|
else if(TRAVERSE_FILTER_PATTERN.matcher(pathFragment).matches()){ |
|
|
|
|
return TRAVERSE_FILTER; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|