You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by je...@apache.org on 2019/08/20 18:16:49 UTC
[sling-whiteboard] 03/03: initial changes
This is an automated email from the ASF dual-hosted git repository.
jeb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit ff546584239e2334c1f8dd4e9bc350c0a13a4319
Author: JE Bailey <je...@apache.org>
AuthorDate: Fri Aug 16 11:45:24 2019 -0400
initial changes
---
transformer/pom.xml | 107 ++----------
.../apache/sling/transformer/ProcessorManager.java | 40 -----
.../sling/transformer/TransformationStep.java | 16 ++
.../sling/transformer/impl/LinkTransformer.java | 91 ++++++++--
.../org/apache/sling/transformer/impl/Process.java | 37 ++--
.../sling/transformer/impl/ProcessManager.java | 76 +++++++-
.../sling/transformer/impl/RewriterResponse.java | 76 +-------
.../transformer/impl/TransformationFilter.java | 6 +-
.../impl/TransformationStepWrapper.java | 16 ++
.../org/apache/sling/transformer/package-info.java | 24 ---
.../apache/sling/rewriter/it/tests/EmojiIT.java | 60 -------
.../impl/ProcessorConfigurationImplTest.java | 193 ---------------------
12 files changed, 213 insertions(+), 529 deletions(-)
diff --git a/transformer/pom.xml b/transformer/pom.xml
index 92cd653..c3a0971 100644
--- a/transformer/pom.xml
+++ b/transformer/pom.xml
@@ -1,23 +1,17 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -28,7 +22,7 @@
</parent>
<artifactId>org.apache.sling.transformer</artifactId>
- <version>1.2.3-SNAPSHOT</version>
+ <version>0.0.0-SNAPSHOT</version>
<name>Apache Sling Transformer</name>
<description>
@@ -37,56 +31,15 @@
or a configurable pipeline.
</description>
- <properties>
- <org.ops4j.pax.exam.version>4.13.1</org.ops4j.pax.exam.version>
- </properties>
-
<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>biz.aQute.bnd</groupId>
- <artifactId>bnd-baseline-maven-plugin</artifactId>
+ <artifactId>bnd-maven-plugin </artifactId>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>sling-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-adapter-metadata</id>
- <phase>process-classes</phase>
- <goals>
- <goal>generate-adapter-metadata</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <systemProperties>
- <property>
- <name>bundle.filename</name>
- <value>${basedir}/target/${project.build.finalName}.jar</value>
- </property>
- </systemProperties>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.servicemix.tooling</groupId>
- <artifactId>depends-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
@@ -206,35 +159,5 @@
<version>1.3_1</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-cm</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-forked</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-link-mvn</artifactId>
- <version>${org.ops4j.pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/transformer/src/main/java/org/apache/sling/transformer/ProcessorManager.java b/transformer/src/main/java/org/apache/sling/transformer/ProcessorManager.java
deleted file mode 100644
index 6d88809..0000000
--- a/transformer/src/main/java/org/apache/sling/transformer/ProcessorManager.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.transformer;
-
-import java.util.List;
-
-/**
- * This service manages the processor configurations.
- */
-public interface ProcessorManager {
-
- /**
- * Return the list of currently available processor configurations.
- *
- * @return The list of processor configurations in the order to check.
- */
- List<ProcessorConfiguration> getProcessorConfigurations();
-
- /**
- * Return a pipeline for a pipeline configuration.
- *
- * @throws org.apache.sling.api.SlingException
- * If an error occurs during setup
- */
- Processor getProcessor(ProcessorConfiguration configuration, ProcessingContext context);
-}
diff --git a/transformer/src/main/java/org/apache/sling/transformer/TransformationStep.java b/transformer/src/main/java/org/apache/sling/transformer/TransformationStep.java
index 38d64ab..364abb7 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/TransformationStep.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/TransformationStep.java
@@ -1,3 +1,19 @@
+/*
+ * 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.transformer;
import org.apache.sling.commons.html.HtmlElement;
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/LinkTransformer.java b/transformer/src/main/java/org/apache/sling/transformer/impl/LinkTransformer.java
index 1ac0836..415efb2 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/LinkTransformer.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/LinkTransformer.java
@@ -1,34 +1,87 @@
+/*
+ * 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.transformer.impl;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Base64;
+import java.util.Map;
+
import org.apache.sling.commons.html.HtmlElement;
-import org.apache.sling.commons.html.HtmlElementType;
import org.apache.sling.transformer.TransformationStep;
import org.osgi.service.component.annotations.Component;
-@Component(property = {
- "extension=html",
- "path=/content/*",
- "type=REQUEST"
-})
+@Component(property = { "extension=html", "path=/content/*", "type=REQUEST" })
public class LinkTransformer implements TransformationStep {
+ private enum State {
+ IN, OUT
+ }
+
public void handle(HtmlElement element, Process process) {
- if (element.getType() != HtmlElementType.START_TAG) {
- process.next(element);
- return;
- }
- if (element.containsAttribute("href")) {
- String value = element.getAttributeValue("href");
- if (value != null && value.startsWith("/")) {
- element.setAttribute("href", "http://www.apache.org" + value);
+
+ Map<String,Object> context = process.getContext();
+ State current = (State) context.getOrDefault("currentState", State.OUT);
+
+ MessageDigest d = (MessageDigest) context.computeIfAbsent("hash", (value)->{
+ MessageDigest digest = null;
+ try {
+ digest = MessageDigest.getInstance("SHA-256");
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
}
- }
- if (element.containsAttribute("src")) {
- String value = element.getAttributeValue("src");
- if (value != null && value.startsWith("/")) {
- element.setAttribute("src", "http://www.apache.org" + value);
+ return digest;
+ });
+
+ switch (current) {
+ case IN:
+ switch (element.getType()) {
+ case END_TAG:
+ context.put("currentState", State.OUT);
+ break;
+ case TEXT:
+ d.update(element.getValue().getBytes());
+ break;
+ default:
+ break;
+ }
+ break;
+ case OUT:
+ switch (element.getType()) {
+ case START_TAG:
+ String tag = element.getValue();
+ if (tag.equals("script") || tag.equals("style")) {
+ context.put("currentState", State.IN);
+ }
+ break;
+ case EOF:
+ String headerValue = Base64.getEncoder().encodeToString(d.digest());
+ process.getResponse().addHeader("X-Sucks", headerValue);
+ break;
+ default:
+ break;
+
}
+ break;
+ default:
+ break;
+
}
+
process.next(element);
}
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/Process.java b/transformer/src/main/java/org/apache/sling/transformer/impl/Process.java
index c2f7855..18ab00d 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/Process.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/Process.java
@@ -18,10 +18,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.BiConsumer;
-import java.util.function.Function;
import java.util.stream.Stream;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.commons.html.Html;
import org.apache.sling.commons.html.HtmlElement;
import org.osgi.annotation.versioning.ProviderType;
@@ -39,9 +40,13 @@ public class Process {
private List<HtmlElement> list = new ArrayList<>();
private Map<String,Object> context = new HashMap<>();
+ private SlingHttpServletRequest request;
+ private SlingHttpServletResponse response;
- private Process() {
+ private Process(SlingHttpServletRequest request, SlingHttpServletResponse response) {
+ this.request = request;
+ this.response = response;
}
/**
@@ -52,22 +57,24 @@ public class Process {
public void next(HtmlElement... elements) {
Collections.addAll(list, elements);
}
-
- Function<HtmlElement, Stream<HtmlElement>> createFlatMap(BiConsumer<HtmlElement, Process> consumer, Process mapper) {
- return element -> {
- list.clear();
- consumer.accept(element, mapper);
- return list.stream();
- };
- }
-
- public static Function<HtmlElement, Stream<HtmlElement>> map(BiConsumer<HtmlElement, Process> consumer) {
- Process mapper = new Process();
- return mapper.createFlatMap(consumer, mapper);
+
+ public void next(String html) {
+ Collections.addAll(list, Html.stream(html).toArray(HtmlElement[]::new));
}
public Stream<HtmlElement> getElements() {
return list.stream();
}
+
+ public Map<String,Object> getContext(){
+ return context;
+ }
+
+ public SlingHttpServletResponse getResponse() {
+ return response;
+ }
+ public SlingHttpServletRequest getRequest() {
+ return request;
+ }
}
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/ProcessManager.java b/transformer/src/main/java/org/apache/sling/transformer/impl/ProcessManager.java
index d36a879..44ffa5c 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/ProcessManager.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/ProcessManager.java
@@ -1,23 +1,81 @@
+/*
+ * 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.transformer.impl;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.transformer.TransformationStep;
+import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
@Component
public class ProcessManager {
-
-
-
- @Reference
- void bindProcess(Process process, Map<String, ?> properties) {
-
+ // comparison in the same manner of a filter, where the highest ranking goes
+ // first
+ // in a situation where ranking is identical, then the lowest service id goes
+ // first
+ private Map<Map<String, Object>, TransformationStep> mapping = new TreeMap<>((map1, map2) -> {
+ Integer value1 = (Integer) map1.getOrDefault(Constants.SERVICE_RANKING, (Integer) 0);
+ Integer value2 = (Integer) map2.getOrDefault(Constants.SERVICE_RANKING, (Integer) 0);
+ if (value1 - value2 == 0) {
+ value1 = (Integer) map1.get(Constants.SERVICE_ID);
+ value2 = (Integer) map2.get(Constants.SERVICE_ID);
+ return value2.compareTo(value1);
+ }
+ return value1.compareTo(value2);
+ });
+
+ public List<TransformationStep> getSteps(SlingHttpServletRequest request) {
+ List<TransformationStep> steps = new ArrayList<>();
+ mapping.forEach((properties, step) -> {
+ if (doStep(properties, request)) {
+ steps.add(step);
+ }
+ });
+ return steps;
}
-
- void unbindProcess(Process process) {
-
+
+ private boolean doStep(Map<String, Object> properties, SlingHttpServletRequest request) {
+ properties.keySet().forEach(key -> {
+
+ });
+ return true;
+ }
+
+ @Reference(service = TransformationStep.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
+ void bindTransformationStep(Map<String, Object> properties, TransformationStep step) {
+ mapping.put(properties, step);
+ }
+
+ void updateTransformationStep(Map<String, Object> properties, TransformationStep step) {
+ mapping.put(properties, step);
+ }
+
+ void unbindTransformationStep(Map<String, Object> properties) {
+ mapping.remove(properties);
}
}
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/RewriterResponse.java b/transformer/src/main/java/org/apache/sling/transformer/impl/RewriterResponse.java
index f21bab2..70febb8 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/RewriterResponse.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/RewriterResponse.java
@@ -19,28 +19,12 @@ package org.apache.sling.transformer.impl;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
-import java.util.Iterator;
-import java.util.List;
-import org.apache.sling.adapter.annotations.Adaptable;
-import org.apache.sling.adapter.annotations.Adapter;
-import org.apache.sling.api.SlingException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
-import org.apache.sling.transformer.ProcessingContext;
import org.apache.sling.transformer.Processor;
-import org.apache.sling.transformer.ProcessorConfiguration;
-import org.apache.sling.transformer.ProcessorManager;
-import org.xml.sax.ContentHandler;
-/**
- * This response is used to pass the output through the rewriter pipeline.
- */
-@Adaptable(adaptableClass=SlingHttpServletResponse.class, adapters={
- @Adapter(value=ContentHandler.class,
- condition="When the response is being processed through the Sling Rewriter filter.")
-})
class RewriterResponse
extends SlingHttpServletResponseWrapper {
@@ -56,19 +40,14 @@ class RewriterResponse
/** response content type */
private String contentType;
- /** The processor manager. */
- private final ProcessorManager processorManager;
-
/**
* Initializes a new instance.
* @param request The sling request.
* @param delegatee The SlingHttpServletResponse wrapped by this instance.
*/
public RewriterResponse(SlingHttpServletRequest request,
- SlingHttpServletResponse delegatee,
- ProcessorManager processorManager) {
+ SlingHttpServletResponse delegatee) {
super(delegatee);
- this.processorManager = processorManager;
this.request = request;
}
@@ -107,13 +86,7 @@ class RewriterResponse
});
}
if (writer == null) {
- this.processor = this.getProcessor();
- if ( this.processor != null ) {
- this.writer = this.processor.getWriter();
- }
- if ( this.writer == null ) {
- this.writer = super.getWriter();
- }
+
}
return writer;
}
@@ -140,49 +113,4 @@ class RewriterResponse
}
}
- /**
- * If we have a pipeline configuration for the current request,
- * we can adapt this response to a content handler.
- * @see org.apache.sling.api.adapter.Adaptable#adaptTo(java.lang.Class)
- */
- public <T> T adaptTo(Class<T> type) {
- if ( type == ContentHandler.class ) {
- this.processor = this.getProcessor();
- if ( this.processor != null ) {
- @SuppressWarnings("unchecked")
- final T object = (T)this.processor.getContentHandler();
- return object;
- }
- }
- return super.adaptTo(type);
- }
-
- /**
- * Search the first matching processor
- */
- private Processor getProcessor() {
- final ProcessingContext processorContext = new ServletProcessingContext(this.request, this, this.getSlingResponse(), this.contentType);
- Processor found = null;
- final List<ProcessorConfiguration> processorConfigs = this.processorManager.getProcessorConfigurations();
- final Iterator<ProcessorConfiguration> i = processorConfigs.iterator();
- while ( found == null && i.hasNext() ) {
- final ProcessorConfiguration config = i.next();
- if ( config.match(processorContext) ) {
- try {
- found = this.processorManager.getProcessor(config, processorContext);
- this.request.getRequestProgressTracker().log("Found processor for post processing {0}", config);
- } catch (final SlingException se) {
- // if an exception occurs during setup of the pipeline and we are currently
- // already processing an error, we ignore this!
- if ( processorContext.getRequest().getAttribute("javax.servlet.error.status_code") != null ) {
- this.request.getRequestProgressTracker().log("Ignoring found processor for post processing {0}" +
- " as an error occured ({1}) during setup while processing another error.", config, se);
- } else {
- throw se;
- }
- }
- }
- }
- return found;
- }
}
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationFilter.java b/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationFilter.java
index e8bd178..d21616c 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationFilter.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationFilter.java
@@ -27,7 +27,7 @@ import javax.servlet.ServletResponse;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.transformer.ProcessorManager;
+import org.apache.sling.transformer.TransformationStep;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@@ -48,7 +48,7 @@ import org.osgi.service.component.annotations.Reference;
public class TransformationFilter implements Filter {
@Reference
- private ProcessorManager pipelineManager;
+ private TransformationStep pipelineManager;
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
@@ -81,7 +81,7 @@ public class TransformationFilter implements Filter {
final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
final RewriterResponse rewriterResponse =
- new RewriterResponse(slingRequest, slingResponse, this.pipelineManager);
+ new RewriterResponse(slingRequest, slingResponse);
boolean errorOccured = true;
try {
chain.doFilter(request, rewriterResponse);
diff --git a/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationStepWrapper.java b/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationStepWrapper.java
index d0e750a..3f7641f 100644
--- a/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationStepWrapper.java
+++ b/transformer/src/main/java/org/apache/sling/transformer/impl/TransformationStepWrapper.java
@@ -1,3 +1,19 @@
+/*
+ * 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.transformer.impl;
import java.util.function.Function;
diff --git a/transformer/src/main/java/org/apache/sling/transformer/package-info.java b/transformer/src/main/java/org/apache/sling/transformer/package-info.java
deleted file mode 100644
index 7d911d9..0000000
--- a/transformer/src/main/java/org/apache/sling/transformer/package-info.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.
- */
-
-@Version("1.0.0")
-package org.apache.sling.transformer;
-
-import org.osgi.annotation.versioning.Version;
-
diff --git a/transformer/src/test/java/org/apache/sling/rewriter/it/tests/EmojiIT.java b/transformer/src/test/java/org/apache/sling/rewriter/it/tests/EmojiIT.java
deleted file mode 100644
index f24a299..0000000
--- a/transformer/src/test/java/org/apache/sling/rewriter/it/tests/EmojiIT.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.rewriter.it.tests;
-
-import java.io.IOException;
-
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class EmojiIT extends RewriterTestSupport {
-
- private Document document;
-
- @Before
- public void setup() throws IOException {
- final String url = String.format("http://localhost:%s/rewriter/emoji.html", httpPort());
- document = Jsoup.connect(url).get();
- }
-
- @Test
- public void testTitle() throws IOException {
- final String title = document.title();
- assertThat(title, is("emoji test"));
- }
-
- @Test
- public void testContent() throws IOException {
- final Element content = document.getElementById("content");
- assertThat(content.text(), is("\u2602\uD83D\uDE03 \uD83C\uDF40 \uD83C\uDF40 \uD83C\uDF40 \uD83D\uDE01 \uD83C\uDF40\uD83C\uDF40"));
- }
-
-}
diff --git a/transformer/src/test/java/org/apache/sling/transformer/impl/ProcessorConfigurationImplTest.java b/transformer/src/test/java/org/apache/sling/transformer/impl/ProcessorConfigurationImplTest.java
deleted file mode 100644
index ab22665..0000000
--- a/transformer/src/test/java/org/apache/sling/transformer/impl/ProcessorConfigurationImplTest.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * 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.transformer.impl;
-
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_CONTENT_TYPES;
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_EXTENSIONS;
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_PATHS;
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_RESOURCE_TYPES;
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_SELECTORS;
-import static org.apache.sling.transformer.impl.ProcessorConfigurationImpl.PROPERTY_UNWRAP_RESOURCES;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.Map;
-
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceWrapper;
-import org.apache.sling.testing.mock.sling.junit.SlingContext;
-import org.apache.sling.transformer.ProcessingContext;
-import org.apache.sling.transformer.impl.ProcessorConfigurationImpl;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-
-import com.google.common.collect.ImmutableMap;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ProcessorConfigurationImplTest {
-
- @Rule
- public SlingContext context = new SlingContext();
-
- @Mock
- private ProcessingContext processingContext;
-
- @Before
- public void setup() {
- when(processingContext.getContentType()).thenReturn("text/html");
- when(processingContext.getRequest()).thenReturn(context.request());
- when(processingContext.getResponse()).thenReturn(context.response());
- }
-
- private ProcessorConfigurationImpl buildConfig(Map<String,Object> configProps) {
- Resource configResoruce = context.create().resource("/apps/myapp/rewriter/config", configProps);
- return new ProcessorConfigurationImpl(configResoruce);
- }
-
- private void assertMatch(Map<String,Object> configProps) {
- assertTrue(buildConfig(configProps).match(processingContext));
- }
-
- private void assertNoMatch(Map<String,Object> configProps) {
- assertFalse(buildConfig(configProps).match(processingContext));
- }
-
- @Test
- public void testMatchContentTypeMismatch() {
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_CONTENT_TYPES, new String[] {"text/xml", "text/plain"}));
- }
-
- @Test
- public void testMatchAtLeastOneContentType() {
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_CONTENT_TYPES, new String[] {"text/html", "text/xml"}));
- }
-
- @Test
- public void testMatchAnyContentType() {
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_CONTENT_TYPES, new String[] {"text/xml", "*"}));
- }
-
- @Test
- public void testMatchExtensionMismatch() {
- context.requestPathInfo().setExtension("html");
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_EXTENSIONS, new String[] {"xml","txt"}));
- }
-
- @Test
- public void testMatchAtLeastOneExtension() {
- context.requestPathInfo().setExtension("html");
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_EXTENSIONS, new String[] {"xml","html"}));
- }
-
- @Test
- public void testMatchResourceTypeMismatch() {
- context.currentResource(context.create().resource("/content/test",
- ImmutableMap.<String, Object>of("sling:resourceType", "type/1")));
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_RESOURCE_TYPES, new String[] {"type/2","type/3"}));
- }
-
- @Test
- public void testMatchAtLeastOneResourceType() {
- context.currentResource(context.create().resource("/content/test",
- ImmutableMap.<String, Object>of("sling:resourceType", "type/1")));
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_RESOURCE_TYPES, new String[] {"type/1","type/2"}));
- }
-
- @Test
- public void testMatchAtLeastOneResourceTypeWithResourceWrapper_UnwrapDisabled() {
- Resource resource = context.create().resource("/content/test", ImmutableMap.<String, Object>of("sling:resourceType", "type/1"));
-
- // overwrite resource type via ResourceWrapper
- Resource resourceWrapper = new ResourceWrapper(resource) {
- @Override
- public String getResourceType() { return "/type/override/1"; }
- };
- context.currentResource(resourceWrapper);
-
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_RESOURCE_TYPES, new String[] {"type/1","type/2"}));
- }
-
- @Test
- public void testMatchAtLeastOneResourceTypeWithResourceWrapper_UnwrapEnabled() {
- Resource resource = context.create().resource("/content/test", ImmutableMap.<String, Object>of("sling:resourceType", "type/1"));
-
- // overwrite resource type via ResourceWrapper
- Resource resourceWrapper = new ResourceWrapper(resource) {
- @Override
- public String getResourceType() { return "/type/override/1"; }
- };
- context.currentResource(resourceWrapper);
-
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_RESOURCE_TYPES, new String[] {"type/1","type/2"},
- PROPERTY_UNWRAP_RESOURCES, true));
- }
-
- @Test
- public void testMatchPathMismatch() {
- context.requestPathInfo().setResourcePath("/content/test");
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps","/var"}));
- }
-
- @Test
- public void testMatchAtLeastOnePath() {
- context.requestPathInfo().setResourcePath("/content/test");
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps","/content"}));
- }
-
- @Test
- public void testMatchAnyPath() {
- context.requestPathInfo().setResourcePath("/content/test");
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps","*"}));
- }
-
- @Test
- public void testMatchSelectorRequired() {
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_SELECTORS, new String[] {"sel"}));
- }
-
- @Test
- public void testMatchSelectorMismatch() {
- context.requestPathInfo().setSelectorString("sel1.sel2");
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_SELECTORS, new String[] {"sel3"}));
- }
-
- @Test
- public void testMatchAtLeastOneSelector() {
- context.requestPathInfo().setSelectorString("sel1.sel2");
- assertMatch(ImmutableMap.<String,Object>of(PROPERTY_SELECTORS, new String[] {"sel1"}));
- }
-
- @Test
- public void testNoMatchRequestAttribute() {
- context.request().setAttribute(ProcessorConfigurationImpl.ATTR_PIPELINE, "config2");
- context.requestPathInfo().setResourcePath("/content/test");
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps","/content"}));
- }
-
- @Test
- public void testNoMatchRequestAttributeIfConditionsDoNotMatch() {
- context.request().setAttribute(ProcessorConfigurationImpl.ATTR_PIPELINE, "config");
- context.requestPathInfo().setResourcePath("/content/test");
- assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps"}));
- }
-
-}