Skip to content

Commit

Permalink
Merge 15329a7 into fdd9364
Browse files Browse the repository at this point in the history
  • Loading branch information
id-keenan committed May 12, 2021
2 parents fdd9364 + 15329a7 commit ff4cc89
Show file tree
Hide file tree
Showing 24 changed files with 2,252 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)

### Added
- #2536 - Extended renovator MCP Process to handle audit trail entries of moved assets and pages.
- #2512 - Added Contextual Content Variables feature

## 5.0.4 - 2021-03-14

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2021 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.ccvar;

import org.apache.sling.api.SlingHttpServletRequest;

import java.util.Map;

/**
* Extensible interface allowing pluggable content variables to be used in the {@link PropertyAggregatorService} to allow
* for replacement in content responses.
*/
public interface ContentVariableProvider {

/**
* Method to add the properties to the passed map. This will be overridden to run custom logic and add properties to
* the Map.
*
* @param map The current set of properties (may or may not be empty)
* @param request The request used as the context to add properties.
*/
void addProperties(Map<String, Object> map, SlingHttpServletRequest request);

/**
* Determines whether or not the current ContentVariableProvider will accept the request. This can limit what
* providers to use and allow for more contextual content variables in a multi-tenant situation.
*
* @param request The current request
* @return Whether the ContentVariableProvider should add variables to the property map
*/
boolean accepts(SlingHttpServletRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2021 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.ccvar;

import org.apache.sling.api.SlingHttpServletRequest;

import java.util.Map;

/**
* Service used to aggregate property keys and values into a {@link Map}, given the context of a
* {@link SlingHttpServletRequest}, that can be used to replace these tokens in content responses.
*/
public interface PropertyAggregatorService {

/**
* Uses a list of {@link ContentVariableProvider} classes to create a map of properties available for content
* variable replacement to be used in supporting classes.
*
* @param request The currently scoped request
* @return The map of properties
*/
Map<String, Object> getProperties(SlingHttpServletRequest request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2021 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.ccvar;

/**
* Configuration service used to store property exclusions for the {@link PropertyAggregatorService} processes. Contains
* helper methods to determine if a property should be added to the properties aggregated based on the property name or
* type.
*/
public interface PropertyConfigService {

/**
* Checks whether the passed property name should be excluded or not. This check is based on the OSGi
* configuration for the service.
*
* @param propertyName current property name
* @return whether to exclude or not
*/
boolean isAllowed(final String propertyName);

/**
* Checks if the property value is of an allowed type. Currently only supports String and Long values.
*
* @param object current property value
* @return whether it is allowed or not
*/
boolean isAllowedType(Object object);

/**
* Takes the key and determines if there is an action specified in it and checks the action specified against the
* full configured list of actions present in the system.
*
* @param key The key that may contain an action
* @return The configured action or null
*/
TransformAction getAction(String key);

/**
* Returns the configuration value stored that controls whether HTML content is automatically escaped.
*
* @return Configuration value
*/
boolean disableBaseEscaping();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2021 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.ccvar;

/**
* Interface used to implement custom actions that transform values based on the name authored by users. All
* replacements in HTML and JSON are able to use custom actions created based on this interface.
*/
public interface TransformAction {

/**
* Returns the configured name of the action. Used to map to the action present in a placeholder.
*
* @return The name of the action
*/
String getName();

/**
* Used to perform custom actions on the input value before being rendered. This runs on the actual value already
* replaced.
*
* @param value The input value
* @return The transformed value
*/
String execute(String value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* #%L
* ACS AEM Commons Bundle
* %%
* Copyright (C) 2021 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.ccvar.filter;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/**
* Response Wrapper used to allow for full output of the current response data so that it can be manipulated
* and rewritten.
*/
public class CapturingResponseWrapper extends HttpServletResponseWrapper {

private final ByteArrayOutputStream capture;
private ServletOutputStream output;
private PrintWriter writer;

public CapturingResponseWrapper(HttpServletResponse response) {
super(response);
capture = new ByteArrayOutputStream(response.getBufferSize());
}

@Override
public ServletOutputStream getOutputStream() {
if (writer != null) {
throw new IllegalStateException(
"getWriter() has already been called on this response.");
}

if (output == null) {
output = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
capture.write(b);
}

@Override
public void flush() throws IOException {
capture.flush();
}

@Override
public void close() throws IOException {
capture.close();
}

@Override
public boolean isReady() {
return true;
}

@Override
public void setWriteListener(WriteListener writeListener) {
// do nothing
}
};
}

return output;
}

@Override
public PrintWriter getWriter() throws IOException {
if (output != null) {
throw new IllegalStateException(
"getOutputStream() has already been called on this response.");
}

if (writer == null) {
writer = new PrintWriter(new OutputStreamWriter(capture,
getCharacterEncoding()));
}

return writer;
}

public byte[] getCaptureAsBytes() throws IOException {
if (writer != null) {
writer.close();
} else if (output != null) {
output.close();
}

return capture.toByteArray();
}

public String getCaptureAsString() throws IOException {
return new String(getCaptureAsBytes(), getCharacterEncoding());
}
}

0 comments on commit ff4cc89

Please sign in to comment.