List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLocale
public Locale getLocale()
From source file:com.liferay.layout.admin.web.internal.portlet.action.AddSimpleLayoutMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId"); long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId"); long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId"); boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout"); long parentLayoutId = ParamUtil.getLong(actionRequest, "parentLayoutId"); String name = ParamUtil.getString(actionRequest, "name"); String type = ParamUtil.getString(actionRequest, "type"); Map<Locale, String> nameMap = new HashMap<>(); nameMap.put(themeDisplay.getLocale(), name); ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest); UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {/*from ww w. j ava2 s . c om*/ Layout layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, new HashMap<Locale, String>(), new HashMap<Locale, String>(), new HashMap<Locale, String>(), new HashMap<Locale, String>(), type, typeSettingsProperties.toString(), false, new HashMap<Locale, String>(), serviceContext); LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID); _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings()); _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties()); jsonObject.put("redirectURL", getRedirectURL(actionResponse)); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale()); jsonObject.put("error", LanguageUtil.get(resourceBundle, "an-unexpected-error-occurred")); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } }
From source file:com.liferay.layout.admin.web.internal.portlet.action.AssetDisplayContributorFieldsMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String className = ParamUtil.getString(actionRequest, "className"); AssetDisplayContributor assetDisplayContributor = _assetDisplayContributorTracker .getAssetDisplayContributor(className); if (assetDisplayContributor == null) { JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, JSONFactoryUtil.createJSONArray()); return;/*from w ww .ja va 2 s .com*/ } JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (AssetDisplayField assetDisplayField : assetDisplayContributor .getAssetEntryFields(themeDisplay.getLocale())) { jsonArray.put(assetDisplayField.toJSONObject()); } JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonArray); }
From source file:com.liferay.layout.admin.web.internal.theme.contributor.ToggleControlsTemplateContextContributor.java
License:Open Source License
@Override public void prepare(Map<String, Object> contextObjects, HttpServletRequest request) { String liferayToggleControls = SessionClicks.get(request, "com.liferay.frontend.js.web_toggleControls", "visible"); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); if (layout.isTypeControlPanel()) { liferayToggleControls = "visible"; }// w w w.j av a 2s . com String cssClass = GetterUtil.getString(contextObjects.get("bodyCssClass")); if (Objects.equals(liferayToggleControls, "visible")) { cssClass += " controls-visible"; } else { cssClass += " controls-hidden"; } contextObjects.put("bodyCssClass", cssClass); contextObjects.put("liferay_toggle_controls", liferayToggleControls); contextObjects.put("show_toggle_controls", themeDisplay.isSignedIn()); if (themeDisplay.isSignedIn()) { ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", themeDisplay.getLocale(), getClass()); contextObjects.put("toggle_controls_text", LanguageUtil.get(resourceBundle, "toggle-controls")); contextObjects.put("toggle_controls_url", "javascript:;"); } }
From source file:com.liferay.layout.internal.util.LayoutsTreeImpl.java
License:Open Source License
private JSONObject _toJSONObject(HttpServletRequest request, long groupId, LayoutTreeNodes layoutTreeNodes, LayoutSetBranch layoutSetBranch) throws Exception { if (_log.isDebugEnabled()) { StringBundler sb = new StringBundler(5); sb.append("_toJSON(groupId="); sb.append(groupId);//from ww w . ja va 2s.c om sb.append(", layoutTreeNodes="); sb.append(layoutTreeNodes); sb.append(StringPool.CLOSE_PARENTHESIS); _log.debug(sb.toString()); } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); boolean hasManageLayoutsPermission = GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS); boolean mobile = BrowserSnifferUtil.isMobile(request); for (LayoutTreeNode layoutTreeNode : layoutTreeNodes) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); JSONObject childrenJSONObject = _toJSONObject(request, groupId, layoutTreeNode.getChildLayoutTreeNodes(), layoutSetBranch); jsonObject.put("children", childrenJSONObject); Layout layout = layoutTreeNode.getLayout(); jsonObject.put("contentDisplayPage", layout.isContentDisplayPage()); jsonObject.put("deleteable", _isDeleteable(layout, themeDisplay, layoutSetBranch)); jsonObject.put("friendlyURL", layout.getFriendlyURL()); if (layout instanceof VirtualLayout) { VirtualLayout virtualLayout = (VirtualLayout) layout; jsonObject.put("groupId", virtualLayout.getSourceGroupId()); } else { jsonObject.put("groupId", layout.getGroupId()); } jsonObject.put("hasChildren", layout.hasChildren()); jsonObject.put("layoutId", layout.getLayoutId()); jsonObject.put("name", layout.getName(themeDisplay.getLocale())); jsonObject.put("parentable", LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.ADD_LAYOUT)); jsonObject.put("parentLayoutId", layout.getParentLayoutId()); jsonObject.put("plid", layout.getPlid()); jsonObject.put("priority", layout.getPriority()); jsonObject.put("privateLayout", layout.isPrivateLayout()); jsonObject.put("regularURL", layout.getRegularURL(request)); jsonObject.put("sortable", hasManageLayoutsPermission && !mobile && SitesUtil.isLayoutSortable(layout)); jsonObject.put("type", layout.getType()); jsonObject.put("updateable", LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE)); jsonObject.put("uuid", layout.getUuid()); LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout); if (layoutRevision != null) { long layoutSetBranchId = layoutRevision.getLayoutSetBranchId(); if (_staging.isIncomplete(layout, layoutSetBranchId)) { jsonObject.put("incomplete", true); } LayoutSetBranch boundLayoutSetBranch = _layoutSetBranchLocalService .getLayoutSetBranch(layoutSetBranchId); LayoutBranch layoutBranch = layoutRevision.getLayoutBranch(); if (!layoutBranch.isMaster()) { jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId()); jsonObject.put("layoutBranchName", layoutBranch.getName()); } if (layoutRevision.isHead()) { jsonObject.put("layoutRevisionHead", true); } jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId()); jsonObject.put("layoutSetBranchId", layoutSetBranchId); jsonObject.put("layoutSetBranchName", boundLayoutSetBranch.getName()); } jsonArray.put(jsonObject); } JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject(); responseJSONObject.put("layouts", jsonArray); responseJSONObject.put("total", layoutTreeNodes.getTotal()); return responseJSONObject; }
From source file:com.liferay.layout.item.selector.web.internal.display.context.LayoutItemSelectorViewDisplayContext.java
License:Open Source License
private String _getLayoutBreadcrumb(Layout layout) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); Locale locale = themeDisplay.getLocale(); List<Layout> ancestors = layout.getAncestors(); StringBundler sb = new StringBundler(4 * ancestors.size() + 5); if (layout.isPrivateLayout()) { sb.append(LanguageUtil.get(_request, "private-pages")); } else {/*from ww w . j av a 2 s . c o m*/ sb.append(LanguageUtil.get(_request, "public-pages")); } sb.append(StringPool.SPACE); sb.append(StringPool.GREATER_THAN); sb.append(StringPool.SPACE); Collections.reverse(ancestors); for (Layout ancestor : ancestors) { sb.append(HtmlUtil.escape(ancestor.getName(locale))); sb.append(StringPool.SPACE); sb.append(StringPool.GREATER_THAN); sb.append(StringPool.SPACE); } sb.append(HtmlUtil.escape(layout.getName(locale))); return sb.toString(); }
From source file:com.liferay.layout.item.selector.web.internal.display.context.LayoutItemSelectorViewDisplayContext.java
License:Open Source License
private JSONArray _getLayoutsJSONArray(long groupId, boolean privateLayout, long parentLayoutId, String selectedLayoutUuid) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout, parentLayoutId); for (Layout layout : layouts) { if (StagingUtil.isIncomplete(layout)) { continue; }//from w ww . j a v a 2s . co m JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); JSONArray childrenJSONArray = _getLayoutsJSONArray(groupId, privateLayout, layout.getLayoutId(), selectedLayoutUuid); if (childrenJSONArray.length() > 0) { jsonObject.put("children", childrenJSONArray); } if ((_layoutItemSelectorCriterion.isCheckDisplayPage() && !layout.isContentDisplayPage()) || (!_layoutItemSelectorCriterion.isEnableCurrentPage() && (layout.getPlid() == _getSelPlid()))) { jsonObject.put("disabled", true); } jsonObject.put("groupId", layout.getGroupId()); jsonObject.put("icon", "page"); jsonObject.put("id", layout.getUuid()); jsonObject.put("layoutId", layout.getLayoutId()); jsonObject.put("name", layout.getName(themeDisplay.getLocale())); jsonObject.put("privateLayout", layout.isPrivateLayout()); jsonObject.put("url", PortalUtil.getLayoutURL(layout, themeDisplay)); if (Objects.equals(layout.getUuid(), selectedLayoutUuid)) { jsonObject.put("selected", true); } jsonObject.put("value", _getLayoutBreadcrumb(layout)); jsonArray.put(jsonObject); } return jsonArray; }
From source file:com.liferay.layout.type.controller.link.to.page.internal.display.context.LinkToPageLayoutTypeControllerDisplayContext.java
License:Open Source License
public String getLayoutBreadcrumb(Layout layout) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(_liferayPortletRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Locale locale = themeDisplay.getLocale(); List<Layout> ancestors = layout.getAncestors(); StringBundler sb = new StringBundler(4 * ancestors.size() + 5); if (layout.isPrivateLayout()) { sb.append(LanguageUtil.get(request, "private-pages")); } else {//from ww w . j a va 2s .c o m sb.append(LanguageUtil.get(request, "public-pages")); } sb.append(StringPool.SPACE); sb.append(StringPool.GREATER_THAN); sb.append(StringPool.SPACE); Collections.reverse(ancestors); for (Layout ancestor : ancestors) { sb.append(HtmlUtil.escape(ancestor.getName(locale))); sb.append(StringPool.SPACE); sb.append(StringPool.GREATER_THAN); sb.append(StringPool.SPACE); } sb.append(HtmlUtil.escape(layout.getName(locale))); return sb.toString(); }
From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java
License:Open Source License
protected void updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = _portal .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest)); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); boolean autoPassword = true; String password1 = null;/*from w w w .j a v a2s . co m*/ String password2 = null; boolean autoScreenName = false; String screenName = ParamUtil.getString(actionRequest, "screenName"); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); HttpSession session = request.getSession(); long facebookId = GetterUtil.getLong(session.getAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID)); String googleUserId = GetterUtil.getString(session.getAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID)); if (Validator.isNotNull(googleUserId)) { autoPassword = false; } if ((facebookId > 0) || Validator.isNotNull(googleUserId)) { password1 = PwdGenerator.getPassword(); password2 = password1; } String openId = ParamUtil.getString(actionRequest, "openId"); String firstName = ParamUtil.getString(actionRequest, "firstName"); String middleName = ParamUtil.getString(actionRequest, "middleName"); String lastName = ParamUtil.getString(actionRequest, "lastName"); long prefixId = ParamUtil.getInteger(actionRequest, "prefixId"); long suffixId = ParamUtil.getInteger(actionRequest, "suffixId"); boolean male = ParamUtil.getBoolean(actionRequest, "male", true); int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth"); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay"); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear"); String jobTitle = ParamUtil.getString(actionRequest, "jobTitle"); boolean updateUserInformation = true; boolean sendEmail = true; if (Validator.isNotNull(googleUserId)) { sendEmail = false; } ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); User user = _userService.updateIncompleteUser(themeDisplay.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, updateUserInformation, sendEmail, serviceContext); if (facebookId > 0) { session.removeAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID); updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1); return; } if (Validator.isNotNull(googleUserId)) { _userLocalService.updateGoogleUserId(user.getUserId(), googleUserId); session.removeAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID); updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1); return; } // Session messages if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) { SessionMessages.add(request, "userAdded", user.getEmailAddress()); SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted()); } else { SessionMessages.add(request, "userPending", user.getEmailAddress()); } // Send redirect sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted()); }
From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java
License:Open Source License
protected void addAnonymousUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = _portal.getHttpServletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); boolean autoPassword = true; String password1 = null;/*from w ww .ja v a2 s . c o m*/ String password2 = null; boolean autoScreenName = true; String screenName = null; String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); long facebookId = 0; String openId = StringPool.BLANK; String firstName = ParamUtil.getString(actionRequest, "firstName"); String lastName = ParamUtil.getString(actionRequest, "lastName"); long prefixId = 0; long suffixId = 0; boolean male = true; int birthdayMonth = 0; int birthdayDay = 1; int birthdayYear = 1970; String jobTitle = null; long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; boolean sendEmail = false; ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); serviceContext.setAttribute("anonymousUser", Boolean.TRUE); CaptchaConfiguration captchaConfiguration = getCaptchaConfiguration(); if (captchaConfiguration.createAccountCaptchaEnabled()) { CaptchaUtil.check(actionRequest); } serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); User user = _userService.addUser(themeDisplay.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName, null, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); _userLocalService.updateStatus(user.getUserId(), WorkflowConstants.STATUS_INCOMPLETE, new ServiceContext()); // Session messages SessionMessages.add(request, "userAdded", user.getEmailAddress()); SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted()); }
From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java
License:Open Source License
protected JSONObject updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); boolean autoPassword = true; String password1 = null;// w w w . j ava2 s . co m String password2 = null; boolean autoScreenName = false; String screenName = null; String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); long facebookId = 0; String openId = null; String firstName = null; String middleName = null; String lastName = null; long prefixId = 0; long suffixId = 0; boolean male = true; int birthdayMonth = 0; int birthdayDay = 1; int birthdayYear = 1970; String jobTitle = null; boolean updateUserInformation = false; boolean sendEmail = true; User user = _userService.updateIncompleteUser(themeDisplay.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, updateUserInformation, sendEmail, serviceContext); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) { jsonObject.put("userStatus", "user_added"); } else { jsonObject.put("userStatus", "user_pending"); } return jsonObject; }