private void _readColorSchemes( Element themeElement, Map<String, ColorScheme> colorSchemes, ContextReplace themeContextReplace) { List<Element> colorSchemeElements = themeElement.elements("color-scheme"); for (Element colorSchemeElement : colorSchemeElements) { ContextReplace colorSchemeContextReplace = (ContextReplace) themeContextReplace.clone(); String id = colorSchemeElement.attributeValue("id"); colorSchemeContextReplace.addValue("color-scheme-id", id); ColorScheme colorSchemeModel = colorSchemes.get(id); if (colorSchemeModel == null) { colorSchemeModel = new ColorSchemeImpl(id); } String name = GetterUtil.getString( colorSchemeElement.attributeValue("name"), colorSchemeModel.getName()); name = colorSchemeContextReplace.replace(name); boolean defaultCs = GetterUtil.getBoolean( colorSchemeElement.elementText("default-cs"), colorSchemeModel.isDefaultCs()); String cssClass = GetterUtil.getString( colorSchemeElement.elementText("css-class"), colorSchemeModel.getCssClass()); cssClass = colorSchemeContextReplace.replace(cssClass); colorSchemeContextReplace.addValue("css-class", cssClass); String colorSchemeImagesPath = GetterUtil.getString( colorSchemeElement.elementText("color-scheme-images-path"), colorSchemeModel.getColorSchemeImagesPath()); colorSchemeImagesPath = colorSchemeContextReplace.replace(colorSchemeImagesPath); colorSchemeContextReplace.addValue("color-scheme-images-path", colorSchemeImagesPath); colorSchemeModel.setName(name); colorSchemeModel.setDefaultCs(defaultCs); colorSchemeModel.setCssClass(cssClass); colorSchemeModel.setColorSchemeImagesPath(colorSchemeImagesPath); colorSchemes.put(id, colorSchemeModel); } }
public boolean equals(Object obj) { if (obj == null) { return false; } ColorScheme colorScheme = null; try { colorScheme = (ColorScheme) obj; } catch (ClassCastException cce) { return false; } String colorSchemeId = colorScheme.getColorSchemeId(); if (getColorSchemeId().equals(colorSchemeId)) { return true; } else { return false; } }
public ColorScheme getColorScheme( long companyId, String themeId, String colorSchemeId, boolean wapTheme) throws SystemException { colorSchemeId = GetterUtil.getString(colorSchemeId); Theme theme = getTheme(companyId, themeId, wapTheme); Map<String, ColorScheme> colorSchemesMap = theme.getColorSchemesMap(); ColorScheme colorScheme = colorSchemesMap.get(colorSchemeId); if (colorScheme == null) { List<ColorScheme> colorSchemes = theme.getColorSchemes(); if (colorSchemes.size() > 0) { for (int i = (colorSchemes.size() - 1); i >= 0; i--) { colorScheme = colorSchemes.get(i); if (colorScheme.isDefaultCs()) { break; } } } } if (colorScheme == null) { if (wapTheme) { colorSchemeId = ColorSchemeImpl.getDefaultWapColorSchemeId(); } else { colorSchemeId = ColorSchemeImpl.getDefaultRegularColorSchemeId(); } } if (colorScheme == null) { colorScheme = ColorSchemeImpl.getNullColorScheme(); } return colorScheme; }
public void setLookAndFeel(Theme theme, ColorScheme colorScheme) { _theme = theme; _colorScheme = colorScheme; if ((theme != null) && (colorScheme != null)) { String themeStaticResourcePath = theme.getStaticResourcePath(); String cdnBaseURL = getCDNBaseURL(); setPathColorSchemeImages( cdnBaseURL + themeStaticResourcePath + colorScheme.getColorSchemeImagesPath()); String dynamicResourcesHost = getCDNDynamicResourcesHost(); if (Validator.isNull(dynamicResourcesHost)) { String portalURL = getPortalURL(); if (getServerName() != null) { try { portalURL = PortalUtil.getPortalURL(getLayout(), this); } catch (Exception e) { _log.error(e, e); } } dynamicResourcesHost = portalURL; } setPathThemeCss(dynamicResourcesHost + themeStaticResourcePath + theme.getCssPath()); setPathThemeImages(cdnBaseURL + themeStaticResourcePath + theme.getImagesPath()); setPathThemeJavaScript(cdnBaseURL + themeStaticResourcePath + theme.getJavaScriptPath()); setPathThemeRoot(themeStaticResourcePath + theme.getRootPath()); setPathThemeTemplates(cdnBaseURL + themeStaticResourcePath + theme.getTemplatesPath()); } }
@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); } }
public int compareTo(ColorScheme colorScheme) { return getName().compareTo(colorScheme.getName()); }