You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2021/10/07 01:49:14 UTC
[sling-org-apache-sling-app-cms] 01/01: Working on integrating
Sling Sitemap
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch sitemap-support
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
commit 9038a353e8485a7d5f691e952972abfe999f61bf
Author: Dan Klco <kl...@adobe.com>
AuthorDate: Wed Oct 6 21:49:01 2021 -0400
Working on integrating Sling Sitemap
---
core/pom.xml | 144 ++++++++++-----------
.../core/insights/impl/PageInsightRequestImpl.java | 5 +-
.../internal/models/PageInsightRequestModel.java | 38 ++++++
.../internal/sitemap/PageTreeSitemapGenerator.java | 66 ++++++++++
.../internal/sitemap/SitemapExternalizerImpl.java | 47 +++++++
feature/pom.xml | 2 +-
feature/src/main/features/cms/cms-repoinit.txt | 6 +
feature/src/main/features/cms/dependencies.json | 10 ++
feature/src/main/features/sitemap.json | 24 ++++
pom.xml | 1 +
.../resources/SLING-INF/nodetypes/nodetypes.cnd | 1 +
11 files changed, 267 insertions(+), 77 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index 2b8ba3c..30f75d6 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -15,7 +15,6 @@
<name>Apache Sling - CMS Core</name>
<description>The core for the Apache Sling Reference CMS Application</description>
-
<build>
<plugins>
<plugin>
@@ -41,15 +40,16 @@
</build>
<dependencies>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-atinject_1.0_spec</artifactId>
- </dependency>
+ <!-- java / osgi -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
@@ -70,141 +70,139 @@
<artifactId>osgi.annotation</artifactId>
</dependency>
<dependency>
- <groupId>javax.jcr</groupId>
- <artifactId>jcr</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.api</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.webconsole</artifactId>
</dependency>
+
+ <!-- commons -->
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.servlets.post</artifactId>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>test</scope>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-text</artifactId>
</dependency>
+
+ <!-- General Apache -->
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.models.api</artifactId>
+ <groupId>org.apache.geronimo.bundles</groupId>
+ <artifactId>jstl</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.jcr.resource</artifactId>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
+ <groupId>org.apache.tika</groupId>
+ <artifactId>tika-core</artifactId>
</dependency>
+
+ <!-- JCR/Jackrabbit/Oak -->
<dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
</dependency>
+
+ <!-- Sling -->
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.rewriter</artifactId>
- </dependency>
- <dependency>
- <artifactId>jstl</artifactId>
- <groupId>org.apache.geronimo.bundles</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.caconfig.api</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>oak-jackrabbit-api</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.cms.api</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.johnzon</artifactId>
</dependency>
<dependency>
- <artifactId>org.apache.sling.engine</artifactId>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.discovery.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.cms.api</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.jsoup</groupId>
- <artifactId>jsoup</artifactId>
+ <artifactId>org.apache.sling.distribution.api</artifactId>
</dependency>
<dependency>
+ <artifactId>org.apache.sling.engine</artifactId>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.i18n</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.webconsole</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-math</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.event.api</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.fileoptim</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.tika</groupId>
- <artifactId>tika-core</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.models.api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.event.api</artifactId>
+ <artifactId>org.apache.sling.rewriter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.scripting.api</artifactId>
+ <artifactId>org.apache.sling.servlets.post</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.fileoptim</artifactId>
+ <artifactId>org.apache.sling.sitemap</artifactId>
+ <version>${org-apache-sling-sitemap-version}</version>
+ <scope>compile</scope>
</dependency>
+
+ <!-- misc -->
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+ <groupId>org.jsoup</groupId>
+ <artifactId>jsoup</artifactId>
</dependency>
<dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>javax.annotation-api</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
</dependency>
+
+ <!-- test -->
<dependency>
- <artifactId>commons-text</artifactId>
- <groupId>org.apache.commons</groupId>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <artifactId>org.apache.sling.distribution.api</artifactId>
- <groupId>org.apache.sling</groupId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.discovery.api</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.jetbrains</groupId>
- <artifactId>annotations</artifactId>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/core/src/main/java/org/apache/sling/cms/core/insights/impl/PageInsightRequestImpl.java b/core/src/main/java/org/apache/sling/cms/core/insights/impl/PageInsightRequestImpl.java
index eadd4cd..5ea83e6 100644
--- a/core/src/main/java/org/apache/sling/cms/core/insights/impl/PageInsightRequestImpl.java
+++ b/core/src/main/java/org/apache/sling/cms/core/insights/impl/PageInsightRequestImpl.java
@@ -63,9 +63,8 @@ public class PageInsightRequestImpl implements PageInsightRequest {
private String getContents(String url) {
log.trace("getLocalPageHTML");
if (!markupCache.containsKey(url)) {
- String requestPath = page.getPath() + ".html";
- log.debug("Loading local page HTML from {}", requestPath);
- HttpServletRequest req = new FakeRequest("GET", requestPath);
+ log.debug("Loading local page HTML from {}", url);
+ HttpServletRequest req = new FakeRequest("GET", url);
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse resp;
try {
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/PageInsightRequestModel.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/PageInsightRequestModel.java
new file mode 100644
index 0000000..7e7f67c
--- /dev/null
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/PageInsightRequestModel.java
@@ -0,0 +1,38 @@
+/*
+ * 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.cms.core.internal.models;
+
+import javax.inject.Inject;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.PageManager;
+import org.apache.sling.cms.core.insights.impl.PageInsightRequestImpl;
+import org.apache.sling.cms.insights.PageInsightRequest;
+import org.apache.sling.engine.SlingRequestProcessor;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.OSGiService;
+import org.apache.sling.models.annotations.injectorspecific.Self;
+
+@Model(adaptables = { Resource.class }, adapters = { PageInsightRequest.class })
+public class PageInsightRequestModel extends PageInsightRequestImpl {
+
+ @Inject
+ public PageInsightRequestModel(@Self Resource resource, @OSGiService SlingRequestProcessor requestProcessor) {
+ super(resource.adaptTo(PageManager.class).getPage(), requestProcessor);
+ }
+
+}
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/PageTreeSitemapGenerator.java b/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/PageTreeSitemapGenerator.java
new file mode 100644
index 0000000..b326ef8
--- /dev/null
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/PageTreeSitemapGenerator.java
@@ -0,0 +1,66 @@
+/*
+ * 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.cms.core.internal.sitemap;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.Page;
+import org.apache.sling.cms.PageManager;
+import org.apache.sling.cms.SiteManager;
+import org.apache.sling.sitemap.SitemapException;
+import org.apache.sling.sitemap.SitemapService;
+import org.apache.sling.sitemap.builder.Sitemap;
+import org.apache.sling.sitemap.spi.generator.ResourceTreeSitemapGenerator;
+import org.apache.sling.sitemap.spi.generator.SitemapGenerator;
+import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service = SitemapGenerator.class)
+public class PageTreeSitemapGenerator extends ResourceTreeSitemapGenerator {
+
+ @Override
+ public Set<String> getNames(@NotNull Resource sitemapRoot) {
+ return Collections.singleton(SitemapService.DEFAULT_SITEMAP_NAME);
+ }
+
+ @Override
+ public Set<String> getOnDemandNames(Resource sitemapRoot) {
+ return Collections.singleton(SitemapService.DEFAULT_SITEMAP_NAME);
+ }
+
+ @Override
+ protected void addResource(@NotNull String name, @NotNull Sitemap sitemap, @NotNull Resource resource)
+ throws SitemapException {
+ String site = resource.adaptTo(SiteManager.class).getSite().getUrl();
+ String path = resource.adaptTo(PageManager.class).getPage().getPublishedPath();
+ sitemap.addUrl(site + path);
+ }
+
+ @Override
+ protected boolean shouldInclude(@NotNull Resource resource) {
+ if (super.shouldInclude(resource)) {
+ Page page = resource.adaptTo(PageManager.class).getPage();
+ return page.isPublished() && !page.getProperties().get("jcr:content/hideInSitemap", false);
+ }
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/SitemapExternalizerImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/SitemapExternalizerImpl.java
new file mode 100644
index 0000000..926811a
--- /dev/null
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/sitemap/SitemapExternalizerImpl.java
@@ -0,0 +1,47 @@
+
+/*
+ * 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.cms.core.internal.sitemap;
+
+import java.util.Optional;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.cms.Site;
+import org.apache.sling.cms.SiteManager;
+import org.apache.sling.sitemap.spi.common.SitemapLinkExternalizer;
+import org.osgi.service.component.annotations.Component;
+
+/**
+ * Externalizes the URLs using the Sling CMS site url.
+ */
+@Component
+public class SitemapExternalizerImpl implements SitemapLinkExternalizer {
+
+ @Override
+ public String externalize(SlingHttpServletRequest context, String uri) {
+ return context.getResourceResolver().map(context, uri);
+ }
+
+ @Override
+ public String externalize(Resource resource) {
+ return Optional.ofNullable(resource.adaptTo(SiteManager.class)).map(SiteManager::getSite).map(Site::getUrl)
+ .map(url -> url + resource.getResourceResolver().map(resource.getPath())).orElse(null);
+ }
+}
\ No newline at end of file
diff --git a/feature/pom.xml b/feature/pom.xml
index baee578..7651b7d 100644
--- a/feature/pom.xml
+++ b/feature/pom.xml
@@ -156,7 +156,7 @@
<goal>attach-featurearchives</goal>
</goals>
<configuration>
- <replacePropertyVariables>asm-version,org-apache-sling-api-version,org-apache-sling-scripting-jsp-taglib-version,cms-version,composum-nodes-version,groovy-version,guava-version,jackrabbit-version,jackson-version,oak-version,slf4j-version,cocoon-serializers-charsets-version,org.apache.felix.webconsole-version,commons-lang3-version,jstl-version,org-apache-sling-models-api-version,org.apache.sling.scripting.jsp.taglib,geronimo-atinject_1-0_spec-version,commons-io [...]
+ <replacePropertyVariables>asm-version,org-apache-sling-api-version,org-apache-sling-scripting-jsp-taglib-version,org-apache-sling-sitemap-version,cms-version,composum-nodes-version,groovy-version,guava-version,jackrabbit-version,jackson-version,oak-version,slf4j-version,cocoon-serializers-charsets-version,org.apache.felix.webconsole-version,commons-lang3-version,jstl-version,org-apache-sling-models-api-version,org.apache.sling.scripting.jsp.taglib,geronimo-ati [...]
</configuration>
</execution>
</executions>
diff --git a/feature/src/main/features/cms/cms-repoinit.txt b/feature/src/main/features/cms/cms-repoinit.txt
index 600ab1d..6d7d3f0 100644
--- a/feature/src/main/features/cms/cms-repoinit.txt
+++ b/feature/src/main/features/cms/cms-repoinit.txt
@@ -84,4 +84,10 @@ create service user sling-cms-versionmgr
set ACL for sling-cms-versionmgr
allow jcr:write,jcr:nodeTypeManagement,jcr:versionManagement on /
allow jcr:read on /jcr:system/jcr:versionStorage
+end
+create path (sling:Folder) /var/sitemaps
+create service user sling-cms-sitemapwriter with path system/cms
+set ACL for sling-cms-sitemapwriter
+ allow jcr:read on /content
+ allow jcr:all on /var/sitemaps
end
\ No newline at end of file
diff --git a/feature/src/main/features/cms/dependencies.json b/feature/src/main/features/cms/dependencies.json
index a4ee50a..6058756 100644
--- a/feature/src/main/features/cms/dependencies.json
+++ b/feature/src/main/features/cms/dependencies.json
@@ -107,6 +107,10 @@
{
"id": "org.apache.sling:org.apache.sling.security:1.1.20",
"start-order": "20"
+ },
+ {
+ "id": "org.apache.sling:org.apache.sling.sitemap:${org-apache-sling-sitemap-version}",
+ "start-order": "20"
}
],
"configurations": {
@@ -136,6 +140,12 @@
"org.apache.sling.serviceuser.webconsole"
],
"whitelist.name": "org.apache.sling.serviceuser.webconsole"
+ },
+ "org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~sitemap": {
+ "user.mapping": [
+ "org.apache.sling.sitemap:sitemap-reader=[sling-readall]",
+ "org.apache.sling.sitemap:sitemap-writer=sling-cms-sitemapwriter"
+ ]
}
}
}
diff --git a/feature/src/main/features/sitemap.json b/feature/src/main/features/sitemap.json
new file mode 100644
index 0000000..91bb30c
--- /dev/null
+++ b/feature/src/main/features/sitemap.json
@@ -0,0 +1,24 @@
+{
+ "bundles": [
+ ],
+ "configurations": {
+ "org.apache.sling.sitemap.impl.SitemapServlet": {
+ "sling.servlet.resourceTypes": [
+ "reference/components/pages/base"
+ ],
+ "sling.servlet.selectors": [
+ "sitemap",
+ "sitemap-index"
+ ],
+ "sling.servlet.extensions": [
+ "xml"
+ ]
+ },
+ "org.apache.sling.sitemap.impl.SitemapScheduler~default": {
+ "scheduler.name": "default-sitemap",
+ "scheduler.expression": "0 0 */4 * * ?",
+ "scheduler.runOn": "SINGLE",
+ "scheduler.concurrent": false
+ }
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a649dc8..c1a4448 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,6 +58,7 @@
<org-apache-sling-models-api-version>1.3.8</org-apache-sling-models-api-version>
<org-apache-sling-scripting-api-version>2.2.0</org-apache-sling-scripting-api-version>
<org-apache-sling-scripting-jsp-taglib-version>2.4.0</org-apache-sling-scripting-jsp-taglib-version>
+ <org-apache-sling-sitemap-version>1.0.4</org-apache-sling-sitemap-version>
<org-apache-sling-testing-sling-mock-junit4-version>2.6.2</org-apache-sling-testing-sling-mock-junit4-version>
<org.apache.felix.webconsole-version>4.6.0</org.apache.felix.webconsole-version>
<osgi-annotation-version>8.0.0</osgi-annotation-version>
diff --git a/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd b/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
index 43edb8f..182829a 100644
--- a/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
+++ b/ui/src/main/resources/SLING-INF/nodetypes/nodetypes.cnd
@@ -62,6 +62,7 @@
[sling:Site] > nt:hierarchyNode, mix:lastModified
orderable
- sling:configRef (string)
+ - sling:sitemapRoot (boolean)
- sling:url (string)
- jcr:language (string)
- jcr:title (string)