List of usage examples for com.liferay.portal.kernel.language LanguageUtil getLanguage
public static Language getLanguage()
From source file:com.gleo.groupphoto.web.portlet.action.ViewUserDetailsActionMVCRenderCommand.java
License:Open Source License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) { long userId = ParamUtil.getLong(renderRequest, "userId"); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); String organizationsHTML = StringPool.BLANK; Contact contact = null;//ww w .ja va 2s . c om List<Organization> organizations = null; User user = null; Company company = null; Locale locale = themeDisplay.getLocale(); String birthday = null; String jobTitle = null; String gender = null; String comments = null; // Get User if (userId > 0) { try { user = UserLocalServiceUtil.getUser(userId); company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); } catch (PortalException e) { LOGGER.error(e); } if (user != null) { // Get Contact try { contact = user.getContact(); } catch (PortalException e) { LOGGER.error(e); } // Get Organizations organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId()); StringBundler organizationsHTMLBundler = new StringBundler(organizations.size() * 2); if (!organizations.isEmpty()) { organizationsHTMLBundler.append(organizations.get(0).getName()); } for (int i = 1; i < organizations.size(); i++) { organizationsHTMLBundler.append(", "); organizationsHTMLBundler.append(organizations.get(i).getName()); } organizationsHTML = organizationsHTMLBundler.toString(); // Fields setFields(renderRequest, contact, user, company, locale, birthday, gender, jobTitle); // Contact String className = Contact.class.getName(); long classPK = contact.getContactId(); List<Address> personalAddresses = Collections.emptyList(); List<Address> organizationAddresses = new ArrayList<Address>(); List<EmailAddress> emailAddresses = Collections.emptyList(); List<Website> websites = Collections.emptyList(); List<Phone> personalPhones = Collections.emptyList(); List<Phone> organizationPhones = new ArrayList<Phone>(); if (classPK > 0) { try { personalAddresses = AddressServiceUtil.getAddresses(className, classPK); } catch (PortalException pe) { LOGGER.error(pe); } try { emailAddresses = EmailAddressServiceUtil.getEmailAddresses(className, classPK); } catch (PortalException pe) { LOGGER.error(pe); } try { websites = WebsiteServiceUtil.getWebsites(className, classPK); } catch (PortalException pe) { LOGGER.error(pe); } try { personalPhones = PhoneServiceUtil.getPhones(className, classPK); } catch (PortalException pe) { LOGGER.error(pe); } } for (int i = 0; i < organizations.size(); i++) { try { organizationAddresses.addAll(AddressServiceUtil.getAddresses(Organization.class.getName(), organizations.get(i).getOrganizationId())); } catch (Exception e) { } } for (int i = 0; i < organizations.size(); i++) { try { organizationPhones.addAll(PhoneServiceUtil.getPhones(Organization.class.getName(), organizations.get(i).getOrganizationId())); } catch (Exception e) { } } // Comments comments = user.getComments(); LOGGER.info("comments" + comments); if (comments != null && !comments.trim().equals(StringPool.BLANK)) { comments = StringUtil.replace(BBCodeTranslatorUtil.getHTML(user.getComments()), ThemeConstants.TOKEN_THEME_IMAGES_PATH + EMOTICONS, themeDisplay.getPathThemeImages() + EMOTICONS); } renderRequest.setAttribute("organizationAddresses", organizationAddresses); renderRequest.setAttribute("personalAddresses", personalAddresses); renderRequest.setAttribute("emailAddresses", emailAddresses); renderRequest.setAttribute("organizationAddresses", organizationAddresses); renderRequest.setAttribute("websites", websites); renderRequest.setAttribute("personalPhones", personalPhones); renderRequest.setAttribute("organizationPhones", organizationPhones); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("userId =" + userId); LOGGER.debug("birthday =" + birthday); LOGGER.debug("gender =" + gender); LOGGER.debug("jobTitle =" + jobTitle); LOGGER.debug("comments =" + comments); } renderRequest.setAttribute("organizations", organizations); renderRequest.setAttribute("organizationsHTML", organizationsHTML); renderRequest.setAttribute("user2", user); renderRequest.setAttribute("contact", contact); renderRequest.setAttribute("languageUtil", LanguageUtil.getLanguage()); renderRequest.setAttribute("locale", locale); renderRequest.setAttribute("comments", comments); renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml()); return "/userdetails/jsp/user_details.jsp"; }
From source file:com.liferay.dynamic.data.mapping.internal.test.util.DDMFixture.java
License:Open Source License
protected void setUpLanguageUtil() { _language = LanguageUtil.getLanguage(); LanguageUtil languageUtil = new LanguageUtil(); languageUtil.setLanguage(Mockito.mock(Language.class)); }
From source file:com.liferay.portlet.wiki.service.impl.WikiPageServiceImpl.java
License:Open Source License
protected String getPageDiff(long companyId, WikiPage latestPage, WikiPage page, Locale locale) throws SystemException { String sourceContent = WikiUtil.processContent(latestPage.getContent()); String targetContent = WikiUtil.processContent(page.getContent()); sourceContent = HtmlUtil.escape(sourceContent); targetContent = HtmlUtil.escape(targetContent); List<DiffResult>[] diffResults = DiffUtil.diff(new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent)); String velocityTemplateId = "com/liferay/portlet/wiki/dependencies/rss.vm"; String velocityTemplateContent = ContentUtil.get(velocityTemplateId); VelocityContext velocityContext = VelocityEngineUtil.getWrappedStandardToolsContext(); velocityContext.put("companyId", companyId); velocityContext.put("contextLine", Diff.CONTEXT_LINE); velocityContext.put("diffUtil", new DiffUtil()); velocityContext.put("languageUtil", LanguageUtil.getLanguage()); velocityContext.put("locale", locale); velocityContext.put("sourceResults", diffResults[0]); velocityContext.put("targetResults", diffResults[1]); try {/*from w ww .j av a2 s. c o m*/ UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter(); VelocityEngineUtil.mergeTemplate(velocityTemplateId, velocityTemplateContent, velocityContext, unsyncStringWriter); return unsyncStringWriter.toString(); } catch (Exception e) { throw new SystemException(e); } }