Skip to content

Commit 26138c8

Browse files
committed
LPD-52709 Change aui:script so that it can use hashed URLs
1 parent d4b303c commit 26138c8

File tree

8 files changed

+64
-7
lines changed

8 files changed

+64
-7
lines changed

util-taglib/bnd.bnd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Bundle-Name: ${manifest.bundle.name}
22
Bundle-SymbolicName: ${manifest.bundle.symbolic.name}
3-
Bundle-Version: 28.1.1
3+
Bundle-Version: 28.2.0
44
Export-Package: com.liferay.taglib.*
55
Import-Package:\
66
!com.liferay.portal.freemarker,\

util-taglib/src/META-INF/liferay-aui.tld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,11 @@
11581158
<required>false</required>
11591159
<rtexprvalue>true</rtexprvalue>
11601160
</attribute>
1161+
<attribute>
1162+
<name>hashedFile</name>
1163+
<required>false</required>
1164+
<rtexprvalue>true</rtexprvalue>
1165+
</attribute>
11611166
<attribute>
11621167
<name>id</name>
11631168
<required>false</required>

util-taglib/src/com/liferay/taglib/aui/LinkTag.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ public int doEndTag() throws JspException {
6363
}
6464

6565
sb.append(PortalUtil.getPathProxy());
66-
sb.append(
66+
67+
String unhashedFileURI =
68+
PortalUtil.getPathModule() + StringPool.SLASH + href;
69+
70+
String hashedFileURI =
6771
HashedFilesRegistryUtil.getHashedFileURI(
68-
PortalUtil.getPathModule() + StringPool.SLASH +
69-
href));
72+
unhashedFileURI);
73+
74+
sb.append(
75+
(hashedFileURI == null) ? unhashedFileURI :
76+
hashedFileURI);
7077

7178
href = sb.toString();
7279
}

util-taglib/src/com/liferay/taglib/aui/ScriptTag.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import com.liferay.petra.string.StringBundler;
99
import com.liferay.petra.string.StringPool;
1010
import com.liferay.portal.kernel.content.security.policy.ContentSecurityPolicyNonceProviderUtil;
11+
import com.liferay.portal.kernel.exception.PortalException;
12+
import com.liferay.portal.kernel.frontend.hashed.files.HashedFilesRegistryUtil;
1113
import com.liferay.portal.kernel.model.Portlet;
1214
import com.liferay.portal.kernel.servlet.FileAvailabilityUtil;
1315
import com.liferay.portal.kernel.servlet.taglib.BodyContentWrapper;
1416
import com.liferay.portal.kernel.servlet.taglib.aui.ScriptData;
17+
import com.liferay.portal.kernel.util.PortalUtil;
1518
import com.liferay.portal.kernel.util.Validator;
1619
import com.liferay.portal.kernel.util.WebKeys;
1720
import com.liferay.taglib.aui.base.BaseScriptTag;
@@ -265,7 +268,34 @@ private int _endTag() throws IOException, JspException {
265268
_write(jspWriter, "id", getId());
266269
_write(jspWriter, "integrity", getIntegrity());
267270
_write(jspWriter, "referrerpolicy", getReferrerPolicy());
268-
_write(jspWriter, "src", getSrc());
271+
272+
String src = getSrc();
273+
274+
if (getHashedFile()) {
275+
StringBundler sb = new StringBundler(3);
276+
277+
try {
278+
sb.append(PortalUtil.getCDNHost(getRequest()));
279+
}
280+
catch (PortalException portalException) {
281+
throw new RuntimeException(portalException);
282+
}
283+
284+
sb.append(PortalUtil.getPathProxy());
285+
286+
String unhashedFileURI =
287+
PortalUtil.getPathModule() + StringPool.SLASH + getSrc();
288+
289+
String hashedFileURI = HashedFilesRegistryUtil.getHashedFileURI(
290+
unhashedFileURI);
291+
292+
sb.append(
293+
(hashedFileURI == null) ? unhashedFileURI : hashedFileURI);
294+
295+
src = sb.toString();
296+
}
297+
298+
_write(jspWriter, "src", src);
269299
_write(jspWriter, "type", getType());
270300

271301
String senna = getSenna();

util-taglib/src/com/liferay/taglib/aui/base/BaseScriptTag.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public java.lang.String getFetchPriority() {
4040
return _fetchPriority;
4141
}
4242

43+
public boolean getHashedFile() {
44+
return _hashedFile;
45+
}
46+
47+
public void setHashedFile(boolean hashedFile) {
48+
_hashedFile = hashedFile;
49+
}
50+
4351
public java.lang.String getId() {
4452
return _id;
4553
}
@@ -138,6 +146,7 @@ protected void cleanUp() {
138146
_crossOrigin = null;
139147
_defer = false;
140148
_fetchPriority = null;
149+
_hashedFile = false;
141150
_id = null;
142151
_integrity = null;
143152
_referrerPolicy = null;
@@ -161,6 +170,7 @@ protected String getPage() {
161170
private java.lang.String _crossOrigin = null;
162171
private boolean _defer = false;
163172
private java.lang.String _fetchPriority = null;
173+
private boolean _hashedFile;
164174
private java.lang.String _id = null;
165175
private java.lang.String _integrity = null;
166176
private java.lang.String _referrerPolicy = null;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version 18.1.0
1+
version 18.2.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version 19.1.0
1+
version 19.2.0

util-taglib/src/com/liferay/taglib/liferay-aui.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@
10611061
<inputType>java.lang.String</inputType>
10621062
<outputType>java.lang.String</outputType>
10631063
</attribute>
1064+
<attribute>
1065+
<name>hashedFile</name>
1066+
<inputType>java.lang.Boolean</inputType>
1067+
<outputType>java.lang.Boolean</outputType>
1068+
</attribute>
10641069
<attribute>
10651070
<name>id</name>
10661071
<inputType>java.lang.String</inputType>

0 commit comments

Comments
 (0)