-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
ProductNavigationControlMenuTopHeadDynamicInclude.java
97 lines (76 loc) · 2.92 KB
/
ProductNavigationControlMenuTopHeadDynamicInclude.java
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
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.product.navigation.control.menu.theme.contributor.internal.servlet.taglib;
import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.servlet.taglib.DynamicInclude;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.url.builder.AbsolutePortalURLBuilder;
import com.liferay.portal.url.builder.AbsolutePortalURLBuilderFactory;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
/**
* @author Iván Zaera Avellón
*/
@Component(immediate = true, service = DynamicInclude.class)
public class ProductNavigationControlMenuTopHeadDynamicInclude
implements DynamicInclude {
@Override
public void include(
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse, String key)
throws IOException {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
if (!themeDisplay.isSignedIn()) {
return;
}
PrintWriter printWriter = httpServletResponse.getWriter();
StringBundler sb = new StringBundler(3);
sb.append("<link data-senna-track=\"permanent\" href=\"");
AbsolutePortalURLBuilder absolutePortalURLBuilder =
_absolutePortalURLBuilderFactory.getAbsolutePortalURLBuilder(
httpServletRequest);
sb.append(
absolutePortalURLBuilder.forModule(
_bundle,
"/product_navigation_control_menu.css?languageId=" +
themeDisplay.getLanguageId()
).build());
sb.append("\" rel=\"stylesheet\" type = \"text/css\" />\n");
printWriter.println(sb.toString());
}
@Override
public void register(DynamicIncludeRegistry dynamicIncludeRegistry) {
dynamicIncludeRegistry.register(
"/html/common/themes/top_head.jsp#post");
}
@Activate
@Modified
protected void activate(BundleContext bundleContext) {
_bundle = bundleContext.getBundle();
}
@Reference
private AbsolutePortalURLBuilderFactory _absolutePortalURLBuilderFactory;
private Bundle _bundle;
}