You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/11/18 16:30:28 UTC
[sling-whiteboard] branch master updated: Switch to ContentMapper
implementation
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new 84df318 Switch to ContentMapper implementation
84df318 is described below
commit 84df3183b4151d210519d031190b7e13fc5dad3c
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Nov 18 17:20:28 2020 +0100
Switch to ContentMapper implementation
---
.../apache/sling/jsonifier/api/JsonRenderer.java | 45 ------
.../sling/jsonifier/api/JsonRendererSelector.java | 29 ----
.../sling/jsonifier/impl/DefaultJsonRenderer.java | 47 ------
.../jsonifier/impl/JsonRendererSelectorImpl.java | 37 -----
.../sling/jsonifier/servlet/RendererServlet.java | 70 ---------
.../DefaultContentAggregatorServlet.java | 88 -----------
.../aggregator/NoContentAggregatorServlet.java | 57 --------
.../aggregator/ResourceAggregator.java | 138 ------------------
.../sling/remotecontentapi/rcaservlet/P.java | 91 ------------
.../rcaservlet/PipelineContext.java | 92 ------------
.../remotecontentapi/take5/ResourceProcessor.java | 30 ----
.../remotecontentapi/take5/ResourceRules.java | 65 ---------
.../sling/remotecontentapi/take5/RulesList.java | 162 ---------------------
.../sling/remotecontentapi/take5/Take5Servlet.java | 89 -----------
.../sling/remotecontentapi/take5/UrlBuilder.java | 49 -------
.../sling/remotecontentapi/xyz/ProcessingRule.java | 28 ----
.../xyz/ProcessingRuleSelector.java | 117 ---------------
.../sling/remotecontentapi/xyz/UrlBuilder.java | 49 -------
.../sling/remotecontentapi/xyz/XyzContext.java | 87 -----------
.../sling/remotecontentapi/xyz/XyzServlet.java | 74 ----------
.../resources/SLING-INF/initial-content/ROOT.json | 2 +-
21 files changed, 1 insertion(+), 1445 deletions(-)
diff --git a/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRenderer.java b/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRenderer.java
deleted file mode 100644
index 10b8cf3..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRenderer.java
+++ /dev/null
@@ -1,45 +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.jsonifier.api;
-
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.Resource;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public interface JsonRenderer {
- enum Mode {
- CONTENT,
- NAVIGATION
- };
-
- String SP_RESOURCE_TYPES = "sling.json.resourceTypes";
- String SP_SELECTORS = "sling.json.selectors";
-
- /** Render supplied Resource to JSON according to supplied selectors
- * TODO the target should be a MapOfMaps that can be used for both
- * JSON serialization and as part of a GraphQL query response
- */
- void render(@NotNull JsonObjectBuilder target, @NotNull Resource r, Mode mode, @Nullable String [] selectors);
-
- /** Decide whether to recurse into supplied child resource */
- boolean recurseInto(Resource child, Mode mode);
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRendererSelector.java b/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRendererSelector.java
deleted file mode 100644
index 7921e14..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/jsonifier/api/JsonRendererSelector.java
+++ /dev/null
@@ -1,29 +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.jsonifier.api;
-
-import org.apache.sling.api.resource.Resource;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public interface JsonRendererSelector {
- /** @return a renderer for the supplied Resource */
- @NotNull JsonRenderer select(@NotNull Resource r, @Nullable String [] selectors);
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/DefaultJsonRenderer.java b/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/DefaultJsonRenderer.java
deleted file mode 100644
index a076c51..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/DefaultJsonRenderer.java
+++ /dev/null
@@ -1,47 +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.jsonifier.impl;
-
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.jsonifier.api.JsonRenderer;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.service.component.annotations.Component;
-
-@Component(
- service = JsonRenderer.class,
- property = {
- JsonRenderer.SP_RESOURCE_TYPES + "=" + JsonRendererSelectorImpl.DEFAULT_RESOURCE_TYPE,
- })
-class DefaultJsonRenderer implements JsonRenderer {
-
- @Override
- public void render(@NotNull JsonObjectBuilder target, @NotNull Resource r, Mode mode,
- @Nullable String[] selectors) {
- target.add("source", getClass().getName());
- }
-
- @Override
- public boolean recurseInto(Resource child, Mode mode) {
- return true;
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/JsonRendererSelectorImpl.java b/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/JsonRendererSelectorImpl.java
deleted file mode 100644
index e181726..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/jsonifier/impl/JsonRendererSelectorImpl.java
+++ /dev/null
@@ -1,37 +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.jsonifier.impl;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.jsonifier.api.JsonRendererSelector;
-import org.apache.sling.jsonifier.api.JsonRenderer;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.service.component.annotations.Component;
-
-@Component(service = JsonRendererSelector.class)
-public class JsonRendererSelectorImpl implements JsonRendererSelector {
- public static final String DEFAULT_RESOURCE_TYPE = "sling/servlet/default";
-
- /** @return a ResourceJsonifier for the supplied Resource */
- public @NotNull JsonRenderer select(@NotNull Resource r, @Nullable String [] selectors) {
- return new DefaultJsonRenderer();
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/jsonifier/servlet/RendererServlet.java b/remote-content-api/src/main/java/org/apache/sling/jsonifier/servlet/RendererServlet.java
deleted file mode 100644
index 6257e5c..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/jsonifier/servlet/RendererServlet.java
+++ /dev/null
@@ -1,70 +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.jsonifier.servlet;
-
-import java.io.IOException;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-import javax.servlet.Servlet;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.apache.sling.jsonifier.api.JsonRendererSelector;
-import org.apache.sling.jsonifier.api.JsonRenderer;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-/** Render the current Resource to JSON */
-@Component(service = Servlet.class,
- property = {
- "sling.servlet.resourceTypes=sling/servlet/default",
- "sling.servlet.prefix:Integer=-1",
-
- "sling.servlet.methods=GET",
- "sling.servlet.methods=HEAD",
- "sling.servlet.selectors=s:jr",
- "sling.servlet.extension=json",
- })
-public class RendererServlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = 1L;
-
- @Reference
- private transient JsonRendererSelector renderers;
-
- @Override
- public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
- final JsonObjectBuilder result = Json.createObjectBuilder();
-
- final Resource resource = request.getResource();
- final String [] selectors = request.getRequestPathInfo().getSelectors();
-
- final JsonRenderer renderer = renderers.select(
- request.getResource(),
- request.getRequestPathInfo().getSelectors());
- renderer.render(result, resource, JsonRenderer.Mode.CONTENT, selectors);
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
- response.getWriter().write(result.build().toString());
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/DefaultContentAggregatorServlet.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/DefaultContentAggregatorServlet.java
deleted file mode 100644
index 3923dad..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/DefaultContentAggregatorServlet.java
+++ /dev/null
@@ -1,88 +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.remotecontentapi.aggregator;
-
-import java.io.IOException;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-import javax.servlet.Servlet;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.apache.sling.remotecontentapi.rcaservlet.PipelineContext;
-import org.osgi.service.component.annotations.Component;
-
-/** This is a first shot at this remote content API, that
- * works well with the (simplistic) test content
- * found under /content/articles
- */
-@Component(service = Servlet.class,
- property = {
- "service.description=Apache Sling Content Aggregator Servlet",
- "service.vendor=The Apache Software Foundation",
-
- "sling.servlet.resourceTypes=sling/servlet/default",
- "sling.servlet.prefix:Integer=-1",
-
- "sling.servlet.methods=GET",
- "sling.servlet.methods=HEAD",
- "sling.servlet.selectors=s:cagg",
- "sling.servlet.extension=json",
- })
-public class DefaultContentAggregatorServlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = 1L;
-
- static class ConverterContext implements ResourceAggregator.Context {
- private final PipelineContext pc;
-
- ConverterContext(PipelineContext pc) {
- this.pc = pc;
- }
-
- @Override
- public String getUrlForPath(String path, boolean includeApiSelectorsAndExtension) {
- if(includeApiSelectorsAndExtension) {
- return pc.pathToUrl(path);
- } else {
- return pc.pathToUrlNoJsonExtension(path);
- }
- }
-
- @Override
- public String getRelativePath(Resource r) {
- return r.getPath().substring(pc.resource.getPath().length());
- }
- }
-
- @Override
- public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
- final JsonObjectBuilder json = Json.createObjectBuilder();
- new ResourceAggregator(
- request.getResource(),
- new ConverterContext(new PipelineContext(request))
- ).addTo(json);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
- response.getWriter().write(json.build().toString());
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/NoContentAggregatorServlet.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/NoContentAggregatorServlet.java
deleted file mode 100644
index 067732e..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/NoContentAggregatorServlet.java
+++ /dev/null
@@ -1,57 +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.remotecontentapi.aggregator;
-
-import java.io.IOException;
-
-import javax.servlet.Servlet;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.osgi.service.component.annotations.Component;
-
-/** Servlet that output no content, for resource types like
- * folders who do not have their own content.
- * (TODO: those can have titles and descriptions, should output that)
- */
-@Component(service = Servlet.class,
- property = {
- "service.description=Apache Sling Content Aggregator Servlet",
- "service.vendor=The Apache Software Foundation",
-
- "sling.servlet.resourceTypes=sling/Folder",
- "sling.servlet.resourceTypes=sling/OrderedFolder",
- "sling.servlet.prefix:Integer=-1",
-
- "sling.servlet.methods=GET",
- "sling.servlet.methods=HEAD",
- "sling.servlet.selectors=s:cagg",
- "sling.servlet.extension=json",
- })
-public class NoContentAggregatorServlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
- response.setStatus(HttpServletResponse.SC_OK);
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/ResourceAggregator.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/ResourceAggregator.java
deleted file mode 100644
index c7f7056..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/aggregator/ResourceAggregator.java
+++ /dev/null
@@ -1,138 +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.remotecontentapi.aggregator;
-
-import java.util.Map;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.remotecontentapi.rcaservlet.P;
-
-public class ResourceAggregator {
- public static final String SLING_RESOURCE_TYPE = "sling:resourceType";
-
- public static interface Context {
- /** Return the full URL to access the given path */
- String getUrlForPath(String path, boolean includeApiSelectorsAndExtension);
-
- /** Return r's path relative to the Resource being rendered */
- String getRelativePath(Resource r);
- }
-
- private final Context context;
- private final Resource resource;
-
- private void addProperties(JsonObjectBuilder json, Resource r, ValueMap vm) {
- if(vm != null) {
- // Add an _id to all components which have a resource type
- if(vm.containsKey(SLING_RESOURCE_TYPE)) {
- json.add("_id", r.getPath());
- }
-
- for(Map.Entry<String, Object> entry : vm.entrySet()) {
- processProperty(json, entry.getKey(), entry.getValue());
- }
- }
- }
-
- private void addChild(JsonObjectBuilder parent, JsonObjectBuilder childJson, Resource r, ValueMap vm) {
- if(context.getRelativePath(r).isEmpty()) {
- // at content root, do not add intermediate element
- parent.addAll(childJson);
- } else {
- if("jcr:content".equals(r.getName())) {
- parent.add("_composite", childJson);
- } else {
- parent.add(r.getName(), childJson);
- }
- }
- }
-
- /** True if r is a "document" like a website
- * page, that shouldn't be recursed into when
- * visiting content.
- */
- private static boolean isDocument(Resource r) {
- // TODO shouldn't be hardcoded, of course...but we'll need
- // to differentiate between our first-class content objects
- // and their content.
- return isNodeType(r.adaptTo(ValueMap.class), "cq:Page");
- }
-
- private void addTo(JsonObjectBuilder parentJson, Resource r) {
- final ValueMap vm = r.adaptTo(ValueMap.class);
-
- if(isNodeType(vm, "nt:file")) {
- // nt:file nodes: emit just a link
- parentJson.add("file", Json.createObjectBuilder()
- .add("url", context.getUrlForPath(r.getPath(), false))
- );
- } else {
- // general node: add a child JSON node with its name, properties and non-document child nodes
- final JsonObjectBuilder childJson = Json.createObjectBuilder();
- addProperties(childJson, r, vm);
- for(Resource child : r.getChildren()) {
- if(!isDocument(child)) {
- addTo(childJson, child);
- }
- }
- addChild(parentJson, childJson, r, vm);
- }
- }
-
- private static boolean isNodeType(ValueMap vm, String nodeType) {
- return vm == null ? false : nodeType.equals(vm.get("jcr:primaryType", String.class));
- }
-
- private void processProperty(JsonObjectBuilder json, String key, Object value) {
- if(value != null) {
- final String newName = processPropertyName(key);
- if(newName != null) {
- P.addValue(json, newName, value);
- }
- }
- }
-
- private String processPropertyName(String propertyName) {
- if(!propertyName.contains(":")) {
- return propertyName;
- } else if(propertyName.equals("jcr:title")) {
- return "_title";
- } else if(propertyName.equals("jcr:description")) {
- return "_description";
- } else if(propertyName.equals(SLING_RESOURCE_TYPE)) {
- return "_componentType";
- } else {
- return null;
- }
- }
-
- public ResourceAggregator(Resource r, Context ctx) {
- context = ctx;
- resource = r;
- }
-
- public void addTo(JsonObjectBuilder content) {
- addTo(content, resource);
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/P.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/P.java
deleted file mode 100644
index 13a25d4..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/P.java
+++ /dev/null
@@ -1,91 +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.remotecontentapi.rcaservlet;
-
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.ValueMap;
-
-public class P {
- public static final String [] IGNORE_RESOURCE_PREIX = { "jcr:", "rep:", "oak:" };
- public static final String [] TITLE_PROPS = { "jcr:title", "title" };
- public static final String [] NAME_PROPS = { "jcr:name", "name" };
- public static final String [] TEXT_PROPS = { "jcr:text", "text" };
- public static final String [] DESCRIPTION_PROPS = { "jcr:description", "description" };
-
- public static boolean maybeAdd(JsonObjectBuilder b, String propName, String jsonName, ValueMap vm) {
- if(vm.containsKey(propName)) {
- final Object value = vm.get(propName);
- if(value != null) {
- addValue(b, jsonName, value);
- }
- return true;
- }
- return false;
- }
-
- public static void addValue(JsonObjectBuilder json, String key, Object value) {
- if(value instanceof Object[]) {
- final JsonArrayBuilder a = Json.createArrayBuilder();
- for(Object o : (Object[])value) {
- a.add(o.toString());
- }
- json.add(key, a.build());
- } else {
- json.add(key, value.toString());
- }
- }
-
- public static void maybeAddOneOf(JsonObjectBuilder b, String propName, ValueMap vm, String [] props) {
- for(String prop : props) {
- if(maybeAdd(b, prop, propName, vm)) {
- break;
- }
- }
- }
-
- public static boolean ignoreProperty(String key) {
- return key.startsWith("jcr:");
- }
-
- public static boolean ignoreResource(String name) {
- for(String prefix : IGNORE_RESOURCE_PREIX) {
- if(name.startsWith(prefix)) {
- return true;
- }
- }
- return false;
- }
-
- public static String convertName(String in) {
- if("sling:resourceType".equals(in)) {
- return "_componentType";
- } else if("sling:resourceSuperType".equals(in)) {
- return "_componentSuperType";
- }
- return in.replace("sling:", "_");
- }
-
- public static boolean isMetadata(String propName) {
- return propName.startsWith("sling:");
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/PipelineContext.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/PipelineContext.java
deleted file mode 100644
index 89269d2..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/rcaservlet/PipelineContext.java
+++ /dev/null
@@ -1,92 +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.remotecontentapi.rcaservlet;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.resource.Resource;
-
-public class PipelineContext {
- private final SlingHttpServletRequest request;
- public final Resource resource;
- public final JsonObjectBuilder navigation;
- public final JsonObjectBuilder metadata;
- public final JsonObjectBuilder children;
- private JsonObject content;
-
- public PipelineContext(SlingHttpServletRequest request) {
- this.request = request;
- resource = request.getResource();
-
- navigation = Json.createObjectBuilder();
- metadata = Json.createObjectBuilder();
- children = Json.createObjectBuilder();
-
- navigation.add("self", pathToUrl(resource.getPath()));
- if(resource.getParent() != null) {
- navigation.add("parent", pathToUrl(resource.getParent().getPath()));
- }
- metadata.add("_id", resource.getPath());
- }
-
- private void maybeAdd(JsonObjectBuilder target, String key, JsonObjectBuilder src) {
- final JsonObject jo = src.build();
- if(!jo.isEmpty()) {
- target.add(key, jo);
- }
- }
-
- public void setContent(JsonObject content) {
- this.content = content;
- }
-
- JsonObject build() {
- final JsonObjectBuilder b = Json.createObjectBuilder();
- maybeAdd(b, "navigation", navigation);
- maybeAdd(b, "metadata", metadata);
- maybeAdd(b, "children", children);
- if(content != null && !content.isEmpty()) {
- b.add("content", content);
- }
- return b.build();
- }
-
- public String pathToUrlNoJsonExtension(String path) {
- return String.format(
- "%s://%s:%d%s",
- request.getScheme(),
- request.getServerName(),
- request.getServerPort(),
- path
- );
- }
-
- public String pathToUrl(String path) {
- return String.format(
- "%s.%s.%s",
- pathToUrlNoJsonExtension(path),
- request.getRequestPathInfo().getSelectorString(),
- request.getRequestPathInfo().getExtension()
- );
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceProcessor.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceProcessor.java
deleted file mode 100644
index 6de8c6e..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceProcessor.java
+++ /dev/null
@@ -1,30 +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.remotecontentapi.take5;
-
-import java.io.IOException;
-
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.Resource;
-
-interface ResourceProcessor {
- void process(Resource r, JsonObjectBuilder b, UrlBuilder urlb) throws IOException;
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceRules.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceRules.java
deleted file mode 100644
index 2669499..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/ResourceRules.java
+++ /dev/null
@@ -1,65 +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.remotecontentapi.take5;
-
-import java.util.function.Predicate;
-
-import org.apache.sling.api.resource.Resource;
-
-class ResourceRules {
- final Predicate<Resource> matcher;
- final ResourceProcessor navigationProcessor;
- final ResourceProcessor contentProcessor;
-
- private ResourceRules(Predicate<Resource> matcher, ResourceProcessor navigationProcessor, ResourceProcessor contentProcessor) {
- this.matcher = matcher;
- this.navigationProcessor = navigationProcessor;
- this.contentProcessor = contentProcessor;
- }
-
- static class Builder {
- private final Predicate<Resource> matcher;
- private ResourceProcessor navigationProcessor;
- private ResourceProcessor contentProcessor;
-
- Builder(Predicate<Resource> matcher) {
- this.matcher = matcher;
- }
-
- Builder withNavigationProcessor(ResourceProcessor rp) {
- navigationProcessor = rp;
- return this;
- }
-
- Builder withContentProcessor(ResourceProcessor rp) {
- contentProcessor = rp;
- return this;
- }
-
- ResourceRules build() {
- return new ResourceRules(matcher, navigationProcessor, contentProcessor);
- }
-
- }
-
- static Builder builder(Predicate<Resource> matcher) {
- return new Builder(matcher);
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/RulesList.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/RulesList.java
deleted file mode 100644
index a7d20f4..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/RulesList.java
+++ /dev/null
@@ -1,162 +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.remotecontentapi.take5;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ValueMap;
-
-class RulesList {
- private final List<ResourceRules> rules = new ArrayList<>();
-
- static class DefaultProcessor implements ResourceProcessor {
- private final String name;
-
- DefaultProcessor(String name) {
- this.name = name;
- }
-
- @Override
- public void process(Resource r, JsonObjectBuilder b, UrlBuilder urlb) throws IOException {
- b.add(name, r.getPath());
- }
- }
-
- static boolean matchAny(String in, String ... variants) {
- if(in == null) {
- return false;
- }
- for(String variant : variants) {
- if(in.equals(variant)) {
- return true;
- }
- }
- return false;
- }
-
- static class DefaultNavProcessor implements ResourceProcessor {
- @Override
- public void process(Resource r, JsonObjectBuilder b, UrlBuilder urlb) throws IOException {
- b.add("_id", r.getPath());
- b.add("_url", urlb.pathToUrl(r.getPath()));
- if(!r.getResourceType().isEmpty()) {
- b.add("_resourceType", r.getResourceType());
- }
- }
- }
-
- static class WkndImageContentProcessor implements ResourceProcessor {
- @Override
- public void process(Resource r, JsonObjectBuilder b, UrlBuilder urlb) throws IOException {
- final ValueMap vm = r.adaptTo(ValueMap.class);
- if(vm != null) {
- vm.entrySet().stream()
- .filter(entry -> "fileReference".equals(entry.getKey()))
- .forEach(entry -> b.add(entry.getKey(), String.valueOf(entry.getValue())));
- }
- }
- }
-
- static class DefaultContentProcessor implements ResourceProcessor {
- private final RulesList rules;
-
- DefaultContentProcessor(RulesList rules) {
- this.rules = rules;
- }
-
- @Override
- public void process(Resource r, JsonObjectBuilder b, UrlBuilder urlb) throws IOException {
- final ValueMap vm = r.adaptTo(ValueMap.class);
- if(vm != null) {
- vm.entrySet().stream().forEach(entry -> b.add(entry.getKey(), String.valueOf(entry.getValue())));
- }
- for(Resource child : r.getChildren()) {
- final JsonObjectBuilder childJson = Json.createObjectBuilder();
- if(rules.applyRules(child, true, childJson, urlb)) {
- b.add(child.getName(), childJson);
- }
- }
- }
- }
-
- static boolean isNodeType(Resource r, String ... nodeTypes) {
- final ValueMap vm = r.adaptTo(ValueMap.class);
- if(vm != null) {
- return matchAny(vm.get("jcr:primaryType", String.class), nodeTypes);
- }
- return false;
- }
-
- RulesList() {
- rules.add(
- ResourceRules.builder(r -> isNodeType(r, "sling:Folder", "sling:OrderedFolder", "nt:folder"))
- .withNavigationProcessor(new DefaultNavProcessor())
- .withContentProcessor(new DefaultProcessor("FolderContent"))
- .build()
- );
- rules.add(
- ResourceRules.builder(r -> "wknd/components/image".equals(r.getResourceType()))
- .withNavigationProcessor(null)
- .withContentProcessor(new WkndImageContentProcessor())
- .build()
- );
- rules.add(
- ResourceRules.builder(r -> isNodeType(r, "cq:Page"))
- .withNavigationProcessor(new DefaultNavProcessor())
- .withContentProcessor(new DefaultContentProcessor(this))
- .build()
- );
- rules.add(
- ResourceRules.builder(r -> "samples/article".equals(r.getResourceSuperType()))
- .withNavigationProcessor(new DefaultNavProcessor())
- .withContentProcessor(new DefaultContentProcessor(this))
- .build()
- );
- rules.add(
- ResourceRules.builder(r -> true)
- .withContentProcessor(new DefaultContentProcessor(this))
- .build()
- );
- }
-
- boolean applyRules(Resource resource, boolean contentMode, JsonObjectBuilder json, UrlBuilder urlb) throws IOException {
- final Optional<ResourceRules> activeRule = matchingRules(resource)
- .filter(rule -> contentMode ? rule.contentProcessor != null : rule.navigationProcessor != null)
- .findFirst();
- if(activeRule.isPresent()) {
- final ResourceProcessor p = contentMode ? activeRule.get().contentProcessor : activeRule.get().navigationProcessor;
- p.process(resource, json, urlb);
- return true;
- }
- return false;
- }
-
- private Stream<ResourceRules> matchingRules(Resource r) {
- return rules.stream().filter(rule -> rule.matcher.test(r));
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/Take5Servlet.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/Take5Servlet.java
deleted file mode 100644
index b38f0f8..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/Take5Servlet.java
+++ /dev/null
@@ -1,89 +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.remotecontentapi.take5;
-
-import java.io.IOException;
-import java.util.Optional;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-import javax.servlet.Servlet;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.osgi.service.component.annotations.Component;
-
-/** This is "take 5" of this experiment, using a table of
- * content processors driven by Resource matchers
- */
-@Component(service = Servlet.class,
- property = {
- "sling.servlet.resourceTypes=sling/servlet/default",
- "sling.servlet.prefix:Integer=-1",
-
- "sling.servlet.methods=GET",
- "sling.servlet.methods=HEAD",
- "sling.servlet.selectors=s:t5",
- "sling.servlet.extension=json",
- })
-public class Take5Servlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = 1L;
- private final RulesList rules = new RulesList();
-
- @Override
- public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
- final JsonObjectBuilder result = Json.createObjectBuilder();
- final UrlBuilder urlb = new UrlBuilder(request);
- final Resource resource = request.getResource();
-
- // Nav and metadata
- final JsonObjectBuilder navigation = Json.createObjectBuilder();
- navigation.add("self", urlb.pathToUrl(resource.getPath()));
- if(resource.getParent() != null) {
- navigation.add("parent", urlb.pathToUrl(resource.getParent().getPath()));
- }
- result.add("navigation", navigation);
-
- final JsonObjectBuilder metadata = Json.createObjectBuilder();
- metadata.add("_id", resource.getPath());
- result.add("metatada", metadata);
-
- // Apply the first rule that matches and has a non-null processor
- final JsonObjectBuilder content = Json.createObjectBuilder();
- rules.applyRules(resource, true, content, urlb);
- result.add("content", content);
-
- // And recurse into children
- final JsonObjectBuilder children = Json.createObjectBuilder();
- for(Resource child : resource.getChildren()) {
- final JsonObjectBuilder childJson = Json.createObjectBuilder();
- if(rules.applyRules(child, false, childJson, urlb)) {
- children.add(child.getName(), childJson);
- }
- }
- result.add("children", children);
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
- response.getWriter().write(result.build().toString());
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/UrlBuilder.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/UrlBuilder.java
deleted file mode 100644
index 4a3744d..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/take5/UrlBuilder.java
+++ /dev/null
@@ -1,49 +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.remotecontentapi.take5;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-
-class UrlBuilder {
- private SlingHttpServletRequest request;
-
- UrlBuilder(SlingHttpServletRequest request) {
- this.request = request;
- }
-
- public String pathToUrlNoExtension(String path) {
- return String.format(
- "%s://%s:%d%s",
- request.getScheme(),
- request.getServerName(),
- request.getServerPort(),
- path
- );
- }
-
- public String pathToUrl(String path) {
- return String.format(
- "%s.%s.%s",
- pathToUrlNoExtension(path),
- request.getRequestPathInfo().getSelectorString(),
- request.getRequestPathInfo().getExtension()
- );
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRule.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRule.java
deleted file mode 100644
index d18a7d8..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRule.java
+++ /dev/null
@@ -1,28 +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.remotecontentapi.xyz;
-
-import java.io.IOException;
-
-import javax.json.JsonObjectBuilder;
-
-interface ProcessingRule {
- void process(JsonObjectBuilder b, UrlBuilder urlb) throws IOException;
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRuleSelector.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRuleSelector.java
deleted file mode 100644
index 08eda18..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/ProcessingRuleSelector.java
+++ /dev/null
@@ -1,117 +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.remotecontentapi.xyz;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import javax.json.Json;
-import javax.json.JsonObjectBuilder;
-import javax.json.JsonReader;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ValueMap;
-import org.apache.sling.api.servlets.ServletResolver;
-import org.apache.sling.remotecontentapi.rcaservlet.P;
-import org.apache.sling.servlethelpers.internalrequests.ServletInternalRequest;
-
-class ProcessingRuleSelector {
- private final ServletResolver servletResolver;
-
- enum RuleType {
- METADATA, CHILDREN, CONTENT
- };
-
- static class DefaultMetadataRule implements ProcessingRule {
- private final Resource resource;
-
- DefaultMetadataRule(Resource r) {
- resource = r;
- }
-
- @Override
- public void process(JsonObjectBuilder b, UrlBuilder urlb) {
- // nothing to for do for now
- }
- }
-
- static class DefaultChildrenRule implements ProcessingRule {
- private final Resource resource;
-
- DefaultChildrenRule(Resource r) {
- resource = r;
- }
-
- @Override
- public void process(JsonObjectBuilder b, UrlBuilder urlb) {
- for (Resource child : resource.getChildren()) {
- if (P.ignoreResource(child.getName())) {
- continue;
- }
- final JsonObjectBuilder childBuilder = Json.createObjectBuilder();
- final ValueMap vm = child.adaptTo(ValueMap.class);
- if (vm != null) {
- childBuilder.add("_path", child.getPath());
- childBuilder.add("_url", urlb.pathToUrl(child.getPath()));
- P.maybeAdd(childBuilder, "sling:resourceType", "_resourceType", vm);
- P.maybeAddOneOf(childBuilder, "title", vm, P.TITLE_PROPS);
- P.maybeAddOneOf(childBuilder, "name", vm, P.NAME_PROPS);
- }
- b.add(child.getName(), childBuilder.build());
- }
- }
- }
-
- class DefaultContentRule implements ProcessingRule {
- private final Resource resource;
-
- DefaultContentRule(Resource r) {
- resource = r;
- }
-
- @Override
- public void process(JsonObjectBuilder b, UrlBuilder urlb) throws IOException {
- final String jsonResponse = new ServletInternalRequest(servletResolver, resource)
- .withSelectors("s:cagg")
- .execute()
- .getResponseAsString();
-
- if(!jsonResponse.trim().isEmpty()) {
- try (JsonReader parser = Json.createReader(new StringReader(jsonResponse))) {
- b.add("xyz", parser.readObject());
- }
- }
-
- }
- }
-
- ProcessingRuleSelector(ServletResolver sr) {
- servletResolver = sr;
- }
-
- ProcessingRule getRule(RuleType t, Resource r) {
- switch(t) {
- case METADATA : return new DefaultMetadataRule(r);
- case CHILDREN : return new DefaultChildrenRule(r);
- case CONTENT : return new DefaultContentRule(r);
- }
- return null;
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/UrlBuilder.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/UrlBuilder.java
deleted file mode 100644
index 6246729..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/UrlBuilder.java
+++ /dev/null
@@ -1,49 +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.remotecontentapi.xyz;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-
-class UrlBuilder {
- private SlingHttpServletRequest request;
-
- UrlBuilder(SlingHttpServletRequest request) {
- this.request = request;
- }
-
- public String pathToUrlNoExtension(String path) {
- return String.format(
- "%s://%s:%d%s",
- request.getScheme(),
- request.getServerName(),
- request.getServerPort(),
- path
- );
- }
-
- public String pathToUrl(String path) {
- return String.format(
- "%s.%s.%s",
- pathToUrlNoExtension(path),
- request.getRequestPathInfo().getSelectorString(),
- request.getRequestPathInfo().getExtension()
- );
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzContext.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzContext.java
deleted file mode 100644
index cf905e9..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzContext.java
+++ /dev/null
@@ -1,87 +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.remotecontentapi.xyz;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.resource.Resource;
-
-class XyzContext {
- private final SlingHttpServletRequest request;
- public final Resource resource;
- public final JsonObjectBuilder navigation;
- public final JsonObjectBuilder metadata;
- public final JsonObjectBuilder children;
- public final JsonObjectBuilder content;
-
- public XyzContext(SlingHttpServletRequest request) {
- this.request = request;
- resource = request.getResource();
-
- navigation = Json.createObjectBuilder();
- metadata = Json.createObjectBuilder();
- children = Json.createObjectBuilder();
- content = Json.createObjectBuilder();
-
- navigation.add("self", pathToUrl(resource.getPath()));
- if(resource.getParent() != null) {
- navigation.add("parent", pathToUrl(resource.getParent().getPath()));
- }
- metadata.add("_id", resource.getPath());
- }
-
- private void maybeAdd(JsonObjectBuilder target, String key, JsonObjectBuilder src) {
- final JsonObject jo = src.build();
- if(!jo.isEmpty()) {
- target.add(key, jo);
- }
- }
-
- JsonObject build() {
- final JsonObjectBuilder b = Json.createObjectBuilder();
- maybeAdd(b, "navigation", navigation);
- maybeAdd(b, "metadata", metadata);
- maybeAdd(b, "children", children);
- maybeAdd(b, "content", content);
- return b.build();
- }
-
- public String pathToUrlNoJsonExtension(String path) {
- return String.format(
- "%s://%s:%d%s",
- request.getScheme(),
- request.getServerName(),
- request.getServerPort(),
- path
- );
- }
-
- public String pathToUrl(String path) {
- return String.format(
- "%s.%s.%s",
- pathToUrlNoJsonExtension(path),
- request.getRequestPathInfo().getSelectorString(),
- request.getRequestPathInfo().getExtension()
- );
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzServlet.java b/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzServlet.java
deleted file mode 100644
index 9f3ca5d..0000000
--- a/remote-content-api/src/main/java/org/apache/sling/remotecontentapi/xyz/XyzServlet.java
+++ /dev/null
@@ -1,74 +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.remotecontentapi.xyz;
-
-import java.io.IOException;
-
-import javax.json.JsonObject;
-import javax.servlet.Servlet;
-
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.servlets.ServletResolver;
-import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-/** Experimenting with dynamic generators, which might become
- * script-driven.
- */
-@Component(service = Servlet.class,
- property = {
- "service.description=Sling XYZ Servlet",
- "service.vendor=The Apache Software Foundation",
-
- "sling.servlet.resourceTypes=sling/servlet/default",
- "sling.servlet.prefix:Integer=-1",
-
- "sling.servlet.methods=GET",
- "sling.servlet.methods=HEAD",
- "sling.servlet.selectors=s:xyz",
- "sling.servlet.extension=json",
- })
-public class XyzServlet extends SlingSafeMethodsServlet {
- private static final long serialVersionUID = 1L;
-
- @Reference
- private ServletResolver servletResolver;
-
- @Override
- public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
- final XyzContext context = new XyzContext(request);
-
- final Resource r = request.getResource();
- final UrlBuilder urlb = new UrlBuilder(request);
- final ProcessingRuleSelector s = new ProcessingRuleSelector(servletResolver);
- s.getRule(ProcessingRuleSelector.RuleType.METADATA, r).process(context.metadata, urlb);
- s.getRule(ProcessingRuleSelector.RuleType.CHILDREN, r).process(context.children, urlb);
- s.getRule(ProcessingRuleSelector.RuleType.CONTENT, r).process(context.content, urlb);
-
- final JsonObject json = context.build();
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application/json");
- response.getWriter().write(json.toString());
- }
-}
\ No newline at end of file
diff --git a/remote-content-api/src/main/resources/SLING-INF/initial-content/ROOT.json b/remote-content-api/src/main/resources/SLING-INF/initial-content/ROOT.json
index 52efecc..a9335d0 100644
--- a/remote-content-api/src/main/resources/SLING-INF/initial-content/ROOT.json
+++ b/remote-content-api/src/main/resources/SLING-INF/initial-content/ROOT.json
@@ -1,4 +1,4 @@
{
"sling:resourceType" : "sling:redirect",
- "sling:target" : "/content.s:jr.json"
+ "sling:target" : "/content.s:ts.json"
}
\ No newline at end of file