public Theme getWapTheme() throws PortalException, SystemException { if (isInheritWapLookAndFeel()) { return getLayoutSet().getWapTheme(); } else { return ThemeLocalServiceUtil.getTheme(getCompanyId(), getWapThemeId(), true); } }
@Override public ColorScheme getColorScheme() throws PortalException, SystemException { if (isInheritLookAndFeel()) { return getLayoutSet().getColorScheme(); } else { return ThemeLocalServiceUtil.getColorScheme( getCompanyId(), getTheme().getThemeId(), getColorSchemeId(), false); } }
protected void initThemes(PluginPackage pluginPackage, List<Portlet> portlets) throws Exception { ServletContext servletContext = getServletContext(); String[] xmls = new String[] { HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-look-and-feel.xml")), HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-look-and-feel-ext.xml")) }; List<Theme> themes = ThemeLocalServiceUtil.init(servletContext, null, true, xmls, pluginPackage); servletContext.setAttribute(WebKeys.PLUGIN_THEMES, themes); }
protected void updateLayoutSetThemeId(JSONObject sitemapJSONObject) throws Exception { String themeId = sitemapJSONObject.getString("themeId"); if (Validator.isNotNull(themeId)) { Theme theme = ThemeLocalServiceUtil.fetchTheme(companyId, themeId); if (theme == null) { themeId = null; } } if (Validator.isNull(themeId)) { int pos = servletContextName.indexOf("-theme"); if (pos != -1) { themeId = servletContextName.substring(0, pos) + PortletConstants.WAR_SEPARATOR + servletContextName; themeId = PortalUtil.getJsSafePortletId(themeId); Theme theme = ThemeLocalServiceUtil.fetchTheme(companyId, themeId); if (theme == null) { themeId = null; } } } if (Validator.isNotNull(themeId)) { LayoutSetLocalServiceUtil.updateLookAndFeel( groupId, privateLayout, themeId, null, null, false); } }
protected void registerTheme(File liferayLookAndFeelXML) { if (_log.isDebugEnabled()) { _log.debug("Registering " + liferayLookAndFeelXML); } try { String content = FileUtil.read(liferayLookAndFeelXML); ThemeLocalServiceUtil.init( _servletContextName, _servletContext, _themesPath, _loadFromServletContext, new String[] {content}, null); } catch (Exception e) { _log.error("Error registering theme " + liferayLookAndFeelXML.toString(), e); } }
@Override public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException { try { // Do not randomize look and feel unless the user is logged in ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); if (!themeDisplay.isSignedIn()) { return; } // Do not randomize look and feel unless the user is accessing the // portal String requestURI = GetterUtil.getString(request.getRequestURI()); if (!requestURI.endsWith("/portal/layout")) { return; } // Do not randomize look and feel unless the user is accessing a // personal layout Layout layout = themeDisplay.getLayout(); if (layout == null) { return; } boolean wapTheme = BrowserSnifferUtil.isWap(request); List<Theme> themes = ThemeLocalServiceUtil.getPageThemes( themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), themeDisplay.getUserId(), wapTheme); if (!themes.isEmpty()) { Theme theme = themes.get(RandomUtil.nextInt(themes.size())); List<ColorScheme> colorSchemes = theme.getColorSchemes(); ColorScheme colorScheme = colorSchemes.get(RandomUtil.nextInt(colorSchemes.size())); LayoutServiceUtil.updateLookAndFeel( layout.getGroupId(), layout.isPrivateLayout(), layout.getPlid(), theme.getThemeId(), colorScheme.getColorSchemeId(), layout.getCss(), wapTheme); themeDisplay.setLookAndFeel(theme, colorScheme); request.setAttribute(WebKeys.THEME, theme); request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme); } } catch (Exception e) { _log.error(e, e); throw new ActionException(e); } }