PathRewriterTransformerFactory.java
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.Externalizer
* com.day.cq.rewriter.linkchecker.LinkChecker
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.osgi.OsgiUtil
* org.apache.sling.rewriter.Transformer
* org.apache.sling.rewriter.TransformerFactory
* org.osgi.service.component.ComponentContext
*/
package com.day.cq.wcm.contentsync.impl.rewriter;
import com.day.cq.commons.Externalizer;
import com.day.cq.rewriter.linkchecker.LinkChecker;
import com.day.cq.wcm.contentsync.impl.rewriter.PathRewriterTransformer;
import com.day.cq.wcm.contentsync.impl.rewriter.PathRewriterTransformerConfig;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.ComponentContext;
@Component(metatype=1)
@Service
@Property(name="pipeline.type", value={"contentsync"})
public class PathRewriterTransformerFactory
implements TransformerFactory {
@Property(value={"a:href", "area:href", "form:action"})
private static final String PROPERTY_LINKS_MAPPING = "cq.contentsync.pathrewritertransformer.mapping.links";
@Property(value={"script:src", "styles:src", "link:href"})
private static final String PROPERTY_CLIENTLIBS_MAPPING = "cq.contentsync.pathrewritertransformer.mapping.clientlibs";
@Property(value={"img:src", "video:src:poster", "source:src"})
private static final String PROPERTY_IMAGES_MAPPING = "cq.contentsync.pathrewritertransformer.mapping.images";
@Property(value={"style:url\\('(.+)'\\)"})
private static final String PROPERTY_ATTRIBUTE_PATTERN = "cq.contentsync.pathrewritertransformer.attribute.pattern";
@Property(value={"\"p\":\"(/[^\"]*)\""})
private static final String PROPERTY_CLIENT_LIBRARY_PATTERN = "cq.contentsync.pathrewritertransformer.clientlibrary.pattern";
@Property(value={"\"p\":\"$1\""})
private static final String PROPERTY_CLIENT_LIBRARY_REPLACE = "cq.contentsync.pathrewritertransformer.clientlibrary.replace";
@Reference
private LinkChecker checker;
@Reference
private Externalizer externalizer;
private PathRewriterTransformerConfig config;
@Activate
protected void activate(ComponentContext context) {
Dictionary props = context.getProperties();
this.config = new PathRewriterTransformerConfig(OsgiUtil.toStringArray(props.get("cq.contentsync.pathrewritertransformer.mapping.links"), (String[])new String[]{"a:href", "area:href", "form:action"}), OsgiUtil.toStringArray(props.get("cq.contentsync.pathrewritertransformer.mapping.clientlibs"), (String[])new String[]{"script:src", "styles:src", "link:href"}), OsgiUtil.toStringArray(props.get("cq.contentsync.pathrewritertransformer.mapping.images"), (String[])new String[]{"img:src", "video:src:poster", "source:src"}), OsgiUtil.toStringArray(props.get("cq.contentsync.pathrewritertransformer.attribute.pattern"), (String[])new String[]{"style:url\\('(.+)'\\)"}), OsgiUtil.toString(props.get("cq.contentsync.pathrewritertransformer.clientlibrary.pattern"), (String)"\"p\":\"(/[^\"]*)\""), OsgiUtil.toString(props.get("cq.contentsync.pathrewritertransformer.clientlibrary.replace"), (String)"\"p\":\"$1\""));
}
public Transformer createTransformer() {
return new PathRewriterTransformer(this.checker, this.externalizer, this.config);
}
protected void bindChecker(LinkChecker linkChecker) {
this.checker = linkChecker;
}
protected void unbindChecker(LinkChecker linkChecker) {
if (this.checker == linkChecker) {
this.checker = null;
}
}
protected void bindExternalizer(Externalizer externalizer) {
this.externalizer = externalizer;
}
protected void unbindExternalizer(Externalizer externalizer) {
if (this.externalizer == externalizer) {
this.externalizer = null;
}
}
}