-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
2,240 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
bundle/src/main/java/com/adobe/acs/commons/ccvar/ContentVariableProvider.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,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); | ||
} |
40 changes: 40 additions & 0 deletions
40
bundle/src/main/java/com/adobe/acs/commons/ccvar/PropertyAggregatorService.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,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); | ||
} |
61 changes: 61 additions & 0 deletions
61
bundle/src/main/java/com/adobe/acs/commons/ccvar/PropertyConfigService.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,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(); | ||
} |
43 changes: 43 additions & 0 deletions
43
bundle/src/main/java/com/adobe/acs/commons/ccvar/TransformAction.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,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); | ||
} |
114 changes: 114 additions & 0 deletions
114
bundle/src/main/java/com/adobe/acs/commons/ccvar/filter/CapturingResponseWrapper.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,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()); | ||
} | ||
} |
Oops, something went wrong.