1
14
15 package com.liferay.taglib.aui;
16
17 import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18 import com.liferay.portal.kernel.util.ServerDetector;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.kernel.util.Validator;
21 import com.liferay.portal.kernel.util.WebKeys;
22 import com.liferay.portal.servlet.taglib.aui.ScriptData;
23 import com.liferay.portal.theme.ThemeDisplay;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.tagext.BodyTagSupport;
28
29
34 public class ScriptTag extends BodyTagSupport {
35
36 public static final String PAGE = "/html/taglib/aui/script/page.jsp";
37
38 public int doStartTag() {
39 return EVAL_BODY_BUFFERED;
40 }
41
42 public int doAfterBody() {
43 _bodyContentString = getBodyContent().getString();
44
45 return SKIP_BODY;
46 }
47
48 public int doEndTag() throws JspException {
49 HttpServletRequest request =
50 (HttpServletRequest)pageContext.getRequest();
51
52 try {
53 if (Validator.isNull(_position)) {
54 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
55 WebKeys.THEME_DISPLAY);
56
57 if (themeDisplay.isIsolated() ||
58 themeDisplay.isLifecycleResource() ||
59 themeDisplay.isStateExclusive()) {
60
61 _position = _POSITION_INLINE;
62 }
63 else {
64 _position = _POSITION_AUTO;
65 }
66 }
67
68 if (_position.equals(_POSITION_INLINE)) {
69 ScriptData scriptData = new ScriptData();
70
71 request.setAttribute(ScriptTag.class.getName(), scriptData);
72
73 scriptData.append(_bodyContentString, _use);
74
75 PortalIncludeUtil.include(pageContext, PAGE);
76 }
77 else {
78 ScriptData scriptData = (ScriptData)request.getAttribute(
79 WebKeys.AUI_SCRIPT_DATA);
80
81 if (scriptData == null) {
82 scriptData = new ScriptData();
83
84 request.setAttribute(WebKeys.AUI_SCRIPT_DATA, scriptData);
85 }
86
87 scriptData.append(_bodyContentString, _use);
88 }
89
90 return EVAL_PAGE;
91 }
92 catch (Exception e) {
93 throw new JspException(e);
94 }
95 finally {
96 if (_position.equals(_POSITION_INLINE)) {
97 request.removeAttribute(ScriptTag.class.getName());
98 }
99
100 if (!ServerDetector.isResin()) {
101 _bodyContentString = StringPool.BLANK;
102 _position = null;
103 _use = null;
104 }
105 }
106 }
107
108 public void setPosition(String position) {
109 _position = position;
110 }
111
112 public void setUse(String use) {
113 _use = use;
114 }
115
116 private static final String _POSITION_AUTO = "auto";
117
118 private static final String _POSITION_INLINE = "inline";
119
120 private String _bodyContentString = StringPool.BLANK;
121 private String _position;
122 private String _use;
123
124 }