I18nJSPProcessor.java
7.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* 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 I18nJSPProcessor
extends I18nContentProcessor {
private static Logger logger = LoggerFactory.getLogger(I18nJSPProcessor.class);
public I18nJSPProcessor(I18nStringExtractor i18nStringExtractor, HashSet<String> existingI18nStringSet, ResourceResolver resourceResolver) {
super(i18nStringExtractor, existingI18nStringSet, resourceResolver);
}
@Override
protected boolean processFileForI18nStrings(Node node, HashMap<String, String> i18nStringMap) {
String regEx;
boolean bSave = false;
String fileContent = I18nStringExtractor.getFileContentsFromNode(node);
try {
logger.trace("In function: processFileForI18nStrings for {}", (Object)node.getPath());
regEx = "[iI]18n.get\\(\\s*\"([^,]*?)\"\\)";
if (this.searchAndAddI18nString(fileContent, i18nStringMap, regEx, 1)) {
bSave = true;
}
}
catch (Exception ignored) {
// empty catch block
}
try {
regEx = "[iI]18n.get\\(\\s*\"([^\\)]*?)\"\\s*,\\s*(\"(.*?)\"|null\\s*)";
if (this.searchAndAddI18nStringWithComment(fileContent, i18nStringMap, regEx, 1, 3)) {
bSave = true;
}
}
catch (Exception ignored) {
// empty catch block
}
return bSave;
}
@Override
protected boolean processFileForIncludes(Node node) {
boolean bSave = false;
try {
String includePath;
Node includeFileNode;
String jspContent = I18nStringExtractor.getFileContentsFromNode(node);
String regEx = "<cq:include\\s+script\\s*=\\s*\"(.*?)\"/>";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(jspContent);
while (matcher.find()) {
try {
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("cqInclude : {}", (Object)includePath);
if (!this.i18nStringExtractor.addFileForStringExtraction(includeFileNode)) continue;
bSave = true;
}
catch (Exception ignored) {}
}
regEx = "include\\s*file\\s*=\\s*\"(.*?)\"";
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(jspContent);
while (matcher.find()) {
try {
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 : {}", (Object)includePath);
if (!this.i18nStringExtractor.addFileForStringExtraction(includeFileNode)) continue;
bSave = true;
}
catch (Exception ignored) {}
}
regEx = "<cq:include\\s+path\\s*=\\s*\"(.*?)\"\\s+resourceType\\s*=\\s*\"(.*?)\"";
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(jspContent);
while (matcher.find()) {
try {
String name = matcher.group(1);
String resourceType = matcher.group(2);
if (name == null || resourceType == null) continue;
Resource resource = this.resourceResolver.getResource(resourceType);
String includePath2 = resource.getPath() + "/" + name + ".jsp";
try {
includeFileNode = (Node)this.resourceResolver.getResource(includePath2).adaptTo(Node.class);
}
catch (Exception e) {
includePath2 = resource.getPath() + "/" + name + ".html";
includeFileNode = (Node)this.resourceResolver.getResource(includePath2).adaptTo(Node.class);
}
if (!I18nStringExtractor.isI18nContentStringExtractionRequired(includeFileNode)) continue;
logger.trace("cqInclude path : {}", (Object)includePath2);
if (!this.i18nStringExtractor.addFileForStringExtraction(includeFileNode)) continue;
bSave = true;
}
catch (Exception ignored) {}
}
regEx = "<script\\s+.*?src\\s*=\\s*\"(.*?)\"";
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(jspContent);
while (matcher.find()) {
try {
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 : {}", (Object)includePath);
if (!this.i18nStringExtractor.addFileForStringExtraction(includeFileNode)) continue;
bSave = true;
}
catch (Exception ignored) {}
}
if (this.processFileForClientLibCategories(node)) {
bSave = true;
}
}
catch (Exception ignored) {
// empty catch block
}
return bSave;
}
public boolean processFileForClientLibCategories(Node node) {
boolean bSave = false;
try {
String jspContent = I18nStringExtractor.getFileContentsFromNode(node);
String regEx = "<cq:includeClientLib\\s+(categories|js)\\s*=\\s*\"\\s*(.*?)\"";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(jspContent);
while (matcher.find()) {
try {
String[] categories;
for (String category : categories = matcher.group(2).trim().split(",")) {
bSave = this.i18nStringExtractor.addClientCategory(category);
}
continue;
}
catch (Exception ignored) {
continue;
}
}
}
catch (Exception ignored) {
// empty catch block
}
return bSave;
}
}