This is an automated email from the ASF dual-hosted git repository.
henrykuijpers pushed a commit to branch SLING-12352
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
The following commit(s) were added to refs/heads/SLING-12352 by this push:
new 616348c SLING-12352 Delay instantiation of JSON & FileVaultXML
ContentLoader to the moment they are actually used
616348c is described below
commit 616348cf53c66d9f660629b1e4912477a8aeb669
Author: henrykuijpers <[email protected]>
AuthorDate: Wed Jun 12 11:49:52 2024 +0200
SLING-12352 Delay instantiation of JSON & FileVaultXML ContentLoader to the
moment they are actually used
---
.../testing/mock/sling/loader/ContentLoader.java | 29 ++++++++++++++++++----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git
a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
index 7561db5..6a057bb 100644
---
a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
+++
b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
@@ -94,9 +94,15 @@ public final class ContentLoader {
private final BundleContext bundleContext;
private final boolean autoCommit;
private final Set<String> ignoredNames;
+
+ @Nullable
private final ContentParser jsonParser;
+
private final ParserOptions jsonParserOptions;
+
+ @Nullable
private final ContentParser fileVaultXmlParser;
+
private final ParserOptions fileVaultXmlParserOptions;
/**
@@ -145,13 +151,10 @@ public final class ContentLoader {
.detectCalendarValues(true)
.ignorePropertyNames(this.ignoredNames)
.ignoreResourceNames(this.ignoredNames);
- this.jsonParser = new JSONContentParser();
-
this.fileVaultXmlParserOptions = new ParserOptions()
.detectCalendarValues(true)
.ignorePropertyNames(this.ignoredNames)
.ignoreResourceNames(this.ignoredNames);
- this.fileVaultXmlParser = new JCRXMLContentParser();
}
private final Set<String>
getIgnoredNamesForResourceResolverType(ResourceResolverType
resourceResolverType) {
@@ -217,7 +220,7 @@ public final class ContentLoader {
* @return Resource
*/
public @NotNull Resource json(@NotNull InputStream inputStream, @NotNull
String destPath) {
- return mountParsedFile(inputStream, destPath, jsonParser,
jsonParserOptions);
+ return mountParsedFile(inputStream, destPath, getJsonParser(),
jsonParserOptions);
}
/**
@@ -275,7 +278,23 @@ public final class ContentLoader {
* @return Resource
*/
public @NotNull Resource fileVaultXml(@NotNull InputStream inputStream,
@NotNull String destPath) {
- return mountParsedFile(inputStream, destPath, fileVaultXmlParser,
fileVaultXmlParserOptions);
+ return mountParsedFile(inputStream, destPath, getFileVaultXmlParser(),
fileVaultXmlParserOptions);
+ }
+
+ @NotNull
+ private ContentParser getJsonParser() {
+ if (jsonParser == null) {
+ jsonParser = new JSONContentParser();
+ }
+ return jsonParser;
+ }
+
+ @NotNull
+ private ContentParser getFileVaultXmlParser() {
+ if (fileVaultXmlParser == null) {
+ fileVaultXmlParser = new JCRXMLContentParser();
+ }
+ return fileVaultXmlParser;
}
@SuppressWarnings("null")