PathRewriterTransformerFactory.java 4.35 KB
/*
 * 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;
        }
    }
}