001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.servlet.taglib.ui.FormNavigatorCategoryUtil;
018 import com.liferay.portal.kernel.servlet.taglib.ui.FormNavigatorEntryUtil;
019 import com.liferay.portal.kernel.util.ArrayUtil;
020 import com.liferay.portal.kernel.util.WebKeys;
021 import com.liferay.portal.theme.ThemeDisplay;
022 import com.liferay.taglib.util.IncludeTag;
023
024 import javax.servlet.http.HttpServletRequest;
025
026
030 public class FormNavigatorTag extends IncludeTag {
031
032 @Override
033 public int doStartTag() {
034 return EVAL_BODY_INCLUDE;
035 }
036
037 public void setBackURL(String backURL) {
038 _backURL = backURL;
039 }
040
041
044 @Deprecated
045 public void setCategoryNames(String[] categoryNames) {
046 _categoryNames = categoryNames;
047 }
048
049
052 @Deprecated
053 public void setCategorySections(String[][] categorySections) {
054 _categorySections = categorySections;
055 }
056
057 public void setDisplayStyle(String displayStyle) {
058 _displayStyle = displayStyle;
059 }
060
061 public void setFormModelBean(Object formModelBean) {
062 _formModelBean = formModelBean;
063 }
064
065 public void setFormName(String formName) {
066 _formName = formName;
067 }
068
069 public void setHtmlBottom(String htmlBottom) {
070 _htmlBottom = htmlBottom;
071 }
072
073 public void setHtmlTop(String htmlTop) {
074 _htmlTop = htmlTop;
075 }
076
077 public void setId(String id) {
078 _id = id;
079 }
080
081
084 @Deprecated
085 public void setJspPath(String jspPath) {
086 _jspPath = jspPath;
087 }
088
089 public void setShowButtons(boolean showButtons) {
090 _showButtons = showButtons;
091 }
092
093 @Override
094 protected void cleanUp() {
095 _backURL = null;
096 _categoryNames = null;
097 _categorySections = null;
098 _displayStyle = "form";
099 _formModelBean = null;
100 _formName = "fm";
101 _htmlBottom = null;
102 _htmlTop = null;
103 _id = null;
104 _jspPath = null;
105 _showButtons = true;
106 }
107
108 protected String[] getCategoryKeys() {
109 if (_categoryNames != null) {
110 return _categoryNames;
111 }
112
113 return FormNavigatorCategoryUtil.getKeys(_id);
114 }
115
116 protected String[] getCategoryLabels() {
117 if (_categoryNames != null) {
118 return _categoryNames;
119 }
120
121 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
122 WebKeys.THEME_DISPLAY);
123
124 return FormNavigatorCategoryUtil.getLabels(
125 _id, themeDisplay.getLocale());
126 }
127
128 protected String[][] getCategorySectionKeys() {
129 if (_categorySections != null) {
130 return _categorySections;
131 }
132
133 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
134 WebKeys.THEME_DISPLAY);
135
136 String[] categoryKeys = getCategoryKeys();
137
138 String[][] categorySectionKeys = new String[0][];
139
140 for (int i = 0; i < categoryKeys.length; i++) {
141 String categoryKey = categoryKeys[i];
142
143 categorySectionKeys = ArrayUtil.append(
144 categorySectionKeys,
145 FormNavigatorEntryUtil.getKeys(
146 _id, categoryKey, themeDisplay.getUser(), _formModelBean));
147 }
148
149 return categorySectionKeys;
150 }
151
152 protected String[][] getCategorySectionLabels() {
153 if (_categorySections != null) {
154 return _categorySections;
155 }
156
157 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
158 WebKeys.THEME_DISPLAY);
159
160 String[] categoryKeys = getCategoryKeys();
161
162 String[][] categorySectionLabels = new String[0][];
163
164 for (int i = 0; i < categoryKeys.length; i++) {
165 String categoryKey = categoryKeys[i];
166
167 categorySectionLabels = ArrayUtil.append(
168 categorySectionLabels,
169 FormNavigatorEntryUtil.getLabels(
170 _id, categoryKey, themeDisplay.getUser(), _formModelBean,
171 themeDisplay.getLocale()));
172 }
173
174 return categorySectionLabels;
175 }
176
177 protected String[] getDeprecatedCategorySections() {
178 if (_categorySections == null) {
179 return new String[0];
180 }
181
182 String[] deprecatedCategorySections = new String[0];
183
184 for (String[] categorySection : _categorySections) {
185 deprecatedCategorySections = ArrayUtil.append(
186 deprecatedCategorySections, categorySection);
187 }
188
189 return deprecatedCategorySections;
190 }
191
192 @Override
193 protected String getPage() {
194 return _PAGE;
195 }
196
197 @Override
198 protected void setAttributes(HttpServletRequest request) {
199 request.setAttribute("liferay-ui:form-navigator:backURL", _backURL);
200 request.setAttribute(
201 "liferay-ui:form-navigator:categoryLabels", getCategoryLabels());
202 request.setAttribute(
203 "liferay-ui:form-navigator:categorySectionKeys",
204 getCategorySectionKeys());
205 request.setAttribute(
206 "liferay-ui:form-navigator:categorySectionLabels",
207 getCategorySectionLabels());
208 request.setAttribute(
209 "liferay-ui:form-navigator:deprecatedCategorySections",
210 getDeprecatedCategorySections());
211 request.setAttribute(
212 "liferay-ui:form-navigator:displayStyle", _displayStyle);
213 request.setAttribute(
214 "liferay-ui:form-navigator:formModelBean", _formModelBean);
215 request.setAttribute("liferay-ui:form-navigator:formName", _formName);
216 request.setAttribute("liferay-ui:form-navigator:id", _id);
217 request.setAttribute(
218 "liferay-ui:form-navigator:htmlBottom", _htmlBottom);
219 request.setAttribute("liferay-ui:form-navigator:htmlTop", _htmlTop);
220 request.setAttribute("liferay-ui:form-navigator:jspPath", _jspPath);
221 request.setAttribute(
222 "liferay-ui:form-navigator:showButtons",
223 String.valueOf(_showButtons));
224 }
225
226 private static final String _PAGE =
227 "/html/taglib/ui/form_navigator/page.jsp";
228
229 private String _backURL;
230 private String[] _categoryNames;
231 private String[][] _categorySections;
232 private String _displayStyle = "form";
233 private Object _formModelBean;
234 private String _formName = "fm";
235 private String _htmlBottom;
236 private String _htmlTop;
237 private String _id;
238 private String _jspPath;
239 private boolean _showButtons = true;
240
241 }