MobileAppsCampaginRewriterTransformer.java
3.71 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
88
89
90
91
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.text.Text
* javax.servlet.http.HttpServletRequest
* org.apache.cocoon.xml.sax.AbstractSAXPipe
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.rewriter.ProcessingComponentConfiguration
* org.apache.sling.rewriter.ProcessingContext
* org.apache.sling.rewriter.Transformer
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.platform.impl.rewriter;
import com.adobe.cq.mobile.platform.impl.rewriter.HybridAppPathRewriterOptions;
import com.adobe.cq.mobile.platform.impl.rewriter.MobileAppsCampaignTransformerConfig;
import com.day.text.Text;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.cocoon.xml.sax.AbstractSAXPipe;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.rewriter.ProcessingComponentConfiguration;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class MobileAppsCampaginRewriterTransformer
extends AbstractSAXPipe
implements Transformer {
private static final Logger log = LoggerFactory.getLogger(MobileAppsCampaginRewriterTransformer.class);
private MobileAppsCampaignTransformerConfig config;
private HttpServletRequest request;
private boolean isEnabled = false;
private HybridAppPathRewriterOptions options;
public MobileAppsCampaginRewriterTransformer(MobileAppsCampaignTransformerConfig config) {
this.config = config;
}
public void init(ProcessingContext context, ProcessingComponentConfiguration config) throws IOException {
this.request = context.getRequest();
this.options = (HybridAppPathRewriterOptions)this.request.getAttribute("hybridAppPathRewritingOptions");
this.isEnabled = this.options != null;
}
public void startElement(String uri, String name, String raw, Attributes a) throws SAXException {
if (this.isEnabled && this.options.isPublishMode()) {
log.info("{} is in production mode", (Object)this.getClass().getName());
AttributesImpl attrs = new AttributesImpl(a);
boolean result = this.rewriteMboxProperties(this.config.mapping, name, attrs);
if (result) {
super.startElement(uri, name, raw, (Attributes)attrs);
return;
}
}
super.startElement(uri, name, raw, a);
}
private boolean rewriteMboxProperties(Map<String, String> mapping, String name, AttributesImpl attrs) throws SAXException {
boolean targetFound = false;
if (mapping.containsKey(name)) {
String[] attributesOfInterest;
for (String attrName : attributesOfInterest = Text.explode((String)mapping.get(name), (int)58)) {
String value = attrs.getValue(attrName);
if (!StringUtils.isNotBlank((CharSequence)value)) continue;
int index = attrs.getIndex(attrName);
if (!value.endsWith("--author")) continue;
String original = value;
int i = value.lastIndexOf("--author");
value = value.substring(0, i);
attrs.setAttribute(index, "", attrName, attrName, "String", value);
log.debug("Modified {} to {}", (Object)original, (Object)value);
targetFound = true;
}
}
return targetFound;
}
public void dispose() {
}
}