You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/07/22 09:08:46 UTC
[sling-org-apache-sling-contentparser-api] 09/11: SLING-8570 -
Extract a generic Content Parser API from
org.apache.sling.jcr.contentparser with pluggable implementations
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-contentparser-api.git
commit 9fbd47a5eb3a80ea284112f6a72e961e4dc3ebb1
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Jul 22 09:39:40 2019 +0200
SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations
* completely decoupled the API from implementations - the ContentParser API
doesn't suggest any content types any more
* removed JSON specific parser options from the ParserOptions class
* made the ParserOptions class extendable
* switched exported API packages to version 2.0.0, to eliminate all possible
confusion with the older org.apache.sling.jcr.contentparser API
---
README.md | 3 +-
.../sling/contentparser/api/ContentParser.java | 38 +++++++---------------
.../sling/contentparser/api/JsonParserFeature.java | 36 --------------------
.../sling/contentparser/api/ParserOptions.java | 31 +++---------------
.../sling/contentparser/api/package-info.java | 2 +-
5 files changed, 18 insertions(+), 92 deletions(-)
diff --git a/README.md b/README.md
index ab05675..b8d102b 100644
--- a/README.md
+++ b/README.md
@@ -8,8 +8,7 @@ continuation of the one provided by the [Apache Sling JCR Content Parser](https:
1. the API is now available in the `org.apache.sling.contentparser.api` package;
2. there is no replacement for the `org.apache.sling.jcr.contentparser.ContentParserFactory`; to obtain a `ContentParser`, given that
they are exposed as OSGi services, one has to filter on the `ContentParser.SERVICE_PROPERTY_CONTENT_TYPE` service registration property,
-to select the appropriate file format (see `ContentParser.JSON_CONTENT_TYPE`, `ContentParser.XML_CONTENT_TYPE` and
-`ContentParser.JCR_XML_CONTENT_TYPE`);
+to select the appropriate file format;
3. as a consequence of 2., the `ParserOptions` are now passed directly to the `ContentParser#parse` method.
Implementations of the API are made available from separate bundles:
diff --git a/src/main/java/org/apache/sling/contentparser/api/ContentParser.java b/src/main/java/org/apache/sling/contentparser/api/ContentParser.java
index 1a684ca..2738088 100644
--- a/src/main/java/org/apache/sling/contentparser/api/ContentParser.java
+++ b/src/main/java/org/apache/sling/contentparser/api/ContentParser.java
@@ -31,37 +31,23 @@ import org.osgi.annotation.versioning.ProviderType;
@ProviderType
public interface ContentParser {
- /**
- * JSON content descriptor file.
- *
- * @see <a href="https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html#json-descriptor-files">JCR
- * ContentLoader JSON descriptor files</a>
- */
- String JSON_CONTENT_TYPE = "json";
/**
- * XML content descriptor file.
+ * OSGi service registration property indicating the content type this {@code ContentParser} supports. The simplest way to retrieve a
+ * {@code ContentParser} for a certain content type is to apply a filter on the service reference:
*
- * @see <a href="https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html#xml-descriptor-files">JCR
- * ContentLoader XML descriptor files</a>
- */
- String XML_CONTENT_TYPE = "xml";
-
- /**
- * JCR XML content (FileVault XML),aAlso known as extended document view XML. Extends the regular document view as specified by JCR 2.0
- * with specifics like multi-value and type information.
+ * <pre>
+ * {@literal @}Reference(target = "(" + ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=" + _value_ + ")")
+ * private ContentParser parser;
+ * </pre>
*
- * @see <a href="https://docs.adobe.com/content/docs/en/spec/jcr/2.0/7_Export.html#7.3%20Document%20View">JCR 2.0, 7.3 Document View</a>
- * @see <a href="http://jackrabbit.apache.org/filevault/">Jackrabbit FileVault</a>
- */
- String JCR_XML_CONTENT_TYPE = "jcr.xml";
-
- /**
- * OSGi service registration property indicating the content type this {@code ContentParser} supports.
+ * If multiple services are registered for the same content type, the above code snippet will provide you with the service
+ * implementation with the highest ranking. However, if a certain implementation is needed, an additional filter can be added:
*
- * @see #JSON_CONTENT_TYPE
- * @see #XML_CONTENT_TYPE
- * @see #JCR_XML_CONTENT_TYPE
+ * <pre>
+ * {@literal @}Reference(target = "(&(" + ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=" + _value_ + ")(component.name=" + _class_name_ + "))")
+ * private ContentParser parser;
+ * </pre>
*/
String SERVICE_PROPERTY_CONTENT_TYPE = "org.apache.sling.contentparser.content_type";
diff --git a/src/main/java/org/apache/sling/contentparser/api/JsonParserFeature.java b/src/main/java/org/apache/sling/contentparser/api/JsonParserFeature.java
deleted file mode 100644
index 58c3e2b..0000000
--- a/src/main/java/org/apache/sling/contentparser/api/JsonParserFeature.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.contentparser.api;
-
-/**
- * Feature flags for parsing JSON files.
- */
-public enum JsonParserFeature {
-
- /**
- * Support comments (/* ... */) in JSON files.
- */
- COMMENTS,
-
- /**
- * Support ticks (') additional to double quotes (") as quoting symbol for JSON names and strings.
- */
- QUOTE_TICK
-
-}
diff --git a/src/main/java/org/apache/sling/contentparser/api/ParserOptions.java b/src/main/java/org/apache/sling/contentparser/api/ParserOptions.java
index ebf80f0..c28ffe7 100644
--- a/src/main/java/org/apache/sling/contentparser/api/ParserOptions.java
+++ b/src/main/java/org/apache/sling/contentparser/api/ParserOptions.java
@@ -20,17 +20,17 @@ package org.apache.sling.contentparser.api;
import java.util.Arrays;
import java.util.Collections;
-import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import org.osgi.annotation.versioning.ProviderType;
/**
- * Options for content parsers.
+ * Generic options for content parsers. Parser implementations can extend this class to provide additional options, valid only in the
+ * context of those implementations.
*/
@ProviderType
-public final class ParserOptions {
+public class ParserOptions {
/**
* Default primary type.
@@ -57,18 +57,13 @@ public final class ParserOptions {
"security:principals"
)));
- /**
- * List of JSON parser features activated by default.
- */
- public static final EnumSet<JsonParserFeature> DEFAULT_JSON_PARSER_FEATURES
- = EnumSet.of(JsonParserFeature.COMMENTS);
+
private String defaultPrimaryType = DEFAULT_PRIMARY_TYPE;
private boolean detectCalendarValues;
private Set<String> ignorePropertyNames = Collections.emptySet();
private Set<String> ignoreResourceNames = DEFAULT_IGNORE_RESOURCE_NAMES;
private Set<String> removePropertyNamePrefixes = DEFAULT_REMOVE_PROPERTY_NAME_PREFIXES;
- private EnumSet<JsonParserFeature> jsonParserFeatures = DEFAULT_JSON_PARSER_FEATURES;
/**
* Default "jcr:primaryType" property for resources that have no explicit value for this value.
@@ -148,24 +143,6 @@ public final class ParserOptions {
return removePropertyNamePrefixes;
}
- /**
- * Set set of features the JSON parser should apply when parsing files.
- *
- * @param value JSON parser features
- * @return this
- */
- public ParserOptions jsonParserFeatures(EnumSet<JsonParserFeature> value) {
- this.jsonParserFeatures = value;
- return this;
- }
-
- public ParserOptions jsonParserFeatures(JsonParserFeature... value) {
- this.jsonParserFeatures = EnumSet.copyOf(Arrays.asList(value));
- return this;
- }
- public EnumSet<JsonParserFeature> getJsonParserFeatures() {
- return jsonParserFeatures;
- }
}
diff --git a/src/main/java/org/apache/sling/contentparser/api/package-info.java b/src/main/java/org/apache/sling/contentparser/api/package-info.java
index 8997911..9368f3a 100644
--- a/src/main/java/org/apache/sling/contentparser/api/package-info.java
+++ b/src/main/java/org/apache/sling/contentparser/api/package-info.java
@@ -16,7 +16,7 @@
~ specific language governing permissions and limitations
~ under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-@Version("1.0.0")
+@Version("2.0.0")
package org.apache.sling.contentparser.api;
import org.osgi.annotation.versioning.Version;