-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Collect config for XContentParser #79814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
elasticsearchmachine
merged 16 commits into
elastic:master
from
nik9000:xcontent_parser_config
Oct 27, 2021
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5522db4
Collect config for XContentParser
nik9000 796bf5e
Merge branch 'master' into xcontent_parser_config
nik9000 4fe5bc9
Merge branch 'master' into xcontent_parser_config
nik9000 53d4c87
Rename
nik9000 cd8e874
Restore field
nik9000 d8d82c4
More cleanup
nik9000 b9201d6
Merge commit '4e09186b3d3a20e97e44713d4200b22bc3cec332' into xcontent…
nik9000 90aae4d
format
nik9000 0b749af
Merge commit '12ad399c488f0cc60e19b5e1b29c6d569cb4351a' into xcontent…
nik9000 857e774
Merge branch 'master' into xcontent_parser_config
nik9000 b48653b
Sneaky
nik9000 ceeed9e
Better?
nik9000 86ccf08
Another
nik9000 37a9181
More
nik9000 2d79c7c
Merge branch 'master' into xcontent_parser_config
nik9000 2c4f5ed
Merge branch 'master' into xcontent_parser_config
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentParserConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.xcontent; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.filter.FilteringParserDelegate; | ||
|
||
import org.elasticsearch.core.RestApiVersion; | ||
import org.elasticsearch.xcontent.support.filtering.FilterPath; | ||
import org.elasticsearch.xcontent.support.filtering.FilterPathBasedFilter; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Configuration for {@link XContentParser}. | ||
*/ | ||
public class XContentParserConfiguration { | ||
public static final XContentParserConfiguration PLAIN = new XContentParserConfiguration( | ||
NamedXContentRegistry.EMPTY, | ||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, | ||
RestApiVersion.current(), | ||
null, | ||
null | ||
); | ||
|
||
final NamedXContentRegistry registry; | ||
final DeprecationHandler deprecationHandler; | ||
final RestApiVersion restApiVersion; | ||
final FilterPath[] includes; | ||
final FilterPath[] excludes; | ||
|
||
private XContentParserConfiguration( | ||
NamedXContentRegistry registry, | ||
DeprecationHandler deprecationHandler, | ||
RestApiVersion restApiVersion, | ||
FilterPath[] includes, | ||
FilterPath[] excludes | ||
) { | ||
this.registry = registry; | ||
this.deprecationHandler = deprecationHandler; | ||
this.restApiVersion = restApiVersion; | ||
this.includes = includes; | ||
this.excludes = excludes; | ||
} | ||
|
||
public XContentParserConfiguration withRegistry(NamedXContentRegistry registry) { | ||
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes); | ||
} | ||
|
||
public NamedXContentRegistry registry() { | ||
return registry; | ||
} | ||
|
||
public XContentParserConfiguration withDeprecationHandler(DeprecationHandler deprecationHandler) { | ||
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes); | ||
} | ||
|
||
public DeprecationHandler deprecationHandler() { | ||
return deprecationHandler; | ||
} | ||
|
||
public XContentParserConfiguration withRestApiVersion(RestApiVersion restApiVersion) { | ||
return new XContentParserConfiguration(registry, deprecationHandler, restApiVersion, includes, excludes); | ||
} | ||
|
||
public RestApiVersion restApiVersion() { | ||
return restApiVersion; | ||
} | ||
|
||
public XContentParserConfiguration withFiltering(Set<String> includes, Set<String> excludes) { | ||
return new XContentParserConfiguration( | ||
registry, | ||
deprecationHandler, | ||
restApiVersion, | ||
FilterPath.compile(includes), | ||
FilterPath.compile(excludes) | ||
); | ||
} | ||
|
||
public JsonParser filter(JsonParser parser) { | ||
JsonParser filtered = parser; | ||
if (excludes != null) { | ||
for (FilterPath e : excludes) { | ||
if (e.hasDoubleWildcard()) { | ||
// Fixed in Jackson 2.13 - https://github.com/FasterXML/jackson-core/issues/700 | ||
throw new UnsupportedOperationException("double wildcards are not supported in filtered excludes"); | ||
} | ||
} | ||
filtered = new FilteringParserDelegate(filtered, new FilterPathBasedFilter(excludes, false), true, true); | ||
} | ||
if (includes != null) { | ||
filtered = new FilteringParserDelegate(filtered, new FilterPathBasedFilter(includes, true), true, true); | ||
} | ||
return filtered; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about DEFAULT? or EMPTY?
PLAIN reminds me of
plaint/text
and I think it would be better away from thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a pretty compelling reason not to call it
PLAIN
. I thinkEMPTY
is pretty good though. It sort of implies at least a chunk of the configuration it encodes.