-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bugfix/fix-bnd-config-merging
- Loading branch information
Showing
46 changed files
with
1,218 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
bundle/src/main/java/com/adobe/acs/commons/redirects/servlets/RewriteMapServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
bundle/src/main/java/com/adobe/acs/commons/wcm/impl/CopySitesPublishUrlFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
bundle/src/main/java/com/adobe/acs/commons/wcm/impl/PublishUrlServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | ||
} | ||
} |
Oops, something went wrong.