|
6 | 6 | package com.liferay.portal.kernel.portlet.render; |
7 | 7 |
|
8 | 8 | import com.liferay.petra.io.StreamUtil; |
9 | | -import com.liferay.petra.string.StringBundler; |
10 | 9 | import com.liferay.petra.string.StringPool; |
11 | 10 | import com.liferay.portal.kernel.content.security.policy.ContentSecurityPolicyNonceProviderUtil; |
12 | | -import com.liferay.portal.kernel.frontend.esm.FrontendESMUtil; |
13 | 11 | import com.liferay.portal.kernel.frontend.hashed.files.HashedFilesRegistryUtil; |
14 | 12 | import com.liferay.portal.kernel.frontend.hashed.files.HashedFilesUtil; |
15 | 13 | import com.liferay.portal.kernel.log.Log; |
16 | 14 | import com.liferay.portal.kernel.log.LogFactoryUtil; |
17 | 15 | import com.liferay.portal.kernel.model.LayoutTypePortlet; |
18 | 16 | import com.liferay.portal.kernel.model.Portlet; |
19 | | -import com.liferay.portal.kernel.model.Theme; |
20 | 17 | import com.liferay.portal.kernel.theme.ThemeDisplay; |
21 | 18 | import com.liferay.portal.kernel.util.HashMapBuilder; |
22 | 19 | import com.liferay.portal.kernel.util.HtmlUtil; |
|
47 | 44 | import java.util.Map; |
48 | 45 | import java.util.Set; |
49 | 46 | import java.util.concurrent.ConcurrentHashMap; |
50 | | -import java.util.function.Predicate; |
51 | 47 |
|
52 | 48 | /** |
53 | 49 | * @author Iván Zaera Avellón |
@@ -197,110 +193,6 @@ private static List<Portlet> _getAllPortlets( |
197 | 193 | return allPortlets; |
198 | 194 | } |
199 | 195 |
|
200 | | - private static List<String> _getComboServletURLs( |
201 | | - Collection<PortletResourceAccessor> portletResourceAccessors, |
202 | | - Collection<Portlet> portlets, Predicate<String> predicate, |
203 | | - long timestamp, String urlPrefix, Set<String> visitedURLs) { |
204 | | - |
205 | | - if (predicate == null) { |
206 | | - predicate = s -> true; |
207 | | - } |
208 | | - |
209 | | - List<String> urls = new ArrayList<>(); |
210 | | - |
211 | | - StringBundler comboServletSB = new StringBundler(); |
212 | | - |
213 | | - for (Portlet portlet : portlets) { |
214 | | - for (PortletResourceAccessor portletResourceAccessor : |
215 | | - portletResourceAccessors) { |
216 | | - |
217 | | - String contextPath = null; |
218 | | - |
219 | | - if (portletResourceAccessor.isPortalResource()) { |
220 | | - contextPath = PortalUtil.getPathContext(); |
221 | | - } |
222 | | - else { |
223 | | - contextPath = |
224 | | - PortalUtil.getPathProxy() + portlet.getContextPath(); |
225 | | - } |
226 | | - |
227 | | - Collection<String> portletResources = |
228 | | - portletResourceAccessor.get(portlet); |
229 | | - |
230 | | - for (String portletResource : portletResources) { |
231 | | - if (!predicate.test(portletResource)) { |
232 | | - continue; |
233 | | - } |
234 | | - |
235 | | - String prefix = null; |
236 | | - |
237 | | - for (String specialPrefix : _specialPrefixes) { |
238 | | - if (portletResource.startsWith(specialPrefix)) { |
239 | | - portletResource = portletResource.substring( |
240 | | - specialPrefix.length()); |
241 | | - |
242 | | - prefix = specialPrefix; |
243 | | - |
244 | | - break; |
245 | | - } |
246 | | - } |
247 | | - |
248 | | - boolean absolute = HttpComponentsUtil.hasProtocol( |
249 | | - portletResource); |
250 | | - |
251 | | - if (!absolute) { |
252 | | - portletResource = contextPath + portletResource; |
253 | | - } |
254 | | - |
255 | | - if (Validator.isNotNull(prefix)) { |
256 | | - portletResource = prefix + portletResource; |
257 | | - } |
258 | | - |
259 | | - if (visitedURLs.contains(portletResource)) { |
260 | | - continue; |
261 | | - } |
262 | | - |
263 | | - visitedURLs.add(portletResource); |
264 | | - |
265 | | - if (absolute || Validator.isNotNull(prefix)) { |
266 | | - urls.add(portletResource); |
267 | | - } |
268 | | - else { |
269 | | - comboServletSB.append(StringPool.AMPERSAND); |
270 | | - |
271 | | - if (!portletResourceAccessor.isPortalResource()) { |
272 | | - comboServletSB.append(portlet.getPortletId()); |
273 | | - comboServletSB.append(StringPool.COLON); |
274 | | - } |
275 | | - |
276 | | - comboServletSB.append( |
277 | | - HtmlUtil.escapeURL(portletResource)); |
278 | | - |
279 | | - timestamp = Math.max(timestamp, portlet.getTimestamp()); |
280 | | - } |
281 | | - } |
282 | | - } |
283 | | - } |
284 | | - |
285 | | - if (comboServletSB.length() > 0) { |
286 | | - String url = urlPrefix + comboServletSB; |
287 | | - |
288 | | - url = HttpComponentsUtil.addParameter(url, "t", timestamp); |
289 | | - |
290 | | - urls.add(url); |
291 | | - } |
292 | | - |
293 | | - return urls; |
294 | | - } |
295 | | - |
296 | | - private static String _getMinifierType(URLType urlType) { |
297 | | - if (urlType == URLType.CSS) { |
298 | | - return "css"; |
299 | | - } |
300 | | - |
301 | | - return "js"; |
302 | | - } |
303 | | - |
304 | 196 | private static PortletRenderParts _getPortletRenderParts( |
305 | 197 | HttpServletRequest httpServletRequest, String portletHTML, |
306 | 198 | Portlet portlet, boolean portletOnLayout) { |
@@ -432,12 +324,15 @@ private static List<String> _getStaticURLs( |
432 | 324 | contextPath + portletResource); |
433 | 325 | } |
434 | 326 | else if (urlType == URLType.JAVASCRIPT) { |
435 | | - Portlet rootPortlet = portlet.getRootPortlet(); |
| 327 | + portletResource = contextPath + portletResource; |
| 328 | + |
| 329 | + String hashedFileURI = |
| 330 | + HashedFilesRegistryUtil.getHashedFileURI( |
| 331 | + portletResource); |
436 | 332 |
|
437 | | - portletResource = PortalUtil.getStaticResourceURL( |
438 | | - httpServletRequest, |
439 | | - contextPath + portletResource, |
440 | | - rootPortlet.getTimestamp()); |
| 333 | + if (hashedFileURI != null) { |
| 334 | + portletResource = hashedFileURI; |
| 335 | + } |
441 | 336 | } |
442 | 337 | else { |
443 | 338 | throw new UnsupportedOperationException( |
@@ -492,36 +387,9 @@ private static Collection<String> _getURLs( |
492 | 387 | visitedURLs); |
493 | 388 | } |
494 | 389 | else if (urlType == URLType.JAVASCRIPT) { |
495 | | - ThemeDisplay themeDisplay = |
496 | | - (ThemeDisplay)httpServletRequest.getAttribute( |
497 | | - WebKeys.THEME_DISPLAY); |
498 | | - |
499 | | - boolean fastLoad = themeDisplay.isThemeJsFastLoad(); |
500 | | - |
501 | | - if (fastLoad) { |
502 | | - Predicate<String> predicate = |
503 | | - resource -> !themeDisplay.isIncludedJs(resource); |
504 | | - |
505 | | - Theme theme = themeDisplay.getTheme(); |
506 | | - |
507 | | - urls = _getComboServletURLs( |
508 | | - portletResourceAccessors, portlets, predicate, |
509 | | - theme.getTimestamp(), |
510 | | - PortalUtil.getStaticResourceURL( |
511 | | - httpServletRequest, |
512 | | - themeDisplay.getCDNDynamicResourcesHost() + |
513 | | - themeDisplay.getPathContext() + "/combo", |
514 | | - StringBundler.concat( |
515 | | - "minifierType=", _getMinifierType(urlType), |
516 | | - "&themeId=", themeDisplay.getThemeId()), |
517 | | - -1), |
518 | | - visitedURLs); |
519 | | - } |
520 | | - else { |
521 | | - urls = _getStaticURLs( |
522 | | - httpServletRequest, portletResourceAccessors, portlets, |
523 | | - urlType, visitedURLs); |
524 | | - } |
| 390 | + urls = _getStaticURLs( |
| 391 | + httpServletRequest, portletResourceAccessors, portlets, urlType, |
| 392 | + visitedURLs); |
525 | 393 | } |
526 | 394 | else { |
527 | 395 | throw new UnsupportedOperationException( |
|
0 commit comments