List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay translate
public String translate(String key)
From source file:com.liferay.blogs.internal.trash.BlogsEntryTrashHandler.java
License:Open Source License
@Override public String getRestoreMessage(PortletRequest portletRequest, long classPK) { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); return themeDisplay.translate("blogs"); }
From source file:com.liferay.blogs.web.internal.trackback.Trackback.java
License:Open Source License
protected String buildBBCodeBody(ThemeDisplay themeDisplay, String excerpt, String url) { url = StringUtil.replace(url, new char[] { CharPool.CLOSE_BRACKET, CharPool.OPEN_BRACKET }, new String[] { "%5D", "%5B" }); StringBundler sb = new StringBundler(7); sb.append("[...] "); sb.append(excerpt);//w w w. j ava2 s.c om sb.append(" [...] [url="); sb.append(url); sb.append("]"); sb.append(themeDisplay.translate("read-more")); sb.append("[/url]"); return sb.toString(); }
From source file:com.liferay.blogs.web.internal.trackback.Trackback.java
License:Open Source License
protected String buildHTMLBody(ThemeDisplay themeDisplay, String excerpt, String url) { StringBundler sb = new StringBundler(7); sb.append("[...] "); sb.append(excerpt);//from w w w . j a v a 2 s.c o m sb.append(" [...] <a href=\""); sb.append(url); sb.append("\">"); sb.append(themeDisplay.translate("read-more")); sb.append("</a>"); return sb.toString(); }
From source file:com.liferay.bookmarks.util.BookmarksUtil.java
License:Open Source License
public static String getAbsolutePath(PortletRequest portletRequest, long folderId) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); if (folderId == BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) { return themeDisplay.translate("home"); }/*from w w w .j a v a2s .com*/ BookmarksFolder folder = BookmarksFolderLocalServiceUtil.fetchBookmarksFolder(folderId); List<BookmarksFolder> folders = folder.getAncestors(); StringBundler sb = new StringBundler((folders.size() * 3) + 5); sb.append(themeDisplay.translate("home")); sb.append(StringPool.SPACE); Collections.reverse(folders); for (BookmarksFolder curFolder : folders) { sb.append(StringPool.RAQUO_CHAR); sb.append(StringPool.SPACE); sb.append(curFolder.getName()); } sb.append(StringPool.RAQUO_CHAR); sb.append(StringPool.SPACE); sb.append(folder.getName()); return sb.toString(); }
From source file:com.liferay.bookmarks.web.internal.portlet.util.BookmarksUtil.java
License:Open Source License
public static void addPortletBreadcrumbEntries(BookmarksFolder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String mvcRenderCommandName = ParamUtil.getString(request, "mvcRenderCommandName"); PortletURL portletURL = renderResponse.createRenderURL(); if (mvcRenderCommandName.equals("/bookmarks/select_folder")) { portletURL.setParameter("mvcRenderCommandName", "/bookmarks/select_folder"); portletURL.setWindowState(LiferayWindowState.POP_UP); } else {/*from w ww . ja v a 2 s . c om*/ portletURL.setParameter("mvcRenderCommandName", "/bookmarks/view"); } PortalUtil.addPortletBreadcrumbEntry(request, themeDisplay.translate("home"), portletURL.toString()); if (folder == null) { return; } if (!mvcRenderCommandName.equals("/bookmarks/select_folder")) { portletURL.setParameter("mvcRenderCommandName", "/bookmarks/view_folder"); } List<BookmarksFolder> ancestorFolders = folder.getAncestors(); Collections.reverse(ancestorFolders); for (BookmarksFolder ancestorFolder : ancestorFolders) { portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId())); PortalUtil.addPortletBreadcrumbEntry(request, ancestorFolder.getName(), portletURL.toString()); } portletURL.setParameter("folderId", String.valueOf(folder.getFolderId())); if (folder.getFolderId() != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID) { BookmarksFolder unescapedFolder = folder.toUnescapedModel(); PortalUtil.addPortletBreadcrumbEntry(request, unescapedFolder.getName(), portletURL.toString()); } }
From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java
License:Open Source License
public void importCalendar(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long calendarId = ParamUtil.getLong(uploadPortletRequest, "calendarId"); File file = uploadPortletRequest.getFile("file"); String data = FileUtil.read(file); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (Validator.isNotNull(data)) { try {//from w ww . ja v a 2s .c o m CalendarDataHandler calendarDataHandler = CalendarDataHandlerFactory .getCalendarDataHandler(CalendarDataFormat.ICAL); calendarDataHandler.importCalendar(calendarId, data); jsonObject.put("success", true); } catch (Exception e) { String message = themeDisplay.translate("an-unexpected-error-occurred-while-importing-your-file"); jsonObject.put("error", message); jsonObject.put("success", false); } } else { ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", themeDisplay.getLocale(), getClass()); String message = ResourceBundleUtil.getString(resourceBundle, "failed-to-import-empty-file"); jsonObject.put("error", message); jsonObject.put("success", false); } writeJSON(actionRequest, actionResponse, jsonObject); }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void deleteTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long folderId = ParamUtil.getLong(actionRequest, "folderId"); String fileName = ParamUtil.getString(actionRequest, "fileName"); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try {//from w w w. ja v a 2 s . c om _dlAppService.deleteTempFileEntry(themeDisplay.getScopeGroupId(), folderId, TEMP_FOLDER_NAME, fileName); jsonObject.put("deleted", Boolean.TRUE); } catch (Exception e) { String errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-deleting-the-file"); jsonObject.put("deleted", Boolean.FALSE); jsonObject.put("errorMessage", errorMessage); } JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected String getAddMultipleFileEntriesErrorMessage(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, Exception e) throws Exception { String errorMessage = null;/*from w w w . java 2s.c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); } else if (e instanceof AssetCategoryException) { AssetCategoryException ace = (AssetCategoryException) e; AssetVocabulary assetVocabulary = ace.getVocabulary(); String vocabularyTitle = StringPool.BLANK; if (assetVocabulary != null) { vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale()); } if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) { errorMessage = themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle); } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) { errorMessage = themeDisplay.translate("you-cannot-select-more-than-one-category-for-x", vocabularyTitle); } } else if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate("the-folder-you-selected-already-has-an-entry-with-this-" + "name.-please-select-a-different-folder"); } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil.merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-size-no-larger-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); } else if (e instanceof InvalidFileEntryTypeException) { errorMessage = themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder"); } else { errorMessage = themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document"); } return errorMessage; }
From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java
License:Open Source License
protected void handleUploadException(PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse, String cmd, Exception e) throws Exception { if (e instanceof AssetCategoryException || e instanceof AssetTagException) { SessionErrors.add(actionRequest, e.getClass(), e); } else if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof DuplicateFolderNameException || e instanceof FileExtensionException || e instanceof FileMimeTypeException || e instanceof FileNameException || e instanceof FileSizeException || e instanceof LiferayFileItemException || e instanceof NoSuchFolderException || e instanceof SourceFileNameException || e instanceof StorageFieldRequiredException || e instanceof UploadRequestSizeException) { if (!cmd.equals(Constants.ADD_DYNAMIC) && !cmd.equals(Constants.ADD_MULTIPLE) && !cmd.equals(Constants.ADD_TEMP)) { if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); }/* w w w . j av a 2s . com*/ return; } else if (cmd.equals(Constants.ADD_TEMP)) { hideDefaultErrorMessage(actionRequest); } if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException || e instanceof FileExtensionException || e instanceof FileNameException || e instanceof FileSizeException || e instanceof UploadRequestSizeException) { HttpServletResponse response = _portal.getHttpServletResponse(actionResponse); response.setContentType(ContentTypes.TEXT_HTML); response.setStatus(HttpServletResponse.SC_OK); String errorMessage = StringPool.BLANK; int errorType = 0; ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (e instanceof AntivirusScannerException) { AntivirusScannerException ase = (AntivirusScannerException) e; errorMessage = themeDisplay.translate(ase.getMessageKey()); errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION; } if (e instanceof DuplicateFileEntryException) { errorMessage = themeDisplay.translate("please-enter-a-unique-document-name"); errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION; } else if (e instanceof FileExtensionException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil .merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse))); errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION; } else if (e instanceof FileNameException) { errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name"); errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION; } else if (e instanceof FileSizeException) { long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE); if (fileMaxSize == 0) { fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE); } errorMessage = themeDisplay.translate( "please-enter-a-file-with-a-valid-file-size-no-" + "larger-than-x", TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale())); errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION; } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("message", errorMessage); jsonObject.put("status", errorType); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } if (e instanceof AntivirusScannerException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { SessionErrors.add(actionRequest, e.getClass()); } } else if (e instanceof DuplicateLockException || e instanceof FileEntryLockException.MustOwnLock || e instanceof InvalidFileVersionException || e instanceof NoSuchFileEntryException || e instanceof PrincipalException) { if (e instanceof DuplicateLockException) { DuplicateLockException dle = (DuplicateLockException) e; SessionErrors.add(actionRequest, dle.getClass(), dle.getLock()); } else { SessionErrors.add(actionRequest, e.getClass()); } actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp"); } else { Throwable cause = e.getCause(); if (cause instanceof DuplicateFileEntryException) { SessionErrors.add(actionRequest, DuplicateFileEntryException.class); } else { throw e; } } }
From source file:com.liferay.document.library.web.internal.util.DLBreadcrumbUtil.java
License:Open Source License
public static void addPortletBreadcrumbEntries(Folder folder, HttpServletRequest request, LiferayPortletResponse liferayPortletResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL portletURL = liferayPortletResponse.createRenderURL(); portletURL.setParameter("mvcRenderCommandName", "/document_library/view"); Map<String, Object> data = new HashMap<>(); data.put("direction-right", Boolean.TRUE.toString()); PortletDisplay portletDisplay = themeDisplay.getPortletDisplay(); DLPortletInstanceSettings dlPortletInstanceSettings = DLPortletInstanceSettings .getInstance(themeDisplay.getLayout(), portletDisplay.getId()); data.put("folder-id", dlPortletInstanceSettings.getRootFolderId()); PortalUtil.addPortletBreadcrumbEntry(request, themeDisplay.translate("home"), portletURL.toString(), data); portletURL.setParameter("mvcRenderCommandName", "/document_library/view_folder"); addPortletBreadcrumbEntries(folder, request, portletURL); }