Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/fix-bnd-config-merging
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgonzalez authored Dec 13, 2024
2 parents 02ce4da + 8b89efc commit c791475
Show file tree
Hide file tree
Showing 46 changed files with 1,218 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ bundle/mockserver.log
.java-version

# Maven versions plugin
pom.xml.versionsBackup
pom.xml.versionsBackup

# Qlty plugin folder
/.qlty/
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)

## Unreleased ([details][unreleased changes details])

- #3484 - Redirect Manager: A servlet to export redirects to a TXT file to use with pipeline-free redirects
- #3480 - AEM Sites Copy Publish URLs

### Fixed
- #3479 - Fixed Configurations Model for Redirect Manager after change in "redirect" resource as "sling:Folder"

### Fixed

- #3483 - Fixed issue with genericlist/body.jsp importing a class from an impl package.

## 6.9.6 - 2024-11-20

### Fixed

- #3473 - Fix Broken Styling when the notification is active
- #3474 - Fixed reintroduction of dependency to outdated Apache Commons Collections 3

Expand All @@ -34,11 +42,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
## 6.9.0 - 2024-10-29

### Fixed

- #3459 - Top level properties in parameterized include are now respected.
- #3460 - Fixes issue where double parameters were not working for the parameterized include
- #3443 - Content Sync: don't drill down into content tree if recursion is off

### Changed

- #3385 Made nesting parameterized includes inside a multi-field (ignored resource types) possible

## 6.8.0 - 2024-10-17
Expand Down
2 changes: 1 addition & 1 deletion all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons</artifactId>
<version>6.9.7-SNAPSHOT</version>
<version>6.10.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion bundle-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons</artifactId>
<version>6.9.7-SNAPSHOT</version>
<version>6.10.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion bundle-onprem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons</artifactId>
<version>6.9.7-SNAPSHOT</version>
<version>6.10.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>com.adobe.acs</groupId>
<artifactId>acs-aem-commons</artifactId>
<version>6.9.7-SNAPSHOT</version>
<version>6.10.0-SNAPSHOT</version>
</parent>

<!-- ====================================================================== -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*-
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 - 2024 Adobe
* %%
* Licensed 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.
* #L%
*/
package com.adobe.acs.commons.redirects.servlets;

import com.adobe.acs.commons.redirects.filter.RedirectFilter;
import com.adobe.acs.commons.redirects.models.RedirectRule;
import org.apache.http.entity.ContentType;
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;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;

import static com.adobe.acs.commons.redirects.servlets.CreateRedirectConfigurationServlet.REDIRECTS_RESOURCE_PATH;


/**
* Servlet for generating an Apache RewriteMap text file to use with
* he Pipeline-free URL Redirects feature in AEM as a Cloud Service
*
* Usage: http://localhost:4502/conf/my-site/settings/redirects.txt
* To filter by status code: http://localhost:4502/conf/my-site/settings/redirects.301.txt
*
* See https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/content-delivery/pipeline-free-url-redirects
*
*/
@Component(service = Servlet.class, property = {
"sling.servlet.methods=GET",
"sling.servlet.extensions=txt",
"sling.servlet.resourceTypes=" + REDIRECTS_RESOURCE_PATH
})
public class RewriteMapServlet extends SlingSafeMethodsServlet {

private static final long serialVersionUID = -3564475196678277711L;

@Override
@SuppressWarnings("java:S3457")
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
response.setContentType(ContentType.TEXT_PLAIN.getMimeType());

String[] selectors = request.getRequestPathInfo().getSelectors();
int statusCode = 0;
if(selectors != null && selectors.length > 0) {
statusCode = Integer.parseInt(selectors[0]);
}
Collection<RedirectRule> rules = RedirectFilter.getRules(request.getResource());
PrintWriter out = response.getWriter();
out.printf("# %s Redirects\n", statusCode == 0 ? "All" : "" + statusCode);
for (RedirectRule rule : rules) {
if(statusCode != 0 && rule.getStatusCode() != statusCode) {
continue;
}
String note = rule.getNote();
if(note != null && !note.isEmpty()) {
out.printf("# %s\n", note);
}
out.printf("%s %s\n", rule.getSource(), rule.getTarget());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@org.osgi.annotation.versioning.Version("1.1.0")
@org.osgi.annotation.versioning.Version("1.2.0")
package com.adobe.acs.commons.redirects.servlets;
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*-
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 - 2024 Adobe
* %%
* Licensed 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.
* #L%
*/

package com.adobe.acs.commons.wcm.impl;

import org.apache.sling.featureflags.ExecutionContext;
import org.apache.sling.featureflags.Feature;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;


/**
* OSGi Feature flag to enable or disable the copy publish URLs dropdown field in the Sites Editor.
*/
@Component(service = Feature.class)
@Designate(ocd = CopySitesPublishUrlFeature.Config.class)
public class CopySitesPublishUrlFeature implements Feature {
static final String FEATURE_FLAG_PID = "com.adobe.acs.commons.wcm.impl.copysitespublishurlfeature.feature.flag";

private Config config;

@ObjectClassDefinition(
name = "ACS AEM Commons - Copy Sites Publish URL Feature Flag",
description = "ACS Commons feature flag enables or disables the copy publish url dropdown field in the Sites Editor."
)
@interface Config {
@AttributeDefinition(
name = "Enable",
description = "Check to enable the AEM Sites Copy Publish URL feature."
)
boolean feature_flag_active_status() default false;
}

@SuppressWarnings("ClassEscapesDefinedScope")
@Activate
protected final void activate(Config config) {
this.config = config;
}

@Override
public String getName() {
return FEATURE_FLAG_PID;
}

@Override
public String getDescription() {
return "ACS AEM Commons feature flag enables or disables the copy publish URL dropdown field in the Sites Editor.";
}

@Override
public boolean isEnabled(ExecutionContext executionContext) {
return config.feature_flag_active_status();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*-
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2013 - 2024 Adobe
* %%
* Licensed 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.
* #L%
*/

package com.adobe.acs.commons.wcm.impl;

import com.day.cq.commons.Externalizer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

import javax.servlet.Servlet;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
* This servlet generates a JSON response with the externalized URLs for the given path using configured keys in its
* configuration. They keys need to match the environment keys configured in the Externalizer configuration. The servlet
* uses Externalizer service to generate the externalized URLs via Externalizer.externalLink() method. The response is
* in format {"Author": "Author URL", "Publish": "Publish URL", ...}.
*/
@Component(service = Servlet.class, configurationPolicy = ConfigurationPolicy.REQUIRE)
@SlingServletResourceTypes(
resourceTypes = PublishUrlServlet.RESOURCE_TYPE,
methods = HttpConstants.METHOD_GET,
extensions = PublishUrlServlet.JSON_EXTENSION
)
@Designate(ocd = PublishUrlServlet.PublishUrlServletConfig.class)
public class PublishUrlServlet extends SlingSafeMethodsServlet implements Serializable {

private static final long serialVersionUID = 1L;
protected static final String RESOURCE_TYPE = "acs-commons/components/utilities/publish-url";
protected static final String JSON_EXTENSION = "json";
private static final String PATH = "path";
private static final String JSON_TYPE = "application/json";
private String[] externalizerKeys;

@Activate
protected void activate(final PublishUrlServletConfig config) {
this.externalizerKeys = config.externalizerKeys();
}

/**
* Gets the path parameter from the request and generates the externalized URLs for the given path using the
* Externalizer service. Writes the JSON response with the externalized URLs to the response.
*
* @param request SlingHttpServletRequest
* @param response SlingHttpServletResponse
* @throws IOException if response.getWriter() fails
*/
@Override
protected void doGet(SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException {
String path = request.getParameter(PATH);
ResourceResolver resolver = request.getResourceResolver();
Externalizer externalizer = resolver.adaptTo(Externalizer.class);
ObjectMapper mapper = new ObjectMapper();
ObjectNode jsonResponse = mapper.createObjectNode();

if (externalizer != null) {
Arrays.asList(externalizerKeys).forEach(key -> {
String capitalizedKey = StringUtils.capitalize(key);
String externalLink = externalizer.externalLink(resolver, key, request.getScheme(), path);
jsonResponse.put(capitalizedKey, externalLink);
});
}

response.setContentType(JSON_TYPE);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.getWriter().write(jsonResponse.toString());
}

@ObjectClassDefinition(
name = "ACS AEM Commons - Publish URL Servlet",
description = "Servlet that accepts a GET request with a resource path in the path parameter, and returns a JSON object of the externalized URLs for the path."
)
public @interface PublishUrlServletConfig {
@AttributeDefinition(
name = "Externalizer environment keys",
description = "Keys must match the environment keys configured in the AEM Externalizer OSGi configuration.",
type = AttributeType.STRING
)
String[] externalizerKeys() default {};
}
}
Loading

0 comments on commit c791475

Please sign in to comment.