I18nHandlebarsProcessor.java
2.62 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.wcm.translation.impl;
import com.adobe.cq.wcm.translation.impl.I18nContentProcessor;
import com.adobe.cq.wcm.translation.impl.I18nStringExtractor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jcr.Node;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class I18nHandlebarsProcessor
extends I18nContentProcessor {
private static Logger logger = LoggerFactory.getLogger(I18nHandlebarsProcessor.class);
public I18nHandlebarsProcessor(I18nStringExtractor i18nStringExtractor, HashSet<String> existingI18nStringSet, ResourceResolver resourceResolver) {
super(i18nStringExtractor, existingI18nStringSet, resourceResolver);
}
@Override
boolean processFileForI18nStrings(Node node, HashMap<String, String> i18nStringMap) {
String regEx = "\\{\\{\\s*i18n\\s+['\"](.*?)(?<!\\\\)['\"](\\s+.*?comment\\s*=\\s*['\"](.*?)(?<!\\\\)['\"])?";
String fileContent = I18nStringExtractor.getFileContentsFromNode(node);
return this.searchAndAddI18nStringWithComment(fileContent, i18nStringMap, regEx, 1, 3);
}
@Override
boolean processFileForIncludes(Node node) {
boolean bSave = false;
String fileContent = I18nStringExtractor.getFileContentsFromNode(node);
String regEx = "<script\\s+.*?src\\s*=\\s*\"(.*?)\"";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(fileContent);
while (matcher.find()) {
try {
Node includeFileNode;
String includePath = matcher.group(1);
if (includePath == null) continue;
if (!includePath.startsWith("/")) {
includePath = node.getParent().getPath() + "/" + includePath;
}
if (!I18nStringExtractor.isI18nContentStringExtractionRequired(includeFileNode = (Node)this.resourceResolver.getResource(includePath).adaptTo(Node.class))) continue;
logger.trace("include script : {}", (Object)includePath);
if (!this.i18nStringExtractor.addFileForStringExtraction(includeFileNode)) continue;
bSave = true;
}
catch (Exception ignored) {}
}
return bSave;
}
}